def user(): """Prepare user object.""" profile = fake.simple_profile() user = User(None, username=profile['username'], password=fake.password(), organization=organization(), active=True) user.save() return user
def setup(self): self.auth_header_test = AuthHeader() self.auth_header = self.auth_header_test.get(self.client) self.namespace = self.auth_header['X-Test-Namespace'] self.user = User.load(None, self.auth_header['X-User']) self.provisioner_id = None
def main(): args = parser.parse_args() app = create_app() with app.app_context(): # Organization and user try: organization = Organization( id=organization_id, name=args.organization, namespace=args.namespace, created_at=datetime.utcnow() ) organization.save() print('Organization {} successfully created!'.format(organization.name)) except Exception: raise Exception('Adding {} organization failed'.format(args.organization)) try: user = User.create( None, id=user_id, username=args.username, password=args.password, email='*****@*****.**', organization=organization, created_at=datetime.utcnow(), role='superadmin', active=True ) user.save() print('User {} successfully created!'.format(user.username)) except Exception: raise Exception('Adding {} user failed'.format(args.username))
def __init__(self, namespace=None): profile = fake.simple_profile() self.test_org = OrganizationFixture(namespace) user = User.create(None, username=profile['username'], password=profile['username'] + 'password', organization=self.test_org.obj, role='superadmin', active=True) user.save(validate=False) self.obj = user
def user(): """Prepare user object.""" profile = fake.simple_profile() user = User.create(None, username=profile['username'], password=profile['username'] + 'password', organization=organization(), role='superadmin', active=True) user.save() return user
def identity(payload): """ Read user_id from payload and return User. Args: payload (dict): Request payload Returns: user: detected user """ user_id = payload['identity'] try: user = User.load(None, user_id) except Exception: user = None return user
def authenticate(username, password): """ Authenticate user. Args: username (str): Username to login password (str): Password Returns: user: authenticated user """ # find user by username users = list(User.list(None, return_objects=True).values()) username_table = {u.username: u for u in users} user = username_table.get(username) if user: given_password = password.encode('utf-8') # fallback to local auth, this options is default if nothing is specified if not user.auth: user.auth = "LocalAuth" logger.debug("User {} will be authenticated using {}".format( username, user.auth)) auth_instance = get_auth_instance(user.auth) try: verified_user, verification_error = auth_instance.verify( user, given_password) except Exception as e: logger.exception("Verification method {} failed".format(user.auth)) verified_user, verification_error = None, str(e) if isinstance(verified_user, User) and verified_user.active: return verified_user else: logger.info( "User {user} failed auth using {method} auth method with error {error}" .format( user=user, method=user.auth, error=verification_error, ))
def authenticate(username, password): """ Authenticate user. Args: username (str): Username to login password (str): Passwore Returns: user: authenticated user """ users = list(User.list(return_objects=True).values()) username_table = {u.username: u for u in users} user = username_table.get(username, None) if user and safe_str_cmp(user.password.encode('utf-8'), password.encode('utf-8')): return user
def authenticate(username, password): """ Authenticate user. Args: username (str): Username to login password (str): Password Returns: user: authenticated user """ users = list(User.list(None, return_objects=True).values()) username_table = {u.username: u for u in users} user = username_table.get(username) if user: user_password = user.password.encode('utf-8') given_password = password.encode('utf-8') if user.active and bcrypt.checkpw(given_password, user_password): return user
def user(): """Prepare user object.""" with current_app.app_context(): test_org = OrganizationFixture() profile = fake.simple_profile() user = User.create(None, username=profile['username'], password=profile['username'] + 'password', organization=test_org.obj, role='superadmin', active=True) user.save() yield user try: user.delete() test_org.destroy() except Exception: # objects may be already deleted pass
with app.app_context(): # Organization and user try: organization = Organization( id=uuid_organization, name='DemoOrg', namespace='demoorg' ) organization.save() except: raise Exception('Adding DemoOrg organization failed') try: user = User( username='******', password='******', organization=organization, ) user.save() except: raise Exception('Adding admin user failed') # AWS + Jenkins try: provisioner = Provisioner( id=uuid_provisioner_jenkins, name='Jenkins provisioner to AWS', state='OK', engine='kqueen.engines.JenkinsEngine', parameters={ 'username': '******',
app = create_app() with app.app_context(): # Organization and user try: organization = Organization(id=uuid_organization, name='DemoOrg', namespace='demoorg', created_at=datetime.utcnow()) organization.save() except: raise Exception('Adding DemoOrg organization failed') try: user = User(None, username='******', password='******', organization=organization, created_at=datetime.utcnow(), active=True) user.save() except: raise Exception('Adding admin user failed') # AWS + Jenkins try: provisioner = Provisioner(user.namespace, id=uuid_provisioner_jenkins, name='Jenkins provisioner to AWS', state='OK', engine='kqueen.engines.JenkinsEngine', parameters={ 'username': '******',
with app.app_context(): # Organization and user try: organization = Organization(id=uuid_organization, name='DemoOrg', namespace='demoorg', created_at=datetime.utcnow()) organization.save() except: raise Exception('Adding DemoOrg organization failed') try: user = User.create(None, username='******', password='******', organization=organization, created_at=datetime.utcnow(), role='superadmin', active=True) user.save() except: raise Exception('Adding admin user failed') # AWS + Jenkins try: provisioner = Provisioner(user.namespace, id=uuid_provisioner_jenkins, name='Jenkins provisioner to AWS', state='OK', engine='kqueen.engines.JenkinsEngine', parameters={