1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package signer 4 5import ( 6 "context" 7 "errors" 8 "fmt" 9 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" 10 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" 11 "github.com/aws/aws-sdk-go-v2/service/signer/types" 12 "github.com/aws/smithy-go/middleware" 13 smithytime "github.com/aws/smithy-go/time" 14 smithyhttp "github.com/aws/smithy-go/transport/http" 15 smithywaiter "github.com/aws/smithy-go/waiter" 16 "github.com/jmespath/go-jmespath" 17 "time" 18) 19 20// Returns information about a specific code signing job. You specify the job by 21// using the jobId value that is returned by the StartSigningJob operation. 22func (c *Client) DescribeSigningJob(ctx context.Context, params *DescribeSigningJobInput, optFns ...func(*Options)) (*DescribeSigningJobOutput, error) { 23 if params == nil { 24 params = &DescribeSigningJobInput{} 25 } 26 27 result, metadata, err := c.invokeOperation(ctx, "DescribeSigningJob", params, optFns, addOperationDescribeSigningJobMiddlewares) 28 if err != nil { 29 return nil, err 30 } 31 32 out := result.(*DescribeSigningJobOutput) 33 out.ResultMetadata = metadata 34 return out, nil 35} 36 37type DescribeSigningJobInput struct { 38 39 // The ID of the signing job on input. 40 // 41 // This member is required. 42 JobId *string 43} 44 45type DescribeSigningJobOutput struct { 46 47 // Date and time that the signing job was completed. 48 CompletedAt *time.Time 49 50 // Date and time that the signing job was created. 51 CreatedAt *time.Time 52 53 // The ID of the signing job on output. 54 JobId *string 55 56 // The IAM entity that initiated the signing job. 57 JobInvoker *string 58 59 // The AWS account ID of the job owner. 60 JobOwner *string 61 62 // A list of any overrides that were applied to the signing operation. 63 Overrides *types.SigningPlatformOverrides 64 65 // A human-readable name for the signing platform associated with the signing job. 66 PlatformDisplayName *string 67 68 // The microcontroller platform to which your signed code image will be 69 // distributed. 70 PlatformId *string 71 72 // The name of the profile that initiated the signing operation. 73 ProfileName *string 74 75 // The version of the signing profile used to initiate the signing job. 76 ProfileVersion *string 77 78 // The IAM principal that requested the signing job. 79 RequestedBy *string 80 81 // A revocation record if the signature generated by the signing job has been 82 // revoked. Contains a timestamp and the ID of the IAM entity that revoked the 83 // signature. 84 RevocationRecord *types.SigningJobRevocationRecord 85 86 // Thr expiration timestamp for the signature generated by the signing job. 87 SignatureExpiresAt *time.Time 88 89 // Name of the S3 bucket where the signed code image is saved by code signing. 90 SignedObject *types.SignedObject 91 92 // The Amazon Resource Name (ARN) of your code signing certificate. 93 SigningMaterial *types.SigningMaterial 94 95 // Map of user-assigned key-value pairs used during signing. These values contain 96 // any information that you specified for use in your signing job. 97 SigningParameters map[string]string 98 99 // The object that contains the name of your S3 bucket or your raw code. 100 Source *types.Source 101 102 // Status of the signing job. 103 Status types.SigningStatus 104 105 // String value that contains the status reason. 106 StatusReason *string 107 108 // Metadata pertaining to the operation's result. 109 ResultMetadata middleware.Metadata 110} 111 112func addOperationDescribeSigningJobMiddlewares(stack *middleware.Stack, options Options) (err error) { 113 err = stack.Serialize.Add(&awsRestjson1_serializeOpDescribeSigningJob{}, middleware.After) 114 if err != nil { 115 return err 116 } 117 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpDescribeSigningJob{}, middleware.After) 118 if err != nil { 119 return err 120 } 121 if err = addSetLoggerMiddleware(stack, options); err != nil { 122 return err 123 } 124 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 125 return err 126 } 127 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 128 return err 129 } 130 if err = addResolveEndpointMiddleware(stack, options); err != nil { 131 return err 132 } 133 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 134 return err 135 } 136 if err = addRetryMiddlewares(stack, options); err != nil { 137 return err 138 } 139 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 140 return err 141 } 142 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 143 return err 144 } 145 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 146 return err 147 } 148 if err = addClientUserAgent(stack); err != nil { 149 return err 150 } 151 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 152 return err 153 } 154 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 155 return err 156 } 157 if err = addOpDescribeSigningJobValidationMiddleware(stack); err != nil { 158 return err 159 } 160 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeSigningJob(options.Region), middleware.Before); err != nil { 161 return err 162 } 163 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 164 return err 165 } 166 if err = addResponseErrorMiddleware(stack); err != nil { 167 return err 168 } 169 if err = addRequestResponseLogging(stack, options); err != nil { 170 return err 171 } 172 return nil 173} 174 175// DescribeSigningJobAPIClient is a client that implements the DescribeSigningJob 176// operation. 177type DescribeSigningJobAPIClient interface { 178 DescribeSigningJob(context.Context, *DescribeSigningJobInput, ...func(*Options)) (*DescribeSigningJobOutput, error) 179} 180 181var _ DescribeSigningJobAPIClient = (*Client)(nil) 182 183// SuccessfulSigningJobWaiterOptions are waiter options for 184// SuccessfulSigningJobWaiter 185type SuccessfulSigningJobWaiterOptions struct { 186 187 // Set of options to modify how an operation is invoked. These apply to all 188 // operations invoked for this client. Use functional options on operation call to 189 // modify this list for per operation behavior. 190 APIOptions []func(*middleware.Stack) error 191 192 // MinDelay is the minimum amount of time to delay between retries. If unset, 193 // SuccessfulSigningJobWaiter will use default minimum delay of 20 seconds. Note 194 // that MinDelay must resolve to a value lesser than or equal to the MaxDelay. 195 MinDelay time.Duration 196 197 // MaxDelay is the maximum amount of time to delay between retries. If unset or set 198 // to zero, SuccessfulSigningJobWaiter will use default max delay of 120 seconds. 199 // Note that MaxDelay must resolve to value greater than or equal to the MinDelay. 200 MaxDelay time.Duration 201 202 // LogWaitAttempts is used to enable logging for waiter retry attempts 203 LogWaitAttempts bool 204 205 // Retryable is function that can be used to override the service defined 206 // waiter-behavior based on operation output, or returned error. This function is 207 // used by the waiter to decide if a state is retryable or a terminal state. By 208 // default service-modeled logic will populate this option. This option can thus be 209 // used to define a custom waiter state with fall-back to service-modeled waiter 210 // state mutators.The function returns an error in case of a failure state. In case 211 // of retry state, this function returns a bool value of true and nil error, while 212 // in case of success it returns a bool value of false and nil error. 213 Retryable func(context.Context, *DescribeSigningJobInput, *DescribeSigningJobOutput, error) (bool, error) 214} 215 216// SuccessfulSigningJobWaiter defines the waiters for SuccessfulSigningJob 217type SuccessfulSigningJobWaiter struct { 218 client DescribeSigningJobAPIClient 219 220 options SuccessfulSigningJobWaiterOptions 221} 222 223// NewSuccessfulSigningJobWaiter constructs a SuccessfulSigningJobWaiter. 224func NewSuccessfulSigningJobWaiter(client DescribeSigningJobAPIClient, optFns ...func(*SuccessfulSigningJobWaiterOptions)) *SuccessfulSigningJobWaiter { 225 options := SuccessfulSigningJobWaiterOptions{} 226 options.MinDelay = 20 * time.Second 227 options.MaxDelay = 120 * time.Second 228 options.Retryable = successfulSigningJobStateRetryable 229 230 for _, fn := range optFns { 231 fn(&options) 232 } 233 return &SuccessfulSigningJobWaiter{ 234 client: client, 235 options: options, 236 } 237} 238 239// Wait calls the waiter function for SuccessfulSigningJob waiter. The maxWaitDur 240// is the maximum wait duration the waiter will wait. The maxWaitDur is required 241// and must be greater than zero. 242func (w *SuccessfulSigningJobWaiter) Wait(ctx context.Context, params *DescribeSigningJobInput, maxWaitDur time.Duration, optFns ...func(*SuccessfulSigningJobWaiterOptions)) error { 243 if maxWaitDur <= 0 { 244 return fmt.Errorf("maximum wait time for waiter must be greater than zero") 245 } 246 247 options := w.options 248 for _, fn := range optFns { 249 fn(&options) 250 } 251 252 if options.MaxDelay <= 0 { 253 options.MaxDelay = 120 * time.Second 254 } 255 256 if options.MinDelay > options.MaxDelay { 257 return fmt.Errorf("minimum waiter delay %v must be lesser than or equal to maximum waiter delay of %v.", options.MinDelay, options.MaxDelay) 258 } 259 260 ctx, cancelFn := context.WithTimeout(ctx, maxWaitDur) 261 defer cancelFn() 262 263 logger := smithywaiter.Logger{} 264 remainingTime := maxWaitDur 265 266 var attempt int64 267 for { 268 269 attempt++ 270 apiOptions := options.APIOptions 271 start := time.Now() 272 273 if options.LogWaitAttempts { 274 logger.Attempt = attempt 275 apiOptions = append([]func(*middleware.Stack) error{}, options.APIOptions...) 276 apiOptions = append(apiOptions, logger.AddLogger) 277 } 278 279 out, err := w.client.DescribeSigningJob(ctx, params, func(o *Options) { 280 o.APIOptions = append(o.APIOptions, apiOptions...) 281 }) 282 283 retryable, err := options.Retryable(ctx, params, out, err) 284 if err != nil { 285 return err 286 } 287 if !retryable { 288 return nil 289 } 290 291 remainingTime -= time.Since(start) 292 if remainingTime < options.MinDelay || remainingTime <= 0 { 293 break 294 } 295 296 // compute exponential backoff between waiter retries 297 delay, err := smithywaiter.ComputeDelay( 298 attempt, options.MinDelay, options.MaxDelay, remainingTime, 299 ) 300 if err != nil { 301 return fmt.Errorf("error computing waiter delay, %w", err) 302 } 303 304 remainingTime -= delay 305 // sleep for the delay amount before invoking a request 306 if err := smithytime.SleepWithContext(ctx, delay); err != nil { 307 return fmt.Errorf("request cancelled while waiting, %w", err) 308 } 309 } 310 return fmt.Errorf("exceeded max wait time for SuccessfulSigningJob waiter") 311} 312 313func successfulSigningJobStateRetryable(ctx context.Context, input *DescribeSigningJobInput, output *DescribeSigningJobOutput, err error) (bool, error) { 314 315 if err == nil { 316 pathValue, err := jmespath.Search("status", output) 317 if err != nil { 318 return false, fmt.Errorf("error evaluating waiter state: %w", err) 319 } 320 321 expectedValue := "Succeeded" 322 value, ok := pathValue.(types.SigningStatus) 323 if !ok { 324 return false, fmt.Errorf("waiter comparator expected types.SigningStatus value, got %T", pathValue) 325 } 326 327 if string(value) == expectedValue { 328 return false, nil 329 } 330 } 331 332 if err == nil { 333 pathValue, err := jmespath.Search("status", output) 334 if err != nil { 335 return false, fmt.Errorf("error evaluating waiter state: %w", err) 336 } 337 338 expectedValue := "Failed" 339 value, ok := pathValue.(types.SigningStatus) 340 if !ok { 341 return false, fmt.Errorf("waiter comparator expected types.SigningStatus value, got %T", pathValue) 342 } 343 344 if string(value) == expectedValue { 345 return false, fmt.Errorf("waiter state transitioned to Failure") 346 } 347 } 348 349 if err != nil { 350 var errorType *types.ResourceNotFoundException 351 if errors.As(err, &errorType) { 352 return false, fmt.Errorf("waiter state transitioned to Failure") 353 } 354 } 355 356 return true, nil 357} 358 359func newServiceMetadataMiddleware_opDescribeSigningJob(region string) *awsmiddleware.RegisterServiceMetadata { 360 return &awsmiddleware.RegisterServiceMetadata{ 361 Region: region, 362 ServiceID: ServiceID, 363 SigningName: "signer", 364 OperationName: "DescribeSigningJob", 365 } 366} 367