-
Notifications
You must be signed in to change notification settings - Fork 642
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates SDK middleware values scoped to the stack being invoked
Updates the SDK's middleware metadata to be scoped to the individual stack's execution. This ensures that operations invoked nested within a stack will not be polluted with values from parent stack(s). Fixes #914
- Loading branch information
Showing
15 changed files
with
152 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,48 @@ | ||
package presignedurl | ||
|
||
import "context" | ||
import ( | ||
"context" | ||
|
||
// WithIsPresigning adds the isPresigning sentinal value to a context to signal | ||
"github.com/aws/smithy-go/middleware" | ||
) | ||
|
||
// WithIsPresigning adds the isPresigning sentinel value to a context to signal | ||
// that the middleware stack is using the presign flow. | ||
// | ||
// Scoped to stack values. Use github.com/aws/smithy-go/middleware#ClearStackValues | ||
// to clear all stack values. | ||
func WithIsPresigning(ctx context.Context) context.Context { | ||
return context.WithValue(ctx, isPresigning{}, true) | ||
return middleware.WithStackValue(ctx, isPresigningKey{}, true) | ||
} | ||
|
||
// GetIsPresigning returns if the context contains the isPresigning sentinel | ||
// value for presigning flows. | ||
// | ||
// Scoped to stack values. Use github.com/aws/smithy-go/middleware#ClearStackValues | ||
// to clear all stack values. | ||
func GetIsPresigning(ctx context.Context) bool { | ||
v := ctx.Value(isPresigning{}) | ||
if v == nil { | ||
return false | ||
} | ||
v, _ := middleware.GetStackValue(ctx, isPresigningKey{}).(bool) | ||
return v | ||
} | ||
|
||
type isPresigningKey struct{} | ||
|
||
return v.(bool) | ||
// AddAsIsPresigingMiddleware adds a middleware to the head of the stack that | ||
// will update the stack's context to be flagged as being invoked for the | ||
// purpose of presigning. | ||
func AddAsIsPresigingMiddleware(stack *middleware.Stack) error { | ||
return stack.Initialize.Add(asIsPresigningMiddleware{}, middleware.Before) | ||
} | ||
|
||
type isPresigning struct{} | ||
type asIsPresigningMiddleware struct{} | ||
|
||
func (asIsPresigningMiddleware) ID() string { return "AsIsPresigningMiddleware" } | ||
|
||
func (asIsPresigningMiddleware) HandleInitialize( | ||
ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler, | ||
) ( | ||
out middleware.InitializeOutput, metadata middleware.Metadata, err error, | ||
) { | ||
ctx = WithIsPresigning(ctx) | ||
return next.HandleInitialize(ctx, in) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.