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

hub.exec.boto3.client.kms.connect_custom_key_store
hub.exec.boto3.client.kms.create_custom_key_store
hub.exec.boto3.client.kms.delete_custom_key_store
hub.exec.boto3.client.kms.describe_custom_key_stores
hub.exec.boto3.client.kms.disconnect_custom_key_store
hub.exec.boto3.client.kms.update_custom_key_store
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, custom_key_store_name: Text, cloud_hsm_cluster_id: Text, trust_anchor_certificate: Text, key_store_password: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a custom key store that is associated with an AWS CloudHSM cluster that you own and manage. This
    operation is part of the Custom Key Store feature feature in AWS KMS, which combines the convenience and
    extensive integration of AWS KMS with the isolation and control of a single-tenant key store. Before you create
    the custom key store, you must assemble the required elements, including an AWS CloudHSM cluster that fulfills
    the requirements for a custom key store. For details about the required elements, see Assemble the Prerequisites
    in the AWS Key Management Service Developer Guide. When the operation completes successfully, it returns the ID
    of the new custom key store. Before you can use your new custom key store, you need to use the
    ConnectCustomKeyStore operation to connect the new key store to its AWS CloudHSM cluster. Even if you are not
    going to use your custom key store immediately, you might want to connect it to verify that all settings are
    correct and then disconnect it until you are ready to use it. For help with failures, see Troubleshooting a
    Custom Key Store in the AWS Key Management Service Developer Guide.  Cross-account use: No. You cannot perform
    this operation on a custom key store in a different AWS account.  Required permissions: kms:CreateCustomKeyStore
    (IAM policy).  Related operations:     ConnectCustomKeyStore     DeleteCustomKeyStore
    DescribeCustomKeyStores     DisconnectCustomKeyStore     UpdateCustomKeyStore

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        custom_key_store_name(Text): Specifies a friendly name for the custom key store. The name must be unique in your AWS account.
        cloud_hsm_cluster_id(Text): Identifies the AWS CloudHSM cluster for the custom key store. Enter the cluster ID of any active
            AWS CloudHSM cluster that is not already associated with a custom key store. To find the cluster
            ID, use the DescribeClusters operation.
        trust_anchor_certificate(Text): Enter the content of the trust anchor certificate for the cluster. This is the content of the
            customerCA.crt file that you created when you initialized the cluster.
        key_store_password(Text): Enter the password of the  kmsuser crypto user (CU) account in the specified AWS CloudHSM
            cluster. AWS KMS logs into the cluster as this user to manage key material on your behalf. The
            password must be a string of 7 to 32 characters. Its value is case sensitive. This parameter
            tells AWS KMS the kmsuser account password; it does not change the password in the AWS CloudHSM
            cluster.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.kms.custom_key_store.present:
                - name: value
                - custom_key_store_name: value
                - cloud_hsm_cluster_id: value
                - trust_anchor_certificate: value
                - key_store_password: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.kms.custom_key_store.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.kms.describe_custom_key_stores(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.kms.create_custom_key_store(
                ctx,
                
                
                **{"CustomKeyStoreName": custom_key_store_name, "CloudHsmClusterId": cloud_hsm_cluster_id, "TrustAnchorCertificate": trust_anchor_certificate, "KeyStorePassword": key_store_password}
            )
            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.kms.describe_custom_key_stores(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, custom_key_store_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a custom key store. This operation does not delete the AWS CloudHSM cluster that is associated with the
    custom key store, or affect any users or keys in the cluster. The custom key store that you delete cannot
    contain any AWS KMS customer master keys (CMKs). Before deleting the key store, verify that you will never need
    to use any of the CMKs in the key store for any cryptographic operations. Then, use ScheduleKeyDeletion to
    delete the AWS KMS customer master keys (CMKs) from the key store. When the scheduled waiting period expires,
    the ScheduleKeyDeletion operation deletes the CMKs. Then it makes a best effort to delete the key material from
    the associated cluster. However, you might need to manually delete the orphaned key material from the cluster
    and its backups. After all CMKs are deleted from AWS KMS, use DisconnectCustomKeyStore to disconnect the key
    store from AWS KMS. Then, you can delete the custom key store. Instead of deleting the custom key store,
    consider using DisconnectCustomKeyStore to disconnect it from AWS KMS. While the key store is disconnected, you
    cannot create or use the CMKs in the key store. But, you do not need to delete CMKs and you can reconnect a
    disconnected custom key store at any time. If the operation succeeds, it returns a JSON object with no
    properties. This operation is part of the Custom Key Store feature feature in AWS KMS, which combines the
    convenience and extensive integration of AWS KMS with the isolation and control of a single-tenant key store.
    Cross-account use: No. You cannot perform this operation on a custom key store in a different AWS account.
    Required permissions: kms:DeleteCustomKeyStore (IAM policy)  Related operations:     ConnectCustomKeyStore
    CreateCustomKeyStore     DescribeCustomKeyStores     DisconnectCustomKeyStore     UpdateCustomKeyStore

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        custom_key_store_id(Text): Enter the ID of the custom key store you want to delete. To find the ID of a custom key store,
            use the DescribeCustomKeyStores operation.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.kms.custom_key_store.absent:
                - name: value
                - custom_key_store_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.kms.custom_key_store.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.kms.describe_custom_key_stores(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.kms.delete_custom_key_store(
                ctx,
                
                
                **{"CustomKeyStoreId": custom_key_store_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.kms.describe_custom_key_stores(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

