<jupyter_start><jupyter_text>Set up a new workflow registry on LifeMonitor  * Registries are the main type of actors allowed to interact with LifeMonitor * They act both as clients and identity providers * The protocol used to authorize both sides of the communication is OAuth2. In more detail, we use:    1. the **authorization code** grant type to authenticate users from workflow registries and authorize LifeMonitor to get their data as needed - actually we get only info about user profiles and workflows.    2. the **client credentials** grant type to authorize requests from registries * The reference model of workflow registry we consider is [Seek](https://github.com/seek4science/seek) (aka **WorkflowHub**) which is actually the only supported at the moment. But, in principle, every type of workflow registry which, like WorkflowHub, supports OAuth2 as authorization protocol can be easily integrated in LifeMonitor.  Register LifeMonitor as Workflow Registry Client The first step to set up a new workflow registry is to provide LifeMonitor with the OAuth2 client credentials it needs to access the registry. This implies you need to register LifeMonitor as OAuth2 client application of your registry.The only info you need from LifeMonitor in this step is the **Redirect URI**, which has always the following form:      /oauth2/authorized/... where `REGISTRY_NAME` is the name you'd like to assign to your registry on LifeMonitor. Taking WorkflowHub as reference, you need to:1. access the **API Applications** configuration page by clicking on your "user name" and then going through *My Profile > Actions > API Applications > New Application*;2. choose a name, 3. set Redirect URI as described above (e.g., https://localhost:8000/oauth2/authorized/seek), 4. activate Confidential and Scopes > Read, 5. submit the form.As a result, you get an **Application UID** and a **Secret** that will be used as **CLIENT_ID** and **CLIENT_SECRET** on the registration process described below.With respect to the WorkflowHub instance included in dev deployment of LifeMonitor, all the steps described above have already been done (for the "admin" user) and the CLIENT_ID and CLIENT_SECRET you need to complete the registration are:<jupyter_code>APP_UID = "ehukdECYQNmXxgJslBqNaJ2J4lPtoX_GADmLNztE8MI"
SECRET = "<KEY>"<jupyter_output><empty_output><jupyter_text>Add the registry to LifeMonitor LifeMonitor provides an administrative CLI to manage workflow registries which can be accessed from the root path the LifeMonitor folder by typing:```bash flask registry --help```If you are using the LifeMonitor `docker-compose` deployment, you can run the command within the `lm` container by typing:<jupyter_code>!docker-compose exec lm /bin/bash -c "flask registry --help"<jupyter_output>INFO:lifemonitor.app:Logging is active. Log level: INFO
Usage: flask registry [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Show this message and exit.

Commands:
  add     Add a new workflow registry and generate its OAuth2 credentials
  list    List all workflow registries
  show    Show info of a workflow registry
  update  Update a workflow registry<jupyter_text>The `registry add` command takes as input the following parameters: ```bashINFO:lifemonitor.app:Logging is active. Log level: INFOUsage: flask registry add [OPTIONS] NAME [[seek]] CLIENT_ID CLIENT_SECRET                          API_URL  Add a new workflow registry and generate its OAuth2 credentialsOptions:  --redirect-uris TEXT            Redirect URIs (comma separated) to be used                                  with authorization code flow  --client-auth-method [client_secret_basic|client_secret_post]                                  Specifies the method used for authenticating                                  the registry with LifeMonitor  --help                          Show this message and exit.``` With respect to the `seek` registry instance we are considering, they should be set as follows:<jupyter_code>NAME = "seek"                             # the name to be assigned to the registry on LifeMonitor
TYPE = "seek"                             # the registry type ('seek' is the only value allowed at the moment)
CLIENT_ID = APP_UID                       # LifeMonitor APP_UID from WorkflowHub
CLIENT_SECRET = SECRET                    # LifeMonitor SECRET from WorkflowHub
CLIENT_AUTH_METHOD="client_secret_post"   # OAuth2 authentication method (client_secret_post|client_secret_basic) 
API_URL="https://seek:3000"               # URL of the workflow registry
REDIRECT_URIS="https://seek:3000"         # URL of the OAuth2 callback on the workflow registry<jupyter_output><empty_output><jupyter_text>You can now easily add your registry on LifeMonitor through the following command (assumed to be launched from the root of the LifeMonitor repository):<jupyter_code>add_registry_cmd = f"""
docker-compose exec lm /bin/bash -c \
"flask registry add {NAME} {TYPE} {CLIENT_ID} {CLIENT_SECRET} {API_URL} \
--client-auth-method {CLIENT_AUTH_METHOD} \
--redirect-uris {REDIRECT_URIS}"
"""
print(add_registry_cmd)
!{add_registry_cmd}<jupyter_output>INFO:lifemonitor.app:Logging is active. Log level: INFO
INFO:lifemonitor.commands.registry:Registry 'seek' created!


****************************************************************************************************
Workflow Registry 'seek' (uuid: 1c40002b-8676-4f51-b529-9ff02ff78234, type: seek) registered!
****************************************************************************************************


OAuth2 settings to connect to LifeMonitor:
----------------------------------------------------------------------------------------------------
REGISTRY NAME: seek
REGISTRY API URL: https://seek:3000
REGISTRY CLIENT ID: bAVlsOwx2Z7sPgQJU7mdg1CE
REGISTRY CLIENT SECRET: <KEY>
REGISTRY CLIENT ALLOWED SCOPES: read write
REGISTRY CLIENT ALLOWED FLOWS: ['client_credentials', 'authorization_code', 'refresh_token']
REGISTRY CLIENT REDIRECT URIs: ['https://seek:3000']
REGISTRY CLIENT AUTH METHOD: client_secret_post
AUTHORIZE URL: <LIFE_MONITOR_[...]
{'fraction_non_alphanumeric': 0.11322925225965488, 'fraction_numerical': 0.011503697617091208, 'mean_word_length': 3.9722222222222223, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 21, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '204446', 'license': 'MIT', 'n_tokens_mistral': 1668, 'n_tokens_neox': 1553, 'n_words': 670, 'path': 'examples/1_WorkflowRegistrySetup.ipynb', 'repo_name': 'ilveroluca/life_monitor', 'size': '6166'}