private async Task CreateRepoAsync()
        {
            var csrDatasource = CsrUtils.CreateCsrDataSource(_project.ProjectId);

            IsReady = false;
            try
            {
                var watch = Stopwatch.StartNew();
                // No null check. By the time user gets here, csrDatasource won't be null.
                Result = await csrDatasource.CreateRepoAsync(RepositoryName.Trim());

                EventsReporterWrapper.ReportEvent(
                    CsrCreatedEvent.Create(CommandStatus.Success, duration: watch.Elapsed));
                _owner.Close();
            }
            catch (Exception)
            {
                EventsReporterWrapper.ReportEvent(CsrCreatedEvent.Create(CommandStatus.Failure));
                throw;
            }
            finally
            {
                IsReady = true;
            }
        }
예제 #2
0
        public Task <RepositoryName> GetRepositoryNameFromLocalDirectoryPath(LocalRepositoryDirectoryPath localRepositoryDirectoryPath)
        {
            // Example: C:\Code\DEV\Git\GitHub\SafetyCone\R5T.Aalborg\
            var directoryPath = localRepositoryDirectoryPath.Value;

            var repositoryDirectoryName = this.StringlyTypedPathOperator.GetDirectoryNameForDirectoryPath(directoryPath);

            var organizationDirectoryPath = this.StringlyTypedPathOperator.GetParentDirectoryPathForDirectoryPath(directoryPath);

            var organizationDirectoryName = this.StringlyTypedPathOperator.GetDirectoryNameForDirectoryPath(organizationDirectoryPath);

            var remoteRepositoryProviderDirectoryPath = this.StringlyTypedPathOperator.GetParentDirectoryPathForDirectoryPath(organizationDirectoryPath);

            var remoteRepositoryProviderDirectoryName = this.StringlyTypedPathOperator.GetDirectoryNameForDirectoryPath(remoteRepositoryProviderDirectoryPath);

            // Convention is to directly use the directory names.
            var remoteRepositoryProviderNameToken = remoteRepositoryProviderDirectoryName;
            var organizationNameToken             = organizationDirectoryName;
            var repositoryNameToken = repositoryDirectoryName;

            var repositoryNameValue = $"{remoteRepositoryProviderNameToken}/{organizationNameToken}/{repositoryNameToken}";

            var repositoryName = RepositoryName.From(repositoryNameValue);

            return(Task.FromResult(repositoryName));
        }
        void ReleaseDesignerOutlets()
        {
            if (ContentConstraint != null)
            {
                ContentConstraint.Dispose();
                ContentConstraint = null;
            }

            if (RepositoryDescription != null)
            {
                RepositoryDescription.Dispose();
                RepositoryDescription = null;
            }

            if (RepositoryImage != null)
            {
                RepositoryImage.Dispose();
                RepositoryImage = null;
            }

            if (RepositoryName != null)
            {
                RepositoryName.Dispose();
                RepositoryName = null;
            }

            if (RepositoryOwner != null)
            {
                RepositoryOwner.Dispose();
                RepositoryOwner = null;
            }
        }
예제 #4
0
        public async stt::Task GetRepositoryRequestObjectAsync()
        {
            moq::Mock <ArtifactRegistry.ArtifactRegistryClient> mockGrpcClient = new moq::Mock <ArtifactRegistry.ArtifactRegistryClient>(moq::MockBehavior.Strict);
            GetRepositoryRequest request = new GetRepositoryRequest
            {
                RepositoryName = RepositoryName.FromProjectLocationRepository("[PROJECT]", "[LOCATION]", "[REPOSITORY]"),
            };
            Repository expectedResponse = new Repository
            {
                RepositoryName = RepositoryName.FromProjectLocationRepository("[PROJECT]", "[LOCATION]", "[REPOSITORY]"),
                Format         = Repository.Types.Format.Yum,
                Description    = "description2cf9da67",
                Labels         =
                {
                    {
                        "key8a0b6e3c",
                        "value60c16320"
                    },
                },
                CreateTime = new wkt::Timestamp(),
                UpdateTime = new wkt::Timestamp(),
                KmsKeyName = "kms_key_name06bd122b",
            };

            mockGrpcClient.Setup(x => x.GetRepositoryAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <Repository>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            ArtifactRegistryClient client = new ArtifactRegistryClientImpl(mockGrpcClient.Object, null);
            Repository             responseCallSettings = await client.GetRepositoryAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            Repository responseCancellationToken = await client.GetRepositoryAsync(request, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
        internal IEnumerable <ValidationResult> ValidateRepoName()
        {
            string name = RepositoryName?.Trim();

            // Note, we have only one text box input, no error when it's empty or null
            if (String.IsNullOrWhiteSpace(name))
            {
                yield break;
            }

            if (!s_repoNameRegex.IsMatch(name))
            {
                yield return(StringValidationResult.FromResource(nameof(Resources.CsrRepoNameRuleMessage)));
            }

            if (name[0] == RepoNameExcludingCharacter)
            {
                yield return(StringValidationResult.FromResource(
                                 nameof(Resources.CsrRepoNameFirstCharacterExtraRuleMessage)));
            }

            if (name.Length < 3 || name.Length > NameMaxLength)
            {
                yield return(StringValidationResult.FromResource(nameof(Resources.CsrRepoNameLengthLimitMessage)));
            }

            if (_repos.Any(x => String.Compare(x.GetRepoName(), name, ignoreCase: true) == 0))
            {
                yield return(StringValidationResult.FromResource(nameof(Resources.CsrRepoNameExistsMessage)));
            }
        }
예제 #6
0
        public void GetRepository()
        {
            moq::Mock <ArtifactRegistry.ArtifactRegistryClient> mockGrpcClient = new moq::Mock <ArtifactRegistry.ArtifactRegistryClient>(moq::MockBehavior.Strict);
            GetRepositoryRequest request = new GetRepositoryRequest
            {
                RepositoryName = RepositoryName.FromProjectLocationRepository("[PROJECT]", "[LOCATION]", "[REPOSITORY]"),
            };
            Repository expectedResponse = new Repository
            {
                RepositoryName = RepositoryName.FromProjectLocationRepository("[PROJECT]", "[LOCATION]", "[REPOSITORY]"),
                Format         = Repository.Types.Format.Yum,
                Description    = "description2cf9da67",
                Labels         =
                {
                    {
                        "key8a0b6e3c",
                        "value60c16320"
                    },
                },
                CreateTime = new wkt::Timestamp(),
                UpdateTime = new wkt::Timestamp(),
                KmsKeyName = "kms_key_name06bd122b",
            };

            mockGrpcClient.Setup(x => x.GetRepository(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            ArtifactRegistryClient client   = new ArtifactRegistryClientImpl(mockGrpcClient.Object, null);
            Repository             response = client.GetRepository(request.Name);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
예제 #7
0
 public bool Equals(VersionData versionData) =>
 RepositoryName.Equals(versionData.RepositoryName) &&
 BranchName.Equals(versionData.BranchName) &&
 ParentBranchName.Equals(versionData.BranchName) &&
 NewBranch.Equals(versionData.NewBranch) &&
 DeltaContent.Equals(versionData.DeltaContent) &&
 FileHierarchy.All(versionData.FileHierarchy.Contains) &&
 FileHierarchy.Count.Equals(versionData.FileHierarchy.Count) &&
 EventId.Equals(versionData.EventId);
 /// <summary>Snippet for GetRepository</summary>
 public void GetRepositoryResourceNames()
 {
     // Snippet: GetRepository(RepositoryName, CallSettings)
     // Create client
     ArtifactRegistryClient artifactRegistryClient = ArtifactRegistryClient.Create();
     // Initialize request argument(s)
     RepositoryName name = RepositoryName.FromProjectLocationRepository("[PROJECT]", "[LOCATION]", "[REPOSITORY]");
     // Make the request
     Repository response = artifactRegistryClient.GetRepository(name);
     // End snippet
 }
예제 #9
0
        protected override Task <RepositoryNameAndLocalDirectoryPathMapping> DeserializeTokens(string[] tokens)
        {
            var repositoryNameToken = tokens[0];
            var localRepositoryDirectoryPathToken = tokens[1];

            var repositoryName = RepositoryName.From(repositoryNameToken);
            var localRepositoryDirectoryPath = LocalRepositoryDirectoryPath.From(localRepositoryDirectoryPathToken);

            var mapping = new RepositoryNameAndLocalDirectoryPathMapping(repositoryName, localRepositoryDirectoryPath);

            return(Task.FromResult(mapping));
        }
예제 #10
0
        protected override Task <RepositoryNameAndRemoteUrlMapping> DeserializeTokens(string[] tokens)
        {
            var repositoryNameToken      = tokens[0];
            var remoteRepositoryUrlToken = tokens[1];

            var repositoryName      = RepositoryName.From(repositoryNameToken);
            var remoteRepositoryUrl = RemoteRepositoryUrl.From(remoteRepositoryUrlToken);

            var mapping = new RepositoryNameAndRemoteUrlMapping(repositoryName, remoteRepositoryUrl);

            return(Task.FromResult(mapping));
        }
        /// <summary>Snippet for GetRepositoryAsync</summary>
        public async Task GetRepositoryResourceNamesAsync()
        {
            // Snippet: GetRepositoryAsync(RepositoryName, CallSettings)
            // Additional: GetRepositoryAsync(RepositoryName, CancellationToken)
            // Create client
            ArtifactRegistryClient artifactRegistryClient = await ArtifactRegistryClient.CreateAsync();

            // Initialize request argument(s)
            RepositoryName name = RepositoryName.FromProjectLocationRepository("[PROJECT]", "[LOCATION]", "[REPOSITORY]");
            // Make the request
            Repository response = await artifactRegistryClient.GetRepositoryAsync(name);

            // End snippet
        }
 /// <summary>Snippet for GetRepository</summary>
 public void GetRepositoryRequestObject()
 {
     // Snippet: GetRepository(GetRepositoryRequest, CallSettings)
     // Create client
     ArtifactRegistryClient artifactRegistryClient = ArtifactRegistryClient.Create();
     // Initialize request argument(s)
     GetRepositoryRequest request = new GetRepositoryRequest
     {
         RepositoryName = RepositoryName.FromProjectLocationRepository("[PROJECT]", "[LOCATION]", "[REPOSITORY]"),
     };
     // Make the request
     Repository response = artifactRegistryClient.GetRepository(request);
     // End snippet
 }
        private void ExecuteImpl()
        {
            if (ProductDropName != "" && !ProductDropName.StartsWith(ProductDropNamePrefix, StringComparison.Ordinal))
            {
                Log.LogError($"Invalid value of vsDropName argument: must start with '{ProductDropNamePrefix}'.");
                return;
            }

            var dropName       = ProductDropName?.Substring(ProductDropNamePrefix.Length) ?? "dummy";
            var outputFilePath = Path.Combine(OutputDirectory, RepositoryName.Replace('/', '.') + ".props");

            Directory.CreateDirectory(OutputDirectory);
            File.WriteAllText(outputFilePath,
                              $@"<?xml version=""1.0""?>
<Project>
  <ItemGroup>
    <TestStore Include=""vstsdrop:ProfilingInputs/{dropName}"" />
  </ItemGroup>
</Project>", Encoding.UTF8);
        }
        public Task <RepositoryName> GetRepositoryNameFromRemoteUrl(RemoteRepositoryUrl remoteRepositoryUrl)
        {
            // Example: https://api.github.com/repos/SafetyCone/R5T.Aalborg
            var url = new Uri(remoteRepositoryUrl.Value);

            var hostTokens = url.Host.Split('.');

            var hostToken = hostTokens[1];

            var isGitHub = hostToken == "github";
            var remoteRepositoryProviderNameToken = isGitHub ? "GitHub" : throw new Exception($"Unrecognized host token: '{hostToken}'");

            var segments = url.Segments;
            var organizationNameToken = segments.SecondToLast().ExceptLast();
            var repositoryNameToken   = segments.Last();

            var repositoryNameValue = $"{remoteRepositoryProviderNameToken}/{organizationNameToken}/{repositoryNameToken}";

            var repositoryName = RepositoryName.From(repositoryNameValue);

            return(Task.FromResult(repositoryName));
        }
예제 #15
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (RegistryId.Length != 0)
            {
                hash ^= RegistryId.GetHashCode();
            }
            if (RepositoryName.Length != 0)
            {
                hash ^= RepositoryName.GetHashCode();
            }
            if (FolderId.Length != 0)
            {
                hash ^= FolderId.GetHashCode();
            }
            if (PageSize != 0L)
            {
                hash ^= PageSize.GetHashCode();
            }
            if (PageToken.Length != 0)
            {
                hash ^= PageToken.GetHashCode();
            }
            if (Filter.Length != 0)
            {
                hash ^= Filter.GetHashCode();
            }
            if (OrderBy.Length != 0)
            {
                hash ^= OrderBy.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
예제 #16
0
        public async stt::Task GetFunctionResourceNamesAsync()
        {
            moq::Mock <CloudFunctionsService.CloudFunctionsServiceClient> mockGrpcClient = new moq::Mock <CloudFunctionsService.CloudFunctionsServiceClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            GetFunctionRequest request = new GetFunctionRequest
            {
                CloudFunctionName = CloudFunctionName.FromProjectLocationFunction("[PROJECT]", "[LOCATION]", "[FUNCTION]"),
            };
            CloudFunction expectedResponse = new CloudFunction
            {
                CloudFunctionName   = CloudFunctionName.FromProjectLocationFunction("[PROJECT]", "[LOCATION]", "[FUNCTION]"),
                Description         = "description2cf9da67",
                SourceArchiveUrl    = "source_archive_url88af9b91",
                SourceRepository    = new SourceRepository(),
                HttpsTrigger        = new HttpsTrigger(),
                EventTrigger        = new EventTrigger(),
                Status              = CloudFunctionStatus.Offline,
                EntryPoint          = "entry_pointb3d450a5",
                Timeout             = new wkt::Duration(),
                AvailableMemoryMb   = 1905057947,
                ServiceAccountEmail = "service_account_emailb0c3703d",
                UpdateTime          = new wkt::Timestamp(),
                VersionId           = 8696643459580522033L,
                Labels              =
                {
                    {
                        "key8a0b6e3c",
                        "value60c16320"
                    },
                },
                SourceUploadUrl      = "source_upload_urle9bc6ad5",
                EnvironmentVariables =
                {
                    {
                        "key8a0b6e3c",
                        "value60c16320"
                    },
                },
                Network      = "networkd22ce091",
                Runtime      = "runtime2519a6b4",
                MaxInstances = -1449803711,
                VpcConnector = "vpc_connectordc82c0cc",
                VpcConnectorEgressSettings = CloudFunction.Types.VpcConnectorEgressSettings.AllTraffic,
                IngressSettings            = CloudFunction.Types.IngressSettings.AllowAll,
                KmsKeyNameAsCryptoKeyName  = CryptoKeyName.FromProjectLocationKeyRingCryptoKey("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]"),
                BuildWorkerPool            = "build_worker_pool4c1ad1a6",
                BuildId = "build_id2ab7699b",
                BuildEnvironmentVariables =
                {
                    {
                        "key8a0b6e3c",
                        "value60c16320"
                    },
                },
                SecretEnvironmentVariables = { new SecretEnvVar(), },
                SecretVolumes = { new SecretVolume(), },
                SourceToken   = "source_tokenecdd3693",
                MinInstances  = 445814344,
                BuildName     = "build_namead3cc4b7",
                DockerRepositoryAsRepositoryName = RepositoryName.FromProjectLocationRepository("[PROJECT]", "[LOCATION]", "[REPOSITORY]"),
            };

            mockGrpcClient.Setup(x => x.GetFunctionAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <CloudFunction>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            CloudFunctionsServiceClient client = new CloudFunctionsServiceClientImpl(mockGrpcClient.Object, null);
            CloudFunction responseCallSettings = await client.GetFunctionAsync(request.CloudFunctionName, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            CloudFunction responseCancellationToken = await client.GetFunctionAsync(request.CloudFunctionName, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
예제 #17
0
        private async Task <bool> ExecuteAsync()
        {
            try
            {
                if (CommitSha?.Length < ShaUsableLength)
                {
                    Log.LogError($"The CommitSHA should be at least {ShaUsableLength} characters long: CommitSha is '{CommitSha}'. Aborting feed creation.");
                    return(false);
                }

                JsonSerializerSettings _serializerSettings = new JsonSerializerSettings
                {
                    ContractResolver  = new CamelCasePropertyNamesContractResolver(),
                    NullValueHandling = NullValueHandling.Ignore
                };

                // GitHub repos may appear in the repository name with an 'org/repo' form.
                // When creating a repo, Github aslready replaces all of the characters invalid in AzDO feed names (see below)
                // with '-' in the repo name. We just need to replace '/' with '-' to deal with the org/repo input.
                // From the AzDO docs:
                // The feed name can't contain spaces, start with a '.' or '_', end with a '.',
                // or contain any of these: @ ~ ; { } ' + = , < > | / \ ? : & $ * " # [ ] %
                string feedCompatibleRepositoryName = RepositoryName?.Replace('/', '-');

                // For clarity, and compatibility with existing infrastructure, we include the feed visibility tag.
                // This serves two purposes:
                // 1. In nuget.config files (and elsewhere), the name at a glance can identify its visibility
                // 2. Existing automation has knowledge of "darc-int" and "darc-pub" for purposes of injecting authentication for internal builds
                //    and managing the isolated feeds within the NuGet.config files.
                string extraContentInfo  = !string.IsNullOrEmpty(ContentIdentifier) ? $"-{ContentIdentifier}" : "";
                string baseFeedName      = FeedName ?? $"darc-{GetFeedVisibilityTag(AzureDevOpsOrg, AzureDevOpsProject)}{extraContentInfo}-{feedCompatibleRepositoryName}-{CommitSha.Substring(0, ShaUsableLength)}";
                string versionedFeedName = baseFeedName;
                bool   needsUniqueName   = false;
                int    subVersion        = 0;

                Log.LogMessage(MessageImportance.High, $"Creating the new Azure DevOps artifacts feed '{baseFeedName}'...");

                if (baseFeedName.Length > MaxLengthForAzDoFeedNames)
                {
                    Log.LogError($"The name of the new feed ({baseFeedName}) exceeds the maximum feed name size of 64 chars. Aborting feed creation.");
                    return(false);
                }

                string azureDevOpsFeedsBaseUrl = $"https://feeds.dev.azure.com/{AzureDevOpsOrg}/";
                do
                {
                    using (HttpClient client = new HttpClient(new HttpClientHandler {
                        CheckCertificateRevocationList = true
                    })
                    {
                        BaseAddress = new Uri(azureDevOpsFeedsBaseUrl)
                    })
                    {
                        client.DefaultRequestHeaders.Add(
                            "Accept",
                            $"application/json;api-version={AzureDevOpsFeedsApiVersion}");
                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
                            "Basic",
                            Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("{0}:{1}", "", AzureDevOpsPersonalAccessToken))));

                        AzureDevOpsArtifactFeed newFeed = new AzureDevOpsArtifactFeed(versionedFeedName, AzureDevOpsOrg, AzureDevOpsProject);

                        string createBody = JsonConvert.SerializeObject(newFeed, _serializerSettings);

                        using HttpRequestMessage createFeedMessage = new HttpRequestMessage(HttpMethod.Post, $"{AzureDevOpsProject}/_apis/packaging/feeds");
                        createFeedMessage.Content = new StringContent(createBody, Encoding.UTF8, "application/json");
                        using HttpResponseMessage createFeedResponse = await client.SendAsync(createFeedMessage);

                        if (createFeedResponse.StatusCode == HttpStatusCode.Created)
                        {
                            needsUniqueName = false;
                            baseFeedName    = versionedFeedName;

                            /// This is where we would potentially update the Local feed view with permissions to the organization's
                            /// valid users. But, see <seealso cref="AzureDevOpsArtifactFeed"/> for more info on why this is not
                            /// done this way.
                        }
                        else if (createFeedResponse.StatusCode == HttpStatusCode.Conflict)
                        {
                            versionedFeedName = $"{baseFeedName}-{++subVersion}";
                            needsUniqueName   = true;

                            if (versionedFeedName.Length > MaxLengthForAzDoFeedNames)
                            {
                                Log.LogError($"The name of the new feed ({baseFeedName}) exceeds the maximum feed name size of 64 chars. Aborting feed creation.");
                                return(false);
                            }
                        }
                        else
                        {
                            throw new Exception($"Feed '{baseFeedName}' was not created. Request failed with status code {createFeedResponse.StatusCode}. Exception: {await createFeedResponse.Content.ReadAsStringAsync()}");
                        }
                    }
                } while (needsUniqueName);

                TargetFeedURL  = $"https://pkgs.dev.azure.com/{AzureDevOpsOrg}/{AzureDevOpsProject}/_packaging/{baseFeedName}/nuget/v3/index.json";
                TargetFeedName = baseFeedName;

                Log.LogMessage(MessageImportance.High, $"Feed '{TargetFeedURL}' created successfully!");
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e, true);
            }

            return(!Log.HasLoggedErrors);
        }
예제 #18
0
 public bool Equals(PermissionLookup other) =>
 Message.Equals(other.Message) &&
 RequestingUser.Equals(other.RequestingUser) &&
 RepositoryName.Equals(other.RepositoryName) &&
 RequestId.Equals(other.RequestId);
예제 #19
0
        private async Task <bool> ExecuteAsync()
        {
            try
            {
                if (CommitSha.Length < ShaUsableLength)
                {
                    Log.LogError($"The CommitSHA should be at least {ShaUsableLength} characters long: CommitSha is '{CommitSha}'. Aborting feed creation.");
                    return(false);
                }

                JsonSerializerSettings _serializerSettings = new JsonSerializerSettings
                {
                    ContractResolver  = new CamelCasePropertyNamesContractResolver(),
                    NullValueHandling = NullValueHandling.Ignore
                };

                // GitHub repos may appear in the repository name with an 'org/repo' form.
                // When creating a repo, Github aslready replaces all of the characters invalid in AzDO feed names (see below)
                // with '-' in the repo name. We just need to replace '/' with '-' to deal with the org/repo input.
                // From the AzDO docs:
                // The feed name can't contain spaces, start with a '.' or '_', end with a '.',
                // or contain any of these: @ ~ ; { } ' + = , < > | / \ ? : & $ * " # [ ] %
                string feedCompatibleRepositoryName = RepositoryName.Replace('/', '-');

                string accessType        = IsInternal ? "internal" : "public";
                string publicSegment     = IsInternal ? string.Empty : "public/";
                string accessId          = IsInternal ? "int" : "pub";
                string extraContentInfo  = !string.IsNullOrEmpty(ContentIdentifier) ? $"-{ContentIdentifier}" : "";
                string baseFeedName      = $"darc-{accessId}{extraContentInfo}-{feedCompatibleRepositoryName}-{CommitSha.Substring(0, ShaUsableLength)}";
                string versionedFeedName = baseFeedName;
                bool   needsUniqueName   = false;
                int    subVersion        = 0;

                Log.LogMessage(MessageImportance.High, $"Creating the new {accessType} Azure DevOps artifacts feed '{baseFeedName}'...");

                if (baseFeedName.Length > MaxLengthForAzDoFeedNames)
                {
                    Log.LogError($"The name of the new feed ({baseFeedName}) exceeds the maximum feed name size of 64 chars. Aborting feed creation.");
                    return(false);
                }

                do
                {
                    using (HttpClient client = new HttpClient(new HttpClientHandler {
                        CheckCertificateRevocationList = true
                    })
                    {
                        BaseAddress = new Uri(AzureDevOpsFeedsBaseUrl)
                    })
                    {
                        client.DefaultRequestHeaders.Add(
                            "Accept",
                            $"application/json;api-version={AzureDevOpsFeedsApiVersion}");
                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
                            "Basic",
                            Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("{0}:{1}", "", AzureDevOpsPersonalAccessToken))));

                        AzureDevOpsArtifactFeed newFeed = new AzureDevOpsArtifactFeed(versionedFeedName);

                        string body = JsonConvert.SerializeObject(newFeed, _serializerSettings);

                        HttpRequestMessage postMessage = new HttpRequestMessage(HttpMethod.Post, $"{publicSegment}_apis/packaging/feeds");
                        postMessage.Content = new StringContent(body, Encoding.UTF8, "application/json");

                        HttpResponseMessage response = await client.SendAsync(postMessage);

                        if (response.StatusCode == HttpStatusCode.Created)
                        {
                            needsUniqueName = false;
                            baseFeedName    = versionedFeedName;
                        }
                        else if (response.StatusCode == HttpStatusCode.Conflict)
                        {
                            versionedFeedName = $"{baseFeedName}-{++subVersion}";
                            needsUniqueName   = true;

                            if (versionedFeedName.Length > MaxLengthForAzDoFeedNames)
                            {
                                Log.LogError($"The name of the new feed ({baseFeedName}) exceeds the maximum feed name size of 64 chars. Aborting feed creation.");
                                return(false);
                            }
                        }
                        else
                        {
                            throw new Exception($"Feed '{baseFeedName}' was not created. Request failed with status code {response.StatusCode}. Exception: {await response.Content.ReadAsStringAsync()}");
                        }
                    }
                } while (needsUniqueName);

                TargetFeedURL  = $"https://pkgs.dev.azure.com/{AzureDevOpsOrg}/{publicSegment}_packaging/{baseFeedName}/nuget/v3/index.json";
                TargetFeedName = baseFeedName;

                Log.LogMessage(MessageImportance.High, $"Feed '{TargetFeedURL}' created successfully!");
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e, true);
            }

            return(!Log.HasLoggedErrors);
        }
예제 #20
0
 public SnapshotHeader AsHeader() => new SnapshotHeader(Id,
                                                        RepositoryName.Match(x => x, string.Empty),
                                                        AtHash.Match(x => x, string.Empty),
                                                        CommitCreationDate.Match(x => x, null));