Skip to content

Commit

Permalink
S3: add option '--newbucketpath' to 'xs3 adduser' command to configur…
Browse files Browse the repository at this point in the history
…e the namespace location where new buckets will be located physically
  • Loading branch information
apeters1971 committed May 22, 2024
1 parent 64fbb81 commit d5652c7
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/XrdS3/app/xs3
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit d5652c7

Please sign in to comment.