def remove_user(self, force=False): try: if force: uc = User(self.db_obj, uu=self.get_canonical_id(), create=False) uc.destroy_brutally() else: self.alias.remove() finally: self.db_obj.commit()
def test_destroy_user(self): user1 = User(self.db) uu = user1.get_id() user1.destroy_brutally() try: user1 = User(self.db, uu) self.fail("The uuid should have been deleted %s" % (uu)) except: pass
def remove_user(self, force=False): pycb.log(logging.INFO, "===== def remove_user of cbAuthzSecurity.py") try: if force: uc = User(self.db_obj, uu=self.get_canonical_id(), create=False) uc.destroy_brutally() else: self.alias.remove() finally: self.db_obj.commit()
def main(argv=sys.argv[1:]): try: con_str = pynimbusauthz.get_db_connection_string() db_obj = DB(con_str=con_str) (opts, args) = setup_options(argv) user_uu = None if len(args) == 1: user_uu = args[0] if opts.new: user = User(db_obj, user_uu, friendly=opts.friendlyname, create=True) pynimbusauthz.print_msg(opts, 0, "User %s added" % (user.get_id())) else: user = User(db_obj, user_uu) pynimbusauthz.print_msg(opts, 0, "User %s" % (user.get_id())) if opts.alias != None: user_alias = user.get_alias(opts.alias, opts.type) if user_alias == None: user_alias = user.create_alias(opts.alias, opts.type, opts.friendlyname) pynimbusauthz.print_msg( opts, 0, "Creating new alias %s:%s" % (opts.type, opts.alias)) if opts.genkey: data = pynimbusauthz.random_string_gen(42) pynimbusauthz.print_msg(opts, 0, "Key generated %s" % (data)) user_alias.set_data(data) elif opts.setkey != None: data = opts.setkey user_alias.set_data(data) pynimbusauthz.print_msg(opts, 0, "updated the alias key") if opts.remove_alias != None: user_alias = user.get_alias(opts.remove_alias, opts.type) user_alias.remove() if opts.remove: pynimbusauthz.print_msg(opts, 1, "Removing user %s" % (user.get_id())) if opts.force: pynimbusauthz.print_msg(opts, 1, "Removing all references") user.destroy_brutally() else: user.destroy() db_obj.commit() except AuthzException, ae: print ae return ae.get_rc()
class TestUser(unittest.TestCase): def setUp(self): # os.environ['CUMULUS_AUTHZ_DDL'] = "/home/bresnaha/Dev/Nimbus/nimbus/cumulus/authz/etc/acl.sql" con = pynimbusauthz.db.make_test_database() self.db = DB(con=con) self.user = User(self.db) def tearDown(self): self.user.destroy_brutally() self.db.close() def test_get_no_quota(self): q = self.user.get_quota() self.assertEqual(q, User.UNLIMITED) def test_set_quota(self): q = 100 self.user.set_quota(q) qrc = self.user.get_quota() self.assertEqual(q, qrc) def test_get_no_usage(self): u = self.user.get_quota_usage() self.assertEqual(u, 0) def test_add_file_usage_one_file(self): size1 = 100 name = "/file/name" data = "/etc/group" file1 = File.create_file(self.db, name, self.user, data, pynimbusauthz.object_type_s3, size=size1) self.db.commit() u = self.user.get_quota_usage() self.assertEqual(u, size1) def test_add_file_usage_many_files(self): size1 = 100 name = "/file/name" data = "/etc/group" total = 0 for i in range(0, 10): file1 = File.create_file(self.db, name+str(i), self.user, data, pynimbusauthz.object_type_s3, size=size1) total = total + size1 self.db.commit() u = self.user.get_quota_usage() self.assertEqual(u, total)
def main(argv=sys.argv[1:]): try: con_str = pynimbusauthz.get_db_connection_string() db_obj = DB(con_str=con_str) (opts,args) = setup_options(argv) user_uu = None if len(args) == 1: user_uu = args[0] if opts.new: user = User(db_obj, user_uu, friendly=opts.friendlyname, create=True) pynimbusauthz.print_msg(opts, 0, "User %s added" % (user.get_id())) else: user = User(db_obj, user_uu) pynimbusauthz.print_msg(opts, 0, "User %s" % (user.get_id())) if opts.alias != None: user_alias = user.get_alias(opts.alias, opts.type) if user_alias == None: user_alias = user.create_alias(opts.alias, opts.type, opts.friendlyname) pynimbusauthz.print_msg(opts, 0, "Creating new alias %s:%s" % (opts.type,opts.alias)) if opts.genkey: data = pynimbusauthz.random_string_gen(42) pynimbusauthz.print_msg(opts, 0, "Key generated %s" % (data)) user_alias.set_data(data) elif opts.setkey != None: data = opts.setkey user_alias.set_data(data) pynimbusauthz.print_msg(opts, 0, "updated the alias key") if opts.remove_alias != None: user_alias = user.get_alias(opts.remove_alias, opts.type) user_alias.remove() if opts.remove: pynimbusauthz.print_msg(opts, 1, "Removing user %s" % (user.get_id())) if opts.force: pynimbusauthz.print_msg(opts, 1, "Removing all references") user.destroy_brutally() else: user.destroy() db_obj.commit() except AuthzException, ae: print ae return ae.get_rc()