Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
Panaetius committed Jan 24, 2024
1 parent cdfafa4 commit 96ec411
Show file tree
Hide file tree
Showing 31 changed files with 143 additions and 144 deletions.
2 changes: 1 addition & 1 deletion client/src/features/session/sessions.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const sessionsApi = createApi({
({
id: sessionName,
type: "Session",
}) as const,
} as const)
),
"Session",
]
Expand Down
8 changes: 4 additions & 4 deletions server/src/api-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class APIClient {
*
*/
async getSessionStatus(
authHeathers: Record<string, string>
authHeathers: Record<string, string>,
): Promise<Response> {
const sessionsUrl = `${this.gatewayUrl}/notebooks/servers`;
logger.debug(`Fetching session status.`);
Expand All @@ -55,15 +55,15 @@ class APIClient {
*/
async kgActivationStatus(
projectId: number,
authHeaders: Headers
authHeaders: Headers,
): Promise<Response> {
const headers = new Headers(authHeaders);
const activationStatusURL = `${this.gatewayUrl}/projects/${projectId}/graph/status`;
logger.info(`Fetching kg activation from ${projectId} project`);
return this.clientFetch(
activationStatusURL,
{ headers },
RETURN_TYPES.json
RETURN_TYPES.json,
);
}

Expand All @@ -78,7 +78,7 @@ class APIClient {
async clientFetch(
url: string,
options = FETCH_DEFAULT.options,
returnType = FETCH_DEFAULT.returnType
returnType = FETCH_DEFAULT.returnType,
): Promise<Response> {
return this._renkuFetch(url, options)
.catch((error: unknown) => {
Expand Down
44 changes: 21 additions & 23 deletions server/src/authentication/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Authenticator {
callbackUrl: string = config.server.url +
config.server.prefix +
config.routes.auth +
"/callback"
"/callback",
) {
// Validate and save parameters
for (const param of [
Expand Down Expand Up @@ -112,7 +112,7 @@ class Authenticator {
logger.error(
"Cannot initialize the auth client. The authentication server may be down or some paramaters may be wrong. " +
`Attempt number ${this.retryAttempt} of ${maxAttempts} ` +
"Please check the next log entry for further details."
"Please check the next log entry for further details.",
);
logger.error(error);
if (this.retryAttempt < maxAttempts) {
Expand All @@ -126,7 +126,7 @@ class Authenticator {
private checkInit(): boolean {
if (!this.ready) {
const newError = new Error(
"Cannot interact with the authentication server. Did you invoke `await init()`?"
"Cannot interact with the authentication server. Did you invoke `await init()`?",
);
logger.error(newError);
throw newError;
Expand All @@ -150,7 +150,7 @@ class Authenticator {
*/
private async deleteStorageValue(
storageKey: string,
actionDesc: string
actionDesc: string,
): Promise<boolean> {
const numDeleted = await this.storage.delete(storageKey);
if (numDeleted < 0) {
Expand All @@ -163,19 +163,19 @@ class Authenticator {
}

private async getStorageValueAsString(
key: string
key: string,
): Promise<GetStorageValueReturn> {
const storageKey = `${config.auth.storagePrefix}${key}`;
const storageValue = await this.storage.get(
storageKey,
this.getStorageOptions
this.getStorageOptions,
);
return { storageKey, value: storageValue as string };
}

private async saveStorageValueAsString(
key: string,
value: string
value: string,
): Promise<boolean> {
const storageKey = `${config.auth.storagePrefix}${key}`;
return await this.storage.save(storageKey, value, this.saveStorageOptions);
Expand All @@ -191,7 +191,7 @@ class Authenticator {
*/
async getPostLoginParametersAndDelete(
sessionId: string,
deleteAfter = true
deleteAfter = true,
): Promise<string> {
const parametersKey = this.getParametersKey(sessionId);
const { storageKey, value: parametersString } =
Expand All @@ -200,7 +200,7 @@ class Authenticator {
if (deleteAfter) {
await this.deleteStorageValue(
storageKey,
`login parameters for session ${sessionId}`
`login parameters for session ${sessionId}`,
);
}
return parametersString;
Expand All @@ -213,7 +213,7 @@ class Authenticator {
*/
async startAuthFlow(
sessionId: string,
redirectParams: string = null
redirectParams: string = null,
): Promise<string> {
// ? REF: https://darutk.medium.com/diagrams-of-all-the-openid-connect-flows-6968e3990660
this.checkInit();
Expand Down Expand Up @@ -268,37 +268,36 @@ class Authenticator {

// get the verifier code and remove it from redis
const verifierKey = this.getVerifierKey(sessionId);
const { storageKey, value: verifier } = await this.getStorageValueAsString(
verifierKey
);
const { storageKey, value: verifier } =
await this.getStorageValueAsString(verifierKey);
if (verifier == null) {
const error =
"Code challenge not available. Are you re-loading an old page?";
throw new APIError(
"Auth callback reloading page error",
HttpStatusCode.INTERNAL_SERVER,
error
error,
);
}

await this.deleteStorageValue(
storageKey,
`cleanup verifier for ${sessionId}`
`cleanup verifier for ${sessionId}`,
);

try {
const tokens = await this.authClient.callback(
this.callbackUrl,
{ code },
{ code_verifier: verifier }
{ code_verifier: verifier },
);
if (tokens) return tokens;
return null;
} catch (error) {
throw new APIError(
"Error callback for Authorization Server",
HttpStatusCode.INTERNAL_SERVER,
error
error,
);
}
}
Expand All @@ -314,7 +313,7 @@ class Authenticator {

const result = await this.saveStorageValueAsString(
sessionId,
JSON.stringify(tokens)
JSON.stringify(tokens),
);
if (!result) {
const errorMessage = `Could not store refresh tokens for session ${sessionId}`;
Expand All @@ -335,9 +334,8 @@ class Authenticator {
this.checkInit();

// Get tokens from the store
const { value: stringyTokens } = await this.getStorageValueAsString(
sessionId
);
const { value: stringyTokens } =
await this.getStorageValueAsString(sessionId);
if (stringyTokens == null) return null;
let tokens = new TokenSet(JSON.parse(stringyTokens) as TokenSet);

Expand Down Expand Up @@ -386,7 +384,7 @@ class Authenticator {
this.checkInit();
return await this.deleteStorageValue(
`${config.auth.storagePrefix}${sessionId}`,
`tokens for session ${sessionId}`
`tokens for session ${sessionId}`,
);
}

Expand All @@ -398,7 +396,7 @@ class Authenticator {
async refreshTokens(
sessionId: string,
tokens: TokenSet = null,
removeIfFailed = true
removeIfFailed = true,
): Promise<TokenSet> {
// get the tokens from the store when not provided.
if (tokens == null) {
Expand Down
4 changes: 2 additions & 2 deletions server/src/authentication/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function renkuAuth(authenticator: Authenticator) {
return async (
req: express.Request,
res: express.Response,
next: express.NextFunction
next: express.NextFunction,
): Promise<void> => {
// get or create session
const sessionId = getOrCreateSessionId(req, res);
Expand Down Expand Up @@ -89,7 +89,7 @@ function renkuAuth(authenticator: Authenticator) {

async function wsRenkuAuth(
authenticator: Authenticator,
sessionId: string
sessionId: string,
): Promise<WsMessage | Record<string, string>> {
let tokens: TokenSet;
try {
Expand Down
6 changes: 3 additions & 3 deletions server/src/authentication/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { Authenticator } from "./index";
function getOrCreateSessionId(
req: express.Request,
res: express.Response,
serverPrefix: string = config.server.prefix
serverPrefix: string = config.server.prefix,
): string {
const cookiesKey = config.auth.cookiesKey;
let sessionId: string;
Expand Down Expand Up @@ -65,7 +65,7 @@ function getStringyParams(req: express.Request): string {

function registerAuthenticationRoutes(
app: express.Application,
authenticator: Authenticator
authenticator: Authenticator,
): void {
const authPrefix = config.server.prefix + config.routes.auth;

Expand All @@ -76,7 +76,7 @@ function registerAuthenticationRoutes(
const inputParams = getStringyParams(req);
const loginCodeUrl = await authenticator.startAuthFlow(
sessionId,
inputParams
inputParams,
);

res.redirect(loginCodeUrl);
Expand Down
12 changes: 6 additions & 6 deletions server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@ const DEPLOYMENT = {
gatewayUrl,
gatewayLoginUrl: urlJoin(
gatewayUrl,
process.env.GATEWAY_LOGIN_PATH || "/auth/login"
process.env.GATEWAY_LOGIN_PATH || "/auth/login",
),
gatewayLogoutUrl: urlJoin(
gatewayUrl,
process.env.GATEWAY_LOGOUT_PATH || "/auth/logout"
process.env.GATEWAY_LOGOUT_PATH || "/auth/logout",
),
};

const SENTRY = {
enabled: ["true", "1"].includes(
(process.env.SENTRY_ENABLED ?? "").toLowerCase()
(process.env.SENTRY_ENABLED ?? "").toLowerCase(),
),
url: process.env.SENTRY_URL || undefined,
namespace: process.env.SENTRY_NAMESPACE || undefined,
telepresence: !!process.env.TELEPRESENCE,
sampleRate: parseFloat(process.env.SENTRY_TRACE_RATE) || 0,
debugMode: ["true", "1"].includes(
(process.env.SENTRY_DEBUG ?? "").toLowerCase()
(process.env.SENTRY_DEBUG ?? "").toLowerCase(),
),
};

Expand Down Expand Up @@ -97,7 +97,7 @@ const DATA = {

const WEBSOCKET = {
enabled: ["true", "1"].includes(
(process.env.WEBSOCKET_ENABLED ?? "").toLowerCase()
(process.env.WEBSOCKET_ENABLED ?? "").toLowerCase(),
),
shortIntervalSec: 5, // ? in seconds
longIntervalSec: 180, // ? in seconds
Expand All @@ -107,7 +107,7 @@ const WEBSOCKET = {

const PROMETHEUS = {
enabled: ["true", "1"].includes(
(process.env.PROMETHEUS_ENABLED ?? "").toLowerCase()
(process.env.PROMETHEUS_ENABLED ?? "").toLowerCase(),
),
path: "/metrics",
};
Expand Down
2 changes: 1 addition & 1 deletion server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ app.use(
if (!req.url.startsWith(config.server.prefix)) return true;
return false;
},
})
}),
);

logger.info("Server configuration: " + JSON.stringify(config));
Expand Down
Loading

0 comments on commit 96ec411

Please sign in to comment.