From d5652c74c829b756147f71b00bccb1cceae13718 Mon Sep 17 00:00:00 2001 From: Andreas Joachim Peters Date: Wed, 22 May 2024 12:00:02 +0200 Subject: [PATCH] S3: add option '--newbucketpath' to 'xs3 adduser' command to configure the namespace location where new buckets will be located physically --- src/XrdS3/app/xs3 | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/XrdS3/app/xs3 b/src/XrdS3/app/xs3 index f63b5ba6894..ee36718617c 100755 --- a/src/XrdS3/app/xs3 +++ b/src/XrdS3/app/xs3 @@ -46,7 +46,8 @@ def main(): adduser_parser = subparsers.add_parser('adduser', help='Add a new user') adduser_parser.add_argument('username', help='Username to add') adduser_parser.add_argument('bucketpath', help='Filesystem path for the default bucket for the given user') - + adduser_parser.add_argument('--newbucketpath', help='New bucket path', default=None) + # Add the 'deleteuser' subcommand deleteuser_parser = subparsers.add_parser('deleteuser', help='Delete an existing user') deleteuser_parser.add_argument('username', help='Username to delete') @@ -135,7 +136,8 @@ def generate_unique_random_string(base_path, length=8): def handle_adduser(args): username = args.username bucket_path = args.bucketpath - + new_bucket_path = args.newbucketpath + # Determine the users directory from the config file config_dir = os.path.join(os.path.expanduser('~'), '.xs3') config_file = os.path.join(config_dir, 'config') @@ -170,6 +172,15 @@ def handle_adduser(args): os.makedirs(user_dir) print(f"Info: User '{username}' added successfully.") + if new_bucket_path: + try: + os.setxattr(user_dir, 'user.s3.new_bucket_path', new_bucket_path.encode()) + print(f"Info: Extended attribute 'user.s3.new_bucket_path' set on '{user_dir}': {new_bucket_path}") + except AttributeError: + print("info: Extended attributes are not supported on this platform.") + except OSError as e: + print(f"Error: Failed to set extended attribute on '{user_dir}'. {e}") + # Create the empty file in the user directory user_file = os.path.join(user_dir, f"b_{username}") open(user_file, 'w').close()