{-# 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.CodeArtifact.GetDomainPermissionsPolicy
-- 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)
--
-- Returns the resource policy attached to the specified domain.
--
-- The policy is a resource-based policy, not an identity-based policy. For
-- more information, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_identity-vs-resource.html Identity-based policies and resource-based policies>
-- in the /AWS Identity and Access Management User Guide/.
module Amazonka.CodeArtifact.GetDomainPermissionsPolicy
  ( -- * Creating a Request
    GetDomainPermissionsPolicy (..),
    newGetDomainPermissionsPolicy,

    -- * Request Lenses
    getDomainPermissionsPolicy_domainOwner,
    getDomainPermissionsPolicy_domain,

    -- * Destructuring the Response
    GetDomainPermissionsPolicyResponse (..),
    newGetDomainPermissionsPolicyResponse,

    -- * Response Lenses
    getDomainPermissionsPolicyResponse_policy,
    getDomainPermissionsPolicyResponse_httpStatus,
  )
where

import Amazonka.CodeArtifact.Types
import qualified Amazonka.Core as Core
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:/ 'newGetDomainPermissionsPolicy' smart constructor.
data GetDomainPermissionsPolicy = GetDomainPermissionsPolicy'
  { -- | The 12-digit account number of the AWS account that owns the domain. It
    -- does not include dashes or spaces.
    GetDomainPermissionsPolicy -> Maybe Text
domainOwner :: Prelude.Maybe Prelude.Text,
    -- | The name of the domain to which the resource policy is attached.
    GetDomainPermissionsPolicy -> Text
domain :: Prelude.Text
  }
  deriving (GetDomainPermissionsPolicy -> GetDomainPermissionsPolicy -> Bool
(GetDomainPermissionsPolicy -> GetDomainPermissionsPolicy -> Bool)
-> (GetDomainPermissionsPolicy
    -> GetDomainPermissionsPolicy -> Bool)
-> Eq GetDomainPermissionsPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetDomainPermissionsPolicy -> GetDomainPermissionsPolicy -> Bool
$c/= :: GetDomainPermissionsPolicy -> GetDomainPermissionsPolicy -> Bool
== :: GetDomainPermissionsPolicy -> GetDomainPermissionsPolicy -> Bool
$c== :: GetDomainPermissionsPolicy -> GetDomainPermissionsPolicy -> Bool
Prelude.Eq, ReadPrec [GetDomainPermissionsPolicy]
ReadPrec GetDomainPermissionsPolicy
Int -> ReadS GetDomainPermissionsPolicy
ReadS [GetDomainPermissionsPolicy]
(Int -> ReadS GetDomainPermissionsPolicy)
-> ReadS [GetDomainPermissionsPolicy]
-> ReadPrec GetDomainPermissionsPolicy
-> ReadPrec [GetDomainPermissionsPolicy]
-> Read GetDomainPermissionsPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetDomainPermissionsPolicy]
$creadListPrec :: ReadPrec [GetDomainPermissionsPolicy]
readPrec :: ReadPrec GetDomainPermissionsPolicy
$creadPrec :: ReadPrec GetDomainPermissionsPolicy
readList :: ReadS [GetDomainPermissionsPolicy]
$creadList :: ReadS [GetDomainPermissionsPolicy]
readsPrec :: Int -> ReadS GetDomainPermissionsPolicy
$creadsPrec :: Int -> ReadS GetDomainPermissionsPolicy
Prelude.Read, Int -> GetDomainPermissionsPolicy -> ShowS
[GetDomainPermissionsPolicy] -> ShowS
GetDomainPermissionsPolicy -> String
(Int -> GetDomainPermissionsPolicy -> ShowS)
-> (GetDomainPermissionsPolicy -> String)
-> ([GetDomainPermissionsPolicy] -> ShowS)
-> Show GetDomainPermissionsPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetDomainPermissionsPolicy] -> ShowS
$cshowList :: [GetDomainPermissionsPolicy] -> ShowS
show :: GetDomainPermissionsPolicy -> String
$cshow :: GetDomainPermissionsPolicy -> String
showsPrec :: Int -> GetDomainPermissionsPolicy -> ShowS
$cshowsPrec :: Int -> GetDomainPermissionsPolicy -> ShowS
Prelude.Show, (forall x.
 GetDomainPermissionsPolicy -> Rep GetDomainPermissionsPolicy x)
-> (forall x.
    Rep GetDomainPermissionsPolicy x -> GetDomainPermissionsPolicy)
-> Generic GetDomainPermissionsPolicy
forall x.
Rep GetDomainPermissionsPolicy x -> GetDomainPermissionsPolicy
forall x.
GetDomainPermissionsPolicy -> Rep GetDomainPermissionsPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetDomainPermissionsPolicy x -> GetDomainPermissionsPolicy
$cfrom :: forall x.
GetDomainPermissionsPolicy -> Rep GetDomainPermissionsPolicy x
Prelude.Generic)

-- |
-- Create a value of 'GetDomainPermissionsPolicy' 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:
--
-- 'domainOwner', 'getDomainPermissionsPolicy_domainOwner' - The 12-digit account number of the AWS account that owns the domain. It
-- does not include dashes or spaces.
--
-- 'domain', 'getDomainPermissionsPolicy_domain' - The name of the domain to which the resource policy is attached.
newGetDomainPermissionsPolicy ::
  -- | 'domain'
  Prelude.Text ->
  GetDomainPermissionsPolicy
newGetDomainPermissionsPolicy :: Text -> GetDomainPermissionsPolicy
newGetDomainPermissionsPolicy Text
pDomain_ =
  GetDomainPermissionsPolicy' :: Maybe Text -> Text -> GetDomainPermissionsPolicy
GetDomainPermissionsPolicy'
    { $sel:domainOwner:GetDomainPermissionsPolicy' :: Maybe Text
domainOwner =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:domain:GetDomainPermissionsPolicy' :: Text
domain = Text
pDomain_
    }

-- | The 12-digit account number of the AWS account that owns the domain. It
-- does not include dashes or spaces.
getDomainPermissionsPolicy_domainOwner :: Lens.Lens' GetDomainPermissionsPolicy (Prelude.Maybe Prelude.Text)
getDomainPermissionsPolicy_domainOwner :: (Maybe Text -> f (Maybe Text))
-> GetDomainPermissionsPolicy -> f GetDomainPermissionsPolicy
getDomainPermissionsPolicy_domainOwner = (GetDomainPermissionsPolicy -> Maybe Text)
-> (GetDomainPermissionsPolicy
    -> Maybe Text -> GetDomainPermissionsPolicy)
-> Lens
     GetDomainPermissionsPolicy
     GetDomainPermissionsPolicy
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDomainPermissionsPolicy' {Maybe Text
domainOwner :: Maybe Text
$sel:domainOwner:GetDomainPermissionsPolicy' :: GetDomainPermissionsPolicy -> Maybe Text
domainOwner} -> Maybe Text
domainOwner) (\s :: GetDomainPermissionsPolicy
s@GetDomainPermissionsPolicy' {} Maybe Text
a -> GetDomainPermissionsPolicy
s {$sel:domainOwner:GetDomainPermissionsPolicy' :: Maybe Text
domainOwner = Maybe Text
a} :: GetDomainPermissionsPolicy)

-- | The name of the domain to which the resource policy is attached.
getDomainPermissionsPolicy_domain :: Lens.Lens' GetDomainPermissionsPolicy Prelude.Text
getDomainPermissionsPolicy_domain :: (Text -> f Text)
-> GetDomainPermissionsPolicy -> f GetDomainPermissionsPolicy
getDomainPermissionsPolicy_domain = (GetDomainPermissionsPolicy -> Text)
-> (GetDomainPermissionsPolicy
    -> Text -> GetDomainPermissionsPolicy)
-> Lens
     GetDomainPermissionsPolicy GetDomainPermissionsPolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDomainPermissionsPolicy' {Text
domain :: Text
$sel:domain:GetDomainPermissionsPolicy' :: GetDomainPermissionsPolicy -> Text
domain} -> Text
domain) (\s :: GetDomainPermissionsPolicy
s@GetDomainPermissionsPolicy' {} Text
a -> GetDomainPermissionsPolicy
s {$sel:domain:GetDomainPermissionsPolicy' :: Text
domain = Text
a} :: GetDomainPermissionsPolicy)

instance Core.AWSRequest GetDomainPermissionsPolicy where
  type
    AWSResponse GetDomainPermissionsPolicy =
      GetDomainPermissionsPolicyResponse
  request :: GetDomainPermissionsPolicy -> Request GetDomainPermissionsPolicy
request = Service
-> GetDomainPermissionsPolicy -> Request GetDomainPermissionsPolicy
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetDomainPermissionsPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetDomainPermissionsPolicy)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetDomainPermissionsPolicy))
-> Logger
-> Service
-> Proxy GetDomainPermissionsPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetDomainPermissionsPolicy)))
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 ResourcePolicy -> Int -> GetDomainPermissionsPolicyResponse
GetDomainPermissionsPolicyResponse'
            (Maybe ResourcePolicy -> Int -> GetDomainPermissionsPolicyResponse)
-> Either String (Maybe ResourcePolicy)
-> Either String (Int -> GetDomainPermissionsPolicyResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe ResourcePolicy)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"policy")
            Either String (Int -> GetDomainPermissionsPolicyResponse)
-> Either String Int
-> Either String GetDomainPermissionsPolicyResponse
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 GetDomainPermissionsPolicy

instance Prelude.NFData GetDomainPermissionsPolicy

instance Core.ToHeaders GetDomainPermissionsPolicy where
  toHeaders :: GetDomainPermissionsPolicy -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetDomainPermissionsPolicy -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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.ToPath GetDomainPermissionsPolicy where
  toPath :: GetDomainPermissionsPolicy -> ByteString
toPath =
    ByteString -> GetDomainPermissionsPolicy -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/v1/domain/permissions/policy"

instance Core.ToQuery GetDomainPermissionsPolicy where
  toQuery :: GetDomainPermissionsPolicy -> QueryString
toQuery GetDomainPermissionsPolicy' {Maybe Text
Text
domain :: Text
domainOwner :: Maybe Text
$sel:domain:GetDomainPermissionsPolicy' :: GetDomainPermissionsPolicy -> Text
$sel:domainOwner:GetDomainPermissionsPolicy' :: GetDomainPermissionsPolicy -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"domain-owner" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
domainOwner,
        ByteString
"domain" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
domain
      ]

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

-- |
-- Create a value of 'GetDomainPermissionsPolicyResponse' 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', 'getDomainPermissionsPolicyResponse_policy' - The returned resource policy.
--
-- 'httpStatus', 'getDomainPermissionsPolicyResponse_httpStatus' - The response's http status code.
newGetDomainPermissionsPolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetDomainPermissionsPolicyResponse
newGetDomainPermissionsPolicyResponse :: Int -> GetDomainPermissionsPolicyResponse
newGetDomainPermissionsPolicyResponse Int
pHttpStatus_ =
  GetDomainPermissionsPolicyResponse' :: Maybe ResourcePolicy -> Int -> GetDomainPermissionsPolicyResponse
GetDomainPermissionsPolicyResponse'
    { $sel:policy:GetDomainPermissionsPolicyResponse' :: Maybe ResourcePolicy
policy =
        Maybe ResourcePolicy
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetDomainPermissionsPolicyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The returned resource policy.
getDomainPermissionsPolicyResponse_policy :: Lens.Lens' GetDomainPermissionsPolicyResponse (Prelude.Maybe ResourcePolicy)
getDomainPermissionsPolicyResponse_policy :: (Maybe ResourcePolicy -> f (Maybe ResourcePolicy))
-> GetDomainPermissionsPolicyResponse
-> f GetDomainPermissionsPolicyResponse
getDomainPermissionsPolicyResponse_policy = (GetDomainPermissionsPolicyResponse -> Maybe ResourcePolicy)
-> (GetDomainPermissionsPolicyResponse
    -> Maybe ResourcePolicy -> GetDomainPermissionsPolicyResponse)
-> Lens
     GetDomainPermissionsPolicyResponse
     GetDomainPermissionsPolicyResponse
     (Maybe ResourcePolicy)
     (Maybe ResourcePolicy)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDomainPermissionsPolicyResponse' {Maybe ResourcePolicy
policy :: Maybe ResourcePolicy
$sel:policy:GetDomainPermissionsPolicyResponse' :: GetDomainPermissionsPolicyResponse -> Maybe ResourcePolicy
policy} -> Maybe ResourcePolicy
policy) (\s :: GetDomainPermissionsPolicyResponse
s@GetDomainPermissionsPolicyResponse' {} Maybe ResourcePolicy
a -> GetDomainPermissionsPolicyResponse
s {$sel:policy:GetDomainPermissionsPolicyResponse' :: Maybe ResourcePolicy
policy = Maybe ResourcePolicy
a} :: GetDomainPermissionsPolicyResponse)

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

instance
  Prelude.NFData
    GetDomainPermissionsPolicyResponse