Skip to content

Commit 3c90d6b

Browse files
author
Alberto Gutierrez
committed
Kiali version control
1 parent 9b5ec90 commit 3c90d6b

File tree

6 files changed

+62
-25
lines changed

6 files changed

+62
-25
lines changed

plugins/kiali-backend/src/clients/KialiAPIConnector.ts

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
import { Logger } from 'winston';
22

3+
import supported from '../kiali_supported.json';
34
import { KialiDetails } from '../service/config';
4-
import { KialiFetcher } from './fetch';
5+
import { AuthValid, KialiFetcher } from './fetch';
56

67
export type Options = {
78
logger: Logger;
89
kiali: KialiDetails;
910
};
1011

12+
const KIALI_CORE_VERSION = 'Kiali version';
13+
14+
type Status = { [K: string]: string };
15+
16+
interface StatusState {
17+
status: Status;
18+
}
19+
1120
export interface KialiApi {
1221
proxy(endpoint: string, method?: string): Promise<any>;
1322
}
@@ -21,7 +30,26 @@ export class KialiApiImpl implements KialiApi {
2130
this.kialiFetcher = new KialiFetcher(options.kiali, options.logger);
2231
}
2332

24-
async proxy(endpoint: string, method: string): Promise<any> {
33+
supportedVersion = (version: string): string | undefined => {
34+
this.logger.info('Validating kiali version');
35+
const versionSupported = supported[KIALI_CORE_VERSION].replace(
36+
/^./,
37+
'',
38+
).split('.');
39+
const versionClean = version.replace(/^./, '').split('.');
40+
this.logger.info(
41+
`Kiali Version supported ${supported[KIALI_CORE_VERSION]}`,
42+
);
43+
if (
44+
versionSupported[0] === versionClean[0] &&
45+
versionSupported[1] === versionClean[1]
46+
) {
47+
return undefined;
48+
}
49+
return `kiali version supported is ${supported[KIALI_CORE_VERSION]}, we found version ${version}`;
50+
};
51+
52+
async proxy(endpoint: string): Promise<any> {
2553
const authValid = await this.kialiFetcher.checkSession();
2654
if (authValid.verify) {
2755
this.logger.debug(
@@ -30,7 +58,7 @@ export class KialiApiImpl implements KialiApi {
3058
}`,
3159
);
3260
return this.kialiFetcher
33-
.newRequest<any>(endpoint, false, method)
61+
.newRequest<any>(endpoint, false)
3462
.then(resp => resp.data);
3563
}
3664
this.logger.debug(
@@ -45,9 +73,21 @@ export class KialiApiImpl implements KialiApi {
4573
async status(): Promise<any> {
4674
const authValid = await this.kialiFetcher.checkSession();
4775
if (authValid.verify) {
48-
return this.kialiFetcher
49-
.newRequest<any>('api/status')
50-
.then(resp => resp.data);
76+
return this.kialiFetcher.newRequest<any>('api/status').then(resp => {
77+
const st: StatusState = resp.data;
78+
const versionControl = this.supportedVersion(
79+
st.status[KIALI_CORE_VERSION],
80+
);
81+
if (versionControl) {
82+
const response: AuthValid = {
83+
verify: false,
84+
title: 'kiali version not supported',
85+
message: versionControl,
86+
};
87+
return Promise.resolve(response);
88+
}
89+
return Promise.resolve(resp.data);
90+
});
5191
}
5292
return Promise.resolve(authValid);
5393
}

plugins/kiali-backend/src/clients/fetch.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414

1515
export type AuthValid = {
1616
verify: boolean;
17+
title?: string;
1718
missingAttributes?: string[];
1819
message?: string;
1920
helper?: string;
@@ -32,13 +33,9 @@ export class KialiFetcher {
3233
this.kialiAuth = new KialiAuthentication(KD);
3334
}
3435

35-
newRequest = async <P>(
36-
endpoint: string,
37-
auth: boolean = false,
38-
method?: string,
39-
) => {
36+
newRequest = async <P>(endpoint: string, auth: boolean = false) => {
4037
this.logger.info(`Query to ${endpoint}`);
41-
return axios.request<P>(this.getRequestInit(endpoint, auth, method));
38+
return axios.request<P>(this.getRequestInit(endpoint, auth));
4239
};
4340

4441
private async getAuthInfo(): Promise<AuthInfo> {
@@ -63,6 +60,7 @@ export class KialiFetcher {
6360
this.KialiDetails.serviceAccountToken === ''
6461
) {
6562
result.verify = false;
63+
result.title = 'Authentication failed';
6664
result.message = `Attribute 'serviceAccountToken' is not in the backstage configuration`;
6765
result.helper = `For more information follow the steps in https://janus-idp.io/plugins/kiali`;
6866
result.missingAttributes = ['serviceAccountToken'];
@@ -71,6 +69,7 @@ export class KialiFetcher {
7169
}
7270
default:
7371
result.verify = false;
72+
result.title = 'Authentication failed';
7473
result.message = `Strategy ${auth.strategy} is not supported in Kiali backstage plugin yet`;
7574
break;
7675
}
@@ -107,6 +106,7 @@ export class KialiFetcher {
107106
})
108107
.catch(err => {
109108
checkAuth.verify = false;
109+
checkAuth.title = 'Authentication failed';
110110
checkAuth.message = this.handleUnsuccessfulResponse(err);
111111
});
112112
}
@@ -126,7 +126,6 @@ export class KialiFetcher {
126126
private getRequestInit = (
127127
endpoint: string,
128128
auth: boolean = false,
129-
method?: string,
130129
): AxiosRequestConfig => {
131130
const requestInit: AxiosRequestConfig = { timeout: TIMEOUT_FETCH };
132131
const headers = { 'X-Auth-Type-Kiali-UI': '1' };
@@ -141,7 +140,7 @@ export class KialiFetcher {
141140
requestInit.data = params;
142141
requestInit.method = 'post';
143142
} else {
144-
requestInit.method = method ? method : 'get';
143+
requestInit.method = 'get';
145144
requestInit.headers = {
146145
...headers,
147146
Accept: 'application/json',
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"Kiali version": "v1.73"
3+
}

plugins/kiali-backend/src/service/router.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ export const makeRouter = (
2222
// curl -H "Content-type: application/json" -H "Accept: application/json" -X GET localhost:7007/api/kiali/proxy --data '{"endpoint": "api/namespaces"}'
2323
router.post('/proxy', async (req, res) => {
2424
const endpoint = req.body.endpoint;
25-
const method = req.body.method;
26-
2725
logger.info(`Call to Kiali ${endpoint}`);
28-
res.json(await kialiAPI.proxy(endpoint, method));
26+
res.json(await kialiAPI.proxy(endpoint));
2927
});
3028

3129
router.post('/status', async (_, res) => {

plugins/kiali/src/pages/Kiali/KialiHelper.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,13 @@ export const KialiHelper = (props: { check: KialiChecker }) => {
5757
</>
5858
);
5959

60-
const getTitle = () => {
61-
if (!props.check.verify) {
62-
return 'Authentication failed.';
63-
}
64-
65-
return 'Unexpected Check';
66-
};
60+
const printVersionProblem = <>{props.check.message}</>;
6761
return (
6862
<Page themeId="tool">
6963
<Content>
70-
<WarningPanel title={getTitle()}>{printAuthentication}</WarningPanel>
64+
<WarningPanel title={props.check.title || 'Unexpected Check'}>
65+
{props.check.authData ? printAuthentication : printVersionProblem}
66+
</WarningPanel>
7167
</Content>
7268
</Page>
7369
);

plugins/kiali/src/store/KialiProvider.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { KialiContext } from './Context';
3939
export type KialiChecker = {
4040
verify: boolean;
4141
missingAttributes?: string[];
42+
title?: string;
4243
message?: string;
4344
helper?: string;
4445
authData?: AuthInfo;

0 commit comments

Comments
 (0)