{-# 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.PutReplicationConfiguration
-- 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 replication configuration for a registry. The
-- existing replication configuration for a repository can be retrieved
-- with the DescribeRegistry API action. The first time the
-- PutReplicationConfiguration API is called, a service-linked IAM role is
-- created in your account for the replication process. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonECR/latest/userguide/using-service-linked-roles.html Using service-linked roles for Amazon ECR>
-- in the /Amazon Elastic Container Registry User Guide/.
--
-- When configuring cross-account replication, the destination account must
-- grant the source account permission to replicate. This permission is
-- controlled using a registry permissions policy. For more information,
-- see PutRegistryPolicy.
module Amazonka.ECR.PutReplicationConfiguration
  ( -- * Creating a Request
    PutReplicationConfiguration (..),
    newPutReplicationConfiguration,

    -- * Request Lenses
    putReplicationConfiguration_replicationConfiguration,

    -- * Destructuring the Response
    PutReplicationConfigurationResponse (..),
    newPutReplicationConfigurationResponse,

    -- * Response Lenses
    putReplicationConfigurationResponse_replicationConfiguration,
    putReplicationConfigurationResponse_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:/ 'newPutReplicationConfiguration' smart constructor.
data PutReplicationConfiguration = PutReplicationConfiguration'
  { -- | An object representing the replication configuration for a registry.
    PutReplicationConfiguration -> ReplicationConfiguration
replicationConfiguration :: ReplicationConfiguration
  }
  deriving (PutReplicationConfiguration -> PutReplicationConfiguration -> Bool
(PutReplicationConfiguration
 -> PutReplicationConfiguration -> Bool)
-> (PutReplicationConfiguration
    -> PutReplicationConfiguration -> Bool)
-> Eq PutReplicationConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutReplicationConfiguration -> PutReplicationConfiguration -> Bool
$c/= :: PutReplicationConfiguration -> PutReplicationConfiguration -> Bool
== :: PutReplicationConfiguration -> PutReplicationConfiguration -> Bool
$c== :: PutReplicationConfiguration -> PutReplicationConfiguration -> Bool
Prelude.Eq, ReadPrec [PutReplicationConfiguration]
ReadPrec PutReplicationConfiguration
Int -> ReadS PutReplicationConfiguration
ReadS [PutReplicationConfiguration]
(Int -> ReadS PutReplicationConfiguration)
-> ReadS [PutReplicationConfiguration]
-> ReadPrec PutReplicationConfiguration
-> ReadPrec [PutReplicationConfiguration]
-> Read PutReplicationConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutReplicationConfiguration]
$creadListPrec :: ReadPrec [PutReplicationConfiguration]
readPrec :: ReadPrec PutReplicationConfiguration
$creadPrec :: ReadPrec PutReplicationConfiguration
readList :: ReadS [PutReplicationConfiguration]
$creadList :: ReadS [PutReplicationConfiguration]
readsPrec :: Int -> ReadS PutReplicationConfiguration
$creadsPrec :: Int -> ReadS PutReplicationConfiguration
Prelude.Read, Int -> PutReplicationConfiguration -> ShowS
[PutReplicationConfiguration] -> ShowS
PutReplicationConfiguration -> String
(Int -> PutReplicationConfiguration -> ShowS)
-> (PutReplicationConfiguration -> String)
-> ([PutReplicationConfiguration] -> ShowS)
-> Show PutReplicationConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutReplicationConfiguration] -> ShowS
$cshowList :: [PutReplicationConfiguration] -> ShowS
show :: PutReplicationConfiguration -> String
$cshow :: PutReplicationConfiguration -> String
showsPrec :: Int -> PutReplicationConfiguration -> ShowS
$cshowsPrec :: Int -> PutReplicationConfiguration -> ShowS
Prelude.Show, (forall x.
 PutReplicationConfiguration -> Rep PutReplicationConfiguration x)
-> (forall x.
    Rep PutReplicationConfiguration x -> PutReplicationConfiguration)
-> Generic PutReplicationConfiguration
forall x.
Rep PutReplicationConfiguration x -> PutReplicationConfiguration
forall x.
PutReplicationConfiguration -> Rep PutReplicationConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep PutReplicationConfiguration x -> PutReplicationConfiguration
$cfrom :: forall x.
PutReplicationConfiguration -> Rep PutReplicationConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'PutReplicationConfiguration' 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:
--
-- 'replicationConfiguration', 'putReplicationConfiguration_replicationConfiguration' - An object representing the replication configuration for a registry.
newPutReplicationConfiguration ::
  -- | 'replicationConfiguration'
  ReplicationConfiguration ->
  PutReplicationConfiguration
newPutReplicationConfiguration :: ReplicationConfiguration -> PutReplicationConfiguration
newPutReplicationConfiguration
  ReplicationConfiguration
pReplicationConfiguration_ =
    PutReplicationConfiguration' :: ReplicationConfiguration -> PutReplicationConfiguration
PutReplicationConfiguration'
      { $sel:replicationConfiguration:PutReplicationConfiguration' :: ReplicationConfiguration
replicationConfiguration =
          ReplicationConfiguration
pReplicationConfiguration_
      }

-- | An object representing the replication configuration for a registry.
putReplicationConfiguration_replicationConfiguration :: Lens.Lens' PutReplicationConfiguration ReplicationConfiguration
putReplicationConfiguration_replicationConfiguration :: (ReplicationConfiguration -> f ReplicationConfiguration)
-> PutReplicationConfiguration -> f PutReplicationConfiguration
putReplicationConfiguration_replicationConfiguration = (PutReplicationConfiguration -> ReplicationConfiguration)
-> (PutReplicationConfiguration
    -> ReplicationConfiguration -> PutReplicationConfiguration)
-> Lens
     PutReplicationConfiguration
     PutReplicationConfiguration
     ReplicationConfiguration
     ReplicationConfiguration
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutReplicationConfiguration' {ReplicationConfiguration
replicationConfiguration :: ReplicationConfiguration
$sel:replicationConfiguration:PutReplicationConfiguration' :: PutReplicationConfiguration -> ReplicationConfiguration
replicationConfiguration} -> ReplicationConfiguration
replicationConfiguration) (\s :: PutReplicationConfiguration
s@PutReplicationConfiguration' {} ReplicationConfiguration
a -> PutReplicationConfiguration
s {$sel:replicationConfiguration:PutReplicationConfiguration' :: ReplicationConfiguration
replicationConfiguration = ReplicationConfiguration
a} :: PutReplicationConfiguration)

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

instance Prelude.NFData PutReplicationConfiguration

instance Core.ToHeaders PutReplicationConfiguration where
  toHeaders :: PutReplicationConfiguration -> ResponseHeaders
toHeaders =
    ResponseHeaders -> PutReplicationConfiguration -> 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.PutReplicationConfiguration" ::
                          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 PutReplicationConfiguration where
  toJSON :: PutReplicationConfiguration -> Value
toJSON PutReplicationConfiguration' {ReplicationConfiguration
replicationConfiguration :: ReplicationConfiguration
$sel:replicationConfiguration:PutReplicationConfiguration' :: PutReplicationConfiguration -> ReplicationConfiguration
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Key
"replicationConfiguration"
                  Key -> ReplicationConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Core..= ReplicationConfiguration
replicationConfiguration
              )
          ]
      )

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

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

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

-- |
-- Create a value of 'PutReplicationConfigurationResponse' 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:
--
-- 'replicationConfiguration', 'putReplicationConfigurationResponse_replicationConfiguration' - The contents of the replication configuration for the registry.
--
-- 'httpStatus', 'putReplicationConfigurationResponse_httpStatus' - The response's http status code.
newPutReplicationConfigurationResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutReplicationConfigurationResponse
newPutReplicationConfigurationResponse :: Int -> PutReplicationConfigurationResponse
newPutReplicationConfigurationResponse Int
pHttpStatus_ =
  PutReplicationConfigurationResponse' :: Maybe ReplicationConfiguration
-> Int -> PutReplicationConfigurationResponse
PutReplicationConfigurationResponse'
    { $sel:replicationConfiguration:PutReplicationConfigurationResponse' :: Maybe ReplicationConfiguration
replicationConfiguration =
        Maybe ReplicationConfiguration
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:PutReplicationConfigurationResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The contents of the replication configuration for the registry.
putReplicationConfigurationResponse_replicationConfiguration :: Lens.Lens' PutReplicationConfigurationResponse (Prelude.Maybe ReplicationConfiguration)
putReplicationConfigurationResponse_replicationConfiguration :: (Maybe ReplicationConfiguration
 -> f (Maybe ReplicationConfiguration))
-> PutReplicationConfigurationResponse
-> f PutReplicationConfigurationResponse
putReplicationConfigurationResponse_replicationConfiguration = (PutReplicationConfigurationResponse
 -> Maybe ReplicationConfiguration)
-> (PutReplicationConfigurationResponse
    -> Maybe ReplicationConfiguration
    -> PutReplicationConfigurationResponse)
-> Lens
     PutReplicationConfigurationResponse
     PutReplicationConfigurationResponse
     (Maybe ReplicationConfiguration)
     (Maybe ReplicationConfiguration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutReplicationConfigurationResponse' {Maybe ReplicationConfiguration
replicationConfiguration :: Maybe ReplicationConfiguration
$sel:replicationConfiguration:PutReplicationConfigurationResponse' :: PutReplicationConfigurationResponse
-> Maybe ReplicationConfiguration
replicationConfiguration} -> Maybe ReplicationConfiguration
replicationConfiguration) (\s :: PutReplicationConfigurationResponse
s@PutReplicationConfigurationResponse' {} Maybe ReplicationConfiguration
a -> PutReplicationConfigurationResponse
s {$sel:replicationConfiguration:PutReplicationConfigurationResponse' :: Maybe ReplicationConfiguration
replicationConfiguration = Maybe ReplicationConfiguration
a} :: PutReplicationConfigurationResponse)

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

instance
  Prelude.NFData
    PutReplicationConfigurationResponse