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: add secureFieldsWithDetails 😋 #2241

Merged
merged 12 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
55 changes: 53 additions & 2 deletions packages/imperative/src/config/src/ProfileInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
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";
Expand Down Expand Up @@ -50,7 +50,7 @@
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";

/**
Expand Down Expand Up @@ -1388,6 +1388,57 @@
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();

Check warning on line 1400 in packages/imperative/src/config/src/ProfileInfo.ts

View check run for this annotation

Codecov / codecov/patch

packages/imperative/src/config/src/ProfileInfo.ts#L1399-L1400

Added lines #L1399 - L1400 were not covered by tests
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);

Check warning on line 1403 in packages/imperative/src/config/src/ProfileInfo.ts

View check run for this annotation

Codecov / codecov/patch

packages/imperative/src/config/src/ProfileInfo.ts#L1402-L1403

Added lines #L1402 - L1403 were not covered by tests

const response: ISecureFieldDetails[] = [];

Check warning on line 1405 in packages/imperative/src/config/src/ProfileInfo.ts

View check run for this annotation

Codecov / codecov/patch

packages/imperative/src/config/src/ProfileInfo.ts#L1405

Added line #L1405 was not covered by tests

// Search the vault for each secure field
fields.forEach(fieldPath => {

Check warning on line 1408 in packages/imperative/src/config/src/ProfileInfo.ts

View check run for this annotation

Codecov / codecov/patch

packages/imperative/src/config/src/ProfileInfo.ts#L1408

Added line #L1408 was not covered by tests
// Scan the cached contents of the vault
for (const [loc, val] of Object.entries(vault)) {

Check warning on line 1410 in packages/imperative/src/config/src/ProfileInfo.ts

View check run for this annotation

Codecov / codecov/patch

packages/imperative/src/config/src/ProfileInfo.ts#L1410

Added line #L1410 was not covered by tests
// Search inside the secure fields for this layer
Object.entries(val).map(([propPath, propValue]) => {

Check warning on line 1412 in packages/imperative/src/config/src/ProfileInfo.ts

View check run for this annotation

Codecov / codecov/patch

packages/imperative/src/config/src/ProfileInfo.ts#L1412

Added line #L1412 was not covered by tests
if (propPath === fieldPath) {
response.push({

Check warning on line 1414 in packages/imperative/src/config/src/ProfileInfo.ts

View check run for this annotation

Codecov / codecov/patch

packages/imperative/src/config/src/ProfileInfo.ts#L1414

Added line #L1414 was not covered by tests
path: fieldPath,
name: fieldPath.split(".properties.")[1],
type: this.argDataType(typeof propValue),
value: propValue as IProfDataType,
loc,
});
}
});
}
});

fields.forEach(fieldPath => {

Check warning on line 1426 in packages/imperative/src/config/src/ProfileInfo.ts

View check run for this annotation

Codecov / codecov/patch

packages/imperative/src/config/src/ProfileInfo.ts#L1426

Added line #L1426 was not covered by tests
if (response.find(details => details.path === fieldPath) == null) {
response.push({

Check warning on line 1428 in packages/imperative/src/config/src/ProfileInfo.ts

View check run for this annotation

Codecov / codecov/patch

packages/imperative/src/config/src/ProfileInfo.ts#L1428

Added line #L1428 was not covered by tests
path: fieldPath,
name: fieldPath.split(".properties.")[1],
type: undefined,
value: undefined,
loc: undefined
});
}
});

return response;

Check warning on line 1438 in packages/imperative/src/config/src/ProfileInfo.ts

View check run for this annotation

Codecov / codecov/patch

packages/imperative/src/config/src/ProfileInfo.ts#L1438

Added line #L1438 was not covered by tests
}


// _______________________________________________________________________
/**
* Get all of the subprofiles in the configuration.
Expand Down
12 changes: 12 additions & 0 deletions packages/imperative/src/config/src/api/ConfigSecure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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.
Expand Down Expand Up @@ -242,6 +243,17 @@
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);

Check warning on line 253 in packages/imperative/src/config/src/api/ConfigSecure.ts

View check run for this annotation

Codecov / codecov/patch

packages/imperative/src/config/src/api/ConfigSecure.ts#L252-L253

Added lines #L252 - L253 were not covered by tests
return secureLayer ? { [secureLayer] : this.mConfig.mSecure[secureLayer] } : null;
}

/**
* Retrieve info that can be used to store a profile property securely.
*
Expand Down
10 changes: 10 additions & 0 deletions packages/imperative/src/config/src/doc/IConfigSecure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading