{-# 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.SageMaker.CreateImageVersion
-- 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 a version of the SageMaker image specified by @ImageName@. The
-- version represents the Amazon Container Registry (ECR) container image
-- specified by @BaseImage@.
module Amazonka.SageMaker.CreateImageVersion
  ( -- * Creating a Request
    CreateImageVersion (..),
    newCreateImageVersion,

    -- * Request Lenses
    createImageVersion_baseImage,
    createImageVersion_clientToken,
    createImageVersion_imageName,

    -- * Destructuring the Response
    CreateImageVersionResponse (..),
    newCreateImageVersionResponse,

    -- * Response Lenses
    createImageVersionResponse_imageVersionArn,
    createImageVersionResponse_httpStatus,
  )
where

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
import Amazonka.SageMaker.Types

-- | /See:/ 'newCreateImageVersion' smart constructor.
data CreateImageVersion = CreateImageVersion'
  { -- | The registry path of the container image to use as the starting point
    -- for this version. The path is an Amazon Container Registry (ECR) URI in
    -- the following format:
    --
    -- @\<acct-id>.dkr.ecr.\<region>.amazonaws.com\/\<repo-name[:tag] or [\@digest]>@
    CreateImageVersion -> Text
baseImage :: Prelude.Text,
    -- | A unique ID. If not specified, the Amazon Web Services CLI and Amazon
    -- Web Services SDKs, such as the SDK for Python (Boto3), add a unique
    -- value to the call.
    CreateImageVersion -> Text
clientToken :: Prelude.Text,
    -- | The @ImageName@ of the @Image@ to create a version of.
    CreateImageVersion -> Text
imageName :: Prelude.Text
  }
  deriving (CreateImageVersion -> CreateImageVersion -> Bool
(CreateImageVersion -> CreateImageVersion -> Bool)
-> (CreateImageVersion -> CreateImageVersion -> Bool)
-> Eq CreateImageVersion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateImageVersion -> CreateImageVersion -> Bool
$c/= :: CreateImageVersion -> CreateImageVersion -> Bool
== :: CreateImageVersion -> CreateImageVersion -> Bool
$c== :: CreateImageVersion -> CreateImageVersion -> Bool
Prelude.Eq, ReadPrec [CreateImageVersion]
ReadPrec CreateImageVersion
Int -> ReadS CreateImageVersion
ReadS [CreateImageVersion]
(Int -> ReadS CreateImageVersion)
-> ReadS [CreateImageVersion]
-> ReadPrec CreateImageVersion
-> ReadPrec [CreateImageVersion]
-> Read CreateImageVersion
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateImageVersion]
$creadListPrec :: ReadPrec [CreateImageVersion]
readPrec :: ReadPrec CreateImageVersion
$creadPrec :: ReadPrec CreateImageVersion
readList :: ReadS [CreateImageVersion]
$creadList :: ReadS [CreateImageVersion]
readsPrec :: Int -> ReadS CreateImageVersion
$creadsPrec :: Int -> ReadS CreateImageVersion
Prelude.Read, Int -> CreateImageVersion -> ShowS
[CreateImageVersion] -> ShowS
CreateImageVersion -> String
(Int -> CreateImageVersion -> ShowS)
-> (CreateImageVersion -> String)
-> ([CreateImageVersion] -> ShowS)
-> Show CreateImageVersion
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateImageVersion] -> ShowS
$cshowList :: [CreateImageVersion] -> ShowS
show :: CreateImageVersion -> String
$cshow :: CreateImageVersion -> String
showsPrec :: Int -> CreateImageVersion -> ShowS
$cshowsPrec :: Int -> CreateImageVersion -> ShowS
Prelude.Show, (forall x. CreateImageVersion -> Rep CreateImageVersion x)
-> (forall x. Rep CreateImageVersion x -> CreateImageVersion)
-> Generic CreateImageVersion
forall x. Rep CreateImageVersion x -> CreateImageVersion
forall x. CreateImageVersion -> Rep CreateImageVersion x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateImageVersion x -> CreateImageVersion
$cfrom :: forall x. CreateImageVersion -> Rep CreateImageVersion x
Prelude.Generic)

-- |
-- Create a value of 'CreateImageVersion' 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:
--
-- 'baseImage', 'createImageVersion_baseImage' - The registry path of the container image to use as the starting point
-- for this version. The path is an Amazon Container Registry (ECR) URI in
-- the following format:
--
-- @\<acct-id>.dkr.ecr.\<region>.amazonaws.com\/\<repo-name[:tag] or [\@digest]>@
--
-- 'clientToken', 'createImageVersion_clientToken' - A unique ID. If not specified, the Amazon Web Services CLI and Amazon
-- Web Services SDKs, such as the SDK for Python (Boto3), add a unique
-- value to the call.
--
-- 'imageName', 'createImageVersion_imageName' - The @ImageName@ of the @Image@ to create a version of.
newCreateImageVersion ::
  -- | 'baseImage'
  Prelude.Text ->
  -- | 'clientToken'
  Prelude.Text ->
  -- | 'imageName'
  Prelude.Text ->
  CreateImageVersion
newCreateImageVersion :: Text -> Text -> Text -> CreateImageVersion
newCreateImageVersion
  Text
pBaseImage_
  Text
pClientToken_
  Text
pImageName_ =
    CreateImageVersion' :: Text -> Text -> Text -> CreateImageVersion
CreateImageVersion'
      { $sel:baseImage:CreateImageVersion' :: Text
baseImage = Text
pBaseImage_,
        $sel:clientToken:CreateImageVersion' :: Text
clientToken = Text
pClientToken_,
        $sel:imageName:CreateImageVersion' :: Text
imageName = Text
pImageName_
      }

-- | The registry path of the container image to use as the starting point
-- for this version. The path is an Amazon Container Registry (ECR) URI in
-- the following format:
--
-- @\<acct-id>.dkr.ecr.\<region>.amazonaws.com\/\<repo-name[:tag] or [\@digest]>@
createImageVersion_baseImage :: Lens.Lens' CreateImageVersion Prelude.Text
createImageVersion_baseImage :: (Text -> f Text) -> CreateImageVersion -> f CreateImageVersion
createImageVersion_baseImage = (CreateImageVersion -> Text)
-> (CreateImageVersion -> Text -> CreateImageVersion)
-> Lens CreateImageVersion CreateImageVersion Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateImageVersion' {Text
baseImage :: Text
$sel:baseImage:CreateImageVersion' :: CreateImageVersion -> Text
baseImage} -> Text
baseImage) (\s :: CreateImageVersion
s@CreateImageVersion' {} Text
a -> CreateImageVersion
s {$sel:baseImage:CreateImageVersion' :: Text
baseImage = Text
a} :: CreateImageVersion)

-- | A unique ID. If not specified, the Amazon Web Services CLI and Amazon
-- Web Services SDKs, such as the SDK for Python (Boto3), add a unique
-- value to the call.
createImageVersion_clientToken :: Lens.Lens' CreateImageVersion Prelude.Text
createImageVersion_clientToken :: (Text -> f Text) -> CreateImageVersion -> f CreateImageVersion
createImageVersion_clientToken = (CreateImageVersion -> Text)
-> (CreateImageVersion -> Text -> CreateImageVersion)
-> Lens CreateImageVersion CreateImageVersion Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateImageVersion' {Text
clientToken :: Text
$sel:clientToken:CreateImageVersion' :: CreateImageVersion -> Text
clientToken} -> Text
clientToken) (\s :: CreateImageVersion
s@CreateImageVersion' {} Text
a -> CreateImageVersion
s {$sel:clientToken:CreateImageVersion' :: Text
clientToken = Text
a} :: CreateImageVersion)

-- | The @ImageName@ of the @Image@ to create a version of.
createImageVersion_imageName :: Lens.Lens' CreateImageVersion Prelude.Text
createImageVersion_imageName :: (Text -> f Text) -> CreateImageVersion -> f CreateImageVersion
createImageVersion_imageName = (CreateImageVersion -> Text)
-> (CreateImageVersion -> Text -> CreateImageVersion)
-> Lens CreateImageVersion CreateImageVersion Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateImageVersion' {Text
imageName :: Text
$sel:imageName:CreateImageVersion' :: CreateImageVersion -> Text
imageName} -> Text
imageName) (\s :: CreateImageVersion
s@CreateImageVersion' {} Text
a -> CreateImageVersion
s {$sel:imageName:CreateImageVersion' :: Text
imageName = Text
a} :: CreateImageVersion)

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

instance Prelude.NFData CreateImageVersion

instance Core.ToHeaders CreateImageVersion where
  toHeaders :: CreateImageVersion -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateImageVersion -> 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
"SageMaker.CreateImageVersion" ::
                          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 CreateImageVersion where
  toJSON :: CreateImageVersion -> Value
toJSON CreateImageVersion' {Text
imageName :: Text
clientToken :: Text
baseImage :: Text
$sel:imageName:CreateImageVersion' :: CreateImageVersion -> Text
$sel:clientToken:CreateImageVersion' :: CreateImageVersion -> Text
$sel:baseImage:CreateImageVersion' :: CreateImageVersion -> 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
"BaseImage" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
baseImage),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ClientToken" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
clientToken),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ImageName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
imageName)
          ]
      )

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

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

-- | /See:/ 'newCreateImageVersionResponse' smart constructor.
data CreateImageVersionResponse = CreateImageVersionResponse'
  { -- | The Amazon Resource Name (ARN) of the image version.
    CreateImageVersionResponse -> Maybe Text
imageVersionArn :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    CreateImageVersionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateImageVersionResponse -> CreateImageVersionResponse -> Bool
(CreateImageVersionResponse -> CreateImageVersionResponse -> Bool)
-> (CreateImageVersionResponse
    -> CreateImageVersionResponse -> Bool)
-> Eq CreateImageVersionResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateImageVersionResponse -> CreateImageVersionResponse -> Bool
$c/= :: CreateImageVersionResponse -> CreateImageVersionResponse -> Bool
== :: CreateImageVersionResponse -> CreateImageVersionResponse -> Bool
$c== :: CreateImageVersionResponse -> CreateImageVersionResponse -> Bool
Prelude.Eq, ReadPrec [CreateImageVersionResponse]
ReadPrec CreateImageVersionResponse
Int -> ReadS CreateImageVersionResponse
ReadS [CreateImageVersionResponse]
(Int -> ReadS CreateImageVersionResponse)
-> ReadS [CreateImageVersionResponse]
-> ReadPrec CreateImageVersionResponse
-> ReadPrec [CreateImageVersionResponse]
-> Read CreateImageVersionResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateImageVersionResponse]
$creadListPrec :: ReadPrec [CreateImageVersionResponse]
readPrec :: ReadPrec CreateImageVersionResponse
$creadPrec :: ReadPrec CreateImageVersionResponse
readList :: ReadS [CreateImageVersionResponse]
$creadList :: ReadS [CreateImageVersionResponse]
readsPrec :: Int -> ReadS CreateImageVersionResponse
$creadsPrec :: Int -> ReadS CreateImageVersionResponse
Prelude.Read, Int -> CreateImageVersionResponse -> ShowS
[CreateImageVersionResponse] -> ShowS
CreateImageVersionResponse -> String
(Int -> CreateImageVersionResponse -> ShowS)
-> (CreateImageVersionResponse -> String)
-> ([CreateImageVersionResponse] -> ShowS)
-> Show CreateImageVersionResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateImageVersionResponse] -> ShowS
$cshowList :: [CreateImageVersionResponse] -> ShowS
show :: CreateImageVersionResponse -> String
$cshow :: CreateImageVersionResponse -> String
showsPrec :: Int -> CreateImageVersionResponse -> ShowS
$cshowsPrec :: Int -> CreateImageVersionResponse -> ShowS
Prelude.Show, (forall x.
 CreateImageVersionResponse -> Rep CreateImageVersionResponse x)
-> (forall x.
    Rep CreateImageVersionResponse x -> CreateImageVersionResponse)
-> Generic CreateImageVersionResponse
forall x.
Rep CreateImageVersionResponse x -> CreateImageVersionResponse
forall x.
CreateImageVersionResponse -> Rep CreateImageVersionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateImageVersionResponse x -> CreateImageVersionResponse
$cfrom :: forall x.
CreateImageVersionResponse -> Rep CreateImageVersionResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateImageVersionResponse' 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:
--
-- 'imageVersionArn', 'createImageVersionResponse_imageVersionArn' - The Amazon Resource Name (ARN) of the image version.
--
-- 'httpStatus', 'createImageVersionResponse_httpStatus' - The response's http status code.
newCreateImageVersionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateImageVersionResponse
newCreateImageVersionResponse :: Int -> CreateImageVersionResponse
newCreateImageVersionResponse Int
pHttpStatus_ =
  CreateImageVersionResponse' :: Maybe Text -> Int -> CreateImageVersionResponse
CreateImageVersionResponse'
    { $sel:imageVersionArn:CreateImageVersionResponse' :: Maybe Text
imageVersionArn =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateImageVersionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The Amazon Resource Name (ARN) of the image version.
createImageVersionResponse_imageVersionArn :: Lens.Lens' CreateImageVersionResponse (Prelude.Maybe Prelude.Text)
createImageVersionResponse_imageVersionArn :: (Maybe Text -> f (Maybe Text))
-> CreateImageVersionResponse -> f CreateImageVersionResponse
createImageVersionResponse_imageVersionArn = (CreateImageVersionResponse -> Maybe Text)
-> (CreateImageVersionResponse
    -> Maybe Text -> CreateImageVersionResponse)
-> Lens
     CreateImageVersionResponse
     CreateImageVersionResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateImageVersionResponse' {Maybe Text
imageVersionArn :: Maybe Text
$sel:imageVersionArn:CreateImageVersionResponse' :: CreateImageVersionResponse -> Maybe Text
imageVersionArn} -> Maybe Text
imageVersionArn) (\s :: CreateImageVersionResponse
s@CreateImageVersionResponse' {} Maybe Text
a -> CreateImageVersionResponse
s {$sel:imageVersionArn:CreateImageVersionResponse' :: Maybe Text
imageVersionArn = Maybe Text
a} :: CreateImageVersionResponse)

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

instance Prelude.NFData CreateImageVersionResponse