metadata.go (7661B)
1 package middleware 2 3 import ( 4 "context" 5 6 "github.com/aws/aws-sdk-go-v2/aws" 7 8 "github.com/aws/smithy-go/middleware" 9 ) 10 11 // RegisterServiceMetadata registers metadata about the service and operation into the middleware context 12 // so that it is available at runtime for other middleware to introspect. 13 type RegisterServiceMetadata struct { 14 ServiceID string 15 SigningName string 16 Region string 17 OperationName string 18 } 19 20 // ID returns the middleware identifier. 21 func (s *RegisterServiceMetadata) ID() string { 22 return "RegisterServiceMetadata" 23 } 24 25 // HandleInitialize registers service metadata information into the middleware context, allowing for introspection. 26 func (s RegisterServiceMetadata) HandleInitialize( 27 ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler, 28 ) (out middleware.InitializeOutput, metadata middleware.Metadata, err error) { 29 if len(s.ServiceID) > 0 { 30 ctx = SetServiceID(ctx, s.ServiceID) 31 } 32 if len(s.SigningName) > 0 { 33 ctx = SetSigningName(ctx, s.SigningName) 34 } 35 if len(s.Region) > 0 { 36 ctx = setRegion(ctx, s.Region) 37 } 38 if len(s.OperationName) > 0 { 39 ctx = setOperationName(ctx, s.OperationName) 40 } 41 return next.HandleInitialize(ctx, in) 42 } 43 44 // service metadata keys for storing and lookup of runtime stack information. 45 type ( 46 serviceIDKey struct{} 47 signingNameKey struct{} 48 signingRegionKey struct{} 49 regionKey struct{} 50 operationNameKey struct{} 51 partitionIDKey struct{} 52 requiresLegacyEndpointsKey struct{} 53 ) 54 55 // GetServiceID retrieves the service id from the context. 56 // 57 // Scoped to stack values. Use github.com/aws/smithy-go/middleware#ClearStackValues 58 // to clear all stack values. 59 func GetServiceID(ctx context.Context) (v string) { 60 v, _ = middleware.GetStackValue(ctx, serviceIDKey{}).(string) 61 return v 62 } 63 64 // GetSigningName retrieves the service signing name from the context. 65 // 66 // Scoped to stack values. Use github.com/aws/smithy-go/middleware#ClearStackValues 67 // to clear all stack values. 68 // 69 // Deprecated: This value is unstable. The resolved signing name is available 70 // in the signer properties object passed to the signer. 71 func GetSigningName(ctx context.Context) (v string) { 72 v, _ = middleware.GetStackValue(ctx, signingNameKey{}).(string) 73 return v 74 } 75 76 // GetSigningRegion retrieves the region from the context. 77 // 78 // Scoped to stack values. Use github.com/aws/smithy-go/middleware#ClearStackValues 79 // to clear all stack values. 80 // 81 // Deprecated: This value is unstable. The resolved signing region is available 82 // in the signer properties object passed to the signer. 83 func GetSigningRegion(ctx context.Context) (v string) { 84 v, _ = middleware.GetStackValue(ctx, signingRegionKey{}).(string) 85 return v 86 } 87 88 // GetRegion retrieves the endpoint region from the context. 89 // 90 // Scoped to stack values. Use github.com/aws/smithy-go/middleware#ClearStackValues 91 // to clear all stack values. 92 func GetRegion(ctx context.Context) (v string) { 93 v, _ = middleware.GetStackValue(ctx, regionKey{}).(string) 94 return v 95 } 96 97 // GetOperationName retrieves the service operation metadata from the context. 98 // 99 // Scoped to stack values. Use github.com/aws/smithy-go/middleware#ClearStackValues 100 // to clear all stack values. 101 func GetOperationName(ctx context.Context) (v string) { 102 v, _ = middleware.GetStackValue(ctx, operationNameKey{}).(string) 103 return v 104 } 105 106 // GetPartitionID retrieves the endpoint partition id from the context. 107 // 108 // Scoped to stack values. Use github.com/aws/smithy-go/middleware#ClearStackValues 109 // to clear all stack values. 110 func GetPartitionID(ctx context.Context) string { 111 v, _ := middleware.GetStackValue(ctx, partitionIDKey{}).(string) 112 return v 113 } 114 115 // GetRequiresLegacyEndpoints the flag used to indicate if legacy endpoint 116 // customizations need to be executed. 117 // 118 // Scoped to stack values. Use github.com/aws/smithy-go/middleware#ClearStackValues 119 // to clear all stack values. 120 func GetRequiresLegacyEndpoints(ctx context.Context) bool { 121 v, _ := middleware.GetStackValue(ctx, requiresLegacyEndpointsKey{}).(bool) 122 return v 123 } 124 125 // SetRequiresLegacyEndpoints set or modifies the flag indicated that 126 // legacy endpoint customizations are needed. 127 // 128 // Scoped to stack values. Use github.com/aws/smithy-go/middleware#ClearStackValues 129 // to clear all stack values. 130 func SetRequiresLegacyEndpoints(ctx context.Context, value bool) context.Context { 131 return middleware.WithStackValue(ctx, requiresLegacyEndpointsKey{}, value) 132 } 133 134 // SetSigningName set or modifies the sigv4 or sigv4a signing name on the context. 135 // 136 // Scoped to stack values. Use github.com/aws/smithy-go/middleware#ClearStackValues 137 // to clear all stack values. 138 // 139 // Deprecated: This value is unstable. Use WithSigV4SigningName client option 140 // funcs instead. 141 func SetSigningName(ctx context.Context, value string) context.Context { 142 return middleware.WithStackValue(ctx, signingNameKey{}, value) 143 } 144 145 // SetSigningRegion sets or modifies the region on the context. 146 // 147 // Scoped to stack values. Use github.com/aws/smithy-go/middleware#ClearStackValues 148 // to clear all stack values. 149 // 150 // Deprecated: This value is unstable. Use WithSigV4SigningRegion client option 151 // funcs instead. 152 func SetSigningRegion(ctx context.Context, value string) context.Context { 153 return middleware.WithStackValue(ctx, signingRegionKey{}, value) 154 } 155 156 // SetServiceID sets the service id on the context. 157 // 158 // Scoped to stack values. Use github.com/aws/smithy-go/middleware#ClearStackValues 159 // to clear all stack values. 160 func SetServiceID(ctx context.Context, value string) context.Context { 161 return middleware.WithStackValue(ctx, serviceIDKey{}, value) 162 } 163 164 // setRegion sets the endpoint region on the context. 165 // 166 // Scoped to stack values. Use github.com/aws/smithy-go/middleware#ClearStackValues 167 // to clear all stack values. 168 func setRegion(ctx context.Context, value string) context.Context { 169 return middleware.WithStackValue(ctx, regionKey{}, value) 170 } 171 172 // setOperationName sets the service operation on the context. 173 // 174 // Scoped to stack values. Use github.com/aws/smithy-go/middleware#ClearStackValues 175 // to clear all stack values. 176 func setOperationName(ctx context.Context, value string) context.Context { 177 return middleware.WithStackValue(ctx, operationNameKey{}, value) 178 } 179 180 // SetPartitionID sets the partition id of a resolved region on the context 181 // 182 // Scoped to stack values. Use github.com/aws/smithy-go/middleware#ClearStackValues 183 // to clear all stack values. 184 func SetPartitionID(ctx context.Context, value string) context.Context { 185 return middleware.WithStackValue(ctx, partitionIDKey{}, value) 186 } 187 188 // EndpointSource key 189 type endpointSourceKey struct{} 190 191 // GetEndpointSource returns an endpoint source if set on context 192 func GetEndpointSource(ctx context.Context) (v aws.EndpointSource) { 193 v, _ = middleware.GetStackValue(ctx, endpointSourceKey{}).(aws.EndpointSource) 194 return v 195 } 196 197 // SetEndpointSource sets endpoint source on context 198 func SetEndpointSource(ctx context.Context, value aws.EndpointSource) context.Context { 199 return middleware.WithStackValue(ctx, endpointSourceKey{}, value) 200 } 201 202 type signingCredentialsKey struct{} 203 204 // GetSigningCredentials returns the credentials that were used for signing if set on context. 205 func GetSigningCredentials(ctx context.Context) (v aws.Credentials) { 206 v, _ = middleware.GetStackValue(ctx, signingCredentialsKey{}).(aws.Credentials) 207 return v 208 } 209 210 // SetSigningCredentials sets the credentails used for signing on the context. 211 func SetSigningCredentials(ctx context.Context, value aws.Credentials) context.Context { 212 return middleware.WithStackValue(ctx, signingCredentialsKey{}, value) 213 }