...

Source file src/github.com/aws/aws-sdk-go-v2/service/ecr/api_op_ListImages.go

Documentation: github.com/aws/aws-sdk-go-v2/service/ecr

     1  // Code generated by smithy-go-codegen DO NOT EDIT.
     2  
     3  package ecr
     4  
     5  import (
     6  	"context"
     7  	"errors"
     8  	"fmt"
     9  	"github.com/aws/aws-sdk-go-v2/aws"
    10  	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
    11  	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
    12  	internalauth "github.com/aws/aws-sdk-go-v2/internal/auth"
    13  	"github.com/aws/aws-sdk-go-v2/service/ecr/types"
    14  	smithyendpoints "github.com/aws/smithy-go/endpoints"
    15  	"github.com/aws/smithy-go/middleware"
    16  	smithyhttp "github.com/aws/smithy-go/transport/http"
    17  )
    18  
    19  // Lists all the image IDs for the specified repository. You can filter images
    20  // based on whether or not they are tagged by using the tagStatus filter and
    21  // specifying either TAGGED , UNTAGGED or ANY . For example, you can filter your
    22  // results to return only UNTAGGED images and then pipe that result to a
    23  // BatchDeleteImage operation to delete them. Or, you can filter your results to
    24  // return only TAGGED images to list all of the tags in your repository.
    25  func (c *Client) ListImages(ctx context.Context, params *ListImagesInput, optFns ...func(*Options)) (*ListImagesOutput, error) {
    26  	if params == nil {
    27  		params = &ListImagesInput{}
    28  	}
    29  
    30  	result, metadata, err := c.invokeOperation(ctx, "ListImages", params, optFns, c.addOperationListImagesMiddlewares)
    31  	if err != nil {
    32  		return nil, err
    33  	}
    34  
    35  	out := result.(*ListImagesOutput)
    36  	out.ResultMetadata = metadata
    37  	return out, nil
    38  }
    39  
    40  type ListImagesInput struct {
    41  
    42  	// The repository with image IDs to be listed.
    43  	//
    44  	// This member is required.
    45  	RepositoryName *string
    46  
    47  	// The filter key and value with which to filter your ListImages results.
    48  	Filter *types.ListImagesFilter
    49  
    50  	// The maximum number of image results returned by ListImages in paginated output.
    51  	// When this parameter is used, ListImages only returns maxResults results in a
    52  	// single page along with a nextToken response element. The remaining results of
    53  	// the initial request can be seen by sending another ListImages request with the
    54  	// returned nextToken value. This value can be between 1 and 1000. If this
    55  	// parameter is not used, then ListImages returns up to 100 results and a nextToken
    56  	// value, if applicable.
    57  	MaxResults *int32
    58  
    59  	// The nextToken value returned from a previous paginated ListImages request where
    60  	// maxResults was used and the results exceeded the value of that parameter.
    61  	// Pagination continues from the end of the previous results that returned the
    62  	// nextToken value. This value is null when there are no more results to return.
    63  	// This token should be treated as an opaque identifier that is only used to
    64  	// retrieve the next items in a list and not for other programmatic purposes.
    65  	NextToken *string
    66  
    67  	// The Amazon Web Services account ID associated with the registry that contains
    68  	// the repository in which to list images. If you do not specify a registry, the
    69  	// default registry is assumed.
    70  	RegistryId *string
    71  
    72  	noSmithyDocumentSerde
    73  }
    74  
    75  type ListImagesOutput struct {
    76  
    77  	// The list of image IDs for the requested repository.
    78  	ImageIds []types.ImageIdentifier
    79  
    80  	// The nextToken value to include in a future ListImages request. When the results
    81  	// of a ListImages request exceed maxResults , this value can be used to retrieve
    82  	// the next page of results. This value is null when there are no more results to
    83  	// return.
    84  	NextToken *string
    85  
    86  	// Metadata pertaining to the operation's result.
    87  	ResultMetadata middleware.Metadata
    88  
    89  	noSmithyDocumentSerde
    90  }
    91  
    92  func (c *Client) addOperationListImagesMiddlewares(stack *middleware.Stack, options Options) (err error) {
    93  	err = stack.Serialize.Add(&awsAwsjson11_serializeOpListImages{}, middleware.After)
    94  	if err != nil {
    95  		return err
    96  	}
    97  	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListImages{}, middleware.After)
    98  	if err != nil {
    99  		return err
   100  	}
   101  	if err = addlegacyEndpointContextSetter(stack, options); err != nil {
   102  		return err
   103  	}
   104  	if err = addSetLoggerMiddleware(stack, options); err != nil {
   105  		return err
   106  	}
   107  	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
   108  		return err
   109  	}
   110  	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
   111  		return err
   112  	}
   113  	if err = addResolveEndpointMiddleware(stack, options); err != nil {
   114  		return err
   115  	}
   116  	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
   117  		return err
   118  	}
   119  	if err = addRetryMiddlewares(stack, options); err != nil {
   120  		return err
   121  	}
   122  	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
   123  		return err
   124  	}
   125  	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
   126  		return err
   127  	}
   128  	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
   129  		return err
   130  	}
   131  	if err = addClientUserAgent(stack, options); err != nil {
   132  		return err
   133  	}
   134  	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
   135  		return err
   136  	}
   137  	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
   138  		return err
   139  	}
   140  	if err = addListImagesResolveEndpointMiddleware(stack, options); err != nil {
   141  		return err
   142  	}
   143  	if err = addOpListImagesValidationMiddleware(stack); err != nil {
   144  		return err
   145  	}
   146  	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListImages(options.Region), middleware.Before); err != nil {
   147  		return err
   148  	}
   149  	if err = awsmiddleware.AddRecursionDetection(stack); err != nil {
   150  		return err
   151  	}
   152  	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
   153  		return err
   154  	}
   155  	if err = addResponseErrorMiddleware(stack); err != nil {
   156  		return err
   157  	}
   158  	if err = addRequestResponseLogging(stack, options); err != nil {
   159  		return err
   160  	}
   161  	if err = addendpointDisableHTTPSMiddleware(stack, options); err != nil {
   162  		return err
   163  	}
   164  	return nil
   165  }
   166  
   167  // ListImagesAPIClient is a client that implements the ListImages operation.
   168  type ListImagesAPIClient interface {
   169  	ListImages(context.Context, *ListImagesInput, ...func(*Options)) (*ListImagesOutput, error)
   170  }
   171  
   172  var _ ListImagesAPIClient = (*Client)(nil)
   173  
   174  // ListImagesPaginatorOptions is the paginator options for ListImages
   175  type ListImagesPaginatorOptions struct {
   176  	// The maximum number of image results returned by ListImages in paginated output.
   177  	// When this parameter is used, ListImages only returns maxResults results in a
   178  	// single page along with a nextToken response element. The remaining results of
   179  	// the initial request can be seen by sending another ListImages request with the
   180  	// returned nextToken value. This value can be between 1 and 1000. If this
   181  	// parameter is not used, then ListImages returns up to 100 results and a nextToken
   182  	// value, if applicable.
   183  	Limit int32
   184  
   185  	// Set to true if pagination should stop if the service returns a pagination token
   186  	// that matches the most recent token provided to the service.
   187  	StopOnDuplicateToken bool
   188  }
   189  
   190  // ListImagesPaginator is a paginator for ListImages
   191  type ListImagesPaginator struct {
   192  	options   ListImagesPaginatorOptions
   193  	client    ListImagesAPIClient
   194  	params    *ListImagesInput
   195  	nextToken *string
   196  	firstPage bool
   197  }
   198  
   199  // NewListImagesPaginator returns a new ListImagesPaginator
   200  func NewListImagesPaginator(client ListImagesAPIClient, params *ListImagesInput, optFns ...func(*ListImagesPaginatorOptions)) *ListImagesPaginator {
   201  	if params == nil {
   202  		params = &ListImagesInput{}
   203  	}
   204  
   205  	options := ListImagesPaginatorOptions{}
   206  	if params.MaxResults != nil {
   207  		options.Limit = *params.MaxResults
   208  	}
   209  
   210  	for _, fn := range optFns {
   211  		fn(&options)
   212  	}
   213  
   214  	return &ListImagesPaginator{
   215  		options:   options,
   216  		client:    client,
   217  		params:    params,
   218  		firstPage: true,
   219  		nextToken: params.NextToken,
   220  	}
   221  }
   222  
   223  // HasMorePages returns a boolean indicating whether more pages are available
   224  func (p *ListImagesPaginator) HasMorePages() bool {
   225  	return p.firstPage || (p.nextToken != nil && len(*p.nextToken) != 0)
   226  }
   227  
   228  // NextPage retrieves the next ListImages page.
   229  func (p *ListImagesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListImagesOutput, error) {
   230  	if !p.HasMorePages() {
   231  		return nil, fmt.Errorf("no more pages available")
   232  	}
   233  
   234  	params := *p.params
   235  	params.NextToken = p.nextToken
   236  
   237  	var limit *int32
   238  	if p.options.Limit > 0 {
   239  		limit = &p.options.Limit
   240  	}
   241  	params.MaxResults = limit
   242  
   243  	result, err := p.client.ListImages(ctx, &params, optFns...)
   244  	if err != nil {
   245  		return nil, err
   246  	}
   247  	p.firstPage = false
   248  
   249  	prevToken := p.nextToken
   250  	p.nextToken = result.NextToken
   251  
   252  	if p.options.StopOnDuplicateToken &&
   253  		prevToken != nil &&
   254  		p.nextToken != nil &&
   255  		*prevToken == *p.nextToken {
   256  		p.nextToken = nil
   257  	}
   258  
   259  	return result, nil
   260  }
   261  
   262  func newServiceMetadataMiddleware_opListImages(region string) *awsmiddleware.RegisterServiceMetadata {
   263  	return &awsmiddleware.RegisterServiceMetadata{
   264  		Region:        region,
   265  		ServiceID:     ServiceID,
   266  		SigningName:   "ecr",
   267  		OperationName: "ListImages",
   268  	}
   269  }
   270  
   271  type opListImagesResolveEndpointMiddleware struct {
   272  	EndpointResolver EndpointResolverV2
   273  	BuiltInResolver  builtInParameterResolver
   274  }
   275  
   276  func (*opListImagesResolveEndpointMiddleware) ID() string {
   277  	return "ResolveEndpointV2"
   278  }
   279  
   280  func (m *opListImagesResolveEndpointMiddleware) HandleSerialize(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) (
   281  	out middleware.SerializeOutput, metadata middleware.Metadata, err error,
   282  ) {
   283  	if awsmiddleware.GetRequiresLegacyEndpoints(ctx) {
   284  		return next.HandleSerialize(ctx, in)
   285  	}
   286  
   287  	req, ok := in.Request.(*smithyhttp.Request)
   288  	if !ok {
   289  		return out, metadata, fmt.Errorf("unknown transport type %T", in.Request)
   290  	}
   291  
   292  	if m.EndpointResolver == nil {
   293  		return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil")
   294  	}
   295  
   296  	params := EndpointParameters{}
   297  
   298  	m.BuiltInResolver.ResolveBuiltIns(&params)
   299  
   300  	var resolvedEndpoint smithyendpoints.Endpoint
   301  	resolvedEndpoint, err = m.EndpointResolver.ResolveEndpoint(ctx, params)
   302  	if err != nil {
   303  		return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err)
   304  	}
   305  
   306  	req.URL = &resolvedEndpoint.URI
   307  
   308  	for k := range resolvedEndpoint.Headers {
   309  		req.Header.Set(
   310  			k,
   311  			resolvedEndpoint.Headers.Get(k),
   312  		)
   313  	}
   314  
   315  	authSchemes, err := internalauth.GetAuthenticationSchemes(&resolvedEndpoint.Properties)
   316  	if err != nil {
   317  		var nfe *internalauth.NoAuthenticationSchemesFoundError
   318  		if errors.As(err, &nfe) {
   319  			// if no auth scheme is found, default to sigv4
   320  			signingName := "ecr"
   321  			signingRegion := m.BuiltInResolver.(*builtInResolver).Region
   322  			ctx = awsmiddleware.SetSigningName(ctx, signingName)
   323  			ctx = awsmiddleware.SetSigningRegion(ctx, signingRegion)
   324  
   325  		}
   326  		var ue *internalauth.UnSupportedAuthenticationSchemeSpecifiedError
   327  		if errors.As(err, &ue) {
   328  			return out, metadata, fmt.Errorf(
   329  				"This operation requests signer version(s) %v but the client only supports %v",
   330  				ue.UnsupportedSchemes,
   331  				internalauth.SupportedSchemes,
   332  			)
   333  		}
   334  	}
   335  
   336  	for _, authScheme := range authSchemes {
   337  		switch authScheme.(type) {
   338  		case *internalauth.AuthenticationSchemeV4:
   339  			v4Scheme, _ := authScheme.(*internalauth.AuthenticationSchemeV4)
   340  			var signingName, signingRegion string
   341  			if v4Scheme.SigningName == nil {
   342  				signingName = "ecr"
   343  			} else {
   344  				signingName = *v4Scheme.SigningName
   345  			}
   346  			if v4Scheme.SigningRegion == nil {
   347  				signingRegion = m.BuiltInResolver.(*builtInResolver).Region
   348  			} else {
   349  				signingRegion = *v4Scheme.SigningRegion
   350  			}
   351  			if v4Scheme.DisableDoubleEncoding != nil {
   352  				// The signer sets an equivalent value at client initialization time.
   353  				// Setting this context value will cause the signer to extract it
   354  				// and override the value set at client initialization time.
   355  				ctx = internalauth.SetDisableDoubleEncoding(ctx, *v4Scheme.DisableDoubleEncoding)
   356  			}
   357  			ctx = awsmiddleware.SetSigningName(ctx, signingName)
   358  			ctx = awsmiddleware.SetSigningRegion(ctx, signingRegion)
   359  			break
   360  		case *internalauth.AuthenticationSchemeV4A:
   361  			v4aScheme, _ := authScheme.(*internalauth.AuthenticationSchemeV4A)
   362  			if v4aScheme.SigningName == nil {
   363  				v4aScheme.SigningName = aws.String("ecr")
   364  			}
   365  			if v4aScheme.DisableDoubleEncoding != nil {
   366  				// The signer sets an equivalent value at client initialization time.
   367  				// Setting this context value will cause the signer to extract it
   368  				// and override the value set at client initialization time.
   369  				ctx = internalauth.SetDisableDoubleEncoding(ctx, *v4aScheme.DisableDoubleEncoding)
   370  			}
   371  			ctx = awsmiddleware.SetSigningName(ctx, *v4aScheme.SigningName)
   372  			ctx = awsmiddleware.SetSigningRegion(ctx, v4aScheme.SigningRegionSet[0])
   373  			break
   374  		case *internalauth.AuthenticationSchemeNone:
   375  			break
   376  		}
   377  	}
   378  
   379  	return next.HandleSerialize(ctx, in)
   380  }
   381  
   382  func addListImagesResolveEndpointMiddleware(stack *middleware.Stack, options Options) error {
   383  	return stack.Serialize.Insert(&opListImagesResolveEndpointMiddleware{
   384  		EndpointResolver: options.EndpointResolverV2,
   385  		BuiltInResolver: &builtInResolver{
   386  			Region:       options.Region,
   387  			UseDualStack: options.EndpointOptions.UseDualStackEndpoint,
   388  			UseFIPS:      options.EndpointOptions.UseFIPSEndpoint,
   389  			Endpoint:     options.BaseEndpoint,
   390  		},
   391  	}, "ResolveEndpoint", middleware.After)
   392  }
   393  

View as plain text