{-# 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.Glacier.GetVaultAccessPolicy
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- This operation retrieves the @access-policy@ subresource set on the
-- vault; for more information on setting this subresource, see
-- <https://docs.aws.amazon.com/amazonglacier/latest/dev/api-SetVaultAccessPolicy.html Set Vault Access Policy (PUT access-policy)>.
-- If there is no access policy set on the vault, the operation returns a
-- @404 Not found@ error. For more information about vault access policies,
-- see
-- <https://docs.aws.amazon.com/amazonglacier/latest/dev/vault-access-policy.html Amazon Glacier Access Control with Vault Access Policies>.
module Amazonka.Glacier.GetVaultAccessPolicy
  ( -- * Creating a Request
    GetVaultAccessPolicy (..),
    newGetVaultAccessPolicy,

    -- * Request Lenses
    getVaultAccessPolicy_accountId,
    getVaultAccessPolicy_vaultName,

    -- * Destructuring the Response
    GetVaultAccessPolicyResponse (..),
    newGetVaultAccessPolicyResponse,

    -- * Response Lenses
    getVaultAccessPolicyResponse_policy,
    getVaultAccessPolicyResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.Glacier.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | Input for GetVaultAccessPolicy.
--
-- /See:/ 'newGetVaultAccessPolicy' smart constructor.
data GetVaultAccessPolicy = GetVaultAccessPolicy'
  { -- | The @AccountId@ value is the AWS account ID of the account that owns the
    -- vault. You can either specify an AWS account ID or optionally a single
    -- \'@-@\' (hyphen), in which case Amazon S3 Glacier uses the AWS account
    -- ID associated with the credentials used to sign the request. If you use
    -- an account ID, do not include any hyphens (\'-\') in the ID.
    GetVaultAccessPolicy -> Text
accountId :: Prelude.Text,
    -- | The name of the vault.
    GetVaultAccessPolicy -> Text
vaultName :: Prelude.Text
  }
  deriving (GetVaultAccessPolicy -> GetVaultAccessPolicy -> Bool
(GetVaultAccessPolicy -> GetVaultAccessPolicy -> Bool)
-> (GetVaultAccessPolicy -> GetVaultAccessPolicy -> Bool)
-> Eq GetVaultAccessPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetVaultAccessPolicy -> GetVaultAccessPolicy -> Bool
$c/= :: GetVaultAccessPolicy -> GetVaultAccessPolicy -> Bool
== :: GetVaultAccessPolicy -> GetVaultAccessPolicy -> Bool
$c== :: GetVaultAccessPolicy -> GetVaultAccessPolicy -> Bool
Prelude.Eq, ReadPrec [GetVaultAccessPolicy]
ReadPrec GetVaultAccessPolicy
Int -> ReadS GetVaultAccessPolicy
ReadS [GetVaultAccessPolicy]
(Int -> ReadS GetVaultAccessPolicy)
-> ReadS [GetVaultAccessPolicy]
-> ReadPrec GetVaultAccessPolicy
-> ReadPrec [GetVaultAccessPolicy]
-> Read GetVaultAccessPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetVaultAccessPolicy]
$creadListPrec :: ReadPrec [GetVaultAccessPolicy]
readPrec :: ReadPrec GetVaultAccessPolicy
$creadPrec :: ReadPrec GetVaultAccessPolicy
readList :: ReadS [GetVaultAccessPolicy]
$creadList :: ReadS [GetVaultAccessPolicy]
readsPrec :: Int -> ReadS GetVaultAccessPolicy
$creadsPrec :: Int -> ReadS GetVaultAccessPolicy
Prelude.Read, Int -> GetVaultAccessPolicy -> ShowS
[GetVaultAccessPolicy] -> ShowS
GetVaultAccessPolicy -> String
(Int -> GetVaultAccessPolicy -> ShowS)
-> (GetVaultAccessPolicy -> String)
-> ([GetVaultAccessPolicy] -> ShowS)
-> Show GetVaultAccessPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetVaultAccessPolicy] -> ShowS
$cshowList :: [GetVaultAccessPolicy] -> ShowS
show :: GetVaultAccessPolicy -> String
$cshow :: GetVaultAccessPolicy -> String
showsPrec :: Int -> GetVaultAccessPolicy -> ShowS
$cshowsPrec :: Int -> GetVaultAccessPolicy -> ShowS
Prelude.Show, (forall x. GetVaultAccessPolicy -> Rep GetVaultAccessPolicy x)
-> (forall x. Rep GetVaultAccessPolicy x -> GetVaultAccessPolicy)
-> Generic GetVaultAccessPolicy
forall x. Rep GetVaultAccessPolicy x -> GetVaultAccessPolicy
forall x. GetVaultAccessPolicy -> Rep GetVaultAccessPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetVaultAccessPolicy x -> GetVaultAccessPolicy
$cfrom :: forall x. GetVaultAccessPolicy -> Rep GetVaultAccessPolicy x
Prelude.Generic)

-- |
-- Create a value of 'GetVaultAccessPolicy' 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:
--
-- 'accountId', 'getVaultAccessPolicy_accountId' - The @AccountId@ value is the AWS account ID of the account that owns the
-- vault. You can either specify an AWS account ID or optionally a single
-- \'@-@\' (hyphen), in which case Amazon S3 Glacier uses the AWS account
-- ID associated with the credentials used to sign the request. If you use
-- an account ID, do not include any hyphens (\'-\') in the ID.
--
-- 'vaultName', 'getVaultAccessPolicy_vaultName' - The name of the vault.
newGetVaultAccessPolicy ::
  -- | 'accountId'
  Prelude.Text ->
  -- | 'vaultName'
  Prelude.Text ->
  GetVaultAccessPolicy
newGetVaultAccessPolicy :: Text -> Text -> GetVaultAccessPolicy
newGetVaultAccessPolicy Text
pAccountId_ Text
pVaultName_ =
  GetVaultAccessPolicy' :: Text -> Text -> GetVaultAccessPolicy
GetVaultAccessPolicy'
    { $sel:accountId:GetVaultAccessPolicy' :: Text
accountId = Text
pAccountId_,
      $sel:vaultName:GetVaultAccessPolicy' :: Text
vaultName = Text
pVaultName_
    }

-- | The @AccountId@ value is the AWS account ID of the account that owns the
-- vault. You can either specify an AWS account ID or optionally a single
-- \'@-@\' (hyphen), in which case Amazon S3 Glacier uses the AWS account
-- ID associated with the credentials used to sign the request. If you use
-- an account ID, do not include any hyphens (\'-\') in the ID.
getVaultAccessPolicy_accountId :: Lens.Lens' GetVaultAccessPolicy Prelude.Text
getVaultAccessPolicy_accountId :: (Text -> f Text) -> GetVaultAccessPolicy -> f GetVaultAccessPolicy
getVaultAccessPolicy_accountId = (GetVaultAccessPolicy -> Text)
-> (GetVaultAccessPolicy -> Text -> GetVaultAccessPolicy)
-> Lens GetVaultAccessPolicy GetVaultAccessPolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetVaultAccessPolicy' {Text
accountId :: Text
$sel:accountId:GetVaultAccessPolicy' :: GetVaultAccessPolicy -> Text
accountId} -> Text
accountId) (\s :: GetVaultAccessPolicy
s@GetVaultAccessPolicy' {} Text
a -> GetVaultAccessPolicy
s {$sel:accountId:GetVaultAccessPolicy' :: Text
accountId = Text
a} :: GetVaultAccessPolicy)

-- | The name of the vault.
getVaultAccessPolicy_vaultName :: Lens.Lens' GetVaultAccessPolicy Prelude.Text
getVaultAccessPolicy_vaultName :: (Text -> f Text) -> GetVaultAccessPolicy -> f GetVaultAccessPolicy
getVaultAccessPolicy_vaultName = (GetVaultAccessPolicy -> Text)
-> (GetVaultAccessPolicy -> Text -> GetVaultAccessPolicy)
-> Lens GetVaultAccessPolicy GetVaultAccessPolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetVaultAccessPolicy' {Text
vaultName :: Text
$sel:vaultName:GetVaultAccessPolicy' :: GetVaultAccessPolicy -> Text
vaultName} -> Text
vaultName) (\s :: GetVaultAccessPolicy
s@GetVaultAccessPolicy' {} Text
a -> GetVaultAccessPolicy
s {$sel:vaultName:GetVaultAccessPolicy' :: Text
vaultName = Text
a} :: GetVaultAccessPolicy)

instance Core.AWSRequest GetVaultAccessPolicy where
  type
    AWSResponse GetVaultAccessPolicy =
      GetVaultAccessPolicyResponse
  request :: GetVaultAccessPolicy -> Request GetVaultAccessPolicy
request =
    ByteString
-> Request GetVaultAccessPolicy -> Request GetVaultAccessPolicy
forall a. ByteString -> Request a -> Request a
Request.glacierVersionHeader (Service -> ByteString
Core._serviceVersion Service
defaultService)
      (Request GetVaultAccessPolicy -> Request GetVaultAccessPolicy)
-> (GetVaultAccessPolicy -> Request GetVaultAccessPolicy)
-> GetVaultAccessPolicy
-> Request GetVaultAccessPolicy
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. Service -> GetVaultAccessPolicy -> Request GetVaultAccessPolicy
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetVaultAccessPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetVaultAccessPolicy)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetVaultAccessPolicy))
-> Logger
-> Service
-> Proxy GetVaultAccessPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetVaultAccessPolicy)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe VaultAccessPolicy -> Int -> GetVaultAccessPolicyResponse
GetVaultAccessPolicyResponse'
            (Maybe VaultAccessPolicy -> Int -> GetVaultAccessPolicyResponse)
-> Either String (Maybe VaultAccessPolicy)
-> Either String (Int -> GetVaultAccessPolicyResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object -> Either String (Maybe VaultAccessPolicy)
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)
            Either String (Int -> GetVaultAccessPolicyResponse)
-> Either String Int -> Either String GetVaultAccessPolicyResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable GetVaultAccessPolicy

instance Prelude.NFData GetVaultAccessPolicy

instance Core.ToHeaders GetVaultAccessPolicy where
  toHeaders :: GetVaultAccessPolicy -> ResponseHeaders
toHeaders = ResponseHeaders -> GetVaultAccessPolicy -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToPath GetVaultAccessPolicy where
  toPath :: GetVaultAccessPolicy -> ByteString
toPath GetVaultAccessPolicy' {Text
vaultName :: Text
accountId :: Text
$sel:vaultName:GetVaultAccessPolicy' :: GetVaultAccessPolicy -> Text
$sel:accountId:GetVaultAccessPolicy' :: GetVaultAccessPolicy -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
accountId,
        ByteString
"/vaults/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
vaultName,
        ByteString
"/access-policy"
      ]

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

-- | Output for GetVaultAccessPolicy.
--
-- /See:/ 'newGetVaultAccessPolicyResponse' smart constructor.
data GetVaultAccessPolicyResponse = GetVaultAccessPolicyResponse'
  { -- | Contains the returned vault access policy as a JSON string.
    GetVaultAccessPolicyResponse -> Maybe VaultAccessPolicy
policy :: Prelude.Maybe VaultAccessPolicy,
    -- | The response's http status code.
    GetVaultAccessPolicyResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetVaultAccessPolicyResponse
-> GetVaultAccessPolicyResponse -> Bool
(GetVaultAccessPolicyResponse
 -> GetVaultAccessPolicyResponse -> Bool)
-> (GetVaultAccessPolicyResponse
    -> GetVaultAccessPolicyResponse -> Bool)
-> Eq GetVaultAccessPolicyResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetVaultAccessPolicyResponse
-> GetVaultAccessPolicyResponse -> Bool
$c/= :: GetVaultAccessPolicyResponse
-> GetVaultAccessPolicyResponse -> Bool
== :: GetVaultAccessPolicyResponse
-> GetVaultAccessPolicyResponse -> Bool
$c== :: GetVaultAccessPolicyResponse
-> GetVaultAccessPolicyResponse -> Bool
Prelude.Eq, ReadPrec [GetVaultAccessPolicyResponse]
ReadPrec GetVaultAccessPolicyResponse
Int -> ReadS GetVaultAccessPolicyResponse
ReadS [GetVaultAccessPolicyResponse]
(Int -> ReadS GetVaultAccessPolicyResponse)
-> ReadS [GetVaultAccessPolicyResponse]
-> ReadPrec GetVaultAccessPolicyResponse
-> ReadPrec [GetVaultAccessPolicyResponse]
-> Read GetVaultAccessPolicyResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetVaultAccessPolicyResponse]
$creadListPrec :: ReadPrec [GetVaultAccessPolicyResponse]
readPrec :: ReadPrec GetVaultAccessPolicyResponse
$creadPrec :: ReadPrec GetVaultAccessPolicyResponse
readList :: ReadS [GetVaultAccessPolicyResponse]
$creadList :: ReadS [GetVaultAccessPolicyResponse]
readsPrec :: Int -> ReadS GetVaultAccessPolicyResponse
$creadsPrec :: Int -> ReadS GetVaultAccessPolicyResponse
Prelude.Read, Int -> GetVaultAccessPolicyResponse -> ShowS
[GetVaultAccessPolicyResponse] -> ShowS
GetVaultAccessPolicyResponse -> String
(Int -> GetVaultAccessPolicyResponse -> ShowS)
-> (GetVaultAccessPolicyResponse -> String)
-> ([GetVaultAccessPolicyResponse] -> ShowS)
-> Show GetVaultAccessPolicyResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetVaultAccessPolicyResponse] -> ShowS
$cshowList :: [GetVaultAccessPolicyResponse] -> ShowS
show :: GetVaultAccessPolicyResponse -> String
$cshow :: GetVaultAccessPolicyResponse -> String
showsPrec :: Int -> GetVaultAccessPolicyResponse -> ShowS
$cshowsPrec :: Int -> GetVaultAccessPolicyResponse -> ShowS
Prelude.Show, (forall x.
 GetVaultAccessPolicyResponse -> Rep GetVaultAccessPolicyResponse x)
-> (forall x.
    Rep GetVaultAccessPolicyResponse x -> GetVaultAccessPolicyResponse)
-> Generic GetVaultAccessPolicyResponse
forall x.
Rep GetVaultAccessPolicyResponse x -> GetVaultAccessPolicyResponse
forall x.
GetVaultAccessPolicyResponse -> Rep GetVaultAccessPolicyResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetVaultAccessPolicyResponse x -> GetVaultAccessPolicyResponse
$cfrom :: forall x.
GetVaultAccessPolicyResponse -> Rep GetVaultAccessPolicyResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetVaultAccessPolicyResponse' 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:
--
-- 'policy', 'getVaultAccessPolicyResponse_policy' - Contains the returned vault access policy as a JSON string.
--
-- 'httpStatus', 'getVaultAccessPolicyResponse_httpStatus' - The response's http status code.
newGetVaultAccessPolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetVaultAccessPolicyResponse
newGetVaultAccessPolicyResponse :: Int -> GetVaultAccessPolicyResponse
newGetVaultAccessPolicyResponse Int
pHttpStatus_ =
  GetVaultAccessPolicyResponse' :: Maybe VaultAccessPolicy -> Int -> GetVaultAccessPolicyResponse
GetVaultAccessPolicyResponse'
    { $sel:policy:GetVaultAccessPolicyResponse' :: Maybe VaultAccessPolicy
policy =
        Maybe VaultAccessPolicy
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetVaultAccessPolicyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Contains the returned vault access policy as a JSON string.
getVaultAccessPolicyResponse_policy :: Lens.Lens' GetVaultAccessPolicyResponse (Prelude.Maybe VaultAccessPolicy)
getVaultAccessPolicyResponse_policy :: (Maybe VaultAccessPolicy -> f (Maybe VaultAccessPolicy))
-> GetVaultAccessPolicyResponse -> f GetVaultAccessPolicyResponse
getVaultAccessPolicyResponse_policy = (GetVaultAccessPolicyResponse -> Maybe VaultAccessPolicy)
-> (GetVaultAccessPolicyResponse
    -> Maybe VaultAccessPolicy -> GetVaultAccessPolicyResponse)
-> Lens
     GetVaultAccessPolicyResponse
     GetVaultAccessPolicyResponse
     (Maybe VaultAccessPolicy)
     (Maybe VaultAccessPolicy)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetVaultAccessPolicyResponse' {Maybe VaultAccessPolicy
policy :: Maybe VaultAccessPolicy
$sel:policy:GetVaultAccessPolicyResponse' :: GetVaultAccessPolicyResponse -> Maybe VaultAccessPolicy
policy} -> Maybe VaultAccessPolicy
policy) (\s :: GetVaultAccessPolicyResponse
s@GetVaultAccessPolicyResponse' {} Maybe VaultAccessPolicy
a -> GetVaultAccessPolicyResponse
s {$sel:policy:GetVaultAccessPolicyResponse' :: Maybe VaultAccessPolicy
policy = Maybe VaultAccessPolicy
a} :: GetVaultAccessPolicyResponse)

-- | The response's http status code.
getVaultAccessPolicyResponse_httpStatus :: Lens.Lens' GetVaultAccessPolicyResponse Prelude.Int
getVaultAccessPolicyResponse_httpStatus :: (Int -> f Int)
-> GetVaultAccessPolicyResponse -> f GetVaultAccessPolicyResponse
getVaultAccessPolicyResponse_httpStatus = (GetVaultAccessPolicyResponse -> Int)
-> (GetVaultAccessPolicyResponse
    -> Int -> GetVaultAccessPolicyResponse)
-> Lens
     GetVaultAccessPolicyResponse GetVaultAccessPolicyResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetVaultAccessPolicyResponse' {Int
httpStatus :: Int
$sel:httpStatus:GetVaultAccessPolicyResponse' :: GetVaultAccessPolicyResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: GetVaultAccessPolicyResponse
s@GetVaultAccessPolicyResponse' {} Int
a -> GetVaultAccessPolicyResponse
s {$sel:httpStatus:GetVaultAccessPolicyResponse' :: Int
httpStatus = Int
a} :: GetVaultAccessPolicyResponse)

instance Prelude.NFData GetVaultAccessPolicyResponse