From 47fc031028298e46b15d2f96ccb576a4e6e145f1 Mon Sep 17 00:00:00 2001 From: Andrey Berezin Date: Mon, 5 Feb 2024 18:56:36 +0300 Subject: [PATCH] [#125] Adding acl to container and bucket creation Signed-off-by: Andrey Berezin --- scenarios/preset/helpers/aws_cli.py | 9 ++++++--- scenarios/preset/helpers/frostfs_cli.py | 12 +++++++----- scenarios/preset/preset_grpc.py | 3 ++- scenarios/preset/preset_s3.py | 3 ++- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/scenarios/preset/helpers/aws_cli.py b/scenarios/preset/helpers/aws_cli.py index 8dd23c4..5a85a7f 100644 --- a/scenarios/preset/helpers/aws_cli.py +++ b/scenarios/preset/helpers/aws_cli.py @@ -3,15 +3,18 @@ import uuid from helpers.cmd import execute_cmd, log -def create_bucket(endpoint, versioning, location, no_verify_ssl): +def create_bucket(endpoint, versioning, location, acl, no_verify_ssl): if location: location = f"--create-bucket-configuration 'LocationConstraint={location}'" + if acl: + acl = f"--acl {acl}" + bucket_name = str(uuid.uuid4()) no_verify_ssl_str = "--no-verify-ssl" if no_verify_ssl else "" cmd_line = f"aws {no_verify_ssl_str} s3api create-bucket --bucket {bucket_name} " \ - f"--endpoint {endpoint} {location}" + f"--endpoint {endpoint} {location} {acl} " cmd_line_ver = f"aws {no_verify_ssl_str} s3api put-bucket-versioning --bucket {bucket_name} " \ - f"--versioning-configuration Status=Enabled --endpoint {endpoint} " + f"--versioning-configuration Status=Enabled --endpoint {endpoint} {acl} " output, success = execute_cmd(cmd_line) diff --git a/scenarios/preset/helpers/frostfs_cli.py b/scenarios/preset/helpers/frostfs_cli.py index 0f3dcaa..f974d2b 100644 --- a/scenarios/preset/helpers/frostfs_cli.py +++ b/scenarios/preset/helpers/frostfs_cli.py @@ -1,16 +1,18 @@ import re from helpers.cmd import execute_cmd, log -def create_container(endpoint, policy, wallet_path, config, local=False, depth=0): +def create_container(endpoint, policy, wallet_path, config, acl, local=False, depth=0): if depth > 20: raise ValueError(f"unable to create container: too many unsuccessful attempts") if wallet_path: - wallet_file = "--wallet " + wallet_path + wallet_file = f"--wallet {wallet_path}" if config: - wallet_config = "--config " + config + wallet_config = f"--config {config}" + if acl: + acl = f"--basic-acl {acl}" cmd_line = f"frostfs-cli --rpc-endpoint {endpoint} container create {wallet_file} {wallet_config} " \ - f" --policy '{policy}' --basic-acl public-read-write --await" + f" --policy '{policy}' {acl} --await" output, success = execute_cmd(cmd_line) @@ -86,7 +88,7 @@ def create_container(endpoint, policy, wallet_path, config, local=False, depth=0 return cid log(f"Created container {cid} is not stored on {endpoint}, creating another one...", endpoint) - return create_container(endpoint, policy, wallet_path, config, local, depth + 1) + return create_container(endpoint, policy, wallet_path, config, acl, local, depth + 1) def upload_object(container, payload_filepath, endpoint, wallet_file, wallet_config): diff --git a/scenarios/preset/preset_grpc.py b/scenarios/preset/preset_grpc.py index 0c170ea..7b1daa0 100755 --- a/scenarios/preset/preset_grpc.py +++ b/scenarios/preset/preset_grpc.py @@ -35,6 +35,7 @@ parser.add_argument('--workers', help='Count of workers in preset. Max = 50, Def parser.add_argument('--sleep', help='Time to sleep between containers creation and objects upload (in seconds), ' 'Default = 8', default=8) parser.add_argument('--local', help='Create containers that store data on provided endpoints. Warning: additional empty containers may be created.', action='store_true') +parser.add_argument('--acl', help='Container ACL. Default is public-read-write.', default='public-read-write') args: Namespace = parser.parse_args() print(args) @@ -62,7 +63,7 @@ def main(): containers_count = int(args.containers) print(f"Create containers: {containers_count}") with ProcessPoolExecutor(max_workers=min(MAX_WORKERS, workers)) as executor: - containers_runs = [executor.submit(create_container, endpoint, args.policy, wallet, wallet_config, args.local) + containers_runs = [executor.submit(create_container, endpoint, args.policy, wallet, wallet_config, args.acl, args.local) for _, endpoint in zip(range(containers_count), cycle(endpoints))] diff --git a/scenarios/preset/preset_s3.py b/scenarios/preset/preset_s3.py index 0ce6683..c76e57d 100755 --- a/scenarios/preset/preset_s3.py +++ b/scenarios/preset/preset_s3.py @@ -27,6 +27,7 @@ parser.add_argument('--no-verify-ssl', help='Ignore SSL verifications', action=' parser.add_argument('--workers', help='Count of workers in preset. Max = 50, Default = 50', default=50) parser.add_argument('--sleep', help='Time to sleep between buckets creation and objects upload (in seconds), ' 'Default = 8', default=8) +parser.add_argument('--acl', help='Bucket ACL. Default is private. Expected values are: private, public-read or public-read-write.', default="private") args = parser.parse_args() print(args) @@ -58,7 +59,7 @@ def main(): print(f"Create buckets: {buckets_count}") with ProcessPoolExecutor(max_workers=min(MAX_WORKERS, workers)) as executor: - buckets_runs = [executor.submit(create_bucket, endpoint, args.versioning, args.location, no_verify_ssl) + buckets_runs = [executor.submit(create_bucket, endpoint, args.versioning, args.location, args.acl, no_verify_ssl) for _, endpoint in zip(range(buckets_count), cycle(endpoints))]