{-# 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.SSM.Types.AttachmentsSource
-- 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)
module Amazonka.SSM.Types.AttachmentsSource where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SSM.Types.AttachmentsSourceKey

-- | Identifying information about a document attachment, including the file
-- name and a key-value pair that identifies the location of an attachment
-- to a document.
--
-- /See:/ 'newAttachmentsSource' smart constructor.
data AttachmentsSource = AttachmentsSource'
  { -- | The value of a key-value pair that identifies the location of an
    -- attachment to a document. The format for __Value__ depends on the type
    -- of key you specify.
    --
    -- -   For the key /SourceUrl/, the value is an S3 bucket location. For
    --     example:
    --
    --     @\"Values\": [ \"s3:\/\/doc-example-bucket\/my-folder\" ]@
    --
    -- -   For the key /S3FileUrl/, the value is a file in an S3 bucket. For
    --     example:
    --
    --     @\"Values\": [ \"s3:\/\/doc-example-bucket\/my-folder\/my-file.py\" ]@
    --
    -- -   For the key /AttachmentReference/, the value is constructed from the
    --     name of another SSM document in your account, a version number of
    --     that document, and a file attached to that document version that you
    --     want to reuse. For example:
    --
    --     @\"Values\": [ \"MyOtherDocument\/3\/my-other-file.py\" ]@
    --
    --     However, if the SSM document is shared with you from another
    --     account, the full SSM document ARN must be specified instead of the
    --     document name only. For example:
    --
    --     @\"Values\": [ \"arn:aws:ssm:us-east-2:111122223333:document\/OtherAccountDocument\/3\/their-file.py\" ]@
    AttachmentsSource -> Maybe (NonEmpty Text)
values :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | The key of a key-value pair that identifies the location of an
    -- attachment to a document.
    AttachmentsSource -> Maybe AttachmentsSourceKey
key :: Prelude.Maybe AttachmentsSourceKey,
    -- | The name of the document attachment file.
    AttachmentsSource -> Maybe Text
name :: Prelude.Maybe Prelude.Text
  }
  deriving (AttachmentsSource -> AttachmentsSource -> Bool
(AttachmentsSource -> AttachmentsSource -> Bool)
-> (AttachmentsSource -> AttachmentsSource -> Bool)
-> Eq AttachmentsSource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttachmentsSource -> AttachmentsSource -> Bool
$c/= :: AttachmentsSource -> AttachmentsSource -> Bool
== :: AttachmentsSource -> AttachmentsSource -> Bool
$c== :: AttachmentsSource -> AttachmentsSource -> Bool
Prelude.Eq, ReadPrec [AttachmentsSource]
ReadPrec AttachmentsSource
Int -> ReadS AttachmentsSource
ReadS [AttachmentsSource]
(Int -> ReadS AttachmentsSource)
-> ReadS [AttachmentsSource]
-> ReadPrec AttachmentsSource
-> ReadPrec [AttachmentsSource]
-> Read AttachmentsSource
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AttachmentsSource]
$creadListPrec :: ReadPrec [AttachmentsSource]
readPrec :: ReadPrec AttachmentsSource
$creadPrec :: ReadPrec AttachmentsSource
readList :: ReadS [AttachmentsSource]
$creadList :: ReadS [AttachmentsSource]
readsPrec :: Int -> ReadS AttachmentsSource
$creadsPrec :: Int -> ReadS AttachmentsSource
Prelude.Read, Int -> AttachmentsSource -> ShowS
[AttachmentsSource] -> ShowS
AttachmentsSource -> String
(Int -> AttachmentsSource -> ShowS)
-> (AttachmentsSource -> String)
-> ([AttachmentsSource] -> ShowS)
-> Show AttachmentsSource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AttachmentsSource] -> ShowS
$cshowList :: [AttachmentsSource] -> ShowS
show :: AttachmentsSource -> String
$cshow :: AttachmentsSource -> String
showsPrec :: Int -> AttachmentsSource -> ShowS
$cshowsPrec :: Int -> AttachmentsSource -> ShowS
Prelude.Show, (forall x. AttachmentsSource -> Rep AttachmentsSource x)
-> (forall x. Rep AttachmentsSource x -> AttachmentsSource)
-> Generic AttachmentsSource
forall x. Rep AttachmentsSource x -> AttachmentsSource
forall x. AttachmentsSource -> Rep AttachmentsSource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AttachmentsSource x -> AttachmentsSource
$cfrom :: forall x. AttachmentsSource -> Rep AttachmentsSource x
Prelude.Generic)

-- |
-- Create a value of 'AttachmentsSource' 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:
--
-- 'values', 'attachmentsSource_values' - The value of a key-value pair that identifies the location of an
-- attachment to a document. The format for __Value__ depends on the type
-- of key you specify.
--
-- -   For the key /SourceUrl/, the value is an S3 bucket location. For
--     example:
--
--     @\"Values\": [ \"s3:\/\/doc-example-bucket\/my-folder\" ]@
--
-- -   For the key /S3FileUrl/, the value is a file in an S3 bucket. For
--     example:
--
--     @\"Values\": [ \"s3:\/\/doc-example-bucket\/my-folder\/my-file.py\" ]@
--
-- -   For the key /AttachmentReference/, the value is constructed from the
--     name of another SSM document in your account, a version number of
--     that document, and a file attached to that document version that you
--     want to reuse. For example:
--
--     @\"Values\": [ \"MyOtherDocument\/3\/my-other-file.py\" ]@
--
--     However, if the SSM document is shared with you from another
--     account, the full SSM document ARN must be specified instead of the
--     document name only. For example:
--
--     @\"Values\": [ \"arn:aws:ssm:us-east-2:111122223333:document\/OtherAccountDocument\/3\/their-file.py\" ]@
--
-- 'key', 'attachmentsSource_key' - The key of a key-value pair that identifies the location of an
-- attachment to a document.
--
-- 'name', 'attachmentsSource_name' - The name of the document attachment file.
newAttachmentsSource ::
  AttachmentsSource
newAttachmentsSource :: AttachmentsSource
newAttachmentsSource =
  AttachmentsSource' :: Maybe (NonEmpty Text)
-> Maybe AttachmentsSourceKey -> Maybe Text -> AttachmentsSource
AttachmentsSource'
    { $sel:values:AttachmentsSource' :: Maybe (NonEmpty Text)
values = Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:key:AttachmentsSource' :: Maybe AttachmentsSourceKey
key = Maybe AttachmentsSourceKey
forall a. Maybe a
Prelude.Nothing,
      $sel:name:AttachmentsSource' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The value of a key-value pair that identifies the location of an
-- attachment to a document. The format for __Value__ depends on the type
-- of key you specify.
--
-- -   For the key /SourceUrl/, the value is an S3 bucket location. For
--     example:
--
--     @\"Values\": [ \"s3:\/\/doc-example-bucket\/my-folder\" ]@
--
-- -   For the key /S3FileUrl/, the value is a file in an S3 bucket. For
--     example:
--
--     @\"Values\": [ \"s3:\/\/doc-example-bucket\/my-folder\/my-file.py\" ]@
--
-- -   For the key /AttachmentReference/, the value is constructed from the
--     name of another SSM document in your account, a version number of
--     that document, and a file attached to that document version that you
--     want to reuse. For example:
--
--     @\"Values\": [ \"MyOtherDocument\/3\/my-other-file.py\" ]@
--
--     However, if the SSM document is shared with you from another
--     account, the full SSM document ARN must be specified instead of the
--     document name only. For example:
--
--     @\"Values\": [ \"arn:aws:ssm:us-east-2:111122223333:document\/OtherAccountDocument\/3\/their-file.py\" ]@
attachmentsSource_values :: Lens.Lens' AttachmentsSource (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
attachmentsSource_values :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> AttachmentsSource -> f AttachmentsSource
attachmentsSource_values = (AttachmentsSource -> Maybe (NonEmpty Text))
-> (AttachmentsSource
    -> Maybe (NonEmpty Text) -> AttachmentsSource)
-> Lens
     AttachmentsSource
     AttachmentsSource
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachmentsSource' {Maybe (NonEmpty Text)
values :: Maybe (NonEmpty Text)
$sel:values:AttachmentsSource' :: AttachmentsSource -> Maybe (NonEmpty Text)
values} -> Maybe (NonEmpty Text)
values) (\s :: AttachmentsSource
s@AttachmentsSource' {} Maybe (NonEmpty Text)
a -> AttachmentsSource
s {$sel:values:AttachmentsSource' :: Maybe (NonEmpty Text)
values = Maybe (NonEmpty Text)
a} :: AttachmentsSource) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> AttachmentsSource -> f AttachmentsSource)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> AttachmentsSource
-> f AttachmentsSource
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
-> Iso
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
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 AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The key of a key-value pair that identifies the location of an
-- attachment to a document.
attachmentsSource_key :: Lens.Lens' AttachmentsSource (Prelude.Maybe AttachmentsSourceKey)
attachmentsSource_key :: (Maybe AttachmentsSourceKey -> f (Maybe AttachmentsSourceKey))
-> AttachmentsSource -> f AttachmentsSource
attachmentsSource_key = (AttachmentsSource -> Maybe AttachmentsSourceKey)
-> (AttachmentsSource
    -> Maybe AttachmentsSourceKey -> AttachmentsSource)
-> Lens
     AttachmentsSource
     AttachmentsSource
     (Maybe AttachmentsSourceKey)
     (Maybe AttachmentsSourceKey)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachmentsSource' {Maybe AttachmentsSourceKey
key :: Maybe AttachmentsSourceKey
$sel:key:AttachmentsSource' :: AttachmentsSource -> Maybe AttachmentsSourceKey
key} -> Maybe AttachmentsSourceKey
key) (\s :: AttachmentsSource
s@AttachmentsSource' {} Maybe AttachmentsSourceKey
a -> AttachmentsSource
s {$sel:key:AttachmentsSource' :: Maybe AttachmentsSourceKey
key = Maybe AttachmentsSourceKey
a} :: AttachmentsSource)

-- | The name of the document attachment file.
attachmentsSource_name :: Lens.Lens' AttachmentsSource (Prelude.Maybe Prelude.Text)
attachmentsSource_name :: (Maybe Text -> f (Maybe Text))
-> AttachmentsSource -> f AttachmentsSource
attachmentsSource_name = (AttachmentsSource -> Maybe Text)
-> (AttachmentsSource -> Maybe Text -> AttachmentsSource)
-> Lens
     AttachmentsSource AttachmentsSource (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachmentsSource' {Maybe Text
name :: Maybe Text
$sel:name:AttachmentsSource' :: AttachmentsSource -> Maybe Text
name} -> Maybe Text
name) (\s :: AttachmentsSource
s@AttachmentsSource' {} Maybe Text
a -> AttachmentsSource
s {$sel:name:AttachmentsSource' :: Maybe Text
name = Maybe Text
a} :: AttachmentsSource)

instance Prelude.Hashable AttachmentsSource

instance Prelude.NFData AttachmentsSource

instance Core.ToJSON AttachmentsSource where
  toJSON :: AttachmentsSource -> Value
toJSON AttachmentsSource' {Maybe (NonEmpty Text)
Maybe Text
Maybe AttachmentsSourceKey
name :: Maybe Text
key :: Maybe AttachmentsSourceKey
values :: Maybe (NonEmpty Text)
$sel:name:AttachmentsSource' :: AttachmentsSource -> Maybe Text
$sel:key:AttachmentsSource' :: AttachmentsSource -> Maybe AttachmentsSourceKey
$sel:values:AttachmentsSource' :: AttachmentsSource -> Maybe (NonEmpty Text)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Values" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (NonEmpty Text -> Pair) -> Maybe (NonEmpty Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Text)
values,
            (Text
"Key" Text -> AttachmentsSourceKey -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (AttachmentsSourceKey -> Pair)
-> Maybe AttachmentsSourceKey -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe AttachmentsSourceKey
key,
            (Text
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
name
          ]
      )