Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Do not use authority certificate for requests outside Che container (#…
Browse files Browse the repository at this point in the history
…852)

* Do not use authority certificate for requests outside Che container

Signed-off-by: Vitaliy Gulyy <vgulyy@redhat.com>

* Add comments

Signed-off-by: Vitaliy Gulyy <vgulyy@redhat.com>

* Upate comment

Signed-off-by: Vitaliy Gulyy <vgulyy@redhat.com>
  • Loading branch information
vitaliy-guliy authored Sep 16, 2020
1 parent 0e45380 commit 503ca56
Showing 1 changed file with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ export class ChePluginServiceImpl implements ChePluginService {
}
}

private getAxiosInstance(): AxiosInstance {
if (!this.isItNode()) {
return axios;
}

/**
* If the URI points to default plugin registry, axios will use local authority certificates.
*/
private getAxiosInstance(uri: string): AxiosInstance {
const certificateAuthority = this.getCertificateAuthority();

const proxyUrl = process.env.http_proxy;
const baseUrl = process.env.CHE_API;
if (proxyUrl && proxyUrl !== '' && baseUrl) {
Expand Down Expand Up @@ -145,7 +145,7 @@ export class ChePluginServiceImpl implements ChePluginService {
}
}

if (certificateAuthority) {
if (uri.startsWith(this.defaultRegistry.uri) && certificateAuthority) {
return axios.create({
httpsAgent: new https.Agent({
ca: certificateAuthority
Expand Down Expand Up @@ -193,10 +193,6 @@ export class ChePluginServiceImpl implements ChePluginService {
});
}

private isItNode(): boolean {
return (typeof process !== 'undefined') && (typeof process.versions.node !== 'undefined');
}

private getCertificateAuthority(): Array<Buffer> | undefined {
const certificateAuthority: Buffer[] = [];
if (fs.existsSync(SS_CRT_PATH)) {
Expand Down Expand Up @@ -319,7 +315,7 @@ export class ChePluginServiceImpl implements ChePluginService {
* @return list of available plugins
*/
private async loadPluginList(registry: ChePluginRegistry): Promise<ChePluginMetadataInternal[]> {
return (await this.getAxiosInstance().get<ChePluginMetadataInternal[]>(registry.uri)).data;
return (await this.getAxiosInstance(registry.uri).get<ChePluginMetadataInternal[]>(registry.uri)).data;
}

/**
Expand Down Expand Up @@ -362,7 +358,7 @@ export class ChePluginServiceImpl implements ChePluginService {
private async loadPluginYaml(yamlURI: string): Promise<ChePluginMetadata> {
let err;
try {
const data = (await this.getAxiosInstance().get<ChePluginMetadata[]>(yamlURI)).data;
const data = (await this.getAxiosInstance(yamlURI).get<ChePluginMetadata[]>(yamlURI)).data;
return yaml.safeLoad(data);
} catch (error) {
console.error(error);
Expand All @@ -374,7 +370,7 @@ export class ChePluginServiceImpl implements ChePluginService {
yamlURI += '/';
}
yamlURI += 'meta.yaml';
const data = (await this.getAxiosInstance().get<ChePluginMetadata[]>(yamlURI)).data;
const data = (await this.getAxiosInstance(yamlURI).get<ChePluginMetadata[]>(yamlURI)).data;
return yaml.safeLoad(data);
} catch (error) {
console.error(error);
Expand Down

0 comments on commit 503ca56

Please sign in to comment.