def main(cmd_line_args): capella_api = CapellaAPI() if cmd_line_args.debug: capella_logging('debug') capella_api.set_logging_level('DEBUG') else: capella_logging('info') cluster_user_struct = { "password": cmd_line_args.Password, "username": cmd_line_args.UserName, } # Split up into the individual bits we need all_bucket_access = cmd_line_args.Access.strip() # Look at the access requested and then map to what the endpoint expects if all_bucket_access == 'r': cluster_user_struct['allBucketsAccess']="data_reader" elif all_bucket_access == 'w': cluster_user_struct['allBucketsAccess']="data_writer" else: raise UserBucketAccessListError('access not found') # Check Capella API status if capella_api.api_status().status_code == 200: capella_api_response = capella_api.create_cluster_user(False, cmd_line_args.ClusterID, cluster_user_struct) if capella_api_response.status_code == 201: print("Cluster user is being created") else: print("Failed to create user") print("Capella API returned " + str(capella_api_response.status_code)) print("Full error message") print(capella_api_response.json()["message"]) else: print("Check Capella API is up.")
def main(cmd_line_args): capella_api = CapellaAPI() if cmd_line_args.debug: capella_logging('debug') capella_api.set_logging_level('DEBUG') else: capella_logging('INFO') cluster_user_struct = { "password": cmd_line_args.password, "username": cmd_line_args.user_name, "buckets": [] } # Go through each entry for bucket_and_scope_entry in cmd_line_args.buckets_and_scope.split(','): cluster_user_bucket_and_scope_access = { "name": "", "scope": "", "access": "" } # Split up into the individual bits we need bucket_and_scope_entry = bucket_and_scope_entry.strip() bucket_access = bucket_and_scope_entry.split(':')[2] bucket_scope = bucket_and_scope_entry.split(':')[1] bucket_name = bucket_and_scope_entry.split(':')[0] # Set the name of the bucket we're going to grant access to cluster_user_bucket_and_scope_access['name'] = bucket_name # Set the scope cluster_user_bucket_and_scope_access['scope'] = bucket_scope # Look at the access requested and then map to what the endpoint expects if bucket_access == 'r': cluster_user_bucket_and_scope_access["access"] = "data_reader" elif bucket_access == 'w': cluster_user_bucket_and_scope_access["access"] = "data_writer" elif bucket_access == 'rw': cluster_user_bucket_and_scope_access["access"] = "data_writer" elif bucket_access == 'wr': cluster_user_bucket_and_scope_access["access"] = "data_writer" else: # This should never have passed the regex test done in check_bucket_and_scope_type # but just in case.... print('access not found for ' + bucket_and_scope_entry) raise UserBucketAccessListError('access not found for ' + bucket_and_scope_entry) cluster_user_struct["buckets"].append( cluster_user_bucket_and_scope_access) # Check Capella API status if capella_api.api_status().status_code == 200: capella_api_response = capella_api.create_cluster_user( True, cmd_line_args.cluster_id, cluster_user_struct) if capella_api_response.status_code == 201: print("Cluster user is being created") else: print("Failed to create user") print("Capella API returned " + str(capella_api_response.status_code)) print("Full error message") print(capella_api_response.json()["message"]) else: print("Check Capella API is up.")
def main(cmd_line_args): capella_api = CapellaAPI() if cmd_line_args.debug: capella_logging('debug') capella_api.set_logging_level('DEBUG') else: capella_logging('INFO') cluster_user_struct = { "password": cmd_line_args.Password, "username": cmd_line_args.UserName, "buckets": [] } # Go through each entry for bucket_and_access_entry in cmd_line_args.Buckets.split(','): cluster_user_bucket_access_struct = { "bucketName": "", "bucketAccess": [] } # Split up into the individual bits we need bucket_and_access_entry = bucket_and_access_entry.strip() bucket_access_requested = bucket_and_access_entry.split(':')[1] bucket_access_name = bucket_and_access_entry.split(':')[0] # Set the name of the bucket we're going to grant access to cluster_user_bucket_access_struct['bucketName'] = bucket_access_name # Look at the access requested and then map to what the endpoint expects if bucket_access_requested == 'r': cluster_user_bucket_access_struct["bucketAccess"].append( "data_reader") elif bucket_access_requested == 'w': cluster_user_bucket_access_struct["bucketAccess"].append( "data_writer") elif bucket_access_requested == 'rw': cluster_user_bucket_access_struct["bucketAccess"].append( "data_writer") cluster_user_bucket_access_struct["bucketAccess"].append( "data_reader") elif bucket_access_requested == 'wr': cluster_user_bucket_access_struct["bucketAccess"].append( "data_writer") cluster_user_bucket_access_struct["bucketAccess"].append( "data_reader") else: print('access not found for ' + bucket_and_access_entry) raise UserBucketAccessListError('access not found for ' + bucket_and_access_entry) cluster_user_struct["buckets"].append( cluster_user_bucket_access_struct) # Check Capella API status if capella_api.api_status().status_code == 200: capella_api_response = capella_api.create_cluster_user( False, cmd_line_args.ClusterID, cluster_user_struct) if capella_api_response.status_code == 201: print("Cluster user is being created") else: print("Failed to create user") print("Capella API returned " + str(capella_api_response.status_code)) print("Full error message") print(capella_api_response.json()["message"]) else: print("Check Capella API is up.")