o .&aY@sddlZddlmZddlZddlZddlZddlmZddlm Z e dZ dZ dZ dZd Zd Zd d Zd dZdZddZddZddZdefdefdefgZddZGddde ZdS)N)sha1)six)CustomArgumentec2bundleinstancezThe bucket in which to store the AMI. You can specify a bucket that you already own or a new bucket that Amazon EC2 creates on your behalf. If you specify a bucket that belongs to someone else, Amazon EC2 returns an error.zCThe prefix for the image component names being stored in Amazon S3.z7The access key ID of the owner of the Amazon S3 bucket.acAn Amazon S3 upload policy that gives Amazon EC2 permission to upload items into Amazon S3 on the user's behalf. If you provide this parameter, you must also provide your secret access key, so we can create a policy signature for you (the secret access key is not passed to Amazon EC2). If you do not provide this parameter, we generate an upload policy for you automatically. For more information about upload policies see the sections about policy construction and signatures in the Amazon Simple Storage Service Developer Guide.zThe AWS secret access key for the owner of the Amazon S3 bucket specified in the --bucket parameter. This parameter is required so that a signature can be computed for the policy.cKs|d}d|_tddtd}||d<tddtd}||d<tdd td}||d <td d td}||d <td d td}||d <dS)NstorageFBucketbucket) storage_paramname help_textPrefixprefixAWSAccessKeyIdz owner-akid_SAKz owner-sak UploadPolicypolicy)requiredBundleArgument BUCKET_DOCS PREFIX_DOCSOWNER_AKID_DOCSOWNER_SAK_DOCS POLICY_DOCS)argument_tablekwargs storage_argargrJ/usr/lib/python3/dist-packages/awscli/customizations/ec2/bundleinstance.py _add_paramsBs6 rcKs@t|t|}|drdD]}||rd}t|qdSdS)Nr)rr owner_akid owner_sakrzOMixing the --storage option with the simple, scalar options is not recommended.)loggerdebugvars ValueError) parsed_argsrarg_dictkeymsgrrr _check_args^s r*z{{"expiration": "{expires}","conditions": [{{"bucket": "{bucket}"}},{{"acl": "ec2-bundle-read"}},["starts-with", "$key", "{prefix}"]]}}cCsHtjdd}tj|}|d}tj||d|dd}||d<dS)N)hoursz%Y-%m-%dT%H:%M:%S.%fZrr )expiresrr r)datetime timedeltautcnowstrftimePOLICYformat)paramsdeltar- expires_isorrrr_generate_policyvs   r7cCs|d}|d}|r@|rBtt|d}tj|dt d}| t|t |  d}||d<|d=dSdSdS)Nrrzutf-8) digestmodUploadPolicySignature)getbase64 b64encoderbdecodehmacnewencoderupdate encodebytesdigeststrip)r4rsaknew_hmacpsrrr_generate_signatures   rIcKs4|dd}d|vrt|d|vrt|dSdS)NStorageS3rr9)r7rI)r4rrrrr _check_paramss  rLz+building-argument-table.ec2.bundle-instancez)operation-args-parsed.ec2.bundle-instancez)before-parameter-build.ec2.BundleInstancecCstD] \}}|||qdSN)EVENTSregister) event_handlereventhandlerrrrregister_bundleinstances rScs,eZdZfddZddZddZZS)rcs tt|j|i|||_dSrM)superr__init___storage_param)selfr argsr __class__rrrUs zBundleArgument.__init__cCs*d|vr dii|d<||dd|j<dS)NrJrK)rV)rWr4valuerrr_build_storages zBundleArgument._build_storagecCs|r |||dSdSrM)r\)rW parametersr[rrr add_to_paramsszBundleArgument.add_to_params)__name__ __module__ __qualname__rUr\r^ __classcell__rrrYrrs r)logginghashlibrr?r;r. awscli.compatrawscli.argumentsr getLoggerr"rrrrrrr*r2r7rIrLrNrSrrrrrs4