Skip to content

Commit 0df40f8

Browse files
rgrunbervrubezhny
authored andcommitted
Devfile Registries list need not contain Default Devfile Registry.
- When the Devfile Registries list contains other registries, it should be permitted to remove the Default Devfile Registry - Switch between http/https.get(..) depending on URL protocol Signed-off-by: Roland Grunberg <[email protected]>
1 parent 17de041 commit 0df40f8

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

src/devfile-registry/devfileRegistryWrapper.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
* Copyright (c) Red Hat, Inc. All rights reserved.
33
* Licensed under the MIT License. See LICENSE file in the project root for license information.
44
*-----------------------------------------------------------------------------------------------*/
5-
import * as https from 'https';
5+
import { get as httpGet } from 'http';
6+
import { get as httpsGet } from 'https';
67
import * as YAML from 'js-yaml';
78
import { ExecutionContext } from '../cli';
89
import { Registry } from '../odo/componentType';
@@ -143,11 +144,17 @@ export class DevfileRegistry {
143144

144145
private static async _get(url: string, abortTimeout?: number, abortController?: AbortController): Promise<string> {
145146
return new Promise<string>((resolve, reject) => {
147+
let request = httpGet;
148+
try {
149+
request = new URL(url).protocol.startsWith('https') ? httpsGet : httpGet;
150+
} catch (err) {
151+
// continue
152+
}
146153
const signal = abortController?.signal;
147154
const timeout = abortTimeout ? abortTimeout : 5000;
148155
const options = { rejectUnauthorized: false, signal, timeout };
149156
let result: string = '';
150-
https.get(url, options, (response) => {
157+
request(url, options, (response) => {
151158
if (response.statusCode < 500) {
152159
response.on('data', (d) => {
153160
result = result.concat(d);
@@ -181,4 +188,4 @@ export class DevfileRegistry {
181188
this.executionContext = new ExecutionContext();
182189
}
183190

184-
}
191+
}

src/odo/odoPreference.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,11 @@ export class OdoPreference {
120120
const odoPreferenceFile = await fs.readFile(odoPreferenceFilePath, 'utf8');
121121
const odoPreferences = parse(odoPreferenceFile) as OdoPreferenceObject;
122122

123-
// If `odoPreferences.OdoSettings.RegistryList` is `null` or doesn't contain the `DefaultDevfileRegistry` item
124-
// we have to recover at least the 'DefaultDevfileRegistry` item on it because this whole list will be replaced
125-
if (!odoPreferences.OdoSettings.RegistryList) {
123+
// If `odoPreferences.OdoSettings.RegistryList` is `null` or doesn't contain any registry item
124+
// we should recover the 'DefaultDevfileRegistry` item on it
125+
if (!odoPreferences.OdoSettings.RegistryList || odoPreferences.OdoSettings.RegistryList.length === 0) {
126126
odoPreferences.OdoSettings.RegistryList = OdoPreference.DefaultOdoPreference.OdoSettings.RegistryList;
127127
isToBeReWritten = true;
128-
} else {
129-
if (!odoPreferences.OdoSettings.RegistryList.find((r) => r.Name === OdoPreference.DEFAULT_DEVFILE_REGISTRY_NAME)) {
130-
odoPreferences.OdoSettings.RegistryList.push(OdoPreference.DefaultOdoPreference.OdoSettings.RegistryList[0]);
131-
isToBeReWritten = true;
132-
}
133128
}
134129

135130
mergedPreference = { ...mergedPreference, ...odoPreferences };
@@ -172,4 +167,4 @@ export class OdoPreference {
172167
);
173168
}
174169
}
175-
}
170+
}

src/openshift/cluster.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
import { CoreV1Api, KubeConfig, KubernetesObject, V1Secret, V1ServiceAccount } from '@kubernetes/client-node';
77
import { Cluster as KcuCluster, Context as KcuContext, User } from '@kubernetes/client-node/dist/config_types';
8-
import * as https from 'https';
8+
import { get as httpGet } from 'http';
9+
import { get as httpsGet } from 'https';
910
import { Disposable, ExtensionContext, QuickInputButtons, QuickPickItem, QuickPickItemButtonEvent, QuickPickItemKind, ThemeIcon, Uri, commands, env, window, workspace } from 'vscode';
1011
import { CommandText } from '../base/command';
1112
import { CliChannel } from '../cli';
@@ -666,9 +667,15 @@ export class Cluster extends OpenShiftItem implements Disposable {
666667
*/
667668
static async pingCluster(url: string, abortController: AbortController): Promise<boolean> {
668669
return new Promise<boolean>((resolve, reject) => {
670+
let request = httpGet;
671+
try {
672+
request = new URL(url).protocol.startsWith('https') ? httpsGet : httpGet;
673+
} catch (err) {
674+
// continue
675+
}
669676
const signal = abortController?.signal;
670677
const options = { rejectUnauthorized: false, signal };
671-
https.get(`${url}/api`, options, (response) => {
678+
request(`${url}/api`, options, (response) => {
672679
if (response.statusCode < 500) {
673680
resolve(true);
674681
} else {
@@ -1243,4 +1250,4 @@ export class Cluster extends OpenShiftItem implements Disposable {
12431250
}
12441251
return Cluster.tokenLogin(server, true, kcu.currentContext, pipelineToken);
12451252
}
1246-
}
1253+
}

0 commit comments

Comments
 (0)