...

Source file src/github.com/aws/aws-sdk-go-v2/service/ecr/api_op_GetLifecyclePolicyPreview.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  	smithytime "github.com/aws/smithy-go/time"
    17  	smithyhttp "github.com/aws/smithy-go/transport/http"
    18  	smithywaiter "github.com/aws/smithy-go/waiter"
    19  	"github.com/jmespath/go-jmespath"
    20  	"time"
    21  )
    22  
    23  // Retrieves the results of the lifecycle policy preview request for the specified
    24  // repository.
    25  func (c *Client) GetLifecyclePolicyPreview(ctx context.Context, params *GetLifecyclePolicyPreviewInput, optFns ...func(*Options)) (*GetLifecyclePolicyPreviewOutput, error) {
    26  	if params == nil {
    27  		params = &GetLifecyclePolicyPreviewInput{}
    28  	}
    29  
    30  	result, metadata, err := c.invokeOperation(ctx, "GetLifecyclePolicyPreview", params, optFns, c.addOperationGetLifecyclePolicyPreviewMiddlewares)
    31  	if err != nil {
    32  		return nil, err
    33  	}
    34  
    35  	out := result.(*GetLifecyclePolicyPreviewOutput)
    36  	out.ResultMetadata = metadata
    37  	return out, nil
    38  }
    39  
    40  type GetLifecyclePolicyPreviewInput struct {
    41  
    42  	// The name of the repository.
    43  	//
    44  	// This member is required.
    45  	RepositoryName *string
    46  
    47  	// An optional parameter that filters results based on image tag status and all
    48  	// tags, if tagged.
    49  	Filter *types.LifecyclePolicyPreviewFilter
    50  
    51  	// The list of imageIDs to be included.
    52  	ImageIds []types.ImageIdentifier
    53  
    54  	// The maximum number of repository results returned by
    55  	// GetLifecyclePolicyPreviewRequest in
 paginated output. When this parameter is
    56  	// used, GetLifecyclePolicyPreviewRequest only returns
 maxResults results in a
    57  	// single page along with a nextToken 
 response element. The remaining results of
    58  	// the initial request can be seen by sending
 another
    59  	// GetLifecyclePolicyPreviewRequest request with the returned nextToken 
 value.
    60  	// This value can be between 1 and 1000. If this
 parameter is not used, then
    61  	// GetLifecyclePolicyPreviewRequest returns up to
 100 results and a nextToken
    62  	// value, if
 applicable. This option cannot be used when you specify images with
    63  	// imageIds .
    64  	MaxResults *int32
    65  
    66  	// The nextToken value returned from a previous paginated
    67  	// GetLifecyclePolicyPreviewRequest request where maxResults was used and the
    68  	// results exceeded the value of that parameter. Pagination continues from the end
    69  	// of the
 previous results that returned the nextToken value. This value is
 null
    70  	// when there are no more results to return. This option cannot be used when you
    71  	// specify images with imageIds .
    72  	NextToken *string
    73  
    74  	// The Amazon Web Services account ID associated with the registry that contains
    75  	// the repository. If you do not specify a registry, the default registry is
    76  	// assumed.
    77  	RegistryId *string
    78  
    79  	noSmithyDocumentSerde
    80  }
    81  
    82  type GetLifecyclePolicyPreviewOutput struct {
    83  
    84  	// The JSON lifecycle policy text.
    85  	LifecyclePolicyText *string
    86  
    87  	// The nextToken value to include in a future GetLifecyclePolicyPreview request.
    88  	// When the results of a GetLifecyclePolicyPreview request exceed maxResults , this
    89  	// value can be used to retrieve the next page of results. This value is null when
    90  	// there are no more results to return.
    91  	NextToken *string
    92  
    93  	// The results of the lifecycle policy preview request.
    94  	PreviewResults []types.LifecyclePolicyPreviewResult
    95  
    96  	// The registry ID associated with the request.
    97  	RegistryId *string
    98  
    99  	// The repository name associated with the request.
   100  	RepositoryName *string
   101  
   102  	// The status of the lifecycle policy preview request.
   103  	Status types.LifecyclePolicyPreviewStatus
   104  
   105  	// The list of images that is returned as a result of the action.
   106  	Summary *types.LifecyclePolicyPreviewSummary
   107  
   108  	// Metadata pertaining to the operation's result.
   109  	ResultMetadata middleware.Metadata
   110  
   111  	noSmithyDocumentSerde
   112  }
   113  
   114  func (c *Client) addOperationGetLifecyclePolicyPreviewMiddlewares(stack *middleware.Stack, options Options) (err error) {
   115  	err = stack.Serialize.Add(&awsAwsjson11_serializeOpGetLifecyclePolicyPreview{}, middleware.After)
   116  	if err != nil {
   117  		return err
   118  	}
   119  	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpGetLifecyclePolicyPreview{}, middleware.After)
   120  	if err != nil {
   121  		return err
   122  	}
   123  	if err = addlegacyEndpointContextSetter(stack, options); err != nil {
   124  		return err
   125  	}
   126  	if err = addSetLoggerMiddleware(stack, options); err != nil {
   127  		return err
   128  	}
   129  	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
   130  		return err
   131  	}
   132  	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
   133  		return err
   134  	}
   135  	if err = addResolveEndpointMiddleware(stack, options); err != nil {
   136  		return err
   137  	}
   138  	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
   139  		return err
   140  	}
   141  	if err = addRetryMiddlewares(stack, options); err != nil {
   142  		return err
   143  	}
   144  	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
   145  		return err
   146  	}
   147  	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
   148  		return err
   149  	}
   150  	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
   151  		return err
   152  	}
   153  	if err = addClientUserAgent(stack, options); err != nil {
   154  		return err
   155  	}
   156  	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
   157  		return err
   158  	}
   159  	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
   160  		return err
   161  	}
   162  	if err = addGetLifecyclePolicyPreviewResolveEndpointMiddleware(stack, options); err != nil {
   163  		return err
   164  	}
   165  	if err = addOpGetLifecyclePolicyPreviewValidationMiddleware(stack); err != nil {
   166  		return err
   167  	}
   168  	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetLifecyclePolicyPreview(options.Region), middleware.Before); err != nil {
   169  		return err
   170  	}
   171  	if err = awsmiddleware.AddRecursionDetection(stack); err != nil {
   172  		return err
   173  	}
   174  	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
   175  		return err
   176  	}
   177  	if err = addResponseErrorMiddleware(stack); err != nil {
   178  		return err
   179  	}
   180  	if err = addRequestResponseLogging(stack, options); err != nil {
   181  		return err
   182  	}
   183  	if err = addendpointDisableHTTPSMiddleware(stack, options); err != nil {
   184  		return err
   185  	}
   186  	return nil
   187  }
   188  
   189  // GetLifecyclePolicyPreviewAPIClient is a client that implements the
   190  // GetLifecyclePolicyPreview operation.
   191  type GetLifecyclePolicyPreviewAPIClient interface {
   192  	GetLifecyclePolicyPreview(context.Context, *GetLifecyclePolicyPreviewInput, ...func(*Options)) (*GetLifecyclePolicyPreviewOutput, error)
   193  }
   194  
   195  var _ GetLifecyclePolicyPreviewAPIClient = (*Client)(nil)
   196  
   197  // GetLifecyclePolicyPreviewPaginatorOptions is the paginator options for
   198  // GetLifecyclePolicyPreview
   199  type GetLifecyclePolicyPreviewPaginatorOptions struct {
   200  	// The maximum number of repository results returned by
   201  	// GetLifecyclePolicyPreviewRequest in
 paginated output. When this parameter is
   202  	// used, GetLifecyclePolicyPreviewRequest only returns
 maxResults results in a
   203  	// single page along with a nextToken 
 response element. The remaining results of
   204  	// the initial request can be seen by sending
 another
   205  	// GetLifecyclePolicyPreviewRequest request with the returned nextToken 
 value.
   206  	// This value can be between 1 and 1000. If this
 parameter is not used, then
   207  	// GetLifecyclePolicyPreviewRequest returns up to
 100 results and a nextToken
   208  	// value, if
 applicable. This option cannot be used when you specify images with
   209  	// imageIds .
   210  	Limit int32
   211  
   212  	// Set to true if pagination should stop if the service returns a pagination token
   213  	// that matches the most recent token provided to the service.
   214  	StopOnDuplicateToken bool
   215  }
   216  
   217  // GetLifecyclePolicyPreviewPaginator is a paginator for GetLifecyclePolicyPreview
   218  type GetLifecyclePolicyPreviewPaginator struct {
   219  	options   GetLifecyclePolicyPreviewPaginatorOptions
   220  	client    GetLifecyclePolicyPreviewAPIClient
   221  	params    *GetLifecyclePolicyPreviewInput
   222  	nextToken *string
   223  	firstPage bool
   224  }
   225  
   226  // NewGetLifecyclePolicyPreviewPaginator returns a new
   227  // GetLifecyclePolicyPreviewPaginator
   228  func NewGetLifecyclePolicyPreviewPaginator(client GetLifecyclePolicyPreviewAPIClient, params *GetLifecyclePolicyPreviewInput, optFns ...func(*GetLifecyclePolicyPreviewPaginatorOptions)) *GetLifecyclePolicyPreviewPaginator {
   229  	if params == nil {
   230  		params = &GetLifecyclePolicyPreviewInput{}
   231  	}
   232  
   233  	options := GetLifecyclePolicyPreviewPaginatorOptions{}
   234  	if params.MaxResults != nil {
   235  		options.Limit = *params.MaxResults
   236  	}
   237  
   238  	for _, fn := range optFns {
   239  		fn(&options)
   240  	}
   241  
   242  	return &GetLifecyclePolicyPreviewPaginator{
   243  		options:   options,
   244  		client:    client,
   245  		params:    params,
   246  		firstPage: true,
   247  		nextToken: params.NextToken,
   248  	}
   249  }
   250  
   251  // HasMorePages returns a boolean indicating whether more pages are available
   252  func (p *GetLifecyclePolicyPreviewPaginator) HasMorePages() bool {
   253  	return p.firstPage || (p.nextToken != nil && len(*p.nextToken) != 0)
   254  }
   255  
   256  // NextPage retrieves the next GetLifecyclePolicyPreview page.
   257  func (p *GetLifecyclePolicyPreviewPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*GetLifecyclePolicyPreviewOutput, error) {
   258  	if !p.HasMorePages() {
   259  		return nil, fmt.Errorf("no more pages available")
   260  	}
   261  
   262  	params := *p.params
   263  	params.NextToken = p.nextToken
   264  
   265  	var limit *int32
   266  	if p.options.Limit > 0 {
   267  		limit = &p.options.Limit
   268  	}
   269  	params.MaxResults = limit
   270  
   271  	result, err := p.client.GetLifecyclePolicyPreview(ctx, &params, optFns...)
   272  	if err != nil {
   273  		return nil, err
   274  	}
   275  	p.firstPage = false
   276  
   277  	prevToken := p.nextToken
   278  	p.nextToken = result.NextToken
   279  
   280  	if p.options.StopOnDuplicateToken &&
   281  		prevToken != nil &&
   282  		p.nextToken != nil &&
   283  		*prevToken == *p.nextToken {
   284  		p.nextToken = nil
   285  	}
   286  
   287  	return result, nil
   288  }
   289  
   290  // LifecyclePolicyPreviewCompleteWaiterOptions are waiter options for
   291  // LifecyclePolicyPreviewCompleteWaiter
   292  type LifecyclePolicyPreviewCompleteWaiterOptions struct {
   293  
   294  	// Set of options to modify how an operation is invoked. These apply to all
   295  	// operations invoked for this client. Use functional options on operation call to
   296  	// modify this list for per operation behavior.
   297  	APIOptions []func(*middleware.Stack) error
   298  
   299  	// MinDelay is the minimum amount of time to delay between retries. If unset,
   300  	// LifecyclePolicyPreviewCompleteWaiter will use default minimum delay of 5
   301  	// seconds. Note that MinDelay must resolve to a value lesser than or equal to the
   302  	// MaxDelay.
   303  	MinDelay time.Duration
   304  
   305  	// MaxDelay is the maximum amount of time to delay between retries. If unset or
   306  	// set to zero, LifecyclePolicyPreviewCompleteWaiter will use default max delay of
   307  	// 120 seconds. Note that MaxDelay must resolve to value greater than or equal to
   308  	// the MinDelay.
   309  	MaxDelay time.Duration
   310  
   311  	// LogWaitAttempts is used to enable logging for waiter retry attempts
   312  	LogWaitAttempts bool
   313  
   314  	// Retryable is function that can be used to override the service defined
   315  	// waiter-behavior based on operation output, or returned error. This function is
   316  	// used by the waiter to decide if a state is retryable or a terminal state. By
   317  	// default service-modeled logic will populate this option. This option can thus be
   318  	// used to define a custom waiter state with fall-back to service-modeled waiter
   319  	// state mutators.The function returns an error in case of a failure state. In case
   320  	// of retry state, this function returns a bool value of true and nil error, while
   321  	// in case of success it returns a bool value of false and nil error.
   322  	Retryable func(context.Context, *GetLifecyclePolicyPreviewInput, *GetLifecyclePolicyPreviewOutput, error) (bool, error)
   323  }
   324  
   325  // LifecyclePolicyPreviewCompleteWaiter defines the waiters for
   326  // LifecyclePolicyPreviewComplete
   327  type LifecyclePolicyPreviewCompleteWaiter struct {
   328  	client GetLifecyclePolicyPreviewAPIClient
   329  
   330  	options LifecyclePolicyPreviewCompleteWaiterOptions
   331  }
   332  
   333  // NewLifecyclePolicyPreviewCompleteWaiter constructs a
   334  // LifecyclePolicyPreviewCompleteWaiter.
   335  func NewLifecyclePolicyPreviewCompleteWaiter(client GetLifecyclePolicyPreviewAPIClient, optFns ...func(*LifecyclePolicyPreviewCompleteWaiterOptions)) *LifecyclePolicyPreviewCompleteWaiter {
   336  	options := LifecyclePolicyPreviewCompleteWaiterOptions{}
   337  	options.MinDelay = 5 * time.Second
   338  	options.MaxDelay = 120 * time.Second
   339  	options.Retryable = lifecyclePolicyPreviewCompleteStateRetryable
   340  
   341  	for _, fn := range optFns {
   342  		fn(&options)
   343  	}
   344  	return &LifecyclePolicyPreviewCompleteWaiter{
   345  		client:  client,
   346  		options: options,
   347  	}
   348  }
   349  
   350  // Wait calls the waiter function for LifecyclePolicyPreviewComplete waiter. The
   351  // maxWaitDur is the maximum wait duration the waiter will wait. The maxWaitDur is
   352  // required and must be greater than zero.
   353  func (w *LifecyclePolicyPreviewCompleteWaiter) Wait(ctx context.Context, params *GetLifecyclePolicyPreviewInput, maxWaitDur time.Duration, optFns ...func(*LifecyclePolicyPreviewCompleteWaiterOptions)) error {
   354  	_, err := w.WaitForOutput(ctx, params, maxWaitDur, optFns...)
   355  	return err
   356  }
   357  
   358  // WaitForOutput calls the waiter function for LifecyclePolicyPreviewComplete
   359  // waiter and returns the output of the successful operation. The maxWaitDur is the
   360  // maximum wait duration the waiter will wait. The maxWaitDur is required and must
   361  // be greater than zero.
   362  func (w *LifecyclePolicyPreviewCompleteWaiter) WaitForOutput(ctx context.Context, params *GetLifecyclePolicyPreviewInput, maxWaitDur time.Duration, optFns ...func(*LifecyclePolicyPreviewCompleteWaiterOptions)) (*GetLifecyclePolicyPreviewOutput, error) {
   363  	if maxWaitDur <= 0 {
   364  		return nil, fmt.Errorf("maximum wait time for waiter must be greater than zero")
   365  	}
   366  
   367  	options := w.options
   368  	for _, fn := range optFns {
   369  		fn(&options)
   370  	}
   371  
   372  	if options.MaxDelay <= 0 {
   373  		options.MaxDelay = 120 * time.Second
   374  	}
   375  
   376  	if options.MinDelay > options.MaxDelay {
   377  		return nil, fmt.Errorf("minimum waiter delay %v must be lesser than or equal to maximum waiter delay of %v.", options.MinDelay, options.MaxDelay)
   378  	}
   379  
   380  	ctx, cancelFn := context.WithTimeout(ctx, maxWaitDur)
   381  	defer cancelFn()
   382  
   383  	logger := smithywaiter.Logger{}
   384  	remainingTime := maxWaitDur
   385  
   386  	var attempt int64
   387  	for {
   388  
   389  		attempt++
   390  		apiOptions := options.APIOptions
   391  		start := time.Now()
   392  
   393  		if options.LogWaitAttempts {
   394  			logger.Attempt = attempt
   395  			apiOptions = append([]func(*middleware.Stack) error{}, options.APIOptions...)
   396  			apiOptions = append(apiOptions, logger.AddLogger)
   397  		}
   398  
   399  		out, err := w.client.GetLifecyclePolicyPreview(ctx, params, func(o *Options) {
   400  			o.APIOptions = append(o.APIOptions, apiOptions...)
   401  		})
   402  
   403  		retryable, err := options.Retryable(ctx, params, out, err)
   404  		if err != nil {
   405  			return nil, err
   406  		}
   407  		if !retryable {
   408  			return out, nil
   409  		}
   410  
   411  		remainingTime -= time.Since(start)
   412  		if remainingTime < options.MinDelay || remainingTime <= 0 {
   413  			break
   414  		}
   415  
   416  		// compute exponential backoff between waiter retries
   417  		delay, err := smithywaiter.ComputeDelay(
   418  			attempt, options.MinDelay, options.MaxDelay, remainingTime,
   419  		)
   420  		if err != nil {
   421  			return nil, fmt.Errorf("error computing waiter delay, %w", err)
   422  		}
   423  
   424  		remainingTime -= delay
   425  		// sleep for the delay amount before invoking a request
   426  		if err := smithytime.SleepWithContext(ctx, delay); err != nil {
   427  			return nil, fmt.Errorf("request cancelled while waiting, %w", err)
   428  		}
   429  	}
   430  	return nil, fmt.Errorf("exceeded max wait time for LifecyclePolicyPreviewComplete waiter")
   431  }
   432  
   433  func lifecyclePolicyPreviewCompleteStateRetryable(ctx context.Context, input *GetLifecyclePolicyPreviewInput, output *GetLifecyclePolicyPreviewOutput, err error) (bool, error) {
   434  
   435  	if err == nil {
   436  		pathValue, err := jmespath.Search("status", output)
   437  		if err != nil {
   438  			return false, fmt.Errorf("error evaluating waiter state: %w", err)
   439  		}
   440  
   441  		expectedValue := "COMPLETE"
   442  		value, ok := pathValue.(types.LifecyclePolicyPreviewStatus)
   443  		if !ok {
   444  			return false, fmt.Errorf("waiter comparator expected types.LifecyclePolicyPreviewStatus value, got %T", pathValue)
   445  		}
   446  
   447  		if string(value) == expectedValue {
   448  			return false, nil
   449  		}
   450  	}
   451  
   452  	if err == nil {
   453  		pathValue, err := jmespath.Search("status", output)
   454  		if err != nil {
   455  			return false, fmt.Errorf("error evaluating waiter state: %w", err)
   456  		}
   457  
   458  		expectedValue := "FAILED"
   459  		value, ok := pathValue.(types.LifecyclePolicyPreviewStatus)
   460  		if !ok {
   461  			return false, fmt.Errorf("waiter comparator expected types.LifecyclePolicyPreviewStatus value, got %T", pathValue)
   462  		}
   463  
   464  		if string(value) == expectedValue {
   465  			return false, fmt.Errorf("waiter state transitioned to Failure")
   466  		}
   467  	}
   468  
   469  	return true, nil
   470  }
   471  
   472  func newServiceMetadataMiddleware_opGetLifecyclePolicyPreview(region string) *awsmiddleware.RegisterServiceMetadata {
   473  	return &awsmiddleware.RegisterServiceMetadata{
   474  		Region:        region,
   475  		ServiceID:     ServiceID,
   476  		SigningName:   "ecr",
   477  		OperationName: "GetLifecyclePolicyPreview",
   478  	}
   479  }
   480  
   481  type opGetLifecyclePolicyPreviewResolveEndpointMiddleware struct {
   482  	EndpointResolver EndpointResolverV2
   483  	BuiltInResolver  builtInParameterResolver
   484  }
   485  
   486  func (*opGetLifecyclePolicyPreviewResolveEndpointMiddleware) ID() string {
   487  	return "ResolveEndpointV2"
   488  }
   489  
   490  func (m *opGetLifecyclePolicyPreviewResolveEndpointMiddleware) HandleSerialize(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) (
   491  	out middleware.SerializeOutput, metadata middleware.Metadata, err error,
   492  ) {
   493  	if awsmiddleware.GetRequiresLegacyEndpoints(ctx) {
   494  		return next.HandleSerialize(ctx, in)
   495  	}
   496  
   497  	req, ok := in.Request.(*smithyhttp.Request)
   498  	if !ok {
   499  		return out, metadata, fmt.Errorf("unknown transport type %T", in.Request)
   500  	}
   501  
   502  	if m.EndpointResolver == nil {
   503  		return out, metadata, fmt.Errorf("expected endpoint resolver to not be nil")
   504  	}
   505  
   506  	params := EndpointParameters{}
   507  
   508  	m.BuiltInResolver.ResolveBuiltIns(&params)
   509  
   510  	var resolvedEndpoint smithyendpoints.Endpoint
   511  	resolvedEndpoint, err = m.EndpointResolver.ResolveEndpoint(ctx, params)
   512  	if err != nil {
   513  		return out, metadata, fmt.Errorf("failed to resolve service endpoint, %w", err)
   514  	}
   515  
   516  	req.URL = &resolvedEndpoint.URI
   517  
   518  	for k := range resolvedEndpoint.Headers {
   519  		req.Header.Set(
   520  			k,
   521  			resolvedEndpoint.Headers.Get(k),
   522  		)
   523  	}
   524  
   525  	authSchemes, err := internalauth.GetAuthenticationSchemes(&resolvedEndpoint.Properties)
   526  	if err != nil {
   527  		var nfe *internalauth.NoAuthenticationSchemesFoundError
   528  		if errors.As(err, &nfe) {
   529  			// if no auth scheme is found, default to sigv4
   530  			signingName := "ecr"
   531  			signingRegion := m.BuiltInResolver.(*builtInResolver).Region
   532  			ctx = awsmiddleware.SetSigningName(ctx, signingName)
   533  			ctx = awsmiddleware.SetSigningRegion(ctx, signingRegion)
   534  
   535  		}
   536  		var ue *internalauth.UnSupportedAuthenticationSchemeSpecifiedError
   537  		if errors.As(err, &ue) {
   538  			return out, metadata, fmt.Errorf(
   539  				"This operation requests signer version(s) %v but the client only supports %v",
   540  				ue.UnsupportedSchemes,
   541  				internalauth.SupportedSchemes,
   542  			)
   543  		}
   544  	}
   545  
   546  	for _, authScheme := range authSchemes {
   547  		switch authScheme.(type) {
   548  		case *internalauth.AuthenticationSchemeV4:
   549  			v4Scheme, _ := authScheme.(*internalauth.AuthenticationSchemeV4)
   550  			var signingName, signingRegion string
   551  			if v4Scheme.SigningName == nil {
   552  				signingName = "ecr"
   553  			} else {
   554  				signingName = *v4Scheme.SigningName
   555  			}
   556  			if v4Scheme.SigningRegion == nil {
   557  				signingRegion = m.BuiltInResolver.(*builtInResolver).Region
   558  			} else {
   559  				signingRegion = *v4Scheme.SigningRegion
   560  			}
   561  			if v4Scheme.DisableDoubleEncoding != nil {
   562  				// The signer sets an equivalent value at client initialization time.
   563  				// Setting this context value will cause the signer to extract it
   564  				// and override the value set at client initialization time.
   565  				ctx = internalauth.SetDisableDoubleEncoding(ctx, *v4Scheme.DisableDoubleEncoding)
   566  			}
   567  			ctx = awsmiddleware.SetSigningName(ctx, signingName)
   568  			ctx = awsmiddleware.SetSigningRegion(ctx, signingRegion)
   569  			break
   570  		case *internalauth.AuthenticationSchemeV4A:
   571  			v4aScheme, _ := authScheme.(*internalauth.AuthenticationSchemeV4A)
   572  			if v4aScheme.SigningName == nil {
   573  				v4aScheme.SigningName = aws.String("ecr")
   574  			}
   575  			if v4aScheme.DisableDoubleEncoding != nil {
   576  				// The signer sets an equivalent value at client initialization time.
   577  				// Setting this context value will cause the signer to extract it
   578  				// and override the value set at client initialization time.
   579  				ctx = internalauth.SetDisableDoubleEncoding(ctx, *v4aScheme.DisableDoubleEncoding)
   580  			}
   581  			ctx = awsmiddleware.SetSigningName(ctx, *v4aScheme.SigningName)
   582  			ctx = awsmiddleware.SetSigningRegion(ctx, v4aScheme.SigningRegionSet[0])
   583  			break
   584  		case *internalauth.AuthenticationSchemeNone:
   585  			break
   586  		}
   587  	}
   588  
   589  	return next.HandleSerialize(ctx, in)
   590  }
   591  
   592  func addGetLifecyclePolicyPreviewResolveEndpointMiddleware(stack *middleware.Stack, options Options) error {
   593  	return stack.Serialize.Insert(&opGetLifecyclePolicyPreviewResolveEndpointMiddleware{
   594  		EndpointResolver: options.EndpointResolverV2,
   595  		BuiltInResolver: &builtInResolver{
   596  			Region:       options.Region,
   597  			UseDualStack: options.EndpointOptions.UseDualStackEndpoint,
   598  			UseFIPS:      options.EndpointOptions.UseFIPSEndpoint,
   599  			Endpoint:     options.BaseEndpoint,
   600  		},
   601  	}, "ResolveEndpoint", middleware.After)
   602  }
   603  

View as plain text