Skip to content

Commit

Permalink
Merge pull request #42 from CanDIG/feature/whoami
Browse files Browse the repository at this point in the history
Feature/whoami
  • Loading branch information
OrdiNeu authored Jun 19, 2024
2 parents 700c195 + 11e4a67 commit 8c5c476
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
1 change: 0 additions & 1 deletion config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ CANDIG_KATSU_URL = <KATSU_URL>

[authz]
CANDIG_OPA_URL = <OPA_URL>
CANDIG_VAULT_URL = <VAULT_URL>
1 change: 1 addition & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
if [[ -f "initial_setup" ]]; then
sed -i s@\<HTSGET_URL\>@$CANDIG_HTSGET_URL@ config.ini
sed -i s@\<KATSU_URL\>@$CANDIG_KATSU_URL@ config.ini
sed -i s@\<OPA_URL\>@$OPA_URL@ config.ini

rm initial_setup
fi
Expand Down
1 change: 1 addition & 0 deletions query_server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

HTSGET_URL = config['DEFAULT']['CANDIG_HTSGET_URL']
KATSU_URL = config['DEFAULT']['CANDIG_KATSU_URL']
OPA_URL = config['authz']['CANDIG_OPA_URL']

DEBUG_MODE = False
if os.getenv("DEBUG_MODE", "1") == "1":
Expand Down
21 changes: 21 additions & 0 deletions query_server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ paths:
$ref: '#/components/schemas/DiscoveryProgramBody'
5XX:
$ref: "#/components/responses/5xxServerError"
/whoami:
get:
summary: Retrieve the user key (usually the email) for the currently logged-in user
description: Retrieve the user key (usually the email) for the currently logged-in user
operationId: query_operations.whoami
responses:
200:
description: User info
content:
application/json:
schema:
$ref: '#/components/schemas/UserInfo'
5XX:
$ref: "#/components/responses/5xxServerError"

components:
parameters:
Expand Down Expand Up @@ -254,6 +268,13 @@ components:
programs:
type: array
description: Per-program summary statistics
UserInfo:
type: object
description: Information about a user
properties:
key:
type: string
description: The user key associated with this user. Usually an email
# ERROR SCHEMAS
Error:
type: object
Expand Down
22 changes: 22 additions & 0 deletions query_server/query_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import requests
import secrets
import urllib
from authx.auth import get_user_id, get_auth_token

import config

Expand Down Expand Up @@ -490,3 +491,24 @@ def discovery_query(treatment="", primary_site="", chemotherapy="", immunotherap
summary_stats = censor_response(summary_stats)

return fix_dicts(summary_stats), 200

@app.route('/whoami')
def whoami():
# Grab information about the currently logged-in user
print(config.OPA_URL)
print(config.AUTHZ)
token = get_auth_token(request)
headers = {
"Authorization": f"Bearer {token}"
}
response = requests.post(
config.OPA_URL + f"/v1/data/idp/user_key",
headers=headers,
json={
"input": {
"token": token
}
}
)
print(response)
return { 'key': get_user_id(request, opa_url = config.OPA_URL) }

0 comments on commit 8c5c476

Please sign in to comment.