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

VSC Proxy Support #3291

Merged
merged 34 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
33b33fb
initial vsc proxy work
JillieBeanSim Oct 15, 2024
a1fa9f6
Merge branch 'main' into vsc-proxy-support
JillieBeanSim Oct 30, 2024
d536f51
fix circ dependency issues
JillieBeanSim Oct 30, 2024
b88c615
update zosmf session obtaining methods
JillieBeanSim Oct 30, 2024
7cd69de
update workflow and fix some unit tests
JillieBeanSim Nov 1, 2024
d196ff7
fix ZE API unit tests
JillieBeanSim Nov 4, 2024
325d9d6
fix ZE unit tests
JillieBeanSim Nov 4, 2024
d740e81
Merge remote-tracking branch 'origin/main' into vsc-proxy-support
JillieBeanSim Nov 4, 2024
a4e823a
add VscSettings unit tests
JillieBeanSim Nov 4, 2024
9907c04
profilesCache unit tests
JillieBeanSim Nov 4, 2024
3755ed1
add CHANGELOGs
JillieBeanSim Nov 4, 2024
7ede2bb
Merge remote-tracking branch 'origin/main' into vsc-proxy-support
JillieBeanSim Nov 5, 2024
9df5df9
update sdks
JillieBeanSim Nov 6, 2024
371f76e
fix unit tests
JillieBeanSim Nov 6, 2024
9f707a4
Merge branch 'main' into vsc-proxy-support
JillieBeanSim Nov 6, 2024
d15b808
update sdk version in changelogs
JillieBeanSim Nov 6, 2024
7c23f6e
Merge remote-tracking branch 'origin/main' into vsc-proxy-support
JillieBeanSim Nov 7, 2024
42c34ab
run prepublish
JillieBeanSim Nov 7, 2024
a69607f
Merge branch 'main' into vsc-proxy-support
JillieBeanSim Nov 13, 2024
20c1c38
Merge branch 'main' into vsc-proxy-support
JillieBeanSim Nov 14, 2024
ae40c7c
Merge branch 'main' into vsc-proxy-support
JillieBeanSim Nov 15, 2024
f92e5d0
Merge branch 'main' into vsc-proxy-support
zFernand0 Nov 19, 2024
8829262
Merge remote-tracking branch 'origin/main' into vsc-proxy-support
JillieBeanSim Nov 19, 2024
8c6af6a
Merge branch 'main' into vsc-proxy-support
zFernand0 Nov 20, 2024
415e801
address comments
JillieBeanSim Nov 20, 2024
16864bd
get lock from main
JillieBeanSim Nov 20, 2024
7891e31
update sdk changelog entry in ftp extenstion to match other packages
JillieBeanSim Nov 20, 2024
2bc1d38
Merge remote-tracking branch 'origin/main' into vsc-proxy-support
JillieBeanSim Nov 21, 2024
b8f090c
address feedback
JillieBeanSim Nov 21, 2024
3dfe351
Merge branch 'main' into vsc-proxy-support
JillieBeanSim Nov 21, 2024
c8e2675
Merge branch 'main' into vsc-proxy-support
JillieBeanSim Nov 21, 2024
ccae372
remove session check and undefined return type
JillieBeanSim Nov 21, 2024
aeb8393
Merge remote-tracking branch 'origin/main' into vsc-proxy-support
JillieBeanSim Nov 21, 2024
9e1b653
Merge branch 'main' into vsc-proxy-support
zFernand0 Nov 22, 2024
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
2 changes: 2 additions & 0 deletions packages/zowe-explorer-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ All notable changes to the "zowe-explorer-api" extension will be documented in t

### New features and enhancements

- 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)
- 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
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);
});
});
});
10 changes: 10 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 { 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,15 @@
return convertResult;
}

public static getProfileSessionWithVscProxy(session: imperative.Session): imperative.Session | undefined {
zFernand0 marked this conversation as resolved.
Show resolved Hide resolved
if (!session) {
return;

Check warning on line 394 in packages/zowe-explorer-api/src/profiles/ProfilesCache.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer-api/src/profiles/ProfilesCache.ts#L394

Added line #L394 was not covered by tests
}
const VsCodeProxySettings = VscSettings.getVsCodeProxySettings();
Fixed Show fixed Hide fixed
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);
JillieBeanSim marked this conversation as resolved.
Show resolved Hide resolved
}

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);
}
traeok marked this conversation as resolved.
Show resolved Hide resolved

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");
zFernand0 marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -10,6 +10,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)
- Allow extenders to add context menu actions to a top level node, i.e. data sets, USS, Jobs, by encoding the profile type in the context value. [#3309](https://github.com/zowe/zowe-explorer-vscode/pull/3309)
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 @@ -171,6 +171,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 @@ -216,6 +216,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