src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

api_op_GetChange.go (11158B)


      1 // Code generated by smithy-go-codegen DO NOT EDIT.
      2 
      3 package route53
      4 
      5 import (
      6 	"context"
      7 	"fmt"
      8 	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
      9 	"github.com/aws/aws-sdk-go-v2/service/route53/types"
     10 	"github.com/aws/smithy-go/middleware"
     11 	smithytime "github.com/aws/smithy-go/time"
     12 	smithyhttp "github.com/aws/smithy-go/transport/http"
     13 	smithywaiter "github.com/aws/smithy-go/waiter"
     14 	"github.com/jmespath/go-jmespath"
     15 	"time"
     16 )
     17 
     18 // Returns the current status of a change batch request. The status is one of the
     19 // following values:
     20 //   - PENDING indicates that the changes in this request have not propagated to
     21 //     all Amazon Route 53 DNS servers managing the hosted zone. This is the initial
     22 //     status of all change batch requests.
     23 //   - INSYNC indicates that the changes have propagated to all Route 53 DNS
     24 //     servers managing the hosted zone.
     25 func (c *Client) GetChange(ctx context.Context, params *GetChangeInput, optFns ...func(*Options)) (*GetChangeOutput, error) {
     26 	if params == nil {
     27 		params = &GetChangeInput{}
     28 	}
     29 
     30 	result, metadata, err := c.invokeOperation(ctx, "GetChange", params, optFns, c.addOperationGetChangeMiddlewares)
     31 	if err != nil {
     32 		return nil, err
     33 	}
     34 
     35 	out := result.(*GetChangeOutput)
     36 	out.ResultMetadata = metadata
     37 	return out, nil
     38 }
     39 
     40 // The input for a GetChange request.
     41 type GetChangeInput struct {
     42 
     43 	// The ID of the change batch request. The value that you specify here is the
     44 	// value that ChangeResourceRecordSets returned in the Id element when you
     45 	// submitted the request.
     46 	//
     47 	// This member is required.
     48 	Id *string
     49 
     50 	noSmithyDocumentSerde
     51 }
     52 
     53 // A complex type that contains the ChangeInfo element.
     54 type GetChangeOutput struct {
     55 
     56 	// A complex type that contains information about the specified change batch.
     57 	//
     58 	// This member is required.
     59 	ChangeInfo *types.ChangeInfo
     60 
     61 	// Metadata pertaining to the operation's result.
     62 	ResultMetadata middleware.Metadata
     63 
     64 	noSmithyDocumentSerde
     65 }
     66 
     67 func (c *Client) addOperationGetChangeMiddlewares(stack *middleware.Stack, options Options) (err error) {
     68 	if err := stack.Serialize.Add(&setOperationInputMiddleware{}, middleware.After); err != nil {
     69 		return err
     70 	}
     71 	err = stack.Serialize.Add(&awsRestxml_serializeOpGetChange{}, middleware.After)
     72 	if err != nil {
     73 		return err
     74 	}
     75 	err = stack.Deserialize.Add(&awsRestxml_deserializeOpGetChange{}, middleware.After)
     76 	if err != nil {
     77 		return err
     78 	}
     79 	if err := addProtocolFinalizerMiddlewares(stack, options, "GetChange"); err != nil {
     80 		return fmt.Errorf("add protocol finalizers: %v", err)
     81 	}
     82 
     83 	if err = addlegacyEndpointContextSetter(stack, options); err != nil {
     84 		return err
     85 	}
     86 	if err = addSetLoggerMiddleware(stack, options); err != nil {
     87 		return err
     88 	}
     89 	if err = addClientRequestID(stack); err != nil {
     90 		return err
     91 	}
     92 	if err = addComputeContentLength(stack); err != nil {
     93 		return err
     94 	}
     95 	if err = addResolveEndpointMiddleware(stack, options); err != nil {
     96 		return err
     97 	}
     98 	if err = addComputePayloadSHA256(stack); err != nil {
     99 		return err
    100 	}
    101 	if err = addRetry(stack, options); err != nil {
    102 		return err
    103 	}
    104 	if err = addRawResponseToMetadata(stack); err != nil {
    105 		return err
    106 	}
    107 	if err = addRecordResponseTiming(stack); err != nil {
    108 		return err
    109 	}
    110 	if err = addClientUserAgent(stack, options); err != nil {
    111 		return err
    112 	}
    113 	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
    114 		return err
    115 	}
    116 	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
    117 		return err
    118 	}
    119 	if err = addSetLegacyContextSigningOptionsMiddleware(stack); err != nil {
    120 		return err
    121 	}
    122 	if err = addOpGetChangeValidationMiddleware(stack); err != nil {
    123 		return err
    124 	}
    125 	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetChange(options.Region), middleware.Before); err != nil {
    126 		return err
    127 	}
    128 	if err = addRecursionDetection(stack); err != nil {
    129 		return err
    130 	}
    131 	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
    132 		return err
    133 	}
    134 	if err = addResponseErrorMiddleware(stack); err != nil {
    135 		return err
    136 	}
    137 	if err = addSanitizeURLMiddleware(stack); err != nil {
    138 		return err
    139 	}
    140 	if err = addRequestResponseLogging(stack, options); err != nil {
    141 		return err
    142 	}
    143 	if err = addDisableHTTPSMiddleware(stack, options); err != nil {
    144 		return err
    145 	}
    146 	return nil
    147 }
    148 
    149 // GetChangeAPIClient is a client that implements the GetChange operation.
    150 type GetChangeAPIClient interface {
    151 	GetChange(context.Context, *GetChangeInput, ...func(*Options)) (*GetChangeOutput, error)
    152 }
    153 
    154 var _ GetChangeAPIClient = (*Client)(nil)
    155 
    156 // ResourceRecordSetsChangedWaiterOptions are waiter options for
    157 // ResourceRecordSetsChangedWaiter
    158 type ResourceRecordSetsChangedWaiterOptions struct {
    159 
    160 	// Set of options to modify how an operation is invoked. These apply to all
    161 	// operations invoked for this client. Use functional options on operation call to
    162 	// modify this list for per operation behavior.
    163 	//
    164 	// Passing options here is functionally equivalent to passing values to this
    165 	// config's ClientOptions field that extend the inner client's APIOptions directly.
    166 	APIOptions []func(*middleware.Stack) error
    167 
    168 	// Functional options to be passed to all operations invoked by this client.
    169 	//
    170 	// Function values that modify the inner APIOptions are applied after the waiter
    171 	// config's own APIOptions modifiers.
    172 	ClientOptions []func(*Options)
    173 
    174 	// MinDelay is the minimum amount of time to delay between retries. If unset,
    175 	// ResourceRecordSetsChangedWaiter will use default minimum delay of 30 seconds.
    176 	// Note that MinDelay must resolve to a value lesser than or equal to the MaxDelay.
    177 	MinDelay time.Duration
    178 
    179 	// MaxDelay is the maximum amount of time to delay between retries. If unset or
    180 	// set to zero, ResourceRecordSetsChangedWaiter will use default max delay of 120
    181 	// seconds. Note that MaxDelay must resolve to value greater than or equal to the
    182 	// MinDelay.
    183 	MaxDelay time.Duration
    184 
    185 	// LogWaitAttempts is used to enable logging for waiter retry attempts
    186 	LogWaitAttempts bool
    187 
    188 	// Retryable is function that can be used to override the service defined
    189 	// waiter-behavior based on operation output, or returned error. This function is
    190 	// used by the waiter to decide if a state is retryable or a terminal state. By
    191 	// default service-modeled logic will populate this option. This option can thus be
    192 	// used to define a custom waiter state with fall-back to service-modeled waiter
    193 	// state mutators.The function returns an error in case of a failure state. In case
    194 	// of retry state, this function returns a bool value of true and nil error, while
    195 	// in case of success it returns a bool value of false and nil error.
    196 	Retryable func(context.Context, *GetChangeInput, *GetChangeOutput, error) (bool, error)
    197 }
    198 
    199 // ResourceRecordSetsChangedWaiter defines the waiters for
    200 // ResourceRecordSetsChanged
    201 type ResourceRecordSetsChangedWaiter struct {
    202 	client GetChangeAPIClient
    203 
    204 	options ResourceRecordSetsChangedWaiterOptions
    205 }
    206 
    207 // NewResourceRecordSetsChangedWaiter constructs a ResourceRecordSetsChangedWaiter.
    208 func NewResourceRecordSetsChangedWaiter(client GetChangeAPIClient, optFns ...func(*ResourceRecordSetsChangedWaiterOptions)) *ResourceRecordSetsChangedWaiter {
    209 	options := ResourceRecordSetsChangedWaiterOptions{}
    210 	options.MinDelay = 30 * time.Second
    211 	options.MaxDelay = 120 * time.Second
    212 	options.Retryable = resourceRecordSetsChangedStateRetryable
    213 
    214 	for _, fn := range optFns {
    215 		fn(&options)
    216 	}
    217 	return &ResourceRecordSetsChangedWaiter{
    218 		client:  client,
    219 		options: options,
    220 	}
    221 }
    222 
    223 // Wait calls the waiter function for ResourceRecordSetsChanged waiter. The
    224 // maxWaitDur is the maximum wait duration the waiter will wait. The maxWaitDur is
    225 // required and must be greater than zero.
    226 func (w *ResourceRecordSetsChangedWaiter) Wait(ctx context.Context, params *GetChangeInput, maxWaitDur time.Duration, optFns ...func(*ResourceRecordSetsChangedWaiterOptions)) error {
    227 	_, err := w.WaitForOutput(ctx, params, maxWaitDur, optFns...)
    228 	return err
    229 }
    230 
    231 // WaitForOutput calls the waiter function for ResourceRecordSetsChanged waiter
    232 // and returns the output of the successful operation. The maxWaitDur is the
    233 // maximum wait duration the waiter will wait. The maxWaitDur is required and must
    234 // be greater than zero.
    235 func (w *ResourceRecordSetsChangedWaiter) WaitForOutput(ctx context.Context, params *GetChangeInput, maxWaitDur time.Duration, optFns ...func(*ResourceRecordSetsChangedWaiterOptions)) (*GetChangeOutput, error) {
    236 	if maxWaitDur <= 0 {
    237 		return nil, fmt.Errorf("maximum wait time for waiter must be greater than zero")
    238 	}
    239 
    240 	options := w.options
    241 	for _, fn := range optFns {
    242 		fn(&options)
    243 	}
    244 
    245 	if options.MaxDelay <= 0 {
    246 		options.MaxDelay = 120 * time.Second
    247 	}
    248 
    249 	if options.MinDelay > options.MaxDelay {
    250 		return nil, fmt.Errorf("minimum waiter delay %v must be lesser than or equal to maximum waiter delay of %v.", options.MinDelay, options.MaxDelay)
    251 	}
    252 
    253 	ctx, cancelFn := context.WithTimeout(ctx, maxWaitDur)
    254 	defer cancelFn()
    255 
    256 	logger := smithywaiter.Logger{}
    257 	remainingTime := maxWaitDur
    258 
    259 	var attempt int64
    260 	for {
    261 
    262 		attempt++
    263 		apiOptions := options.APIOptions
    264 		start := time.Now()
    265 
    266 		if options.LogWaitAttempts {
    267 			logger.Attempt = attempt
    268 			apiOptions = append([]func(*middleware.Stack) error{}, options.APIOptions...)
    269 			apiOptions = append(apiOptions, logger.AddLogger)
    270 		}
    271 
    272 		out, err := w.client.GetChange(ctx, params, func(o *Options) {
    273 			o.APIOptions = append(o.APIOptions, apiOptions...)
    274 			for _, opt := range options.ClientOptions {
    275 				opt(o)
    276 			}
    277 		})
    278 
    279 		retryable, err := options.Retryable(ctx, params, out, err)
    280 		if err != nil {
    281 			return nil, err
    282 		}
    283 		if !retryable {
    284 			return out, nil
    285 		}
    286 
    287 		remainingTime -= time.Since(start)
    288 		if remainingTime < options.MinDelay || remainingTime <= 0 {
    289 			break
    290 		}
    291 
    292 		// compute exponential backoff between waiter retries
    293 		delay, err := smithywaiter.ComputeDelay(
    294 			attempt, options.MinDelay, options.MaxDelay, remainingTime,
    295 		)
    296 		if err != nil {
    297 			return nil, fmt.Errorf("error computing waiter delay, %w", err)
    298 		}
    299 
    300 		remainingTime -= delay
    301 		// sleep for the delay amount before invoking a request
    302 		if err := smithytime.SleepWithContext(ctx, delay); err != nil {
    303 			return nil, fmt.Errorf("request cancelled while waiting, %w", err)
    304 		}
    305 	}
    306 	return nil, fmt.Errorf("exceeded max wait time for ResourceRecordSetsChanged waiter")
    307 }
    308 
    309 func resourceRecordSetsChangedStateRetryable(ctx context.Context, input *GetChangeInput, output *GetChangeOutput, err error) (bool, error) {
    310 
    311 	if err == nil {
    312 		pathValue, err := jmespath.Search("ChangeInfo.Status", output)
    313 		if err != nil {
    314 			return false, fmt.Errorf("error evaluating waiter state: %w", err)
    315 		}
    316 
    317 		expectedValue := "INSYNC"
    318 		value, ok := pathValue.(types.ChangeStatus)
    319 		if !ok {
    320 			return false, fmt.Errorf("waiter comparator expected types.ChangeStatus value, got %T", pathValue)
    321 		}
    322 
    323 		if string(value) == expectedValue {
    324 			return false, nil
    325 		}
    326 	}
    327 
    328 	return true, nil
    329 }
    330 
    331 func newServiceMetadataMiddleware_opGetChange(region string) *awsmiddleware.RegisterServiceMetadata {
    332 	return &awsmiddleware.RegisterServiceMetadata{
    333 		Region:        region,
    334 		ServiceID:     ServiceID,
    335 		OperationName: "GetChange",
    336 	}
    337 }