in tools/cli/wsk/wskadmin.py [0:0]
def createUserCmd(args, props):
subject = args.subject.strip()
if len(subject) < 5:
print('Subject name must be at least 5 characters')
return 2
if args.namespace and args.namespace.strip() == '':
print('Namespace must not be empty')
return 2
else:
desiredNamespace = subject if not args.namespace else args.namespace.strip()
if args.auth:
try:
parts = args.auth.split(':')
try:
uid = str(uuid.UUID(parts[0], version = 4))
except ValueError:
print('authorization id is not a valid UUID')
return 2
key = parts[1]
if len(key) < 64:
print('authorization key must be at least 64 characters long')
return 2
except Exception as e:
print('failed to determine authorization id and key: %s' % e)
return 2
else:
uid = str(uuid.uuid4())
key = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(64))
if args.genonly:
print('%s:%s' % (uid, key))
return 0
(doc, res) = getDocumentFromDb(props, args.subject, args.verbose)
if doc is None:
doc = {
'_id': subject,
'subject': subject,
'namespaces': [
{
'name': desiredNamespace,
'uuid': uid,
'key': key
}
]
}
else:
if not doc.get('blocked'):
namespaces = [ns for ns in doc['namespaces'] if ns['name'] == desiredNamespace]
if len(namespaces) == 0:
doc['namespaces'].append({
'name': desiredNamespace,
'uuid': uid,
'key': key
})
elif args.revoke:
if len(namespaces) == 1:
namespaces[0]['uuid'] = uid
namespaces[0]['key'] = key
else:
print('Namespace is not unique')
return 1
else:
print('Namespace already exists')
return 1
else:
print('The subject you want to edit is blocked')
return 1
res = insertIntoDatabase(props, doc, args.verbose)
if res.status in [201, 202]:
if not args.silent:
print('%s:%s' % (uid, key))
else:
print('Failed to create subject (%s)' % res.read().strip())
return 1