Skip to content

Commit b2f2f38

Browse files
authored
Merge pull request #82 from britive/develop
v1.4.0rc3
2 parents d3830fd + f62afbe commit b2f2f38

5 files changed

Lines changed: 63 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@
33
* All changes to the package starting with v0.3.1 will be logged here.
44
* As of v1.4.0 release candidates will be published in an effort to get new features out faster while still allowing time for full QA testing before moving the release candidate to a full release.
55

6+
## v1.4.0rc3 [2023-05-16]
7+
#### What's New
8+
* None
9+
10+
#### Enhancements
11+
* When checking in an AWS profile remove any AWS `credential_process` cached credentials.
12+
* `cache clear cached-aws-credentials PROFILE`
13+
14+
#### Bug Fixes
15+
* None
16+
17+
#### Dependencies
18+
* None
19+
20+
#### Other
21+
* None
22+
23+
624
## v1.4.0rc2 [2023-05-09]
725
#### What's New
826
* 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.4.0rc2
3+
version = 1.4.0rc3
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: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ def __get_cloud_credential_printer(self, app_type, console, mode, profile, silen
377377

378378
def checkin(self, profile):
379379
self.login()
380+
self._set_available_profiles()
380381
parts = self._split_profile_into_parts(profile)
381382

382383
ids = self._convert_names_to_ids(
@@ -386,9 +387,19 @@ def checkin(self, profile):
386387
)
387388

388389
transaction_id = None
389-
for profile in self.b.my_access.list_checked_out_profiles():
390-
if profile['environmentId'] == ids['environment_id'] and profile['papId'] == ids['profile_id']:
391-
transaction_id = profile['transactionId']
390+
application_type = None
391+
for checked_out_profile in self.b.my_access.list_checked_out_profiles():
392+
same_env = checked_out_profile['environmentId'] == ids['environment_id']
393+
same_profile = checked_out_profile['papId'] == ids['profile_id']
394+
if all([same_env, same_profile]):
395+
transaction_id = checked_out_profile['transactionId']
396+
397+
for available_profile in self.available_profiles:
398+
same_env_2 = checked_out_profile['environmentId'] == available_profile['env_id']
399+
same_profile_2 = checked_out_profile['papId'] == available_profile['profile_id']
400+
if all([same_env_2, same_profile_2]):
401+
application_type = available_profile['app_type'].lower()
402+
break
392403
break
393404
if not transaction_id:
394405
raise ValueError(f'no checked out profile found for the given profile')
@@ -397,6 +408,9 @@ def checkin(self, profile):
397408
transaction_id=transaction_id
398409
)
399410

411+
if application_type in ('aws', 'aws standalone'):
412+
self.clear_cached_aws_credentials(profile)
413+
400414
def _checkout(self, profile_name, env_name, app_name, programmatic, blocktime, maxpolltime, justification):
401415
try:
402416
self.login()
@@ -1030,3 +1044,14 @@ def request_disposition(self, request_id, decision):
10301044
self.b.my_access.approve_request(request_id=request_id)
10311045
if decision == 'reject':
10321046
self.b.my_access.reject_request(request_id=request_id)
1047+
1048+
def clear_cached_aws_credentials(self, profile):
1049+
# start with the profile name that was passed in from the command
1050+
Cache().clear_awscredentialprocess(profile_name=profile)
1051+
1052+
# then we can try to split it into parts and clear that version of the
1053+
# profile name as well - it will not hurt anything to try to clear
1054+
# both versions
1055+
parts = self._split_profile_into_parts(profile)
1056+
Cache().clear_awscredentialprocess(profile_name=f"{parts['app']}/{parts['env']}/{parts['profile']}")
1057+

src/pybritive/commands/clear.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import click
22
from ..helpers.build_britive import build_britive
3-
3+
from ..helpers.profile_argument_dectorator import click_smart_profile_argument
44

55
@click.group()
66
def clear():
@@ -22,3 +22,10 @@ def gcloud_auth_key_files(ctx):
2222
ctx.obj.britive.clear_gcloud_auth_key_files()
2323

2424

25+
@clear.command(name='cached-aws-credentials')
26+
@build_britive
27+
@click_smart_profile_argument
28+
def cached_aws_credentials(ctx, profile):
29+
"""Clears cached AWS credentials used as part of the AWS CLI credential process."""
30+
ctx.obj.britive.clear_cached_aws_credentials(profile=profile)
31+

src/pybritive/helpers/cache.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from pathlib import Path
22
import json
33
import os
4+
5+
46
from .encryption import StringEncryption, InvalidPassphraseException
57

68

@@ -54,7 +56,7 @@ def clear(self):
5456

5557
def get_awscredentialprocess(self, profile_name: str):
5658
try:
57-
ciphertext = self.cache['awscredentialprocess'].get(profile_name)
59+
ciphertext = self.cache['awscredentialprocess'].get(profile_name.lower())
5860
if not ciphertext:
5961
return None
6062
return json.loads(self.string_encryptor.decrypt(ciphertext))
@@ -63,5 +65,9 @@ def get_awscredentialprocess(self, profile_name: str):
6365

6466
def save_awscredentialprocess(self, profile_name: str, credentials: dict):
6567
ciphertext = self.string_encryptor.encrypt(json.dumps(credentials, default=str))
66-
self.cache['awscredentialprocess'][profile_name] = ciphertext
68+
self.cache['awscredentialprocess'][profile_name.lower()] = ciphertext
69+
self.write()
70+
71+
def clear_awscredentialprocess(self, profile_name: str):
72+
self.cache['awscredentialprocess'].pop(profile_name.lower(), None)
6773
self.write()

0 commit comments

Comments
 (0)