{-# 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-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)
--
-- 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 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.Lens as Lens
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
(CreateBucketAccessKey -> CreateBucketAccessKey -> Bool)
-> (CreateBucketAccessKey -> CreateBucketAccessKey -> Bool)
-> Eq CreateBucketAccessKey
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]
(Int -> ReadS CreateBucketAccessKey)
-> ReadS [CreateBucketAccessKey]
-> ReadPrec CreateBucketAccessKey
-> ReadPrec [CreateBucketAccessKey]
-> Read 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
(Int -> CreateBucketAccessKey -> ShowS)
-> (CreateBucketAccessKey -> String)
-> ([CreateBucketAccessKey] -> ShowS)
-> Show CreateBucketAccessKey
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. CreateBucketAccessKey -> Rep CreateBucketAccessKey x)
-> (forall x. Rep CreateBucketAccessKey x -> CreateBucketAccessKey)
-> Generic CreateBucketAccessKey
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' :: Text -> CreateBucketAccessKey
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 :: (Text -> f Text)
-> CreateBucketAccessKey -> f CreateBucketAccessKey
createBucketAccessKey_bucketName = (CreateBucketAccessKey -> Text)
-> (CreateBucketAccessKey -> Text -> CreateBucketAccessKey)
-> Lens CreateBucketAccessKey CreateBucketAccessKey Text Text
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 :: CreateBucketAccessKey -> Request CreateBucketAccessKey
request = Service -> CreateBucketAccessKey -> Request CreateBucketAccessKey
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateBucketAccessKey
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateBucketAccessKey)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateBucketAccessKey))
-> Logger
-> Service
-> Proxy CreateBucketAccessKey
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateBucketAccessKey)))
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 AccessKey
-> Maybe [Operation] -> Int -> CreateBucketAccessKeyResponse
CreateBucketAccessKeyResponse'
            (Maybe AccessKey
 -> Maybe [Operation] -> Int -> CreateBucketAccessKeyResponse)
-> Either String (Maybe AccessKey)
-> Either
     String (Maybe [Operation] -> Int -> CreateBucketAccessKeyResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe AccessKey)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"accessKey")
            Either
  String (Maybe [Operation] -> Int -> CreateBucketAccessKeyResponse)
-> Either String (Maybe [Operation])
-> Either String (Int -> CreateBucketAccessKeyResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe (Maybe [Operation]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"operations" Either String (Maybe (Maybe [Operation]))
-> Maybe [Operation] -> Either String (Maybe [Operation])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [Operation]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> CreateBucketAccessKeyResponse)
-> Either String Int -> Either String CreateBucketAccessKeyResponse
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 CreateBucketAccessKey

instance Prelude.NFData CreateBucketAccessKey

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

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

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

instance Core.ToQuery CreateBucketAccessKey where
  toQuery :: CreateBucketAccessKey -> QueryString
toQuery = QueryString -> CreateBucketAccessKey -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(CreateBucketAccessKeyResponse
 -> CreateBucketAccessKeyResponse -> Bool)
-> (CreateBucketAccessKeyResponse
    -> CreateBucketAccessKeyResponse -> Bool)
-> Eq CreateBucketAccessKeyResponse
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
(Int -> CreateBucketAccessKeyResponse -> ShowS)
-> (CreateBucketAccessKeyResponse -> String)
-> ([CreateBucketAccessKeyResponse] -> ShowS)
-> Show CreateBucketAccessKeyResponse
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.
 CreateBucketAccessKeyResponse
 -> Rep CreateBucketAccessKeyResponse x)
-> (forall x.
    Rep CreateBucketAccessKeyResponse x
    -> CreateBucketAccessKeyResponse)
-> Generic CreateBucketAccessKeyResponse
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' :: Maybe AccessKey
-> Maybe [Operation] -> Int -> CreateBucketAccessKeyResponse
CreateBucketAccessKeyResponse'
    { $sel:accessKey:CreateBucketAccessKeyResponse' :: Maybe AccessKey
accessKey =
        Maybe AccessKey
forall a. Maybe a
Prelude.Nothing,
      $sel:operations:CreateBucketAccessKeyResponse' :: Maybe [Operation]
operations = Maybe [Operation]
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 :: (Maybe AccessKey -> f (Maybe AccessKey))
-> CreateBucketAccessKeyResponse -> f CreateBucketAccessKeyResponse
createBucketAccessKeyResponse_accessKey = (CreateBucketAccessKeyResponse -> Maybe AccessKey)
-> (CreateBucketAccessKeyResponse
    -> Maybe AccessKey -> CreateBucketAccessKeyResponse)
-> Lens
     CreateBucketAccessKeyResponse
     CreateBucketAccessKeyResponse
     (Maybe AccessKey)
     (Maybe 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 :: (Maybe [Operation] -> f (Maybe [Operation]))
-> CreateBucketAccessKeyResponse -> f CreateBucketAccessKeyResponse
createBucketAccessKeyResponse_operations = (CreateBucketAccessKeyResponse -> Maybe [Operation])
-> (CreateBucketAccessKeyResponse
    -> Maybe [Operation] -> CreateBucketAccessKeyResponse)
-> Lens
     CreateBucketAccessKeyResponse
     CreateBucketAccessKeyResponse
     (Maybe [Operation])
     (Maybe [Operation])
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) ((Maybe [Operation] -> f (Maybe [Operation]))
 -> CreateBucketAccessKeyResponse
 -> f CreateBucketAccessKeyResponse)
-> ((Maybe [Operation] -> f (Maybe [Operation]))
    -> Maybe [Operation] -> f (Maybe [Operation]))
-> (Maybe [Operation] -> f (Maybe [Operation]))
-> CreateBucketAccessKeyResponse
-> f CreateBucketAccessKeyResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Operation] [Operation] [Operation] [Operation]
-> Iso
     (Maybe [Operation])
     (Maybe [Operation])
     (Maybe [Operation])
     (Maybe [Operation])
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 AnIso [Operation] [Operation] [Operation] [Operation]
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 :: (Int -> f Int)
-> CreateBucketAccessKeyResponse -> f CreateBucketAccessKeyResponse
createBucketAccessKeyResponse_httpStatus = (CreateBucketAccessKeyResponse -> Int)
-> (CreateBucketAccessKeyResponse
    -> Int -> CreateBucketAccessKeyResponse)
-> Lens
     CreateBucketAccessKeyResponse CreateBucketAccessKeyResponse Int Int
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