"""
Autogenerated state module using `pop-create-idem <https://gitlab.com/saltstack/pop/pop-create-idem>`__

hub.exec.boto3.client.iam.create_saml_provider
hub.exec.boto3.client.iam.delete_saml_provider
hub.exec.boto3.client.iam.get_saml_provider
hub.exec.boto3.client.iam.list_saml_providers
hub.exec.boto3.client.iam.tag_saml_provider
hub.exec.boto3.client.iam.untag_saml_provider
hub.exec.boto3.client.iam.update_saml_provider
resource = hub.tool.boto3.resource.create(ctx, "iam", "SamlProvider", name)
hub.tool.boto3.resource.exec(resource, delete, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, update, *args, **kwargs)
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, saml_metadata_document: Text, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    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 Management Console or one that supports API access to Amazon
    Web Services. 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.   This operation
    requires Signature Version 4.   For more information, see Enabling SAML 2.0 federated users to access the
    Management Console and About SAML 2.0-based federation in the IAM User Guide.

    Args:
        name(Text): The name of the provider to create. This parameter allows (through its 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: _+=,.@-.
        saml_metadata_document(Text): 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 About SAML 2.0-based federation in the IAM User Guide.
        tags(List, optional): A list of tags that you want to attach to the new IAM SAML provider. Each tag consists of a key
            name and an associated value. For more information about tagging, see Tagging IAM resources in
            the IAM User Guide.  If any one of the tags is invalid or if you exceed the allowed maximum
            number of tags, then the entire request fails and the resource is not created. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.iam.saml_provider.present:
                - name: value
                - saml_metadata_document: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iam.saml_provider.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    resource = hub.tool.boto3.resource.create(ctx, "iam", "SamlProvider", name)
    before = await hub.tool.boto3.resource.describe(resource)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iam.create_saml_provider(
                ctx,
                
                
                **{"Name": name, "SAMLMetadataDocument": saml_metadata_document, "Tags": tags}
            )
            result["result"] = ret["status"]
            if not result["result"]:
                result["comment"] = ret["comment"]
                return result
            ret["comment"] = f"Created '{name}'"
        except hub.tool.boto3.exception.ClientError as e:
            result["comment"] = f"{e.__class__.__name__}: {e}"

    
    # TODO perform other modifications as needed here
    ...

    after = await hub.tool.boto3.resource.describe(resource)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, saml_provider_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a SAML provider resource in IAM. Deleting the provider resource from IAM does not update any roles that
    reference the SAML provider resource's ARN as a principal in their trust policies. Any attempt to assume a role
    that references a non-existent provider resource ARN fails.   This operation requires Signature Version 4.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        saml_provider_arn(Text): The Amazon Resource Name (ARN) of the SAML provider to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.iam.saml_provider.absent:
                - name: value
                - saml_provider_arn: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iam.saml_provider.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    resource = hub.tool.boto3.resource.create(ctx, "iam", "SamlProvider", name)

    before = await hub.tool.boto3.resource.describe(resource)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.iam.delete_saml_provider(
                ctx,
                
                
                **{"SAMLProviderArn": saml_provider_arn}
            )
            result["result"] = ret["status"]
            if not result["result"]:
                result["comment"] = ret["comment"]
                return result
            result["comment"] = f"Deleted '{name}'"
        except hub.tool.boto3.exception.ClientError as e:
            result["comment"] = f"{e.__class__.__name__}: {e}"

    

    after = await hub.tool.boto3.resource.describe(resource)
    result["changes"] = differ.deep_diff(before, after)
    return result

