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

[v3] Rename Proxy class to ProxySettings #2238

Merged
merged 3 commits into from
Aug 23, 2024
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
3 changes: 2 additions & 1 deletion packages/imperative/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ All notable changes to the Imperative package will be documented in this file.

## Recent Changes

- LTS Breaking: Fixed command parsing error where `string` typed options would be converted into `number`s if the value provided by the user consists only of numeric characters. [#1881](https://github.com/zowe/zowe-cli/issues/1881)
- LTS Breaking: Fixed command parsing error where `string` typed options would be converted into `number`s if the value provided by the user consists only of numeric characters. [#1881](https://github.com/zowe/zowe-cli/issues/1881)
- LTS Breaking: Renamed `Proxy` class to `ProxySettings` to avoid name conflict with JS built-in `Proxy` object. [#2230](https://github.com/zowe/zowe-cli/issues/2230)

## `8.0.0-next.202408191401`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { AbstractRestClient } from "../../src/client/AbstractRestClient";
import * as os from "os";
import { join } from "path";
import { IO } from "../../../io";
import { Proxy } from "../../src/client/Proxy";
import { ProxySettings } from "../../src/client/ProxySettings";
import { HttpsProxyAgent } from "https-proxy-agent";

/**
Expand Down Expand Up @@ -1436,8 +1436,8 @@ describe("AbstractRestClient tests", () => {

beforeEach(() => {
jest.clearAllMocks();
getSystemProxyUrlSpy = jest.spyOn(Proxy, "getSystemProxyUrl");
getProxyAgentSpy = jest.spyOn(Proxy, "getProxyAgent");
getSystemProxyUrlSpy = jest.spyOn(ProxySettings, "getSystemProxyUrl");
getProxyAgentSpy = jest.spyOn(ProxySettings, "getProxyAgent");
setCertPemAuthSpy = jest.spyOn(privateRestClient, "setCertPemAuth");
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import * as process from "process";

import { Proxy } from "../../src/client/Proxy";
import { ProxySettings } from "../../src/client/ProxySettings";

import { HTTPS_PROTOCOL, HTTP_PROTOCOL } from "../../src/session/SessConstants";
import { HttpsProxyAgent } from "https-proxy-agent";
Expand All @@ -25,7 +25,7 @@ describe("Proxy tests", () => {
port: 443,
rejectUnauthorized: false
} as ISession;
const privateProxy = Proxy as any;
const privateProxy = ProxySettings as any;
const httpUrl = "http://www.zowe.com";
const httpsUrl = "https://www.zowe.com";
const noProxyList = "www.zowe.com, fake.com,ibm.com,broadcom.com ";
Expand All @@ -44,7 +44,7 @@ describe("Proxy tests", () => {
proxyUrl: httpUrl,
protocol: HTTP_PROTOCOL
});
expect(JSON.stringify(Proxy.getProxyAgent(session))).toEqual(JSON.stringify(expected));
expect(JSON.stringify(ProxySettings.getProxyAgent(session))).toEqual(JSON.stringify(expected));
});

it("Should retrieve the HTTPS proxy agent", () => {
Expand All @@ -53,7 +53,7 @@ describe("Proxy tests", () => {
proxyUrl: httpsUrl,
protocol: HTTPS_PROTOCOL
});
expect(JSON.stringify(Proxy.getProxyAgent(session))).toEqual(JSON.stringify(expected));
expect(JSON.stringify(ProxySettings.getProxyAgent(session))).toEqual(JSON.stringify(expected));
});
});

Expand All @@ -68,7 +68,7 @@ describe("Proxy tests", () => {
proxyUrl: httpsUrl,
protocol: HTTPS_PROTOCOL
});
expect(Proxy.getSystemProxyUrl(session)).toEqual(httpsUrl);
expect(ProxySettings.getSystemProxyUrl(session)).toEqual(httpsUrl);
});
});

Expand All @@ -84,7 +84,7 @@ describe("Proxy tests", () => {
protocol: HTTPS_PROTOCOL
};
checkUrlSpy.mockReturnValue(httpsUrl);
expect(Proxy["getProxySettings"](session)).toEqual(expected);
expect(ProxySettings["getProxySettings"](session)).toEqual(expected);
});
});

Expand All @@ -96,7 +96,7 @@ describe("Proxy tests", () => {
it("Should return the HTTP environment variables if they exist", () => {
const expected = httpUrl;
process.env["HTTP_PROXY"] = expected;
expect(Proxy["getHttpEnvVariables"]()).toEqual(expected);
expect(ProxySettings["getHttpEnvVariables"]()).toEqual(expected);
process.env["HTTP_PROXY"] = undefined;
});
});
Expand All @@ -105,15 +105,15 @@ describe("Proxy tests", () => {
it("Should match session hostname with no_proxy", () => {
const expected = true;
process.env["NO_PROXY"] = noProxyList;
expect(Proxy["matchesNoProxySettings"](session)).toEqual(expected);
expect(ProxySettings["matchesNoProxySettings"](session)).toEqual(expected);
process.env["NO_PROXY"] = undefined;
});

it("Should not match session hostname with no_proxy", () => {
const expected = false;
process.env["NO_PROXY"] = noProxyList;
session.hostname = "microsoft.com";
expect(Proxy["matchesNoProxySettings"](session)).toEqual(expected);
expect(ProxySettings["matchesNoProxySettings"](session)).toEqual(expected);
process.env["NO_PROXY"] = undefined;
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/imperative/src/rest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export * from "./src/client/doc/IRestClientError";
export * from "./src/client/doc/IRestClientResponse";
export * from "./src/client/doc/IRestOptions";
export * from "./src/client/Headers";
export * from "./src/client/Proxy";
export * from "./src/client/ProxySettings";
export * from "./src/client/AbstractRestClient";
// export * from "./src/client/CompressionUtils";
export * from "./src/client/RestClient";
Expand Down
8 changes: 4 additions & 4 deletions packages/imperative/src/rest/src/client/AbstractRestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { TextUtils } from "../../../utilities";
import { IRestOptions } from "./doc/IRestOptions";
import * as SessConstants from "../session/SessConstants";
import { CompressionUtils } from "./CompressionUtils";
import { Proxy } from "./Proxy";
import { ProxySettings } from "./ProxySettings";

export type RestClientResolve = (data: string) => void;

Expand Down Expand Up @@ -461,13 +461,13 @@ export abstract class AbstractRestClient {
// NOTE(Kelosky): This cannot be set for http requests
// options.agent = new https.Agent({secureProtocol: this.session.ISession.secureProtocol});

const proxyUrl = Proxy.getSystemProxyUrl(this.session.ISession);
const proxyUrl = ProxySettings.getSystemProxyUrl(this.session.ISession);
if (proxyUrl) {
if (Proxy.matchesNoProxySettings(this.session.ISession)) {
if (ProxySettings.matchesNoProxySettings(this.session.ISession)) {
this.mLogger.info(`Proxy setting "${proxyUrl.href}" will not be used as hostname was found listed under "no_proxy" setting.`);
} else {
this.mLogger.info(`Using the following proxy setting for the request: ${proxyUrl.href}`);
options.agent = Proxy.getProxyAgent(this.session.ISession);
options.agent = ProxySettings.getProxyAgent(this.session.ISession);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { ISession } from '../session/doc/ISession';
* variables NO_PROXY or no_proxy. These work with a simple comma separated list of hostnames that need
* to match with the hostname of the Zowe profile.
*/
export class Proxy {
export class ProxySettings {

/**
* Retrieve an appropriate http.agent instance if proxy environment variables can be found.
Expand All @@ -41,7 +41,7 @@ export class Proxy {
* Uses the session's `rejectUnauthorized` also for the proxy connection.
* @returns an instance of an appropriate subclass of node's https.agent if proxy
* settings were found. Returns `undefined` if no proxy settings are found.
* @memberof Proxy
* @memberof ProxySettings
*/
public static getProxyAgent(session: ISession): Agent | undefined {
const proxySetting = this.getProxySettings(session);
Expand All @@ -60,7 +60,7 @@ export class Proxy {
* @static
* @param session Zowe `ISession` containing the hostname for the http request.
* @returns `URL` to proxy server
* @memberof Proxy
* @memberof ProxySettings
*/
public static getSystemProxyUrl(session: ISession): URL | undefined {
return this.getProxySettings(session)?.proxyUrl;
Expand All @@ -75,7 +75,7 @@ export class Proxy {
* @param session Zowe `ISession` containing the hostname for the http request.
* @returns `true` if the Zowe session host matches an entry in the comma separated
* list of hostnames in the environment variable. `false` otherwise.
* @memberof Proxy
* @memberof ProxySettings
*/
public static matchesNoProxySettings(session: ISession): boolean {
const noProxyValues = this.getNoProxyEnvVariables();
Expand All @@ -94,7 +94,7 @@ export class Proxy {
* @static
* @param session Zowe `ISession` containing the hostname for the http request.
* @returns instance of private `ProxySetting` or `undefined`
* @memberof Proxy
* @memberof ProxySettings
*/
private static getProxySettings(session: ISession): ProxySetting | undefined {
if (this.matchesNoProxySettings(session)) {
Expand All @@ -119,7 +119,7 @@ export class Proxy {
* @private
* @static
* @returns `string` if valid variable is found or undefined.
* @memberof Proxy
* @memberof ProxySettings
*/
private static getHttpEnvVariables(): string | undefined {
return env.HTTP_PROXY ?? env.http_proxy;
Expand All @@ -130,7 +130,7 @@ export class Proxy {
* @private
* @static
* @returns `string` if valid variable is found or undefined.
* @memberof Proxy
* @memberof ProxySettings
*/
private static getHttpsEnvVariables(): string | undefined {
return env.HTTPS_PROXY ?? env.https_proxy ?? this.getHttpEnvVariables();
Expand All @@ -142,7 +142,7 @@ export class Proxy {
* @static
* @returns `string[]` of all hostnames found in the comma separated list
* in lowercase without white spaces.
* @memberof Proxy
* @memberof ProxySettings
*/
private static getNoProxyEnvVariables(): string[] | undefined {
const noProxyValue = env.NO_PROXY ?? env.no_proxy;
Expand Down
Loading