How to use put_bucket_acl method in localstack

Best Python code snippet using localstack_python

bucket.py

Source: bucket.py Github

copy

Full Screen

...32 print url33 response = requests.get(url)34 print 'Presigned list buckets: ', response.text35 assert response.status_code != 20036def put_bucket_acl(name, client):37 client.put_bucket_acl(38 Bucket=name+'hehe',39 ACL='public-read-write',40 )41def get_bucket_acl(name, client):42 ans = client.get_bucket_acl(43 Bucket=name+'hehe',44 )45 print 'Get bucket ACL:', ans46# boto cannot even send presigned acl requests correctly,47# so comment out48# def put_bucket_acl_presigned(name, client):49# url = client.generate_presigned_url(50# ClientMethod='put_bucket_acl',51# Params={...

Full Screen

Full Screen

put_bucket_acl.py

Source: put_bucket_acl.py Github

copy

Full Screen

...19 # Return both the Owner and Grants keys20 # The Owner and Grants settings together form the Access Control Policy.21 # The Grants alone form the Access Control List.22 return {'Owner': response['Owner'], 'Grants': response['Grants']}23def put_bucket_acl(bucket_name, acl):24 """Set the access control list of an Amazon S3 bucket25 :param bucket_name: string26 :param acl: Dictionary defining the ACL consisting of grants and permissions27 :return: True if ACL was set, otherwise False28 """29 # Set the ACL30 s3 = boto3.client('s3')31 try:32 s3.put_bucket_acl(Bucket=bucket_name, AccessControlPolicy=acl)33 except ClientError as e:34 # AccessDenied error == bucket prohibits public access35 # AllAccessDisabled error == bucket not found36 # AmbiguousGrantByEmailAddress == email address is associated with37 # multiple AWS accounts38 logging.error(e)39 return False40 return True41def main():42 """Exercise put_bucket_acl()"""43 # Assign these values before running the program44 test_bucket_name = 'BUCKET_NAME'45 new_grantee_canonical_user_id = 'AWS_USER_ID'46 # new_grantee_email = 'EMAIL_ADDRESS' # Set AWS User ID or email, but not both47 new_grantee_permission = 'READ' # Or 'FULL_CONTROL', etc.48 # Set up logging49 logging.basicConfig(level=logging.DEBUG,50 format='%(levelname)s: %(asctime)s: %(message)s')51 # Get the bucket's current ACL52 acl = get_bucket_acl(test_bucket_name)53 if acl is None:54 exit(-1)55 # Add a new grant to the current ACL56 new_grant = {57 'Grantee': {58 'ID': new_grantee_canonical_user_id,59 'Type': 'CanonicalUser',60 #'EmailAddress': new_grantee_email, # Set ID or Email61 #'Type': 'AmazonCustomerByEmail',62 },63 'Permission': new_grantee_permission,64 }65 # If we don't want to modify the original ACL variable, then we66 # must do a deepcopy67 modified_acl = copy.deepcopy(acl)68 modified_acl['Grants'].append(new_grant)69 # Put the updated bucket ACL70 if put_bucket_acl(test_bucket_name, modified_acl):71 logging.info(f'The ACL was set for {test_bucket_name}')72if __name__ == '__main__':...

Full Screen

Full Screen

handler.py

Source: handler.py Github

copy

Full Screen

...29 resource = list(event['detail']['requestParameters']['evaluations'])[0]30 bucket_name = resource['complianceResourceId']31 compliance_failure = event['detail']['requestParameters']['evaluations'][0]['annotation']32 if compliance_failure == ACL_RD_WARNING or compliance_failure == ACL_WRT_WARNING:33 s3.put_bucket_acl(Bucket = bucket_name, ACL = 'private')34 policy_notifier(bucket_name)35 elif compliance_failure == PLCY_RD_WARNING or compliance_failure == PLCY_WRT_WARNING:36 s3.put_bucket_acl(Bucket = bucket_name, ACL = 'private')37 s3.delete_bucket_policy(Bucket = bucket_name)38 policy_notifier(bucket_name)39 elif compliance_failure == RD_COMBO_WARNING or compliance_failure == WRT_COMBO_WARNING:40 s3.put_bucket_acl(Bucket = bucket_name, ACL = 'private')41 s3.delete_bucket_policy(Bucket = bucket_name)42 policy_notifier(bucket_name)...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

13 Best Java Testing Frameworks For 2023

The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.

QA Innovation – Using the senseshaping concept to discover customer needs

QA Innovation - Using the senseshaping concept to discover customer needsQA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.

Best 23 Web Design Trends To Follow In 2023

Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.

Acquiring Employee Support for Change Management Implementation

Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful