Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/devfile-registry/devfileRegistryWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
import * as https from 'https';
import { get as httpGet } from 'http';
import { get as httpsGet } from 'https';
import * as YAML from 'js-yaml';
import { ExecutionContext } from '../cli';
import { Registry } from '../odo/componentType';
Expand Down Expand Up @@ -143,11 +144,17 @@ export class DevfileRegistry {

private static async _get(url: string, abortTimeout?: number, abortController?: AbortController): Promise<string> {
return new Promise<string>((resolve, reject) => {
let request = httpGet;
try {
request = new URL(url).protocol.startsWith('https') ? httpsGet : httpGet;
} catch (err) {
// continue
}
const signal = abortController?.signal;
const timeout = abortTimeout ? abortTimeout : 5000;
const options = { rejectUnauthorized: false, signal, timeout };
let result: string = '';
https.get(url, options, (response) => {
request(url, options, (response) => {
if (response.statusCode < 500) {
response.on('data', (d) => {
result = result.concat(d);
Expand Down Expand Up @@ -181,4 +188,4 @@ export class DevfileRegistry {
this.executionContext = new ExecutionContext();
}

}
}
13 changes: 4 additions & 9 deletions src/odo/odoPreference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,11 @@ export class OdoPreference {
const odoPreferenceFile = await fs.readFile(odoPreferenceFilePath, 'utf8');
const odoPreferences = parse(odoPreferenceFile) as OdoPreferenceObject;

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

mergedPreference = { ...mergedPreference, ...odoPreferences };
Expand Down Expand Up @@ -172,4 +167,4 @@ export class OdoPreference {
);
}
}
}
}
13 changes: 10 additions & 3 deletions src/openshift/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

import { CoreV1Api, KubeConfig, KubernetesObject, V1Secret, V1ServiceAccount } from '@kubernetes/client-node';
import { Cluster as KcuCluster, Context as KcuContext, User } from '@kubernetes/client-node/dist/config_types';
import * as https from 'https';
import { get as httpGet } from 'http';
import { get as httpsGet } from 'https';
import { Disposable, ExtensionContext, QuickInputButtons, QuickPickItem, QuickPickItemButtonEvent, QuickPickItemKind, ThemeIcon, Uri, commands, env, window, workspace } from 'vscode';
import { CommandText } from '../base/command';
import { CliChannel } from '../cli';
Expand Down Expand Up @@ -666,9 +667,15 @@ export class Cluster extends OpenShiftItem implements Disposable {
*/
static async pingCluster(url: string, abortController: AbortController): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
let request = httpGet;
try {
request = new URL(url).protocol.startsWith('https') ? httpsGet : httpGet;
} catch (err) {
// continue
}
const signal = abortController?.signal;
const options = { rejectUnauthorized: false, signal };
https.get(`${url}/api`, options, (response) => {
request(`${url}/api`, options, (response) => {
if (response.statusCode < 500) {
resolve(true);
} else {
Expand Down Expand Up @@ -1243,4 +1250,4 @@ export class Cluster extends OpenShiftItem implements Disposable {
}
return Cluster.tokenLogin(server, true, kcu.currentContext, pipelineToken);
}
}
}
Loading