private PSRepositoryInfo AddToRepositoryStoreHelper(string repoName, Uri repoUri, int repoPriority, bool repoTrusted, PSCredentialInfo repoCredentialInfo) { // remove trailing and leading whitespaces, and if Name is just whitespace Name should become null now and be caught by following condition repoName = repoName.Trim(' '); if (String.IsNullOrEmpty(repoName) || repoName.Contains("*")) { throw new ArgumentException("Name cannot be null/empty, contain asterisk or be just whitespace"); } if (repoUri == null || !(repoUri.Scheme == System.Uri.UriSchemeHttp || repoUri.Scheme == System.Uri.UriSchemeHttps || repoUri.Scheme == System.Uri.UriSchemeFtp || repoUri.Scheme == System.Uri.UriSchemeFile)) { throw new ArgumentException("Invalid Uri, must be one of the following Uri schemes: HTTPS, HTTP, FTP, File Based"); } if (repoCredentialInfo != null) { bool isSecretManagementModuleAvailable = Utils.IsSecretManagementModuleAvailable(repoName, this); if (repoCredentialInfo.Credential != null) { if (!isSecretManagementModuleAvailable) { ThrowTerminatingError(new ErrorRecord( new PSInvalidOperationException($"Microsoft.PowerShell.SecretManagement module is not found, but is required for saving PSResourceRepository {repoName}'s Credential in a vault."), "RepositoryCredentialSecretManagementUnavailableModule", ErrorCategory.ResourceUnavailable, this)); } else { Utils.SaveRepositoryCredentialToSecretManagementVault(repoName, repoCredentialInfo, this); } } if (!isSecretManagementModuleAvailable) { WriteWarning($"Microsoft.PowerShell.SecretManagement module cannot be found. Make sure it is installed before performing PSResource operations in order to successfully authenticate to PSResourceRepository \"{repoName}\" with its CredentialInfo."); } } WriteVerbose("All required values to add to repository provided, calling internal Add() API now"); if (!ShouldProcess(repoName, "Register repository to repository store")) { return(null); } return(RepositorySettings.Add(repoName, repoUri, repoPriority, repoTrusted, repoCredentialInfo)); }
private PSRepositoryInfo AddToRepositoryStoreHelper(string repoName, Uri repoUrl, int repoPriority, bool repoTrusted) { // remove trailing and leading whitespaces, and if Name is just whitespace Name should become null now and be caught by following condition repoName = repoName.Trim(' '); if (String.IsNullOrEmpty(repoName) || repoName.Contains("*")) { throw new ArgumentException("Name cannot be null/empty, contain asterisk or be just whitespace"); } if (repoUrl == null || !(repoUrl.Scheme == Uri.UriSchemeHttp || repoUrl.Scheme == Uri.UriSchemeHttps || repoUrl.Scheme == Uri.UriSchemeFtp || repoUrl.Scheme == Uri.UriSchemeFile)) { throw new ArgumentException("Invalid url, must be one of the following Uri schemes: HTTPS, HTTP, FTP, File Based"); } WriteVerbose("All required values to add to repository provided, calling internal Add() API now"); if (!ShouldProcess(repoName, "Register repository to repository store")) { return(null); } return(RepositorySettings.Add(repoName, repoUrl, repoPriority, repoTrusted)); }