src

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

context.go (1585B)


      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 // AddAsIsPresigingMiddleware 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 AddAsIsPresigingMiddleware(stack *middleware.Stack) error {
     34 	return stack.Initialize.Add(asIsPresigningMiddleware{}, middleware.Before)
     35 }
     36 
     37 type asIsPresigningMiddleware struct{}
     38 
     39 func (asIsPresigningMiddleware) ID() string { return "AsIsPresigningMiddleware" }
     40 
     41 func (asIsPresigningMiddleware) HandleInitialize(
     42 	ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler,
     43 ) (
     44 	out middleware.InitializeOutput, metadata middleware.Metadata, err error,
     45 ) {
     46 	ctx = WithIsPresigning(ctx)
     47 	return next.HandleInitialize(ctx, in)
     48 }