...

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

View as plain text