Skip to content

Commit

Permalink
fix: support fallback to env variable for JH token
Browse files Browse the repository at this point in the history
  • Loading branch information
x-oflisback committed Jun 27, 2023
1 parent ab8da03 commit 73833b2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
27 changes: 17 additions & 10 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,28 @@ class Api {
}: {
impactApiKey?: string
impactToken?: string
jupyterHubToken: string
jupyterHubToken?: string
serverAddress: string
jupyterHubUserPath?: string
}) {
this.baseUrl = serverAddress
this.impactApiKey = impactApiKey
this.impactToken = impactToken

if (!jupyterHubToken) {
throw new ApiError({
errorCode: MissingJupyterHubToken,
message:
'Impact client instantiation failed: The jupyterHubToken parameter is mandatory',
})
if (jupyterHubToken) {
this.jhToken = jupyterHubToken
} else {
// No provided JupyterHub token, to mimick impact-python-client we try to
// fallback on the environment variable available inside JupyterHub.
if (process.env.JUPYTERHUB_API_TOKEN) {
this.jhToken = process.env.JUPYTERHUB_API_TOKEN
} else {
throw new ApiError({
errorCode: MissingJupyterHubToken,
message:
'Impact client instantiation failed: Missing JupyterHub token.',
})
}
}

if (jupyterHubUserPath) {
Expand All @@ -113,7 +121,6 @@ class Api {
(jupyterHubUserPath.endsWith('/') ? '' : '/')
}

this.jhToken = jupyterHubToken
this.configureAxios()
}

Expand All @@ -124,7 +131,7 @@ class Api {
serverAddress,
}: {
impactApiKey: string
jupyterHubToken: string
jupyterHubToken?: string
jupyterHubUserPath?: string
serverAddress: string
}) {
Expand All @@ -143,7 +150,7 @@ class Api {
serverAddress,
}: {
impactToken: string
jupyterHubToken: string
jupyterHubToken?: string
jupyterHubUserPath?: string
serverAddress: string
}) {
Expand Down
4 changes: 2 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Client {
serverAddress,
}: {
impactApiKey: string
jupyterHubToken: string
jupyterHubToken?: string
jupyterHubUserPath?: string
serverAddress: string
}) {
Expand All @@ -36,7 +36,7 @@ class Client {
serverAddress,
}: {
impactToken: string
jupyterHubToken: string
jupyterHubToken?: string
jupyterHubUserPath?: string
serverAddress: string
}) {
Expand Down

0 comments on commit 73833b2

Please sign in to comment.