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

Feature/whoami #42

Merged
merged 1 commit into from
Jun 19, 2024
Merged
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
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) }