api_op_GetCallerIdentity.go raw

   1  // Code generated by smithy-go-codegen DO NOT EDIT.
   2  
   3  package sts
   4  
   5  import (
   6  	"context"
   7  	"fmt"
   8  	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
   9  	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
  10  	"github.com/aws/smithy-go/middleware"
  11  	smithyhttp "github.com/aws/smithy-go/transport/http"
  12  )
  13  
  14  // Returns details about the IAM user or role whose credentials are used to call
  15  // the operation.
  16  //
  17  // No permissions are required to perform this operation. If an administrator
  18  // attaches a policy to your identity that explicitly denies access to the
  19  // sts:GetCallerIdentity action, you can still perform this operation. Permissions
  20  // are not required because the same information is returned when access is denied.
  21  // To view an example response, see [I Am Not Authorized to Perform: iam:DeleteVirtualMFADevice]in the IAM User Guide.
  22  //
  23  // [I Am Not Authorized to Perform: iam:DeleteVirtualMFADevice]: https://docs.aws.amazon.com/IAM/latest/UserGuide/troubleshoot_general.html#troubleshoot_general_access-denied-delete-mfa
  24  func (c *Client) GetCallerIdentity(ctx context.Context, params *GetCallerIdentityInput, optFns ...func(*Options)) (*GetCallerIdentityOutput, error) {
  25  	if params == nil {
  26  		params = &GetCallerIdentityInput{}
  27  	}
  28  
  29  	result, metadata, err := c.invokeOperation(ctx, "GetCallerIdentity", params, optFns, c.addOperationGetCallerIdentityMiddlewares)
  30  	if err != nil {
  31  		return nil, err
  32  	}
  33  
  34  	out := result.(*GetCallerIdentityOutput)
  35  	out.ResultMetadata = metadata
  36  	return out, nil
  37  }
  38  
  39  type GetCallerIdentityInput struct {
  40  	noSmithyDocumentSerde
  41  }
  42  
  43  // Contains the response to a successful GetCallerIdentity request, including information about the
  44  // entity making the request.
  45  type GetCallerIdentityOutput struct {
  46  
  47  	// The Amazon Web Services account ID number of the account that owns or contains
  48  	// the calling entity.
  49  	Account *string
  50  
  51  	// The Amazon Web Services ARN associated with the calling entity.
  52  	Arn *string
  53  
  54  	// The unique identifier of the calling entity. The exact value depends on the
  55  	// type of entity that is making the call. The values returned are those listed in
  56  	// the aws:userid column in the [Principal table]found on the Policy Variables reference page in
  57  	// the IAM User Guide.
  58  	//
  59  	// [Principal table]: https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_variables.html#principaltable
  60  	UserId *string
  61  
  62  	// Metadata pertaining to the operation's result.
  63  	ResultMetadata middleware.Metadata
  64  
  65  	noSmithyDocumentSerde
  66  }
  67  
  68  func (c *Client) addOperationGetCallerIdentityMiddlewares(stack *middleware.Stack, options Options) (err error) {
  69  	if err := stack.Serialize.Add(&setOperationInputMiddleware{}, middleware.After); err != nil {
  70  		return err
  71  	}
  72  	err = stack.Serialize.Add(&awsAwsquery_serializeOpGetCallerIdentity{}, middleware.After)
  73  	if err != nil {
  74  		return err
  75  	}
  76  	err = stack.Deserialize.Add(&awsAwsquery_deserializeOpGetCallerIdentity{}, middleware.After)
  77  	if err != nil {
  78  		return err
  79  	}
  80  	if err := addProtocolFinalizerMiddlewares(stack, options, "GetCallerIdentity"); err != nil {
  81  		return fmt.Errorf("add protocol finalizers: %v", err)
  82  	}
  83  
  84  	if err = addlegacyEndpointContextSetter(stack, options); err != nil {
  85  		return err
  86  	}
  87  	if err = addSetLoggerMiddleware(stack, options); err != nil {
  88  		return err
  89  	}
  90  	if err = addClientRequestID(stack); err != nil {
  91  		return err
  92  	}
  93  	if err = addComputeContentLength(stack); err != nil {
  94  		return err
  95  	}
  96  	if err = addResolveEndpointMiddleware(stack, options); err != nil {
  97  		return err
  98  	}
  99  	if err = addComputePayloadSHA256(stack); err != nil {
 100  		return err
 101  	}
 102  	if err = addRetry(stack, options); err != nil {
 103  		return err
 104  	}
 105  	if err = addRawResponseToMetadata(stack); err != nil {
 106  		return err
 107  	}
 108  	if err = addRecordResponseTiming(stack); err != nil {
 109  		return err
 110  	}
 111  	if err = addSpanRetryLoop(stack, options); err != nil {
 112  		return err
 113  	}
 114  	if err = addClientUserAgent(stack, options); err != nil {
 115  		return err
 116  	}
 117  	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
 118  		return err
 119  	}
 120  	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
 121  		return err
 122  	}
 123  	if err = addSetLegacyContextSigningOptionsMiddleware(stack); err != nil {
 124  		return err
 125  	}
 126  	if err = addTimeOffsetBuild(stack, c); err != nil {
 127  		return err
 128  	}
 129  	if err = addUserAgentRetryMode(stack, options); err != nil {
 130  		return err
 131  	}
 132  	if err = addCredentialSource(stack, options); err != nil {
 133  		return err
 134  	}
 135  	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetCallerIdentity(options.Region), middleware.Before); err != nil {
 136  		return err
 137  	}
 138  	if err = addRecursionDetection(stack); err != nil {
 139  		return err
 140  	}
 141  	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
 142  		return err
 143  	}
 144  	if err = addResponseErrorMiddleware(stack); err != nil {
 145  		return err
 146  	}
 147  	if err = addRequestResponseLogging(stack, options); err != nil {
 148  		return err
 149  	}
 150  	if err = addDisableHTTPSMiddleware(stack, options); err != nil {
 151  		return err
 152  	}
 153  	if err = addInterceptBeforeRetryLoop(stack, options); err != nil {
 154  		return err
 155  	}
 156  	if err = addInterceptAttempt(stack, options); err != nil {
 157  		return err
 158  	}
 159  	if err = addInterceptors(stack, options); err != nil {
 160  		return err
 161  	}
 162  	return nil
 163  }
 164  
 165  func newServiceMetadataMiddleware_opGetCallerIdentity(region string) *awsmiddleware.RegisterServiceMetadata {
 166  	return &awsmiddleware.RegisterServiceMetadata{
 167  		Region:        region,
 168  		ServiceID:     ServiceID,
 169  		OperationName: "GetCallerIdentity",
 170  	}
 171  }
 172  
 173  // PresignGetCallerIdentity is used to generate a presigned HTTP Request which
 174  // contains presigned URL, signed headers and HTTP method used.
 175  func (c *PresignClient) PresignGetCallerIdentity(ctx context.Context, params *GetCallerIdentityInput, optFns ...func(*PresignOptions)) (*v4.PresignedHTTPRequest, error) {
 176  	if params == nil {
 177  		params = &GetCallerIdentityInput{}
 178  	}
 179  	options := c.options.copy()
 180  	for _, fn := range optFns {
 181  		fn(&options)
 182  	}
 183  	clientOptFns := append(options.ClientOptions, withNopHTTPClientAPIOption)
 184  
 185  	result, _, err := c.client.invokeOperation(ctx, "GetCallerIdentity", params, clientOptFns,
 186  		c.client.addOperationGetCallerIdentityMiddlewares,
 187  		presignConverter(options).convertToPresignMiddleware,
 188  	)
 189  	if err != nil {
 190  		return nil, err
 191  	}
 192  
 193  	out := result.(*v4.PresignedHTTPRequest)
 194  	return out, nil
 195  }
 196