Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Web bulk upload updates #210

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions importer/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,47 @@
config.py
importer.log

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

.python-version

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
2 changes: 1 addition & 1 deletion importer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This script is used to setup keycloak roles and groups. It takes in a csv file w
### To run script
1. Create virtualenv
2. Install requirements.txt - `pip install -r requirements.txt`
3. Create a `config.py` file. The `sample_config.py` is an example of what this should look like. Populate it with the right credentials, you can either provide an access token or client credentials. Ensure that the user whose details you provide in this config file has the necessary permissions/privilleges.
3. Create a `config/config.py` file. The `config/sample_config.py` is an example of what this should look like. Populate it with the right credentials, you can either provide an access token or client credentials. Ensure that the user whose details you provide in this config file has the necessary permissions/privilleges.
4. Run script - `python3 main.py --setup roles --csv_file csv/setup/roles.csv --group Supervisor`
5. If you are running the script without `https` setup e.g locally or a server without https setup, you will need to set the `OAUTHLIB_INSECURE_TRANSPORT` environment variable to 1. For example `export OAUTHLIB_INSECURE_TRANSPORT=1 && python3 main.py --setup roles --csv_file csv/setup/roles.csv --group OpenSRP_Provider --log_level debug`
6. You can turn on logging by passing a `--log_level` to the command line as `info`, `debug` or `error`. For example `python3 main.py --setup roles --csv_file csv/setup/roles.csv --group Supervisor --log_level debug`
Expand Down
File renamed without changes.
17 changes: 17 additions & 0 deletions importer/config/sample_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
client_id = 'example-client-id'
client_secret = 'example-client-secret'
fhir_base_url = 'https://example.smartregister.org/fhir'
keycloak_url = 'https://keycloak.smartregister.org/auth'

# access token for access to where product images are remotely stored
product_access_token = 'example-product-access-token'

# if using resource owner credentials (i.e importer handles getting authentication by itself)
# This has greater precedence over the access and refresh tokens if supplied
username = 'example-username'
password = 'example-password'

# if embedding importer into a service that already does the authentication
access_token = 'example-access-token'
refresh_token = 'example-refresh-token'

41 changes: 41 additions & 0 deletions importer/config/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import importlib
import sys
import logging.config

from services.fhir_keycloak_api import FhirKeycloakApi, FhirKeycloakApiOptions, ExternalAuthenticationOptions, \
InternalAuthenticationOptions
from config.config import client_id, client_secret, fhir_base_url, keycloak_url, realm


def dynamic_import(variable_name):
try:
config_module = importlib.import_module("config.config")
value = getattr(config_module, variable_name, None)
return value
except:
logging.error("Unable to import the configuration!")
sys.exit(1)


username = dynamic_import("username")
password = dynamic_import("password")

# TODO - retrieving at and rt as args via the command line as well.
access_token = dynamic_import("access_token")
refresh_token = dynamic_import("refresh_token")
product_access_token = dynamic_import("product_access_token")

authentication_options = None
if username is not None and password is not None:
authentication_options = InternalAuthenticationOptions(client_id=client_id, client_secret=client_secret, keycloak_base_uri=keycloak_url, realm=realm, user_username=username, user_password=password)
elif access_token is not None and refresh_token is not None:
authentication_options = ExternalAuthenticationOptions(client_id=client_id, client_secret=client_secret, keycloak_base_uri=keycloak_url, realm=realm, access_token=access_token, refresh_token=refresh_token)
else:
raise ValueError("Unable to get authentication parameters!")

api_service_options = FhirKeycloakApiOptions(fhir_base_uri=fhir_base_url, authentication_options=authentication_options)
api_service = FhirKeycloakApi(api_service_options)




10 changes: 10 additions & 0 deletions importer/json_payloads/locations_payload.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@
"display": "Level $adminLevelCode"
}
]
},
{
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/location-physical-type",
"code": "$pt_code",
"display": "$pt_display"
}
]
}

],
"physicalType": {
"coding": [
Expand Down
Loading
Loading