Skip to content

Commit

Permalink
Merge pull request #348 from eedgar/async
Browse files Browse the repository at this point in the history
run aws session sts code asyncronously vastly improving the performance.
  • Loading branch information
epierce authored Dec 13, 2022
2 parents 3b79892 + 63eea1e commit 2da0af5
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions gimme_aws_creds/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import os
import re
import sys
import concurrent.futures


# extras
import boto3
Expand Down Expand Up @@ -613,6 +615,7 @@ def aws_results(self):
'links': {'appLink': self.config.app_url}
}
aws_results.append(new_app_entry)
self.ui.info("Authentication Success!")

# Use the gimme_creds_lambda service
else:
Expand Down Expand Up @@ -705,7 +708,7 @@ def prepare_data(self, role, generate_credentials=False):
except ClientError as ex:
if 'requested DurationSeconds exceeds the MaxSessionDuration' in ex.response['Error']['Message']:
self.ui.warning(
"The requested session duration was too long for this role. Falling back to 1 hour.")
"The requested session duration was too long for the role {}. Falling back to 1 hour.".format(role.role))
aws_creds = self._get_sts_creds(
self.aws_partition,
self.saml_data['SAMLResponse'],
Expand Down Expand Up @@ -770,12 +773,19 @@ def get_profile_name(self, cred_profile, include_path, naming_data, resolve_alia

def iter_selected_aws_credentials(self):
results = []
for role in self.aws_selected_roles:
aws_results = []

def generate_credentials_prepare_data(role):
data = self.prepare_data(role, generate_credentials=True)
if not data:
return data

with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
aws_results = executor.map(generate_credentials_prepare_data, self.aws_selected_roles)
for ar in aws_results:
if not ar:
continue
results.append(data)
yield data
results.append(ar)
yield ar

self._cache['selected_aws_credentials'] = results

Expand Down

0 comments on commit 2da0af5

Please sign in to comment.