Skip to content

Commit 4ce3f0c

Browse files
authored
chore: propagate use_remote flag up the chain (#2930)
1 parent 56b06b5 commit 4ce3f0c

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

renku/command/login.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ def _login(endpoint, git_login, yes, client_dispatcher: IClientDispatcher):
146146
)
147147

148148

149-
def _parse_endpoint(endpoint):
150-
parsed_endpoint = parse_authentication_endpoint(endpoint=endpoint)
149+
def _parse_endpoint(endpoint, use_remote=False):
150+
parsed_endpoint = parse_authentication_endpoint(endpoint=endpoint, use_remote=use_remote)
151151
if not parsed_endpoint:
152152
raise errors.ParameterError("Parameter 'endpoint' is missing.")
153153

@@ -193,22 +193,24 @@ def _set_renku_url_for_remote(repository: "Repository", remote_name: str, remote
193193

194194

195195
@inject.autoparams()
196-
def read_renku_token(endpoint, client_dispatcher: IClientDispatcher):
196+
def read_renku_token(endpoint: str, client_dispatcher: IClientDispatcher, get_endpoint_from_remote=False) -> str:
197197
"""Read renku token from renku config file.
198198
199199
Args:
200-
endpoint: Endpoint to get token for.
200+
endpoint(str): Endpoint to get token for.
201201
client_dispatcher(IClientDispatcher): Injected client dispatcher.
202+
Keywords:
203+
get_endpoint_from_remote: if no endpoint is specified, use the repository remote to infer one
202204
203205
Returns:
204206
Token for endpoint.
205207
"""
206208
try:
207-
parsed_endpoint = _parse_endpoint(endpoint)
209+
parsed_endpoint = _parse_endpoint(endpoint, use_remote=get_endpoint_from_remote)
208210
except errors.ParameterError:
209-
return
211+
return ""
210212
if not parsed_endpoint:
211-
return
213+
return ""
212214

213215
return _read_renku_token_for_hostname(client_dispatcher.current_client, parsed_endpoint.netloc)
214216

renku/core/util/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def get_path(url: str) -> str:
7373

7474

7575
@inject.autoparams()
76-
def parse_authentication_endpoint(endpoint, client_dispatcher: IClientDispatcher, use_remote=False):
76+
def parse_authentication_endpoint(endpoint: str, client_dispatcher: IClientDispatcher, use_remote=False):
7777
"""Return a parsed url.
7878
7979
If an endpoint is provided then use it, otherwise, look for a configured endpoint. If no configured endpoint exists

tests/cli/test_login.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@
2929

3030
def test_login(runner, client_with_remote, mock_login, client_database_injection_manager):
3131
"""Test login command."""
32-
remote_url = client_with_remote.repository.remotes[0].url
32+
remote_url = f"https://{ENDPOINT}/gitlab/namespace/project"
33+
client_with_remote.repository.remotes[0].set_url(remote_url)
3334

3435
result = runner.invoke(cli, ["login", "--git", ENDPOINT], input="y")
3536

3637
assert 0 == result.exit_code, format_result_exception(result)
3738

3839
with client_database_injection_manager(client_with_remote):
3940
assert ACCESS_TOKEN == read_renku_token(ENDPOINT)
41+
assert ACCESS_TOKEN == read_renku_token("", get_endpoint_from_remote=True)
4042
credential = client_with_remote.repository.get_configuration().get_value("credential", "helper")
4143
assert f"!renku credentials --hostname {ENDPOINT}" == credential
4244
assert {"origin", "renku-backup-origin"} == {r.name for r in client_with_remote.repository.remotes}

0 commit comments

Comments
 (0)