public async Task <List <Dictionary <string, Template> > > GetTemplateCollectionAsync(string schemaImageReference, CancellationToken cancellationToken) { ImageInfo imageInfo = ImageInfo.CreateFromImageReference(schemaImageReference); var accessToken = await _containerRegistryTokenProvider.GetTokenAsync(imageInfo.Registry, cancellationToken); try { var provider = _templateCollectionProviderFactory.CreateTemplateCollectionProvider(schemaImageReference, accessToken); return(await provider.GetTemplateCollectionAsync(cancellationToken)); } catch (ContainerRegistryAuthenticationException authEx) { _logger.LogError(authEx, "Failed to access container registry."); throw new ContainerRegistrySchemaException("Failed to access container registry.", authEx); } catch (ImageFetchException fetchEx) { _logger.LogError(fetchEx, "Failed to fetch template image."); throw new ContainerRegistrySchemaException("Failed to fetch template image.", fetchEx); } catch (TemplateManagementException templateEx) { _logger.LogError(templateEx, "Template collection is invalid."); throw new ContainerRegistrySchemaException("Template collection is invalid.", templateEx); } catch (Exception unhandledEx) { _logger.LogError(unhandledEx, "Unhandled exception: failed to get template collection."); throw new ContainerRegistrySchemaException("Unhandled exception: failed to get template collection.", unhandledEx); } }
public async Task GivenTemplateReference_WhenFetchingTemplates_CorrectTemplateCollectionsShouldBeReturned() { Skip.If(_testContainerRegistryServer == null); ImageInfo imageInfo = ImageInfo.CreateFromImageReference(_testImageReference); await ContainerRegistryTestUtils.GenerateTemplateImageAsync(imageInfo, _testContainerRegistryAccessToken, TestConstants.TestTemplateTarGzPath); var containerRegistryTemplateProvider = GetTestTemplateProvider(_testContainerRegistryAccessToken); var templateCollection = await containerRegistryTemplateProvider.GetTemplateCollectionAsync(_testImageReference, CancellationToken.None); Assert.NotEmpty(templateCollection); }
private void CheckIfCustomTemplateIsConfigured(string registryServer, string templateCollectionReference) { // For compatibility purpose. // Return if registryServer has been configured in previous ConvertDataConfiguration. if (_config.ContainerRegistryServers.Any(server => string.Equals(server, registryServer, StringComparison.OrdinalIgnoreCase))) { return; } var ociImage = ImageInfo.CreateFromImageReference(templateCollectionReference); if (!_artifactStoreConfig.OciArtifacts.Any(ociArtifact => ociArtifact.ContainsOciImage(ociImage.Registry, ociImage.ImageName, ociImage.Digest))) { _logger.LogInformation("The requested template image is not configured."); throw new ContainerRegistryNotConfiguredException(string.Format(Resources.ConvertDataTemplateNotConfigured, templateCollectionReference)); } }