{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.ECR.Types.AuthorizationData
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.ECR.Types.AuthorizationData 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

-- | An object representing authorization data for an Amazon ECR registry.
--
-- /See:/ 'newAuthorizationData' smart constructor.
data AuthorizationData = AuthorizationData'
  { -- | A base64-encoded string that contains authorization data for the
    -- specified Amazon ECR registry. When the string is decoded, it is
    -- presented in the format @user:password@ for private registry
    -- authentication using @docker login@.
    AuthorizationData -> Maybe Text
authorizationToken :: Prelude.Maybe Prelude.Text,
    -- | The Unix time in seconds and milliseconds when the authorization token
    -- expires. Authorization tokens are valid for 12 hours.
    AuthorizationData -> Maybe POSIX
expiresAt :: Prelude.Maybe Data.POSIX,
    -- | The registry URL to use for this authorization token in a @docker login@
    -- command. The Amazon ECR registry URL format is
    -- @https:\/\/aws_account_id.dkr.ecr.region.amazonaws.com@. For example,
    -- @https:\/\/012345678910.dkr.ecr.us-east-1.amazonaws.com@..
    AuthorizationData -> Maybe Text
proxyEndpoint :: Prelude.Maybe Prelude.Text
  }
  deriving (AuthorizationData -> AuthorizationData -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AuthorizationData -> AuthorizationData -> Bool
$c/= :: AuthorizationData -> AuthorizationData -> Bool
== :: AuthorizationData -> AuthorizationData -> Bool
$c== :: AuthorizationData -> AuthorizationData -> Bool
Prelude.Eq, ReadPrec [AuthorizationData]
ReadPrec AuthorizationData
Int -> ReadS AuthorizationData
ReadS [AuthorizationData]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AuthorizationData]
$creadListPrec :: ReadPrec [AuthorizationData]
readPrec :: ReadPrec AuthorizationData
$creadPrec :: ReadPrec AuthorizationData
readList :: ReadS [AuthorizationData]
$creadList :: ReadS [AuthorizationData]
readsPrec :: Int -> ReadS AuthorizationData
$creadsPrec :: Int -> ReadS AuthorizationData
Prelude.Read, Int -> AuthorizationData -> ShowS
[AuthorizationData] -> ShowS
AuthorizationData -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AuthorizationData] -> ShowS
$cshowList :: [AuthorizationData] -> ShowS
show :: AuthorizationData -> String
$cshow :: AuthorizationData -> String
showsPrec :: Int -> AuthorizationData -> ShowS
$cshowsPrec :: Int -> AuthorizationData -> ShowS
Prelude.Show, forall x. Rep AuthorizationData x -> AuthorizationData
forall x. AuthorizationData -> Rep AuthorizationData x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AuthorizationData x -> AuthorizationData
$cfrom :: forall x. AuthorizationData -> Rep AuthorizationData x
Prelude.Generic)

-- |
-- Create a value of 'AuthorizationData' 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:
--
-- 'authorizationToken', 'authorizationData_authorizationToken' - A base64-encoded string that contains authorization data for the
-- specified Amazon ECR registry. When the string is decoded, it is
-- presented in the format @user:password@ for private registry
-- authentication using @docker login@.
--
-- 'expiresAt', 'authorizationData_expiresAt' - The Unix time in seconds and milliseconds when the authorization token
-- expires. Authorization tokens are valid for 12 hours.
--
-- 'proxyEndpoint', 'authorizationData_proxyEndpoint' - The registry URL to use for this authorization token in a @docker login@
-- command. The Amazon ECR registry URL format is
-- @https:\/\/aws_account_id.dkr.ecr.region.amazonaws.com@. For example,
-- @https:\/\/012345678910.dkr.ecr.us-east-1.amazonaws.com@..
newAuthorizationData ::
  AuthorizationData
newAuthorizationData :: AuthorizationData
newAuthorizationData =
  AuthorizationData'
    { $sel:authorizationToken:AuthorizationData' :: Maybe Text
authorizationToken =
        forall a. Maybe a
Prelude.Nothing,
      $sel:expiresAt:AuthorizationData' :: Maybe POSIX
expiresAt = forall a. Maybe a
Prelude.Nothing,
      $sel:proxyEndpoint:AuthorizationData' :: Maybe Text
proxyEndpoint = forall a. Maybe a
Prelude.Nothing
    }

-- | A base64-encoded string that contains authorization data for the
-- specified Amazon ECR registry. When the string is decoded, it is
-- presented in the format @user:password@ for private registry
-- authentication using @docker login@.
authorizationData_authorizationToken :: Lens.Lens' AuthorizationData (Prelude.Maybe Prelude.Text)
authorizationData_authorizationToken :: Lens' AuthorizationData (Maybe Text)
authorizationData_authorizationToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AuthorizationData' {Maybe Text
authorizationToken :: Maybe Text
$sel:authorizationToken:AuthorizationData' :: AuthorizationData -> Maybe Text
authorizationToken} -> Maybe Text
authorizationToken) (\s :: AuthorizationData
s@AuthorizationData' {} Maybe Text
a -> AuthorizationData
s {$sel:authorizationToken:AuthorizationData' :: Maybe Text
authorizationToken = Maybe Text
a} :: AuthorizationData)

-- | The Unix time in seconds and milliseconds when the authorization token
-- expires. Authorization tokens are valid for 12 hours.
authorizationData_expiresAt :: Lens.Lens' AuthorizationData (Prelude.Maybe Prelude.UTCTime)
authorizationData_expiresAt :: Lens' AuthorizationData (Maybe UTCTime)
authorizationData_expiresAt = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AuthorizationData' {Maybe POSIX
expiresAt :: Maybe POSIX
$sel:expiresAt:AuthorizationData' :: AuthorizationData -> Maybe POSIX
expiresAt} -> Maybe POSIX
expiresAt) (\s :: AuthorizationData
s@AuthorizationData' {} Maybe POSIX
a -> AuthorizationData
s {$sel:expiresAt:AuthorizationData' :: Maybe POSIX
expiresAt = Maybe POSIX
a} :: AuthorizationData) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | The registry URL to use for this authorization token in a @docker login@
-- command. The Amazon ECR registry URL format is
-- @https:\/\/aws_account_id.dkr.ecr.region.amazonaws.com@. For example,
-- @https:\/\/012345678910.dkr.ecr.us-east-1.amazonaws.com@..
authorizationData_proxyEndpoint :: Lens.Lens' AuthorizationData (Prelude.Maybe Prelude.Text)
authorizationData_proxyEndpoint :: Lens' AuthorizationData (Maybe Text)
authorizationData_proxyEndpoint = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AuthorizationData' {Maybe Text
proxyEndpoint :: Maybe Text
$sel:proxyEndpoint:AuthorizationData' :: AuthorizationData -> Maybe Text
proxyEndpoint} -> Maybe Text
proxyEndpoint) (\s :: AuthorizationData
s@AuthorizationData' {} Maybe Text
a -> AuthorizationData
s {$sel:proxyEndpoint:AuthorizationData' :: Maybe Text
proxyEndpoint = Maybe Text
a} :: AuthorizationData)

instance Data.FromJSON AuthorizationData where
  parseJSON :: Value -> Parser AuthorizationData
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AuthorizationData"
      ( \Object
x ->
          Maybe Text -> Maybe POSIX -> Maybe Text -> AuthorizationData
AuthorizationData'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"authorizationToken")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"expiresAt")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"proxyEndpoint")
      )

instance Prelude.Hashable AuthorizationData where
  hashWithSalt :: Int -> AuthorizationData -> Int
hashWithSalt Int
_salt AuthorizationData' {Maybe Text
Maybe POSIX
proxyEndpoint :: Maybe Text
expiresAt :: Maybe POSIX
authorizationToken :: Maybe Text
$sel:proxyEndpoint:AuthorizationData' :: AuthorizationData -> Maybe Text
$sel:expiresAt:AuthorizationData' :: AuthorizationData -> Maybe POSIX
$sel:authorizationToken:AuthorizationData' :: AuthorizationData -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
authorizationToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
expiresAt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
proxyEndpoint

instance Prelude.NFData AuthorizationData where
  rnf :: AuthorizationData -> ()
rnf AuthorizationData' {Maybe Text
Maybe POSIX
proxyEndpoint :: Maybe Text
expiresAt :: Maybe POSIX
authorizationToken :: Maybe Text
$sel:proxyEndpoint:AuthorizationData' :: AuthorizationData -> Maybe Text
$sel:expiresAt:AuthorizationData' :: AuthorizationData -> Maybe POSIX
$sel:authorizationToken:AuthorizationData' :: AuthorizationData -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
authorizationToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
expiresAt
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
proxyEndpoint