def execute_perms_command(objs, args, options, credentials): db = ExtendedFluidDB(host=options.hostname, credentials=credentials, debug=options.debug, unixStylePaths=fdblib.path_style(options)) if len(args) < 2: Print(u'Form: perms SPEC list of tags and namespaces') return spec = args[0] assert spec in (u'private', u'default', u'group', u'group-write', u'group-read', u'lock', u'unlock') isGroup = spec.startswith(u'group') if isGroup: group = args[1].split(u'+') if len(args) < 3: Print((u'Group form: perms %s list+of+group+members list of tags ' u'and namespaces' % spec)) fullpaths = (db.abs_tag_path(t, inPref=True) for t in args[1 + isGroup:]) for path in fullpaths: done = False owner = path.split(u'/')[1] for (exists, isTag) in ((db.tag_exists, True), (db.ns_exists, False)): if exists(path): inPerms = FluidinfoPerms(db, path, isTag=isTag, getFromFI=False) if spec == u'private': inPerms.set_to_private() elif spec == u'default': inPerms.set_to_default() elif spec == u'lock': inPerms = FluidinfoPerms(db, path, isTag=isTag, getFromFI=True) inPerms.lock() elif spec == u'unlock': inPerms = FluidinfoPerms(db, path, isTag=isTag, getFromFI=True) inPerms.unlock() else: # group inPerms = FluidinfoPerms(db, path, isTag=isTag, getFromFI=True) if spec in (u'group', u'group-read'): inPerms.set_group_readable(group) if spec in (u'group', u'group-write'): inPerms.set_group_writable(group) inPerms.update_fluidinfo(db) done = True if not done: Print('No tag or namespace %s found' % db.abs_tag_path(path, outPref=True))
def execute_ls_command(objs, tags, options, credentials): db = ExtendedFluidDB(host=options.hostname, credentials=credentials, debug=options.debug, unixStylePaths=fdblib.path_style(options)) long_ = options.long or options.group if options.policy: if len(tags) > 0: Print(u'Form: ls -P') else: Print(unicode(FluidinfoPerms(db, u'/' + db.credentials.username, isTag=False, isPolicy=True))) Print(unicode(FluidinfoPerms(db, u'/' + db.credentials.username, isTag=True, isPolicy=True))) return if len(tags) == 0: tags = [(u'/' if db.unixStyle else u'') + db.credentials.username] for tag in tags: fulltag = db.abs_tag_path(tag, inPref=True) if options.namespace or options.ns: if db.ns_exists(fulltag): if long_ or options.longer: nsResult = db.full_perms(fulltag[1:] + u'/', options.longer, options.group) else: nsResult = fulltag Print(nsResult) else: nsResult = u'Not Found' else: nsResult = db.list_sorted_ns(fulltag[1:], long_=long_, recurse=options.recurse, prnt=True, longer=options.longer) tagExists = db.tag_exists(fulltag) if nsResult == u'Error status 404': if not tagExists: Print(u'%s not found' % fulltag) if tagExists: if long_ or options.longer: Print(db.full_perms(fulltag[1:], options.longer, options.group)) else: Print(tag)
def execute_chmod_command(objs, args, options, credentials): cli.warning('Not implemented yet.') return db = ExtendedFluidDB(host=options.hostname, credentials=credentials, debug=options.debug, unixStylePaths=fdblib.path_style(options)) if len(args) < 2: Print(u'Form: chmod [perms-spec] list-of-tags-and-namespaces') return spec = args[0] if not all(u'0' <= p<= u'7' for p in spec) or len(spec) != 3: Print((u'Permissions specifier must have for ddd with each d between ' u'0 and 7')) new_perms = UnixPerms(spec, db.credentials.username) fullpaths = (db.abs_tag_path(t, inPref=True) for t in args[1:]) Print(unicode(new_perms)) Print(u'READ: %s' % unicode(new_perms.read)) Print(u'WRITE: %s' % unicode(new_perms.write)) Print(u'CONTROL: %s' % unicode(new_perms.control)) new_perms.check_owner_control_ok() for path in fullpaths: done = False if db.tag_exists(path): inPerms = FluidinfoPerms(db, path, isTag=True) Print(unicode(inPerms)) new_perms.isTag = True # outPerms = new_perms.new_fi_tag_perms(inTagPerms) done = True if db.ns_exists(path): inPerms = FluidinfoPerms(db, path, isTag=False) Print(unicode(inPerms)) new_perms.isTag = False # outPerms = new_perms.new_fi_ns_perms(inTagPerms) done = True if not done: Print('No tag or namespace %s found' % db.abs_tag_path(path, outPref=True))
def execute_command_line(action, args, options, parser, user=None, pwd=None): credentials = (Credentials(user or options.user[0], pwd) if (user or options.user) else None) if not action == 'ls': db = FluidDB(host=options.hostname, credentials=credentials, debug=options.debug, unixStylePaths=path_style(options)) ids_from_queries = chain(*imap(lambda q: get_ids_or_fail(q, db), options.query)) ids = chain(options.id, ids_from_queries) command_list = [ 'help', 'version', 'commands', 'tag', 'untag', 'show', 'tags', 'ls', 'perms', 'pwd', 'pwn', 'test', 'testcli', 'testdb', 'testapi', 'whoami', 'su', ] objs = [O({'mode': 'about', 'specifier': a}) for a in options.about] + \ [O({'mode': 'id', 'specifier': id}) for id in ids] if action == 'version' or options.version: Print('fdb %s' % version()) if action == 'version': return if action == 'help': Print(USAGE if db.unixStyle else USAGE_FI) elif action == 'commands': Print(' '.join(command_list)) elif action not in command_list: Print('Unrecognized command %s' % action) elif (action.upper() not in HTTP_METHODS + ARGLESS_COMMANDS and not args): Print('Too few arguments for action %s' % action) elif action == 'count': Print('Total: %s' % (flags.Plural(len(objs), 'object'))) elif action == 'tags': execute_tags_command(objs, db, options) elif action in ('tag', 'untag', 'show'): if not (options.about or options.query or options.id): Print('You must use -q, -a or -i with %s' % action) return tags = args if len(tags) == 0 and action != 'count': nothing_to_do() actions = { 'tag': execute_tag_command, 'untag': execute_untag_command, 'show': execute_show_command, } command = actions[action] command(objs, db, args, options) elif action == 'ls': ls.execute_ls_command(objs, args, options, credentials) elif action == 'chmod': ls.execute_chmod_command(objs, args, options, credentials) elif action == 'perms': ls.execute_perms_command(objs, args, options, credentials) elif action in ('pwd', 'pwn', 'whoami'): execute_whoami_command(db) elif action == 'su': execute_su_command(db, args) elif action in ['get', 'put', 'post', 'delete']: execute_http_request(action, args, db, options) else: Print('Unrecognized command %s' % action)