{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric      #-}
{-# LANGUAGE OverloadedStrings  #-}
{-# LANGUAGE RecordWildCards    #-}
{-# LANGUAGE TypeFamilies       #-}

{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-binds   #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

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

-- |
-- Module      : Network.AWS.IAM.CreateSAMLProvider
-- Copyright   : (c) 2013-2018 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)
--
-- Creates an IAM resource that describes an identity provider (IdP) that supports SAML 2.0.
--
--
-- The SAML provider resource that you create with this operation can be used as a principal in an IAM role's trust policy. Such a policy can enable federated users who sign-in using the SAML IdP to assume the role. You can create an IAM role that supports Web-based single sign-on (SSO) to the AWS Management Console or one that supports API access to AWS.
--
-- When you create the SAML provider resource, you upload a SAML metadata document that you get from your IdP. That document includes the issuer's name, expiration information, and keys that can be used to validate the SAML authentication response (assertions) that the IdP sends. You must generate the metadata document using the identity management software that is used as your organization's IdP.
--
-- For more information, see <http://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_enable-console-saml.html Enabling SAML 2.0 Federated Users to Access the AWS Management Console> and <http://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_saml.html About SAML 2.0-based Federation> in the /IAM User Guide/ .
--
module Network.AWS.IAM.CreateSAMLProvider
    (
    -- * Creating a Request
      createSAMLProvider
    , CreateSAMLProvider
    -- * Request Lenses
    , csamlpSAMLMetadataDocument
    , csamlpName

    -- * Destructuring the Response
    , createSAMLProviderResponse
    , CreateSAMLProviderResponse
    -- * Response Lenses
    , csamlprsSAMLProviderARN
    , csamlprsResponseStatus
    ) where

import Network.AWS.IAM.Types
import Network.AWS.IAM.Types.Product
import Network.AWS.Lens
import Network.AWS.Prelude
import Network.AWS.Request
import Network.AWS.Response

-- | /See:/ 'createSAMLProvider' smart constructor.
data CreateSAMLProvider = CreateSAMLProvider'
  { _csamlpSAMLMetadataDocument :: !Text
  , _csamlpName                 :: !Text
  } deriving (Eq, Read, Show, Data, Typeable, Generic)


-- | Creates a value of 'CreateSAMLProvider' with the minimum fields required to make a request.
--
-- Use one of the following lenses to modify other fields as desired:
--
-- * 'csamlpSAMLMetadataDocument' - An XML document generated by an identity provider (IdP) that supports SAML 2.0. The document includes the issuer's name, expiration information, and keys that can be used to validate the SAML authentication response (assertions) that are received from the IdP. You must generate the metadata document using the identity management software that is used as your organization's IdP. For more information, see <http://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_saml.html About SAML 2.0-based Federation> in the /IAM User Guide/
--
-- * 'csamlpName' - The name of the provider to create. This parameter allows (per its <http://wikipedia.org/wiki/regex regex pattern> ) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: _+=,.@-
createSAMLProvider
    :: Text -- ^ 'csamlpSAMLMetadataDocument'
    -> Text -- ^ 'csamlpName'
    -> CreateSAMLProvider
createSAMLProvider pSAMLMetadataDocument_ pName_ =
  CreateSAMLProvider'
    {_csamlpSAMLMetadataDocument = pSAMLMetadataDocument_, _csamlpName = pName_}


-- | An XML document generated by an identity provider (IdP) that supports SAML 2.0. The document includes the issuer's name, expiration information, and keys that can be used to validate the SAML authentication response (assertions) that are received from the IdP. You must generate the metadata document using the identity management software that is used as your organization's IdP. For more information, see <http://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_saml.html About SAML 2.0-based Federation> in the /IAM User Guide/
csamlpSAMLMetadataDocument :: Lens' CreateSAMLProvider Text
csamlpSAMLMetadataDocument = lens _csamlpSAMLMetadataDocument (\ s a -> s{_csamlpSAMLMetadataDocument = a})

-- | The name of the provider to create. This parameter allows (per its <http://wikipedia.org/wiki/regex regex pattern> ) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: _+=,.@-
csamlpName :: Lens' CreateSAMLProvider Text
csamlpName = lens _csamlpName (\ s a -> s{_csamlpName = a})

instance AWSRequest CreateSAMLProvider where
        type Rs CreateSAMLProvider =
             CreateSAMLProviderResponse
        request = postQuery iam
        response
          = receiveXMLWrapper "CreateSAMLProviderResult"
              (\ s h x ->
                 CreateSAMLProviderResponse' <$>
                   (x .@? "SAMLProviderArn") <*> (pure (fromEnum s)))

instance Hashable CreateSAMLProvider where

instance NFData CreateSAMLProvider where

instance ToHeaders CreateSAMLProvider where
        toHeaders = const mempty

instance ToPath CreateSAMLProvider where
        toPath = const "/"

instance ToQuery CreateSAMLProvider where
        toQuery CreateSAMLProvider'{..}
          = mconcat
              ["Action" =: ("CreateSAMLProvider" :: ByteString),
               "Version" =: ("2010-05-08" :: ByteString),
               "SAMLMetadataDocument" =:
                 _csamlpSAMLMetadataDocument,
               "Name" =: _csamlpName]

-- | Contains the response to a successful 'CreateSAMLProvider' request.
--
--
--
-- /See:/ 'createSAMLProviderResponse' smart constructor.
data CreateSAMLProviderResponse = CreateSAMLProviderResponse'
  { _csamlprsSAMLProviderARN :: !(Maybe Text)
  , _csamlprsResponseStatus  :: !Int
  } deriving (Eq, Read, Show, Data, Typeable, Generic)


-- | Creates a value of 'CreateSAMLProviderResponse' with the minimum fields required to make a request.
--
-- Use one of the following lenses to modify other fields as desired:
--
-- * 'csamlprsSAMLProviderARN' - The Amazon Resource Name (ARN) of the new SAML provider resource in IAM.
--
-- * 'csamlprsResponseStatus' - -- | The response status code.
createSAMLProviderResponse
    :: Int -- ^ 'csamlprsResponseStatus'
    -> CreateSAMLProviderResponse
createSAMLProviderResponse pResponseStatus_ =
  CreateSAMLProviderResponse'
    { _csamlprsSAMLProviderARN = Nothing
    , _csamlprsResponseStatus = pResponseStatus_
    }


-- | The Amazon Resource Name (ARN) of the new SAML provider resource in IAM.
csamlprsSAMLProviderARN :: Lens' CreateSAMLProviderResponse (Maybe Text)
csamlprsSAMLProviderARN = lens _csamlprsSAMLProviderARN (\ s a -> s{_csamlprsSAMLProviderARN = a})

-- | -- | The response status code.
csamlprsResponseStatus :: Lens' CreateSAMLProviderResponse Int
csamlprsResponseStatus = lens _csamlprsResponseStatus (\ s a -> s{_csamlprsResponseStatus = a})

instance NFData CreateSAMLProviderResponse where