1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package lexmodelsv2 4 5import ( 6 "context" 7 "fmt" 8 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" 9 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" 10 "github.com/aws/aws-sdk-go-v2/service/lexmodelsv2/types" 11 "github.com/aws/smithy-go/middleware" 12 smithytime "github.com/aws/smithy-go/time" 13 smithyhttp "github.com/aws/smithy-go/transport/http" 14 smithywaiter "github.com/aws/smithy-go/waiter" 15 "github.com/jmespath/go-jmespath" 16 "time" 17) 18 19// Provides metadata information about a bot. 20func (c *Client) DescribeBot(ctx context.Context, params *DescribeBotInput, optFns ...func(*Options)) (*DescribeBotOutput, error) { 21 if params == nil { 22 params = &DescribeBotInput{} 23 } 24 25 result, metadata, err := c.invokeOperation(ctx, "DescribeBot", params, optFns, c.addOperationDescribeBotMiddlewares) 26 if err != nil { 27 return nil, err 28 } 29 30 out := result.(*DescribeBotOutput) 31 out.ResultMetadata = metadata 32 return out, nil 33} 34 35type DescribeBotInput struct { 36 37 // The unique identifier of the bot to describe. 38 // 39 // This member is required. 40 BotId *string 41 42 noSmithyDocumentSerde 43} 44 45type DescribeBotOutput struct { 46 47 // The unique identifier of the bot. 48 BotId *string 49 50 // The name of the bot. 51 BotName *string 52 53 // The current status of the bot. When the status is Available the bot is ready to 54 // be used in conversations with users. 55 BotStatus types.BotStatus 56 57 // A timestamp of the date and time that the bot was created. 58 CreationDateTime *time.Time 59 60 // Settings for managing data privacy of the bot and its conversations with users. 61 DataPrivacy *types.DataPrivacy 62 63 // The description of the bot. 64 Description *string 65 66 // The maximum time in seconds that Amazon Lex retains the data gathered in a 67 // conversation. 68 IdleSessionTTLInSeconds *int32 69 70 // A timestamp of the date and time that the bot was last updated. 71 LastUpdatedDateTime *time.Time 72 73 // The Amazon Resource Name (ARN) of an IAM role that has permission to access the 74 // bot. 75 RoleArn *string 76 77 // Metadata pertaining to the operation's result. 78 ResultMetadata middleware.Metadata 79 80 noSmithyDocumentSerde 81} 82 83func (c *Client) addOperationDescribeBotMiddlewares(stack *middleware.Stack, options Options) (err error) { 84 err = stack.Serialize.Add(&awsRestjson1_serializeOpDescribeBot{}, middleware.After) 85 if err != nil { 86 return err 87 } 88 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpDescribeBot{}, middleware.After) 89 if err != nil { 90 return err 91 } 92 if err = addSetLoggerMiddleware(stack, options); err != nil { 93 return err 94 } 95 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 96 return err 97 } 98 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 99 return err 100 } 101 if err = addResolveEndpointMiddleware(stack, options); err != nil { 102 return err 103 } 104 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 105 return err 106 } 107 if err = addRetryMiddlewares(stack, options); err != nil { 108 return err 109 } 110 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 111 return err 112 } 113 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 114 return err 115 } 116 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 117 return err 118 } 119 if err = addClientUserAgent(stack); err != nil { 120 return err 121 } 122 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 123 return err 124 } 125 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 126 return err 127 } 128 if err = addOpDescribeBotValidationMiddleware(stack); err != nil { 129 return err 130 } 131 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeBot(options.Region), middleware.Before); err != nil { 132 return err 133 } 134 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 135 return err 136 } 137 if err = addResponseErrorMiddleware(stack); err != nil { 138 return err 139 } 140 if err = addRequestResponseLogging(stack, options); err != nil { 141 return err 142 } 143 return nil 144} 145 146// DescribeBotAPIClient is a client that implements the DescribeBot operation. 147type DescribeBotAPIClient interface { 148 DescribeBot(context.Context, *DescribeBotInput, ...func(*Options)) (*DescribeBotOutput, error) 149} 150 151var _ DescribeBotAPIClient = (*Client)(nil) 152 153// BotAvailableWaiterOptions are waiter options for BotAvailableWaiter 154type BotAvailableWaiterOptions struct { 155 156 // Set of options to modify how an operation is invoked. These apply to all 157 // operations invoked for this client. Use functional options on operation call to 158 // modify this list for per operation behavior. 159 APIOptions []func(*middleware.Stack) error 160 161 // MinDelay is the minimum amount of time to delay between retries. If unset, 162 // BotAvailableWaiter will use default minimum delay of 10 seconds. Note that 163 // MinDelay must resolve to a value lesser than or equal to the MaxDelay. 164 MinDelay time.Duration 165 166 // MaxDelay is the maximum amount of time to delay between retries. If unset or set 167 // to zero, BotAvailableWaiter will use default max delay of 120 seconds. Note that 168 // MaxDelay must resolve to value greater than or equal to the MinDelay. 169 MaxDelay time.Duration 170 171 // LogWaitAttempts is used to enable logging for waiter retry attempts 172 LogWaitAttempts bool 173 174 // Retryable is function that can be used to override the service defined 175 // waiter-behavior based on operation output, or returned error. This function is 176 // used by the waiter to decide if a state is retryable or a terminal state. By 177 // default service-modeled logic will populate this option. This option can thus be 178 // used to define a custom waiter state with fall-back to service-modeled waiter 179 // state mutators.The function returns an error in case of a failure state. In case 180 // of retry state, this function returns a bool value of true and nil error, while 181 // in case of success it returns a bool value of false and nil error. 182 Retryable func(context.Context, *DescribeBotInput, *DescribeBotOutput, error) (bool, error) 183} 184 185// BotAvailableWaiter defines the waiters for BotAvailable 186type BotAvailableWaiter struct { 187 client DescribeBotAPIClient 188 189 options BotAvailableWaiterOptions 190} 191 192// NewBotAvailableWaiter constructs a BotAvailableWaiter. 193func NewBotAvailableWaiter(client DescribeBotAPIClient, optFns ...func(*BotAvailableWaiterOptions)) *BotAvailableWaiter { 194 options := BotAvailableWaiterOptions{} 195 options.MinDelay = 10 * time.Second 196 options.MaxDelay = 120 * time.Second 197 options.Retryable = botAvailableStateRetryable 198 199 for _, fn := range optFns { 200 fn(&options) 201 } 202 return &BotAvailableWaiter{ 203 client: client, 204 options: options, 205 } 206} 207 208// Wait calls the waiter function for BotAvailable waiter. The maxWaitDur is the 209// maximum wait duration the waiter will wait. The maxWaitDur is required and must 210// be greater than zero. 211func (w *BotAvailableWaiter) Wait(ctx context.Context, params *DescribeBotInput, maxWaitDur time.Duration, optFns ...func(*BotAvailableWaiterOptions)) error { 212 if maxWaitDur <= 0 { 213 return fmt.Errorf("maximum wait time for waiter must be greater than zero") 214 } 215 216 options := w.options 217 for _, fn := range optFns { 218 fn(&options) 219 } 220 221 if options.MaxDelay <= 0 { 222 options.MaxDelay = 120 * time.Second 223 } 224 225 if options.MinDelay > options.MaxDelay { 226 return fmt.Errorf("minimum waiter delay %v must be lesser than or equal to maximum waiter delay of %v.", options.MinDelay, options.MaxDelay) 227 } 228 229 ctx, cancelFn := context.WithTimeout(ctx, maxWaitDur) 230 defer cancelFn() 231 232 logger := smithywaiter.Logger{} 233 remainingTime := maxWaitDur 234 235 var attempt int64 236 for { 237 238 attempt++ 239 apiOptions := options.APIOptions 240 start := time.Now() 241 242 if options.LogWaitAttempts { 243 logger.Attempt = attempt 244 apiOptions = append([]func(*middleware.Stack) error{}, options.APIOptions...) 245 apiOptions = append(apiOptions, logger.AddLogger) 246 } 247 248 out, err := w.client.DescribeBot(ctx, params, func(o *Options) { 249 o.APIOptions = append(o.APIOptions, apiOptions...) 250 }) 251 252 retryable, err := options.Retryable(ctx, params, out, err) 253 if err != nil { 254 return err 255 } 256 if !retryable { 257 return nil 258 } 259 260 remainingTime -= time.Since(start) 261 if remainingTime < options.MinDelay || remainingTime <= 0 { 262 break 263 } 264 265 // compute exponential backoff between waiter retries 266 delay, err := smithywaiter.ComputeDelay( 267 attempt, options.MinDelay, options.MaxDelay, remainingTime, 268 ) 269 if err != nil { 270 return fmt.Errorf("error computing waiter delay, %w", err) 271 } 272 273 remainingTime -= delay 274 // sleep for the delay amount before invoking a request 275 if err := smithytime.SleepWithContext(ctx, delay); err != nil { 276 return fmt.Errorf("request cancelled while waiting, %w", err) 277 } 278 } 279 return fmt.Errorf("exceeded max wait time for BotAvailable waiter") 280} 281 282func botAvailableStateRetryable(ctx context.Context, input *DescribeBotInput, output *DescribeBotOutput, err error) (bool, error) { 283 284 if err == nil { 285 pathValue, err := jmespath.Search("botStatus", output) 286 if err != nil { 287 return false, fmt.Errorf("error evaluating waiter state: %w", err) 288 } 289 290 expectedValue := "Available" 291 value, ok := pathValue.(types.BotStatus) 292 if !ok { 293 return false, fmt.Errorf("waiter comparator expected types.BotStatus value, got %T", pathValue) 294 } 295 296 if string(value) == expectedValue { 297 return false, nil 298 } 299 } 300 301 if err == nil { 302 pathValue, err := jmespath.Search("botStatus", output) 303 if err != nil { 304 return false, fmt.Errorf("error evaluating waiter state: %w", err) 305 } 306 307 expectedValue := "Deleting" 308 value, ok := pathValue.(types.BotStatus) 309 if !ok { 310 return false, fmt.Errorf("waiter comparator expected types.BotStatus value, got %T", pathValue) 311 } 312 313 if string(value) == expectedValue { 314 return false, fmt.Errorf("waiter state transitioned to Failure") 315 } 316 } 317 318 if err == nil { 319 pathValue, err := jmespath.Search("botStatus", output) 320 if err != nil { 321 return false, fmt.Errorf("error evaluating waiter state: %w", err) 322 } 323 324 expectedValue := "Failed" 325 value, ok := pathValue.(types.BotStatus) 326 if !ok { 327 return false, fmt.Errorf("waiter comparator expected types.BotStatus value, got %T", pathValue) 328 } 329 330 if string(value) == expectedValue { 331 return false, fmt.Errorf("waiter state transitioned to Failure") 332 } 333 } 334 335 if err == nil { 336 pathValue, err := jmespath.Search("botStatus", output) 337 if err != nil { 338 return false, fmt.Errorf("error evaluating waiter state: %w", err) 339 } 340 341 expectedValue := "Inactive" 342 value, ok := pathValue.(types.BotStatus) 343 if !ok { 344 return false, fmt.Errorf("waiter comparator expected types.BotStatus value, got %T", pathValue) 345 } 346 347 if string(value) == expectedValue { 348 return false, fmt.Errorf("waiter state transitioned to Failure") 349 } 350 } 351 352 return true, nil 353} 354 355func newServiceMetadataMiddleware_opDescribeBot(region string) *awsmiddleware.RegisterServiceMetadata { 356 return &awsmiddleware.RegisterServiceMetadata{ 357 Region: region, 358 ServiceID: ServiceID, 359 SigningName: "lex", 360 OperationName: "DescribeBot", 361 } 362} 363