public async Task DeleteRepository(ProjectServiceDeletedEvent @event)
        {
            HttpClientWrapperAuthorizationModel authCredentials = new HttpClientWrapperAuthorizationModel();

            authCredentials.Schema = "Bearer";
            authCredentials.Value  = @event.CMSAccessToken;

            string deleteRepositoryUrl      = $"https://api.github.com/repos/{@event.CMSAccountName}/{@event.ServiceName}";
            var    deleteRepositoryResponse = await _httpClientWrapperService.DeleteAsync(deleteRepositoryUrl, authCredentials, Headers);

            deleteRepositoryResponse.EnsureSuccessStatusCode();
        }
示例#2
0
        public async Task DeleteProject(ProjectDeletedEvent @event)
        {
            string accountUrl = $"https://{@event.CMSAccountName}.visualstudio.com";

            HttpClientWrapperAuthorizationModel authCredentials = new HttpClientWrapperAuthorizationModel();

            authCredentials.Schema = "Basic";
            authCredentials.Value  = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", @event.CMSAccessSecret)));

            string projectUrl      = $"{accountUrl}/_apis/projects/{@event.ProjectExternalId}?api-version={_vstsOptions.Value.ApiVersion}";
            var    projectResponse = await _httpClientWrapperService.DeleteAsync(projectUrl, authCredentials);

            projectResponse.EnsureSuccessStatusCode();
        }
        public async Task DeleteProject(ProjectDeletedEvent @event)
        {
            //Begin: check data **********
            @event.CMSAccountName  = @event.CMSType == ConfigurationManagementService.VSTS ? @event.CMSAccountName : _fakeAccountOptions.Value.AccountId;
            @event.CMSAccessSecret = @event.CMSType == ConfigurationManagementService.VSTS ? @event.CMSAccessSecret : _fakeAccountOptions.Value.AccessSecret;

            string cmsProjectId = @event.CMSType == ConfigurationManagementService.VSTS ? @event.ProjectExternalId : @event.ProjectVSTSFakeId;
            //End: check data **********

            string accountUrl = $"https://{@event.CMSAccountName}.visualstudio.com";

            HttpClientWrapperAuthorizationModel authCredentials = new HttpClientWrapperAuthorizationModel();

            authCredentials.Schema = "Basic";
            authCredentials.Value  = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", @event.CMSAccessSecret)));

            string projectUrl      = $"{accountUrl}/_apis/projects/{cmsProjectId}?api-version={_fakeAccountOptions.Value.ApiVersion}";
            var    projectResponse = await _httpClientWrapperService.DeleteAsync(projectUrl, authCredentials);

            projectResponse.EnsureSuccessStatusCode();
        }
示例#4
0
        public async Task DeleteProject(ProjectDeletedEvent @event)
        {
            //Begin: check data **********
            @event.CMSAccountName  = @event.CMSType == ConfigurationManagementService.VSTS ? @event.CMSAccountName : _fakeAccountOptions.Value.AccountId;
            @event.CMSAccessSecret = @event.CMSType == ConfigurationManagementService.VSTS ? @event.CMSAccessSecret : _fakeAccountOptions.Value.AccessSecret;

            string cmsProjectId = @event.CMSType == ConfigurationManagementService.VSTS ? @event.ProjectExternalId : @event.ProjectVSTSFakeId;
            //End: check data **********

            string accountUrl = $"https://{@event.CMSAccountName}.visualstudio.com";

            HttpClientWrapperAuthorizationModel authCredentials = new HttpClientWrapperAuthorizationModel();

            authCredentials.Schema = "Basic";
            authCredentials.Value  = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", @event.CMSAccessSecret)));

            string projectUrl      = $"{accountUrl}/_apis/projects/{cmsProjectId}?api-version={_fakeAccountOptions.Value.ApiVersion}";
            var    projectResponse = await _httpClientWrapperService.DeleteAsync(projectUrl, authCredentials);

            projectResponse.EnsureSuccessStatusCode();

            // Delete from Bitbucket

            var client = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", @event.CMSAccountId, @event.CMSAccessToken))));
            client.BaseAddress = new Uri(API_URL);

            var response = await client.GetAsync($"/{API_VERSION}/teams?role=admin");

            var teamResult = await response.MapTo <CMSBitBucketTeamListModel>();

            var defaultTeam = teamResult.Teams.FirstOrDefault(c => c.TeamId.Equals(@event.OrganizationExternalId));

            response = await client.DeleteAsync($"/{API_VERSION}/teams/{defaultTeam.UserName}/projects/{@event.ProjectExternalId}");

            response.EnsureSuccessStatusCode();
        }