Skip to content

Commit b2ddfba

Browse files
authored
refactor(ids): versioned clients (#10911)
1 parent 782f36e commit b2ddfba

41 files changed

Lines changed: 834 additions & 628 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
76 Bytes
Binary file not shown.

ci/etc/expected_install_directories

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,10 @@
279279
./include/google/cloud/iap/v1/internal
280280
./include/google/cloud/iap/v1/mocks
281281
./include/google/cloud/ids
282-
./include/google/cloud/ids/internal
283282
./include/google/cloud/ids/mocks
284283
./include/google/cloud/ids/v1
284+
./include/google/cloud/ids/v1/internal
285+
./include/google/cloud/ids/v1/mocks
285286
./include/google/cloud/iot
286287
./include/google/cloud/iot/internal
287288
./include/google/cloud/iot/mocks

generator/generator_config.textproto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,8 @@ service {
10411041
# IDS (Cloud Intrusion Detection System)
10421042
service {
10431043
service_proto_path: "google/cloud/ids/v1/ids.proto"
1044-
product_path: "google/cloud/ids"
1044+
product_path: "google/cloud/ids/v1"
1045+
forwarding_product_path: "google/cloud/ids"
10451046
initial_copyright_year: "2022"
10461047
retryable_status_codes: ["kUnavailable"]
10471048
}

google/cloud/ids/BUILD.bazel

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,26 @@ package(default_visibility = ["//visibility:private"])
1616

1717
licenses(["notice"]) # Apache 2.0
1818

19+
service_dirs = [
20+
"",
21+
"v1/",
22+
]
23+
24+
src_dirs = service_dirs + [d + "internal/" for d in service_dirs]
25+
1926
filegroup(
2027
name = "srcs",
21-
srcs = glob([
22-
"*.cc",
23-
"internal/*.cc",
24-
]),
28+
srcs = glob([d + "*.cc" for d in src_dirs]),
2529
)
2630

2731
filegroup(
2832
name = "hdrs",
29-
srcs = glob([
30-
"*.h",
31-
"internal/*.h",
32-
]),
33+
srcs = glob([d + "*.h" for d in src_dirs]),
3334
)
3435

3536
filegroup(
3637
name = "mocks",
37-
srcs = glob(["mocks/*.h"]),
38+
srcs = glob([d + "mocks/*.h" for d in service_dirs]),
3839
)
3940

4041
cc_library(
@@ -58,3 +59,13 @@ cc_library(
5859
"@com_google_googletest//:gtest",
5960
],
6061
)
62+
63+
[cc_test(
64+
name = sample.replace("/", "_").replace(".cc", ""),
65+
srcs = [sample],
66+
tags = ["integration-test"],
67+
deps = [
68+
"//:ids",
69+
"//google/cloud/testing_util:google_cloud_cpp_testing_private",
70+
],
71+
) for sample in glob([d + "samples/*.cc" for d in service_dirs])]

google/cloud/ids/CMakeLists.txt

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,22 @@ include(GoogleapisConfig)
1818
set(DOXYGEN_PROJECT_NAME "Cloud IDS API C++ Client")
1919
set(DOXYGEN_PROJECT_BRIEF "A C++ Client Library for the Cloud IDS API")
2020
set(DOXYGEN_PROJECT_NUMBER "${PROJECT_VERSION}")
21-
set(DOXYGEN_EXCLUDE_SYMBOLS "internal" "ids_internal" "ids_testing" "examples")
22-
set(DOXYGEN_EXAMPLE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/samples
23-
${CMAKE_CURRENT_SOURCE_DIR}/quickstart)
21+
set(DOXYGEN_EXCLUDE_SYMBOLS "internal")
22+
set(DOXYGEN_EXAMPLE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/quickstart")
23+
24+
unset(mocks_globs)
25+
unset(source_globs)
26+
set(service_dirs "" "v1/")
27+
foreach (dir IN LISTS service_dirs)
28+
string(REPLACE "/" "_" ns "${dir}")
29+
list(APPEND source_globs "${dir}*.h" "${dir}*.cc" "${dir}internal/*")
30+
list(APPEND mocks_globs "${dir}mocks/*.h")
31+
list(APPEND DOXYGEN_EXCLUDE_SYMBOLS "ids_${ns}internal")
32+
if (NOT dir STREQUAL "")
33+
list(APPEND DOXYGEN_EXAMPLE_PATH
34+
"${CMAKE_CURRENT_SOURCE_DIR}/${dir}samples")
35+
endif ()
36+
endforeach ()
2437

2538
include(GoogleCloudCppDoxygen)
2639
google_cloud_cpp_doxygen_targets("ids" DEPENDS cloud-docs
@@ -44,7 +57,7 @@ target_link_libraries(google_cloud_cpp_ids_protos PUBLIC ${proto_deps})
4457
file(
4558
GLOB source_files
4659
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
47-
"*.h" "*.cc" "internal/*.h" "internal/*.cc")
60+
${source_globs})
4861
list(SORT source_files)
4962
add_library(google_cloud_cpp_ids ${source_files})
5063
target_include_directories(
@@ -74,7 +87,7 @@ add_library(google-cloud-cpp::ids ALIAS google_cloud_cpp_ids)
7487
file(
7588
GLOB relative_mock_files
7689
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
77-
"mocks/*.h")
90+
${mocks_globs})
7891
list(SORT relative_mock_files)
7992
set(mock_files)
8093
foreach (file IN LISTS relative_mock_files)
@@ -168,3 +181,10 @@ install(
168181
COMPONENT google_cloud_cpp_development)
169182

170183
external_googleapis_install_pc("google_cloud_cpp_ids_protos")
184+
185+
# google-cloud-cpp::ids must be defined before we can add the samples.
186+
foreach (dir IN LISTS service_dirs)
187+
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
188+
google_cloud_cpp_add_samples_relative("ids" "${dir}samples/")
189+
endif ()
190+
endforeach ()

google/cloud/ids/doc/main.dox

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ library. Use the `google::cloud::EndpointOption` when initializing the client
9797
library to change this default.
9898

9999
<!-- inject-endpoint-snippet-start -->
100-
For example, this will override the default endpoint for `ids::IDSClient`:
100+
For example, this will override the default endpoint for `ids_v1::IDSClient`:
101101

102102
@snippet ids_client_samples.cc set-client-endpoint
103103

@@ -142,15 +142,15 @@ can override the default policies.
142142

143143
// <!-- inject-endpoint-pages-start -->
144144

145-
/*! @page ids::IDSClient-endpoint-snippet Override ids::IDSClient Endpoint Configuration
145+
/*! @page ids_v1::IDSClient-endpoint-snippet Override ids_v1::IDSClient Endpoint Configuration
146146

147-
@snippet google/cloud/ids/samples/ids_client_samples.cc set-client-endpoint
147+
@snippet google/cloud/ids/v1/samples/ids_client_samples.cc set-client-endpoint
148148

149149
*/
150150

151-
/*! @page ids::IDSClient-service-account-snippet Override ids::IDSClient Authentication Defaults
151+
/*! @page ids_v1::IDSClient-service-account-snippet Override ids_v1::IDSClient Authentication Defaults
152152

153-
@snippet google/cloud/ids/samples/ids_client_samples.cc with-service-account
153+
@snippet google/cloud/ids/v1/samples/ids_client_samples.cc with-service-account
154154

155155
*/
156156
// <!-- inject-endpoint-pages-end -->

google/cloud/ids/ids_client.h

Lines changed: 3 additions & 217 deletions
Original file line numberDiff line numberDiff line change
@@ -20,229 +20,15 @@
2020
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_IDS_IDS_CLIENT_H
2121

2222
#include "google/cloud/ids/ids_connection.h"
23-
#include "google/cloud/future.h"
24-
#include "google/cloud/options.h"
25-
#include "google/cloud/polling_policy.h"
26-
#include "google/cloud/status_or.h"
27-
#include "google/cloud/version.h"
28-
#include <google/longrunning/operations.grpc.pb.h>
29-
#include <map>
30-
#include <memory>
23+
#include "google/cloud/ids/v1/ids_client.h"
3124

3225
namespace google {
3326
namespace cloud {
3427
namespace ids {
3528
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
3629

37-
///
38-
/// The IDS Service
39-
///
40-
/// @par Equality
41-
///
42-
/// Instances of this class created via copy-construction or copy-assignment
43-
/// always compare equal. Instances created with equal
44-
/// `std::shared_ptr<*Connection>` objects compare equal. Objects that compare
45-
/// equal share the same underlying resources.
46-
///
47-
/// @par Performance
48-
///
49-
/// Creating a new instance of this class is a relatively expensive operation,
50-
/// new objects establish new connections to the service. In contrast,
51-
/// copy-construction, move-construction, and the corresponding assignment
52-
/// operations are relatively efficient as the copies share all underlying
53-
/// resources.
54-
///
55-
/// @par Thread Safety
56-
///
57-
/// Concurrent access to different instances of this class, even if they compare
58-
/// equal, is guaranteed to work. Two or more threads operating on the same
59-
/// instance of this class is not guaranteed to work. Since copy-construction
60-
/// and move-construction is a relatively efficient operation, consider using
61-
/// such a copy when using this class from multiple threads.
62-
///
63-
class IDSClient {
64-
public:
65-
explicit IDSClient(std::shared_ptr<IDSConnection> connection,
66-
Options opts = {});
67-
~IDSClient();
68-
69-
///@{
70-
/// @name Copy and move support
71-
IDSClient(IDSClient const&) = default;
72-
IDSClient& operator=(IDSClient const&) = default;
73-
IDSClient(IDSClient&&) = default;
74-
IDSClient& operator=(IDSClient&&) = default;
75-
///@}
76-
77-
///@{
78-
/// @name Equality
79-
friend bool operator==(IDSClient const& a, IDSClient const& b) {
80-
return a.connection_ == b.connection_;
81-
}
82-
friend bool operator!=(IDSClient const& a, IDSClient const& b) {
83-
return !(a == b);
84-
}
85-
///@}
86-
87-
///
88-
/// Lists Endpoints in a given project and location.
89-
///
90-
/// @param parent Required. The parent, which owns this collection of
91-
/// endpoints.
92-
/// @param opts Optional. Override the class-level options, such as retry and
93-
/// backoff policies.
94-
/// @return
95-
/// @googleapis_link{google::cloud::ids::v1::Endpoint,google/cloud/ids/v1/ids.proto#L81}
96-
///
97-
/// [google.cloud.ids.v1.Endpoint]:
98-
/// @googleapis_reference_link{google/cloud/ids/v1/ids.proto#L81}
99-
/// [google.cloud.ids.v1.ListEndpointsRequest]:
100-
/// @googleapis_reference_link{google/cloud/ids/v1/ids.proto#L158}
101-
///
102-
StreamRange<google::cloud::ids::v1::Endpoint> ListEndpoints(
103-
std::string const& parent, Options opts = {});
104-
105-
///
106-
/// Lists Endpoints in a given project and location.
107-
///
108-
/// @param request
109-
/// @googleapis_link{google::cloud::ids::v1::ListEndpointsRequest,google/cloud/ids/v1/ids.proto#L158}
110-
/// @param opts Optional. Override the class-level options, such as retry and
111-
/// backoff policies.
112-
/// @return
113-
/// @googleapis_link{google::cloud::ids::v1::Endpoint,google/cloud/ids/v1/ids.proto#L81}
114-
///
115-
/// [google.cloud.ids.v1.Endpoint]:
116-
/// @googleapis_reference_link{google/cloud/ids/v1/ids.proto#L81}
117-
/// [google.cloud.ids.v1.ListEndpointsRequest]:
118-
/// @googleapis_reference_link{google/cloud/ids/v1/ids.proto#L158}
119-
///
120-
StreamRange<google::cloud::ids::v1::Endpoint> ListEndpoints(
121-
google::cloud::ids::v1::ListEndpointsRequest request, Options opts = {});
122-
123-
///
124-
/// Gets details of a single Endpoint.
125-
///
126-
/// @param name Required. The name of the endpoint to retrieve.
127-
/// Format: `projects/{project}/locations/{location}/endpoints/{endpoint}`
128-
/// @param opts Optional. Override the class-level options, such as retry and
129-
/// backoff policies.
130-
/// @return
131-
/// @googleapis_link{google::cloud::ids::v1::Endpoint,google/cloud/ids/v1/ids.proto#L81}
132-
///
133-
/// [google.cloud.ids.v1.Endpoint]:
134-
/// @googleapis_reference_link{google/cloud/ids/v1/ids.proto#L81}
135-
/// [google.cloud.ids.v1.GetEndpointRequest]:
136-
/// @googleapis_reference_link{google/cloud/ids/v1/ids.proto#L199}
137-
///
138-
StatusOr<google::cloud::ids::v1::Endpoint> GetEndpoint(
139-
std::string const& name, Options opts = {});
140-
141-
///
142-
/// Gets details of a single Endpoint.
143-
///
144-
/// @param request
145-
/// @googleapis_link{google::cloud::ids::v1::GetEndpointRequest,google/cloud/ids/v1/ids.proto#L199}
146-
/// @param opts Optional. Override the class-level options, such as retry and
147-
/// backoff policies.
148-
/// @return
149-
/// @googleapis_link{google::cloud::ids::v1::Endpoint,google/cloud/ids/v1/ids.proto#L81}
150-
///
151-
/// [google.cloud.ids.v1.Endpoint]:
152-
/// @googleapis_reference_link{google/cloud/ids/v1/ids.proto#L81}
153-
/// [google.cloud.ids.v1.GetEndpointRequest]:
154-
/// @googleapis_reference_link{google/cloud/ids/v1/ids.proto#L199}
155-
///
156-
StatusOr<google::cloud::ids::v1::Endpoint> GetEndpoint(
157-
google::cloud::ids::v1::GetEndpointRequest const& request,
158-
Options opts = {});
159-
160-
///
161-
/// Creates a new Endpoint in a given project and location.
162-
///
163-
/// @param parent Required. The endpoint's parent.
164-
/// @param endpoint Required. The endpoint to create.
165-
/// @param endpoint_id Required. The endpoint identifier. This will be part
166-
/// of the endpoint's
167-
/// resource name.
168-
/// This value must start with a lowercase letter followed by up to 62
169-
/// lowercase letters, numbers, or hyphens, and cannot end with a hyphen.
170-
/// Values that do not match this pattern will trigger an INVALID_ARGUMENT
171-
/// error.
172-
/// @param opts Optional. Override the class-level options, such as retry and
173-
/// backoff policies.
174-
/// @return
175-
/// @googleapis_link{google::cloud::ids::v1::Endpoint,google/cloud/ids/v1/ids.proto#L81}
176-
///
177-
/// [google.cloud.ids.v1.CreateEndpointRequest]:
178-
/// @googleapis_reference_link{google/cloud/ids/v1/ids.proto#L210}
179-
/// [google.cloud.ids.v1.Endpoint]:
180-
/// @googleapis_reference_link{google/cloud/ids/v1/ids.proto#L81}
181-
///
182-
future<StatusOr<google::cloud::ids::v1::Endpoint>> CreateEndpoint(
183-
std::string const& parent,
184-
google::cloud::ids::v1::Endpoint const& endpoint,
185-
std::string const& endpoint_id, Options opts = {});
186-
187-
///
188-
/// Creates a new Endpoint in a given project and location.
189-
///
190-
/// @param request
191-
/// @googleapis_link{google::cloud::ids::v1::CreateEndpointRequest,google/cloud/ids/v1/ids.proto#L210}
192-
/// @param opts Optional. Override the class-level options, such as retry and
193-
/// backoff policies.
194-
/// @return
195-
/// @googleapis_link{google::cloud::ids::v1::Endpoint,google/cloud/ids/v1/ids.proto#L81}
196-
///
197-
/// [google.cloud.ids.v1.CreateEndpointRequest]:
198-
/// @googleapis_reference_link{google/cloud/ids/v1/ids.proto#L210}
199-
/// [google.cloud.ids.v1.Endpoint]:
200-
/// @googleapis_reference_link{google/cloud/ids/v1/ids.proto#L81}
201-
///
202-
future<StatusOr<google::cloud::ids::v1::Endpoint>> CreateEndpoint(
203-
google::cloud::ids::v1::CreateEndpointRequest const& request,
204-
Options opts = {});
205-
206-
///
207-
/// Deletes a single Endpoint.
208-
///
209-
/// @param name Required. The name of the endpoint to delete.
210-
/// @param opts Optional. Override the class-level options, such as retry and
211-
/// backoff policies.
212-
/// @return
213-
/// @googleapis_link{google::cloud::ids::v1::OperationMetadata,google/cloud/ids/v1/ids.proto#L272}
214-
///
215-
/// [google.cloud.ids.v1.DeleteEndpointRequest]:
216-
/// @googleapis_reference_link{google/cloud/ids/v1/ids.proto#L246}
217-
/// [google.cloud.ids.v1.OperationMetadata]:
218-
/// @googleapis_reference_link{google/cloud/ids/v1/ids.proto#L272}
219-
///
220-
future<StatusOr<google::cloud::ids::v1::OperationMetadata>> DeleteEndpoint(
221-
std::string const& name, Options opts = {});
222-
223-
///
224-
/// Deletes a single Endpoint.
225-
///
226-
/// @param request
227-
/// @googleapis_link{google::cloud::ids::v1::DeleteEndpointRequest,google/cloud/ids/v1/ids.proto#L246}
228-
/// @param opts Optional. Override the class-level options, such as retry and
229-
/// backoff policies.
230-
/// @return
231-
/// @googleapis_link{google::cloud::ids::v1::OperationMetadata,google/cloud/ids/v1/ids.proto#L272}
232-
///
233-
/// [google.cloud.ids.v1.DeleteEndpointRequest]:
234-
/// @googleapis_reference_link{google/cloud/ids/v1/ids.proto#L246}
235-
/// [google.cloud.ids.v1.OperationMetadata]:
236-
/// @googleapis_reference_link{google/cloud/ids/v1/ids.proto#L272}
237-
///
238-
future<StatusOr<google::cloud::ids::v1::OperationMetadata>> DeleteEndpoint(
239-
google::cloud::ids::v1::DeleteEndpointRequest const& request,
240-
Options opts = {});
241-
242-
private:
243-
std::shared_ptr<IDSConnection> connection_;
244-
Options options_;
245-
};
30+
/// @deprecated Use ids_v1::IDSClient directly.
31+
using ::google::cloud::ids_v1::IDSClient;
24632

24733
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
24834
} // namespace ids

0 commit comments

Comments
 (0)