ProfileManager

class core.zowe.core_for_zowe_sdk.ProfileManager(appname: str = 'zowe', show_warnings: bool = True)

Class used to manage profiles.

Profile Manager contains the logic to merge the different properties of profiles (from the Project Config and the Project User Config as well as the Global Config and Global User Config). This class handles all the exceptions raised in the Config File to provide a smooth user experience.

Parameters:
  • appname (str) – Name of the app

  • show_warnings (bool) – Indicates whether warnings are shown

property config_appname: str

Return the application name.

Returns:

The name of the application as configured in the current instance.

Return type:

str

property config_dir: str | None

Return the folder path where the Zowe z/OSMF Team Project Config files are stored.

Returns:

The directory path where the main project configuration files are located. This path can be None if not set.

Return type:

Optional[str]

property config_filename: str

Return the filename for the Zowe z/OSMF Team Project Config.

Returns:

The filename of the main project configuration file.

Return type:

str

property config_filepath: str | None

Get the full filepath for the Zowe z/OSMF Team Project Config file.

Returns:

Filepath of configuration file or None if the location or filename is not set.

Return type:

Optional[str]

static get_env(cfg: ConfigFile, cwd: str | None = None) dict[str, Any]

Map the env variables to the profile properties.

Parameters:
  • cfg (ConfigFile) – A config file that contains the schema properties.

  • cwd (Optional[str]) – Path of current working directory.

Returns:

Containing profile properties from env variables (prop: value).

Return type:

dict[str, Any]

get_highest_priority_layer(json_path: str) ConfigFile | None

Get the highest priority layer (configuration file) based on the given profile name.

Parameters:

json_path (str) – The path of the json.

Raises:

FileNotFoundError – File is not found in given path.

Returns:

The highest priority layer (configuration file) that contains the specified profile, or None if the profile is not found in any layer.

Return type:

Optional[ConfigFile]

static get_profile(cfg: ConfigFile, profile_name: str | None, profile_type: str | None, validate_schema: bool | None = True) Profile

Retrieve a profile from the configuration file, optionally validating the schema.

Parameters:
  • cfg (ConfigFile) – The configuration file object which contains the profiles.

  • profile_name (Optional[str]) – The name of the profile to retrieve. If None, the method attempts to fetch the profile based only on the type.

  • profile_type (Optional[str]) – The type of the profile to retrieve. If None, the method attempts to fetch the profile based only on the name.

  • validate_schema (Optional[bool]) – Whether to validate the profile against the schema present in the configuration file.

Returns:

A NamedTuple containing the profile data, name, and any secure properties not found.

Return type:

Profile

Raises:
  • ValidationError – If the instance is invalid under the provided schema.

  • SchemaError – If the provided schema itself is invalid.

  • UndefinedTypeCheck – If a type checker is asked to check a type it does not have registered.

  • UnknownType – If an unknown type is found in the schema.

  • FormatError – If validating a format in the configuration fails.

load(profile_name: str | None = None, profile_type: str | None = None, check_missing_props: bool = True, validate_schema: bool | None = True, override_with_env: bool | None = False) dict[str, Any]

Load connection details from a team config profile.

We will load properties from config files in the following order, from highest to lowest priority: 1. Project User Config (./zowe.config.user.json) 2. Project Config (./zowe.config.json) 3. Global User Config (~/zowe.config.user.json) 4. Global Config (~/zowe.config.json)

If profile_type is not base, then we will load properties from both profile_type and base profiles and merge them together.

Parameters:
  • profile_name (Optional[str]) – The name of the profile to load. If None, profiles are loaded based only on profile type.

  • profile_type (Optional[str]) – The type of the profile to load, e.g., ‘zosmf’, ‘zftp’. If None, profiles are loaded based only on name.

  • check_missing_props (bool) – Flag to indicate whether to check for missing secure properties.

  • validate_schema (Optional[bool]) – Whether to validate the loaded profile against the schema defined in the configuration.

  • override_with_env (Optional[bool]) – If True, overrides profile properties with values from environment variables.

Raises:
  • ProfileNotFound – If both profile_name and profile_type are not provided, indicating which profile to load.

  • SecureValuesNotFound – If any secure properties are required but not found or loaded.

Returns:

A dictionary containing the merged connection details from all relevant profiles.

Return type:

dict[str, Any]

save() None

Save the layers (configuration files) to disk.

set_profile(profile_path: str, profile_data: dict[str, Any]) None

Set a profile in the highest priority layer (configuration file) based on the given profile name.

Parameters:
  • profile_path (str) – The path of the profile to be set. eg: profiles.zosmf

  • profile_data (dict[str, Any]) – The data of the profile to set.

set_property(json_path: str, value: str, secure: bool | None = None) None

Set a property in the profile, storing it securely if necessary.

Parameters:
  • json_path (str) – The JSON path of the property to set.

  • value (str) – The value to be set for the property.

  • secure (Optional[bool]) – If True, the property will be stored securely. Default is None.

property user_config_dir: str | None

Return the folder path where the Zowe z/OSMF User Project Config files are stored.

Returns:

The directory path where the user-specific project configuration files are located.

Return type:

Optional[str]