Skip to content

Commit ffc8082

Browse files
authored
Merge pull request #73 from britive/develop
v1.2.2
2 parents 239ebea + 482a4a4 commit ffc8082

15 files changed

Lines changed: 89 additions & 45 deletions

File tree

CHANGELOG.md

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

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

5+
## v1.2.2 [2023-03-17]
6+
#### What's New
7+
* None
8+
9+
#### Enhancements
10+
* None
11+
12+
#### Bug Fixes
13+
* Fix bug with `logout` command when no active credentials were available
14+
* Expand `--silent/-s` flag to the following commands
15+
* `api`
16+
* `cache profiles`
17+
* `checkin`
18+
* `login`
19+
* `logout`
20+
* `ls [profiles|environments|applications|secrets]`
21+
* `request [submit|withdraw]`
22+
* `secret view`
23+
* `user`
24+
* Fix bug when saving profile alias when the `PROFILE` is only 2 parts instead of 3
25+
26+
#### Dependencies
27+
* None
28+
29+
#### Other
30+
* None
31+
532
## v1.2.1 [2023-03-14]
633
#### What's New
734
* None

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = pybritive
3-
version = 1.2.1
3+
version = 1.2.2
44
author = Britive Inc.
55
author_email = support@britive.com
66
description = A pure Python CLI for Britive

src/pybritive/britive_cli.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,26 @@ def _cleanup_credentials(self):
104104
self.credential_manager.delete()
105105

106106
def logout(self):
107+
# if dealing with a token there is no concept of logout
107108
if self.token:
108109
raise click.ClickException('Logout not available when using an API token.')
109-
self.login()
110-
self.b.delete(f'https://{Britive.parse_tenant(self.tenant_name)}/api/auth')
111-
self._cleanup_credentials()
110+
111+
self.tenant_name = self.config.get_tenant()['name']
112+
self.tenant_alias = self.config.alias
113+
self.set_credential_manager()
114+
115+
# let's see if we have credentials for this tenant already
116+
# if we do we need to invalidate them at the tenant and clean them up on the client side
117+
# if we don't have valid credentials for the tenant then there is no need to logout
118+
if self.credential_manager.has_valid_credentials():
119+
120+
self.b = Britive(
121+
tenant=self.tenant_name,
122+
token=self.credential_manager.get_token(),
123+
query_features=False
124+
)
125+
self.b.delete(f'https://{Britive.parse_tenant(self.tenant_name)}/api/auth')
126+
self._cleanup_credentials()
112127

113128
def debug(self, data: object, ignore_silent: bool = False):
114129
if debug_enabled:
@@ -183,11 +198,11 @@ def user(self):
183198
output = f'{username} @ {self.tenant_name}'
184199
if alias != self.tenant_name:
185200
output += f' (alias: {alias})'
186-
self.print(output)
201+
self.print(output, ignore_silent=True)
187202

188203
def list_secrets(self):
189204
self.login()
190-
self.print(self.b.my_secrets.list())
205+
self.print(self.b.my_secrets.list(), ignore_silent=True)
191206

192207
def list_profiles(self, checked_out: bool = False):
193208
self.login()
@@ -219,7 +234,7 @@ def list_profiles(self, checked_out: bool = False):
219234
if self.output_format == 'list':
220235
self.output_format = 'list-profiles'
221236

222-
self.print(data)
237+
self.print(data, ignore_silent=True)
223238

224239
# and set it back
225240
if self.output_format == 'list-profiles':
@@ -242,7 +257,7 @@ def list_applications(self):
242257

243258
}
244259
data.append(row)
245-
self.print(data)
260+
self.print(data, ignore_silent=True)
246261

247262
def list_environments(self):
248263
self.login()
@@ -262,7 +277,7 @@ def list_environments(self):
262277
'Type': env['app_type']
263278
}
264279
data.append(row)
265-
self.print(data)
280+
self.print(data, ignore_silent=True)
266281

267282
def _set_available_profiles(self):
268283
if not self.available_profiles:
@@ -555,7 +570,7 @@ def viewsecret(self, path, blocktime, justification, maxpolltime):
555570
pass
556571

557572
# and finally print the secret data
558-
self.print(value)
573+
self.print(value, ignore_silent=True)
559574

560575
def downloadsecret(self, path, blocktime, justification, maxpolltime, file):
561576
self._validate_justification(justification)
@@ -578,7 +593,7 @@ def downloadsecret(self, path, blocktime, justification, maxpolltime, file):
578593

579594
if file == '-':
580595
try:
581-
self.print(content.decode('utf-8'))
596+
self.print(content.decode('utf-8'), ignore_silent=True)
582597
except UnicodeDecodeError as e:
583598
raise click.ClickException(
584599
'Secret file contents cannot be decoded to utf-8. '
@@ -707,7 +722,7 @@ def api(self, method, parameters={}, query=None):
707722
pass
708723

709724
# output the response, optionally filtering based on provided jmespath query/search
710-
self.print(jmespath.search(query, response) if query else response)
725+
self.print(jmespath.search(query, response) if query else response, ignore_silent=True)
711726

712727
# yes - this method exits in b.my_access as _get_profile_and_environment_ids_given_names
713728
# but we are doing additional business logic here to enhance the cli experience so there is

src/pybritive/commands/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
)
1919
)
2020
@build_britive
21-
@britive_options(names='query,output_format,tenant,token,passphrase,federation_provider')
21+
@britive_options(names='query,output_format,tenant,token,silent,passphrase,federation_provider')
2222
@click_smart_api_method_argument # need to gracefully handle older version of click
23-
def api(ctx, query, output_format, tenant, token, passphrase, federation_provider, method):
23+
def api(ctx, query, output_format, tenant, token, silent, passphrase, federation_provider, method):
2424
"""Exposes the Britive Python SDK methods to the CLI.
2525
2626
Documentation on each SDK method can be found inside the Python SDK itself and on Github

src/pybritive/commands/cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ def cache():
1111

1212
@cache.command()
1313
@build_britive
14-
@britive_options(names='tenant,token,passphrase,federation_provider')
15-
def profiles(ctx, tenant, token, passphrase, federation_provider):
14+
@britive_options(names='tenant,token,silent,passphrase,federation_provider')
15+
def profiles(ctx, tenant, token, silent, passphrase, federation_provider):
1616
"""Cache profiles locally to facilitate auto-completion of profile names on checkin/checkout."""
1717
ctx.obj.britive.cache_profiles()
1818

src/pybritive/commands/checkin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
@click.command()
88
@build_britive
9-
@britive_options(names='tenant,token,passphrase,federation_provider')
9+
@britive_options(names='tenant,token,silent,passphrase,federation_provider')
1010
@click_smart_profile_argument
11-
def checkin(ctx, tenant, token, passphrase, federation_provider, profile):
11+
def checkin(ctx, tenant, token, silent, passphrase, federation_provider, profile):
1212
"""Checkin a profile.
1313
1414
This command takes 1 required argument `PROFILE`. This should be a string representation of the profile

src/pybritive/commands/login.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
@click.command()
77
@build_britive
8-
@britive_options(names='tenant,token,passphrase,federation_provider')
9-
def login(ctx, tenant, token, passphrase, federation_provider):
8+
@britive_options(names='tenant,token,silent,passphrase,federation_provider')
9+
def login(ctx, tenant, token, silent, passphrase, federation_provider):
1010
"""Perform an interactive login to obtain temporary credentials.
1111
1212
This only applies when an API token has not been specified via `--token,-T` or via environment variable

src/pybritive/commands/logout.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
@click.command()
77
@build_britive
8-
@britive_options(names='tenant,passphrase')
9-
def logout(ctx, tenant, passphrase):
8+
@britive_options(names='tenant,silent,passphrase')
9+
def logout(ctx, tenant, silent, passphrase):
1010
"""Logout of an interactive login session.
1111
1212
This only applies when an API token has not been specified via `--token,-T` or via environment variable

src/pybritive/commands/ls.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,32 @@ def ls():
1111

1212
@ls.command()
1313
@build_britive
14-
@britive_options(names='format,tenant,token,passphrase,federation_provider')
15-
def applications(ctx, output_format, tenant, token, passphrase, federation_provider):
14+
@britive_options(names='format,tenant,token,silent,passphrase,federation_provider')
15+
def applications(ctx, output_format, tenant, token, silent, passphrase, federation_provider):
1616
"""List applications for the currently authenticated identity."""
1717
ctx.obj.britive.list_applications()
1818

1919

2020
@ls.command()
2121
@build_britive
22-
@britive_options(names='format,tenant,token,passphrase,federation_provider')
23-
def environments(ctx, output_format, tenant, token, passphrase, federation_provider):
22+
@britive_options(names='format,tenant,token,silent,passphrase,federation_provider')
23+
def environments(ctx, output_format, tenant, token, silent, passphrase, federation_provider):
2424
"""List environments for the currently authenticated identity."""
2525
ctx.obj.britive.list_environments()
2626

2727

2828
@ls.command()
2929
@build_britive
30-
@britive_options(names='checked_out,output_format,tenant,token,passphrase,federation_provider')
31-
def profiles(ctx, checked_out, output_format, tenant, token, passphrase, federation_provider):
30+
@britive_options(names='checked_out,output_format,tenant,token,silent,passphrase,federation_provider')
31+
def profiles(ctx, checked_out, output_format, tenant, token, silent, passphrase, federation_provider):
3232
"""List profiles for the currently authenticated identity."""
3333
ctx.obj.britive.list_profiles(checked_out=checked_out)
3434

3535

3636
@ls.command()
3737
@build_britive
38-
@britive_options(names='format,tenant,token,passphrase, federation_provider')
39-
def secrets(ctx, output_format, tenant, token, passphrase, federation_provider):
38+
@britive_options(names='format,tenant,token,silent,passphrase,federation_provider')
39+
def secrets(ctx, output_format, tenant, token, silent, passphrase, federation_provider):
4040
"""List secrets for the currently authenticated identity."""
4141
ctx.obj.britive.list_secrets()
4242

src/pybritive/commands/request.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ def request():
1212

1313
@request.command()
1414
@build_britive
15-
@britive_options(names='justification,tenant,token,passphrase,federation_provider')
15+
@britive_options(names='justification,tenant,token,silent,passphrase,federation_provider')
1616
@click_smart_profile_argument
17-
def submit(ctx, justification, tenant, token, passphrase, federation_provider, profile):
17+
def submit(ctx, justification, tenant, token, silent, passphrase, federation_provider, profile):
1818
"""Submit a request to checkout a profile.
1919
2020
Only applicable for profiles which require approval. This command will NOT block/wait until the request is
@@ -33,9 +33,9 @@ def submit(ctx, justification, tenant, token, passphrase, federation_provider, p
3333

3434
@request.command()
3535
@build_britive
36-
@britive_options(names='tenant,token,passphrase,federation_provider')
36+
@britive_options(names='tenant,token,silent,passphrase,federation_provider')
3737
@click_smart_profile_argument
38-
def withdraw(ctx, tenant, token, passphrase, federation_provider, profile):
38+
def withdraw(ctx, tenant, token, silent, passphrase, federation_provider, profile):
3939
"""Withdraw a request to checkout a profile.
4040
4141
Only applicable for profiles which require approval.

0 commit comments

Comments
 (0)