{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE StrictData #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE NoImplicitPrelude #-} {-# OPTIONS_GHC -fno-warn-unused-binds #-} {-# OPTIONS_GHC -fno-warn-unused-imports #-} {-# OPTIONS_GHC -fno-warn-unused-matches #-} -- Derived from AWS service descriptions, licensed under Apache 2.0. -- | -- Module : Amazonka.IAM.GetUserPolicy -- Copyright : (c) 2013-2023 Brendan Hay -- License : Mozilla Public License, v. 2.0. -- Maintainer : Brendan Hay -- Stability : auto-generated -- Portability : non-portable (GHC extensions) -- -- Retrieves the specified inline policy document that is embedded in the -- specified IAM user. -- -- Policies returned by this operation are URL-encoded compliant with -- . You can use a URL -- decoding method to convert the policy back to plain JSON text. For -- example, if you use Java, you can use the @decode@ method of the -- @java.net.URLDecoder@ utility class in the Java SDK. Other languages and -- SDKs provide similar functionality. -- -- An IAM user can also have managed policies attached to it. To retrieve a -- managed policy document that is attached to a user, use GetPolicy to -- determine the policy\'s default version. Then use GetPolicyVersion to -- retrieve the policy document. -- -- For more information about policies, see -- -- in the /IAM User Guide/. module Amazonka.IAM.GetUserPolicy ( -- * Creating a Request GetUserPolicy (..), newGetUserPolicy, -- * Request Lenses getUserPolicy_userName, getUserPolicy_policyName, -- * Destructuring the Response GetUserPolicyResponse (..), newGetUserPolicyResponse, -- * Response Lenses getUserPolicyResponse_httpStatus, getUserPolicyResponse_userName, getUserPolicyResponse_policyName, getUserPolicyResponse_policyDocument, ) where import qualified Amazonka.Core as Core import qualified Amazonka.Core.Lens.Internal as Lens import qualified Amazonka.Data as Data import Amazonka.IAM.Types import qualified Amazonka.Prelude as Prelude import qualified Amazonka.Request as Request import qualified Amazonka.Response as Response -- | /See:/ 'newGetUserPolicy' smart constructor. data GetUserPolicy = GetUserPolicy' { -- | The name of the user who the policy is associated with. -- -- This parameter allows (through its -- ) a string of characters -- consisting of upper and lowercase alphanumeric characters with no -- spaces. You can also include any of the following characters: _+=,.\@- userName :: Prelude.Text, -- | The name of the policy document to get. -- -- This parameter allows (through its -- ) a string of characters -- consisting of upper and lowercase alphanumeric characters with no -- spaces. You can also include any of the following characters: _+=,.\@- policyName :: Prelude.Text } deriving (Prelude.Eq, Prelude.Read, Prelude.Show, Prelude.Generic) -- | -- Create a value of 'GetUserPolicy' with all optional fields omitted. -- -- Use or to modify other optional fields. -- -- The following record fields are available, with the corresponding lenses provided -- for backwards compatibility: -- -- 'userName', 'getUserPolicy_userName' - The name of the user who the policy is associated with. -- -- This parameter allows (through its -- ) a string of characters -- consisting of upper and lowercase alphanumeric characters with no -- spaces. You can also include any of the following characters: _+=,.\@- -- -- 'policyName', 'getUserPolicy_policyName' - The name of the policy document to get. -- -- This parameter allows (through its -- ) a string of characters -- consisting of upper and lowercase alphanumeric characters with no -- spaces. You can also include any of the following characters: _+=,.\@- newGetUserPolicy :: -- | 'userName' Prelude.Text -> -- | 'policyName' Prelude.Text -> GetUserPolicy newGetUserPolicy pUserName_ pPolicyName_ = GetUserPolicy' { userName = pUserName_, policyName = pPolicyName_ } -- | The name of the user who the policy is associated with. -- -- This parameter allows (through its -- ) a string of characters -- consisting of upper and lowercase alphanumeric characters with no -- spaces. You can also include any of the following characters: _+=,.\@- getUserPolicy_userName :: Lens.Lens' GetUserPolicy Prelude.Text getUserPolicy_userName = Lens.lens (\GetUserPolicy' {userName} -> userName) (\s@GetUserPolicy' {} a -> s {userName = a} :: GetUserPolicy) -- | The name of the policy document to get. -- -- This parameter allows (through its -- ) a string of characters -- consisting of upper and lowercase alphanumeric characters with no -- spaces. You can also include any of the following characters: _+=,.\@- getUserPolicy_policyName :: Lens.Lens' GetUserPolicy Prelude.Text getUserPolicy_policyName = Lens.lens (\GetUserPolicy' {policyName} -> policyName) (\s@GetUserPolicy' {} a -> s {policyName = a} :: GetUserPolicy) instance Core.AWSRequest GetUserPolicy where type AWSResponse GetUserPolicy = GetUserPolicyResponse request overrides = Request.postQuery (overrides defaultService) response = Response.receiveXMLWrapper "GetUserPolicyResult" ( \s h x -> GetUserPolicyResponse' Prelude.<$> (Prelude.pure (Prelude.fromEnum s)) Prelude.<*> (x Data..@ "UserName") Prelude.<*> (x Data..@ "PolicyName") Prelude.<*> (x Data..@ "PolicyDocument") ) instance Prelude.Hashable GetUserPolicy where hashWithSalt _salt GetUserPolicy' {..} = _salt `Prelude.hashWithSalt` userName `Prelude.hashWithSalt` policyName instance Prelude.NFData GetUserPolicy where rnf GetUserPolicy' {..} = Prelude.rnf userName `Prelude.seq` Prelude.rnf policyName instance Data.ToHeaders GetUserPolicy where toHeaders = Prelude.const Prelude.mempty instance Data.ToPath GetUserPolicy where toPath = Prelude.const "/" instance Data.ToQuery GetUserPolicy where toQuery GetUserPolicy' {..} = Prelude.mconcat [ "Action" Data.=: ("GetUserPolicy" :: Prelude.ByteString), "Version" Data.=: ("2010-05-08" :: Prelude.ByteString), "UserName" Data.=: userName, "PolicyName" Data.=: policyName ] -- | Contains the response to a successful GetUserPolicy request. -- -- /See:/ 'newGetUserPolicyResponse' smart constructor. data GetUserPolicyResponse = GetUserPolicyResponse' { -- | The response's http status code. httpStatus :: Prelude.Int, -- | The user the policy is associated with. userName :: Prelude.Text, -- | The name of the policy. policyName :: Prelude.Text, -- | The policy document. -- -- IAM stores policies in JSON format. However, resources that were created -- using CloudFormation templates can be formatted in YAML. CloudFormation -- always converts a YAML policy to JSON format before submitting it to -- IAM. policyDocument :: Prelude.Text } deriving (Prelude.Eq, Prelude.Read, Prelude.Show, Prelude.Generic) -- | -- Create a value of 'GetUserPolicyResponse' with all optional fields omitted. -- -- Use or to modify other optional fields. -- -- The following record fields are available, with the corresponding lenses provided -- for backwards compatibility: -- -- 'httpStatus', 'getUserPolicyResponse_httpStatus' - The response's http status code. -- -- 'userName', 'getUserPolicyResponse_userName' - The user the policy is associated with. -- -- 'policyName', 'getUserPolicyResponse_policyName' - The name of the policy. -- -- 'policyDocument', 'getUserPolicyResponse_policyDocument' - The policy document. -- -- IAM stores policies in JSON format. However, resources that were created -- using CloudFormation templates can be formatted in YAML. CloudFormation -- always converts a YAML policy to JSON format before submitting it to -- IAM. newGetUserPolicyResponse :: -- | 'httpStatus' Prelude.Int -> -- | 'userName' Prelude.Text -> -- | 'policyName' Prelude.Text -> -- | 'policyDocument' Prelude.Text -> GetUserPolicyResponse newGetUserPolicyResponse pHttpStatus_ pUserName_ pPolicyName_ pPolicyDocument_ = GetUserPolicyResponse' { httpStatus = pHttpStatus_, userName = pUserName_, policyName = pPolicyName_, policyDocument = pPolicyDocument_ } -- | The response's http status code. getUserPolicyResponse_httpStatus :: Lens.Lens' GetUserPolicyResponse Prelude.Int getUserPolicyResponse_httpStatus = Lens.lens (\GetUserPolicyResponse' {httpStatus} -> httpStatus) (\s@GetUserPolicyResponse' {} a -> s {httpStatus = a} :: GetUserPolicyResponse) -- | The user the policy is associated with. getUserPolicyResponse_userName :: Lens.Lens' GetUserPolicyResponse Prelude.Text getUserPolicyResponse_userName = Lens.lens (\GetUserPolicyResponse' {userName} -> userName) (\s@GetUserPolicyResponse' {} a -> s {userName = a} :: GetUserPolicyResponse) -- | The name of the policy. getUserPolicyResponse_policyName :: Lens.Lens' GetUserPolicyResponse Prelude.Text getUserPolicyResponse_policyName = Lens.lens (\GetUserPolicyResponse' {policyName} -> policyName) (\s@GetUserPolicyResponse' {} a -> s {policyName = a} :: GetUserPolicyResponse) -- | The policy document. -- -- IAM stores policies in JSON format. However, resources that were created -- using CloudFormation templates can be formatted in YAML. CloudFormation -- always converts a YAML policy to JSON format before submitting it to -- IAM. getUserPolicyResponse_policyDocument :: Lens.Lens' GetUserPolicyResponse Prelude.Text getUserPolicyResponse_policyDocument = Lens.lens (\GetUserPolicyResponse' {policyDocument} -> policyDocument) (\s@GetUserPolicyResponse' {} a -> s {policyDocument = a} :: GetUserPolicyResponse) instance Prelude.NFData GetUserPolicyResponse where rnf GetUserPolicyResponse' {..} = Prelude.rnf httpStatus `Prelude.seq` Prelude.rnf userName `Prelude.seq` Prelude.rnf policyName `Prelude.seq` Prelude.rnf policyDocument