def upload_file(self, group_id: str, file: IOHandle, name: str) -> Dict: """Create a file for a given workflow group. Parameters ---------- group_id: string Unique workflow group identifier file: fflowserv.model.files.base.IOHandle File object (e.g., uploaded via HTTP request) name: string Name of the file Returns ------- dict Raises ------ flowserv.error.ConstraintViolationError flowserv.error.UnauthorizedAccessError flowserv.error.UnknownWorkflowGroupError """ files = {'files': (name, file.open())} url = self.urls(route.FILES_UPLOAD, userGroupId=group_id) return post(url=url, files=files)
def login_user(self, username: str, password: str) -> Dict: """Get handle for user with given credentials. Raises error if the user is unknown or if invalid credentials are provided. Parameters ---------- username: string Unique name of registered user password: string User password (in plain text) Returns ------- dict """ data = { self.labels['USER_NAME']: username, self.labels['USER_PASSWORD']: password } body = post(url=self.urls(route.USERS_LOGIN), data=data) # Get the access tokrn from the response body and update the global # evironment variable. token = body[self.labels['USER_TOKEN']] os.environ[config.FLOWSERV_ACCESS_TOKEN] = token return body
def start_run(self, group_id: str, arguments: List[Dict]) -> Dict: """Start a new workflow run for the given group. The user provided arguments are expected to be a list of (key,value)-pairs. The key value identifies the template parameter. The data type of the value depends on the type of the parameter. Returns a serialization of the handle for the started run. Raises an unauthorized access error if the user does not have the necessary access to modify the workflow group. Parameters ---------- group_id: string Unique workflow group identifier arguments: list(dict) List of user provided arguments for template parameters. Returns ------- dict """ data = {self.labels['RUN_ARGUMENTS']: arguments} url = self.urls(route.RUNS_START, userGroupId=group_id) return post(url=url, data=data)
def update_group(self, group_id: str, name: Optional[str] = None, members: Optional[List[str]] = None) -> Dict: """Update the name for the workflow group with the given identifier. Parameters ---------- group_id: string Unique workflow group identifier name: string, optional New workflow group name members: list(string), optional Modified list of team members Returns ------- dict """ # Create request body. The group name and the list of members are # both optional. data = dict() if name is not None: data[self.labels['GROUP_NAME']] = name if members is not None: data[self.labels['GROUP_MEMBERS']] = members return post(url=self.urls(route.GROUPS_UPDATE, userGroupId=group_id), data=data)
def register_user(self, username: str, password: str, verify: Optional[bool] = False) -> Dict: """Create a new user for the given username and password. Raises an error if a user with that name already exists or if the user name is ivalid (e.g., empty or too long). Returns success object if user was registered successfully. Parameters ---------- username: string User email address that is used as the username password: string Password used to authenticate the user verify: bool, default=False Determines whether the created user is active or inactive Returns ------- dict """ data = { self.labels['USER_NAME']: username, self.labels['USER_PASSWORD']: password, self.labels['VERIFY_USER']: verify } return post(url=self.urls(route.USERS_REGISTER), data=data)
def request_password_reset(self, username: str) -> Dict: """Request to reset the password for the user with the given name. The result contains a unique request identifier for the user to send along with their new password. Parameters ---------- username: string Unique user login name """ data = {self.labels['USER_NAME']: username} return post(url=self.urls(route.USERS_PASSWORD_REQUEST), data=data)
def logout_user(self, api_key: str) -> Dict: """Logout given user. Parameters ---------- api_key: string API key for user that is being logged out. Returns ------- dict """ return post(url=self.urls(route.USERS_LOGOUT))
def create_group(self, workflow_id: str, name: str, members: Optional[List[str]] = None, parameters: Optional[List[Parameter]] = None, engine_config: Optional[Dict] = None, identifier: Optional[str] = None) -> Dict: """Create a new user group for a given workflow. Each group has a a unique name for the workflow, and an optional list of additional group members. The group owener will be the authenticated user based on the access token that is provided in the request header. Workflow groups also define variants of the original workflow template by allowing to specify a list of additional template parameters. Parameters ---------- workflow_id: string Unique workflow identifier name: string Unique team name members: list(string), default=None List of user identifier for group members parameters: list of flowserv.model.parameter.base.Parameter, default=None Optional list of parameter declarations that are used to modify the template parameters for submissions of the created group. engine_config: dict, default=None Optional configuration settings that will be used as the default when running a workflow. identifier: string, default=None Optional user-provided group identifier. Returns ------- dict """ # Create request body. The list of members and parameters are optional. data = {self.labels['GROUP_NAME']: name} if members is not None: data[self.labels['GROUP_MEMBERS']] = members if parameters is not None: data[self.labels['GROUP_PARAMETERS']] = [ p.to_dict() for p in parameters ] if identifier is not None: data[self.labels['GROUP_ID']] = identifier if engine_config is not None: data[self.labels['ENGINE_CONFIG']] = engine_config return post(url=self.urls(route.GROUPS_CREATE, workflowId=workflow_id), data=data)
def activate_user(self, user_id: str) -> Dict: """Activate a new user with the given identifier. Parameters ---------- user_id: string Unique user name Returns ------- dict """ data = {self.labels['USER_ID']: user_id} return post(url=self.urls(route.USERS_ACTIVATE), data=data)
def reset_password(self, request_id: str, password: str) -> Dict: """Reset the password for the user that made the given password reset request. Raises an error if no such request exists or if the request has timed out. Returns the serialization of the user handle. Parameters ---------- request_id: string Unique password reset request identifier password: string New user password Returns ------- dict """ data = { self.labels['REQUEST_ID']: request_id, self.labels['USER_PASSWORD']: password } return post(url=self.urls(route.USERS_PASSWORD_RESET), data=data)