{-# 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.RolesAnywhere.UpdateProfile
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Updates the profile. A profile is configuration resource to list the
-- roles that RolesAnywhere service is trusted to assume. In addition, by
-- applying a profile you can scope-down permissions with IAM managed
-- policies.
--
-- __Required permissions:__ @rolesanywhere:UpdateProfile@.
module Amazonka.RolesAnywhere.UpdateProfile
  ( -- * Creating a Request
    UpdateProfile (..),
    newUpdateProfile,

    -- * Request Lenses
    updateProfile_durationSeconds,
    updateProfile_managedPolicyArns,
    updateProfile_name,
    updateProfile_roleArns,
    updateProfile_sessionPolicy,
    updateProfile_profileId,

    -- * Destructuring the Response
    ProfileDetailResponse (..),
    newProfileDetailResponse,

    -- * Response Lenses
    profileDetailResponse_profile,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.RolesAnywhere.Types

-- | /See:/ 'newUpdateProfile' smart constructor.
data UpdateProfile = UpdateProfile'
  { -- | The number of seconds the vended session credentials are valid for.
    UpdateProfile -> Maybe Natural
durationSeconds :: Prelude.Maybe Prelude.Natural,
    -- | A list of managed policy ARNs that apply to the vended session
    -- credentials.
    UpdateProfile -> Maybe [Text]
managedPolicyArns :: Prelude.Maybe [Prelude.Text],
    -- | The name of the profile.
    UpdateProfile -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | A list of IAM roles that this profile can assume in a
    -- <https://docs.aws.amazon.com/rolesanywhere/latest/APIReference/API_CreateSession.html CreateSession>
    -- operation.
    UpdateProfile -> Maybe [Text]
roleArns :: Prelude.Maybe [Prelude.Text],
    -- | A session policy that applies to the trust boundary of the vended
    -- session credentials.
    UpdateProfile -> Maybe Text
sessionPolicy :: Prelude.Maybe Prelude.Text,
    -- | The unique identifier of the profile.
    UpdateProfile -> Text
profileId :: Prelude.Text
  }
  deriving (UpdateProfile -> UpdateProfile -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateProfile -> UpdateProfile -> Bool
$c/= :: UpdateProfile -> UpdateProfile -> Bool
== :: UpdateProfile -> UpdateProfile -> Bool
$c== :: UpdateProfile -> UpdateProfile -> Bool
Prelude.Eq, ReadPrec [UpdateProfile]
ReadPrec UpdateProfile
Int -> ReadS UpdateProfile
ReadS [UpdateProfile]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateProfile]
$creadListPrec :: ReadPrec [UpdateProfile]
readPrec :: ReadPrec UpdateProfile
$creadPrec :: ReadPrec UpdateProfile
readList :: ReadS [UpdateProfile]
$creadList :: ReadS [UpdateProfile]
readsPrec :: Int -> ReadS UpdateProfile
$creadsPrec :: Int -> ReadS UpdateProfile
Prelude.Read, Int -> UpdateProfile -> ShowS
[UpdateProfile] -> ShowS
UpdateProfile -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateProfile] -> ShowS
$cshowList :: [UpdateProfile] -> ShowS
show :: UpdateProfile -> String
$cshow :: UpdateProfile -> String
showsPrec :: Int -> UpdateProfile -> ShowS
$cshowsPrec :: Int -> UpdateProfile -> ShowS
Prelude.Show, forall x. Rep UpdateProfile x -> UpdateProfile
forall x. UpdateProfile -> Rep UpdateProfile x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateProfile x -> UpdateProfile
$cfrom :: forall x. UpdateProfile -> Rep UpdateProfile x
Prelude.Generic)

-- |
-- Create a value of 'UpdateProfile' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'durationSeconds', 'updateProfile_durationSeconds' - The number of seconds the vended session credentials are valid for.
--
-- 'managedPolicyArns', 'updateProfile_managedPolicyArns' - A list of managed policy ARNs that apply to the vended session
-- credentials.
--
-- 'name', 'updateProfile_name' - The name of the profile.
--
-- 'roleArns', 'updateProfile_roleArns' - A list of IAM roles that this profile can assume in a
-- <https://docs.aws.amazon.com/rolesanywhere/latest/APIReference/API_CreateSession.html CreateSession>
-- operation.
--
-- 'sessionPolicy', 'updateProfile_sessionPolicy' - A session policy that applies to the trust boundary of the vended
-- session credentials.
--
-- 'profileId', 'updateProfile_profileId' - The unique identifier of the profile.
newUpdateProfile ::
  -- | 'profileId'
  Prelude.Text ->
  UpdateProfile
newUpdateProfile :: Text -> UpdateProfile
newUpdateProfile Text
pProfileId_ =
  UpdateProfile'
    { $sel:durationSeconds:UpdateProfile' :: Maybe Natural
durationSeconds = forall a. Maybe a
Prelude.Nothing,
      $sel:managedPolicyArns:UpdateProfile' :: Maybe [Text]
managedPolicyArns = forall a. Maybe a
Prelude.Nothing,
      $sel:name:UpdateProfile' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing,
      $sel:roleArns:UpdateProfile' :: Maybe [Text]
roleArns = forall a. Maybe a
Prelude.Nothing,
      $sel:sessionPolicy:UpdateProfile' :: Maybe Text
sessionPolicy = forall a. Maybe a
Prelude.Nothing,
      $sel:profileId:UpdateProfile' :: Text
profileId = Text
pProfileId_
    }

-- | The number of seconds the vended session credentials are valid for.
updateProfile_durationSeconds :: Lens.Lens' UpdateProfile (Prelude.Maybe Prelude.Natural)
updateProfile_durationSeconds :: Lens' UpdateProfile (Maybe Natural)
updateProfile_durationSeconds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateProfile' {Maybe Natural
durationSeconds :: Maybe Natural
$sel:durationSeconds:UpdateProfile' :: UpdateProfile -> Maybe Natural
durationSeconds} -> Maybe Natural
durationSeconds) (\s :: UpdateProfile
s@UpdateProfile' {} Maybe Natural
a -> UpdateProfile
s {$sel:durationSeconds:UpdateProfile' :: Maybe Natural
durationSeconds = Maybe Natural
a} :: UpdateProfile)

-- | A list of managed policy ARNs that apply to the vended session
-- credentials.
updateProfile_managedPolicyArns :: Lens.Lens' UpdateProfile (Prelude.Maybe [Prelude.Text])
updateProfile_managedPolicyArns :: Lens' UpdateProfile (Maybe [Text])
updateProfile_managedPolicyArns = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateProfile' {Maybe [Text]
managedPolicyArns :: Maybe [Text]
$sel:managedPolicyArns:UpdateProfile' :: UpdateProfile -> Maybe [Text]
managedPolicyArns} -> Maybe [Text]
managedPolicyArns) (\s :: UpdateProfile
s@UpdateProfile' {} Maybe [Text]
a -> UpdateProfile
s {$sel:managedPolicyArns:UpdateProfile' :: Maybe [Text]
managedPolicyArns = Maybe [Text]
a} :: UpdateProfile) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the profile.
updateProfile_name :: Lens.Lens' UpdateProfile (Prelude.Maybe Prelude.Text)
updateProfile_name :: Lens' UpdateProfile (Maybe Text)
updateProfile_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateProfile' {Maybe Text
name :: Maybe Text
$sel:name:UpdateProfile' :: UpdateProfile -> Maybe Text
name} -> Maybe Text
name) (\s :: UpdateProfile
s@UpdateProfile' {} Maybe Text
a -> UpdateProfile
s {$sel:name:UpdateProfile' :: Maybe Text
name = Maybe Text
a} :: UpdateProfile)

-- | A list of IAM roles that this profile can assume in a
-- <https://docs.aws.amazon.com/rolesanywhere/latest/APIReference/API_CreateSession.html CreateSession>
-- operation.
updateProfile_roleArns :: Lens.Lens' UpdateProfile (Prelude.Maybe [Prelude.Text])
updateProfile_roleArns :: Lens' UpdateProfile (Maybe [Text])
updateProfile_roleArns = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateProfile' {Maybe [Text]
roleArns :: Maybe [Text]
$sel:roleArns:UpdateProfile' :: UpdateProfile -> Maybe [Text]
roleArns} -> Maybe [Text]
roleArns) (\s :: UpdateProfile
s@UpdateProfile' {} Maybe [Text]
a -> UpdateProfile
s {$sel:roleArns:UpdateProfile' :: Maybe [Text]
roleArns = Maybe [Text]
a} :: UpdateProfile) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A session policy that applies to the trust boundary of the vended
-- session credentials.
updateProfile_sessionPolicy :: Lens.Lens' UpdateProfile (Prelude.Maybe Prelude.Text)
updateProfile_sessionPolicy :: Lens' UpdateProfile (Maybe Text)
updateProfile_sessionPolicy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateProfile' {Maybe Text
sessionPolicy :: Maybe Text
$sel:sessionPolicy:UpdateProfile' :: UpdateProfile -> Maybe Text
sessionPolicy} -> Maybe Text
sessionPolicy) (\s :: UpdateProfile
s@UpdateProfile' {} Maybe Text
a -> UpdateProfile
s {$sel:sessionPolicy:UpdateProfile' :: Maybe Text
sessionPolicy = Maybe Text
a} :: UpdateProfile)

-- | The unique identifier of the profile.
updateProfile_profileId :: Lens.Lens' UpdateProfile Prelude.Text
updateProfile_profileId :: Lens' UpdateProfile Text
updateProfile_profileId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateProfile' {Text
profileId :: Text
$sel:profileId:UpdateProfile' :: UpdateProfile -> Text
profileId} -> Text
profileId) (\s :: UpdateProfile
s@UpdateProfile' {} Text
a -> UpdateProfile
s {$sel:profileId:UpdateProfile' :: Text
profileId = Text
a} :: UpdateProfile)

instance Core.AWSRequest UpdateProfile where
  type
    AWSResponse UpdateProfile =
      ProfileDetailResponse
  request :: (Service -> Service) -> UpdateProfile -> Request UpdateProfile
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.patchJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy UpdateProfile
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateProfile)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      (\Int
s ResponseHeaders
h Object
x -> forall a. FromJSON a => Object -> Either String a
Data.eitherParseJSON Object
x)

instance Prelude.Hashable UpdateProfile where
  hashWithSalt :: Int -> UpdateProfile -> Int
hashWithSalt Int
_salt UpdateProfile' {Maybe Natural
Maybe [Text]
Maybe Text
Text
profileId :: Text
sessionPolicy :: Maybe Text
roleArns :: Maybe [Text]
name :: Maybe Text
managedPolicyArns :: Maybe [Text]
durationSeconds :: Maybe Natural
$sel:profileId:UpdateProfile' :: UpdateProfile -> Text
$sel:sessionPolicy:UpdateProfile' :: UpdateProfile -> Maybe Text
$sel:roleArns:UpdateProfile' :: UpdateProfile -> Maybe [Text]
$sel:name:UpdateProfile' :: UpdateProfile -> Maybe Text
$sel:managedPolicyArns:UpdateProfile' :: UpdateProfile -> Maybe [Text]
$sel:durationSeconds:UpdateProfile' :: UpdateProfile -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
durationSeconds
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
managedPolicyArns
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
roleArns
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
sessionPolicy
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
profileId

instance Prelude.NFData UpdateProfile where
  rnf :: UpdateProfile -> ()
rnf UpdateProfile' {Maybe Natural
Maybe [Text]
Maybe Text
Text
profileId :: Text
sessionPolicy :: Maybe Text
roleArns :: Maybe [Text]
name :: Maybe Text
managedPolicyArns :: Maybe [Text]
durationSeconds :: Maybe Natural
$sel:profileId:UpdateProfile' :: UpdateProfile -> Text
$sel:sessionPolicy:UpdateProfile' :: UpdateProfile -> Maybe Text
$sel:roleArns:UpdateProfile' :: UpdateProfile -> Maybe [Text]
$sel:name:UpdateProfile' :: UpdateProfile -> Maybe Text
$sel:managedPolicyArns:UpdateProfile' :: UpdateProfile -> Maybe [Text]
$sel:durationSeconds:UpdateProfile' :: UpdateProfile -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
durationSeconds
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
managedPolicyArns
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
roleArns
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
sessionPolicy
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
profileId

instance Data.ToHeaders UpdateProfile where
  toHeaders :: UpdateProfile -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON UpdateProfile where
  toJSON :: UpdateProfile -> Value
toJSON UpdateProfile' {Maybe Natural
Maybe [Text]
Maybe Text
Text
profileId :: Text
sessionPolicy :: Maybe Text
roleArns :: Maybe [Text]
name :: Maybe Text
managedPolicyArns :: Maybe [Text]
durationSeconds :: Maybe Natural
$sel:profileId:UpdateProfile' :: UpdateProfile -> Text
$sel:sessionPolicy:UpdateProfile' :: UpdateProfile -> Maybe Text
$sel:roleArns:UpdateProfile' :: UpdateProfile -> Maybe [Text]
$sel:name:UpdateProfile' :: UpdateProfile -> Maybe Text
$sel:managedPolicyArns:UpdateProfile' :: UpdateProfile -> Maybe [Text]
$sel:durationSeconds:UpdateProfile' :: UpdateProfile -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"durationSeconds" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
durationSeconds,
            (Key
"managedPolicyArns" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
managedPolicyArns,
            (Key
"name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
name,
            (Key
"roleArns" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
roleArns,
            (Key
"sessionPolicy" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
sessionPolicy
          ]
      )

instance Data.ToPath UpdateProfile where
  toPath :: UpdateProfile -> ByteString
toPath UpdateProfile' {Maybe Natural
Maybe [Text]
Maybe Text
Text
profileId :: Text
sessionPolicy :: Maybe Text
roleArns :: Maybe [Text]
name :: Maybe Text
managedPolicyArns :: Maybe [Text]
durationSeconds :: Maybe Natural
$sel:profileId:UpdateProfile' :: UpdateProfile -> Text
$sel:sessionPolicy:UpdateProfile' :: UpdateProfile -> Maybe Text
$sel:roleArns:UpdateProfile' :: UpdateProfile -> Maybe [Text]
$sel:name:UpdateProfile' :: UpdateProfile -> Maybe Text
$sel:managedPolicyArns:UpdateProfile' :: UpdateProfile -> Maybe [Text]
$sel:durationSeconds:UpdateProfile' :: UpdateProfile -> Maybe Natural
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"/profile/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
profileId]

instance Data.ToQuery UpdateProfile where
  toQuery :: UpdateProfile -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty