src

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

context.go (1868B)


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