Return the GCP token placeholder and its remaining lifetime in seconds. Searches `google_cloud::TOKEN_ENV_KEYS` in priority order (SA before ADC) atomically to avoid inconsistency during credential refresh. Returns `None` if no GCP token is configured or all are expired. The `expires_in` defaults to 3600 when expiry is unknown.
(&self)
| 172 | /// refresh. Returns `None` if no GCP token is configured or all are |
| 173 | /// expired. The `expires_in` defaults to 3600 when expiry is unknown. |
| 174 | pub fn gcp_token_response(&self) -> Option<(String, i64)> { |
| 175 | const DEFAULT_EXPIRES_IN: i64 = 3600; |
| 176 | let resolver = self.resolver()?; |
| 177 | for key in crate::google_cloud::TOKEN_ENV_KEYS { |
| 178 | let placeholder = crate::secrets::placeholder_for_env_key(key); |
| 179 | if resolver.resolve_placeholder(&placeholder).is_none() { |
| 180 | continue; |
| 181 | } |
| 182 | let expires_in = resolver.expires_at_ms_for_placeholder(&placeholder).map_or( |
| 183 | DEFAULT_EXPIRES_IN, |
| 184 | |expires_at_ms| { |
| 185 | if expires_at_ms <= 0 { |
| 186 | DEFAULT_EXPIRES_IN |
| 187 | } else { |
| 188 | let now = crate::time::now_ms(); |
| 189 | (expires_at_ms - now) / 1000 |
| 190 | } |
| 191 | }, |
| 192 | ); |
| 193 | if expires_in <= 0 { |
| 194 | continue; |
| 195 | } |
| 196 | return Some((placeholder, expires_in)); |
| 197 | } |
| 198 | None |
| 199 | } |
| 200 | |
| 201 | pub fn install_environment( |
| 202 | &self, |