{-# 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-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)
--
-- Gets the pre-signed URL to download a public 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 Amazonka.GreengrassV2.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:/ '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 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
(GetComponentVersionArtifact
 -> GetComponentVersionArtifact -> Bool)
-> (GetComponentVersionArtifact
    -> GetComponentVersionArtifact -> Bool)
-> Eq GetComponentVersionArtifact
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]
(Int -> ReadS GetComponentVersionArtifact)
-> ReadS [GetComponentVersionArtifact]
-> ReadPrec GetComponentVersionArtifact
-> ReadPrec [GetComponentVersionArtifact]
-> Read 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
(Int -> GetComponentVersionArtifact -> ShowS)
-> (GetComponentVersionArtifact -> String)
-> ([GetComponentVersionArtifact] -> ShowS)
-> Show GetComponentVersionArtifact
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.
 GetComponentVersionArtifact -> Rep GetComponentVersionArtifact x)
-> (forall x.
    Rep GetComponentVersionArtifact x -> GetComponentVersionArtifact)
-> Generic GetComponentVersionArtifact
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 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' :: Text -> Text -> GetComponentVersionArtifact
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 component version.
getComponentVersionArtifact_arn :: Lens.Lens' GetComponentVersionArtifact Prelude.Text
getComponentVersionArtifact_arn :: (Text -> f Text)
-> GetComponentVersionArtifact -> f GetComponentVersionArtifact
getComponentVersionArtifact_arn = (GetComponentVersionArtifact -> Text)
-> (GetComponentVersionArtifact
    -> Text -> GetComponentVersionArtifact)
-> Lens
     GetComponentVersionArtifact GetComponentVersionArtifact Text Text
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 :: (Text -> f Text)
-> GetComponentVersionArtifact -> f GetComponentVersionArtifact
getComponentVersionArtifact_artifactName = (GetComponentVersionArtifact -> Text)
-> (GetComponentVersionArtifact
    -> Text -> GetComponentVersionArtifact)
-> Lens
     GetComponentVersionArtifact GetComponentVersionArtifact Text Text
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 :: GetComponentVersionArtifact -> Request GetComponentVersionArtifact
request = Service
-> GetComponentVersionArtifact
-> Request GetComponentVersionArtifact
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetComponentVersionArtifact
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetComponentVersionArtifact)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetComponentVersionArtifact))
-> Logger
-> Service
-> Proxy GetComponentVersionArtifact
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetComponentVersionArtifact)))
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 ->
          Int -> Text -> GetComponentVersionArtifactResponse
GetComponentVersionArtifactResponse'
            (Int -> Text -> GetComponentVersionArtifactResponse)
-> Either String Int
-> Either String (Text -> GetComponentVersionArtifactResponse)
forall (f :: * -> *) a b. Functor 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))
            Either String (Text -> GetComponentVersionArtifactResponse)
-> Either String Text
-> Either String GetComponentVersionArtifactResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String Text
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"preSignedUrl")
      )

instance Prelude.Hashable GetComponentVersionArtifact

instance Prelude.NFData GetComponentVersionArtifact

instance Core.ToHeaders GetComponentVersionArtifact where
  toHeaders :: GetComponentVersionArtifact -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetComponentVersionArtifact -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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.ToPath GetComponentVersionArtifact where
  toPath :: GetComponentVersionArtifact -> ByteString
toPath GetComponentVersionArtifact' {Text
artifactName :: Text
arn :: Text
$sel:artifactName:GetComponentVersionArtifact' :: GetComponentVersionArtifact -> Text
$sel:arn:GetComponentVersionArtifact' :: GetComponentVersionArtifact -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/greengrass/v2/components/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
arn,
        ByteString
"/artifacts/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
artifactName
      ]

instance Core.ToQuery GetComponentVersionArtifact where
  toQuery :: GetComponentVersionArtifact -> QueryString
toQuery = QueryString -> GetComponentVersionArtifact -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(GetComponentVersionArtifactResponse
 -> GetComponentVersionArtifactResponse -> Bool)
-> (GetComponentVersionArtifactResponse
    -> GetComponentVersionArtifactResponse -> Bool)
-> Eq GetComponentVersionArtifactResponse
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]
(Int -> ReadS GetComponentVersionArtifactResponse)
-> ReadS [GetComponentVersionArtifactResponse]
-> ReadPrec GetComponentVersionArtifactResponse
-> ReadPrec [GetComponentVersionArtifactResponse]
-> Read 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
(Int -> GetComponentVersionArtifactResponse -> ShowS)
-> (GetComponentVersionArtifactResponse -> String)
-> ([GetComponentVersionArtifactResponse] -> ShowS)
-> Show GetComponentVersionArtifactResponse
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.
 GetComponentVersionArtifactResponse
 -> Rep GetComponentVersionArtifactResponse x)
-> (forall x.
    Rep GetComponentVersionArtifactResponse x
    -> GetComponentVersionArtifactResponse)
-> Generic GetComponentVersionArtifactResponse
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' :: Int -> Text -> GetComponentVersionArtifactResponse
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 :: (Int -> f Int)
-> GetComponentVersionArtifactResponse
-> f GetComponentVersionArtifactResponse
getComponentVersionArtifactResponse_httpStatus = (GetComponentVersionArtifactResponse -> Int)
-> (GetComponentVersionArtifactResponse
    -> Int -> GetComponentVersionArtifactResponse)
-> Lens
     GetComponentVersionArtifactResponse
     GetComponentVersionArtifactResponse
     Int
     Int
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 :: (Text -> f Text)
-> GetComponentVersionArtifactResponse
-> f GetComponentVersionArtifactResponse
getComponentVersionArtifactResponse_preSignedUrl = (GetComponentVersionArtifactResponse -> Text)
-> (GetComponentVersionArtifactResponse
    -> Text -> GetComponentVersionArtifactResponse)
-> Lens
     GetComponentVersionArtifactResponse
     GetComponentVersionArtifactResponse
     Text
     Text
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