コード例 #1
0
def neo_create_bucket(**kwargs):
    """Create a bucket with headers.

    :param auth: Tuple, consists of auth object and endpoint string
    :param acl: Input for canned ACL, defaults to "private"
    :param policy_id: String represent `x-gmt-policyid` or determines how data in the bucket will be distributed, defaults to None
    :param bucket_name: Bucket name
    :param random: A flag for deciding that a bucket name should be suffixed by random string or not, defaults to False
    """
    auth = kwargs.get("auth")
    acl = kwargs.get("acl", "private")
    policy_id = kwargs.get("policy_id", "")
    bucket_name = kwargs.get("bucket_name")

    if kwargs.get("random_name"):
        bucket_name = gen_random_name(bucket_name)

    endpoint = auth_lib.get_endpoint("storage", bucket_name)
    headers = {"x-gmt-policyid": policy_id, "x-amz-acl": acl}

    if "." in bucket_name:
        response = requests.put(endpoint, auth=auth, headers=headers, verify=False)
    else:
        response = requests.put(endpoint, auth=auth, headers=headers)
    return response
コード例 #2
0
ファイル: gmt.py プロジェクト: azzamsa/neo-obs
def policy_id(bucket_name, auth):
    """Get GMT-Policy id from S3 API response headers."""

    endpoint = auth_lib.get_endpoint("storage", bucket_name)
    response = requests.get(endpoint, auth=auth)
    policy_id = response.headers.get("x-gmt-policyid")

    return policy_id
コード例 #3
0
def get_resources(access_key, secret_key):
    endpoint = auth.get_endpoint("storage")
    sess = boto3.Session(aws_access_key_id=access_key,
                         aws_secret_access_key=secret_key)
    s3_resource = sess.resource("s3", endpoint_url=endpoint)
    return s3_resource