(self, parsed_args, parsed_globals)
| 111 | return token_expiration.strftime('%Y-%m-%dT%H:%M:%SZ') |
| 112 | |
| 113 | def _run_main(self, parsed_args, parsed_globals): |
| 114 | client_factory = STSClientFactory(self._session) |
| 115 | sts_client = client_factory.get_sts_client( |
| 116 | region_name=parsed_globals.region, role_arn=parsed_args.role_arn |
| 117 | ) |
| 118 | |
| 119 | validate_mutually_exclusive( |
| 120 | parsed_args, ['cluster_name'], ['cluster_id'] |
| 121 | ) |
| 122 | |
| 123 | if parsed_args.cluster_id: |
| 124 | identifier = parsed_args.cluster_id |
| 125 | elif parsed_args.cluster_name: |
| 126 | identifier = parsed_args.cluster_name |
| 127 | else: |
| 128 | return ValueError( |
| 129 | "Either parameter --cluster-name or --cluster-id must be specified." |
| 130 | ) |
| 131 | |
| 132 | token = TokenGenerator(sts_client).get_token(identifier) |
| 133 | |
| 134 | # By default STS signs the url for 15 minutes so we are creating a |
| 135 | # rfc3339 timestamp with expiration in 14 minutes as part of the token, which |
| 136 | # is used by some clients (client-go) who will refresh the token after 14 mins |
| 137 | token_expiration = self.get_expiration_time() |
| 138 | |
| 139 | full_object = { |
| 140 | "kind": "ExecCredential", |
| 141 | "apiVersion": self.discover_api_version(), |
| 142 | "spec": {}, |
| 143 | "status": { |
| 144 | "expirationTimestamp": token_expiration, |
| 145 | "token": token, |
| 146 | }, |
| 147 | } |
| 148 | |
| 149 | output = parsed_globals.output |
| 150 | if output is None: |
| 151 | output = self._session.get_config_variable('output') |
| 152 | formatter = get_formatter(output, parsed_globals) |
| 153 | formatter.query = parsed_globals.query |
| 154 | |
| 155 | formatter(self.NAME, full_object) |
| 156 | uni_print('\n') |
| 157 | return 0 |
| 158 | |
| 159 | def discover_api_version(self): |
| 160 | """ |
nothing calls this directly
no test coverage detected