1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package iam
4
5import (
6	"context"
7	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
8	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
9	"github.com/aws/smithy-go/middleware"
10	smithyhttp "github.com/aws/smithy-go/transport/http"
11)
12
13// Retrieves the specified inline policy document that is embedded with the
14// specified IAM role. Policies returned by this API are URL-encoded compliant with
15// RFC 3986 (https://tools.ietf.org/html/rfc3986). You can use a URL decoding
16// method to convert the policy back to plain JSON text. For example, if you use
17// Java, you can use the decode method of the java.net.URLDecoder utility class in
18// the Java SDK. Other languages and SDKs provide similar functionality. An IAM
19// role can also have managed policies attached to it. To retrieve a managed policy
20// document that is attached to a role, use GetPolicy to determine the policy's
21// default version, then use GetPolicyVersion to retrieve the policy document. For
22// more information about policies, see Managed Policies and Inline Policies
23// (https://docs.aws.amazon.com/IAM/latest/UserGuide/policies-managed-vs-inline.html)
24// in the IAM User Guide. For more information about roles, see Using Roles to
25// Delegate Permissions and Federate Identities
26// (https://docs.aws.amazon.com/IAM/latest/UserGuide/roles-toplevel.html).
27func (c *Client) GetRolePolicy(ctx context.Context, params *GetRolePolicyInput, optFns ...func(*Options)) (*GetRolePolicyOutput, error) {
28	if params == nil {
29		params = &GetRolePolicyInput{}
30	}
31
32	result, metadata, err := c.invokeOperation(ctx, "GetRolePolicy", params, optFns, addOperationGetRolePolicyMiddlewares)
33	if err != nil {
34		return nil, err
35	}
36
37	out := result.(*GetRolePolicyOutput)
38	out.ResultMetadata = metadata
39	return out, nil
40}
41
42type GetRolePolicyInput struct {
43
44	// The name of the policy document to get. This parameter allows (through its regex
45	// pattern (http://wikipedia.org/wiki/regex)) a string of characters consisting of
46	// upper and lowercase alphanumeric characters with no spaces. You can also include
47	// any of the following characters: _+=,.@-
48	//
49	// This member is required.
50	PolicyName *string
51
52	// The name of the role associated with the policy. This parameter allows (through
53	// its regex pattern (http://wikipedia.org/wiki/regex)) a string of characters
54	// consisting of upper and lowercase alphanumeric characters with no spaces. You
55	// can also include any of the following characters: _+=,.@-
56	//
57	// This member is required.
58	RoleName *string
59}
60
61// Contains the response to a successful GetRolePolicy request.
62type GetRolePolicyOutput struct {
63
64	// The policy document. IAM stores policies in JSON format. However, resources that
65	// were created using AWS CloudFormation templates can be formatted in YAML. AWS
66	// CloudFormation always converts a YAML policy to JSON format before submitting it
67	// to IAM.
68	//
69	// This member is required.
70	PolicyDocument *string
71
72	// The name of the policy.
73	//
74	// This member is required.
75	PolicyName *string
76
77	// The role the policy is associated with.
78	//
79	// This member is required.
80	RoleName *string
81
82	// Metadata pertaining to the operation's result.
83	ResultMetadata middleware.Metadata
84}
85
86func addOperationGetRolePolicyMiddlewares(stack *middleware.Stack, options Options) (err error) {
87	err = stack.Serialize.Add(&awsAwsquery_serializeOpGetRolePolicy{}, middleware.After)
88	if err != nil {
89		return err
90	}
91	err = stack.Deserialize.Add(&awsAwsquery_deserializeOpGetRolePolicy{}, middleware.After)
92	if err != nil {
93		return err
94	}
95	if err = addSetLoggerMiddleware(stack, options); err != nil {
96		return err
97	}
98	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
99		return err
100	}
101	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
102		return err
103	}
104	if err = addResolveEndpointMiddleware(stack, options); err != nil {
105		return err
106	}
107	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
108		return err
109	}
110	if err = addRetryMiddlewares(stack, options); err != nil {
111		return err
112	}
113	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
114		return err
115	}
116	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
117		return err
118	}
119	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
120		return err
121	}
122	if err = addClientUserAgent(stack); err != nil {
123		return err
124	}
125	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
126		return err
127	}
128	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
129		return err
130	}
131	if err = addOpGetRolePolicyValidationMiddleware(stack); err != nil {
132		return err
133	}
134	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetRolePolicy(options.Region), middleware.Before); err != nil {
135		return err
136	}
137	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
138		return err
139	}
140	if err = addResponseErrorMiddleware(stack); err != nil {
141		return err
142	}
143	if err = addRequestResponseLogging(stack, options); err != nil {
144		return err
145	}
146	return nil
147}
148
149func newServiceMetadataMiddleware_opGetRolePolicy(region string) *awsmiddleware.RegisterServiceMetadata {
150	return &awsmiddleware.RegisterServiceMetadata{
151		Region:        region,
152		ServiceID:     ServiceID,
153		SigningName:   "iam",
154		OperationName: "GetRolePolicy",
155	}
156}
157