1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package sts
4
5import (
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
24func (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
39type GetCallerIdentityInput struct {
40 noSmithyDocumentSerde
41}
42
43// Contains the response to a successful GetCallerIdentity request, including information about the
44// entity making the request.
45type 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
68func (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 = addClientUserAgent(stack, options); err != nil {
112 return err
113 }
114 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
115 return err
116 }
117 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
118 return err
119 }
120 if err = addSetLegacyContextSigningOptionsMiddleware(stack); err != nil {
121 return err
122 }
123 if err = addTimeOffsetBuild(stack, c); err != nil {
124 return err
125 }
126 if err = addUserAgentRetryMode(stack, options); err != nil {
127 return err
128 }
129 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetCallerIdentity(options.Region), middleware.Before); err != nil {
130 return err
131 }
132 if err = addRecursionDetection(stack); err != nil {
133 return err
134 }
135 if err = addRequestIDRetrieverMiddleware(stack); err != nil {
136 return err
137 }
138 if err = addResponseErrorMiddleware(stack); err != nil {
139 return err
140 }
141 if err = addRequestResponseLogging(stack, options); err != nil {
142 return err
143 }
144 if err = addDisableHTTPSMiddleware(stack, options); err != nil {
145 return err
146 }
147 return nil
148}
149
150func newServiceMetadataMiddleware_opGetCallerIdentity(region string) *awsmiddleware.RegisterServiceMetadata {
151 return &awsmiddleware.RegisterServiceMetadata{
152 Region: region,
153 ServiceID: ServiceID,
154 OperationName: "GetCallerIdentity",
155 }
156}
157
158// PresignGetCallerIdentity is used to generate a presigned HTTP Request which
159// contains presigned URL, signed headers and HTTP method used.
160func (c *PresignClient) PresignGetCallerIdentity(ctx context.Context, params *GetCallerIdentityInput, optFns ...func(*PresignOptions)) (*v4.PresignedHTTPRequest, error) {
161 if params == nil {
162 params = &GetCallerIdentityInput{}
163 }
164 options := c.options.copy()
165 for _, fn := range optFns {
166 fn(&options)
167 }
168 clientOptFns := append(options.ClientOptions, withNopHTTPClientAPIOption)
169
170 result, _, err := c.client.invokeOperation(ctx, "GetCallerIdentity", params, clientOptFns,
171 c.client.addOperationGetCallerIdentityMiddlewares,
172 presignConverter(options).convertToPresignMiddleware,
173 )
174 if err != nil {
175 return nil, err
176 }
177
178 out := result.(*v4.PresignedHTTPRequest)
179 return out, nil
180}