{-# 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.Lightsail.RegisterContainerImage
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Registers a container image to your Amazon Lightsail container service.
--
-- This action is not required if you install and use the Lightsail Control
-- (lightsailctl) plugin to push container images to your Lightsail
-- container service. For more information, see
-- <https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-pushing-container-images Pushing and managing container images on your Amazon Lightsail container services>
-- in the /Amazon Lightsail Developer Guide/.
module Amazonka.Lightsail.RegisterContainerImage
  ( -- * Creating a Request
    RegisterContainerImage (..),
    newRegisterContainerImage,

    -- * Request Lenses
    registerContainerImage_serviceName,
    registerContainerImage_label,
    registerContainerImage_digest,

    -- * Destructuring the Response
    RegisterContainerImageResponse (..),
    newRegisterContainerImageResponse,

    -- * Response Lenses
    registerContainerImageResponse_containerImage,
    registerContainerImageResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Lightsail.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newRegisterContainerImage' smart constructor.
data RegisterContainerImage = RegisterContainerImage'
  { -- | The name of the container service for which to register a container
    -- image.
    RegisterContainerImage -> Text
serviceName :: Prelude.Text,
    -- | The label for the container image when it\'s registered to the container
    -- service.
    --
    -- Use a descriptive label that you can use to track the different versions
    -- of your registered container images.
    --
    -- Use the @GetContainerImages@ action to return the container images
    -- registered to a Lightsail container service. The label is the
    -- @\<imagelabel>@ portion of the following image name example:
    --
    -- -   @:container-service-1.\<imagelabel>.1@
    --
    -- If the name of your container service is @mycontainerservice@, and the
    -- label that you specify is @mystaticwebsite@, then the name of the
    -- registered container image will be
    -- @:mycontainerservice.mystaticwebsite.1@.
    --
    -- The number at the end of these image name examples represents the
    -- version of the registered container image. If you push and register
    -- another container image to the same Lightsail container service, with
    -- the same label, then the version number for the new registered container
    -- image will be @2@. If you push and register another container image, the
    -- version number will be @3@, and so on.
    RegisterContainerImage -> Text
label :: Prelude.Text,
    -- | The digest of the container image to be registered.
    RegisterContainerImage -> Text
digest :: Prelude.Text
  }
  deriving (RegisterContainerImage -> RegisterContainerImage -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegisterContainerImage -> RegisterContainerImage -> Bool
$c/= :: RegisterContainerImage -> RegisterContainerImage -> Bool
== :: RegisterContainerImage -> RegisterContainerImage -> Bool
$c== :: RegisterContainerImage -> RegisterContainerImage -> Bool
Prelude.Eq, ReadPrec [RegisterContainerImage]
ReadPrec RegisterContainerImage
Int -> ReadS RegisterContainerImage
ReadS [RegisterContainerImage]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegisterContainerImage]
$creadListPrec :: ReadPrec [RegisterContainerImage]
readPrec :: ReadPrec RegisterContainerImage
$creadPrec :: ReadPrec RegisterContainerImage
readList :: ReadS [RegisterContainerImage]
$creadList :: ReadS [RegisterContainerImage]
readsPrec :: Int -> ReadS RegisterContainerImage
$creadsPrec :: Int -> ReadS RegisterContainerImage
Prelude.Read, Int -> RegisterContainerImage -> ShowS
[RegisterContainerImage] -> ShowS
RegisterContainerImage -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegisterContainerImage] -> ShowS
$cshowList :: [RegisterContainerImage] -> ShowS
show :: RegisterContainerImage -> String
$cshow :: RegisterContainerImage -> String
showsPrec :: Int -> RegisterContainerImage -> ShowS
$cshowsPrec :: Int -> RegisterContainerImage -> ShowS
Prelude.Show, forall x. Rep RegisterContainerImage x -> RegisterContainerImage
forall x. RegisterContainerImage -> Rep RegisterContainerImage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RegisterContainerImage x -> RegisterContainerImage
$cfrom :: forall x. RegisterContainerImage -> Rep RegisterContainerImage x
Prelude.Generic)

-- |
-- Create a value of 'RegisterContainerImage' 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:
--
-- 'serviceName', 'registerContainerImage_serviceName' - The name of the container service for which to register a container
-- image.
--
-- 'label', 'registerContainerImage_label' - The label for the container image when it\'s registered to the container
-- service.
--
-- Use a descriptive label that you can use to track the different versions
-- of your registered container images.
--
-- Use the @GetContainerImages@ action to return the container images
-- registered to a Lightsail container service. The label is the
-- @\<imagelabel>@ portion of the following image name example:
--
-- -   @:container-service-1.\<imagelabel>.1@
--
-- If the name of your container service is @mycontainerservice@, and the
-- label that you specify is @mystaticwebsite@, then the name of the
-- registered container image will be
-- @:mycontainerservice.mystaticwebsite.1@.
--
-- The number at the end of these image name examples represents the
-- version of the registered container image. If you push and register
-- another container image to the same Lightsail container service, with
-- the same label, then the version number for the new registered container
-- image will be @2@. If you push and register another container image, the
-- version number will be @3@, and so on.
--
-- 'digest', 'registerContainerImage_digest' - The digest of the container image to be registered.
newRegisterContainerImage ::
  -- | 'serviceName'
  Prelude.Text ->
  -- | 'label'
  Prelude.Text ->
  -- | 'digest'
  Prelude.Text ->
  RegisterContainerImage
newRegisterContainerImage :: Text -> Text -> Text -> RegisterContainerImage
newRegisterContainerImage
  Text
pServiceName_
  Text
pLabel_
  Text
pDigest_ =
    RegisterContainerImage'
      { $sel:serviceName:RegisterContainerImage' :: Text
serviceName =
          Text
pServiceName_,
        $sel:label:RegisterContainerImage' :: Text
label = Text
pLabel_,
        $sel:digest:RegisterContainerImage' :: Text
digest = Text
pDigest_
      }

-- | The name of the container service for which to register a container
-- image.
registerContainerImage_serviceName :: Lens.Lens' RegisterContainerImage Prelude.Text
registerContainerImage_serviceName :: Lens' RegisterContainerImage Text
registerContainerImage_serviceName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterContainerImage' {Text
serviceName :: Text
$sel:serviceName:RegisterContainerImage' :: RegisterContainerImage -> Text
serviceName} -> Text
serviceName) (\s :: RegisterContainerImage
s@RegisterContainerImage' {} Text
a -> RegisterContainerImage
s {$sel:serviceName:RegisterContainerImage' :: Text
serviceName = Text
a} :: RegisterContainerImage)

-- | The label for the container image when it\'s registered to the container
-- service.
--
-- Use a descriptive label that you can use to track the different versions
-- of your registered container images.
--
-- Use the @GetContainerImages@ action to return the container images
-- registered to a Lightsail container service. The label is the
-- @\<imagelabel>@ portion of the following image name example:
--
-- -   @:container-service-1.\<imagelabel>.1@
--
-- If the name of your container service is @mycontainerservice@, and the
-- label that you specify is @mystaticwebsite@, then the name of the
-- registered container image will be
-- @:mycontainerservice.mystaticwebsite.1@.
--
-- The number at the end of these image name examples represents the
-- version of the registered container image. If you push and register
-- another container image to the same Lightsail container service, with
-- the same label, then the version number for the new registered container
-- image will be @2@. If you push and register another container image, the
-- version number will be @3@, and so on.
registerContainerImage_label :: Lens.Lens' RegisterContainerImage Prelude.Text
registerContainerImage_label :: Lens' RegisterContainerImage Text
registerContainerImage_label = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterContainerImage' {Text
label :: Text
$sel:label:RegisterContainerImage' :: RegisterContainerImage -> Text
label} -> Text
label) (\s :: RegisterContainerImage
s@RegisterContainerImage' {} Text
a -> RegisterContainerImage
s {$sel:label:RegisterContainerImage' :: Text
label = Text
a} :: RegisterContainerImage)

-- | The digest of the container image to be registered.
registerContainerImage_digest :: Lens.Lens' RegisterContainerImage Prelude.Text
registerContainerImage_digest :: Lens' RegisterContainerImage Text
registerContainerImage_digest = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterContainerImage' {Text
digest :: Text
$sel:digest:RegisterContainerImage' :: RegisterContainerImage -> Text
digest} -> Text
digest) (\s :: RegisterContainerImage
s@RegisterContainerImage' {} Text
a -> RegisterContainerImage
s {$sel:digest:RegisterContainerImage' :: Text
digest = Text
a} :: RegisterContainerImage)

instance Core.AWSRequest RegisterContainerImage where
  type
    AWSResponse RegisterContainerImage =
      RegisterContainerImageResponse
  request :: (Service -> Service)
-> RegisterContainerImage -> Request RegisterContainerImage
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy RegisterContainerImage
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse RegisterContainerImage)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe ContainerImage -> Int -> RegisterContainerImageResponse
RegisterContainerImageResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"containerImage")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable RegisterContainerImage where
  hashWithSalt :: Int -> RegisterContainerImage -> Int
hashWithSalt Int
_salt RegisterContainerImage' {Text
digest :: Text
label :: Text
serviceName :: Text
$sel:digest:RegisterContainerImage' :: RegisterContainerImage -> Text
$sel:label:RegisterContainerImage' :: RegisterContainerImage -> Text
$sel:serviceName:RegisterContainerImage' :: RegisterContainerImage -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
serviceName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
label
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
digest

instance Prelude.NFData RegisterContainerImage where
  rnf :: RegisterContainerImage -> ()
rnf RegisterContainerImage' {Text
digest :: Text
label :: Text
serviceName :: Text
$sel:digest:RegisterContainerImage' :: RegisterContainerImage -> Text
$sel:label:RegisterContainerImage' :: RegisterContainerImage -> Text
$sel:serviceName:RegisterContainerImage' :: RegisterContainerImage -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
serviceName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
label
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
digest

instance Data.ToHeaders RegisterContainerImage where
  toHeaders :: RegisterContainerImage -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"Lightsail_20161128.RegisterContainerImage" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON RegisterContainerImage where
  toJSON :: RegisterContainerImage -> Value
toJSON RegisterContainerImage' {Text
digest :: Text
label :: Text
serviceName :: Text
$sel:digest:RegisterContainerImage' :: RegisterContainerImage -> Text
$sel:label:RegisterContainerImage' :: RegisterContainerImage -> Text
$sel:serviceName:RegisterContainerImage' :: RegisterContainerImage -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"serviceName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
serviceName),
            forall a. a -> Maybe a
Prelude.Just (Key
"label" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
label),
            forall a. a -> Maybe a
Prelude.Just (Key
"digest" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
digest)
          ]
      )

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

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

-- | /See:/ 'newRegisterContainerImageResponse' smart constructor.
data RegisterContainerImageResponse = RegisterContainerImageResponse'
  { -- | An object that describes a container image that is registered to a
    -- Lightsail container service
    RegisterContainerImageResponse -> Maybe ContainerImage
containerImage :: Prelude.Maybe ContainerImage,
    -- | The response's http status code.
    RegisterContainerImageResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (RegisterContainerImageResponse
-> RegisterContainerImageResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegisterContainerImageResponse
-> RegisterContainerImageResponse -> Bool
$c/= :: RegisterContainerImageResponse
-> RegisterContainerImageResponse -> Bool
== :: RegisterContainerImageResponse
-> RegisterContainerImageResponse -> Bool
$c== :: RegisterContainerImageResponse
-> RegisterContainerImageResponse -> Bool
Prelude.Eq, ReadPrec [RegisterContainerImageResponse]
ReadPrec RegisterContainerImageResponse
Int -> ReadS RegisterContainerImageResponse
ReadS [RegisterContainerImageResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegisterContainerImageResponse]
$creadListPrec :: ReadPrec [RegisterContainerImageResponse]
readPrec :: ReadPrec RegisterContainerImageResponse
$creadPrec :: ReadPrec RegisterContainerImageResponse
readList :: ReadS [RegisterContainerImageResponse]
$creadList :: ReadS [RegisterContainerImageResponse]
readsPrec :: Int -> ReadS RegisterContainerImageResponse
$creadsPrec :: Int -> ReadS RegisterContainerImageResponse
Prelude.Read, Int -> RegisterContainerImageResponse -> ShowS
[RegisterContainerImageResponse] -> ShowS
RegisterContainerImageResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegisterContainerImageResponse] -> ShowS
$cshowList :: [RegisterContainerImageResponse] -> ShowS
show :: RegisterContainerImageResponse -> String
$cshow :: RegisterContainerImageResponse -> String
showsPrec :: Int -> RegisterContainerImageResponse -> ShowS
$cshowsPrec :: Int -> RegisterContainerImageResponse -> ShowS
Prelude.Show, forall x.
Rep RegisterContainerImageResponse x
-> RegisterContainerImageResponse
forall x.
RegisterContainerImageResponse
-> Rep RegisterContainerImageResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep RegisterContainerImageResponse x
-> RegisterContainerImageResponse
$cfrom :: forall x.
RegisterContainerImageResponse
-> Rep RegisterContainerImageResponse x
Prelude.Generic)

-- |
-- Create a value of 'RegisterContainerImageResponse' 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:
--
-- 'containerImage', 'registerContainerImageResponse_containerImage' - An object that describes a container image that is registered to a
-- Lightsail container service
--
-- 'httpStatus', 'registerContainerImageResponse_httpStatus' - The response's http status code.
newRegisterContainerImageResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  RegisterContainerImageResponse
newRegisterContainerImageResponse :: Int -> RegisterContainerImageResponse
newRegisterContainerImageResponse Int
pHttpStatus_ =
  RegisterContainerImageResponse'
    { $sel:containerImage:RegisterContainerImageResponse' :: Maybe ContainerImage
containerImage =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:RegisterContainerImageResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An object that describes a container image that is registered to a
-- Lightsail container service
registerContainerImageResponse_containerImage :: Lens.Lens' RegisterContainerImageResponse (Prelude.Maybe ContainerImage)
registerContainerImageResponse_containerImage :: Lens' RegisterContainerImageResponse (Maybe ContainerImage)
registerContainerImageResponse_containerImage = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterContainerImageResponse' {Maybe ContainerImage
containerImage :: Maybe ContainerImage
$sel:containerImage:RegisterContainerImageResponse' :: RegisterContainerImageResponse -> Maybe ContainerImage
containerImage} -> Maybe ContainerImage
containerImage) (\s :: RegisterContainerImageResponse
s@RegisterContainerImageResponse' {} Maybe ContainerImage
a -> RegisterContainerImageResponse
s {$sel:containerImage:RegisterContainerImageResponse' :: Maybe ContainerImage
containerImage = Maybe ContainerImage
a} :: RegisterContainerImageResponse)

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

instance
  Prelude.NFData
    RegisterContainerImageResponse
  where
  rnf :: RegisterContainerImageResponse -> ()
rnf RegisterContainerImageResponse' {Int
Maybe ContainerImage
httpStatus :: Int
containerImage :: Maybe ContainerImage
$sel:httpStatus:RegisterContainerImageResponse' :: RegisterContainerImageResponse -> Int
$sel:containerImage:RegisterContainerImageResponse' :: RegisterContainerImageResponse -> Maybe ContainerImage
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ContainerImage
containerImage
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus