<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import logging <EOL> from distutils . version import LooseVersion as _LooseVersion <EOL> import json <EOL> import salt . utils . compat <EOL> import salt . utils <EOL> from salt . ext . six import string_types <EOL> log = logging . getLogger ( __name__ ) <EOL> try : <EOL> import boto <EOL> import boto3 <EOL> from botocore . exceptions import ClientError <EOL> logging . getLogger ( '<STR_LIT>' ) . setLevel ( logging . CRITICAL ) <EOL> HAS_BOTO = True <EOL> except ImportError : <EOL> HAS_BOTO = False <EOL> def __virtual__ ( ) : <EOL> '''<STR_LIT>''' <EOL> required_boto3_version = '<STR_LIT>' <EOL> if not HAS_BOTO : <EOL> return False <EOL> elif _LooseVersion ( boto3 . __version__ ) < _LooseVersion ( required_boto3_version ) : <EOL> return False <EOL> else : <EOL> return True <EOL> def __init__ ( opts ) : <EOL> salt . utils . compat . pack_dunder ( __name__ ) <EOL> if HAS_BOTO : <EOL> __utils__ [ '<STR_LIT>' ] ( __name__ , '<STR_LIT>' ) <EOL> def exists ( Bucket , <EOL> region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> buckets = conn . head_bucket ( Bucket = Bucket ) <EOL> return { '<STR_LIT>' : True } <EOL> except ClientError as e : <EOL> if e . response . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> return { '<STR_LIT>' : False } <EOL> err = __utils__ [ '<STR_LIT>' ] ( e ) <EOL> return { '<STR_LIT:error>' : err } <EOL> def create ( Bucket , <EOL> ACL = None , LocationConstraint = None , <EOL> GrantFullControl = None , <EOL> GrantRead = None , <EOL> GrantReadACP = None , <EOL> GrantWrite = None , <EOL> GrantWriteACP = None , <EOL> region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> kwargs = { } <EOL> for arg in ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if locals ( ) [ arg ] is not None : <EOL> kwargs [ arg ] = str ( locals ( ) [ arg ] ) <EOL> if LocationConstraint : <EOL> kwargs [ '<STR_LIT>' ] = { '<STR_LIT>' : LocationConstraint } <EOL> location = conn . create_bucket ( Bucket = Bucket , <EOL> ** kwargs ) <EOL> if location : <EOL> log . info ( '<STR_LIT>' . format ( location [ '<STR_LIT>' ] ) ) <EOL> return { '<STR_LIT>' : True , '<STR_LIT:name>' : Bucket , '<STR_LIT>' : location [ '<STR_LIT>' ] } <EOL> else : <EOL> log . warning ( '<STR_LIT>' ) <EOL> return { '<STR_LIT>' : False } <EOL> except ClientError as e : <EOL> return { '<STR_LIT>' : False , '<STR_LIT:error>' : __utils__ [ '<STR_LIT>' ] ( e ) } <EOL> def delete ( Bucket , <EOL> region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> conn . delete_bucket ( Bucket = Bucket ) <EOL> return { '<STR_LIT>' : True } <EOL> except ClientError as e : <EOL> return { '<STR_LIT>' : False , '<STR_LIT:error>' : __utils__ [ '<STR_LIT>' ] ( e ) } <EOL> def describe ( Bucket , <EOL> region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> result = { } <EOL> for key , query in { <EOL> '<STR_LIT>' : conn . get_bucket_acl , <EOL> '<STR_LIT>' : conn . get_bucket_cors , <EOL> '<STR_LIT>' : conn . get_bucket_lifecycle_configuration , <EOL> '<STR_LIT>' : conn . get_bucket_location , <EOL> '<STR_LIT>' : conn . get_bucket_logging , <EOL> '<STR_LIT>' : conn . get_bucket_notification_configuration , <EOL> '<STR_LIT>' : conn . get_bucket_policy , <EOL> '<STR_LIT>' : conn . get_bucket_replication , <EOL> '<STR_LIT>' : conn . get_bucket_request_payment , <EOL> '<STR_LIT>' : conn . get_bucket_versioning , <EOL> '<STR_LIT>' : conn . get_bucket_website } . iteritems ( ) : <EOL> try : <EOL> data = query ( Bucket = Bucket ) <EOL> except ClientError as e : <EOL> if e . response . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' ) in ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) : <EOL> continue <EOL> raise <EOL> if '<STR_LIT>' in data : <EOL> del data [ '<STR_LIT>' ] <EOL> result [ key ] = data <EOL> tags = { } <EOL> try : <EOL> data = conn . get_bucket_tagging ( Bucket = Bucket ) <EOL> for tagdef in data . get ( '<STR_LIT>' ) : <EOL> tags [ tagdef . get ( '<STR_LIT>' ) ] = tagdef . get ( '<STR_LIT>' ) <EOL> except ClientError as e : <EOL> if not e . response . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> raise <EOL> if tags : <EOL> result [ '<STR_LIT>' ] = tags <EOL> return { '<STR_LIT>' : result } <EOL> except ClientError as e : <EOL> err = __utils__ [ '<STR_LIT>' ] ( e ) <EOL> if e . response . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> return { '<STR_LIT>' : None } <EOL> return { '<STR_LIT:error>' : __utils__ [ '<STR_LIT>' ] ( e ) } <EOL> def list ( region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> buckets = conn . list_buckets ( ) <EOL> if not bool ( buckets . get ( '<STR_LIT>' ) ) : <EOL> log . warning ( '<STR_LIT>' ) <EOL> del buckets [ '<STR_LIT>' ] <EOL> return buckets <EOL> except ClientError as e : <EOL> return { '<STR_LIT:error>' : __utils__ [ '<STR_LIT>' ] ( e ) } <EOL> def put_acl ( Bucket , <EOL> ACL = None , <EOL> AccessControlPolicy = None , <EOL> GrantFullControl = None , <EOL> GrantRead = None , <EOL> GrantReadACP = None , <EOL> GrantWrite = None , <EOL> GrantWriteACP = None , <EOL> region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> kwargs = { } <EOL> if AccessControlPolicy is not None : <EOL> if isinstance ( AccessControlPolicy , string_types ) : <EOL> AccessControlPolicy = json . loads ( AccessControlPolicy ) <EOL> kwargs [ '<STR_LIT>' ] = AccessControlPolicy <EOL> for arg in ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if locals ( ) [ arg ] is not None : <EOL> kwargs [ arg ] = str ( locals ( ) [ arg ] ) <EOL> conn . put_bucket_acl ( Bucket = Bucket , ** kwargs ) <EOL> return { '<STR_LIT>' : True , '<STR_LIT:name>' : Bucket } <EOL> except ClientError as e : <EOL> return { '<STR_LIT>' : False , '<STR_LIT:error>' : __utils__ [ '<STR_LIT>' ] ( e ) } <EOL> def put_cors ( Bucket , <EOL> CORSRules , <EOL> region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> if CORSRules is not None and isinstance ( CORSRules , string_types ) : <EOL> CORSRules = json . loads ( CORSRules ) <EOL> conn . put_bucket_cors ( Bucket = Bucket , CORSConfiguration = { '<STR_LIT>' : CORSRules } ) <EOL> return { '<STR_LIT>' : True , '<STR_LIT:name>' : Bucket } <EOL> except ClientError as e : <EOL> return { '<STR_LIT>' : False , '<STR_LIT:error>' : __utils__ [ '<STR_LIT>' ] ( e ) } <EOL> def put_lifecycle_configuration ( Bucket , <EOL> Rules , <EOL> region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> if Rules is not None and isinstance ( Rules , string_types ) : <EOL> Rules = json . loads ( Rules ) <EOL> conn . put_bucket_lifecycle_configuration ( Bucket = Bucket , LifecycleConfiguration = { '<STR_LIT>' : Rules } ) <EOL> return { '<STR_LIT>' : True , '<STR_LIT:name>' : Bucket } <EOL> except ClientError as e : <EOL> return { '<STR_LIT>' : False , '<STR_LIT:error>' : __utils__ [ '<STR_LIT>' ] ( e ) } <EOL> def put_logging ( Bucket , <EOL> TargetBucket = None , TargetPrefix = None , TargetGrants = None , <EOL> region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> logstate = { } <EOL> for key , val in { <EOL> '<STR_LIT>' : TargetBucket , <EOL> '<STR_LIT>' : TargetGrants , <EOL> '<STR_LIT>' : TargetPrefix , <EOL> } . iteritems ( ) : <EOL> if val is not None : <EOL> logstate [ key ] = val <EOL> if logstate : <EOL> logstatus = { '<STR_LIT>' : logstate } <EOL> else : <EOL> logstatus = { } <EOL> if TargetGrants is not None and isinstance ( TargetGrants , string_types ) : <EOL> TargetGrants = json . loads ( TargetGrants ) <EOL> conn . put_bucket_logging ( Bucket = Bucket , BucketLoggingStatus = logstatus ) <EOL> return { '<STR_LIT>' : True , '<STR_LIT:name>' : Bucket } <EOL> except ClientError as e : <EOL> return { '<STR_LIT>' : False , '<STR_LIT:error>' : __utils__ [ '<STR_LIT>' ] ( e ) } <EOL> def put_notification_configuration ( Bucket , <EOL> TopicConfigurations = None , QueueConfigurations = None , <EOL> LambdaFunctionConfigurations = None , <EOL> region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> if TopicConfigurations is None : <EOL> TopicConfigurations = [ ] <EOL> elif isinstance ( TopicConfigurations , string_types ) : <EOL> TopicConfigurations = json . loads ( TopicConfigurations ) <EOL> if QueueConfigurations is None : <EOL> QueueConfigurations = [ ] <EOL> elif isinstance ( QueueConfigurations , string_types ) : <EOL> QueueConfigurations = json . loads ( QueueConfigurations ) <EOL> if LambdaFunctionConfigurations is None : <EOL> LambdaFunctionConfigurations = [ ] <EOL> elif isinstance ( LambdaFunctionConfigurations , string_types ) : <EOL> LambdaFunctionConfigurations = json . loads ( LambdaFunctionConfigurations ) <EOL> conn . put_bucket_notification_configuration ( Bucket = Bucket , NotificationConfiguration = { <EOL> '<STR_LIT>' : TopicConfigurations , <EOL> '<STR_LIT>' : QueueConfigurations , <EOL> '<STR_LIT>' : LambdaFunctionConfigurations , <EOL> } ) <EOL> return { '<STR_LIT>' : True , '<STR_LIT:name>' : Bucket } <EOL> except ClientError as e : <EOL> return { '<STR_LIT>' : False , '<STR_LIT:error>' : __utils__ [ '<STR_LIT>' ] ( e ) } <EOL> def put_policy ( Bucket , Policy , <EOL> region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> if Policy is None : <EOL> Policy = '<STR_LIT:{}>' <EOL> elif not isinstance ( Policy , string_types ) : <EOL> Policy = json . dumps ( Policy ) <EOL> conn . put_bucket_policy ( Bucket = Bucket , Policy = Policy ) <EOL> return { '<STR_LIT>' : True , '<STR_LIT:name>' : Bucket } <EOL> except ClientError as e : <EOL> return { '<STR_LIT>' : False , '<STR_LIT:error>' : __utils__ [ '<STR_LIT>' ] ( e ) } <EOL> def _get_role_arn ( name , region = None , key = None , keyid = None , profile = None ) : <EOL> if name . startswith ( '<STR_LIT>' ) : <EOL> return name <EOL> account_id = __salt__ [ '<STR_LIT>' ] ( <EOL> region = region , key = key , keyid = keyid , profile = profile <EOL> ) <EOL> if profile and '<STR_LIT>' in profile : <EOL> region = profile [ '<STR_LIT>' ] <EOL> if region is None : <EOL> region = '<STR_LIT>' <EOL> return '<STR_LIT>' . format ( account_id , name ) <EOL> def put_replication ( Bucket , Role , Rules , <EOL> region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> Role = _get_role_arn ( name = Role , <EOL> region = region , key = key , keyid = keyid , profile = profile ) <EOL> if Rules is None : <EOL> Rules = [ ] <EOL> elif isinstance ( Rules , string_types ) : <EOL> Rules = json . loads ( Rules ) <EOL> conn . put_bucket_replication ( Bucket = Bucket , ReplicationConfiguration = { <EOL> '<STR_LIT>' : Role , <EOL> '<STR_LIT>' : Rules <EOL> } ) <EOL> return { '<STR_LIT>' : True , '<STR_LIT:name>' : Bucket } <EOL> except ClientError as e : <EOL> return { '<STR_LIT>' : False , '<STR_LIT:error>' : __utils__ [ '<STR_LIT>' ] ( e ) } <EOL> def put_request_payment ( Bucket , Payer , <EOL> region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> conn . put_bucket_request_payment ( Bucket = Bucket , RequestPaymentConfiguration = { <EOL> '<STR_LIT>' : Payer , <EOL> } ) <EOL> return { '<STR_LIT>' : True , '<STR_LIT:name>' : Bucket } <EOL> except ClientError as e : <EOL> return { '<STR_LIT>' : False , '<STR_LIT:error>' : __utils__ [ '<STR_LIT>' ] ( e ) } <EOL> def put_tagging ( Bucket , <EOL> region = None , key = None , keyid = None , profile = None , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> tagslist = [ ] <EOL> for k , v in kwargs . iteritems ( ) : <EOL> if str ( k ) . startswith ( '<STR_LIT>' ) : <EOL> continue <EOL> tagslist . append ( { '<STR_LIT>' : str ( k ) , '<STR_LIT>' : str ( v ) } ) <EOL> conn . put_bucket_tagging ( Bucket = Bucket , Tagging = { <EOL> '<STR_LIT>' : tagslist , <EOL> } ) <EOL> return { '<STR_LIT>' : True , '<STR_LIT:name>' : Bucket } <EOL> except ClientError as e : <EOL> return { '<STR_LIT>' : False , '<STR_LIT:error>' : __utils__ [ '<STR_LIT>' ] ( e ) } <EOL> def put_versioning ( Bucket , Status , MFADelete = None , MFA = None , <EOL> region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> VersioningConfiguration = { '<STR_LIT>' : Status } <EOL> if MFADelete is not None : <EOL> VersioningConfiguration [ '<STR_LIT>' ] = MFADelete <EOL> kwargs = { } <EOL> if MFA is not None : <EOL> kwargs [ '<STR_LIT>' ] = MFA <EOL> conn . put_bucket_versioning ( Bucket = Bucket , <EOL> VersioningConfiguration = VersioningConfiguration , <EOL> ** kwargs ) <EOL> return { '<STR_LIT>' : True , '<STR_LIT:name>' : Bucket } <EOL> except ClientError as e : <EOL> return { '<STR_LIT>' : False , '<STR_LIT:error>' : __utils__ [ '<STR_LIT>' ] ( e ) } <EOL> def put_website ( Bucket , ErrorDocument = None , IndexDocument = None , <EOL> RedirectAllRequestsTo = None , RoutingRules = None , <EOL> region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> WebsiteConfiguration = { } <EOL> for key in ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) : <EOL> val = locals ( ) [ key ] <EOL> if val is not None : <EOL> if isinstance ( val , string_types ) : <EOL> WebsiteConfiguration [ key ] = json . loads ( val ) <EOL> else : <EOL> WebsiteConfiguration [ key ] = val <EOL> conn . put_bucket_website ( Bucket = Bucket , <EOL> WebsiteConfiguration = WebsiteConfiguration ) <EOL> return { '<STR_LIT>' : True , '<STR_LIT:name>' : Bucket } <EOL> except ClientError as e : <EOL> return { '<STR_LIT>' : False , '<STR_LIT:error>' : __utils__ [ '<STR_LIT>' ] ( e ) } <EOL> def delete_cors ( Bucket , <EOL> region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> conn . delete_bucket_cors ( Bucket = Bucket ) <EOL> return { '<STR_LIT>' : True , '<STR_LIT:name>' : Bucket } <EOL> except ClientError as e : <EOL> return { '<STR_LIT>' : False , '<STR_LIT:error>' : __utils__ [ '<STR_LIT>' ] ( e ) } <EOL> def delete_lifecycle_configuration ( Bucket , <EOL> region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> conn . delete_bucket_lifecycle ( Bucket = Bucket ) <EOL> return { '<STR_LIT>' : True , '<STR_LIT:name>' : Bucket } <EOL> except ClientError as e : <EOL> return { '<STR_LIT>' : False , '<STR_LIT:error>' : __utils__ [ '<STR_LIT>' ] ( e ) } <EOL> def delete_policy ( Bucket , <EOL> region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> conn . delete_bucket_policy ( Bucket = Bucket ) <EOL> return { '<STR_LIT>' : True , '<STR_LIT:name>' : Bucket } <EOL> except ClientError as e : <EOL> return { '<STR_LIT>' : False , '<STR_LIT:error>' : __utils__ [ '<STR_LIT>' ] ( e ) } <EOL> def delete_replication ( Bucket , <EOL> region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> conn . delete_bucket_replication ( Bucket = Bucket ) <EOL> return { '<STR_LIT>' : True , '<STR_LIT:name>' : Bucket } <EOL> except ClientError as e : <EOL> return { '<STR_LIT>' : False , '<STR_LIT:error>' : __utils__ [ '<STR_LIT>' ] ( e ) } <EOL> def delete_tagging ( Bucket , <EOL> region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> conn . delete_bucket_tagging ( Bucket = Bucket ) <EOL> return { '<STR_LIT>' : True , '<STR_LIT:name>' : Bucket } <EOL> except ClientError as e : <EOL> return { '<STR_LIT>' : False , '<STR_LIT:error>' : __utils__ [ '<STR_LIT>' ] ( e ) } <EOL> def delete_website ( Bucket , <EOL> region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> conn . delete_bucket_website ( Bucket = Bucket ) <EOL> return { '<STR_LIT>' : True , '<STR_LIT:name>' : Bucket } <EOL> except ClientError as e : <EOL> return { '<STR_LIT>' : False , '<STR_LIT:error>' : __utils__ [ '<STR_LIT>' ] ( e ) } </s>
