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

hub.exec.boto3.client.iam.delete_signing_certificate
hub.exec.boto3.client.iam.list_signing_certificates
hub.exec.boto3.client.iam.update_signing_certificate
hub.exec.boto3.client.iam.upload_signing_certificate
resource = hub.tool.boto3.resource.create(ctx, "iam", "SigningCertificate", name)
hub.tool.boto3.resource.exec(resource, activate, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, deactivate, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, delete, *args, **kwargs)
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, certificate_body: Text, user_name: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Uploads an X.509 signing certificate and associates it with the specified IAM user. Some Amazon Web Services
    services require you to use certificates to validate requests that are signed with a corresponding private key.
    When you upload the certificate, its default status is Active. For information about when you would use an X.509
    signing certificate, see Managing server certificates in IAM in the IAM User Guide. If the UserName is not
    specified, the IAM user name is determined implicitly based on the Amazon Web Services access key ID used to
    sign the request. This operation works for access keys under the account. Consequently, you can use this
    operation to manage account root user credentials even if the account has no associated users.  Because the body
    of an X.509 certificate can be large, you should use POST rather than GET when calling UploadSigningCertificate.
    For information about setting up signatures and authorization through the API, see Signing Amazon Web Services
    API requests in the Amazon Web Services General Reference. For general information about using the Query API
    with IAM, see Making query requests in the IAM User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        user_name(Text, optional): The name of the user the signing certificate is for. 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: _+=,.@-. Defaults to None.
        certificate_body(Text): The contents of the signing certificate. The regex pattern used to validate this parameter is a
            string of characters consisting of the following:   Any printable ASCII character ranging from
            the space character (\u0020) through the end of the ASCII character range   The printable
            characters in the Basic Latin and Latin-1 Supplement character set (through \u00FF)   The
            special characters tab (\u0009), line feed (\u000A), and carriage return (\u000D).

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.iam.signing_certificate.present:
                - name: value
                - certificate_body: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iam.signing_certificate.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", "SigningCertificate", 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.upload_signing_certificate(
                ctx,
                
                
                **{"UserName": user_name, "CertificateBody": certificate_body}
            )
            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, certificate_id: Text, user_name: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a signing certificate associated with the specified IAM user. If you do not specify a user name, IAM
    determines the user name implicitly based on the Amazon Web Services access key ID signing the request. This
    operation works for access keys under the account. Consequently, you can use this operation to manage account
    root user credentials even if the account has no associated IAM users.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        user_name(Text, optional): The name of the user the signing certificate belongs to. 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: _+=,.@-. Defaults to None.
        certificate_id(Text): The ID of the signing certificate to delete. The format of this parameter, as described by its
            regex pattern, is a string of characters that can be upper- or lower-cased letters or digits.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.iam.signing_certificate.absent:
                - name: value
                - certificate_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iam.signing_certificate.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", "SigningCertificate", 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_signing_certificate(
                ctx,
                
                
                **{"UserName": user_name, "CertificateId": certificate_id}
            )
            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

