Skip to content

Commit 0c4afaa

Browse files
committed
chore: resolve proxy based on target url
1 parent 0e191d2 commit 0c4afaa

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"@salesforce/core": "^2.15.2",
1414
"@salesforce/kit": "^1.3.3",
1515
"@salesforce/ts-types": "^1.4.3",
16+
"agent-base": "^6.0.2",
1617
"aws-sdk": "^2.782.0",
1718
"chalk": "^4.1.0",
1819
"cli-ux": "^5.5.1",
@@ -23,6 +24,7 @@
2324
"glob": "^7.1.6",
2425
"got": "^11.8.0",
2526
"proxy-agent": "^4.0.1",
27+
"proxy-from-env": "^1.1.0",
2628
"shelljs": "^0.8.4",
2729
"standard-version": "^9.0.0",
2830
"tslib": "^2"

src/codeSigning/packAndSign.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { exec } from 'child_process';
1212
import { EOL } from 'os';
1313
import { basename, join as pathJoin } from 'path';
1414
import { sep as pathSep } from 'path';
15+
// import { URL } from 'url';
1516
import { Readable } from 'stream';
1617
import { copyFile, createReadStream } from 'fs';
1718
import { Agent } from 'https';
@@ -20,7 +21,9 @@ import { UX } from '@salesforce/command';
2021
import { fs, Logger } from '@salesforce/core';
2122
import { NamedError } from '@salesforce/kit';
2223
import * as ProxyAgent from 'proxy-agent';
24+
import { getProxyForUrl } from 'proxy-from-env';
2325

26+
// import { AgentOptions } from 'agent-base';
2427
import {
2528
CodeSignInfo,
2629
CodeVerifierInfo,
@@ -177,7 +180,7 @@ export const api = {
177180
return resolve(
178181
(async (): Promise<boolean> => {
179182
try {
180-
const agent = api.getAgentForUri();
183+
const agent = api.getAgentForUri(publicKeyUrl);
181184
const response = await got.get(publicKeyUrl, { agent });
182185
if (response && response.statusCode === 200) {
183186
verifyInfo.publicKeyStream = Readable.from([response.body]);
@@ -459,8 +462,10 @@ export const api = {
459462
}
460463
},
461464

462-
getAgentForUri(): false | Agents {
463-
const agent = ProxyAgent() as Agent;
465+
getAgentForUri(url: string): false | Agents {
466+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
467+
const proxyUrl: string = getProxyForUrl(url) as string;
468+
const agent = ProxyAgent(proxyUrl) as Agent;
464469
return { https: agent, http: agent };
465470
},
466471
};

src/commands/circleci/envvar/update.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export default class CircelCIEnvvarUpdate extends SfdxCommand {
101101

102102
try {
103103
const url = `${URL_BASE}/${slug}/envvar`;
104-
const agent = api.getAgentForUri();
104+
const agent = api.getAgentForUri(url);
105105
response = await got.get<string>(url, { headers: this.headers, agent });
106106
} catch (err) {
107107
const error = err as SfdxError;
@@ -152,10 +152,10 @@ export default class CircelCIEnvvarUpdate extends SfdxCommand {
152152
try {
153153
// First remove the old envvar
154154
const url = `${envvarUrl}/${name}`;
155-
let agent = api.getAgentForUri();
155+
let agent = api.getAgentForUri(url);
156156
await got.delete(url, { headers: this.headers, agent });
157157

158-
agent = api.getAgentForUri();
158+
agent = api.getAgentForUri(`${envvarUrl}`);
159159
await got.post(`${envvarUrl}`, {
160160
headers: this.headers,
161161
json: { name, value },

src/repositories.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export type RepositoryInfo = {
3434
* Get a list of known tooling repositories that include Salesforce CLI plugins, libraries, and orbs.
3535
*/
3636
export const retrieveKnownRepositories = async (): Promise<RepositoryInfo[]> => {
37-
const agent = api.getAgentForUri();
37+
const agent = api.getAgentForUri(KNOWN_REPOSITORIES_URL);
3838
const response = await got.get(KNOWN_REPOSITORIES_URL, { agent });
3939
const repositories = JSON.parse(response.body) as SourceRepositoryDefinition[];
4040

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ add-stream@^1.0.0:
10261026
resolved "https://registry.npmjs.org/add-stream/-/add-stream-1.0.0.tgz#6a7990437ca736d5e1288db92bd3266d5f5cb2aa"
10271027
integrity sha1-anmQQ3ynNtXhKI25K9MmbV9csqo=
10281028

1029-
agent-base@6, agent-base@^6.0.0:
1029+
agent-base@6, agent-base@^6.0.0, agent-base@^6.0.2:
10301030
version "6.0.2"
10311031
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77"
10321032
integrity sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==
@@ -5753,7 +5753,7 @@ proxy-agent@^4.0.1:
57535753
proxy-from-env "^1.0.0"
57545754
socks-proxy-agent "^5.0.0"
57555755

5756-
proxy-from-env@^1.0.0:
5756+
proxy-from-env@^1.0.0, proxy-from-env@^1.1.0:
57575757
version "1.1.0"
57585758
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
57595759
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==

0 commit comments

Comments
 (0)