ConfigFile

class core.zowe.core_for_zowe_sdk.config_file.ConfigFile(type: str, name: str, _location: str | None = None, profiles: dict[str, ~typing.Any] | None=None, defaults: dict[str, ~typing.Any] | None=None, schema_property: dict[str, ~typing.Any] | None=None, secure_props: dict[str, ~typing.Any] | None=None, jsonc: dict[str, ~typing.Any] | None=None, _missing_secure_props: list[str] = <factory>, _ConfigFile__suppress_config_file_warnings: bool | None = (True, ))

Class used to represent a single config file.

Mainly it will have the following details :
  1. Type (“User Config” or “Team Config”)

    User Configs override Team Configs. User Configs are used to have personalised config details that the user don’t want to have in the Team Config.

  2. Directory in which the file is located.

  3. Name (excluding .config.json or .config.user.json)

  4. Contents of the file.

    4.1 Profiles 4.2 Defaults 4.3 Schema Property

  5. Secure Properties associated with the file.

autodiscover_config_dir() None

Autodiscover Zowe z/OSMF Team Config files by going up the path from current working directory.

Sets path if it finds the config directory, Else, it raises an Exception.

Raises:

FileNotFoundError – Cannot find file in directory.

find_profile(path: str, profiles: dict[str, Any]) dict[str, Any] | None

Find a profile at a specified location from within a set of nested profiles.

Parameters:
  • path (str) – The location to look for the profile

  • profiles (dict[str, Any]) – A dict of nested profiles

Returns:

The profile object that was found, or None if not found

Return type:

Optional[dict[str, Any]]

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

Load given profile including secure properties and excluding values from base profile.

Parameters:
  • profile_name (Optional[str]) – Name of the profile

  • profile_type (Optional[str]) – Type of the profile

  • validate_schema (Optional[bool]) – True if validation is preferred

Raises:

ProfileNotFound – Cannot find profile

Returns:

Returns a namedtuple called Profile

Return type:

Profile

get_profile_name_from_path(path: str) str

Get the name of the profile from the given path.

Parameters:

path (str) – The location to look for the profile

Returns:

Returns the profile name

Return type:

str

get_profile_path_from_name(short_path: str) str

Get the path of the profile from the given name.

Parameters:

short_path (str) – Partial path of profile

Returns:

Returns the full profile path

Return type:

str

get_profilename_from_profiletype(profile_type: str) str

Return profilename from given profiletype as defined in the team config profile.

Parameters:

profile_type (str) – Type of the profile

Returns:

The exact profilename of the profile to load from the mentioned type.

Return type:

str

Raises:

ProfileNotFound – Cannot find profile

init_from_file(validate_schema: bool | None = True) None

Initialize the class variable after setting filepath (or if not set, autodiscover the file).

Parameters:

validate_schema (Optional[bool]) – True if validation is preferred, false otherwise

load_profile_properties(profile_name: str) dict[str, Any]

Load profile properties given profile_name including secure properties.

Load exact profile properties (without prepopulated fields from base profile) from the profile dict and populate fields from the secure credentials storage

Parameters:

profile_name (str) – Name of the profile

Returns:

Object containing profile properties

Return type:

dict[str, Any]

Raises:

ValueError – Profile cannot be None

save(update_secure_props: bool | None = True) None

Save the config file to disk. and secure props to vault.

Parameters:

update_secure_props (Optional[bool]) – If True, the secure properties will be stored in the vault. Default is True.

Raises:

ValueError – Filepath must be set and valid.

schema_list(cwd: str | None = None) list[dict[str, Any]]

Load the schema properties in a sorted order according to the priority.

Parameters:

cwd (Optional[str]) – current working directory

Returns:

properties from schema

Return type:

list[dict[str, Any]]

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

Set a profile in the config file.

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

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

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.

suppress_config_warnings(value: bool) None

Suppress warnings in config files.

Parameters:

value (bool) – Warnings are shown or not

validate_schema() None

Get the $schema_property from the config and load the schema.