public async Task ImportImageAsync(string registry, string repository, List <string> tags) { var credential = new AzureCredentials( new ServicePrincipalLoginInformation { ClientId = TestEnvironment.ClientId, ClientSecret = TestEnvironment.ClientSecret, }, TestEnvironment.TenantId, AzureEnvironment.AzureGlobalCloud); var managementClient = new ContainerRegistryManagementClient(credential.WithDefaultSubscription(TestEnvironment.SubscriptionId)); managementClient.SubscriptionId = TestEnvironment.SubscriptionId; var importSource = new ImportSource { SourceImage = repository, RegistryUri = "registry.hub.docker.com" }; var targetTags = tags.Select(tag => $"{repository}:{tag}"); await managementClient.Registries.ImportImageAsync( resourceGroupName : TestEnvironment.ResourceGroup, registryName : registry, parameters : new ImportImageParameters { Mode = ImportMode.Force, Source = importSource, TargetTags = targetTags.ToList() }); }
public async Task ImportImage(string tag) { var credential = new AzureCredentials( new ServicePrincipalLoginInformation { ClientId = TestEnvironment.ClientId, ClientSecret = TestEnvironment.ClientSecret, }, TestEnvironment.TenantId, AzureEnvironment.AzureGlobalCloud); var _registryClient = new ContainerRegistryManagementClient(credential.WithDefaultSubscription(TestEnvironment.SubscriptionId)); _registryClient.SubscriptionId = TestEnvironment.SubscriptionId; var importSource = new ImportSource { SourceImage = "library/hello-world", RegistryUri = "registry.hub.docker.com" }; await _registryClient.Registries.ImportImageAsync( resourceGroupName : TestEnvironment.ResourceGroup, registryName : TestEnvironment.Registry, parameters : new ImportImageParameters { Mode = ImportMode.Force, Source = importSource, TargetTags = new List <string>() { $"library/hello-world:{tag}" } }); }
public TransferClient( AzureEnvironmentConfiguration azureEnvironmentConfiguration, IdentityConfiguration identityConfiguration, RegistryConfiguration registryConfiguration) { _registryConfiguration = registryConfiguration ?? throw new ArgumentNullException(nameof(registryConfiguration)); var env = AzureEnvironment.FromName(azureEnvironmentConfiguration.Name); if (env == null) { env = new AzureEnvironment { Name = azureEnvironmentConfiguration.Name, AuthenticationEndpoint = azureEnvironmentConfiguration.AuthenticationEndpoint, ManagementEndpoint = azureEnvironmentConfiguration.ManagementEndpoint, ResourceManagerEndpoint = azureEnvironmentConfiguration.ResourceManagerEndpoint, GraphEndpoint = azureEnvironmentConfiguration.GraphEndpoint, KeyVaultSuffix = azureEnvironmentConfiguration.KeyVaultSuffix, StorageEndpointSuffix = azureEnvironmentConfiguration.StorageEndpointSuffix }; } var credential = new AzureCredentials( new ServicePrincipalLoginInformation { ClientId = identityConfiguration.ClientId, ClientSecret = identityConfiguration.ClientSecret }, registryConfiguration.TenantId, env); _registryClient = new ContainerRegistryManagementClient(credential.WithDefaultSubscription(registryConfiguration.SubscriptionId)); _registryClient.SubscriptionId = registryConfiguration.SubscriptionId; }
public void CanSetMultipleDelegateHandlers() { using (var context = FluentMockContext.Start(GetType().FullName)) { string rgName = TestUtilities.GenerateName("rg"); string stgName = TestUtilities.GenerateName("stg"); IAzure azure = null; // Sets the interceptor so that logging and user agent in log can be asserted. var logAndUserAgentInterceptor = new LogAndUserAgentInterceptor(); ServiceClientTracing.AddTracingInterceptor(logAndUserAgentInterceptor); ServiceClientTracing.IsEnabled = true; try { AzureCredentials credentials = SdkContext.AzureCredentialsFactory.FromFile(Environment.GetEnvironmentVariable("AZURE_AUTH_LOCATION")); credentials.WithDefaultSubscription(null); // Clearing subscriptionId loaded from the auth // file so that below WithDefaultSubscription() // will force listing subscriptions and fetching // the first. azure = Microsoft.Azure.Management.Fluent.Azure .Configure() .WithUserAgent("azure-fluent-test", "1.0.0-prelease") .WithLogLevel(HttpLoggingDelegatingHandler.Level.BodyAndHeaders) .WithDelegatingHandlers(TestHelper.GetHandlers()) .Authenticate(credentials) .WithDefaultSubscription(); IStorageAccount storageAccount = azure.StorageAccounts .Define(stgName) .WithRegion(Region.USEast) .WithNewResourceGroup(rgName) .Create(); Assert.Equal(storageAccount.ResourceGroupName, rgName); } finally { ServiceClientTracing.RemoveTracingInterceptor(logAndUserAgentInterceptor); ServiceClientTracing.IsEnabled = false; if (azure != null) { azure.ResourceGroups.DeleteByName(rgName); } } Assert.True(logAndUserAgentInterceptor.FoundUserAgentInLog); } }
public AzureUtility(AzureEnvironment environment, string tenantId, string subscriptionId, string miClientId, string spClientId, string spClientSecret) { if (string.IsNullOrWhiteSpace(tenantId)) { throw new ArgumentNullException(nameof(tenantId)); } if (string.IsNullOrWhiteSpace(subscriptionId)) { throw new ArgumentNullException(nameof(subscriptionId)); } if (!string.IsNullOrWhiteSpace(miClientId)) { credential = new AzureCredentials( new MSILoginInformation(MSIResourceType.VirtualMachine, miClientId), environment, tenantId); } else if (!string.IsNullOrWhiteSpace(spClientId) && !string.IsNullOrWhiteSpace(spClientSecret)) { credential = new AzureCredentials( new ServicePrincipalLoginInformation { ClientId = spClientId, ClientSecret = spClientSecret }, tenantId, environment); } else { throw new ArgumentNullException("No subscription credential"); } RegistryClient = new ContainerRegistryManagementClient(credential.WithDefaultSubscription(subscriptionId)); RegistryClient.SubscriptionId = subscriptionId; }