コード例 #1
0
        public async Task SetImagePropertiesAsync()
        {
            // Set up
            await ImportImageAsync(TestEnvironment.Registry, "library/hello-world", new List <string>() { "v1", "latest" });

            Environment.SetEnvironmentVariable("REGISTRY_ENDPOINT", TestEnvironment.Endpoint);

            #region Snippet:ContainerRegistry_Tests_Samples_SetArtifactPropertiesAsync
            // Get the service endpoint from the environment
            Uri endpoint = new Uri(Environment.GetEnvironmentVariable("REGISTRY_ENDPOINT"));

            // Create a new ContainerRegistryClient and RegistryArtifact to access image operations
            ContainerRegistryClient client = new ContainerRegistryClient(endpoint, new DefaultAzureCredential());
            RegistryArtifact        image  = client.GetArtifact("library/hello-world", "v1");

            // Set permissions on the image's "latest" tag
            await image.UpdateTagPropertiesAsync("latest", new ArtifactTagProperties()
            {
                CanWrite  = false,
                CanDelete = false
            });

            #endregion

            // Reset registry state
            await image.UpdateTagPropertiesAsync("latest", new ArtifactTagProperties()
            {
                CanRead   = true,
                CanList   = true,
                CanWrite  = true,
                CanDelete = true
            });
        }
コード例 #2
0
        public async Task AnonymouslyListTagsAsync()
        {
            Environment.SetEnvironmentVariable("REGISTRY_ENDPOINT", TestEnvironment.AnonymousAccessEndpoint);

            #region Snippet:ContainerRegistry_Tests_Samples_ListTagsAnonymousAsync
            // Get the service endpoint from the environment
            Uri endpoint = new Uri(Environment.GetEnvironmentVariable("REGISTRY_ENDPOINT"));

            // Create a new ContainerRegistryClient for anonymous access
            ContainerRegistryClient client = new ContainerRegistryClient(endpoint, new ContainerRegistryClientOptions()
            {
                Audience = ContainerRegistryAudience.AzureResourceManagerPublicCloud
            });

            // Obtain a RegistryArtifact object to get access to image operations
            RegistryArtifact image = client.GetArtifact("library/hello-world", "latest");

            // List the set of tags on the hello_world image tagged as "latest"
            AsyncPageable <ArtifactTagProperties> tags = image.GetAllTagPropertiesAsync();

            // Iterate through the image's tags, listing the tagged alias for the image
            Console.WriteLine($"{image.FullyQualifiedReference} has the following aliases:");
            await foreach (ArtifactTagProperties tag in tags)
            {
                Console.WriteLine($"    {image.RegistryEndpoint.Host}/{image.RepositoryName}:{tag}");
            }
            #endregion
        }
コード例 #3
0
 public void TestSetup()
 {
     client = InstrumentClient(new ContainerRegistryClient(_url, GetCredential(), new ContainerRegistryClientOptions()
     {
         Audience = ContainerRegistryAudience.AzureResourceManagerPublicCloud
     }));
     artifact = client.GetArtifact(_repositoryName, _artifactTag);
 }
コード例 #4
0
        public async Task DeleteImagesAsync()
        {
            Environment.SetEnvironmentVariable("REGISTRY_ENDPOINT", TestEnvironment.Endpoint);

            #region Snippet:ContainerRegistry_Tests_Samples_DeleteImageAsync
#if SNIPPET
            using System.Linq;
            using Azure.Containers.ContainerRegistry;
            using Azure.Identity;
#endif

            // Get the service endpoint from the environment
            Uri endpoint = new Uri(Environment.GetEnvironmentVariable("REGISTRY_ENDPOINT"));

            // Create a new ContainerRegistryClient
            ContainerRegistryClient client = new ContainerRegistryClient(endpoint, new DefaultAzureCredential(),
                                                                         new ContainerRegistryClientOptions()
            {
                Audience = ContainerRegistryAudience.AzureResourceManagerPublicCloud
            });

            // Iterate through repositories
            AsyncPageable <string> repositoryNames = client.GetRepositoryNamesAsync();
            await foreach (string repositoryName in repositoryNames)
            {
                ContainerRepository repository = client.GetRepository(repositoryName);

                // Obtain the images ordered from newest to oldest
                AsyncPageable <ArtifactManifestProperties> imageManifests =
                    repository.GetAllManifestPropertiesAsync(manifestOrder: ArtifactManifestOrder.LastUpdatedOnDescending);

                // Delete images older than the first three.
                await foreach (ArtifactManifestProperties imageManifest in imageManifests.Skip(3))
                {
                    RegistryArtifact image = repository.GetArtifact(imageManifest.Digest);
                    Console.WriteLine($"Deleting image with digest {imageManifest.Digest}.");
                    Console.WriteLine($"   Deleting the following tags from the image: ");
                    foreach (var tagName in imageManifest.Tags)
                    {
                        Console.WriteLine($"        {imageManifest.RepositoryName}:{tagName}");
                        await image.DeleteTagAsync(tagName);
                    }
                    await image.DeleteAsync();
                }
            }

            #endregion
        }
コード例 #5
0
        public void DeleteImages()
        {
            Environment.SetEnvironmentVariable("REGISTRY_ENDPOINT", TestEnvironment.Endpoint);

            #region Snippet:ContainerRegistry_Tests_Samples_DeleteImage
#if SNIPPET
            using Azure.Containers.ContainerRegistry;
            using Azure.Identity;
#endif

            // Get the service endpoint from the environment
            Uri endpoint = new Uri(Environment.GetEnvironmentVariable("REGISTRY_ENDPOINT"));

            // Create a new ContainerRegistryClient
            ContainerRegistryClient client = new ContainerRegistryClient(endpoint, new DefaultAzureCredential());

            // Iterate through repositories
            Pageable <string> repositoryNames = client.GetRepositoryNames();
            foreach (string repositoryName in repositoryNames)
            {
                ContainerRepository repository = client.GetRepository(repositoryName);

                // Obtain the images ordered from newest to oldest
                Pageable <ArtifactManifestProperties> imageManifests =
                    repository.GetManifestPropertiesCollection(orderBy: ArtifactManifestOrderBy.LastUpdatedOnDescending);

                // Delete images older than the first three.
                foreach (ArtifactManifestProperties imageManifest in imageManifests.Skip(3))
                {
                    RegistryArtifact image = repository.GetArtifact(imageManifest.Digest);
                    Console.WriteLine($"Deleting image with digest {imageManifest.Digest}.");
                    Console.WriteLine($"   Deleting the following tags from the image: ");
                    foreach (var tagName in imageManifest.Tags)
                    {
                        Console.WriteLine($"        {imageManifest.RepositoryName}:{tagName}");
                        image.DeleteTag(tagName);
                    }
                    image.Delete();
                }
            }
            #endregion
        }
コード例 #6
0
 public void TestSetup()
 {
     client   = InstrumentClient(new ContainerRegistryClient(_url, GetCredential(), new ContainerRegistryClientOptions()));
     artifact = client.GetArtifact(_repositoryName, _artifactTag);
 }