Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: more idiomatic got/Readable #290

Merged
merged 1 commit into from
Aug 5, 2022
Merged
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
41 changes: 9 additions & 32 deletions src/shared/installationVerification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,39 +269,16 @@ export class InstallationVerification implements Verifier {
*
* @param url host url.
*/
public getSigningContent(url: string): Promise<Readable> {
return new Promise((resolve, reject) => {
got
.get({
timeout: {
request: 10000,
},
agent: {
https: ProxyAgent(getProxyForUrl(url)),
},
url,
})
.then((res) => {
if (res && res.statusCode === 200) {
// The verification api expects a readable
return resolve(
new Readable({
read(): void {
this.push(res.body);
this.push(null);
},
})
);
} else {
return reject(
new SfError(`A request to url ${url} failed with error code: [${res.statusCode}]`, 'ErrorGettingContent')
);
}
})
.catch((err) => {
return reject(err);
});
public async getSigningContent(url: string): Promise<Readable> {
const res = await got.get({
url,
timeout: { request: 10000 },
agent: { https: ProxyAgent(getProxyForUrl(url)) },
});
if (res.statusCode !== 200) {
throw new SfError(`A request to url ${url} failed with error code: [${res.statusCode}]`, 'ErrorGettingContent');
}
return Readable.from(Buffer.from(res.body));
}

/**
Expand Down