Skip to content

Commit 354569d

Browse files
authored
Merge pull request #45 from britive/progress-bar
Progress bar
2 parents f0aa704 + 7650108 commit 354569d

File tree

7 files changed

+61
-10
lines changed

7 files changed

+61
-10
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
All changes to the package starting with v0.3.1 will be logged here.
44

5+
## v0.9.0 [2023-01-06]
6+
#### What's New
7+
* `pybritive checkout` will now report progress of the action by default (if `stdout` is a tty). Can show more verbose output with `--verbose/-v`. Can silence the progress with the already available `--silent\-s` flag.
8+
#### Enhancements
9+
* None
10+
11+
#### Bug Fixes
12+
* None
13+
14+
#### Dependencies
15+
* `britive~=2.13.0` from `britive~=2.12.4` - checkout progress callback
16+
17+
#### Other
18+
* None
19+
520
## v0.8.0 [2023-01-05]
621
#### What's New
722
* Ability to store a GCP `gcloud` key file locally so `eval $(pybritive checkout "profile" -m gcloudauth)` will automatically authenticate the user with the gcloud CLI.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
britive~=2.12.4
1+
britive~=2.13.0
22
certifi==2022.6.15
33
charset-normalizer==2.1.0
44
click==8.1.3

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = pybritive
3-
version = 0.8.0
3+
version = 0.9.0
44
author = Britive Inc.
55
author_email = support@britive.com
66
description = A pure Python CLI for Britive
@@ -26,7 +26,7 @@ install_requires =
2626
toml
2727
cryptography
2828
python-dateutil
29-
britive>=2.12.4
29+
britive>=2.13.0
3030

3131
[options.packages.find]
3232
where = src

src/pybritive/britive_cli.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import io
2-
import socket
32
from britive.britive import Britive
43
from .helpers.config import ConfigManager
54
from .helpers.credentials import FileCredentialManager, EncryptedFileCredentialManager
@@ -14,6 +13,7 @@
1413
from pathlib import Path
1514
from datetime import datetime
1615
import os
16+
import sys
1717

1818

1919
default_table_format = 'fancy_grid'
@@ -35,6 +35,8 @@ def __init__(self, tenant_name: str = None, token: str = None, silent: bool = Fa
3535
self.passphrase = passphrase
3636
self.federation_provider = federation_provider
3737
self.credential_manager = None
38+
self.verbose_checkout = False
39+
self.checkout_progress_previous_message = None
3840

3941
def set_output_format(self, output_format: str):
4042
self.output_format = self.config.get_output_format(output_format)
@@ -109,6 +111,24 @@ def debug(self, data: object, ignore_silent: bool = False):
109111
if debug_enabled:
110112
self.print(data=data, ignore_silent=ignore_silent)
111113

114+
# will be passed to the britive checkout_by_name progress_func parameter when appropriate
115+
def checkout_callback_printer(self, message: str):
116+
if self.silent or not sys.stdout.isatty():
117+
return
118+
if message == 'complete':
119+
click.echo('')
120+
return
121+
122+
if self.verbose_checkout:
123+
if self.checkout_progress_previous_message != message:
124+
newline = '\n' if self.checkout_progress_previous_message else ''
125+
self.checkout_progress_previous_message = message
126+
click.echo(f'{newline}{message} ', nl=False)
127+
else:
128+
click.echo('.', nl=False)
129+
else:
130+
click.echo('.', nl=False)
131+
112132
# will take a list of dicts and print to the screen based on the format specified in the config file
113133
# dict can only be 1 level deep (no nesting) - caller needs to massage the data accordingly
114134
def print(self, data: object, ignore_silent: bool = False):
@@ -317,7 +337,8 @@ def _checkout(self, profile_name, env_name, app_name, programmatic, blocktime, m
317337
include_credentials=True,
318338
wait_time=blocktime,
319339
max_wait_time=maxpolltime,
320-
justification=justification
340+
justification=justification,
341+
progress_func=self.checkout_callback_printer # callback will handle silent, isatty, etc.
321342
)
322343
except exceptions.ApprovalRequiredButNoJustificationProvided:
323344
raise click.ClickException('approval required and no justification provided.')
@@ -349,11 +370,12 @@ def _split_profile_into_parts(self, profile):
349370
return parts_dict
350371

351372
def checkout(self, alias, blocktime, console, justification, mode, maxpolltime, profile, passphrase,
352-
force_renew, aws_credentials_file, gcloud_key_file):
373+
force_renew, aws_credentials_file, gcloud_key_file, verbose):
353374
credentials = None
354375
app_type = None
355376
credential_process_creds_found = False
356377
response = None
378+
self.verbose_checkout = verbose
357379

358380
if mode == 'awscredentialprocess':
359381
self.silent = True # the aws credential process CANNOT output anything other than the expected JSON

src/pybritive/commands/checkout.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
@click.command()
88
@build_britive
99
@britive_options(names='alias,blocktime,console,justification,mode,maxpolltime,silent,force_renew,aws_credentials_file,'
10-
'gcloud_key_file,tenant,token,passphrase,federation_provider')
10+
'gcloud_key_file,verbose,tenant,token,passphrase,federation_provider')
1111
@click.argument('profile', shell_complete=profile_completer)
1212
def checkout(ctx, alias, blocktime, console, justification, mode, maxpolltime, silent, force_renew,
13-
aws_credentials_file, gcloud_key_file, tenant, token, passphrase, federation_provider, profile):
13+
aws_credentials_file, gcloud_key_file,verbose, tenant, token, passphrase, federation_provider, profile):
1414
"""Checkout a profile.
1515
1616
This command takes 1 required argument `PROFILE`. This should be a string representation of the profile
@@ -29,5 +29,6 @@ def checkout(ctx, alias, blocktime, console, justification, mode, maxpolltime, s
2929
passphrase=passphrase,
3030
force_renew=force_renew,
3131
aws_credentials_file=aws_credentials_file,
32-
gcloud_key_file=gcloud_key_file
32+
gcloud_key_file=gcloud_key_file,
33+
verbose=verbose
3334
)

src/pybritive/options/britive_options.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from ..options.aws_credentials_file import option as aws_credentials_file
2222
from ..options.federation_provider import option as federation_provider
2323
from ..options.gcloud_key_file import option as gcloud_key_file
24+
from ..options.verbose import option as verbose
2425

2526
options_map = {
2627
'tenant': tenant,
@@ -45,7 +46,8 @@
4546
'force_renew': force_renew,
4647
'aws_credentials_file': aws_credentials_file,
4748
'federation_provider': federation_provider,
48-
'gcloud_key_file': gcloud_key_file
49+
'gcloud_key_file': gcloud_key_file,
50+
'verbose': verbose
4951
}
5052

5153

src/pybritive/options/verbose.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import click
2+
3+
4+
option = click.option(
5+
'--verbose', '-v',
6+
default=False,
7+
is_flag=True,
8+
show_default=True,
9+
help='Enable verbose checkout mode.'
10+
)
11+

0 commit comments

Comments
 (0)