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

Fixes profile merge order to match Node.js SDK #203

Merged
merged 16 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ All notable changes to the Zowe Client Python SDK will be documented in this fil

## Recent Changes

- Bug: Fixed profile merge order to match Node.js SDK
- Feature: Added method to load profile properties from environment variables
- Feature: Added a CredentialManager class to securely retrieve values from credentials and manage multiple credential entries on Windows [#134](https://github.com/zowe/zowe-client-python-sdk/issues/134)
- Feature: Added method to load profile properties from environment variables
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ chardet==4.0.0
colorama==0.4.4
commentjson==0.9.0
coverage==5.4
deepmerge==1.1.0
flake8==3.8.4
idna==2.10
importlib-metadata==3.6.0
Expand Down
18 changes: 16 additions & 2 deletions src/core/zowe/core_for_zowe_sdk/profile_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import os
import warnings
from typing import Optional
from deepmerge import always_merger

from .config_file import ConfigFile, Profile
from .custom_warnings import (
Expand Down Expand Up @@ -259,10 +260,14 @@ def load(

missing_secure_props = [] # track which secure props were not loaded

loaded_cfg: dict = {}

for i, (config_type, cfg) in enumerate(config_layers.items()):

profile_loaded = self.get_profile(
aadityasinha-dotcom marked this conversation as resolved.
Show resolved Hide resolved
cfg, profile_name, profile_type, config_type
)
# How about we update by iterating each layer and at last we will get the merged layer
# TODO Why don't user and password show up here for Project User Config?
# Probably need to update load_profile_properties method in config_file.py
if profile_loaded.name and not profile_name:
Expand All @@ -273,12 +278,21 @@ def load(

missing_secure_props.extend(profile_loaded.missing_secure_props)

if override_with_env:
env_var = {**self.get_env(cfg)}

if i == 1 and profile_props:
break # Skip loading from global config if profile was found in project config

usrProject = self.project_user_config.profiles
project = self.project_config.profiles
prjt = always_merger.merge(usrProject, project)

usrGlobal = self.global_user_config.profiles
glbal = self.global_config.profiles
glbl = always_merger.merge(usrGlobal, glbal)
aadityasinha-dotcom marked this conversation as resolved.
Show resolved Hide resolved

if override_with_env:
env_var = {**self.get_env(cfg)}

aadityasinha-dotcom marked this conversation as resolved.
Show resolved Hide resolved
if profile_type != BASE_PROFILE:
profile_props = {
**self.load(profile_type=BASE_PROFILE, check_missing_props=False),
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_zowe_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def test_profile_loading_with_user_overriden_properties(self, get_pass_func):
self.assertEqual(prof_manager.config_filepath, cwd_up_file_path)

expected_props = {
"host": "zowe.test.user.cloud",
"host": "zowe.test.cloud",
"rejectUnauthorized": False,
"user": "user",
"password": "password",
Expand Down