Skip to content

Commit 2fc404d

Browse files
committed
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 - Replace usage of https.get(..) with fetch Signed-off-by: Roland Grunberg <rgrunber@redhat.com>
1 parent 0ceadd9 commit 2fc404d

File tree

2 files changed

+22
-32
lines changed

2 files changed

+22
-32
lines changed

src/devfile-registry/devfileRegistryWrapper.ts

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -142,31 +142,26 @@ export class DevfileRegistry {
142142
}
143143

144144
private static async _get(url: string, abortTimeout?: number, abortController?: AbortController): Promise<string> {
145+
const timeoutVal = abortTimeout ? abortTimeout : 5000;
146+
const controller = new AbortController();
147+
const signal = controller.signal;
148+
149+
const timeout = setTimeout(() => {
150+
controller.abort();
151+
}, timeoutVal);
152+
145153
return new Promise<string>((resolve, reject) => {
146-
const signal = abortController?.signal;
147-
const timeout = abortTimeout ? abortTimeout : 5000;
148-
const options = { rejectUnauthorized: false, signal, timeout };
149-
let result: string = '';
150-
https.get(url, options, (response) => {
151-
if (response.statusCode < 500) {
152-
response.on('data', (d) => {
153-
result = result.concat(d);
154-
});
155-
response.resume();
156-
response.on('end', () => {
157-
if (!response.complete) {
158-
reject(new Error(`The connection was terminated while the message was still being sent: ${response.statusMessage}`));
159-
} else {
160-
resolve(result);
161-
}
162-
});
163-
} else {
164-
reject(new Error(`Connect error: ${response.statusMessage}`));
154+
fetch(url, { signal }).then(response => {
155+
if (!response.ok) {
156+
reject(`Connect error: ${response.statusText}`);
165157
}
166-
}).on('error', (e) => {
167-
reject(new Error(`Connect error: ${e}`));
168-
}).on('success', (s) => {
158+
return response.text();
159+
}).then(result => {
169160
resolve(result);
161+
}).catch(error => {
162+
reject(new Error(`Connect error: ${error}`));
163+
}).finally(() => {
164+
clearTimeout(timeout);
170165
});
171166
});
172167
}
@@ -181,4 +176,4 @@ export class DevfileRegistry {
181176
this.executionContext = new ExecutionContext();
182177
}
183178

184-
}
179+
}

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+
}

0 commit comments

Comments
 (0)