diff --git a/packages/imperative/src/config/src/ProfileInfo.ts b/packages/imperative/src/config/src/ProfileInfo.ts index 54dcc32713..bca1c0f791 100644 --- a/packages/imperative/src/config/src/ProfileInfo.ts +++ b/packages/imperative/src/config/src/ProfileInfo.ts @@ -16,7 +16,7 @@ import * as lodash from "lodash"; import * as semver from "semver"; // for ProfileInfo structures -import { IProfArgAttrs } from "./doc/IProfArgAttrs"; +import { IProfArgAttrs, IProfDataType } from "./doc/IProfArgAttrs"; import { IProfAttrs } from "./doc/IProfAttrs"; import { IArgTeamConfigLoc, IProfLoc, IProfLocOsLoc, IProfLocOsLocLayer, ProfLocType } from "./doc/IProfLoc"; import { IProfMergeArgOpts } from "./doc/IProfMergeArgOpts"; @@ -50,7 +50,7 @@ import { IProfInfoRemoveKnownPropOpts } from "./doc/IProfInfoRemoveKnownPropOpts import { ConfigUtils } from "./ConfigUtils"; import { ConfigBuilder } from "./ConfigBuilder"; import { IAddProfTypeResult, IExtenderTypeInfo, IExtendersJsonOpts } from "./doc/IExtenderOpts"; -import { IConfigLayer } from ".."; +import { IConfigLayer, ISecureFieldDetails } from ".."; import { Constants } from "../../constants"; /** @@ -1388,6 +1388,57 @@ export class ProfileInfo { return finalSchema; } + // _______________________________________________________________________ + /** + * List of secure properties with more details, like value, location, and type + * + * @param opts The user and global flags that specify one of the four + * config files (aka layers). + * @returns Array of secure property details + */ + public secureFieldsWithDetails(opts?: { user: boolean; global: boolean }): ISecureFieldDetails[] { + const config = this.getTeamConfig(); + const layer = opts ? config.findLayer(opts.user, opts.global) : config.layerActive(); + const fields = config.api.secure.findSecure(layer.properties.profiles, "profiles"); + const vault = config.api.secure.getSecureFieldsForLayer(layer.path); + + const response: ISecureFieldDetails[] = []; + + // Search the vault for each secure field + fields.forEach(fieldPath => { + // Scan the cached contents of the vault + for (const [loc, val] of Object.entries(vault)) { + // Search inside the secure fields for this layer + Object.entries(val).map(([propPath, propValue]) => { + if (propPath === fieldPath) { + response.push({ + path: fieldPath, + name: fieldPath.split(".properties.")[1], + type: this.argDataType(typeof propValue), + value: propValue as IProfDataType, + loc, + }); + } + }); + } + }); + + fields.forEach(fieldPath => { + if (response.find(details => details.path === fieldPath) == null) { + response.push({ + path: fieldPath, + name: fieldPath.split(".properties.")[1], + type: undefined, + value: undefined, + loc: undefined + }); + } + }); + + return response; + } + + // _______________________________________________________________________ /** * Get all of the subprofiles in the configuration. diff --git a/packages/imperative/src/config/src/api/ConfigSecure.ts b/packages/imperative/src/config/src/api/ConfigSecure.ts index 7586cfaab1..8a6178234f 100644 --- a/packages/imperative/src/config/src/api/ConfigSecure.ts +++ b/packages/imperative/src/config/src/api/ConfigSecure.ts @@ -22,6 +22,7 @@ import { CredentialManagerFactory } from "../../../security"; import { ConfigUtils } from "../ConfigUtils"; import { ZoweUserEvents } from "../../../events/src/EventConstants"; import { EventOperator } from "../../../events/src/EventOperator"; +import { IConfigLayer } from "../doc/IConfigLayer"; /** * API Class for manipulating config layers. @@ -242,6 +243,17 @@ export class ConfigSecure extends ConfigApi { return secureProps; } + /** + * Retrieve secure properties for a givne layer path + * + * @param layerPath Path of the layer to get secure properties for + * @returns the secure properties for the given layer + */ + public getSecureFieldsForLayer(layerPath: string): IConfigSecureProperties { + const secureLayer = Object.keys(this.mConfig.mSecure).find(osLocation => osLocation === layerPath); + return secureLayer ? { [secureLayer] : this.mConfig.mSecure[secureLayer] } : null; + } + /** * Retrieve info that can be used to store a profile property securely. * diff --git a/packages/imperative/src/config/src/doc/IConfigSecure.ts b/packages/imperative/src/config/src/doc/IConfigSecure.ts index 283054446e..b66a96b4ca 100644 --- a/packages/imperative/src/config/src/doc/IConfigSecure.ts +++ b/packages/imperative/src/config/src/doc/IConfigSecure.ts @@ -9,6 +9,16 @@ * */ +import { IProfArgValue, IProfDataType } from "./IProfArgAttrs"; + export type IConfigSecureProperties = { [key: string]: any }; export type IConfigSecure = { [path: string]: IConfigSecureProperties }; + +export interface ISecureFieldDetails { + path: string; + name: string; + type: IProfDataType; + value: IProfArgValue; + loc: string; +} \ No newline at end of file