Options
All
  • Public
  • Public/Protected
  • All
Menu

This class provides functions to retrieve profile-related information. It can load the relevant configuration files, merge all possible profile argument values using the Zowe order-of-precedence, and access desired profile attributes from the Zowe configuration settings.

Pseudocode examples:

   // Construct a new object. Use it to read the profiles from disk.
   // ProfileInfo functions throw a ProfInfoErr exception for errors.
   // You can catch those errors and test the errorCode for known
   // values. We are only showing the try/catch on the function
   // below, but it applies to any ProfileInfo function.
   profInfo = new ProfileInfo("zowe");
   try {
       await profInfo.readProfilesFromDisk();
   } catch(err) {
       if (err instanceof ProfInfoErr) {
           if (err.errcode == ProfInfoErr.CANT_GET_SCHEMA_URL) {
               youTakeAnAlternateAction();
           } else {
               // report the error
           }
       } else {
           // handle other exceptions
       }
   }

   // Maybe you want the list of all zosmf profiles
   let arrayOfProfiles = profInfo.getAllProfiles("zosmf");
   youDisplayTheListOfProfiles(arrayOfProfiles);

   // Maybe you want the default zosmf profile
   let zosmfProfile = profInfo.getDefaultProfile("zosmf");
   youUseTheProfile(zosmfProfile);

   // Maybe you want the arg values for the default JCLCheck profile
   let jckProfile = profInfo.getDefaultProfile("jclcheck");
   let jckMergedArgs = profInfo.mergeArgsForProfile(jckProfile);
   let jckFinalArgs = youPromptForMissingArgsAndCombineWithKnownArgs(
       jckMergedArgs.knownArgs, jckMergedArgs.missingArgs
   );
   youRunJclCheck(jckFinalArgs);

   // Maybe no profile of type "zosmf" even exists.
   let zosmfProfiles = profInfo.getAllProfiles("zosmf");
   if (zosmfProfiles.length == 0) {
       // No zosmf profile exists
       // Merge any required arg values for the zosmf profile type
       let zosmfMergedArgs =
           profInfo.mergeArgsForProfileType("zosmf");

       // Values of secure arguments must be loaded separately. You can
       // freely log the contents of zosmfMergedArgs without leaking secure
       // argument values, until they are loaded with the lines below.
       zosmfMergedArgs.knownArgs.forEach((arg) => {
           if (arg.secure) arg.argValue = profInfo.loadSecureArg(arg);
       });

       let finalZosmfArgs =
           youPromptForMissingArgsAndCombineWithKnownArgs(
               zosmfMergedArgs.knownArgs,
               zosmfMergedArgs.missingArgs
           );
       youRunSomeZosmfCommand(finalZosmfArgs);
   }

   // So you want to write to a config file? You must use your own
   // old-school techniques to write to old-school profiles.
   // You then use alternate logic for a team config.
   // You must use the Config API to write to a team configuration.
   // See the Config class documentation for functions to set
   // and save team config arguments.

   // Let's save some zosmf arguments from the example above.
   let yourZosmfArgsToWrite: IProfArgAttrs =
       youSetValuesToOverwrite(
           zosmfMergedArgs.knownArgs, zosmfMergedArgs.missingArgs
       );
   if (profInfo.usingTeamConfig {
       let configObj: Config = profInfo.getTeamConfig();
       youWriteArgValuesUsingConfigObj(
           configObj, yourZosmfArgsToWrite
       );
   } else {
       youWriteOldSchoolProfiles(yourZosmfArgsToWrite);
   }

Hierarchy

  • ProfileInfo

Index

Constructors

constructor

Properties

Private mAppName

mAppName: string = null

Private mCredentials

mCredentials: ProfileCredentials

Private mImpLogger

mImpLogger: Logger = null

Private mLoadedConfig

mLoadedConfig: Config = null

Private mOldSchoolProfileCache

mOldSchoolProfileCache: IProfileLoaded[] = null

Private mOldSchoolProfileDefaults

mOldSchoolProfileDefaults: {} = null

Type declaration

  • [key: string]: string

Private mOldSchoolProfileRootDir

mOldSchoolProfileRootDir: string = null

Private mOldSchoolProfileTypes

mOldSchoolProfileTypes: string[]

Private mOverrideWithEnv

mOverrideWithEnv: boolean = false

Private mProfileSchemaCache

mProfileSchemaCache: Map<string, IProfileSchema>

Cache of profile schema objects mapped by profile type and config path if applicable. Examples of map keys:

  • For team config: "/root/.zowe/zowe.config.json:zosmf"
  • For old profiles: "zosmf"

Private mUsingTeamConfig

mUsingTeamConfig: boolean = false

Accessors

usingTeamConfig

  • get usingTeamConfig(): boolean
  • Returns an indicator of whether we are using a team configuration or old-school profiles.

    You must call ProfileInfo.readProfilesFromDisk() before calling this function.

    Returns boolean

    True when we are using a team config. False means old-school profiles.

Methods

Private argDataType

  • argDataType(propType: string | string[]): "string" | "number" | "boolean" | "array" | "object"
  • Get arg data type from a "typeof" string. Arg data types can be basic types like string, number, and boolean. If they are any other type or a union of types, their type will be represented simply as object.

    Parameters

    • propType: string | string[]

      The type of a profile property

    Returns "string" | "number" | "boolean" | "array" | "object"

Private argOldProfileLoc

  • argOldProfileLoc(profileName: string, profileType: string): IProfLoc

Private argTeamConfigLoc

Private ensureReadFromDisk

  • ensureReadFromDisk(): void

Private findTeamOsLocation

  • findTeamOsLocation(jsonPath: string, excludeHomeDir?: boolean): string[]
  • Parameters

    • jsonPath: string

      The long form JSON path of the profile we are searching for.

    • Optional excludeHomeDir: boolean

      The long form JSON path of the profile we are searching for.

    Returns string[]

    A string array containing the location of all files containing the specified team profile

getAllProfiles

  • Get all of the typed profiles in the configuration.

    Parameters

    • Optional profileType: string
         Limit selection to only profiles of the specified type.
         If not supplied, the names of all typed profiles are returned.
      
    • Optional options: IGetAllProfilesOptions

    Returns IProfAttrs[]

    An array of profile attribute objects. In addition to the name, you get the profile type, an indicator of whether the profile is the default profile for that type, and the location of that profile.

         If no profile exists for the specified type (or if
         no profiles of any kind exist), we return an empty array
         ie, length is zero.
    

getDefaultProfile

  • getDefaultProfile(profileType: string): IProfAttrs | null

getOsLocInfo

getTeamConfig

  • Get the Config object used to manipulate the team configuration on disk.

    Our current market direction is to encourage customers to edit the team configuration files in their favorite text editor.

    If you must ignore this recommended practice, you must use the Config class to manipulate the team config files. This class has a more detailed and therefore more complicated API, but it does contain functions to write data to the team configuration files.

    You must call ProfileInfo.readProfilesFromDisk() before calling this function.

    Returns Config

    An instance of the Config class that can be used to manipulate the team configuration on disk.

Private getTeamSubProfiles

  • getTeamSubProfiles(path: string, jsonPath: string, profObj: {}, profileType?: string): IProfAttrs[]
  • Get all of the subprofiles in the configuration.

    Parameters

    • path: string
           The short form profile name dotted path
      
    • jsonPath: string
           The long form profile dotted path
      
    • profObj: {}
           The profiles object from the parent profile.
           Contains the subprofiles to search through.
      
      • [key: string]: any
    • Optional profileType: string
           Limit selection to only profiles of the specified type.
           If not supplied, the names of all typed profiles are returned.
      

    Returns IProfAttrs[]

    An array of profile attribute objects. In addition to the name, you get the profile type, an indicator of whether the profile is the default profile for that type, and the location of that profile.

         If no profile exists for the specified type (or if
         no profiles of any kind exist), we return an empty array
         ie, length is zero.
    

Private initImpUtils

  • initImpUtils(): void

Private isDefaultTeamProfile

  • isDefaultTeamProfile(path: string, profileType?: string): boolean
  • Parameters

    • path: string
               The short form profile name dotted path
      
    • Optional profileType: string
               Limit selection to profiles of the specified type
      

    Returns boolean

    A boolean true if the profile is a default profile, and a boolean false if the profile is not a default profile

isSecured

  • isSecured(): boolean

Private loadAllSchemas

  • loadAllSchemas(): void
  • Load any profile schema objects found on disk and cache them. For team config, we check each config layer and load its schema JSON if there is one associated. For old school profiles, we load the meta YAML file for each profile type if it exists in the profile root directory.

    Returns void

Private loadSchema

loadSecureArg

mergeArgsForProfile

  • Merge all of the available values for arguments defined for the specified profile. Values are retrieved from the following sources. Each successive source will override the previous source.

    • A default value for the argument that is defined in the profile definition.
    • A value defined in the base profile.
    • A value defined in the specified service profile.
    • For a team configuration, both the base profile values and the service profile values will be overridden with values from a zowe.config.user.json file (if it exists).
    • An environment variable for that argument (if environment overrides are enabled).

    Parameters

    • profile: IProfAttrs
         The profile whose arguments are to be merged.
      
    • Default value mergeOpts: IProfMergeArgOpts = { getSecureVals: false }
         Options to use when merging arguments.
         This parameter is not required. Defaults will be used.
      

    Returns IProfMergedArg

    An object that contains an array of known profile argument values and an array of required profile arguments which have no value assigned. Either of the two arrays could be of zero length, depending on the user's configuration and environment.

         We will return null if the profile does not exist
         in the current Zowe configuration.
    

mergeArgsForProfileType

  • Merge all of the available values for arguments defined for the specified profile type. See mergeArgsForProfile() for details about the merging algorithm. The intended use is when no profile of a specific type exists. The consumer app can prompt for values for missing arguments and then perform the desired operation.

    Parameters

    • profileType: string
         The type of profile of interest.
      
    • Default value mergeOpts: IProfMergeArgOpts = { getSecureVals: false }
         Options to use when merging arguments.
         This parameter is not required. Defaults will be used.
      

    Returns IProfMergedArg

    The complete set of required properties;

Private oldProfileFilePath

  • oldProfileFilePath(profileType: string, profileName: string): string
  • Given a profile name and type, return the OS location of the associated YAML file.

    Parameters

    • profileType: string

      Type of an old school profile (e.g., zosmf)

    • profileName: string

      Name of an old school profile (e.g., LPAR1)

    Returns string

Private overrideWithEnv

  • Override values in a merged argument object with values found in environment variables. The choice to override enviroment variables is controlled by an option on the ProfileInfo constructor.

    Parameters

    • mergedArgs: IProfMergedArg
       On input, this must be an object containing merged arguments
       obtained from configuration settings. This function will override
       values in mergedArgs.knownArgs with values found in environment
       variables. It will also move arguments from mergedArgs.missingArgs
       into mergedArgs.knownArgs if a value is found in an environment
       variable for any missingArgs.
      
    • Optional profSchema: IProfileSchema

    Returns void

readProfilesFromDisk

  • Read either the new team configuration files (if any exist) or read the old-school profile files.

    Parameters

    • Optional teamCfgOpts: IConfigOpts
         The optional choices used when reading a team configuration.
         This parameter is ignored, if the end-user is using old-school
         profiles.
      

    Returns Promise<void>

removeKnownProperty

  • Remove a known property from the ProfileInfo class This method will call the updateKnownProperty method with a value set to undefined and serves as a helper function to make is easier to understand when a known property is removed.

    example

    The example below describes how to remove a property

        // Using the removeKnownProperty method
        profileInfo.removeKnownProperty({mergedArgs, property: "someProperty"});
        // Using the updateKnownProperty method
        profileInfo.updateKnownProperty({mergedArgs, property: "someProperty", value: undefined, isSecure: false});
    

    Parameters

    Returns Promise<boolean>

    Returns a boolean indicating if the property has been removed

updateKnownProperty

  • Update a given property with the value provided. This function only works for properties that can be found in the config files (including secure arrays). If the property cannot be found, this function will resolve to false This function supports v1 profiles

    Parameters

    Returns Promise<boolean>

updateProperty

Static createSession

  • Create a session from profile arguments that have been retrieved from ProfileInfo functions.

    Parameters

    • profArgs: IProfArgAttrs[]
       An array of profile arguments.
      
    • Default value connOpts: IOptionsForAddConnProps = {}
       Options that alter our actions. See IOptionsForAddConnProps.
       The connOpts parameter need not be supplied.
       Default properties may be added to any supplied connOpts.
       The only option values used by this function are:
           connOpts.requestToken
           connOpts.defaultTokenType
      

    Returns Session

    A session that can be used to connect to a remote host.

Static initSessCfg

Static profAttrsToProfLoaded

  • Convert an IProfAttrs object into an IProfileLoaded objects This is a convenience function. IProfileLoaded was frequently passed among functions. This conversion function allows existing code to acquire values in the IProfAttrs structure but pass those values around in the older IProfileLoaded structure. The IProfAttrs properties will be copied as follows:

     IProfileLoaded.name    <-- IProfAttrs.profName
     IProfileLoaded.type    <-- IProfAttrs.profType
     IProfileLoaded.profile <-- profAttrs
    

    Parameters

    • profAttrs: IProfAttrs
       A profile attributes object.
      
    • Optional dfltProfLoadedVals: any
       A JSON object containing additional names from IProfileLoaded for
       which a value should be supplied. IProfileLoaded contains more
       properties than IProfAttrs. The items in this object will be
       placed into the resulting IProfileLoaded object.
       We use type "any" because all of the required properties of
       IProfileLoaded will not be supplied by dfltProfLoadedVals.
       If dfltProfLoadedVals is not supplied, only the following minimal
       set if hard-coded properties will be added to the IProfileLoaded object.
      
       IProfileLoaded.message      <-- "" (an empty string)
       IProfileLoaded.failNotFound <-- false
      

    Returns IProfileLoaded

    An IProfileLoaded object;

Generated using TypeDoc