Get credentials by calling SSO get role credentials.
(self)
| 2300 | return timestamp.strftime(self._UTC_DATE_FORMAT) |
| 2301 | |
| 2302 | def _get_credentials(self): |
| 2303 | """Get credentials by calling SSO get role credentials.""" |
| 2304 | config = Config( |
| 2305 | signature_version=UNSIGNED, |
| 2306 | region_name=self._sso_region, |
| 2307 | ) |
| 2308 | client = self._client_creator('sso', config=config) |
| 2309 | if self._token_provider: |
| 2310 | initial_token_data = self._token_provider.load_token() |
| 2311 | token = initial_token_data.get_frozen_token().token |
| 2312 | else: |
| 2313 | token_dict = self._token_loader(self._start_url) |
| 2314 | token = token_dict['accessToken'] |
| 2315 | |
| 2316 | # raise an UnauthorizedSSOTokenError if the loaded legacy token |
| 2317 | # is expired to save a call to GetRoleCredentials with an |
| 2318 | # expired token. |
| 2319 | expiration = dateutil.parser.parse(token_dict['expiresAt']) |
| 2320 | remaining = total_seconds(expiration - self._time_fetcher()) |
| 2321 | if remaining <= 0: |
| 2322 | raise UnauthorizedSSOTokenError() |
| 2323 | |
| 2324 | kwargs = { |
| 2325 | 'roleName': self._role_name, |
| 2326 | 'accountId': self._account_id, |
| 2327 | 'accessToken': token, |
| 2328 | } |
| 2329 | try: |
| 2330 | register_feature_ids(self.feature_ids) |
| 2331 | response = client.get_role_credentials(**kwargs) |
| 2332 | except client.exceptions.UnauthorizedException: |
| 2333 | raise UnauthorizedSSOTokenError() |
| 2334 | credentials = response['roleCredentials'] |
| 2335 | |
| 2336 | credentials = { |
| 2337 | 'ProviderType': 'sso', |
| 2338 | 'Credentials': { |
| 2339 | 'AccessKeyId': credentials['accessKeyId'], |
| 2340 | 'SecretAccessKey': credentials['secretAccessKey'], |
| 2341 | 'SessionToken': credentials['sessionToken'], |
| 2342 | 'Expiration': self._parse_timestamp(credentials['expiration']), |
| 2343 | 'AccountId': self._account_id, |
| 2344 | }, |
| 2345 | } |
| 2346 | return credentials |
| 2347 | |
| 2348 | |
| 2349 | class SSOProvider(CredentialProvider): |
nothing calls this directly
no test coverage detected