Skip to content

Commit

Permalink
perf(kiali): add context, remove kiali-common and refactor backend
Browse files Browse the repository at this point in the history
  • Loading branch information
aljesusg committed Jan 18, 2024
1 parent cf5fe74 commit f60f53c
Show file tree
Hide file tree
Showing 442 changed files with 19,680 additions and 6,034 deletions.
9 changes: 0 additions & 9 deletions plugins/kiali-backend/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@ export interface Config {
* Url of the hub cluster API endpoint
*/
url: string;
/**
* Strategy used to auth with Kiali
* - anonymous
* - token
*
* More info in https://kiali.io/docs/configuration/authentication/
*
*/
strategy: string;
/**
* Service Account Token which is used for querying data from Kiali
* @visibility secret
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,66 @@
import moment from 'moment';
import { Logger } from 'winston';

import { config, KialiDetails } from '@janus-idp/backstage-plugin-kiali-common';

export type Session = {
expiresOn: string;
username: string;
};
import { KialiDetails } from '../service/config';

export const MILLISECONDS = 1000;
export const AUTH_KIALI_TOKEN = 'kiali-token-aes';

const timeOutforWarningUser = 60 * MILLISECONDS;

export enum AuthStrategy {
anonymous = 'anonymous',
openshift = 'openshift',
token = 'token',
openid = 'openid',
header = 'header',
}

export interface SessionInfo {
username?: string;
expiresOn?: string;
}

export interface AuthConfig {
authorizationEndpoint?: string;
logoutEndpoint?: string;
logoutRedirect?: string;
strategy?: AuthStrategy;
}

export type AuthInfo = {
sessionInfo: SessionInfo;
} & AuthConfig;

export class KialiAuthentication {
protected session: Session;
protected cookie: string;
private KialiDetails: KialiDetails;
protected auth: AuthInfo;
private readonly sessionSeconds: number;

constructor(KD: KialiDetails) {
this.KialiDetails = KD;
this.sessionSeconds = KD.sessionTime
? KD.sessionTime * MILLISECONDS
: config.session.timeOutforWarningUser;
this.session = { expiresOn: '', username: 'anonymous' };
: timeOutforWarningUser;
this.auth = {
sessionInfo: { expiresOn: '', username: 'anonymous' },
};
this.cookie = '';
}

setAuthInfo = (auth: AuthInfo) => {
this.auth = auth;
};

getSession = () => {
return this.session;
return this.auth;
};

getCookie = () => {
return this.cookie;
};

setSession = (session: Session) => {
this.session = session;
setSession = (session: SessionInfo) => {
this.auth.sessionInfo = session;
};

checkIfExtendSession = () => {
Expand All @@ -52,7 +79,7 @@ export class KialiAuthentication {
};

private timeLeft = (): number => {
const expiresOn = moment(this.session.expiresOn);
const expiresOn = moment(this.auth.sessionInfo.expiresOn);

if (expiresOn <= moment()) {
return -1;
Expand All @@ -62,12 +89,12 @@ export class KialiAuthentication {
};

shouldRelogin = (): boolean => {
if (this.KialiDetails.strategy === 'anonymous') {
if (this.auth.strategy === 'anonymous') {
return false;
}
if (this.cookie === '') {
return true;
}
return moment(this.session.expiresOn).diff(moment()) <= 0;
return moment(this.auth.sessionInfo.expiresOn).diff(moment()) <= 0;
};
}
Loading

0 comments on commit f60f53c

Please sign in to comment.