{-# 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.Snowball.GetJobUnlockCode
-- 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)
--
-- Returns the @UnlockCode@ code value for the specified job. A particular
-- @UnlockCode@ value can be accessed for up to 360 days after the
-- associated job has been created.
--
-- The @UnlockCode@ value is a 29-character code with 25 alphanumeric
-- characters and 4 hyphens. This code is used to decrypt the manifest file
-- when it is passed along with the manifest to the Snow device through the
-- Snowball client when the client is started for the first time.
--
-- As a best practice, we recommend that you don\'t save a copy of the
-- @UnlockCode@ in the same location as the manifest file for that job.
-- Saving these separately helps prevent unauthorized parties from gaining
-- access to the Snow device associated with that job.
module Amazonka.Snowball.GetJobUnlockCode
  ( -- * Creating a Request
    GetJobUnlockCode (..),
    newGetJobUnlockCode,

    -- * Request Lenses
    getJobUnlockCode_jobId,

    -- * Destructuring the Response
    GetJobUnlockCodeResponse (..),
    newGetJobUnlockCodeResponse,

    -- * Response Lenses
    getJobUnlockCodeResponse_unlockCode,
    getJobUnlockCodeResponse_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.Snowball.Types

-- | /See:/ 'newGetJobUnlockCode' smart constructor.
data GetJobUnlockCode = GetJobUnlockCode'
  { -- | The ID for the job that you want to get the @UnlockCode@ value for, for
    -- example @JID123e4567-e89b-12d3-a456-426655440000@.
    GetJobUnlockCode -> Text
jobId :: Prelude.Text
  }
  deriving (GetJobUnlockCode -> GetJobUnlockCode -> Bool
(GetJobUnlockCode -> GetJobUnlockCode -> Bool)
-> (GetJobUnlockCode -> GetJobUnlockCode -> Bool)
-> Eq GetJobUnlockCode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetJobUnlockCode -> GetJobUnlockCode -> Bool
$c/= :: GetJobUnlockCode -> GetJobUnlockCode -> Bool
== :: GetJobUnlockCode -> GetJobUnlockCode -> Bool
$c== :: GetJobUnlockCode -> GetJobUnlockCode -> Bool
Prelude.Eq, ReadPrec [GetJobUnlockCode]
ReadPrec GetJobUnlockCode
Int -> ReadS GetJobUnlockCode
ReadS [GetJobUnlockCode]
(Int -> ReadS GetJobUnlockCode)
-> ReadS [GetJobUnlockCode]
-> ReadPrec GetJobUnlockCode
-> ReadPrec [GetJobUnlockCode]
-> Read GetJobUnlockCode
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetJobUnlockCode]
$creadListPrec :: ReadPrec [GetJobUnlockCode]
readPrec :: ReadPrec GetJobUnlockCode
$creadPrec :: ReadPrec GetJobUnlockCode
readList :: ReadS [GetJobUnlockCode]
$creadList :: ReadS [GetJobUnlockCode]
readsPrec :: Int -> ReadS GetJobUnlockCode
$creadsPrec :: Int -> ReadS GetJobUnlockCode
Prelude.Read, Int -> GetJobUnlockCode -> ShowS
[GetJobUnlockCode] -> ShowS
GetJobUnlockCode -> String
(Int -> GetJobUnlockCode -> ShowS)
-> (GetJobUnlockCode -> String)
-> ([GetJobUnlockCode] -> ShowS)
-> Show GetJobUnlockCode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetJobUnlockCode] -> ShowS
$cshowList :: [GetJobUnlockCode] -> ShowS
show :: GetJobUnlockCode -> String
$cshow :: GetJobUnlockCode -> String
showsPrec :: Int -> GetJobUnlockCode -> ShowS
$cshowsPrec :: Int -> GetJobUnlockCode -> ShowS
Prelude.Show, (forall x. GetJobUnlockCode -> Rep GetJobUnlockCode x)
-> (forall x. Rep GetJobUnlockCode x -> GetJobUnlockCode)
-> Generic GetJobUnlockCode
forall x. Rep GetJobUnlockCode x -> GetJobUnlockCode
forall x. GetJobUnlockCode -> Rep GetJobUnlockCode x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetJobUnlockCode x -> GetJobUnlockCode
$cfrom :: forall x. GetJobUnlockCode -> Rep GetJobUnlockCode x
Prelude.Generic)

-- |
-- Create a value of 'GetJobUnlockCode' 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:
--
-- 'jobId', 'getJobUnlockCode_jobId' - The ID for the job that you want to get the @UnlockCode@ value for, for
-- example @JID123e4567-e89b-12d3-a456-426655440000@.
newGetJobUnlockCode ::
  -- | 'jobId'
  Prelude.Text ->
  GetJobUnlockCode
newGetJobUnlockCode :: Text -> GetJobUnlockCode
newGetJobUnlockCode Text
pJobId_ =
  GetJobUnlockCode' :: Text -> GetJobUnlockCode
GetJobUnlockCode' {$sel:jobId:GetJobUnlockCode' :: Text
jobId = Text
pJobId_}

-- | The ID for the job that you want to get the @UnlockCode@ value for, for
-- example @JID123e4567-e89b-12d3-a456-426655440000@.
getJobUnlockCode_jobId :: Lens.Lens' GetJobUnlockCode Prelude.Text
getJobUnlockCode_jobId :: (Text -> f Text) -> GetJobUnlockCode -> f GetJobUnlockCode
getJobUnlockCode_jobId = (GetJobUnlockCode -> Text)
-> (GetJobUnlockCode -> Text -> GetJobUnlockCode)
-> Lens GetJobUnlockCode GetJobUnlockCode Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetJobUnlockCode' {Text
jobId :: Text
$sel:jobId:GetJobUnlockCode' :: GetJobUnlockCode -> Text
jobId} -> Text
jobId) (\s :: GetJobUnlockCode
s@GetJobUnlockCode' {} Text
a -> GetJobUnlockCode
s {$sel:jobId:GetJobUnlockCode' :: Text
jobId = Text
a} :: GetJobUnlockCode)

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

instance Prelude.NFData GetJobUnlockCode

instance Core.ToHeaders GetJobUnlockCode where
  toHeaders :: GetJobUnlockCode -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetJobUnlockCode -> 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
"AWSIESnowballJobManagementService.GetJobUnlockCode" ::
                          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 GetJobUnlockCode where
  toJSON :: GetJobUnlockCode -> Value
toJSON GetJobUnlockCode' {Text
jobId :: Text
$sel:jobId:GetJobUnlockCode' :: GetJobUnlockCode -> 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
"JobId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
jobId)]
      )

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

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

-- | /See:/ 'newGetJobUnlockCodeResponse' smart constructor.
data GetJobUnlockCodeResponse = GetJobUnlockCodeResponse'
  { -- | The @UnlockCode@ value for the specified job. The @UnlockCode@ value can
    -- be accessed for up to 360 days after the job has been created.
    GetJobUnlockCodeResponse -> Maybe Text
unlockCode :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    GetJobUnlockCodeResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetJobUnlockCodeResponse -> GetJobUnlockCodeResponse -> Bool
(GetJobUnlockCodeResponse -> GetJobUnlockCodeResponse -> Bool)
-> (GetJobUnlockCodeResponse -> GetJobUnlockCodeResponse -> Bool)
-> Eq GetJobUnlockCodeResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetJobUnlockCodeResponse -> GetJobUnlockCodeResponse -> Bool
$c/= :: GetJobUnlockCodeResponse -> GetJobUnlockCodeResponse -> Bool
== :: GetJobUnlockCodeResponse -> GetJobUnlockCodeResponse -> Bool
$c== :: GetJobUnlockCodeResponse -> GetJobUnlockCodeResponse -> Bool
Prelude.Eq, ReadPrec [GetJobUnlockCodeResponse]
ReadPrec GetJobUnlockCodeResponse
Int -> ReadS GetJobUnlockCodeResponse
ReadS [GetJobUnlockCodeResponse]
(Int -> ReadS GetJobUnlockCodeResponse)
-> ReadS [GetJobUnlockCodeResponse]
-> ReadPrec GetJobUnlockCodeResponse
-> ReadPrec [GetJobUnlockCodeResponse]
-> Read GetJobUnlockCodeResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetJobUnlockCodeResponse]
$creadListPrec :: ReadPrec [GetJobUnlockCodeResponse]
readPrec :: ReadPrec GetJobUnlockCodeResponse
$creadPrec :: ReadPrec GetJobUnlockCodeResponse
readList :: ReadS [GetJobUnlockCodeResponse]
$creadList :: ReadS [GetJobUnlockCodeResponse]
readsPrec :: Int -> ReadS GetJobUnlockCodeResponse
$creadsPrec :: Int -> ReadS GetJobUnlockCodeResponse
Prelude.Read, Int -> GetJobUnlockCodeResponse -> ShowS
[GetJobUnlockCodeResponse] -> ShowS
GetJobUnlockCodeResponse -> String
(Int -> GetJobUnlockCodeResponse -> ShowS)
-> (GetJobUnlockCodeResponse -> String)
-> ([GetJobUnlockCodeResponse] -> ShowS)
-> Show GetJobUnlockCodeResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetJobUnlockCodeResponse] -> ShowS
$cshowList :: [GetJobUnlockCodeResponse] -> ShowS
show :: GetJobUnlockCodeResponse -> String
$cshow :: GetJobUnlockCodeResponse -> String
showsPrec :: Int -> GetJobUnlockCodeResponse -> ShowS
$cshowsPrec :: Int -> GetJobUnlockCodeResponse -> ShowS
Prelude.Show, (forall x.
 GetJobUnlockCodeResponse -> Rep GetJobUnlockCodeResponse x)
-> (forall x.
    Rep GetJobUnlockCodeResponse x -> GetJobUnlockCodeResponse)
-> Generic GetJobUnlockCodeResponse
forall x.
Rep GetJobUnlockCodeResponse x -> GetJobUnlockCodeResponse
forall x.
GetJobUnlockCodeResponse -> Rep GetJobUnlockCodeResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetJobUnlockCodeResponse x -> GetJobUnlockCodeResponse
$cfrom :: forall x.
GetJobUnlockCodeResponse -> Rep GetJobUnlockCodeResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetJobUnlockCodeResponse' 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:
--
-- 'unlockCode', 'getJobUnlockCodeResponse_unlockCode' - The @UnlockCode@ value for the specified job. The @UnlockCode@ value can
-- be accessed for up to 360 days after the job has been created.
--
-- 'httpStatus', 'getJobUnlockCodeResponse_httpStatus' - The response's http status code.
newGetJobUnlockCodeResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetJobUnlockCodeResponse
newGetJobUnlockCodeResponse :: Int -> GetJobUnlockCodeResponse
newGetJobUnlockCodeResponse Int
pHttpStatus_ =
  GetJobUnlockCodeResponse' :: Maybe Text -> Int -> GetJobUnlockCodeResponse
GetJobUnlockCodeResponse'
    { $sel:unlockCode:GetJobUnlockCodeResponse' :: Maybe Text
unlockCode =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetJobUnlockCodeResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The @UnlockCode@ value for the specified job. The @UnlockCode@ value can
-- be accessed for up to 360 days after the job has been created.
getJobUnlockCodeResponse_unlockCode :: Lens.Lens' GetJobUnlockCodeResponse (Prelude.Maybe Prelude.Text)
getJobUnlockCodeResponse_unlockCode :: (Maybe Text -> f (Maybe Text))
-> GetJobUnlockCodeResponse -> f GetJobUnlockCodeResponse
getJobUnlockCodeResponse_unlockCode = (GetJobUnlockCodeResponse -> Maybe Text)
-> (GetJobUnlockCodeResponse
    -> Maybe Text -> GetJobUnlockCodeResponse)
-> Lens
     GetJobUnlockCodeResponse
     GetJobUnlockCodeResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetJobUnlockCodeResponse' {Maybe Text
unlockCode :: Maybe Text
$sel:unlockCode:GetJobUnlockCodeResponse' :: GetJobUnlockCodeResponse -> Maybe Text
unlockCode} -> Maybe Text
unlockCode) (\s :: GetJobUnlockCodeResponse
s@GetJobUnlockCodeResponse' {} Maybe Text
a -> GetJobUnlockCodeResponse
s {$sel:unlockCode:GetJobUnlockCodeResponse' :: Maybe Text
unlockCode = Maybe Text
a} :: GetJobUnlockCodeResponse)

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

instance Prelude.NFData GetJobUnlockCodeResponse