Skip to content

Commit

Permalink
VSC Proxy Support (#3291)
Browse files Browse the repository at this point in the history
* initial vsc proxy work

Signed-off-by: Billie Simmons <[email protected]>

* fix circ dependency issues

Signed-off-by: Billie Simmons <[email protected]>

* update zosmf session obtaining methods

Signed-off-by: Billie Simmons <[email protected]>

* update workflow and fix some unit tests

Signed-off-by: Billie Simmons <[email protected]>

* fix ZE API unit tests

Signed-off-by: Billie Simmons <[email protected]>

* fix ZE unit tests

Signed-off-by: Billie Simmons <[email protected]>

* add VscSettings unit tests

Signed-off-by: Billie Simmons <[email protected]>

* profilesCache unit tests

Signed-off-by: Billie Simmons <[email protected]>

* add CHANGELOGs

Signed-off-by: Billie Simmons <[email protected]>

* update sdks

Signed-off-by: Billie Simmons <[email protected]>

* fix unit tests

Signed-off-by: Billie Simmons <[email protected]>

* update sdk version in changelogs

Signed-off-by: Billie Simmons <[email protected]>

* run prepublish

Signed-off-by: Billie Simmons <[email protected]>

* address comments

Signed-off-by: Billie Simmons <[email protected]>

* get lock from main

Signed-off-by: Billie Simmons <[email protected]>

* update sdk changelog entry in ftp extenstion to match other packages

Signed-off-by: Billie Simmons <[email protected]>

* address feedback

Signed-off-by: Billie Simmons <[email protected]>

* remove session check and undefined return type

Signed-off-by: Billie Simmons <[email protected]>

---------

Signed-off-by: Billie Simmons <[email protected]>
Signed-off-by: Fernando Rijo Cedeno <[email protected]>
Co-authored-by: Fernando Rijo Cedeno <[email protected]>
  • Loading branch information
JillieBeanSim and zFernand0 authored Nov 25, 2024
1 parent 07232b7 commit 3e75cfe
Show file tree
Hide file tree
Showing 18 changed files with 332 additions and 150 deletions.
7 changes: 3 additions & 4 deletions packages/zowe-explorer-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ All notable changes to the "zowe-explorer-api" extension will be documented in t

### New features and enhancements

- - Update Zowe SDKs to `8.8.2` to get the latest enhancements from Imperative. [#3296](https://github.com/zowe/zowe-explorer-vscode/pull/3296)
- Added support for extenders to obtain an updated Session that will includes VS Code proxy settings values if set, `getProfileSessionWithVscProxy`. [#3010](https://github.com/zowe/zowe-explorer-vscode/issues/3010)
- Added support for VS Code proxy settings with zosmf profile types. [#3010](https://github.com/zowe/zowe-explorer-vscode/issues/3010)
- Added optional `getLocalStorage` function to the `IApiExplorerExtender` interface to expose local storage access to Zowe Explorer extenders. [#3180](https://github.com/zowe/zowe-explorer-vscode/issues/3180)

### Bug fixes

## `3.0.3`

### New features and enhancements

- Update Zowe SDKs to `8.8.2` to get the latest enhancements from Imperative. [#3296](https://github.com/zowe/zowe-explorer-vscode/pull/3296)

### Bug fixes

- Fixed an issue to review inconsistent capitalization across translation strings. [#2935](https://github.com/zowe/zowe-explorer-vscode/issues/2935)
Expand Down
3 changes: 2 additions & 1 deletion packages/zowe-explorer-api/__mocks__/vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1096,14 +1096,15 @@ export class FileSystemError extends Error {
*/
export namespace workspace {
export const textDocuments: TextDocument[] = [];
export function getConfiguration(_configuration: string): { update: () => void; inspect: () => void } {
export function getConfiguration(_configuration: string) {
return {
update: () => {
return;
},
inspect: () => {
return {};
},
get: () => {},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as imperative from "@zowe/imperative";
import { ProfilesCache } from "../../../src/profiles/ProfilesCache";
import { FileManagement, Types } from "../../../src";
import { mocked } from "../../../__mocks__/mockUtils";
import { VscSettings } from "../../../src/vscode/doc/VscSettings";

jest.mock("fs");

Expand Down Expand Up @@ -544,6 +545,27 @@ describe("ProfilesCache", () => {
});
});

describe("getProfileSessionWithVscProxy", () => {
it("should return same session if no VSC proxy values", () => {
const fakeSession = imperative.Session.createFromUrl(new URL("https://example.com"));
jest.spyOn(VscSettings, "getVsCodeProxySettings").mockReturnValue(undefined as any);
expect(ProfilesCache.getProfileSessionWithVscProxy(fakeSession)).toEqual(fakeSession);
});
it("should return updated session if VSC proxy values", () => {
const fakeSession = imperative.Session.createFromUrl(new URL("https://example.com"));
const proxyValues = {
http_proxy: "fake.com",
https_proxy: "fake.com",
no_proxy: ["zowe.com"],
proxy_authorization: null,
proxy_strict_ssl: true,
};
fakeSession.ISession.proxy = proxyValues as any;
jest.spyOn(VscSettings, "getVsCodeProxySettings").mockReturnValue(proxyValues as any);
expect(ProfilesCache.getProfileSessionWithVscProxy(fakeSession)).toEqual(fakeSession);
});
});

it("getProfileFromConfig should return profile attributes for given name", async () => {
const profCache = new ProfilesCache(fakeLogger as unknown as imperative.Logger);
jest.spyOn(profCache, "getProfileInfo").mockResolvedValue(createProfInfoMock([{ name: "lpar1", type: "zosmf" }]));
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ZosmfUssApi constants should be unchanged 1`] = `"zosmf"`;
exports[`ZosmfUssApi misc constants should be unchanged 1`] = `"zosmf"`;

exports[`ZosmfUssApi constants should be unchanged 2`] = `"apimlAuthenticationToken"`;
exports[`ZosmfUssApi misc constants should be unchanged 2`] = `"apimlAuthenticationToken"`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/

import * as vscode from "vscode";
import { VscSettings } from "../../../../src/vscode/doc/VscSettings";

function createGlobalMocks() {
const globalMocks = {
vscConfSpy: jest.spyOn(vscode.workspace, "getConfiguration"),
getConfiguration: jest.fn(),
testProxyVars: {
http_proxy: "host.com",
https_proxy: "host.com",
no_proxy: ["fake.com"],
proxy_authorization: null,
proxy_strict_ssl: true,
},
};
globalMocks.getConfiguration = jest.fn().mockReturnValue({
get: jest.fn(),
});
globalMocks.vscConfSpy.mockImplementation(globalMocks.getConfiguration);

return globalMocks;
}

describe("VscSettings", () => {
describe("getVsCodeProxySettings", () => {
beforeEach(() => {
jest.resetAllMocks();
});
it("should return undefined with VSC proxy support off", () => {
const globalMocks = createGlobalMocks();
globalMocks.getConfiguration().get.mockReturnValueOnce("off");
const response = VscSettings.getVsCodeProxySettings();
expect(response).not.toBeDefined();
});
it("should return undefined with VSC proxy support off", () => {
const globalMocks = createGlobalMocks();
globalMocks.getConfiguration().get.mockReturnValueOnce("on");
globalMocks.getConfiguration().get.mockReturnValueOnce("host.com");
globalMocks.getConfiguration().get.mockReturnValueOnce(["fake.com"]);
globalMocks.getConfiguration().get.mockReturnValueOnce(true);
globalMocks.getConfiguration().get.mockReturnValueOnce(null);
const response = VscSettings.getVsCodeProxySettings();
expect(response).toEqual(globalMocks.testProxyVars);
});
});
});
7 changes: 7 additions & 0 deletions packages/zowe-explorer-api/src/profiles/ProfilesCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ZosmfProfile } from "@zowe/zosmf-for-zowe-sdk";
import { ZosTsoProfile } from "@zowe/zos-tso-for-zowe-sdk";
import { ZosUssProfile } from "@zowe/zos-uss-for-zowe-sdk";
import { Types } from "../Types";
import { VscSettings } from "../vscode/doc/VscSettings";

export class ProfilesCache {
public profilesForValidation: Validation.IValidationProfile[] = [];
Expand Down Expand Up @@ -388,6 +389,12 @@ export class ProfilesCache {
return convertResult;
}

public static getProfileSessionWithVscProxy(session: imperative.Session): imperative.Session {
const VsCodeProxySettings = VscSettings.getVsCodeProxySettings();
session.ISession.proxy = VsCodeProxySettings;
return session;
}

protected getCoreProfileTypes(): imperative.IProfileTypeConfiguration[] {
return [ZosmfProfile, ZosTsoProfile, ZosUssProfile];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as zosmf from "@zowe/zosmf-for-zowe-sdk";
import { MainframeInteraction } from "../extend/MainframeInteraction";
import { FileManagement } from "../utils";
import { Types } from "../Types";
import { ProfilesCache } from "../profiles/ProfilesCache";

/**
* Implementations of Zowe Explorer API for z/OSMF profiles
Expand All @@ -44,7 +45,7 @@ export namespace ZoweExplorerZosmf {
const sessCfg = zosmf.ZosmfSession.createSessCfgFromArgs(cmdArgs);
imperative.ConnectionPropsForSessCfg.resolveSessCfgProps(sessCfg, cmdArgs);
const sessionToUse = new imperative.Session(sessCfg);
return sessionToUse;
return ProfilesCache.getProfileSessionWithVscProxy(sessionToUse);
}

public getSession(profile?: imperative.IProfileLoaded): imperative.Session {
Expand All @@ -56,7 +57,7 @@ export namespace ZoweExplorerZosmf {
imperative.Logger.getAppLogger().error(error as string);
}
}
return this.session;
return ProfilesCache.getProfileSessionWithVscProxy(this.session);
}

private _getSession(serviceProfile: imperative.IProfileLoaded): imperative.Session {
Expand Down
4 changes: 2 additions & 2 deletions packages/zowe-explorer-api/src/vscode/ZoweVsCodeExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

import * as semver from "semver";
import * as vscode from "vscode";
import { ProfilesCache } from "../profiles";
import { ProfilesCache } from "../profiles/ProfilesCache";
import { Login, Logout } from "@zowe/core-for-zowe-sdk";
import * as imperative from "@zowe/imperative";
import { Gui } from "../globals/Gui";
import { PromptCredentialsOptions } from "./doc/PromptCredentials";
import { Types } from "../Types";
import { BaseProfileAuthOptions } from "./doc";
import { BaseProfileAuthOptions } from "./doc/BaseProfileAuth";

/**
* Collection of utility functions for writing Zowe Explorer VS Code extensions.
Expand Down
44 changes: 44 additions & 0 deletions packages/zowe-explorer-api/src/vscode/doc/VscSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/

import * as vscode from "vscode";
import * as imperative from "@zowe/imperative";

export class VscSettings {
/**
* Retrieves a generic setting either in user or workspace.
* @param {string} key - The config property that needs retrieving
* @param {T} defaultValue - Default value if config property is undefined
*/
public static getDirectValue<T>(key: string, defaultValue?: T): T {
const [first, ...rest] = key.split(".");
return vscode.workspace.getConfiguration(first).get(rest.join("."), defaultValue);
}

public static getVsCodeProxySettings(): imperative.ProxyVariables {
const proxySupport = this.getDirectValue("http.proxySupport");
if (proxySupport !== "on") {
return;
}
const http_proxy: string = this.getDirectValue("http.proxy");
const no_proxy: string[] = this.getDirectValue("http.noProxy");
const proxy_strict_ssl: boolean = this.getDirectValue("http.proxyStrictSSL");
const proxy_authorization: string = this.getDirectValue("http.proxyAuthorization");

return {
http_proxy,
https_proxy: http_proxy,
no_proxy,
proxy_authorization,
proxy_strict_ssl,
};
}
}
1 change: 1 addition & 0 deletions packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen
- Added expired JSON web token detection for profiles in each tree view (Data Sets, USS, Jobs). When a user performs a search on a profile, they are prompted to log in if their token expired. [#3175](https://github.com/zowe/zowe-explorer-vscode/issues/3175)
- Add a data set or USS resource to a virtual workspace with the new "Add to Workspace" context menu option. [#3265](https://github.com/zowe/zowe-explorer-vscode/issues/3265)
- Power users and developers can now build links to efficiently open mainframe resources in Zowe Explorer. Use the **Copy External Link** option in the context menu to get the URL for a data set or USS resource, or create a link in the format `vscode://Zowe.vscode-extension-for-zowe?<ZoweResourceUri>`. For more information on building resource URIs, see the [FileSystemProvider wiki article](https://github.com/zowe/zowe-explorer-vscode/wiki/FileSystemProvider#file-paths-vs-uris). [#3271](https://github.com/zowe/zowe-explorer-vscode/pull/3271)
- Adopted support for VS Code proxy settings with zosmf profile types. [#3010](https://github.com/zowe/zowe-explorer-vscode/issues/3010)
- Implemented more user-friendly error messages for API or network errors within Zowe Explorer. [#3243](https://github.com/zowe/zowe-explorer-vscode/pull/3243)
- Use the "Troubleshoot" option for certain errors to obtain additional context, tips, and resources for how to resolve the errors. [#3243](https://github.com/zowe/zowe-explorer-vscode/pull/3243)
- Updated Zowe SDKs to `8.8.2` for technical currency. [#3296](https://github.com/zowe/zowe-explorer-vscode/pull/3296)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,17 @@ import {
createMockNode,
} from "../../__mocks__/mockCreators/shared";
import { createDatasetSessionNode, createDatasetTree } from "../../__mocks__/mockCreators/datasets";
import { imperative, Gui, ZoweTreeNode, ZoweVsCodeExtension, IZoweTree, IZoweTreeNode, Validation, FileManagement } from "@zowe/zowe-explorer-api";
import {
imperative,
Gui,
ZoweTreeNode,
ZoweVsCodeExtension,
IZoweTree,
IZoweTreeNode,
Validation,
FileManagement,
ProfilesCache,
} from "@zowe/zowe-explorer-api";
import { Profiles } from "../../../src/configuration/Profiles";
import { ZoweExplorerExtender } from "../../../src/extending/ZoweExplorerExtender";
import { ZoweExplorerApiRegister } from "../../../src/extending/ZoweExplorerApiRegister";
Expand Down Expand Up @@ -194,6 +204,10 @@ function createGlobalMocks(): { [key: string]: any } {
}),
configurable: true,
});
Object.defineProperty(ProfilesCache, "getProfileSessionWithVscProxy", {
value: jest.fn().mockReturnValue(newMocks.testSession),
configurable: true,
});

newMocks.testUSSTree = createUSSTree(undefined as any, [createUSSNode(newMocks.testSession, newMocks.testProfile)], createTreeView());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

import * as zosfiles from "@zowe/zos-files-for-zowe-sdk";
import { imperative, ZoweExplorerZosmf } from "@zowe/zowe-explorer-api";
import { imperative, ProfilesCache, ZoweExplorerZosmf } from "@zowe/zowe-explorer-api";

export declare enum TaskStage {
IN_PROGRESS = 0,
Expand All @@ -20,6 +20,10 @@ export declare enum TaskStage {
}

describe("Zosmf API tests", () => {
Object.defineProperty(ProfilesCache, "getProfileSessionWithVscProxy", {
value: jest.fn(),
configurable: true,
});
it("should test that copy data set uses default options", async () => {
const dataSet = jest.fn((_session, _toDataSet, options) => {
expect(options).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import * as vscode from "vscode";
import * as zosfiles from "@zowe/zos-files-for-zowe-sdk";
import { Gui, imperative, Validation, Types, ZoweExplorerApiType } from "@zowe/zowe-explorer-api";
import { Gui, imperative, Validation, Types, ProfilesCache, ZoweExplorerApiType } from "@zowe/zowe-explorer-api";
import { DatasetFSProvider } from "../../../../src/trees/dataset/DatasetFSProvider";
import { bindMvsApi, createMvsApi } from "../../../__mocks__/mockCreators/api";
import {
Expand Down Expand Up @@ -133,6 +133,7 @@ const createBlockMocksShared = () => {
const mvsApi = createMvsApi(imperativeProfile);
const fetchDsAtUri = jest.spyOn(DatasetFSProvider.instance, "fetchDatasetAtUri").mockImplementation();
bindMvsApi(mvsApi);
Object.defineProperty(ProfilesCache, "getProfileSessionWithVscProxy", { value: jest.fn().mockReturnValue(zosmfSession), configurable: true });

return {
session,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ function createGlobalMocks() {
Object.defineProperty(ZoweLogger, "warn", { value: jest.fn(), configurable: true });
Object.defineProperty(ZoweLogger, "info", { value: jest.fn(), configurable: true });
Object.defineProperty(ZoweLogger, "trace", { value: jest.fn(), configurable: true });
Object.defineProperty(ProfilesCache, "getProfileSessionWithVscProxy", { value: jest.fn().mockReturnValue(createISession()), configurable: true });

return globalMocks;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as vscode from "vscode";
import * as zosconsole from "@zowe/zos-console-for-zowe-sdk";
import * as zosjobs from "@zowe/zos-jobs-for-zowe-sdk";
import * as zosmf from "@zowe/zosmf-for-zowe-sdk";
import { Gui, IZoweJobTreeNode, Sorting, Validation, ZoweScheme } from "@zowe/zowe-explorer-api";
import { Gui, IZoweJobTreeNode, ProfilesCache, Sorting, Validation, ZoweScheme } from "@zowe/zowe-explorer-api";
import {
createISession,
createIProfile,
Expand Down Expand Up @@ -135,6 +135,10 @@ function createGlobalMocks() {
value: jest.fn().mockReturnValue([newMocks.imperativeProfile.name]),
configurable: true,
});
Object.defineProperty(ProfilesCache, "getProfileSessionWithVscProxy", {
value: jest.fn().mockReturnValue(newMocks.session),
configurable: true,
});
function settingJobObjects(
job: zosjobs.IJob,
setjobname: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ function createGlobalMocks() {
value: jest.fn().mockReturnValue(true),
configurable: true,
});
Object.defineProperty(ProfilesCache, "getProfileSessionWithVscProxy", {
value: jest.fn().mockReturnValue(globalMocks.testSession),
configurable: true,
});

jest.spyOn(SharedTreeProviders, "providers", "get").mockReturnValue({
ds: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import * as vscode from "vscode";
import * as zosfiles from "@zowe/zos-files-for-zowe-sdk";
import * as zosmf from "@zowe/zosmf-for-zowe-sdk";
import { Gui, imperative, UssDirectory, UssFile, Validation, ZoweScheme } from "@zowe/zowe-explorer-api";
import { Gui, imperative, ProfilesCache, UssDirectory, UssFile, Validation, ZoweScheme } from "@zowe/zowe-explorer-api";
import { ZoweExplorerApiRegister } from "../../../../src/extending/ZoweExplorerApiRegister";
import { Profiles } from "../../../../src/configuration/Profiles";
import { ZoweUSSNode } from "../../../../src/trees/uss/ZoweUSSNode";
Expand Down Expand Up @@ -167,6 +167,10 @@ function createGlobalMocks() {
},
configurable: true,
});
Object.defineProperty(ProfilesCache, "getProfileSessionWithVscProxy", {
value: jest.fn().mockReturnValue(globalMocks.session),
configurable: true,
});
return globalMocks;
}

Expand Down

0 comments on commit 3e75cfe

Please sign in to comment.