|
22 | 22 | #include "google/cloud/version.h" |
23 | 23 | #include <chrono> |
24 | 24 | #include <string> |
| 25 | +#include <variant> |
25 | 26 | #include <vector> |
26 | 27 |
|
27 | 28 | namespace google { |
28 | 29 | namespace cloud { |
29 | 30 | namespace oauth2_internal { |
30 | 31 | GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN |
31 | 32 |
|
| 33 | +struct ServiceAccountAllowedLocationsRequest { |
| 34 | + std::string service_account_email; |
| 35 | +}; |
| 36 | + |
| 37 | +struct WorkloadIdentityAllowedLocationsRequest { |
| 38 | + std::string project_id; |
| 39 | + std::string pool_id; |
| 40 | +}; |
| 41 | + |
| 42 | +struct WorkforceIdentityAllowedLocationsRequest { |
| 43 | + std::string pool_id; |
| 44 | +}; |
| 45 | + |
32 | 46 | /** |
33 | 47 | * Interface for OAuth 2.0 credentials for use with Google's Unified Auth Client |
34 | 48 | * (GUAC) library. Internally, GUAC credentials are mapped to the appropriate |
@@ -69,9 +83,8 @@ class Credentials { |
69 | 83 | * @param endpoint the endpoint of the GCP service the RPC request will be |
70 | 84 | * sent to. |
71 | 85 | */ |
72 | | - virtual StatusOr<std::vector<rest_internal::HttpHeader>> |
73 | | - AuthenticationHeaders(std::chrono::system_clock::time_point tp, |
74 | | - std::string_view endpoint); |
| 86 | + StatusOr<std::vector<rest_internal::HttpHeader>> AuthenticationHeaders( |
| 87 | + std::chrono::system_clock::time_point tp, std::string_view endpoint); |
75 | 88 |
|
76 | 89 | /** |
77 | 90 | * Try to sign @p string_to_sign using @p service_account. |
@@ -160,6 +173,20 @@ class Credentials { |
160 | 173 | */ |
161 | 174 | virtual StatusOr<AccessToken> GetToken( |
162 | 175 | std::chrono::system_clock::time_point tp) = 0; |
| 176 | + |
| 177 | + using AllowedLocationsRequestType = |
| 178 | + std::variant<std::monostate, ServiceAccountAllowedLocationsRequest, |
| 179 | + WorkforceIdentityAllowedLocationsRequest, |
| 180 | + WorkloadIdentityAllowedLocationsRequest>; |
| 181 | + /** |
| 182 | + * Obtains the request type from the underlying credential, if supported. |
| 183 | + * |
| 184 | + * Not all credential types support the `x-allowed-locations` header, but |
| 185 | + * those that do vary in the data needed to format the request to IAM. |
| 186 | + */ |
| 187 | + virtual AllowedLocationsRequestType AllowedLocationsRequest() const { |
| 188 | + return std::monostate{}; |
| 189 | + } |
163 | 190 | }; |
164 | 191 |
|
165 | 192 | GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END |
|
0 commit comments