{-# 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.GreengrassV2.GetComponentVersionArtifact
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Gets the pre-signed URL to download a public or a Lambda component
-- artifact. Core devices call this operation to identify the URL that they
-- can use to download an artifact to install.
module Amazonka.GreengrassV2.GetComponentVersionArtifact
  ( -- * Creating a Request
    GetComponentVersionArtifact (..),
    newGetComponentVersionArtifact,

    -- * Request Lenses
    getComponentVersionArtifact_arn,
    getComponentVersionArtifact_artifactName,

    -- * Destructuring the Response
    GetComponentVersionArtifactResponse (..),
    newGetComponentVersionArtifactResponse,

    -- * Response Lenses
    getComponentVersionArtifactResponse_httpStatus,
    getComponentVersionArtifactResponse_preSignedUrl,
  )
where

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

-- | /See:/ 'newGetComponentVersionArtifact' smart constructor.
data GetComponentVersionArtifact = GetComponentVersionArtifact'
  { -- | The
    -- <https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html ARN>
    -- of the component version. Specify the ARN of a public or a Lambda
    -- component version.
    GetComponentVersionArtifact -> Text
arn :: Prelude.Text,
    -- | The name of the artifact.
    --
    -- You can use the
    -- <https://docs.aws.amazon.com/greengrass/v2/APIReference/API_GetComponent.html GetComponent>
    -- operation to download the component recipe, which includes the URI of
    -- the artifact. The artifact name is the section of the URI after the
    -- scheme. For example, in the artifact URI @greengrass:SomeArtifact.zip@,
    -- the artifact name is @SomeArtifact.zip@.
    GetComponentVersionArtifact -> Text
artifactName :: Prelude.Text
  }
  deriving (GetComponentVersionArtifact -> GetComponentVersionArtifact -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetComponentVersionArtifact -> GetComponentVersionArtifact -> Bool
$c/= :: GetComponentVersionArtifact -> GetComponentVersionArtifact -> Bool
== :: GetComponentVersionArtifact -> GetComponentVersionArtifact -> Bool
$c== :: GetComponentVersionArtifact -> GetComponentVersionArtifact -> Bool
Prelude.Eq, ReadPrec [GetComponentVersionArtifact]
ReadPrec GetComponentVersionArtifact
Int -> ReadS GetComponentVersionArtifact
ReadS [GetComponentVersionArtifact]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetComponentVersionArtifact]
$creadListPrec :: ReadPrec [GetComponentVersionArtifact]
readPrec :: ReadPrec GetComponentVersionArtifact
$creadPrec :: ReadPrec GetComponentVersionArtifact
readList :: ReadS [GetComponentVersionArtifact]
$creadList :: ReadS [GetComponentVersionArtifact]
readsPrec :: Int -> ReadS GetComponentVersionArtifact
$creadsPrec :: Int -> ReadS GetComponentVersionArtifact
Prelude.Read, Int -> GetComponentVersionArtifact -> ShowS
[GetComponentVersionArtifact] -> ShowS
GetComponentVersionArtifact -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetComponentVersionArtifact] -> ShowS
$cshowList :: [GetComponentVersionArtifact] -> ShowS
show :: GetComponentVersionArtifact -> String
$cshow :: GetComponentVersionArtifact -> String
showsPrec :: Int -> GetComponentVersionArtifact -> ShowS
$cshowsPrec :: Int -> GetComponentVersionArtifact -> ShowS
Prelude.Show, forall x.
Rep GetComponentVersionArtifact x -> GetComponentVersionArtifact
forall x.
GetComponentVersionArtifact -> Rep GetComponentVersionArtifact x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetComponentVersionArtifact x -> GetComponentVersionArtifact
$cfrom :: forall x.
GetComponentVersionArtifact -> Rep GetComponentVersionArtifact x
Prelude.Generic)

-- |
-- Create a value of 'GetComponentVersionArtifact' 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:
--
-- 'arn', 'getComponentVersionArtifact_arn' - The
-- <https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html ARN>
-- of the component version. Specify the ARN of a public or a Lambda
-- component version.
--
-- 'artifactName', 'getComponentVersionArtifact_artifactName' - The name of the artifact.
--
-- You can use the
-- <https://docs.aws.amazon.com/greengrass/v2/APIReference/API_GetComponent.html GetComponent>
-- operation to download the component recipe, which includes the URI of
-- the artifact. The artifact name is the section of the URI after the
-- scheme. For example, in the artifact URI @greengrass:SomeArtifact.zip@,
-- the artifact name is @SomeArtifact.zip@.
newGetComponentVersionArtifact ::
  -- | 'arn'
  Prelude.Text ->
  -- | 'artifactName'
  Prelude.Text ->
  GetComponentVersionArtifact
newGetComponentVersionArtifact :: Text -> Text -> GetComponentVersionArtifact
newGetComponentVersionArtifact Text
pArn_ Text
pArtifactName_ =
  GetComponentVersionArtifact'
    { $sel:arn:GetComponentVersionArtifact' :: Text
arn = Text
pArn_,
      $sel:artifactName:GetComponentVersionArtifact' :: Text
artifactName = Text
pArtifactName_
    }

-- | The
-- <https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html ARN>
-- of the component version. Specify the ARN of a public or a Lambda
-- component version.
getComponentVersionArtifact_arn :: Lens.Lens' GetComponentVersionArtifact Prelude.Text
getComponentVersionArtifact_arn :: Lens' GetComponentVersionArtifact Text
getComponentVersionArtifact_arn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetComponentVersionArtifact' {Text
arn :: Text
$sel:arn:GetComponentVersionArtifact' :: GetComponentVersionArtifact -> Text
arn} -> Text
arn) (\s :: GetComponentVersionArtifact
s@GetComponentVersionArtifact' {} Text
a -> GetComponentVersionArtifact
s {$sel:arn:GetComponentVersionArtifact' :: Text
arn = Text
a} :: GetComponentVersionArtifact)

-- | The name of the artifact.
--
-- You can use the
-- <https://docs.aws.amazon.com/greengrass/v2/APIReference/API_GetComponent.html GetComponent>
-- operation to download the component recipe, which includes the URI of
-- the artifact. The artifact name is the section of the URI after the
-- scheme. For example, in the artifact URI @greengrass:SomeArtifact.zip@,
-- the artifact name is @SomeArtifact.zip@.
getComponentVersionArtifact_artifactName :: Lens.Lens' GetComponentVersionArtifact Prelude.Text
getComponentVersionArtifact_artifactName :: Lens' GetComponentVersionArtifact Text
getComponentVersionArtifact_artifactName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetComponentVersionArtifact' {Text
artifactName :: Text
$sel:artifactName:GetComponentVersionArtifact' :: GetComponentVersionArtifact -> Text
artifactName} -> Text
artifactName) (\s :: GetComponentVersionArtifact
s@GetComponentVersionArtifact' {} Text
a -> GetComponentVersionArtifact
s {$sel:artifactName:GetComponentVersionArtifact' :: Text
artifactName = Text
a} :: GetComponentVersionArtifact)

instance Core.AWSRequest GetComponentVersionArtifact where
  type
    AWSResponse GetComponentVersionArtifact =
      GetComponentVersionArtifactResponse
  request :: (Service -> Service)
-> GetComponentVersionArtifact
-> Request GetComponentVersionArtifact
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.get (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetComponentVersionArtifact
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetComponentVersionArtifact)))
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 ->
          Int -> Text -> GetComponentVersionArtifactResponse
GetComponentVersionArtifactResponse'
            forall (f :: * -> *) a b. Functor 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))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String a
Data..:> Key
"preSignedUrl")
      )

instance Prelude.Hashable GetComponentVersionArtifact where
  hashWithSalt :: Int -> GetComponentVersionArtifact -> Int
hashWithSalt Int
_salt GetComponentVersionArtifact' {Text
artifactName :: Text
arn :: Text
$sel:artifactName:GetComponentVersionArtifact' :: GetComponentVersionArtifact -> Text
$sel:arn:GetComponentVersionArtifact' :: GetComponentVersionArtifact -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
arn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
artifactName

instance Prelude.NFData GetComponentVersionArtifact where
  rnf :: GetComponentVersionArtifact -> ()
rnf GetComponentVersionArtifact' {Text
artifactName :: Text
arn :: Text
$sel:artifactName:GetComponentVersionArtifact' :: GetComponentVersionArtifact -> Text
$sel:arn:GetComponentVersionArtifact' :: GetComponentVersionArtifact -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
arn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
artifactName

instance Data.ToHeaders GetComponentVersionArtifact where
  toHeaders :: GetComponentVersionArtifact -> ResponseHeaders
toHeaders = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

instance Data.ToPath GetComponentVersionArtifact where
  toPath :: GetComponentVersionArtifact -> ByteString
toPath GetComponentVersionArtifact' {Text
artifactName :: Text
arn :: Text
$sel:artifactName:GetComponentVersionArtifact' :: GetComponentVersionArtifact -> Text
$sel:arn:GetComponentVersionArtifact' :: GetComponentVersionArtifact -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/greengrass/v2/components/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
arn,
        ByteString
"/artifacts/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
artifactName
      ]

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

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

-- |
-- Create a value of 'GetComponentVersionArtifactResponse' 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:
--
-- 'httpStatus', 'getComponentVersionArtifactResponse_httpStatus' - The response's http status code.
--
-- 'preSignedUrl', 'getComponentVersionArtifactResponse_preSignedUrl' - The URL of the artifact.
newGetComponentVersionArtifactResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'preSignedUrl'
  Prelude.Text ->
  GetComponentVersionArtifactResponse
newGetComponentVersionArtifactResponse :: Int -> Text -> GetComponentVersionArtifactResponse
newGetComponentVersionArtifactResponse
  Int
pHttpStatus_
  Text
pPreSignedUrl_ =
    GetComponentVersionArtifactResponse'
      { $sel:httpStatus:GetComponentVersionArtifactResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:preSignedUrl:GetComponentVersionArtifactResponse' :: Text
preSignedUrl = Text
pPreSignedUrl_
      }

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

-- | The URL of the artifact.
getComponentVersionArtifactResponse_preSignedUrl :: Lens.Lens' GetComponentVersionArtifactResponse Prelude.Text
getComponentVersionArtifactResponse_preSignedUrl :: Lens' GetComponentVersionArtifactResponse Text
getComponentVersionArtifactResponse_preSignedUrl = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetComponentVersionArtifactResponse' {Text
preSignedUrl :: Text
$sel:preSignedUrl:GetComponentVersionArtifactResponse' :: GetComponentVersionArtifactResponse -> Text
preSignedUrl} -> Text
preSignedUrl) (\s :: GetComponentVersionArtifactResponse
s@GetComponentVersionArtifactResponse' {} Text
a -> GetComponentVersionArtifactResponse
s {$sel:preSignedUrl:GetComponentVersionArtifactResponse' :: Text
preSignedUrl = Text
a} :: GetComponentVersionArtifactResponse)

instance
  Prelude.NFData
    GetComponentVersionArtifactResponse
  where
  rnf :: GetComponentVersionArtifactResponse -> ()
rnf GetComponentVersionArtifactResponse' {Int
Text
preSignedUrl :: Text
httpStatus :: Int
$sel:preSignedUrl:GetComponentVersionArtifactResponse' :: GetComponentVersionArtifactResponse -> Text
$sel:httpStatus:GetComponentVersionArtifactResponse' :: GetComponentVersionArtifactResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
preSignedUrl