{-# 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.CreateVault
-- 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 creates a new vault with the specified name. The name of
-- the vault must be unique within a region for an AWS account. You can
-- create up to 1,000 vaults per account. If you need to create more
-- vaults, contact Amazon S3 Glacier.
--
-- You must use the following guidelines when naming a vault.
--
-- -   Names can be between 1 and 255 characters long.
--
-- -   Allowed characters are a-z, A-Z, 0-9, \'_\' (underscore), \'-\'
--     (hyphen), and \'.\' (period).
--
-- This operation is idempotent.
--
-- An AWS account has full permission to perform all operations (actions).
-- However, AWS Identity and Access Management (IAM) users don\'t have any
-- permissions by default. You must grant them explicit permission to
-- perform specific actions. For more information, see
-- <https://docs.aws.amazon.com/amazonglacier/latest/dev/using-iam-with-amazon-glacier.html Access Control Using AWS Identity and Access Management (IAM)>.
--
-- For conceptual information and underlying REST API, see
-- <https://docs.aws.amazon.com/amazonglacier/latest/dev/creating-vaults.html Creating a Vault in Amazon Glacier>
-- and
-- <https://docs.aws.amazon.com/amazonglacier/latest/dev/api-vault-put.html Create Vault>
-- in the /Amazon Glacier Developer Guide/.
module Amazonka.Glacier.CreateVault
  ( -- * Creating a Request
    CreateVault (..),
    newCreateVault,

    -- * Request Lenses
    createVault_accountId,
    createVault_vaultName,

    -- * Destructuring the Response
    CreateVaultResponse (..),
    newCreateVaultResponse,

    -- * Response Lenses
    createVaultResponse_location,
    createVaultResponse_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

-- | Provides options to create a vault.
--
-- /See:/ 'newCreateVault' smart constructor.
data CreateVault = CreateVault'
  { -- | The @AccountId@ value is the AWS account ID. This value must match the
    -- AWS account ID associated with the credentials used to sign the request.
    -- 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 specify
    -- your account ID, do not include any hyphens (\'-\') in the ID.
    CreateVault -> Text
accountId :: Prelude.Text,
    -- | The name of the vault.
    CreateVault -> Text
vaultName :: Prelude.Text
  }
  deriving (CreateVault -> CreateVault -> Bool
(CreateVault -> CreateVault -> Bool)
-> (CreateVault -> CreateVault -> Bool) -> Eq CreateVault
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateVault -> CreateVault -> Bool
$c/= :: CreateVault -> CreateVault -> Bool
== :: CreateVault -> CreateVault -> Bool
$c== :: CreateVault -> CreateVault -> Bool
Prelude.Eq, ReadPrec [CreateVault]
ReadPrec CreateVault
Int -> ReadS CreateVault
ReadS [CreateVault]
(Int -> ReadS CreateVault)
-> ReadS [CreateVault]
-> ReadPrec CreateVault
-> ReadPrec [CreateVault]
-> Read CreateVault
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateVault]
$creadListPrec :: ReadPrec [CreateVault]
readPrec :: ReadPrec CreateVault
$creadPrec :: ReadPrec CreateVault
readList :: ReadS [CreateVault]
$creadList :: ReadS [CreateVault]
readsPrec :: Int -> ReadS CreateVault
$creadsPrec :: Int -> ReadS CreateVault
Prelude.Read, Int -> CreateVault -> ShowS
[CreateVault] -> ShowS
CreateVault -> String
(Int -> CreateVault -> ShowS)
-> (CreateVault -> String)
-> ([CreateVault] -> ShowS)
-> Show CreateVault
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateVault] -> ShowS
$cshowList :: [CreateVault] -> ShowS
show :: CreateVault -> String
$cshow :: CreateVault -> String
showsPrec :: Int -> CreateVault -> ShowS
$cshowsPrec :: Int -> CreateVault -> ShowS
Prelude.Show, (forall x. CreateVault -> Rep CreateVault x)
-> (forall x. Rep CreateVault x -> CreateVault)
-> Generic CreateVault
forall x. Rep CreateVault x -> CreateVault
forall x. CreateVault -> Rep CreateVault x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateVault x -> CreateVault
$cfrom :: forall x. CreateVault -> Rep CreateVault x
Prelude.Generic)

-- |
-- Create a value of 'CreateVault' 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', 'createVault_accountId' - The @AccountId@ value is the AWS account ID. This value must match the
-- AWS account ID associated with the credentials used to sign the request.
-- 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 specify
-- your account ID, do not include any hyphens (\'-\') in the ID.
--
-- 'vaultName', 'createVault_vaultName' - The name of the vault.
newCreateVault ::
  -- | 'accountId'
  Prelude.Text ->
  -- | 'vaultName'
  Prelude.Text ->
  CreateVault
newCreateVault :: Text -> Text -> CreateVault
newCreateVault Text
pAccountId_ Text
pVaultName_ =
  CreateVault' :: Text -> Text -> CreateVault
CreateVault'
    { $sel:accountId:CreateVault' :: Text
accountId = Text
pAccountId_,
      $sel:vaultName:CreateVault' :: Text
vaultName = Text
pVaultName_
    }

-- | The @AccountId@ value is the AWS account ID. This value must match the
-- AWS account ID associated with the credentials used to sign the request.
-- 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 specify
-- your account ID, do not include any hyphens (\'-\') in the ID.
createVault_accountId :: Lens.Lens' CreateVault Prelude.Text
createVault_accountId :: (Text -> f Text) -> CreateVault -> f CreateVault
createVault_accountId = (CreateVault -> Text)
-> (CreateVault -> Text -> CreateVault)
-> Lens CreateVault CreateVault Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateVault' {Text
accountId :: Text
$sel:accountId:CreateVault' :: CreateVault -> Text
accountId} -> Text
accountId) (\s :: CreateVault
s@CreateVault' {} Text
a -> CreateVault
s {$sel:accountId:CreateVault' :: Text
accountId = Text
a} :: CreateVault)

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

instance Core.AWSRequest CreateVault where
  type AWSResponse CreateVault = CreateVaultResponse
  request :: CreateVault -> Request CreateVault
request =
    ByteString -> Request CreateVault -> Request CreateVault
forall a. ByteString -> Request a -> Request a
Request.glacierVersionHeader (Service -> ByteString
Core._serviceVersion Service
defaultService)
      (Request CreateVault -> Request CreateVault)
-> (CreateVault -> Request CreateVault)
-> CreateVault
-> Request CreateVault
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. Service -> CreateVault -> Request CreateVault
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateVault
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateVault)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse CreateVault))
-> Logger
-> Service
-> Proxy CreateVault
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateVault)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Maybe Text -> Int -> CreateVaultResponse
CreateVaultResponse'
            (Maybe Text -> Int -> CreateVaultResponse)
-> Either String (Maybe Text)
-> Either String (Int -> CreateVaultResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (ResponseHeaders
h ResponseHeaders -> HeaderName -> Either String (Maybe Text)
forall a.
FromText a =>
ResponseHeaders -> HeaderName -> Either String (Maybe a)
Core..#? HeaderName
"Location")
            Either String (Int -> CreateVaultResponse)
-> Either String Int -> Either String CreateVaultResponse
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 CreateVault

instance Prelude.NFData CreateVault

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

instance Core.ToJSON CreateVault where
  toJSON :: CreateVault -> Value
toJSON = Value -> CreateVault -> Value
forall a b. a -> b -> a
Prelude.const (Object -> Value
Core.Object Object
forall a. Monoid a => a
Prelude.mempty)

instance Core.ToPath CreateVault where
  toPath :: CreateVault -> ByteString
toPath CreateVault' {Text
vaultName :: Text
accountId :: Text
$sel:vaultName:CreateVault' :: CreateVault -> Text
$sel:accountId:CreateVault' :: CreateVault -> 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
      ]

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

-- | Contains the Amazon S3 Glacier response to your request.
--
-- /See:/ 'newCreateVaultResponse' smart constructor.
data CreateVaultResponse = CreateVaultResponse'
  { -- | The URI of the vault that was created.
    CreateVaultResponse -> Maybe Text
location :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    CreateVaultResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateVaultResponse -> CreateVaultResponse -> Bool
(CreateVaultResponse -> CreateVaultResponse -> Bool)
-> (CreateVaultResponse -> CreateVaultResponse -> Bool)
-> Eq CreateVaultResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateVaultResponse -> CreateVaultResponse -> Bool
$c/= :: CreateVaultResponse -> CreateVaultResponse -> Bool
== :: CreateVaultResponse -> CreateVaultResponse -> Bool
$c== :: CreateVaultResponse -> CreateVaultResponse -> Bool
Prelude.Eq, ReadPrec [CreateVaultResponse]
ReadPrec CreateVaultResponse
Int -> ReadS CreateVaultResponse
ReadS [CreateVaultResponse]
(Int -> ReadS CreateVaultResponse)
-> ReadS [CreateVaultResponse]
-> ReadPrec CreateVaultResponse
-> ReadPrec [CreateVaultResponse]
-> Read CreateVaultResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateVaultResponse]
$creadListPrec :: ReadPrec [CreateVaultResponse]
readPrec :: ReadPrec CreateVaultResponse
$creadPrec :: ReadPrec CreateVaultResponse
readList :: ReadS [CreateVaultResponse]
$creadList :: ReadS [CreateVaultResponse]
readsPrec :: Int -> ReadS CreateVaultResponse
$creadsPrec :: Int -> ReadS CreateVaultResponse
Prelude.Read, Int -> CreateVaultResponse -> ShowS
[CreateVaultResponse] -> ShowS
CreateVaultResponse -> String
(Int -> CreateVaultResponse -> ShowS)
-> (CreateVaultResponse -> String)
-> ([CreateVaultResponse] -> ShowS)
-> Show CreateVaultResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateVaultResponse] -> ShowS
$cshowList :: [CreateVaultResponse] -> ShowS
show :: CreateVaultResponse -> String
$cshow :: CreateVaultResponse -> String
showsPrec :: Int -> CreateVaultResponse -> ShowS
$cshowsPrec :: Int -> CreateVaultResponse -> ShowS
Prelude.Show, (forall x. CreateVaultResponse -> Rep CreateVaultResponse x)
-> (forall x. Rep CreateVaultResponse x -> CreateVaultResponse)
-> Generic CreateVaultResponse
forall x. Rep CreateVaultResponse x -> CreateVaultResponse
forall x. CreateVaultResponse -> Rep CreateVaultResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateVaultResponse x -> CreateVaultResponse
$cfrom :: forall x. CreateVaultResponse -> Rep CreateVaultResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateVaultResponse' 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:
--
-- 'location', 'createVaultResponse_location' - The URI of the vault that was created.
--
-- 'httpStatus', 'createVaultResponse_httpStatus' - The response's http status code.
newCreateVaultResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateVaultResponse
newCreateVaultResponse :: Int -> CreateVaultResponse
newCreateVaultResponse Int
pHttpStatus_ =
  CreateVaultResponse' :: Maybe Text -> Int -> CreateVaultResponse
CreateVaultResponse'
    { $sel:location:CreateVaultResponse' :: Maybe Text
location = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateVaultResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The URI of the vault that was created.
createVaultResponse_location :: Lens.Lens' CreateVaultResponse (Prelude.Maybe Prelude.Text)
createVaultResponse_location :: (Maybe Text -> f (Maybe Text))
-> CreateVaultResponse -> f CreateVaultResponse
createVaultResponse_location = (CreateVaultResponse -> Maybe Text)
-> (CreateVaultResponse -> Maybe Text -> CreateVaultResponse)
-> Lens
     CreateVaultResponse CreateVaultResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateVaultResponse' {Maybe Text
location :: Maybe Text
$sel:location:CreateVaultResponse' :: CreateVaultResponse -> Maybe Text
location} -> Maybe Text
location) (\s :: CreateVaultResponse
s@CreateVaultResponse' {} Maybe Text
a -> CreateVaultResponse
s {$sel:location:CreateVaultResponse' :: Maybe Text
location = Maybe Text
a} :: CreateVaultResponse)

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

instance Prelude.NFData CreateVaultResponse