{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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. The only
-- valid status for calling this API is @WithCustomer@ as the manifest and
-- @Unlock@ code values are used for securing your device and should only
-- be used when you have the device.
--
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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' {$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 :: Lens' GetJobUnlockCode Text
getJobUnlockCode_jobId = 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 :: (Service -> Service)
-> GetJobUnlockCode -> Request GetJobUnlockCode
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 GetJobUnlockCode
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetJobUnlockCode)))
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 Text -> Int -> GetJobUnlockCodeResponse
GetJobUnlockCodeResponse'
            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
"UnlockCode")
            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 GetJobUnlockCode where
  hashWithSalt :: Int -> GetJobUnlockCode -> Int
hashWithSalt Int
_salt GetJobUnlockCode' {Text
jobId :: Text
$sel:jobId:GetJobUnlockCode' :: GetJobUnlockCode -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
jobId

instance Prelude.NFData GetJobUnlockCode where
  rnf :: GetJobUnlockCode -> ()
rnf GetJobUnlockCode' {Text
jobId :: Text
$sel:jobId:GetJobUnlockCode' :: GetJobUnlockCode -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
jobId

instance Data.ToHeaders GetJobUnlockCode where
  toHeaders :: GetJobUnlockCode -> 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
"AWSIESnowballJobManagementService.GetJobUnlockCode" ::
                          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 GetJobUnlockCode where
  toJSON :: GetJobUnlockCode -> Value
toJSON GetJobUnlockCode' {Text
jobId :: Text
$sel:jobId:GetJobUnlockCode' :: GetJobUnlockCode -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"JobId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
jobId)]
      )

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

instance Data.ToQuery GetJobUnlockCode where
  toQuery :: GetJobUnlockCode -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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.
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'
    { $sel:unlockCode:GetJobUnlockCodeResponse' :: Maybe Text
unlockCode =
        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 :: Lens' GetJobUnlockCodeResponse (Maybe Text)
getJobUnlockCodeResponse_unlockCode = 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 :: Lens' GetJobUnlockCodeResponse Int
getJobUnlockCodeResponse_httpStatus = 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 where
  rnf :: GetJobUnlockCodeResponse -> ()
rnf GetJobUnlockCodeResponse' {Int
Maybe Text
httpStatus :: Int
unlockCode :: Maybe Text
$sel:httpStatus:GetJobUnlockCodeResponse' :: GetJobUnlockCodeResponse -> Int
$sel:unlockCode:GetJobUnlockCodeResponse' :: GetJobUnlockCodeResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
unlockCode
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus