Skip to content

Commit 99b476e

Browse files
authored
cleanup: revert ApiKeyOption changes (#14761)
1 parent 30e89e0 commit 99b476e

9 files changed

+1
-94
lines changed

google/cloud/common_options.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -280,30 +280,6 @@ struct CustomHeadersOption {
280280
using Type = std::unordered_multimap<std::string, std::string>;
281281
};
282282

283-
/**
284-
* An option to authenticate using an [API key].
285-
*
286-
* API keys are convenient because no [principal] is needed. The API key
287-
* associates the request with a Google Cloud project for billing and quota
288-
* purposes.
289-
*
290-
* @note Most Cloud APIs do not support API keys, instead requiring full
291-
* credentials.
292-
*
293-
* @note Using API keys is mutually exclusive with providing credentials. The
294-
* client library will error out if both `ApiKeyOption` and
295-
* `UnifiedCredentialsOption` are set.
296-
*
297-
* @ingroup guac
298-
* @ingroup options
299-
*
300-
* [API key]: https://cloud.google.com/docs/authentication/api-keys-use
301-
* [principal]: https://cloud.google.com/docs/authentication#principal
302-
*/
303-
struct ApiKeyOption {
304-
using Type = std::string;
305-
};
306-
307283
/**
308284
* Configure server-side filtering.
309285
*

google/cloud/grpc_options.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ void SetMetadata(grpc::ClientContext& context, Options const& options,
4545
if (options.has<QuotaUserOption>()) {
4646
context.AddMetadata("x-goog-quota-user", options.get<QuotaUserOption>());
4747
}
48-
if (options.has<ApiKeyOption>()) {
49-
context.AddMetadata("x-goog-api-key", options.get<ApiKeyOption>());
50-
}
5148
if (options.has<FieldMaskOption>()) {
5249
context.AddMetadata("x-goog-fieldmask", options.get<FieldMaskOption>());
5350
}

google/cloud/grpc_options_test.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@ TEST(GrpcSetMetadata, Full) {
329329
Options{}
330330
.set<UserProjectOption>("user-project")
331331
.set<QuotaUserOption>("quota-user")
332-
.set<ApiKeyOption>("api-key")
333332
.set<AuthorityOption>("authority.googleapis.com")
334333
.set<CustomHeadersOption>(
335334
{{"custom-header-1", "v1"}, {"custom-header-2", "v2"}}),
@@ -341,7 +340,6 @@ TEST(GrpcSetMetadata, Full) {
341340
UnorderedElementsAre(
342341
Pair("x-goog-user-project", "user-project"),
343342
Pair("x-goog-quota-user", "quota-user"),
344-
Pair("x-goog-api-key", "api-key"),
345343
Pair("fixed-header-1", "v1"), Pair("fixed-header-2", "v2"),
346344
Pair("custom-header-1", "v1"), Pair("custom-header-2", "v2"),
347345
Pair("x-goog-api-client", "api-client-header")));

google/cloud/internal/populate_grpc_options.cc

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
2525
namespace internal {
2626

2727
Options PopulateGrpcOptions(Options opts) {
28-
if (opts.has<ApiKeyOption>()) {
29-
if (opts.has<UnifiedCredentialsOption>()) {
30-
opts.set<UnifiedCredentialsOption>(
31-
internal::MakeErrorCredentials(internal::InvalidArgumentError(
32-
"API Keys and Credentials are mutually exclusive authentication "
33-
"methods and cannot be used together.")));
34-
}
35-
opts.set<GrpcCredentialOption>(grpc::SslCredentials({}));
36-
}
3728
if (!opts.has<GrpcCredentialOption>() &&
3829
!opts.has<UnifiedCredentialsOption>()) {
3930
opts.set<UnifiedCredentialsOption>(MakeGoogleDefaultCredentials());

google/cloud/internal/populate_grpc_options_test.cc

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,6 @@ TEST(PopulateGrpcOptions, GrpcCredentialOptionBackCompat) {
6363
EXPECT_EQ(creds, actual.get<GrpcCredentialOption>());
6464
}
6565

66-
TEST(PopulateGrpcOptions, ApiKey) {
67-
auto actual = PopulateGrpcOptions(Options{}.set<ApiKeyOption>("api-key"));
68-
EXPECT_TRUE(actual.has<GrpcCredentialOption>());
69-
EXPECT_FALSE(actual.has<UnifiedCredentialsOption>());
70-
}
71-
72-
TEST(PopulateGrpcOptions, ApiKeyWithCredentialsErrors) {
73-
auto actual = PopulateGrpcOptions(
74-
Options{}.set<ApiKeyOption>("api-key").set<UnifiedCredentialsOption>(
75-
MakeGoogleDefaultCredentials()));
76-
77-
EXPECT_TRUE(actual.has<UnifiedCredentialsOption>());
78-
auto const& creds = actual.get<UnifiedCredentialsOption>();
79-
TestCredentialsVisitor v;
80-
CredentialsVisitor::dispatch(*creds, v);
81-
EXPECT_EQ(v.name, "ErrorCredentialsConfig");
82-
}
83-
8466
TEST(PopulateGrpcOptions, TracingOptions) {
8567
ScopedEnvironment env("GOOGLE_CLOUD_CPP_TRACING_OPTIONS",
8668
"truncate_string_field_longer_than=42");

google/cloud/internal/populate_rest_options.cc

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,7 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
2929
namespace internal {
3030

3131
Options PopulateRestOptions(Options opts) {
32-
if (opts.has<ApiKeyOption>() && opts.has<UnifiedCredentialsOption>()) {
33-
opts.set<UnifiedCredentialsOption>(
34-
internal::MakeErrorCredentials(internal::InvalidArgumentError(
35-
"API Keys and Credentials are mutually exclusive authentication "
36-
"methods and cannot be used together.")));
37-
}
38-
if (!opts.has<UnifiedCredentialsOption>() && !opts.has<ApiKeyOption>()) {
32+
if (!opts.has<UnifiedCredentialsOption>()) {
3933
opts.set<UnifiedCredentialsOption>(
4034
MakeGoogleDefaultCredentials(internal::MakeAuthOptions(opts)));
4135
}

google/cloud/internal/populate_rest_options_test.cc

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,23 +103,6 @@ TEST(PopulateRestOptions, TracingOptions) {
103103
EXPECT_EQ(tracing.truncate_string_field_longer_than(), 42);
104104
}
105105

106-
TEST(PopulateRestOptions, ApiKey) {
107-
auto actual = PopulateRestOptions(Options{}.set<ApiKeyOption>("api-key"));
108-
EXPECT_FALSE(actual.has<UnifiedCredentialsOption>());
109-
}
110-
111-
TEST(PopulateRestOptions, ApiKeyWithCredentialsErrors) {
112-
auto actual = PopulateRestOptions(
113-
Options{}.set<ApiKeyOption>("api-key").set<UnifiedCredentialsOption>(
114-
MakeGoogleDefaultCredentials()));
115-
116-
EXPECT_TRUE(actual.has<UnifiedCredentialsOption>());
117-
auto const& creds = actual.get<UnifiedCredentialsOption>();
118-
TestCredentialsVisitor v;
119-
CredentialsVisitor::dispatch(*creds, v);
120-
EXPECT_EQ(v.name, "ErrorCredentialsConfig");
121-
}
122-
123106
} // namespace
124107
} // namespace internal
125108
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END

google/cloud/internal/rest_set_metadata.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ void SetMetadata(RestContext& context, Options const& options,
3838
if (options.has<QuotaUserOption>()) {
3939
context.AddHeader("x-goog-quota-user", options.get<QuotaUserOption>());
4040
}
41-
if (options.has<ApiKeyOption>()) {
42-
context.AddHeader("x-goog-api-key", options.get<ApiKeyOption>());
43-
}
4441
if (options.has<FieldMaskOption>()) {
4542
context.AddHeader("x-goog-fieldmask", options.get<FieldMaskOption>());
4643
}

google/cloud/internal/rest_set_metadata_test.cc

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ namespace rest_internal {
2525
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
2626
namespace {
2727

28-
using ::testing::Contains;
2928
using ::testing::ElementsAre;
3029
using ::testing::Pair;
3130
using ::testing::UnorderedElementsAre;
@@ -53,7 +52,6 @@ TEST(RestContextTest, SetMetadataFull) {
5352
Options{}
5453
.set<UserProjectOption>("user-project")
5554
.set<QuotaUserOption>("quota-user")
56-
.set<ApiKeyOption>("api-key")
5755
.set<FieldMaskOption>("items.name,token")
5856
.set<ServerTimeoutOption>(std::chrono::milliseconds(1050))
5957
.set<CustomHeadersOption>(
@@ -65,21 +63,12 @@ TEST(RestContextTest, SetMetadataFull) {
6563
Pair("x-goog-request-params", ElementsAre("p1=v1&p2=v2")),
6664
Pair("x-goog-user-project", ElementsAre("user-project")),
6765
Pair("x-goog-quota-user", ElementsAre("quota-user")),
68-
Pair("x-goog-api-key", ElementsAre("api-key")),
6966
Pair("x-goog-fieldmask", ElementsAre("items.name,token")),
7067
Pair("x-server-timeout", ElementsAre("1.050")),
7168
Pair("custom-header-1", ElementsAre("v1")),
7269
Pair("custom-header-2", ElementsAre("v2"))));
7370
}
7471

75-
TEST(RestContextTest, Regression14745) {
76-
RestContext lhs;
77-
SetMetadata(lhs, Options{}.set<ApiKeyOption>("api-key"), {},
78-
"api-client-header");
79-
EXPECT_THAT(lhs.headers(),
80-
Contains(Pair("x-goog-api-key", ElementsAre("api-key"))));
81-
}
82-
8372
} // namespace
8473
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
8574
} // namespace rest_internal

0 commit comments

Comments
 (0)