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

hub.exec.boto3.client.s3.copy_object
hub.exec.boto3.client.s3.delete_objects
hub.exec.boto3.client.s3.get_object
hub.exec.boto3.client.s3.head_object
hub.exec.boto3.client.s3.list_objects
hub.exec.boto3.client.s3.put_object
hub.exec.boto3.client.s3.restore_object
resource = hub.tool.boto3.resource.create(ctx, "s3", "Object", name)
hub.tool.boto3.resource.exec(resource, copy_from, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, delete, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, get, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, initiate_multipart_upload, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, put, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, restore_object, *args, **kwargs)
"""



from typing import *
import dict_tools.differ as differ


__virtualname__ = "object"
async def present(hub, ctx, name: Text, bucket: Text, key: Text, acl: Text = None, body: ByteString = None, cache_control: Text = None, content_disposition: Text = None, content_encoding: Text = None, content_language: Text = None, content_length: int = None, content_md5: Text = None, content_type: Text = None, expires: Text = None, grant_full_control: Text = None, grant_read: Text = None, grant_read_acp: Text = None, grant_write_acp: Text = None, metadata: Dict = None, server_side_encryption: Text = None, storage_class: Text = None, website_redirect_location: Text = None, sse_customer_algorithm: Text = None, sse_customer_key: Text = None, sse_customer_key_md5: Text = None, ssekms_key_id: Text = None, ssekms_encryption_context: Text = None, bucket_key_enabled: bool = None, request_payer: Text = None, tagging: Text = None, object_lock_mode: Text = None, object_lock_retain_until_date: Text = None, object_lock_legal_hold_status: Text = None, expected_bucket_owner: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Adds an object to a bucket. You must have WRITE permissions on a bucket to add an object to it. Amazon S3 never
    adds partial objects; if you receive a success response, Amazon S3 added the entire object to the bucket. Amazon
    S3 is a distributed system. If it receives multiple write requests for the same object simultaneously, it
    overwrites all but the last object written. Amazon S3 does not provide object locking; if you need this, make
    sure to build it into your application layer or use versioning instead. To ensure that data is not corrupted
    traversing the network, use the Content-MD5 header. When you use this header, Amazon S3 checks the object
    against the provided MD5 value and, if they do not match, returns an error. Additionally, you can calculate the
    MD5 while putting an object to Amazon S3 and compare the returned ETag to the calculated MD5 value.    To
    successfully complete the PutObject request, you must have the s3:PutObject in your IAM permissions.   To
    successfully change the objects acl of your PutObject request, you must have the s3:PutObjectAcl in your IAM
    permissions.    The Content-MD5 header is required for any request to upload an object with a retention period
    configured using Amazon S3 Object Lock. For more information about Amazon S3 Object Lock, see Amazon S3 Object
    Lock Overview in the Amazon S3 User Guide.      Server-side Encryption  You can optionally request server-side
    encryption. With server-side encryption, Amazon S3 encrypts your data as it writes it to disks in its data
    centers and decrypts the data when you access it. You have the option to provide your own encryption key or use
    Amazon Web Services managed encryption keys (SSE-S3 or SSE-KMS). For more information, see Using Server-Side
    Encryption. If you request server-side encryption using Amazon Web Services Key Management Service (SSE-KMS),
    you can enable an S3 Bucket Key at the object-level. For more information, see Amazon S3 Bucket Keys in the
    Amazon S3 User Guide.  Access Control List (ACL)-Specific Request Headers  You can use headers to grant ACL-
    based permissions. By default, all objects are private. Only the owner has full access control. When adding a
    new object, you can grant permissions to individual Amazon Web Services accounts or to predefined groups defined
    by Amazon S3. These permissions are then added to the ACL on the object. For more information, see Access
    Control List (ACL) Overview and Managing ACLs Using the REST API.   Storage Class Options  By default, Amazon S3
    uses the STANDARD Storage Class to store newly created objects. The STANDARD storage class provides high
    durability and high availability. Depending on performance needs, you can specify a different Storage Class.
    Amazon S3 on Outposts only uses the OUTPOSTS Storage Class. For more information, see Storage Classes in the
    Amazon S3 User Guide.  Versioning  If you enable versioning for a bucket, Amazon S3 automatically generates a
    unique version ID for the object being stored. Amazon S3 returns this ID in the response. When you enable
    versioning for a bucket, if Amazon S3 receives multiple write requests for the same object simultaneously, it
    stores all of the objects. For more information about versioning, see Adding Objects to Versioning Enabled
    Buckets. For information about returning the versioning state of a bucket, see GetBucketVersioning.   Related
    Resources     CopyObject     DeleteObject

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        acl(Text, optional): The canned ACL to apply to the object. For more information, see Canned ACL. This action is not
            supported by Amazon S3 on Outposts. Defaults to None.
        body(ByteString, optional): Object data. Defaults to None.
        bucket(Text): The bucket name to which the PUT action was initiated.  When using this action with an access
            point, you must direct requests to the access point hostname. The access point hostname takes
            the form AccessPointName-AccountId.s3-accesspoint.Region.amazonaws.com. When using this action
            with an access point through the Amazon Web Services SDKs, you provide the access point ARN in
            place of the bucket name. For more information about access point ARNs, see Using access points
            in the Amazon S3 User Guide. When using this action with Amazon S3 on Outposts, you must direct
            requests to the S3 on Outposts hostname. The S3 on Outposts hostname takes the form
            AccessPointName-AccountId.outpostID.s3-outposts.Region.amazonaws.com. When using this action
            using S3 on Outposts through the Amazon Web Services SDKs, you provide the Outposts bucket ARN
            in place of the bucket name. For more information about S3 on Outposts ARNs, see Using S3 on
            Outposts in the Amazon S3 User Guide.
        cache_control(Text, optional):  Can be used to specify caching behavior along the request/reply chain. For more information,
            see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9. Defaults to None.
        content_disposition(Text, optional): Specifies presentational information for the object. For more information, see
            http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1. Defaults to None.
        content_encoding(Text, optional): Specifies what content encodings have been applied to the object and thus what decoding
            mechanisms must be applied to obtain the media-type referenced by the Content-Type header field.
            For more information, see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11. Defaults to None.
        content_language(Text, optional): The language the content is in. Defaults to None.
        content_length(int, optional): Size of the body in bytes. This parameter is useful when the size of the body cannot be
            determined automatically. For more information, see
            http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13. Defaults to None.
        content_md5(Text, optional): The base64-encoded 128-bit MD5 digest of the message (without the headers) according to RFC
            1864. This header can be used as a message integrity check to verify that the data is the same
            data that was originally sent. Although it is optional, we recommend using the Content-MD5
            mechanism as an end-to-end integrity check. For more information about REST request
            authentication, see REST Authentication. Defaults to None.
        content_type(Text, optional): A standard MIME type describing the format of the contents. For more information, see
            http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17. Defaults to None.
        expires(Text, optional): The date and time at which the object is no longer cacheable. For more information, see
            http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21. Defaults to None.
        grant_full_control(Text, optional): Gives the grantee READ, READ_ACP, and WRITE_ACP permissions on the object. This action is not
            supported by Amazon S3 on Outposts. Defaults to None.
        grant_read(Text, optional): Allows grantee to read the object data and its metadata. This action is not supported by Amazon
            S3 on Outposts. Defaults to None.
        grant_read_acp(Text, optional): Allows grantee to read the object ACL. This action is not supported by Amazon S3 on Outposts. Defaults to None.
        grant_write_acp(Text, optional): Allows grantee to write the ACL for the applicable object. This action is not supported by
            Amazon S3 on Outposts. Defaults to None.
        key(Text): Object key for which the PUT action was initiated.
        metadata(Dict, optional): A map of metadata to store with the object in S3. Defaults to None.
        server_side_encryption(Text, optional): The server-side encryption algorithm used when storing this object in Amazon S3 (for example,
            AES256, aws:kms). Defaults to None.
        storage_class(Text, optional): By default, Amazon S3 uses the STANDARD Storage Class to store newly created objects. The
            STANDARD storage class provides high durability and high availability. Depending on performance
            needs, you can specify a different Storage Class. Amazon S3 on Outposts only uses the OUTPOSTS
            Storage Class. For more information, see Storage Classes in the Amazon S3 User Guide. Defaults to None.
        website_redirect_location(Text, optional): If the bucket is configured as a website, redirects requests for this object to another object
            in the same bucket or to an external URL. Amazon S3 stores the value of this header in the
            object metadata. For information about object metadata, see Object Key and Metadata. In the
            following example, the request header sets the redirect to an object (anotherPage.html) in the
            same bucket:  x-amz-website-redirect-location: /anotherPage.html  In the following example, the
            request header sets the object redirect to another website:  x-amz-website-redirect-location:
            http://www.example.com/  For more information about website hosting in Amazon S3, see Hosting
            Websites on Amazon S3 and How to Configure Website Page Redirects. Defaults to None.
        sse_customer_algorithm(Text, optional): Specifies the algorithm to use to when encrypting the object (for example, AES256). Defaults to None.
        sse_customer_key(Text, optional): Specifies the customer-provided encryption key for Amazon S3 to use in encrypting data. This
            value is used to store the object and then it is discarded; Amazon S3 does not store the
            encryption key. The key must be appropriate for use with the algorithm specified in the x-amz-
            server-side-encryption-customer-algorithm header. Defaults to None.
        sse_customer_key_md5(Text, optional): Specifies the 128-bit MD5 digest of the encryption key according to RFC 1321. Amazon S3 uses
            this header for a message integrity check to ensure that the encryption key was transmitted
            without error. Defaults to None.
        ssekms_key_id(Text, optional): If x-amz-server-side-encryption is present and has the value of aws:kms, this header specifies
            the ID of the Amazon Web Services Key Management Service (Amazon Web Services KMS) symmetrical
            customer managed customer master key (CMK) that was used for the object. If you specify x-amz-
            server-side-encryption:aws:kms, but do not provide x-amz-server-side-encryption-aws-kms-key-id,
            Amazon S3 uses the Amazon Web Services managed CMK in Amazon Web Services to protect the data.
            If the KMS key does not exist in the same account issuing the command, you must use the full ARN
            and not just the ID. Defaults to None.
        ssekms_encryption_context(Text, optional): Specifies the Amazon Web Services KMS Encryption Context to use for object encryption. The value
            of this header is a base64-encoded UTF-8 string holding JSON with the encryption context key-
            value pairs. Defaults to None.
        bucket_key_enabled(bool, optional): Specifies whether Amazon S3 should use an S3 Bucket Key for object encryption with server-side
            encryption using AWS KMS (SSE-KMS). Setting this header to true causes Amazon S3 to use an S3
            Bucket Key for object encryption with SSE-KMS. Specifying this header with a PUT action doesn’t
            affect bucket-level settings for S3 Bucket Key. Defaults to None.
        request_payer(Text, optional): Confirms that the requester knows that they will be charged for the request. Bucket owners need
            not specify this parameter in their requests. For information about downloading objects from
            requester pays buckets, see Downloading Objects in Requestor Pays Buckets in the Amazon S3 User
            Guide. Defaults to None.
        tagging(Text, optional): The tag-set for the object. The tag-set must be encoded as URL Query parameters. (For example,
            "Key1=Value1"). Defaults to None.
        object_lock_mode(Text, optional): The Object Lock mode that you want to apply to this object. Defaults to None.
        object_lock_retain_until_date(Text, optional): The date and time when you want this object's Object Lock to expire. Must be formatted as a
            timestamp parameter. Defaults to None.
        object_lock_legal_hold_status(Text, optional): Specifies whether a legal hold will be applied to this object. For more information about S3
            Object Lock, see Object Lock. Defaults to None.
        expected_bucket_owner(Text, optional): The account ID of the expected bucket owner. If the bucket is owned by a different account, the
            request will fail with an HTTP 403 (Access Denied) error. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.s3.object_.present:
                - name: value
                - bucket: value
                - key: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.s3.object.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, "s3", "Object", 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.s3.put_object(
                ctx,
                
                
                **{"ACL": acl, "Body": body, "Bucket": bucket, "CacheControl": cache_control, "ContentDisposition": content_disposition, "ContentEncoding": content_encoding, "ContentLanguage": content_language, "ContentLength": content_length, "ContentMD5": content_md5, "ContentType": content_type, "Expires": expires, "GrantFullControl": grant_full_control, "GrantRead": grant_read, "GrantReadACP": grant_read_acp, "GrantWriteACP": grant_write_acp, "Key": key, "Metadata": metadata, "ServerSideEncryption": server_side_encryption, "StorageClass": storage_class, "WebsiteRedirectLocation": website_redirect_location, "SSECustomerAlgorithm": sse_customer_algorithm, "SSECustomerKey": sse_customer_key, "SSECustomerKeyMD5": sse_customer_key_md5, "SSEKMSKeyId": ssekms_key_id, "SSEKMSEncryptionContext": ssekms_encryption_context, "BucketKeyEnabled": bucket_key_enabled, "RequestPayer": request_payer, "Tagging": tagging, "ObjectLockMode": object_lock_mode, "ObjectLockRetainUntilDate": object_lock_retain_until_date, "ObjectLockLegalHoldStatus": object_lock_legal_hold_status, "ExpectedBucketOwner": expected_bucket_owner}
            )
            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, bucket: Text, delete: Dict, mfa: Text = None, request_payer: Text = None, bypass_governance_retention: bool = None, expected_bucket_owner: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    This action enables you to delete multiple objects from a bucket using a single HTTP request. If you know the
    object keys that you want to delete, then this action provides a suitable alternative to sending individual
    delete requests, reducing per-request overhead. The request contains a list of up to 1000 keys that you want to
    delete. In the XML, you provide the object key names, and optionally, version IDs if you want to delete a
    specific version of the object from a versioning-enabled bucket. For each key, Amazon S3 performs a delete
    action and returns the result of that delete, success, or failure, in the response. Note that if the object
    specified in the request is not found, Amazon S3 returns the result as deleted.  The action supports two modes
    for the response: verbose and quiet. By default, the action uses verbose mode in which the response includes the
    result of deletion of each key in your request. In quiet mode the response includes only keys where the delete
    action encountered an error. For a successful deletion, the action does not return any information about the
    delete in the response body. When performing this action on an MFA Delete enabled bucket, that attempts to
    delete any versioned objects, you must include an MFA token. If you do not provide one, the entire request will
    fail, even if there are non-versioned objects you are trying to delete. If you provide an invalid token, whether
    there are versioned keys in the request or not, the entire Multi-Object Delete request will fail. For
    information about MFA Delete, see  MFA Delete. Finally, the Content-MD5 header is required for all Multi-Object
    Delete requests. Amazon S3 uses the header value to ensure that your request body has not been altered in
    transit. The following operations are related to DeleteObjects:    CreateMultipartUpload     UploadPart
    CompleteMultipartUpload     ListParts     AbortMultipartUpload

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        bucket(Text): The bucket name containing the objects to delete.  When using this action with an access point,
            you must direct requests to the access point hostname. The access point hostname takes the form
            AccessPointName-AccountId.s3-accesspoint.Region.amazonaws.com. When using this action with an
            access point through the Amazon Web Services SDKs, you provide the access point ARN in place of
            the bucket name. For more information about access point ARNs, see Using access points in the
            Amazon S3 User Guide. When using this action with Amazon S3 on Outposts, you must direct
            requests to the S3 on Outposts hostname. The S3 on Outposts hostname takes the form
            AccessPointName-AccountId.outpostID.s3-outposts.Region.amazonaws.com. When using this action
            using S3 on Outposts through the Amazon Web Services SDKs, you provide the Outposts bucket ARN
            in place of the bucket name. For more information about S3 on Outposts ARNs, see Using S3 on
            Outposts in the Amazon S3 User Guide.
        delete(Dict): Container for the request.
        mfa(Text, optional): The concatenation of the authentication device's serial number, a space, and the value that is
            displayed on your authentication device. Required to permanently delete a versioned object if
            versioning is configured with MFA delete enabled. Defaults to None.
        request_payer(Text, optional): Confirms that the requester knows that they will be charged for the request. Bucket owners need
            not specify this parameter in their requests. For information about downloading objects from
            requester pays buckets, see Downloading Objects in Requestor Pays Buckets in the Amazon S3 User
            Guide. Defaults to None.
        bypass_governance_retention(bool, optional): Specifies whether you want to delete this object even if it has a Governance-type Object Lock in
            place. You must have sufficient permissions to perform this operation. Defaults to None.
        expected_bucket_owner(Text, optional): The account ID of the expected bucket owner. If the bucket is owned by a different account, the
            request will fail with an HTTP 403 (Access Denied) error. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.s3.object_.absent:
                - name: value
                - bucket: value
                - delete: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.s3.object.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, "s3", "Object", 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.s3.delete_objects(
                ctx,
                
                
                **{"Bucket": bucket, "Delete": delete, "MFA": mfa, "RequestPayer": request_payer, "BypassGovernanceRetention": bypass_governance_retention, "ExpectedBucketOwner": expected_bucket_owner}
            )
            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

