{-# 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.Lightsail.CreateBucketAccessKey
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates a new access key for the specified Amazon Lightsail bucket.
-- Access keys consist of an access key ID and corresponding secret access
-- key.
--
-- Access keys grant full programmatic access to the specified bucket and
-- its objects. You can have a maximum of two access keys per bucket. Use
-- the
-- <https://docs.aws.amazon.com/lightsail/2016-11-28/api-reference/API_GetBucketAccessKeys.html GetBucketAccessKeys>
-- action to get a list of current access keys for a specific bucket. For
-- more information about access keys, see
-- <https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-creating-bucket-access-keys Creating access keys for a bucket in Amazon Lightsail>
-- in the /Amazon Lightsail Developer Guide/.
--
-- The @secretAccessKey@ value is returned only in response to the
-- @CreateBucketAccessKey@ action. You can get a secret access key only
-- when you first create an access key; you cannot get the secret access
-- key later. If you lose the secret access key, you must create a new
-- access key.
module Amazonka.Lightsail.CreateBucketAccessKey
  ( -- * Creating a Request
    CreateBucketAccessKey (..),
    newCreateBucketAccessKey,

    -- * Request Lenses
    createBucketAccessKey_bucketName,

    -- * Destructuring the Response
    CreateBucketAccessKeyResponse (..),
    newCreateBucketAccessKeyResponse,

    -- * Response Lenses
    createBucketAccessKeyResponse_accessKey,
    createBucketAccessKeyResponse_operations,
    createBucketAccessKeyResponse_httpStatus,
  )
where

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

-- | /See:/ 'newCreateBucketAccessKey' smart constructor.
data CreateBucketAccessKey = CreateBucketAccessKey'
  { -- | The name of the bucket that the new access key will belong to, and grant
    -- access to.
    CreateBucketAccessKey -> Text
bucketName :: Prelude.Text
  }
  deriving (CreateBucketAccessKey -> CreateBucketAccessKey -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateBucketAccessKey -> CreateBucketAccessKey -> Bool
$c/= :: CreateBucketAccessKey -> CreateBucketAccessKey -> Bool
== :: CreateBucketAccessKey -> CreateBucketAccessKey -> Bool
$c== :: CreateBucketAccessKey -> CreateBucketAccessKey -> Bool
Prelude.Eq, ReadPrec [CreateBucketAccessKey]
ReadPrec CreateBucketAccessKey
Int -> ReadS CreateBucketAccessKey
ReadS [CreateBucketAccessKey]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateBucketAccessKey]
$creadListPrec :: ReadPrec [CreateBucketAccessKey]
readPrec :: ReadPrec CreateBucketAccessKey
$creadPrec :: ReadPrec CreateBucketAccessKey
readList :: ReadS [CreateBucketAccessKey]
$creadList :: ReadS [CreateBucketAccessKey]
readsPrec :: Int -> ReadS CreateBucketAccessKey
$creadsPrec :: Int -> ReadS CreateBucketAccessKey
Prelude.Read, Int -> CreateBucketAccessKey -> ShowS
[CreateBucketAccessKey] -> ShowS
CreateBucketAccessKey -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateBucketAccessKey] -> ShowS
$cshowList :: [CreateBucketAccessKey] -> ShowS
show :: CreateBucketAccessKey -> String
$cshow :: CreateBucketAccessKey -> String
showsPrec :: Int -> CreateBucketAccessKey -> ShowS
$cshowsPrec :: Int -> CreateBucketAccessKey -> ShowS
Prelude.Show, forall x. Rep CreateBucketAccessKey x -> CreateBucketAccessKey
forall x. CreateBucketAccessKey -> Rep CreateBucketAccessKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateBucketAccessKey x -> CreateBucketAccessKey
$cfrom :: forall x. CreateBucketAccessKey -> Rep CreateBucketAccessKey x
Prelude.Generic)

-- |
-- Create a value of 'CreateBucketAccessKey' 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:
--
-- 'bucketName', 'createBucketAccessKey_bucketName' - The name of the bucket that the new access key will belong to, and grant
-- access to.
newCreateBucketAccessKey ::
  -- | 'bucketName'
  Prelude.Text ->
  CreateBucketAccessKey
newCreateBucketAccessKey :: Text -> CreateBucketAccessKey
newCreateBucketAccessKey Text
pBucketName_ =
  CreateBucketAccessKey' {$sel:bucketName:CreateBucketAccessKey' :: Text
bucketName = Text
pBucketName_}

-- | The name of the bucket that the new access key will belong to, and grant
-- access to.
createBucketAccessKey_bucketName :: Lens.Lens' CreateBucketAccessKey Prelude.Text
createBucketAccessKey_bucketName :: Lens' CreateBucketAccessKey Text
createBucketAccessKey_bucketName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBucketAccessKey' {Text
bucketName :: Text
$sel:bucketName:CreateBucketAccessKey' :: CreateBucketAccessKey -> Text
bucketName} -> Text
bucketName) (\s :: CreateBucketAccessKey
s@CreateBucketAccessKey' {} Text
a -> CreateBucketAccessKey
s {$sel:bucketName:CreateBucketAccessKey' :: Text
bucketName = Text
a} :: CreateBucketAccessKey)

instance Core.AWSRequest CreateBucketAccessKey where
  type
    AWSResponse CreateBucketAccessKey =
      CreateBucketAccessKeyResponse
  request :: (Service -> Service)
-> CreateBucketAccessKey -> Request CreateBucketAccessKey
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy CreateBucketAccessKey
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateBucketAccessKey)))
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 ->
          Maybe AccessKey
-> Maybe [Operation] -> Int -> CreateBucketAccessKeyResponse
CreateBucketAccessKeyResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"accessKey")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"operations" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable CreateBucketAccessKey where
  hashWithSalt :: Int -> CreateBucketAccessKey -> Int
hashWithSalt Int
_salt CreateBucketAccessKey' {Text
bucketName :: Text
$sel:bucketName:CreateBucketAccessKey' :: CreateBucketAccessKey -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
bucketName

instance Prelude.NFData CreateBucketAccessKey where
  rnf :: CreateBucketAccessKey -> ()
rnf CreateBucketAccessKey' {Text
bucketName :: Text
$sel:bucketName:CreateBucketAccessKey' :: CreateBucketAccessKey -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
bucketName

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

instance Data.ToJSON CreateBucketAccessKey where
  toJSON :: CreateBucketAccessKey -> Value
toJSON CreateBucketAccessKey' {Text
bucketName :: Text
$sel:bucketName:CreateBucketAccessKey' :: CreateBucketAccessKey -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"bucketName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
bucketName)]
      )

instance Data.ToPath CreateBucketAccessKey where
  toPath :: CreateBucketAccessKey -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newCreateBucketAccessKeyResponse' smart constructor.
data CreateBucketAccessKeyResponse = CreateBucketAccessKeyResponse'
  { -- | An object that describes the access key that is created.
    CreateBucketAccessKeyResponse -> Maybe AccessKey
accessKey :: Prelude.Maybe AccessKey,
    -- | An array of objects that describe the result of the action, such as the
    -- status of the request, the timestamp of the request, and the resources
    -- affected by the request.
    CreateBucketAccessKeyResponse -> Maybe [Operation]
operations :: Prelude.Maybe [Operation],
    -- | The response's http status code.
    CreateBucketAccessKeyResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateBucketAccessKeyResponse
-> CreateBucketAccessKeyResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateBucketAccessKeyResponse
-> CreateBucketAccessKeyResponse -> Bool
$c/= :: CreateBucketAccessKeyResponse
-> CreateBucketAccessKeyResponse -> Bool
== :: CreateBucketAccessKeyResponse
-> CreateBucketAccessKeyResponse -> Bool
$c== :: CreateBucketAccessKeyResponse
-> CreateBucketAccessKeyResponse -> Bool
Prelude.Eq, Int -> CreateBucketAccessKeyResponse -> ShowS
[CreateBucketAccessKeyResponse] -> ShowS
CreateBucketAccessKeyResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateBucketAccessKeyResponse] -> ShowS
$cshowList :: [CreateBucketAccessKeyResponse] -> ShowS
show :: CreateBucketAccessKeyResponse -> String
$cshow :: CreateBucketAccessKeyResponse -> String
showsPrec :: Int -> CreateBucketAccessKeyResponse -> ShowS
$cshowsPrec :: Int -> CreateBucketAccessKeyResponse -> ShowS
Prelude.Show, forall x.
Rep CreateBucketAccessKeyResponse x
-> CreateBucketAccessKeyResponse
forall x.
CreateBucketAccessKeyResponse
-> Rep CreateBucketAccessKeyResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateBucketAccessKeyResponse x
-> CreateBucketAccessKeyResponse
$cfrom :: forall x.
CreateBucketAccessKeyResponse
-> Rep CreateBucketAccessKeyResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateBucketAccessKeyResponse' 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:
--
-- 'accessKey', 'createBucketAccessKeyResponse_accessKey' - An object that describes the access key that is created.
--
-- 'operations', 'createBucketAccessKeyResponse_operations' - An array of objects that describe the result of the action, such as the
-- status of the request, the timestamp of the request, and the resources
-- affected by the request.
--
-- 'httpStatus', 'createBucketAccessKeyResponse_httpStatus' - The response's http status code.
newCreateBucketAccessKeyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateBucketAccessKeyResponse
newCreateBucketAccessKeyResponse :: Int -> CreateBucketAccessKeyResponse
newCreateBucketAccessKeyResponse Int
pHttpStatus_ =
  CreateBucketAccessKeyResponse'
    { $sel:accessKey:CreateBucketAccessKeyResponse' :: Maybe AccessKey
accessKey =
        forall a. Maybe a
Prelude.Nothing,
      $sel:operations:CreateBucketAccessKeyResponse' :: Maybe [Operation]
operations = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateBucketAccessKeyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An object that describes the access key that is created.
createBucketAccessKeyResponse_accessKey :: Lens.Lens' CreateBucketAccessKeyResponse (Prelude.Maybe AccessKey)
createBucketAccessKeyResponse_accessKey :: Lens' CreateBucketAccessKeyResponse (Maybe AccessKey)
createBucketAccessKeyResponse_accessKey = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBucketAccessKeyResponse' {Maybe AccessKey
accessKey :: Maybe AccessKey
$sel:accessKey:CreateBucketAccessKeyResponse' :: CreateBucketAccessKeyResponse -> Maybe AccessKey
accessKey} -> Maybe AccessKey
accessKey) (\s :: CreateBucketAccessKeyResponse
s@CreateBucketAccessKeyResponse' {} Maybe AccessKey
a -> CreateBucketAccessKeyResponse
s {$sel:accessKey:CreateBucketAccessKeyResponse' :: Maybe AccessKey
accessKey = Maybe AccessKey
a} :: CreateBucketAccessKeyResponse)

-- | An array of objects that describe the result of the action, such as the
-- status of the request, the timestamp of the request, and the resources
-- affected by the request.
createBucketAccessKeyResponse_operations :: Lens.Lens' CreateBucketAccessKeyResponse (Prelude.Maybe [Operation])
createBucketAccessKeyResponse_operations :: Lens' CreateBucketAccessKeyResponse (Maybe [Operation])
createBucketAccessKeyResponse_operations = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBucketAccessKeyResponse' {Maybe [Operation]
operations :: Maybe [Operation]
$sel:operations:CreateBucketAccessKeyResponse' :: CreateBucketAccessKeyResponse -> Maybe [Operation]
operations} -> Maybe [Operation]
operations) (\s :: CreateBucketAccessKeyResponse
s@CreateBucketAccessKeyResponse' {} Maybe [Operation]
a -> CreateBucketAccessKeyResponse
s {$sel:operations:CreateBucketAccessKeyResponse' :: Maybe [Operation]
operations = Maybe [Operation]
a} :: CreateBucketAccessKeyResponse) 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 response's http status code.
createBucketAccessKeyResponse_httpStatus :: Lens.Lens' CreateBucketAccessKeyResponse Prelude.Int
createBucketAccessKeyResponse_httpStatus :: Lens' CreateBucketAccessKeyResponse Int
createBucketAccessKeyResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateBucketAccessKeyResponse' {Int
httpStatus :: Int
$sel:httpStatus:CreateBucketAccessKeyResponse' :: CreateBucketAccessKeyResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: CreateBucketAccessKeyResponse
s@CreateBucketAccessKeyResponse' {} Int
a -> CreateBucketAccessKeyResponse
s {$sel:httpStatus:CreateBucketAccessKeyResponse' :: Int
httpStatus = Int
a} :: CreateBucketAccessKeyResponse)

instance Prelude.NFData CreateBucketAccessKeyResponse where
  rnf :: CreateBucketAccessKeyResponse -> ()
rnf CreateBucketAccessKeyResponse' {Int
Maybe [Operation]
Maybe AccessKey
httpStatus :: Int
operations :: Maybe [Operation]
accessKey :: Maybe AccessKey
$sel:httpStatus:CreateBucketAccessKeyResponse' :: CreateBucketAccessKeyResponse -> Int
$sel:operations:CreateBucketAccessKeyResponse' :: CreateBucketAccessKeyResponse -> Maybe [Operation]
$sel:accessKey:CreateBucketAccessKeyResponse' :: CreateBucketAccessKeyResponse -> Maybe AccessKey
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe AccessKey
accessKey
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Operation]
operations
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus