{-# 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.PutRegistryPolicy
-- 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 or updates the permissions policy for your registry.
--
-- A registry policy is used to specify permissions for another Amazon Web
-- Services account and is used when configuring cross-account replication.
-- For more information, see
-- <https://docs.aws.amazon.com/AmazonECR/latest/userguide/registry-permissions.html Registry permissions>
-- in the /Amazon Elastic Container Registry User Guide/.
module Amazonka.ECR.PutRegistryPolicy
  ( -- * Creating a Request
    PutRegistryPolicy (..),
    newPutRegistryPolicy,

    -- * Request Lenses
    putRegistryPolicy_policyText,

    -- * Destructuring the Response
    PutRegistryPolicyResponse (..),
    newPutRegistryPolicyResponse,

    -- * Response Lenses
    putRegistryPolicyResponse_registryId,
    putRegistryPolicyResponse_policyText,
    putRegistryPolicyResponse_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:/ 'newPutRegistryPolicy' smart constructor.
data PutRegistryPolicy = PutRegistryPolicy'
  { -- | The JSON policy text to apply to your registry. The policy text follows
    -- the same format as IAM policy text. For more information, see
    -- <https://docs.aws.amazon.com/AmazonECR/latest/userguide/registry-permissions.html Registry permissions>
    -- in the /Amazon Elastic Container Registry User Guide/.
    PutRegistryPolicy -> Text
policyText :: Prelude.Text
  }
  deriving (PutRegistryPolicy -> PutRegistryPolicy -> Bool
(PutRegistryPolicy -> PutRegistryPolicy -> Bool)
-> (PutRegistryPolicy -> PutRegistryPolicy -> Bool)
-> Eq PutRegistryPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutRegistryPolicy -> PutRegistryPolicy -> Bool
$c/= :: PutRegistryPolicy -> PutRegistryPolicy -> Bool
== :: PutRegistryPolicy -> PutRegistryPolicy -> Bool
$c== :: PutRegistryPolicy -> PutRegistryPolicy -> Bool
Prelude.Eq, ReadPrec [PutRegistryPolicy]
ReadPrec PutRegistryPolicy
Int -> ReadS PutRegistryPolicy
ReadS [PutRegistryPolicy]
(Int -> ReadS PutRegistryPolicy)
-> ReadS [PutRegistryPolicy]
-> ReadPrec PutRegistryPolicy
-> ReadPrec [PutRegistryPolicy]
-> Read PutRegistryPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutRegistryPolicy]
$creadListPrec :: ReadPrec [PutRegistryPolicy]
readPrec :: ReadPrec PutRegistryPolicy
$creadPrec :: ReadPrec PutRegistryPolicy
readList :: ReadS [PutRegistryPolicy]
$creadList :: ReadS [PutRegistryPolicy]
readsPrec :: Int -> ReadS PutRegistryPolicy
$creadsPrec :: Int -> ReadS PutRegistryPolicy
Prelude.Read, Int -> PutRegistryPolicy -> ShowS
[PutRegistryPolicy] -> ShowS
PutRegistryPolicy -> String
(Int -> PutRegistryPolicy -> ShowS)
-> (PutRegistryPolicy -> String)
-> ([PutRegistryPolicy] -> ShowS)
-> Show PutRegistryPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutRegistryPolicy] -> ShowS
$cshowList :: [PutRegistryPolicy] -> ShowS
show :: PutRegistryPolicy -> String
$cshow :: PutRegistryPolicy -> String
showsPrec :: Int -> PutRegistryPolicy -> ShowS
$cshowsPrec :: Int -> PutRegistryPolicy -> ShowS
Prelude.Show, (forall x. PutRegistryPolicy -> Rep PutRegistryPolicy x)
-> (forall x. Rep PutRegistryPolicy x -> PutRegistryPolicy)
-> Generic PutRegistryPolicy
forall x. Rep PutRegistryPolicy x -> PutRegistryPolicy
forall x. PutRegistryPolicy -> Rep PutRegistryPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutRegistryPolicy x -> PutRegistryPolicy
$cfrom :: forall x. PutRegistryPolicy -> Rep PutRegistryPolicy x
Prelude.Generic)

-- |
-- Create a value of 'PutRegistryPolicy' 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:
--
-- 'policyText', 'putRegistryPolicy_policyText' - The JSON policy text to apply to your registry. The policy text follows
-- the same format as IAM policy text. For more information, see
-- <https://docs.aws.amazon.com/AmazonECR/latest/userguide/registry-permissions.html Registry permissions>
-- in the /Amazon Elastic Container Registry User Guide/.
newPutRegistryPolicy ::
  -- | 'policyText'
  Prelude.Text ->
  PutRegistryPolicy
newPutRegistryPolicy :: Text -> PutRegistryPolicy
newPutRegistryPolicy Text
pPolicyText_ =
  PutRegistryPolicy' :: Text -> PutRegistryPolicy
PutRegistryPolicy' {$sel:policyText:PutRegistryPolicy' :: Text
policyText = Text
pPolicyText_}

-- | The JSON policy text to apply to your registry. The policy text follows
-- the same format as IAM policy text. For more information, see
-- <https://docs.aws.amazon.com/AmazonECR/latest/userguide/registry-permissions.html Registry permissions>
-- in the /Amazon Elastic Container Registry User Guide/.
putRegistryPolicy_policyText :: Lens.Lens' PutRegistryPolicy Prelude.Text
putRegistryPolicy_policyText :: (Text -> f Text) -> PutRegistryPolicy -> f PutRegistryPolicy
putRegistryPolicy_policyText = (PutRegistryPolicy -> Text)
-> (PutRegistryPolicy -> Text -> PutRegistryPolicy)
-> Lens PutRegistryPolicy PutRegistryPolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRegistryPolicy' {Text
policyText :: Text
$sel:policyText:PutRegistryPolicy' :: PutRegistryPolicy -> Text
policyText} -> Text
policyText) (\s :: PutRegistryPolicy
s@PutRegistryPolicy' {} Text
a -> PutRegistryPolicy
s {$sel:policyText:PutRegistryPolicy' :: Text
policyText = Text
a} :: PutRegistryPolicy)

instance Core.AWSRequest PutRegistryPolicy where
  type
    AWSResponse PutRegistryPolicy =
      PutRegistryPolicyResponse
  request :: PutRegistryPolicy -> Request PutRegistryPolicy
request = Service -> PutRegistryPolicy -> Request PutRegistryPolicy
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutRegistryPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutRegistryPolicy)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse PutRegistryPolicy))
-> Logger
-> Service
-> Proxy PutRegistryPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutRegistryPolicy)))
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 -> PutRegistryPolicyResponse
PutRegistryPolicyResponse'
            (Maybe Text -> Maybe Text -> Int -> PutRegistryPolicyResponse)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Int -> PutRegistryPolicyResponse)
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 -> PutRegistryPolicyResponse)
-> Either String (Maybe Text)
-> Either String (Int -> PutRegistryPolicyResponse)
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 -> PutRegistryPolicyResponse)
-> Either String Int -> Either String PutRegistryPolicyResponse
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 PutRegistryPolicy

instance Prelude.NFData PutRegistryPolicy

instance Core.ToHeaders PutRegistryPolicy where
  toHeaders :: PutRegistryPolicy -> ResponseHeaders
toHeaders =
    ResponseHeaders -> PutRegistryPolicy -> 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.PutRegistryPolicy" ::
                          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 PutRegistryPolicy where
  toJSON :: PutRegistryPolicy -> Value
toJSON PutRegistryPolicy' {Text
policyText :: Text
$sel:policyText:PutRegistryPolicy' :: PutRegistryPolicy -> 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
"policyText" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
policyText)]
      )

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

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

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

-- |
-- Create a value of 'PutRegistryPolicyResponse' 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', 'putRegistryPolicyResponse_registryId' - The registry ID.
--
-- 'policyText', 'putRegistryPolicyResponse_policyText' - The JSON policy text for your registry.
--
-- 'httpStatus', 'putRegistryPolicyResponse_httpStatus' - The response's http status code.
newPutRegistryPolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutRegistryPolicyResponse
newPutRegistryPolicyResponse :: Int -> PutRegistryPolicyResponse
newPutRegistryPolicyResponse Int
pHttpStatus_ =
  PutRegistryPolicyResponse' :: Maybe Text -> Maybe Text -> Int -> PutRegistryPolicyResponse
PutRegistryPolicyResponse'
    { $sel:registryId:PutRegistryPolicyResponse' :: Maybe Text
registryId =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:policyText:PutRegistryPolicyResponse' :: Maybe Text
policyText = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:PutRegistryPolicyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

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

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

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

instance Prelude.NFData PutRegistryPolicyResponse