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

feat: API ML authentication provider to allow connecting to multiple instances #2419

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 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
60 changes: 47 additions & 13 deletions packages/zowe-explorer-api/src/profiles/ProfilesCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class ProfilesCache {
this.allTypes.push(type);
}
// check for proper merging of apiml tokens
this.checkMergingConfigAllProfiles();
await this.checkMergingConfigAllProfiles();
this.profilesForValidation = [];
} catch (error) {
this.log.error(error as string);
Expand Down Expand Up @@ -284,7 +284,7 @@ export class ProfilesCache {
for (const prof of profilesForType) {
const profAttr = this.getMergedAttrs(mProfileInfo, prof);
let profile = this.getProfileLoaded(prof.profName, prof.profType, profAttr);
profile = this.checkMergingConfigSingleProfile(profile);
profile = await this.checkMergingConfigSingleProfile(profile);
profByType.push(profile);
}
}
Expand Down Expand Up @@ -377,9 +377,14 @@ export class ProfilesCache {
}

// This will retrieve the base profile from imperative
public async fetchBaseProfile(): Promise<zowe.imperative.IProfileLoaded | undefined> {
public async fetchBaseProfile(profileName?: string): Promise<zowe.imperative.IProfileLoaded | undefined> {
const mProfileInfo = await this.getProfileInfo();
const baseProfileAttrs = mProfileInfo.getDefaultProfile("base");
let baseProfileAttrs: zowe.imperative.IProfAttrs;
if (profileName == null) {
baseProfileAttrs = mProfileInfo.getDefaultProfile("base");
} else {
baseProfileAttrs = mProfileInfo.getAllProfiles("base").find((p) => p.profName === profileName);
}
if (baseProfileAttrs == null) {
return undefined;
}
Expand Down Expand Up @@ -453,14 +458,14 @@ export class ProfilesCache {
}

// used by refresh to check correct merging of allProfiles
protected checkMergingConfigAllProfiles(): void {
const baseProfile = this.defaultProfileByType.get("base");
protected async checkMergingConfigAllProfiles(): Promise<void> {
const allProfiles: zowe.imperative.IProfileLoaded[] = [];
this.allTypes.forEach((type) => {
for (const type of this.allTypes) {
try {
const allProfilesByType: zowe.imperative.IProfileLoaded[] = [];
const profByType = this.profilesByType.get(type);
profByType.forEach((profile) => {
for (const profile of profByType) {
const baseProfile = await this.findApimlProfile(profile);
if (this.shouldRemoveTokenFromProfile(profile, baseProfile)) {
profile.profile.tokenType = undefined;
profile.profile.tokenValue = undefined;
Expand All @@ -471,20 +476,20 @@ export class ProfilesCache {
}
allProfiles.push(profile);
allProfilesByType.push(profile);
});
}
this.profilesByType.set(type, allProfilesByType);
} catch (error) {
// do nothing, skip if profile type is not included in config file
this.log.debug(error as string);
}
});
}
this.allProfiles = [];
this.allProfiles.push(...allProfiles);
}

// check correct merging of a single profile
protected checkMergingConfigSingleProfile(profile: zowe.imperative.IProfileLoaded): zowe.imperative.IProfileLoaded {
const baseProfile = this.defaultProfileByType.get("base");
protected async checkMergingConfigSingleProfile(profile: zowe.imperative.IProfileLoaded): Promise<zowe.imperative.IProfileLoaded> {
const baseProfile = await this.findApimlProfile(profile);
if (this.shouldRemoveTokenFromProfile(profile, baseProfile)) {
profile.profile.tokenType = undefined;
profile.profile.tokenValue = undefined;
Expand All @@ -499,10 +504,38 @@ export class ProfilesCache {
for (const arg of mergedArgs.knownArgs) {
profile[arg.argName] = arg.argValue;
}
// if (profile.apimlProfile != null) {
// const apimlProfAttrs = mProfileInfo.getAllProfiles("base").find((p) => p.profName === profile.apimlProfile);
// if (apimlProfAttrs != null) {
// const apimlMergedArgs = mProfileInfo.mergeArgsForProfile(apimlProfAttrs, { getSecureVals: true });
// for (const arg of apimlMergedArgs.knownArgs) {
// profile[arg.argName] = arg.argValue;
// }
// }
// }
}
return profile;
}

/**
* Look for a base profile where APIML token can be stored for SSO login.
* @param profile Imperative loaded profile object
* @returns Base profile to store APIML token
*/
public async findApimlProfile(profile: zowe.imperative.IProfileLoaded): Promise<zowe.imperative.IProfileLoaded | undefined> {
// if (profile.profile?.apimlProfile != null) {
// return profile.profile.apimlProfile as string;
// }
if ((await this.getProfileInfo()).usingTeamConfig && profile.name.includes(".")) {
for (const baseProfile of await this.fetchAllProfilesByType("base")) {
if (profile.name.startsWith(baseProfile.name + ".")) {
return baseProfile;
}
}
}
return this.fetchBaseProfile();
}

// create an array that includes registered types from apiRegister.registeredApiTypes()
// and allExternalTypes
private getAllProfileTypes(registeredTypes: string[]): string[] {
Expand All @@ -518,7 +551,8 @@ export class ProfilesCache {
profile?.profile?.host &&
profile?.profile?.port &&
(baseProfile?.profile.host !== profile?.profile.host || baseProfile?.profile.port !== profile?.profile.port) &&
profile?.profile.tokenType === zowe.imperative.SessConstants.TOKEN_TYPE_APIML
profile?.type !== zowe.ProfileConstants.BaseProfile.type &&
(profile?.profile.tokenType as string)?.startsWith(zowe.imperative.SessConstants.TOKEN_TYPE_APIML)
);
}
}
2 changes: 1 addition & 1 deletion packages/zowe-explorer/i18n/sample/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"displayName": "Zowe Explorer",
"description": "VS Code extension, powered by Zowe CLI, that streamlines interaction with mainframe data sets, USS files, and jobs",
"viewsContainers.activitybar": "Zowe Explorer",
"zowe.promptCredentials": "Update Credentials",
"zowe.promptCredentials": "Manage Credentials",
"zowe.extRefresh": "Refresh Zowe Explorer",
"zowe.ds.explorer": "Data Sets",
"zowe.uss.explorer": "Unix System Services (USS)",
Expand Down
66 changes: 18 additions & 48 deletions packages/zowe-explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -929,30 +929,20 @@
"group": "099_zowe_ussModification:@4"
},
{
"when": "view == zowe.uss.explorer && viewItem =~ /_validate/ && !listMultiSelection",
"command": "zowe.uss.disableValidation",
"when": "view == zowe.uss.explorer && viewItem =~ /^(?!.*_fav.*)ussSession.*/ && !listMultiSelection",
"command": "zowe.promptCredentials",
"group": "098_zowe_ussProfileAuthentication@1"
},
{
"when": "view == zowe.uss.explorer && viewItem =~ /_noValidate/ && !listMultiSelection",
"command": "zowe.uss.enableValidation",
"when": "view == zowe.uss.explorer && viewItem =~ /_validate/ && !listMultiSelection",
"command": "zowe.uss.disableValidation",
"group": "098_zowe_ussProfileAuthentication@2"
},
{
"when": "view == zowe.uss.explorer && viewItem =~ /^(?!.*_fav.*)ussSession.*/ && !listMultiSelection",
"command": "zowe.promptCredentials",
"when": "view == zowe.uss.explorer && viewItem =~ /_noValidate/ && !listMultiSelection",
"command": "zowe.uss.enableValidation",
"group": "098_zowe_ussProfileAuthentication@3"
},
{
"when": "view == zowe.uss.explorer && viewItem =~ /^(?!.*_fav.*)ussSession.*/ && !listMultiSelection",
"command": "zowe.uss.ssoLogin",
"group": "098_zowe_ussProfileAuthentication@4"
},
{
"when": "view == zowe.uss.explorer && viewItem =~ /^(?!.*_fav.*)ussSession.*/ && !listMultiSelection",
"command": "zowe.uss.ssoLogout",
"group": "098_zowe_ussProfileAuthentication@5"
},
{
"when": "viewItem =~ /^(?!.*_fav.*)ussSession.*/ && !listMultiSelection",
"command": "zowe.uss.editSession",
Expand Down Expand Up @@ -1139,30 +1129,20 @@
"group": "099_zowe_dsModification@5"
},
{
"when": "view == zowe.ds.explorer && viewItem =~ /_validate/ && !listMultiSelection",
"command": "zowe.ds.disableValidation",
"when": "view == zowe.ds.explorer && viewItem =~ /^(?!.*_fav.*)session.*/ && !listMultiSelection",
"command": "zowe.promptCredentials",
"group": "098_zowe_dsProfileAuthentication@6"
},
{
"when": "view == zowe.ds.explorer && viewItem =~ /_noValidate/ && !listMultiSelection",
"command": "zowe.ds.enableValidation",
"when": "view == zowe.ds.explorer && viewItem =~ /_validate/ && !listMultiSelection",
"command": "zowe.ds.disableValidation",
"group": "098_zowe_dsProfileAuthentication@7"
},
{
"when": "view == zowe.ds.explorer && viewItem =~ /^(?!.*_fav.*)session.*/ && !listMultiSelection",
"command": "zowe.promptCredentials",
"when": "view == zowe.ds.explorer && viewItem =~ /_noValidate/ && !listMultiSelection",
"command": "zowe.ds.enableValidation",
"group": "098_zowe_dsProfileAuthentication@8"
},
{
"when": "view == zowe.ds.explorer && viewItem =~ /^(?!.*_fav.*)session.*/ && !listMultiSelection",
"command": "zowe.ds.ssoLogin",
"group": "098_zowe_dsProfileAuthentication@9"
},
{
"when": "view == zowe.ds.explorer && viewItem =~ /^(?!.*_fav.*)session.*/ && !listMultiSelection",
"command": "zowe.ds.ssoLogout",
"group": "098_zowe_dsProfileAuthentication@10"
},
{
"when": "view == zowe.ds.explorer && viewItem =~ /^(?!.*_fav.*)session.*/ && !listMultiSelection",
"command": "zowe.ds.editSession",
Expand Down Expand Up @@ -1304,30 +1284,20 @@
"group": "099_zowe_jobsModification"
},
{
"when": "view == zowe.jobs.explorer && viewItem =~ /_validate/ && !listMultiSelection",
"command": "zowe.jobs.disableValidation",
"when": "view == zowe.jobs.explorer && viewItem =~ /^(?!.*_fav.*)server.*/ && !listMultiSelection",
"command": "zowe.promptCredentials",
"group": "098_zowe_jobsProfileAuthentication@3"
},
{
"when": "view == zowe.jobs.explorer && viewItem =~ /_noValidate/ && !listMultiSelection",
"command": "zowe.jobs.enableValidation",
"when": "view == zowe.jobs.explorer && viewItem =~ /_validate/ && !listMultiSelection",
"command": "zowe.jobs.disableValidation",
"group": "098_zowe_jobsProfileAuthentication@4"
},
{
"when": "view == zowe.jobs.explorer && viewItem =~ /^(?!.*_fav.*)server.*/ && !listMultiSelection",
"command": "zowe.promptCredentials",
"when": "view == zowe.jobs.explorer && viewItem =~ /_noValidate/ && !listMultiSelection",
"command": "zowe.jobs.enableValidation",
"group": "098_zowe_jobsProfileAuthentication@5"
},
{
"when": "view == zowe.jobs.explorer && viewItem =~ /^(?!.*_fav.*)server.*/ && !listMultiSelection",
"command": "zowe.jobs.ssoLogin",
"group": "098_zowe_jobsProfileAuthentication@6"
},
{
"when": "view == zowe.jobs.explorer && viewItem =~ /^(?!.*_fav.*)server.*/ && !listMultiSelection",
"command": "zowe.jobs.ssoLogout",
"group": "098_zowe_jobsProfileAuthentication@7"
},
{
"when": "view == zowe.jobs.explorer && viewItem =~ /^(?!.*_fav.*)server.*/ && !listMultiSelection",
"command": "zowe.jobs.editSession",
Expand Down
2 changes: 1 addition & 1 deletion packages/zowe-explorer/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"displayName": "Zowe Explorer",
"description": "VS Code extension, powered by Zowe CLI, that streamlines interaction with mainframe data sets, USS files, and jobs",
"viewsContainers.activitybar": "Zowe Explorer",
"zowe.promptCredentials": "Update Credentials",
"zowe.promptCredentials": "Manage Credentials",
"zowe.extRefresh": "Refresh Zowe Explorer",
"zowe.ds.explorer": "Data Sets",
"zowe.uss.explorer": "Unix System Services (USS)",
Expand Down
Loading