context.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package presignedurl
  2. import (
  3. "context"
  4. "github.com/aws/smithy-go/middleware"
  5. )
  6. // WithIsPresigning adds the isPresigning sentinel value to a context to signal
  7. // that the middleware stack is using the presign flow.
  8. //
  9. // Scoped to stack values. Use github.com/aws/smithy-go/middleware#ClearStackValues
  10. // to clear all stack values.
  11. func WithIsPresigning(ctx context.Context) context.Context {
  12. return middleware.WithStackValue(ctx, isPresigningKey{}, true)
  13. }
  14. // GetIsPresigning returns if the context contains the isPresigning sentinel
  15. // value for presigning flows.
  16. //
  17. // Scoped to stack values. Use github.com/aws/smithy-go/middleware#ClearStackValues
  18. // to clear all stack values.
  19. func GetIsPresigning(ctx context.Context) bool {
  20. v, _ := middleware.GetStackValue(ctx, isPresigningKey{}).(bool)
  21. return v
  22. }
  23. type isPresigningKey struct{}
  24. // AddAsIsPresigningMiddleware adds a middleware to the head of the stack that
  25. // will update the stack's context to be flagged as being invoked for the
  26. // purpose of presigning.
  27. func AddAsIsPresigningMiddleware(stack *middleware.Stack) error {
  28. return stack.Initialize.Add(asIsPresigningMiddleware{}, middleware.Before)
  29. }
  30. // AddAsIsPresigingMiddleware is an alias for backwards compatibility.
  31. //
  32. // Deprecated: This API was released with a typo. Use
  33. // [AddAsIsPresigningMiddleware] instead.
  34. func AddAsIsPresigingMiddleware(stack *middleware.Stack) error {
  35. return AddAsIsPresigningMiddleware(stack)
  36. }
  37. type asIsPresigningMiddleware struct{}
  38. func (asIsPresigningMiddleware) ID() string { return "AsIsPresigningMiddleware" }
  39. func (asIsPresigningMiddleware) HandleInitialize(
  40. ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler,
  41. ) (
  42. out middleware.InitializeOutput, metadata middleware.Metadata, err error,
  43. ) {
  44. ctx = WithIsPresigning(ctx)
  45. return next.HandleInitialize(ctx, in)
  46. }