Skip to content

Commit ad0601f

Browse files
authored
Moves credential code to the oauth2 subtree and namespace. (#1185)
Moves credential code to the oauth2 subtree and namespace.
1 parent 8c9da28 commit ad0601f

31 files changed

Lines changed: 189 additions & 152 deletions

google/cloud/storage/CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,8 @@ add_library(storage_client
100100
client.cc
101101
client_options.h
102102
client_options.cc
103-
credentials.h
104-
credentials.cc
105103
internal/access_control_common.h
106104
internal/access_control_common.cc
107-
internal/authorized_user_credentials.h
108105
internal/binary_data_as_debug_string.h
109106
internal/binary_data_as_debug_string.cc
110107
internal/bucket_acl_requests.h
@@ -113,7 +110,6 @@ add_library(storage_client
113110
internal/bucket_requests.cc
114111
internal/raw_client_wrapper_utils.h
115112
internal/common_metadata.h
116-
internal/credential_constants.h
117113
internal/curl_handle.h
118114
internal/curl_handle.cc
119115
internal/curl_handle_factory.h
@@ -140,8 +136,6 @@ add_library(storage_client
140136
internal/format_rfc3339.cc
141137
internal/generic_object_request.h
142138
internal/generic_request.h
143-
internal/google_application_default_credentials_file.h
144-
internal/google_application_default_credentials_file.cc
145139
internal/http_response.h
146140
internal/http_response.cc
147141
internal/logging_client.h
@@ -165,7 +159,6 @@ add_library(storage_client
165159
internal/raw_client.h
166160
internal/retry_client.h
167161
internal/retry_client.cc
168-
internal/service_account_credentials.h
169162
internal/service_account_requests.h
170163
internal/service_account_requests.cc
171164
lifecycle_rule.h
@@ -178,6 +171,13 @@ add_library(storage_client
178171
notification_metadata.h
179172
notification_metadata.cc
180173
notification_payload_format.h
174+
oauth2/authorized_user_credentials.h
175+
oauth2/credential_constants.h
176+
oauth2/credentials.h
177+
oauth2/credentials.cc
178+
oauth2/google_application_default_credentials_file.h
179+
oauth2/google_application_default_credentials_file.cc
180+
oauth2/service_account_credentials.h
181181
object_access_control.h
182182
object_access_control.cc
183183
object_metadata.h
@@ -255,15 +255,12 @@ set(storage_client_unit_tests
255255
client_notifications_test.cc
256256
client_test.cc
257257
client_write_object_test.cc
258-
credentials_test.cc
259258
internal/access_control_common_test.cc
260-
internal/authorized_user_credentials_test.cc
261259
internal/binary_data_as_debug_string_test.cc
262260
internal/bucket_acl_requests_test.cc
263261
internal/bucket_requests_test.cc
264262
internal/default_object_acl_requests_test.cc
265263
internal/format_rfc3339_test.cc
266-
internal/google_application_default_credentials_file_test.cc
267264
internal/http_response_test.cc
268265
internal/logging_client_test.cc
269266
internal/metadata_parser_test.cc
@@ -274,11 +271,14 @@ set(storage_client_unit_tests
274271
internal/parse_rfc3339_test.cc
275272
internal/patch_builder_test.cc
276273
internal/retry_client_test.cc
277-
internal/service_account_credentials_test.cc
278274
internal/service_account_requests_test.cc
279275
lifecycle_rule_test.cc
280276
list_buckets_reader_test.cc
281277
list_objects_reader_test.cc
278+
oauth2/authorized_user_credentials_test.cc
279+
oauth2/credentials_test.cc
280+
oauth2/google_application_default_credentials_file_test.cc
281+
oauth2/service_account_credentials_test.cc
282282
object_access_control_test.cc
283283
object_metadata_test.cc
284284
object_test.cc

google/cloud/storage/bucket_test.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "google/cloud/storage/client.h"
16+
#include "google/cloud/storage/oauth2/credentials.h"
1617
#include "google/cloud/storage/retry_policy.h"
1718
#include "google/cloud/storage/testing/canonical_errors.h"
1819
#include "google/cloud/storage/testing/mock_client.h"
@@ -55,7 +56,8 @@ class BucketTest : public ::testing::Test {
5556

5657
std::shared_ptr<testing::MockClient> mock;
5758
std::unique_ptr<Client> client;
58-
ClientOptions client_options = ClientOptions(CreateInsecureCredentials());
59+
ClientOptions client_options =
60+
ClientOptions(oauth2::CreateInsecureCredentials());
5961
};
6062

6163
TEST_F(BucketTest, CreateBucket) {
@@ -74,7 +76,7 @@ TEST_F(BucketTest, CreateBucket) {
7476
})""";
7577
auto expected = BucketMetadata::ParseFromString(text);
7678

77-
ClientOptions mock_options(CreateInsecureCredentials());
79+
ClientOptions mock_options(oauth2::CreateInsecureCredentials());
7880
mock_options.set_project_id("test-project-name");
7981

8082
EXPECT_CALL(*mock, client_options()).WillRepeatedly(ReturnRef(mock_options));

google/cloud/storage/client.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "google/cloud/storage/list_objects_reader.h"
2222
#include "google/cloud/storage/notification_event_type.h"
2323
#include "google/cloud/storage/notification_payload_format.h"
24+
#include "google/cloud/storage/oauth2/credentials.h"
2425
#include "google/cloud/storage/object_rewriter.h"
2526
#include "google/cloud/storage/object_stream.h"
2627

@@ -48,7 +49,7 @@ class Client {
4849
/**
4950
* Creates the default client type given the credentials.
5051
*/
51-
explicit Client(std::shared_ptr<Credentials> credentials)
52+
explicit Client(std::shared_ptr<oauth2::Credentials> credentials)
5253
: Client(ClientOptions(std::move(credentials))) {}
5354

5455
/// Builds a client and maybe override the retry and/or backoff policies.

google/cloud/storage/client_bucket_acl_test.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "google/cloud/storage/client.h"
16+
#include "google/cloud/storage/oauth2/credentials.h"
1617
#include "google/cloud/storage/retry_policy.h"
1718
#include "google/cloud/storage/testing/canonical_errors.h"
1819
#include "google/cloud/storage/testing/mock_client.h"
@@ -49,7 +50,8 @@ class BucketAccessControlsTest : public ::testing::Test {
4950

5051
std::shared_ptr<testing::MockClient> mock;
5152
std::unique_ptr<Client> client;
52-
ClientOptions client_options = ClientOptions(CreateInsecureCredentials());
53+
ClientOptions client_options =
54+
ClientOptions(oauth2::CreateInsecureCredentials());
5355
};
5456

5557
TEST_F(BucketAccessControlsTest, ListBucketAcl) {

google/cloud/storage/client_default_object_acl_test.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "google/cloud/storage/client.h"
16+
#include "google/cloud/storage/oauth2/credentials.h"
1617
#include "google/cloud/storage/retry_policy.h"
1718
#include "google/cloud/storage/testing/canonical_errors.h"
1819
#include "google/cloud/storage/testing/mock_client.h"
@@ -49,7 +50,8 @@ class DefaultObjectAccessControlsTest : public ::testing::Test {
4950

5051
std::shared_ptr<testing::MockClient> mock;
5152
std::unique_ptr<Client> client;
52-
ClientOptions client_options = ClientOptions(CreateInsecureCredentials());
53+
ClientOptions client_options =
54+
ClientOptions(oauth2::CreateInsecureCredentials());
5355
};
5456

5557
TEST_F(DefaultObjectAccessControlsTest, ListDefaultObjectAcl) {

google/cloud/storage/client_notifications_test.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "google/cloud/storage/client.h"
1616
#include "google/cloud/storage/notification_event_type.h"
1717
#include "google/cloud/storage/notification_payload_format.h"
18+
#include "google/cloud/storage/oauth2/credentials.h"
1819
#include "google/cloud/storage/retry_policy.h"
1920
#include "google/cloud/storage/testing/canonical_errors.h"
2021
#include "google/cloud/storage/testing/mock_client.h"
@@ -52,7 +53,8 @@ class NotificationsTest : public ::testing::Test {
5253

5354
std::shared_ptr<testing::MockClient> mock_;
5455
std::unique_ptr<Client> client_;
55-
ClientOptions client_options_ = ClientOptions(CreateInsecureCredentials());
56+
ClientOptions client_options_ =
57+
ClientOptions(oauth2::CreateInsecureCredentials());
5658
};
5759

5860
TEST_F(NotificationsTest, ListNotifications) {

google/cloud/storage/client_object_acl_test.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "google/cloud/storage/client.h"
16+
#include "google/cloud/storage/oauth2/credentials.h"
1617
#include "google/cloud/storage/retry_policy.h"
1718
#include "google/cloud/storage/testing/canonical_errors.h"
1819
#include "google/cloud/storage/testing/mock_client.h"
@@ -48,7 +49,8 @@ class ObjectAccessControlsTest : public ::testing::Test {
4849

4950
std::shared_ptr<testing::MockClient> mock;
5051
std::unique_ptr<Client> client;
51-
ClientOptions client_options = ClientOptions(CreateInsecureCredentials());
52+
ClientOptions client_options =
53+
ClientOptions(oauth2::CreateInsecureCredentials());
5254
};
5355

5456
TEST_F(ObjectAccessControlsTest, ListObjectAcl) {

google/cloud/storage/client_options.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "google/cloud/storage/client_options.h"
1616
#include "google/cloud/log.h"
17+
#include "google/cloud/storage/oauth2/credentials.h"
1718
#include <cstdlib>
1819
#include <set>
1920
#include <sstream>
@@ -24,13 +25,12 @@ namespace cloud {
2425
namespace storage {
2526
inline namespace STORAGE_CLIENT_NS {
2627
namespace {
27-
std::shared_ptr<google::cloud::storage::Credentials>
28-
StorageDefaultCredentials() {
28+
std::shared_ptr<oauth2::Credentials> StorageDefaultCredentials() {
2929
char const* emulator = std::getenv("CLOUD_STORAGE_TESTBENCH_ENDPOINT");
3030
if (emulator != nullptr) {
31-
return google::cloud::storage::CreateInsecureCredentials();
31+
return oauth2::CreateInsecureCredentials();
3232
}
33-
return google::cloud::storage::GoogleDefaultCredentials();
33+
return oauth2::GoogleDefaultCredentials();
3434
}
3535

3636
std::size_t DefaultConnectionPoolSize() {
@@ -53,7 +53,7 @@ std::size_t DefaultConnectionPoolSize() {
5353

5454
ClientOptions::ClientOptions() : ClientOptions(StorageDefaultCredentials()) {}
5555

56-
ClientOptions::ClientOptions(std::shared_ptr<Credentials> credentials)
56+
ClientOptions::ClientOptions(std::shared_ptr<oauth2::Credentials> credentials)
5757
: credentials_(std::move(credentials)),
5858
endpoint_("https://www.googleapis.com"),
5959
version_("v1"),

google/cloud/storage/client_options.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_CLIENT_OPTIONS_H_
1717

1818
#include "google/cloud/internal/throw_delegate.h"
19-
#include "google/cloud/storage/credentials.h"
19+
#include "google/cloud/storage/oauth2/credentials.h"
2020

2121
namespace google {
2222
namespace cloud {
@@ -40,10 +40,13 @@ inline namespace STORAGE_CLIENT_NS {
4040
class ClientOptions {
4141
public:
4242
ClientOptions();
43-
explicit ClientOptions(std::shared_ptr<Credentials> credentials);
43+
explicit ClientOptions(std::shared_ptr<oauth2::Credentials> credentials);
4444

45-
std::shared_ptr<Credentials> credentials() const { return credentials_; }
46-
ClientOptions& set_credentials(std::shared_ptr<Credentials> credentials) {
45+
std::shared_ptr<oauth2::Credentials> credentials() const {
46+
return credentials_;
47+
}
48+
ClientOptions& set_credentials(
49+
std::shared_ptr<oauth2::Credentials> credentials) {
4750
credentials_ = std::move(credentials);
4851
return *this;
4952
}
@@ -105,7 +108,7 @@ class ClientOptions {
105108
void SetupFromEnvironment();
106109

107110
private:
108-
std::shared_ptr<Credentials> credentials_;
111+
std::shared_ptr<oauth2::Credentials> credentials_;
109112
std::string endpoint_;
110113
std::string version_;
111114
bool enable_http_tracing_;

google/cloud/storage/client_service_account_test.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace cloud {
2424
namespace storage {
2525
inline namespace STORAGE_CLIENT_NS {
2626
namespace {
27+
using storage::oauth2::CreateInsecureCredentials;
2728
using ::testing::_;
2829
using ::testing::Invoke;
2930
using ::testing::Return;

0 commit comments

Comments
 (0)