Exemplo n.º 1
0
        public async Task <CMSServiceAvailabilityResultModel> ValidateServiceAvailability(CMSAuthCredentialModel authCredential, string teamId, string projectExternalId, string projectName, string name)
        {
            CMSServiceAvailabilityResultModel result = new CMSServiceAvailabilityResultModel();
            var response = await _httpProxyService.GetAsync($"{projectExternalId}/_apis/git/repositories?api-version={_vstsOptions.Value.ApiVersion}", authCredential);

            if (!response.IsSuccessStatusCode || response.StatusCode == System.Net.HttpStatusCode.NonAuthoritativeInformation)
            {
                if (response.StatusCode == System.Net.HttpStatusCode.NonAuthoritativeInformation)
                {
                    result.Fail($"Code: {response.StatusCode}, Reason: The credentials are not correct");
                    return(result);
                }

                result.Fail($"Code: {response.StatusCode}, Reason: {await response.Content.ReadAsStringAsync()}");
                return(result);
            }

            var serviceResult = await response.MapTo <CMSVSTSServiceListModel>();

            var existsService = serviceResult.Items.Any(x => x.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));

            if (existsService)
            {
                result.Fail($"The service {name} has already been taken in the VSTS service (Repository)");
            }

            return(result);
        }
Exemplo n.º 2
0
        public async Task <CMSServiceAvailabilityResultModel> ValidateServiceAvailability(CMSAuthCredentialModel authCredential, string teamId, string projectExternalId, string projectName, string name)
        {
            CMSServiceAvailabilityResultModel result = new CMSServiceAvailabilityResultModel();

            var accountList = await GetAccounts(authCredential);

            var defaultTeam = accountList.Items.FirstOrDefault(c => c.AccountId.Equals(authCredential.AccountId));

            var urlRepo = "";

            if (defaultTeam != null && defaultTeam.IsOrganization)
            {
                urlRepo = $"/orgs/{defaultTeam.Name}/repos";
            }
            else
            {
                urlRepo = $"/user/repos";
            }

            var response = await _httpProxyService.GetAsync(urlRepo, authCredential, Headers);

            var serviceResult = await response.MapTo <List <CMSGitHubRepositoryModel> >();

            var serviceName = GetServiceName(projectName, name);

            var existsService = serviceResult.Any(x => x.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));

            if (existsService)
            {
                result.Fail($"The service {name} has already been taken in the CMS service");
            }

            return(result);
        }
        public async Task <CMSServiceAvailabilityResultModel> ValidateServiceAvailability(CMSAuthCredentialModel authCredential, string teamId, string projectExternalId, string projectName, string name)
        {
            CMSServiceAvailabilityResultModel result = new CMSServiceAvailabilityResultModel();

            var client = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authCredential.AccessToken);
            client.BaseAddress = new Uri(authCredential.Url);

            var teamResult = await GetAccountTeams(client, authCredential);

            var defaultTeam = teamResult.Teams.FirstOrDefault(c => c.TeamId.Equals(teamId));

            var response = await client.GetAsync(defaultTeam.Links.Repositories.Href);

            var serviceResult = await response.MapTo <CMSBitBucketRepositoryListModel>();

            var existsService = serviceResult.Repositories.Any(x => x.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));

            if (existsService)
            {
                result.Fail($"The service {name} has already been taken in the {authCredential.Provider} service (Repository)");
            }

            return(result);
        }
        public async Task <CMSServiceAvailabilityResultModel> ValidateServiceAvailability(CMSAuthCredentialModel authCredential, string teamId, string projectExternalId, string projectName, string name)
        {
            CMSServiceAvailabilityResultModel result = new CMSServiceAvailabilityResultModel();

            var httpClient = new HttpClient();

            var request = new HttpRequestMessage(HttpMethod.Get, $"{authCredential.Url}/projects?owned=true");

            request.Headers.Add("Private-Token", authCredential.AccessToken);

            var response = await httpClient.SendAsync(request);

            var data          = response.Content.ReadAsStringAsync().Result;
            var projectResult = await response.MapTo <List <CMSGitLabProjectModel> >();

            var existsProject = projectResult.Any(x => x.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));

            if (existsProject)
            {
                result.Fail($"The service {name} has already been taken in the {authCredential.Provider} service");
            }

            return(result);
        }