Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(common): options for Make*Credentials() #10417

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified ci/abi-dumps/google_cloud_cpp_common.expected.abi.dump.gz
Binary file not shown.
Binary file modified ci/abi-dumps/google_cloud_cpp_storage.expected.abi.dump.gz
Binary file not shown.
17 changes: 9 additions & 8 deletions google/cloud/credentials.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,20 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN

Credentials::~Credentials() = default;

std::shared_ptr<Credentials> MakeInsecureCredentials() {
return std::make_shared<internal::InsecureCredentialsConfig>(Options{});
std::shared_ptr<Credentials> MakeInsecureCredentials(Options opts) {
return std::make_shared<internal::InsecureCredentialsConfig>(std::move(opts));
}

std::shared_ptr<Credentials> MakeGoogleDefaultCredentials() {
return std::make_shared<internal::GoogleDefaultCredentialsConfig>(Options{});
std::shared_ptr<Credentials> MakeGoogleDefaultCredentials(Options opts) {
return std::make_shared<internal::GoogleDefaultCredentialsConfig>(
std::move(opts));
}

std::shared_ptr<Credentials> MakeAccessTokenCredentials(
std::string const& access_token,
std::chrono::system_clock::time_point expiration) {
std::chrono::system_clock::time_point expiration, Options opts) {
return std::make_shared<internal::AccessTokenConfig>(access_token, expiration,
Options{});
std::move(opts));
}

std::shared_ptr<Credentials> MakeImpersonateServiceAccountCredentials(
Expand All @@ -45,9 +46,9 @@ std::shared_ptr<Credentials> MakeImpersonateServiceAccountCredentials(
}

std::shared_ptr<Credentials> MakeServiceAccountCredentials(
std::string json_object) {
std::string json_object, Options opts) {
return std::make_shared<internal::ServiceAccountConfig>(
std::move(json_object), Options{});
std::move(json_object), std::move(opts));
}

GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
Expand Down
41 changes: 36 additions & 5 deletions google/cloud/credentials.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_CREDENTIALS_H
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_CREDENTIALS_H

#include "google/cloud/common_options.h"
#include "google/cloud/options.h"
#include "google/cloud/version.h"
#include <chrono>
Expand Down Expand Up @@ -82,8 +83,12 @@ struct UnifiedCredentialsOption {
* and sometimes even errors.
*
* @ingroup guac
*
* @param opts optional configuration values. Note that the effect of these
* parameters depends on the underlying transport. For example
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/$/,/ et seq.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Fixed.

* `TracingComponentsOption` is ignored by gRPC-based services.
*/
std::shared_ptr<Credentials> MakeInsecureCredentials();
std::shared_ptr<Credentials> MakeInsecureCredentials(Options opts = {});

/**
* Creates the default credentials.
Expand Down Expand Up @@ -114,8 +119,12 @@ std::shared_ptr<Credentials> MakeInsecureCredentials();
* https://cloud.google.com/sdk/gcloud/reference/auth/application-default
*
* @ingroup guac
*
* @param opts optional configuration values. Note that the effect of these
* parameters depends on the underlying transport. For example
* `TracingComponentsOption` is ignored by gRPC-based services.
*/
std::shared_ptr<Credentials> MakeGoogleDefaultCredentials();
std::shared_ptr<Credentials> MakeGoogleDefaultCredentials(Options opts = {});

/**
* Creates credentials with a fixed access token.
Expand All @@ -128,10 +137,16 @@ std::shared_ptr<Credentials> MakeGoogleDefaultCredentials();
* authentication in GCP.
*
* @ingroup guac
*
* @param access_token the access token to be used by the client library.
* @param expiration the expiration time for the token.
* @param opts optional configuration values. Note that the effect of these
* parameters depends on the underlying transport. For example
* `TracingComponentsOption` is ignored by gRPC-based services.
*/
std::shared_ptr<Credentials> MakeAccessTokenCredentials(
std::string const& access_token,
std::chrono::system_clock::time_point expiration);
std::chrono::system_clock::time_point expiration, Options opts = {});

/**
* Creates credentials for service account impersonation.
Expand Down Expand Up @@ -167,6 +182,14 @@ std::shared_ptr<Credentials> MakeAccessTokenCredentials(
* authentication scopes in Google Cloud Platform.
*
* @ingroup guac
*
* @param base_credentials the credentials used to contact the IAM Credentials
* services.
* @param target_service_account the email address of the service account to
* impersonate.
* @param opts optional configuration values. Note that the effect of these
* parameters depends on the underlying transport. For example
* `TracingComponentsOption` is ignored by gRPC-based services.
*/
std::shared_ptr<Credentials> MakeImpersonateServiceAccountCredentials(
std::shared_ptr<Credentials> base_credentials,
Expand Down Expand Up @@ -206,9 +229,16 @@ std::shared_ptr<Credentials> MakeImpersonateServiceAccountCredentials(
* https://cloud.google.com/iam/docs/creating-managing-service-account-keys#iam-service-account-keys-create-cpp
*
* @ingroup guac
*
* @param json_object the service account configuration as a JSON string.
* Typically applications read this from a file, or download the contents from
* something like Google's secret manager service.
* @param opts optional configuration values. Note that the effect of these
* parameters depends on the underlying transport. For example
* `TracingComponentsOption` is ignored by gRPC-based services.
*/
std::shared_ptr<Credentials> MakeServiceAccountCredentials(
std::string json_object);
std::string json_object, Options opts = {});

/**
* Configure the delegates for `MakeImpersonateServiceAccountCredentials()`
Expand Down Expand Up @@ -289,7 +319,8 @@ struct CARootsFilePathOption {
/// A list of options related to authentication.
using UnifiedCredentialsOptionList =
OptionList<AccessTokenLifetimeOption, CARootsFilePathOption,
DelegatesOption, ScopesOption, UnifiedCredentialsOption>;
DelegatesOption, ScopesOption, TracingComponentsOption,
UnifiedCredentialsOption>;

namespace internal {

Expand Down