github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/docs/sts/client-grants.py (about)

     1  #!/usr/bin/env python
     2  # -*- coding: utf-8 -*-
     3  
     4  import logging
     5  
     6  import boto3
     7  from boto3.session import Session
     8  from botocore.session import get_session
     9  
    10  from client_grants import ClientGrantsCredentialProvider
    11  
    12  boto3.set_stream_logger('boto3.resources', logging.DEBUG)
    13  
    14  bc_session = get_session()
    15  bc_session.get_component('credential_provider').insert_before(
    16      'env',
    17      ClientGrantsCredentialProvider('NZLOOFRSluw9RfIkuHGqfk1HFp4a',
    18                                     '0Z4VTG8uJBSekn42HE40DK9vQb4a'),
    19  )
    20  
    21  boto3_session = Session(botocore_session=bc_session)
    22  s3 = boto3_session.resource('s3', endpoint_url='http://localhost:9000')
    23  
    24  with open('/etc/hosts', 'rb') as data:
    25      s3.meta.client.upload_fileobj(data,
    26                                    'testbucket',
    27                                    'hosts',
    28                                    ExtraArgs={'ServerSideEncryption': 'AES256'})
    29  
    30  # Upload with server side encryption, using temporary credentials
    31  s3.meta.client.upload_file('/etc/hosts',
    32                             'testbucket',
    33                             'hosts',
    34                             ExtraArgs={'ServerSideEncryption': 'AES256'})
    35  
    36  # Download encrypted object using temporary credentials
    37  s3.meta.client.download_file('testbucket', 'hosts', '/tmp/hosts')