Skip to content

Commit fb1c0fd

Browse files
committed
add SubjectOption
1 parent 63acd82 commit fb1c0fd

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

google/cloud/credentials.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,9 @@ struct DelegatesOption {
458458
};
459459

460460
/**
461-
* Configure the scopes for `MakeImpersonateServiceAccountCredentials()`
461+
* Configure the scopes for `MakeImpersonateServiceAccountCredentials()`.
462+
* Override the scopes for `MakeServiceAccountCredentials` and
463+
* `MakeServiceAccountCredentialsFromFile()`.
462464
*
463465
* @ingroup options
464466
* @ingroup guac
@@ -467,6 +469,17 @@ struct ScopesOption {
467469
using Type = std::vector<std::string>;
468470
};
469471

472+
/**
473+
* Overrides the subject for `MakeServiceAccountCredentials` and
474+
* `MakeServiceAccountCredentialsFromFile()`.
475+
*
476+
* @ingroup options
477+
* @ingroup guac
478+
*/
479+
struct SubjectOption {
480+
using Type = std::string;
481+
};
482+
470483
/**
471484
* Configure the access token lifetime
472485
*

google/cloud/internal/oauth2_service_account_credentials.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ CreateServiceAccountCredentialsFromJsonContents(
256256
info->scopes = std::move(scopes);
257257
}
258258

259+
if (options.has<SubjectOption>()) {
260+
info->subject = options.get<SubjectOption>();
261+
}
262+
259263
// Verify this is usable before returning it.
260264
auto const tp = std::chrono::system_clock::time_point{};
261265
auto const components = AssertionComponentsFromInfo(*info, tp);
@@ -295,6 +299,11 @@ CreateServiceAccountCredentialsFromP12FilePath(
295299
std::set<std::string> scopes{s.begin(), s.end()};
296300
info->scopes = std::move(scopes);
297301
}
302+
303+
if (options.has<SubjectOption>()) {
304+
info->subject = options.get<SubjectOption>();
305+
}
306+
298307
return StatusOr<std::shared_ptr<Credentials>>(
299308
std::make_shared<ServiceAccountCredentials>(*info, options,
300309
std::move(client_factory)));

0 commit comments

Comments
 (0)