{-# 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.LakeFormation.RegisterResource
-- 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)
--
-- Registers the resource as managed by the Data Catalog.
--
-- To add or update data, Lake Formation needs read\/write access to the
-- chosen Amazon S3 path. Choose a role that you know has permission to do
-- this, or choose the AWSServiceRoleForLakeFormationDataAccess
-- service-linked role. When you register the first Amazon S3 path, the
-- service-linked role and a new inline policy are created on your behalf.
-- Lake Formation adds the first path to the inline policy and attaches it
-- to the service-linked role. When you register subsequent paths, Lake
-- Formation adds the path to the existing policy.
--
-- The following request registers a new location and gives AWS Lake
-- Formation permission to use the service-linked role to access that
-- location.
--
-- @ResourceArn = arn:aws:s3:::my-bucket UseServiceLinkedRole = true@
--
-- If @UseServiceLinkedRole@ is not set to true, you must provide or set
-- the @RoleArn@:
--
-- @arn:aws:iam::12345:role\/my-data-access-role@
module Amazonka.LakeFormation.RegisterResource
  ( -- * Creating a Request
    RegisterResource (..),
    newRegisterResource,

    -- * Request Lenses
    registerResource_useServiceLinkedRole,
    registerResource_roleArn,
    registerResource_resourceArn,

    -- * Destructuring the Response
    RegisterResourceResponse (..),
    newRegisterResourceResponse,

    -- * Response Lenses
    registerResourceResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.LakeFormation.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

-- | /See:/ 'newRegisterResource' smart constructor.
data RegisterResource = RegisterResource'
  { -- | Designates an AWS Identity and Access Management (IAM) service-linked
    -- role by registering this role with the Data Catalog. A service-linked
    -- role is a unique type of IAM role that is linked directly to Lake
    -- Formation.
    --
    -- For more information, see
    -- <https://docs-aws.amazon.com/lake-formation/latest/dg/service-linked-roles.html Using Service-Linked Roles for Lake Formation>.
    RegisterResource -> Maybe Bool
useServiceLinkedRole :: Prelude.Maybe Prelude.Bool,
    -- | The identifier for the role that registers the resource.
    RegisterResource -> Maybe Text
roleArn :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the resource that you want to
    -- register.
    RegisterResource -> Text
resourceArn :: Prelude.Text
  }
  deriving (RegisterResource -> RegisterResource -> Bool
(RegisterResource -> RegisterResource -> Bool)
-> (RegisterResource -> RegisterResource -> Bool)
-> Eq RegisterResource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegisterResource -> RegisterResource -> Bool
$c/= :: RegisterResource -> RegisterResource -> Bool
== :: RegisterResource -> RegisterResource -> Bool
$c== :: RegisterResource -> RegisterResource -> Bool
Prelude.Eq, ReadPrec [RegisterResource]
ReadPrec RegisterResource
Int -> ReadS RegisterResource
ReadS [RegisterResource]
(Int -> ReadS RegisterResource)
-> ReadS [RegisterResource]
-> ReadPrec RegisterResource
-> ReadPrec [RegisterResource]
-> Read RegisterResource
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegisterResource]
$creadListPrec :: ReadPrec [RegisterResource]
readPrec :: ReadPrec RegisterResource
$creadPrec :: ReadPrec RegisterResource
readList :: ReadS [RegisterResource]
$creadList :: ReadS [RegisterResource]
readsPrec :: Int -> ReadS RegisterResource
$creadsPrec :: Int -> ReadS RegisterResource
Prelude.Read, Int -> RegisterResource -> ShowS
[RegisterResource] -> ShowS
RegisterResource -> String
(Int -> RegisterResource -> ShowS)
-> (RegisterResource -> String)
-> ([RegisterResource] -> ShowS)
-> Show RegisterResource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegisterResource] -> ShowS
$cshowList :: [RegisterResource] -> ShowS
show :: RegisterResource -> String
$cshow :: RegisterResource -> String
showsPrec :: Int -> RegisterResource -> ShowS
$cshowsPrec :: Int -> RegisterResource -> ShowS
Prelude.Show, (forall x. RegisterResource -> Rep RegisterResource x)
-> (forall x. Rep RegisterResource x -> RegisterResource)
-> Generic RegisterResource
forall x. Rep RegisterResource x -> RegisterResource
forall x. RegisterResource -> Rep RegisterResource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RegisterResource x -> RegisterResource
$cfrom :: forall x. RegisterResource -> Rep RegisterResource x
Prelude.Generic)

-- |
-- Create a value of 'RegisterResource' 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:
--
-- 'useServiceLinkedRole', 'registerResource_useServiceLinkedRole' - Designates an AWS Identity and Access Management (IAM) service-linked
-- role by registering this role with the Data Catalog. A service-linked
-- role is a unique type of IAM role that is linked directly to Lake
-- Formation.
--
-- For more information, see
-- <https://docs-aws.amazon.com/lake-formation/latest/dg/service-linked-roles.html Using Service-Linked Roles for Lake Formation>.
--
-- 'roleArn', 'registerResource_roleArn' - The identifier for the role that registers the resource.
--
-- 'resourceArn', 'registerResource_resourceArn' - The Amazon Resource Name (ARN) of the resource that you want to
-- register.
newRegisterResource ::
  -- | 'resourceArn'
  Prelude.Text ->
  RegisterResource
newRegisterResource :: Text -> RegisterResource
newRegisterResource Text
pResourceArn_ =
  RegisterResource' :: Maybe Bool -> Maybe Text -> Text -> RegisterResource
RegisterResource'
    { $sel:useServiceLinkedRole:RegisterResource' :: Maybe Bool
useServiceLinkedRole =
        Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:roleArn:RegisterResource' :: Maybe Text
roleArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:resourceArn:RegisterResource' :: Text
resourceArn = Text
pResourceArn_
    }

-- | Designates an AWS Identity and Access Management (IAM) service-linked
-- role by registering this role with the Data Catalog. A service-linked
-- role is a unique type of IAM role that is linked directly to Lake
-- Formation.
--
-- For more information, see
-- <https://docs-aws.amazon.com/lake-formation/latest/dg/service-linked-roles.html Using Service-Linked Roles for Lake Formation>.
registerResource_useServiceLinkedRole :: Lens.Lens' RegisterResource (Prelude.Maybe Prelude.Bool)
registerResource_useServiceLinkedRole :: (Maybe Bool -> f (Maybe Bool))
-> RegisterResource -> f RegisterResource
registerResource_useServiceLinkedRole = (RegisterResource -> Maybe Bool)
-> (RegisterResource -> Maybe Bool -> RegisterResource)
-> Lens RegisterResource RegisterResource (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterResource' {Maybe Bool
useServiceLinkedRole :: Maybe Bool
$sel:useServiceLinkedRole:RegisterResource' :: RegisterResource -> Maybe Bool
useServiceLinkedRole} -> Maybe Bool
useServiceLinkedRole) (\s :: RegisterResource
s@RegisterResource' {} Maybe Bool
a -> RegisterResource
s {$sel:useServiceLinkedRole:RegisterResource' :: Maybe Bool
useServiceLinkedRole = Maybe Bool
a} :: RegisterResource)

-- | The identifier for the role that registers the resource.
registerResource_roleArn :: Lens.Lens' RegisterResource (Prelude.Maybe Prelude.Text)
registerResource_roleArn :: (Maybe Text -> f (Maybe Text))
-> RegisterResource -> f RegisterResource
registerResource_roleArn = (RegisterResource -> Maybe Text)
-> (RegisterResource -> Maybe Text -> RegisterResource)
-> Lens RegisterResource RegisterResource (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterResource' {Maybe Text
roleArn :: Maybe Text
$sel:roleArn:RegisterResource' :: RegisterResource -> Maybe Text
roleArn} -> Maybe Text
roleArn) (\s :: RegisterResource
s@RegisterResource' {} Maybe Text
a -> RegisterResource
s {$sel:roleArn:RegisterResource' :: Maybe Text
roleArn = Maybe Text
a} :: RegisterResource)

-- | The Amazon Resource Name (ARN) of the resource that you want to
-- register.
registerResource_resourceArn :: Lens.Lens' RegisterResource Prelude.Text
registerResource_resourceArn :: (Text -> f Text) -> RegisterResource -> f RegisterResource
registerResource_resourceArn = (RegisterResource -> Text)
-> (RegisterResource -> Text -> RegisterResource)
-> Lens RegisterResource RegisterResource Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterResource' {Text
resourceArn :: Text
$sel:resourceArn:RegisterResource' :: RegisterResource -> Text
resourceArn} -> Text
resourceArn) (\s :: RegisterResource
s@RegisterResource' {} Text
a -> RegisterResource
s {$sel:resourceArn:RegisterResource' :: Text
resourceArn = Text
a} :: RegisterResource)

instance Core.AWSRequest RegisterResource where
  type
    AWSResponse RegisterResource =
      RegisterResourceResponse
  request :: RegisterResource -> Request RegisterResource
request = Service -> RegisterResource -> Request RegisterResource
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy RegisterResource
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse RegisterResource)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse RegisterResource))
-> Logger
-> Service
-> Proxy RegisterResource
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse RegisterResource)))
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 ->
          Int -> RegisterResourceResponse
RegisterResourceResponse'
            (Int -> RegisterResourceResponse)
-> Either String Int -> Either String RegisterResourceResponse
forall (f :: * -> *) a b. Functor 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 RegisterResource

instance Prelude.NFData RegisterResource

instance Core.ToHeaders RegisterResource where
  toHeaders :: RegisterResource -> ResponseHeaders
toHeaders =
    ResponseHeaders -> RegisterResource -> 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
"AWSLakeFormation.RegisterResource" ::
                          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 RegisterResource where
  toJSON :: RegisterResource -> Value
toJSON RegisterResource' {Maybe Bool
Maybe Text
Text
resourceArn :: Text
roleArn :: Maybe Text
useServiceLinkedRole :: Maybe Bool
$sel:resourceArn:RegisterResource' :: RegisterResource -> Text
$sel:roleArn:RegisterResource' :: RegisterResource -> Maybe Text
$sel:useServiceLinkedRole:RegisterResource' :: RegisterResource -> Maybe Bool
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"UseServiceLinkedRole" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
useServiceLinkedRole,
            (Text
"RoleArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
roleArn,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ResourceArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
resourceArn)
          ]
      )

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

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

-- | /See:/ 'newRegisterResourceResponse' smart constructor.
data RegisterResourceResponse = RegisterResourceResponse'
  { -- | The response's http status code.
    RegisterResourceResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (RegisterResourceResponse -> RegisterResourceResponse -> Bool
(RegisterResourceResponse -> RegisterResourceResponse -> Bool)
-> (RegisterResourceResponse -> RegisterResourceResponse -> Bool)
-> Eq RegisterResourceResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegisterResourceResponse -> RegisterResourceResponse -> Bool
$c/= :: RegisterResourceResponse -> RegisterResourceResponse -> Bool
== :: RegisterResourceResponse -> RegisterResourceResponse -> Bool
$c== :: RegisterResourceResponse -> RegisterResourceResponse -> Bool
Prelude.Eq, ReadPrec [RegisterResourceResponse]
ReadPrec RegisterResourceResponse
Int -> ReadS RegisterResourceResponse
ReadS [RegisterResourceResponse]
(Int -> ReadS RegisterResourceResponse)
-> ReadS [RegisterResourceResponse]
-> ReadPrec RegisterResourceResponse
-> ReadPrec [RegisterResourceResponse]
-> Read RegisterResourceResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegisterResourceResponse]
$creadListPrec :: ReadPrec [RegisterResourceResponse]
readPrec :: ReadPrec RegisterResourceResponse
$creadPrec :: ReadPrec RegisterResourceResponse
readList :: ReadS [RegisterResourceResponse]
$creadList :: ReadS [RegisterResourceResponse]
readsPrec :: Int -> ReadS RegisterResourceResponse
$creadsPrec :: Int -> ReadS RegisterResourceResponse
Prelude.Read, Int -> RegisterResourceResponse -> ShowS
[RegisterResourceResponse] -> ShowS
RegisterResourceResponse -> String
(Int -> RegisterResourceResponse -> ShowS)
-> (RegisterResourceResponse -> String)
-> ([RegisterResourceResponse] -> ShowS)
-> Show RegisterResourceResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegisterResourceResponse] -> ShowS
$cshowList :: [RegisterResourceResponse] -> ShowS
show :: RegisterResourceResponse -> String
$cshow :: RegisterResourceResponse -> String
showsPrec :: Int -> RegisterResourceResponse -> ShowS
$cshowsPrec :: Int -> RegisterResourceResponse -> ShowS
Prelude.Show, (forall x.
 RegisterResourceResponse -> Rep RegisterResourceResponse x)
-> (forall x.
    Rep RegisterResourceResponse x -> RegisterResourceResponse)
-> Generic RegisterResourceResponse
forall x.
Rep RegisterResourceResponse x -> RegisterResourceResponse
forall x.
RegisterResourceResponse -> Rep RegisterResourceResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep RegisterResourceResponse x -> RegisterResourceResponse
$cfrom :: forall x.
RegisterResourceResponse -> Rep RegisterResourceResponse x
Prelude.Generic)

-- |
-- Create a value of 'RegisterResourceResponse' 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:
--
-- 'httpStatus', 'registerResourceResponse_httpStatus' - The response's http status code.
newRegisterResourceResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  RegisterResourceResponse
newRegisterResourceResponse :: Int -> RegisterResourceResponse
newRegisterResourceResponse Int
pHttpStatus_ =
  RegisterResourceResponse' :: Int -> RegisterResourceResponse
RegisterResourceResponse'
    { $sel:httpStatus:RegisterResourceResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

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

instance Prelude.NFData RegisterResourceResponse