private async Task ImportImageAsync(string destTagName, string registryName) { AzureCredentials credentials = SdkContext.AzureCredentialsFactory .FromServicePrincipal(Options.Username, Options.Password, Options.Tenant, AzureEnvironment.AzureGlobalCloud); IAzure azure = this.azureManagementFactory.CreateAzureManager(credentials, Options.Subscription); string sourceTagName = destTagName.Replace(Options.RepoPrefix, Options.SourceRepoPrefix); ImportImageParametersInner importParams = new ImportImageParametersInner() { Mode = "Force", Source = new ImportSource( sourceTagName, $"/subscriptions/{Options.Subscription}/resourceGroups/{Options.ResourceGroup}/providers" + $"/Microsoft.ContainerRegistry/registries/{registryName}"), TargetTags = new string[] { destTagName } }; Logger.WriteMessage($"Importing '{destTagName}' from '{sourceTagName}'"); if (!Options.IsDryRun) { try { await azure.ContainerRegistries.Inner.ImportImageAsync(Options.ResourceGroup, registryName, importParams); } catch (Exception e) { Logger.WriteMessage($"Importing Failure: {destTagName}{Environment.NewLine}{e}"); throw; } } }
protected async Task ImportImageAsync(string destTagName, string destRegistryName, string srcTagName, string?srcRegistryName = null, string?srcResourceId = null, ImportSourceCredentials?sourceCredentials = null) { AzureCredentials credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal( Options.ServicePrincipal.ClientId, Options.ServicePrincipal.Secret, Options.ServicePrincipal.Tenant, AzureEnvironment.AzureGlobalCloud); IAzure azure = AzureManagementFactory.CreateAzureManager(credentials, Options.Subscription); ImportImageParametersInner importParams = new ImportImageParametersInner() { Mode = "Force", Source = new ImportSource( srcTagName, srcResourceId, srcRegistryName, sourceCredentials), TargetTags = new string[] { destTagName } }; LoggerService.WriteMessage($"Importing '{destTagName}' from '{srcTagName}'"); if (!Options.IsDryRun) { try { await RetryHelper.GetWaitAndRetryPolicy <Exception>(LoggerService) .ExecuteAsync(() => azure.ContainerRegistries.Inner.ImportImageAsync(Options.ResourceGroup, destRegistryName, importParams)); } catch (Exception e) { string errorMsg = $"Importing Failure: {destTagName}"; if (e is CloudException cloudException) { errorMsg += Environment.NewLine + cloudException.Body.Message; } errorMsg += Environment.NewLine + e.ToString(); LoggerService.WriteMessage(errorMsg); throw; } } }
protected async Task ImportImageAsync(string destTagName, string srcTagName, string srcRegistryName = null, string srcResourceId = null) { AzureCredentials credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal( Options.ServicePrincipal.ClientId, Options.ServicePrincipal.Secret, Options.ServicePrincipal.Tenant, AzureEnvironment.AzureGlobalCloud); IAzure azure = AzureManagementFactory.CreateAzureManager(credentials, Options.Subscription); ImportImageParametersInner importParams = new ImportImageParametersInner() { Mode = "Force", Source = new ImportSource( srcTagName, srcResourceId, srcRegistryName), TargetTags = new string[] { destTagName } }; LoggerService.WriteMessage($"Importing '{destTagName}' from '{srcTagName}'"); if (!Options.IsDryRun) { try { AsyncPolicy <HttpResponseMessage> policy = HttpPolicyBuilder.Create() .WithMeteredRetryPolicy(LoggerService) .Build(); await policy.ExecuteAsync(async() => { await azure.ContainerRegistries.Inner.ImportImageAsync(Options.ResourceGroup, RegistryName, importParams); return(null); }); } catch (Exception e) { LoggerService.WriteMessage($"Importing Failure: {destTagName}{Environment.NewLine}{e}"); throw; } } }
/// <summary> /// Copies an image to this container registry from the specified container /// registry. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group to which the container registry belongs. /// </param> /// <param name='registryName'> /// The name of the container registry. /// </param> /// <param name='parameters'> /// The parameters specifying the image to copy and the source container /// registry. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async System.Threading.Tasks.Task ImportImageAsync(this IRegistriesOperations operations, string resourceGroupName, string registryName, ImportImageParametersInner parameters, CancellationToken cancellationToken = default(CancellationToken)) { (await operations.ImportImageWithHttpMessagesAsync(resourceGroupName, registryName, parameters, null, cancellationToken).ConfigureAwait(false)).Dispose(); }
private static bool VerifyImportImageParameters(ImportImageParametersInner parameters, IList <string> expectedTags) { return(TestHelper.CompareLists(expectedTags, parameters.TargetTags)); }