{-# 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.ECR.GetRegistryPolicy
-- 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)
--
-- Retrieves the permissions policy for a registry.
module Amazonka.ECR.GetRegistryPolicy
  ( -- * Creating a Request
    GetRegistryPolicy (..),
    newGetRegistryPolicy,

    -- * Destructuring the Response
    GetRegistryPolicyResponse (..),
    newGetRegistryPolicyResponse,

    -- * Response Lenses
    getRegistryPolicyResponse_registryId,
    getRegistryPolicyResponse_policyText,
    getRegistryPolicyResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.ECR.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:/ 'newGetRegistryPolicy' smart constructor.
data GetRegistryPolicy = GetRegistryPolicy'
  {
  }
  deriving (GetRegistryPolicy -> GetRegistryPolicy -> Bool
(GetRegistryPolicy -> GetRegistryPolicy -> Bool)
-> (GetRegistryPolicy -> GetRegistryPolicy -> Bool)
-> Eq GetRegistryPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetRegistryPolicy -> GetRegistryPolicy -> Bool
$c/= :: GetRegistryPolicy -> GetRegistryPolicy -> Bool
== :: GetRegistryPolicy -> GetRegistryPolicy -> Bool
$c== :: GetRegistryPolicy -> GetRegistryPolicy -> Bool
Prelude.Eq, ReadPrec [GetRegistryPolicy]
ReadPrec GetRegistryPolicy
Int -> ReadS GetRegistryPolicy
ReadS [GetRegistryPolicy]
(Int -> ReadS GetRegistryPolicy)
-> ReadS [GetRegistryPolicy]
-> ReadPrec GetRegistryPolicy
-> ReadPrec [GetRegistryPolicy]
-> Read GetRegistryPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetRegistryPolicy]
$creadListPrec :: ReadPrec [GetRegistryPolicy]
readPrec :: ReadPrec GetRegistryPolicy
$creadPrec :: ReadPrec GetRegistryPolicy
readList :: ReadS [GetRegistryPolicy]
$creadList :: ReadS [GetRegistryPolicy]
readsPrec :: Int -> ReadS GetRegistryPolicy
$creadsPrec :: Int -> ReadS GetRegistryPolicy
Prelude.Read, Int -> GetRegistryPolicy -> ShowS
[GetRegistryPolicy] -> ShowS
GetRegistryPolicy -> String
(Int -> GetRegistryPolicy -> ShowS)
-> (GetRegistryPolicy -> String)
-> ([GetRegistryPolicy] -> ShowS)
-> Show GetRegistryPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetRegistryPolicy] -> ShowS
$cshowList :: [GetRegistryPolicy] -> ShowS
show :: GetRegistryPolicy -> String
$cshow :: GetRegistryPolicy -> String
showsPrec :: Int -> GetRegistryPolicy -> ShowS
$cshowsPrec :: Int -> GetRegistryPolicy -> ShowS
Prelude.Show, (forall x. GetRegistryPolicy -> Rep GetRegistryPolicy x)
-> (forall x. Rep GetRegistryPolicy x -> GetRegistryPolicy)
-> Generic GetRegistryPolicy
forall x. Rep GetRegistryPolicy x -> GetRegistryPolicy
forall x. GetRegistryPolicy -> Rep GetRegistryPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetRegistryPolicy x -> GetRegistryPolicy
$cfrom :: forall x. GetRegistryPolicy -> Rep GetRegistryPolicy x
Prelude.Generic)

-- |
-- Create a value of 'GetRegistryPolicy' 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.
newGetRegistryPolicy ::
  GetRegistryPolicy
newGetRegistryPolicy :: GetRegistryPolicy
newGetRegistryPolicy = GetRegistryPolicy
GetRegistryPolicy'

instance Core.AWSRequest GetRegistryPolicy where
  type
    AWSResponse GetRegistryPolicy =
      GetRegistryPolicyResponse
  request :: GetRegistryPolicy -> Request GetRegistryPolicy
request = Service -> GetRegistryPolicy -> Request GetRegistryPolicy
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetRegistryPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetRegistryPolicy)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetRegistryPolicy))
-> Logger
-> Service
-> Proxy GetRegistryPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetRegistryPolicy)))
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 Text -> Maybe Text -> Int -> GetRegistryPolicyResponse
GetRegistryPolicyResponse'
            (Maybe Text -> Maybe Text -> Int -> GetRegistryPolicyResponse)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Int -> GetRegistryPolicyResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"registryId")
            Either String (Maybe Text -> Int -> GetRegistryPolicyResponse)
-> Either String (Maybe Text)
-> Either String (Int -> GetRegistryPolicyResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"policyText")
            Either String (Int -> GetRegistryPolicyResponse)
-> Either String Int -> Either String GetRegistryPolicyResponse
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 GetRegistryPolicy

instance Prelude.NFData GetRegistryPolicy

instance Core.ToHeaders GetRegistryPolicy where
  toHeaders :: GetRegistryPolicy -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetRegistryPolicy -> 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
"AmazonEC2ContainerRegistry_V20150921.GetRegistryPolicy" ::
                          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 GetRegistryPolicy where
  toJSON :: GetRegistryPolicy -> Value
toJSON = Value -> GetRegistryPolicy -> Value
forall a b. a -> b -> a
Prelude.const (Object -> Value
Core.Object Object
forall a. Monoid a => a
Prelude.mempty)

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

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

-- | /See:/ 'newGetRegistryPolicyResponse' smart constructor.
data GetRegistryPolicyResponse = GetRegistryPolicyResponse'
  { -- | The ID of the registry.
    GetRegistryPolicyResponse -> Maybe Text
registryId :: Prelude.Maybe Prelude.Text,
    -- | The JSON text of the permissions policy for a registry.
    GetRegistryPolicyResponse -> Maybe Text
policyText :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetRegistryPolicyResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetRegistryPolicyResponse -> GetRegistryPolicyResponse -> Bool
(GetRegistryPolicyResponse -> GetRegistryPolicyResponse -> Bool)
-> (GetRegistryPolicyResponse -> GetRegistryPolicyResponse -> Bool)
-> Eq GetRegistryPolicyResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetRegistryPolicyResponse -> GetRegistryPolicyResponse -> Bool
$c/= :: GetRegistryPolicyResponse -> GetRegistryPolicyResponse -> Bool
== :: GetRegistryPolicyResponse -> GetRegistryPolicyResponse -> Bool
$c== :: GetRegistryPolicyResponse -> GetRegistryPolicyResponse -> Bool
Prelude.Eq, ReadPrec [GetRegistryPolicyResponse]
ReadPrec GetRegistryPolicyResponse
Int -> ReadS GetRegistryPolicyResponse
ReadS [GetRegistryPolicyResponse]
(Int -> ReadS GetRegistryPolicyResponse)
-> ReadS [GetRegistryPolicyResponse]
-> ReadPrec GetRegistryPolicyResponse
-> ReadPrec [GetRegistryPolicyResponse]
-> Read GetRegistryPolicyResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetRegistryPolicyResponse]
$creadListPrec :: ReadPrec [GetRegistryPolicyResponse]
readPrec :: ReadPrec GetRegistryPolicyResponse
$creadPrec :: ReadPrec GetRegistryPolicyResponse
readList :: ReadS [GetRegistryPolicyResponse]
$creadList :: ReadS [GetRegistryPolicyResponse]
readsPrec :: Int -> ReadS GetRegistryPolicyResponse
$creadsPrec :: Int -> ReadS GetRegistryPolicyResponse
Prelude.Read, Int -> GetRegistryPolicyResponse -> ShowS
[GetRegistryPolicyResponse] -> ShowS
GetRegistryPolicyResponse -> String
(Int -> GetRegistryPolicyResponse -> ShowS)
-> (GetRegistryPolicyResponse -> String)
-> ([GetRegistryPolicyResponse] -> ShowS)
-> Show GetRegistryPolicyResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetRegistryPolicyResponse] -> ShowS
$cshowList :: [GetRegistryPolicyResponse] -> ShowS
show :: GetRegistryPolicyResponse -> String
$cshow :: GetRegistryPolicyResponse -> String
showsPrec :: Int -> GetRegistryPolicyResponse -> ShowS
$cshowsPrec :: Int -> GetRegistryPolicyResponse -> ShowS
Prelude.Show, (forall x.
 GetRegistryPolicyResponse -> Rep GetRegistryPolicyResponse x)
-> (forall x.
    Rep GetRegistryPolicyResponse x -> GetRegistryPolicyResponse)
-> Generic GetRegistryPolicyResponse
forall x.
Rep GetRegistryPolicyResponse x -> GetRegistryPolicyResponse
forall x.
GetRegistryPolicyResponse -> Rep GetRegistryPolicyResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetRegistryPolicyResponse x -> GetRegistryPolicyResponse
$cfrom :: forall x.
GetRegistryPolicyResponse -> Rep GetRegistryPolicyResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetRegistryPolicyResponse' 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:
--
-- 'registryId', 'getRegistryPolicyResponse_registryId' - The ID of the registry.
--
-- 'policyText', 'getRegistryPolicyResponse_policyText' - The JSON text of the permissions policy for a registry.
--
-- 'httpStatus', 'getRegistryPolicyResponse_httpStatus' - The response's http status code.
newGetRegistryPolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetRegistryPolicyResponse
newGetRegistryPolicyResponse :: Int -> GetRegistryPolicyResponse
newGetRegistryPolicyResponse Int
pHttpStatus_ =
  GetRegistryPolicyResponse' :: Maybe Text -> Maybe Text -> Int -> GetRegistryPolicyResponse
GetRegistryPolicyResponse'
    { $sel:registryId:GetRegistryPolicyResponse' :: Maybe Text
registryId =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:policyText:GetRegistryPolicyResponse' :: Maybe Text
policyText = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetRegistryPolicyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The ID of the registry.
getRegistryPolicyResponse_registryId :: Lens.Lens' GetRegistryPolicyResponse (Prelude.Maybe Prelude.Text)
getRegistryPolicyResponse_registryId :: (Maybe Text -> f (Maybe Text))
-> GetRegistryPolicyResponse -> f GetRegistryPolicyResponse
getRegistryPolicyResponse_registryId = (GetRegistryPolicyResponse -> Maybe Text)
-> (GetRegistryPolicyResponse
    -> Maybe Text -> GetRegistryPolicyResponse)
-> Lens
     GetRegistryPolicyResponse
     GetRegistryPolicyResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRegistryPolicyResponse' {Maybe Text
registryId :: Maybe Text
$sel:registryId:GetRegistryPolicyResponse' :: GetRegistryPolicyResponse -> Maybe Text
registryId} -> Maybe Text
registryId) (\s :: GetRegistryPolicyResponse
s@GetRegistryPolicyResponse' {} Maybe Text
a -> GetRegistryPolicyResponse
s {$sel:registryId:GetRegistryPolicyResponse' :: Maybe Text
registryId = Maybe Text
a} :: GetRegistryPolicyResponse)

-- | The JSON text of the permissions policy for a registry.
getRegistryPolicyResponse_policyText :: Lens.Lens' GetRegistryPolicyResponse (Prelude.Maybe Prelude.Text)
getRegistryPolicyResponse_policyText :: (Maybe Text -> f (Maybe Text))
-> GetRegistryPolicyResponse -> f GetRegistryPolicyResponse
getRegistryPolicyResponse_policyText = (GetRegistryPolicyResponse -> Maybe Text)
-> (GetRegistryPolicyResponse
    -> Maybe Text -> GetRegistryPolicyResponse)
-> Lens
     GetRegistryPolicyResponse
     GetRegistryPolicyResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetRegistryPolicyResponse' {Maybe Text
policyText :: Maybe Text
$sel:policyText:GetRegistryPolicyResponse' :: GetRegistryPolicyResponse -> Maybe Text
policyText} -> Maybe Text
policyText) (\s :: GetRegistryPolicyResponse
s@GetRegistryPolicyResponse' {} Maybe Text
a -> GetRegistryPolicyResponse
s {$sel:policyText:GetRegistryPolicyResponse' :: Maybe Text
policyText = Maybe Text
a} :: GetRegistryPolicyResponse)

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

instance Prelude.NFData GetRegistryPolicyResponse