def user_create( context: object, username: str, password: str, email: str, first_name: str, last_name: str, role: str, ) -> None: try: config_setup(context) user = User( username=username, password=password, first_name=first_name, last_name=last_name, email=email, role=role if role else "", ) user.add() if user.is_admin(): click.echo(f"Admin user {username} registered") else: click.echo(f"User {username} registered") rv = 0 except Exception as exc: click.echo(exc, err=True) rv = 2 if isinstance(exc, BadConfig) else 1 click.get_current_context().exit(rv)
def execute(self): config = PbenchServerConfig(self.context.config) logger = get_pbench_logger(_NAME_, config) # We're going to need the Postgres DB to track dataset state, so setup # DB access. Database.init_db(config, logger) user = User( username=self.context.username, password=self.context.password, first_name=self.context.first_name, last_name=self.context.last_name, email=self.context.email, role=self.context.role if self.context.role else "", ) user.add() if user.is_admin(): click.echo(f"Admin user {self.context.username} registered") else: click.echo(f"User {self.context.username} registered")