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

hub.exec.boto3.client.iam.delete_ssh_public_key
hub.exec.boto3.client.iam.get_ssh_public_key
hub.exec.boto3.client.iam.list_ssh_public_keys
hub.exec.boto3.client.iam.update_ssh_public_key
hub.exec.boto3.client.iam.upload_ssh_public_key
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, user_name: Text, ssh_public_key_body: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Uploads an SSH public key and associates it with the specified IAM user. The SSH public key uploaded by this
    operation can be used only for authenticating the associated IAM user to an CodeCommit repository. For more
    information about using SSH keys to authenticate to an CodeCommit repository, see Set up CodeCommit for SSH
    connections in the CodeCommit User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        user_name(Text): The name of the IAM user to associate the SSH public key with. 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: _+=,.@-.
        ssh_public_key_body(Text): The SSH public key. The public key must be encoded in ssh-rsa format or PEM format. The minimum
            bit-length of the public key is 2048 bits. For example, you can generate a 2048-bit key, and the
            resulting PEM file is 1679 bytes long. 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.ssh_public_key.present:
                - name: value
                - user_name: value
                - ssh_public_key_body: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iam.ssh_public_key.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    
    before = await hub.exec.boto3.client.iam.get_ssh_public_key(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iam.upload_ssh_public_key(
                ctx,
                
                
                **{"UserName": user_name, "SSHPublicKeyBody": ssh_public_key_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.exec.boto3.client.iam.get_ssh_public_key(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, user_name: Text, ssh_public_key_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified SSH public key. The SSH public key deleted by this operation is used only for
    authenticating the associated IAM user to an CodeCommit repository. For more information about using SSH keys to
    authenticate to an CodeCommit repository, see Set up CodeCommit for SSH connections in the CodeCommit User
    Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        user_name(Text): The name of the IAM user associated with the SSH public key. 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: _+=,.@-.
        ssh_public_key_id(Text): The unique identifier for the SSH public key. This parameter allows (through its regex pattern)
            a string of characters that can consist of any upper or lowercased letter or digit.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    

    before = await hub.exec.boto3.client.iam.get_ssh_public_key(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.iam.delete_ssh_public_key(
                ctx,
                
                
                **{"UserName": user_name, "SSHPublicKeyId": ssh_public_key_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.exec.boto3.client.iam.get_ssh_public_key(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

