rdeploy 0.5.1__tar.gz → 0.5.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rdeploy
3
- Version: 0.5.1
3
+ Version: 0.5.2
4
4
  Summary: CLI that makes it easy to build and deploy an application to k8s.
5
5
  Author-email: Rehive <info@rehive.com>
6
6
  License: MIT
@@ -167,6 +167,10 @@ kubectl fails with an authentication error such as `invalid_grant` or
167
167
  rdeploy kubectl-login
168
168
  ```
169
169
 
170
+ If gcloud's own login has expired too, rdeploy signs gcloud in first: gcloud
171
+ asks for your password in the terminal, or opens the browser for
172
+ `gcloud auth login`.
173
+
170
174
  To check whether the saved session is still valid (exits non-zero if not):
171
175
 
172
176
  ```bash
@@ -130,6 +130,10 @@ kubectl fails with an authentication error such as `invalid_grant` or
130
130
  rdeploy kubectl-login
131
131
  ```
132
132
 
133
+ If gcloud's own login has expired too, rdeploy signs gcloud in first: gcloud
134
+ asks for your password in the terminal, or opens the browser for
135
+ `gcloud auth login`.
136
+
133
137
  To check whether the saved session is still valid (exits non-zero if not):
134
138
 
135
139
  ```bash
rdeploy-0.5.2/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.5.2
@@ -179,6 +179,32 @@ def run_gcloud(cmd):
179
179
  return subprocess.run(cmd, stdout=subprocess.PIPE, text=True)
180
180
 
181
181
 
182
+ def ensure_gcloud_login(account=None):
183
+ """
184
+ Make sure gcloud can get a token for `account` (default: the active
185
+ account) before rdeploy uses it, signing gcloud in again if needed.
186
+
187
+ A password or security-key reauthentication is left to gcloud, which
188
+ prompts for it in the terminal. When gcloud's login has expired, or there
189
+ is none, run `gcloud auth login`, which signs in through the browser.
190
+ """
191
+ account_flag = [f'--account={account}'] if account else []
192
+ # The token itself is never needed: it goes to /dev/null, so rdeploy never
193
+ # holds it. Only the exit code and gcloud's error matter.
194
+ token_cmd = ['gcloud', 'auth', 'print-access-token', *account_flag]
195
+ check = subprocess.run(token_cmd, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
196
+ stderr=subprocess.PIPE, text=True)
197
+ if check.returncode == 0:
198
+ return
199
+ if ('reauth' in check.stderr.lower()
200
+ and subprocess.run(token_cmd, stdout=subprocess.DEVNULL).returncode == 0):
201
+ return
202
+ print('gcloud needs you to sign in again. Opening your browser for gcloud first.', flush=True)
203
+ login_cmd = ['gcloud', 'auth', 'login'] + ([account] if account else [])
204
+ if subprocess.run(login_cmd).returncode != 0:
205
+ raise KubectlLoginError('gcloud sign-in failed; gcloud\'s error is above.')
206
+
207
+
182
208
  def load_client(project, secret, account=None, client_json=None):
183
209
  """Read the OAuth client from a local file, or from Secret Manager with the user's gcloud login."""
184
210
  if client_json:
@@ -480,6 +506,10 @@ def login(project=None, secret=None, account=None, clusters=None, client_json=No
480
506
  check_tools(need_kubeconfig=not skip_kubeconfig)
481
507
  settings = resolve_settings(project, secret, account, clusters)
482
508
 
509
+ # gcloud reads the OAuth client and lists the clusters.
510
+ if not (client_json and skip_kubeconfig):
511
+ ensure_gcloud_login(settings['account'])
512
+
483
513
  client = load_client(settings['project'], settings['secret'], settings['account'], client_json)
484
514
  token = sign_in(client, settings['account'] or gcloud_account(), open_browser)
485
515
  path = write_credentials(client, token['refresh_token'])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rdeploy
3
- Version: 0.5.1
3
+ Version: 0.5.2
4
4
  Summary: CLI that makes it easy to build and deploy an application to k8s.
5
5
  Author-email: Rehive <info@rehive.com>
6
6
  License: MIT
@@ -167,6 +167,10 @@ kubectl fails with an authentication error such as `invalid_grant` or
167
167
  rdeploy kubectl-login
168
168
  ```
169
169
 
170
+ If gcloud's own login has expired too, rdeploy signs gcloud in first: gcloud
171
+ asks for your password in the terminal, or opens the browser for
172
+ `gcloud auth login`.
173
+
170
174
  To check whether the saved session is still valid (exits non-zero if not):
171
175
 
172
176
  ```bash
@@ -370,6 +370,27 @@ class TestLogin:
370
370
  def in_tmp_dir(self, tmp_path, monkeypatch):
371
371
  monkeypatch.chdir(tmp_path)
372
372
 
373
+ @pytest.fixture(autouse=True)
374
+ def gcloud_signed_in(self):
375
+ with patch('rdeploy.gke_auth.ensure_gcloud_login') as ensure:
376
+ yield ensure
377
+
378
+ def test_checks_gcloud_login_first(self, gcloud_signed_in):
379
+ with patch('rdeploy.gke_auth.check_tools'), \
380
+ patch('rdeploy.gke_auth.load_client', return_value=CLIENT), \
381
+ patch('rdeploy.gke_auth.sign_in', return_value={'refresh_token': 'r'}), \
382
+ patch('rdeploy.gke_auth.configure_kubeconfig', return_value=['ctx']):
383
+ gke_auth.login(project='p', secret='s', account='me@example.test')
384
+ gcloud_signed_in.assert_called_once_with('me@example.test')
385
+
386
+ def test_no_gcloud_needed_with_local_client_and_no_kubeconfig(self, gcloud_signed_in, tmp_path):
387
+ path = tmp_path / 'client.json'
388
+ path.write_text(json.dumps({'installed': CLIENT}))
389
+ with patch('rdeploy.gke_auth.check_tools'), \
390
+ patch('rdeploy.gke_auth.sign_in', return_value={'refresh_token': 'r'}):
391
+ gke_auth.login(project='p', secret='s', client_json=str(path), skip_kubeconfig=True)
392
+ gcloud_signed_in.assert_not_called()
393
+
373
394
  @patch('rdeploy.gke_auth.configure_kubeconfig', return_value=['ctx'])
374
395
  @patch('rdeploy.gke_auth.sign_in', return_value={'refresh_token': 'r'})
375
396
  @patch('rdeploy.gke_auth.load_client', return_value=CLIENT)
@@ -397,3 +418,60 @@ class TestLogin:
397
418
  raise KubectlLoginError('explained')
398
419
  with pytest.raises(SystemExit, match='explained'):
399
420
  gke_auth.run(fail)
421
+
422
+
423
+ # gcloud login
424
+ ##############
425
+
426
+ class TestEnsureGcloudLogin:
427
+ TOKEN = ['gcloud', 'auth', 'print-access-token', '--account=me@example.test']
428
+
429
+ @patch('rdeploy.gke_auth.subprocess.run')
430
+ def test_signed_in(self, mock_run):
431
+ mock_run.return_value = completed('token')
432
+ gke_auth.ensure_gcloud_login('me@example.test')
433
+ assert mock_run.call_count == 1
434
+ assert mock_run.call_args[0][0] == self.TOKEN
435
+ kwargs = mock_run.call_args[1]
436
+ assert kwargs['stdin'] == subprocess.DEVNULL
437
+ assert kwargs['stdout'] == subprocess.DEVNULL # the token is discarded
438
+ assert kwargs['stderr'] == subprocess.PIPE
439
+
440
+ @patch('rdeploy.gke_auth.subprocess.run')
441
+ def test_reauth_prompts_in_the_terminal(self, mock_run):
442
+ mock_run.side_effect = [
443
+ completed(returncode=1, stderr='Reauthentication failed. cannot prompt during non-interactive execution.'),
444
+ completed('token'),
445
+ ]
446
+ gke_auth.ensure_gcloud_login('me@example.test')
447
+ retry = mock_run.call_args_list[1]
448
+ assert retry[0][0] == self.TOKEN
449
+ assert 'stderr' not in retry[1] and 'stdin' not in retry[1]
450
+ assert retry[1]['stdout'] == subprocess.DEVNULL
451
+
452
+ @patch('rdeploy.gke_auth.subprocess.run')
453
+ def test_expired_login_runs_gcloud_auth_login(self, mock_run, capsys):
454
+ mock_run.side_effect = [
455
+ completed(returncode=1, stderr='There was a problem refreshing your current auth tokens. Please run: gcloud auth login'),
456
+ completed(),
457
+ ]
458
+ gke_auth.ensure_gcloud_login('me@example.test')
459
+ assert mock_run.call_args_list[1][0][0] == ['gcloud', 'auth', 'login', 'me@example.test']
460
+ assert 'sign in again' in capsys.readouterr().out
461
+
462
+ @patch('rdeploy.gke_auth.subprocess.run')
463
+ def test_failed_reauth_falls_back_to_login(self, mock_run):
464
+ mock_run.side_effect = [
465
+ completed(returncode=1, stderr='reauth related error (invalid_rapt)'),
466
+ completed(returncode=1),
467
+ completed(),
468
+ ]
469
+ gke_auth.ensure_gcloud_login()
470
+ assert mock_run.call_args_list[0][0][0] == ['gcloud', 'auth', 'print-access-token']
471
+ assert mock_run.call_args_list[2][0][0] == ['gcloud', 'auth', 'login']
472
+
473
+ @patch('rdeploy.gke_auth.subprocess.run')
474
+ def test_login_fails(self, mock_run):
475
+ mock_run.side_effect = [completed(returncode=1, stderr='no credentialed accounts'), completed(returncode=1)]
476
+ with pytest.raises(KubectlLoginError, match='gcloud sign-in failed'):
477
+ gke_auth.ensure_gcloud_login()
rdeploy-0.5.1/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.5.1
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes