Skip to content

Commit 32b2ac5

Browse files
authored
Merge pull request #640 from Romazes/feature-charles-schwab-user-name-config
feat: add `--charles-schwab-user-name` option to README
2 parents d2eddf5 + 4ebf210 commit 32b2ac5

4 files changed

Lines changed: 25 additions & 7 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ Options:
193193
--kraken-api-secret TEXT Your Kraken API secret
194194
--kraken-verification-tier [Starter|Intermediate|Pro]
195195
Your Kraken Verification Tier
196+
--charles-schwab-user-name TEXT
197+
Your Charles Schwab login ID
196198
--charles-schwab-account-number TEXT
197199
The CharlesSchwab account number
198200
--iqfeed-iqconnect TEXT The path to the IQConnect binary
@@ -461,6 +463,8 @@ Options:
461463
--kraken-api-secret TEXT Your Kraken API secret
462464
--kraken-verification-tier [Starter|Intermediate|Pro]
463465
Your Kraken Verification Tier
466+
--charles-schwab-user-name TEXT
467+
Your Charles Schwab login ID
464468
--charles-schwab-account-number TEXT
465469
The CharlesSchwab account number
466470
--bybit-api-key TEXT Your Bybit API key
@@ -927,6 +931,8 @@ Options:
927931
--kraken-api-secret TEXT Your Kraken API secret
928932
--kraken-verification-tier [Starter|Intermediate|Pro]
929933
Your Kraken Verification Tier
934+
--charles-schwab-user-name TEXT
935+
Your Charles Schwab login ID
930936
--charles-schwab-account-number TEXT
931937
The CharlesSchwab account number
932938
--iqfeed-iqconnect TEXT The path to the IQConnect binary
@@ -1444,6 +1450,8 @@ Options:
14441450
--kraken-api-secret TEXT Your Kraken API secret
14451451
--kraken-verification-tier [Starter|Intermediate|Pro]
14461452
Your Kraken Verification Tier
1453+
--charles-schwab-user-name TEXT
1454+
Your Charles Schwab login ID
14471455
--charles-schwab-account-number TEXT
14481456
The CharlesSchwab account number
14491457
--bybit-api-key TEXT Your Bybit API key
@@ -1850,6 +1858,8 @@ Options:
18501858
--kraken-api-secret TEXT Your Kraken API secret
18511859
--kraken-verification-tier [Starter|Intermediate|Pro]
18521860
Your Kraken Verification Tier
1861+
--charles-schwab-user-name TEXT
1862+
Your Charles Schwab login ID
18531863
--charles-schwab-account-number TEXT
18541864
The CharlesSchwab account number
18551865
--iqfeed-iqconnect TEXT The path to the IQConnect binary
@@ -2108,6 +2118,8 @@ Options:
21082118
--kraken-api-secret TEXT Your Kraken API secret
21092119
--kraken-verification-tier [Starter|Intermediate|Pro]
21102120
Your Kraken Verification Tier
2121+
--charles-schwab-user-name TEXT
2122+
Your Charles Schwab login ID
21112123
--charles-schwab-account-number TEXT
21122124
The CharlesSchwab account number
21132125
--iqfeed-iqconnect TEXT The path to the IQConnect binary

lean/models/json_module.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,15 @@ def convert_variable_to_lean_key(self, variable_key: str) -> str:
175175
"""
176176
return variable_key.replace('_', '-')
177177

178-
def get_user_name(self, lean_config: Dict[str, Any], configuration, user_provided_options: Dict[str, Any], require_user_name: bool) -> str:
178+
def get_user_name(self, lean_config: Dict[str, Any], configuration, user_provided_options: Dict[str, Any],
179+
require_user_name: bool, interactive: bool) -> str:
179180
"""Retrieve the user name, prompting the user if required and not already set.
180181
181182
:param lean_config: The Lean config dict to read defaults from.
182183
:param configuration: The AuthConfiguration instance.
183184
:param user_provided_options: Options passed as command-line arguments.
184185
:param require_user_name: Flag to determine if prompting is necessary.
186+
:param interactive: ask user input parameter manually (interactively)
185187
:return: The user name, or None if not required.
186188
"""
187189
if not require_user_name:
@@ -193,6 +195,8 @@ def get_user_name(self, lean_config: Dict[str, Any], configuration, user_provide
193195
return user_provided_options[user_name_variable]
194196
if lean_config and lean_config.get(user_name_key):
195197
return lean_config[user_name_key]
198+
if not interactive:
199+
raise RuntimeError(f"You are missing the following option {user_name_key}")
196200
user_name = prompt("Please enter your Login ID to proceed with Auth0 authentication",
197201
show_default=False)
198202
if lean_config is not None:
@@ -263,7 +267,7 @@ def config_build(self,
263267
configuration.require_project_id)
264268
logger.debug(f'project_id: {lean_config["project-id"]}')
265269
user_name = self.get_user_name(lean_config, configuration, user_provided_options,
266-
configuration.require_user_name)
270+
configuration.require_user_name, interactive)
267271
logger.debug(f'user_name: {user_name}')
268272
auth_authorizations = get_authorization(container.api_client.auth0, self._display_name.lower(),
269273
logger, lean_config["project-id"], no_browser=no_browser,

tests/commands/test_live.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,8 @@ def test_live_sets_dependent_configurations_from_modules_json_based_on_environme
432432
"tt-log-fix-messages": "no"
433433
},
434434
"CharlesSchwab": {
435-
"charles-schwab-account-number": "123"
435+
"charles-schwab-account-number": "123",
436+
"charles-schwab-user-name": "user"
436437
},
437438
"Bybit": {
438439
"bybit-api-key": "abc",

tests/components/util/test_json_modules_handler.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ def test_is_value_in_config(searching: str, expected: bool) -> None:
8181
def test_get_user_name_returns_none_when_not_required() -> None:
8282
module = JsonModule({"id": "test", "configurations": [], "display-id": "Test"},
8383
MODULE_BROKERAGE, MODULE_CLI_PLATFORM)
84-
result = module.get_user_name({}, mock.Mock(), {}, require_user_name=False)
84+
result = module.get_user_name({}, mock.Mock(), {}, require_user_name=False,
85+
interactive=False)
8586
assert result is None
8687

8788

@@ -92,7 +93,7 @@ def test_get_user_name_from_user_provided_options() -> None:
9293
config._id = "charles-schwab-oauth-token"
9394
result = module.get_user_name({}, config,
9495
{"charles_schwab_user_name": "cli_login"},
95-
require_user_name=True)
96+
require_user_name=True, interactive=False)
9697
assert result == "cli_login"
9798

9899

@@ -102,7 +103,7 @@ def test_get_user_name_from_lean_config() -> None:
102103
config = mock.Mock()
103104
config._id = "charles-schwab-oauth-token"
104105
lean_config = {"charles-schwab-user-name": "saved_login"}
105-
result = module.get_user_name(lean_config, config, {}, require_user_name=True)
106+
result = module.get_user_name(lean_config, config, {}, require_user_name=True, interactive=False)
106107
assert result == "saved_login"
107108

108109

@@ -113,7 +114,7 @@ def test_get_user_name_prompts_and_saves_to_lean_config() -> None:
113114
config._id = "charles-schwab-oauth-token"
114115
lean_config = {}
115116
with mock.patch("click.prompt", return_value="prompted_login") as mock_prompt:
116-
result = module.get_user_name(lean_config, config, {}, require_user_name=True)
117+
result = module.get_user_name(lean_config, config, {}, require_user_name=True, interactive=True)
117118
assert result == "prompted_login"
118119
assert lean_config["charles-schwab-user-name"] == "prompted_login"
119120
mock_prompt.assert_called_once()

0 commit comments

Comments
 (0)