storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/docs/sts/client-grants.py (about) 1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 import logging 16 17 import boto3 18 from boto3.session import Session 19 from botocore.session import get_session 20 21 from client_grants import ClientGrantsCredentialProvider 22 23 boto3.set_stream_logger('boto3.resources', logging.DEBUG) 24 25 bc_session = get_session() 26 bc_session.get_component('credential_provider').insert_before( 27 'env', 28 ClientGrantsCredentialProvider('NZLOOFRSluw9RfIkuHGqfk1HFp4a', 29 '0Z4VTG8uJBSekn42HE40DK9vQb4a'), 30 ) 31 32 boto3_session = Session(botocore_session=bc_session) 33 s3 = boto3_session.resource('s3', endpoint_url='http://localhost:9000') 34 35 with open('/etc/hosts', 'rb') as data: 36 s3.meta.client.upload_fileobj(data, 37 'testbucket', 38 'hosts', 39 ExtraArgs={'ServerSideEncryption': 'AES256'}) 40 41 # Upload with server side encryption, using temporary credentials 42 s3.meta.client.upload_file('/etc/hosts', 43 'testbucket', 44 'hosts', 45 ExtraArgs={'ServerSideEncryption': 'AES256'}) 46 47 # Download encrypted object using temporary credentials 48 s3.meta.client.download_file('testbucket', 'hosts', '/tmp/hosts')