public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems) { AmazonECRPublicConfig config = new AmazonECRPublicConfig(); config.RegionEndpoint = region; ConfigureClient(config); AmazonECRPublicClient client = new AmazonECRPublicClient(creds, config); DescribeRepositoriesResponse resp = new DescribeRepositoriesResponse(); do { DescribeRepositoriesRequest req = new DescribeRepositoriesRequest { NextToken = resp.NextToken , MaxResults = maxItems }; resp = client.DescribeRepositories(req); CheckError(resp.HttpStatusCode, "200"); foreach (var obj in resp.Repositories) { AddObject(obj); } }while (!string.IsNullOrEmpty(resp.NextToken)); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { DescribeRepositoriesResponse response = new DescribeRepositoriesResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("nextToken", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.NextToken = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("repositories", targetDepth)) { var unmarshaller = new ListUnmarshaller <Repository, RepositoryUnmarshaller>(RepositoryUnmarshaller.Instance); response.Repositories = unmarshaller.Unmarshall(context); continue; } } return(response); }
public static async Task <string> ExpandImageTagIfNecessary(IToolLogger logger, IAmazonECR ecrClient, string dockerImageTag) { try { if (dockerImageTag.Contains(".amazonaws.")) { return(dockerImageTag); } string repositoryName = dockerImageTag; if (repositoryName.Contains(":")) { repositoryName = repositoryName.Substring(0, repositoryName.IndexOf(':')); } DescribeRepositoriesResponse describeResponse = null; try { describeResponse = await ecrClient.DescribeRepositoriesAsync(new DescribeRepositoriesRequest { RepositoryNames = new List <string> { repositoryName } }); } catch (Exception e) { if (!(e is RepositoryNotFoundException)) { throw; } } // Not found in ECR, assume pulling Docker Hub if (describeResponse == null) { return(dockerImageTag); } var fullPath = describeResponse.Repositories[0].RepositoryUri + dockerImageTag.Substring(dockerImageTag.IndexOf(':')); logger?.WriteLine($"Determined full image name to be {fullPath}"); return(fullPath); } catch (DockerToolsException) { throw; } catch (Exception e) { throw new DockerToolsException($"Error determining full repository path for the image {dockerImageTag}: {e.Message}", DockerToolsException.ECSErrorCode.FailedToExpandImageTag); } }
private async Task <Repository> SetupECRRepository(string ecrRepositoryName) { try { DescribeRepositoriesResponse describeResponse = null; try { describeResponse = await this.ECRClient.DescribeRepositoriesAsync(new DescribeRepositoriesRequest { RepositoryNames = new List <string> { ecrRepositoryName } }); } catch (Exception e) { if (!(e is RepositoryNotFoundException)) { throw; } } Repository repository; if (describeResponse != null && describeResponse.Repositories.Count == 1) { this.Logger?.WriteLine($"Found existing ECR Repository {ecrRepositoryName}"); repository = describeResponse.Repositories[0]; } else { this.Logger?.WriteLine($"Creating ECR Repository {ecrRepositoryName}"); repository = (await this.ECRClient.CreateRepositoryAsync(new CreateRepositoryRequest { RepositoryName = ecrRepositoryName })).Repository; } return(repository); } catch (Exception e) { throw new ToolsException($"Error determining Amazon ECR repository: {e.Message}", ToolsException.CommonErrorCode.FailedToSetupECRRepository); } }