Skip to content

Commit 4be20c2

Browse files
authored
cleanup(orgpolicy): split from resource manager (#8043)
1 parent 16c01f6 commit 4be20c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1004
-154
lines changed

BUILD.bazel

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,20 @@ cc_library(
362362
],
363363
)
364364

365+
cc_library(
366+
name = "experimental-orgpolicy",
367+
deps = [
368+
"//google/cloud/orgpolicy:google_cloud_cpp_orgpolicy",
369+
],
370+
)
371+
372+
cc_library(
373+
name = "experimental-orgpolicy_mocks",
374+
deps = [
375+
"//google/cloud/orgpolicy:google_cloud_cpp_orgpolicy_mocks",
376+
],
377+
)
378+
365379
cc_library(
366380
name = "experimental-oslogin",
367381
deps = [

ci/etc/expected_install_directories

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@
102102
./include/google/cloud/orchestration/airflow/service
103103
./include/google/cloud/orchestration/airflow/service/v1
104104
./include/google/cloud/orgpolicy
105+
./include/google/cloud/orgpolicy/internal
106+
./include/google/cloud/orgpolicy/mocks
105107
./include/google/cloud/orgpolicy/v2
106108
./include/google/cloud/oslogin
107109
./include/google/cloud/oslogin/internal
@@ -255,6 +257,7 @@
255257
./lib64/cmake/google_cloud_cpp_kms
256258
./lib64/cmake/google_cloud_cpp_logging
257259
./lib64/cmake/google_cloud_cpp_notebooks
260+
./lib64/cmake/google_cloud_cpp_orgpolicy
258261
./lib64/cmake/google_cloud_cpp_oslogin
259262
./lib64/cmake/google_cloud_cpp_policytroubleshooter
260263
./lib64/cmake/google_cloud_cpp_privateca

ci/etc/full_feature_list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ iot
2020
kms
2121
logging
2222
notebooks
23+
orgpolicy
2324
oslogin
2425
policytroubleshooter
2526
privateca
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@com_google_googleapis//google/api:annotations_proto
2+
@com_google_googleapis//google/api:client_proto
3+
@com_google_googleapis//google/api:field_behavior_proto
4+
@com_google_googleapis//google/api:http_proto
5+
@com_google_googleapis//google/api:resource_proto
6+
@com_google_googleapis//google/type:expr_proto
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@com_google_googleapis//google/cloud/orgpolicy/v2:constraint.proto
2+
@com_google_googleapis//google/cloud/orgpolicy/v2:orgpolicy.proto

external/googleapis/protolists/resourcemanager.list

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
@com_google_googleapis//google/cloud/orgpolicy/v2:constraint.proto
2-
@com_google_googleapis//google/cloud/orgpolicy/v2:orgpolicy.proto
31
@com_google_googleapis//google/cloud/resourcemanager/v3:folders.proto
42
@com_google_googleapis//google/cloud/resourcemanager/v3:organizations.proto
53
@com_google_googleapis//google/cloud/resourcemanager/v3:projects.proto

external/googleapis/update_libraries.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ declare -A -r LIBRARIES=(
8484
["logging"]="@com_google_googleapis//google/logging/v2:logging_cc_grpc"
8585
["monitoring"]="@com_google_googleapis//google/monitoring/v3:monitoring_cc_grpc"
8686
["notebooks"]="@com_google_googleapis//google/cloud/notebooks/v1:notebooks_cc_grpc"
87+
["orgpolicy"]="@com_google_googleapis//google/cloud/orgpolicy/v2:orgpolicy_cc_grpc"
8788
["oslogin"]="$(
8889
printf ",%s" \
8990
"@com_google_googleapis//google/cloud/oslogin/v1:oslogin_cc_grpc" \
@@ -98,11 +99,7 @@ declare -A -r LIBRARIES=(
9899
"@com_google_googleapis//google/cloud/recommender/v1:recommender_cc_grpc" \
99100
"@com_google_googleapis//google/cloud/recommender/logging/v1:logging_cc_grpc"
100101
)"
101-
["resourcemanager"]="$(
102-
printf ",%s" \
103-
"@com_google_googleapis//google/cloud/orgpolicy/v2:orgpolicy_cc_grpc" \
104-
"@com_google_googleapis//google/cloud/resourcemanager/v3:resourcemanager_cc_grpc"
105-
)"
102+
["resourcemanager"]="@com_google_googleapis//google/cloud/resourcemanager/v3:resourcemanager_cc_grpc"
106103
["retail"]="@com_google_googleapis//google/cloud/retail/v2:retail_cc_grpc"
107104
["scheduler"]="@com_google_googleapis//google/cloud/scheduler/v1:scheduler_cc_grpc"
108105
["secretmanager"]="$(

generator/generator_config.textproto

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,14 @@ service {
298298
retryable_status_codes: ["kUnavailable"]
299299
}
300300

301+
# Organization Policy
302+
service {
303+
service_proto_path: "google/cloud/orgpolicy/v2/orgpolicy.proto"
304+
product_path: "google/cloud/orgpolicy"
305+
initial_copyright_year: "2022"
306+
retryable_status_codes: ["kDeadlineExceeded", "kUnavailable"]
307+
}
308+
301309
# OS Login
302310
service {
303311
service_proto_path: "google/cloud/oslogin/v1/oslogin.proto"
@@ -361,15 +369,6 @@ service {
361369
retryable_status_codes: ["kUnavailable"]
362370
}
363371

364-
service {
365-
# This service is very closely related to `Resource Manager`, in fact, both are
366-
# documented under the same product https://cloud.google.com/resource-manager
367-
service_proto_path: "google/cloud/orgpolicy/v2/orgpolicy.proto"
368-
product_path: "google/cloud/resourcemanager"
369-
initial_copyright_year: "2022"
370-
retryable_status_codes: ["kDeadlineExceeded", "kUnavailable"]
371-
}
372-
373372
service {
374373
service_proto_path: "google/cloud/resourcemanager/v3/organizations.proto"
375374
product_path: "google/cloud/resourcemanager"

google/cloud/orgpolicy/BUILD.bazel

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
package(default_visibility = ["//visibility:private"])
16+
17+
licenses(["notice"]) # Apache 2.0
18+
19+
SOURCE_GLOB = "**/*.cc"
20+
21+
MOCK_SOURCE_GLOB = "mocks/*.cc"
22+
23+
HEADER_GLOB = "**/*.h"
24+
25+
MOCK_HEADER_GLOB = "mocks/*.h"
26+
27+
cc_library(
28+
name = "google_cloud_cpp_orgpolicy",
29+
srcs = glob(
30+
include = [SOURCE_GLOB],
31+
exclude = [MOCK_SOURCE_GLOB],
32+
),
33+
hdrs = glob(
34+
include = [HEADER_GLOB],
35+
exclude = [MOCK_HEADER_GLOB],
36+
),
37+
visibility = ["//:__pkg__"],
38+
deps = [
39+
"//google/cloud:google_cloud_cpp_common",
40+
"//google/cloud:google_cloud_cpp_grpc_utils",
41+
"@com_google_googleapis//google/cloud/orgpolicy/v2:orgpolicy_cc_grpc",
42+
],
43+
)
44+
45+
cc_library(
46+
name = "google_cloud_cpp_orgpolicy_mocks",
47+
srcs = glob(
48+
include = [MOCK_SOURCE_GLOB],
49+
),
50+
hdrs = glob(
51+
include = [MOCK_HEADER_GLOB],
52+
),
53+
visibility = ["//:__pkg__"],
54+
deps = [
55+
":google_cloud_cpp_orgpolicy",
56+
"//google/cloud:google_cloud_cpp_common",
57+
"//google/cloud:google_cloud_cpp_grpc_utils",
58+
],
59+
)
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
# ~~~
2+
# Copyright 2022 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ~~~
16+
17+
include(GoogleapisConfig)
18+
set(DOXYGEN_PROJECT_NAME "Organization Policy API C++ Client")
19+
set(DOXYGEN_PROJECT_BRIEF
20+
"A C++ Client Library for the Organization Policy API")
21+
set(DOXYGEN_PROJECT_NUMBER "${PROJECT_VERSION} (Experimental)")
22+
set(DOXYGEN_EXCLUDE_SYMBOLS "internal" "orgpolicy_internal" "orgpolicy_testing"
23+
"examples")
24+
set(DOXYGEN_EXAMPLE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/quickstart)
25+
26+
# Creates the proto headers needed by doxygen.
27+
set(GOOGLE_CLOUD_CPP_DOXYGEN_DEPS google-cloud-cpp::orgpolicy_protos)
28+
29+
find_package(gRPC REQUIRED)
30+
find_package(ProtobufWithTargets REQUIRED)
31+
find_package(absl CONFIG REQUIRED)
32+
33+
include(GoogleCloudCppCommon)
34+
35+
set(EXTERNAL_GOOGLEAPIS_SOURCE
36+
"${PROJECT_BINARY_DIR}/external/googleapis/src/googleapis_download")
37+
find_path(PROTO_INCLUDE_DIR google/protobuf/descriptor.proto)
38+
if (PROTO_INCLUDE_DIR)
39+
list(INSERT PROTOBUF_IMPORT_DIRS 0 "${PROTO_INCLUDE_DIR}")
40+
endif ()
41+
42+
include(CompileProtos)
43+
google_cloud_cpp_grpcpp_library(
44+
google_cloud_cpp_orgpolicy_protos
45+
# cmake-format: sort
46+
${EXTERNAL_GOOGLEAPIS_SOURCE}/google/cloud/orgpolicy/v2/constraint.proto
47+
${EXTERNAL_GOOGLEAPIS_SOURCE}/google/cloud/orgpolicy/v2/orgpolicy.proto
48+
PROTO_PATH_DIRECTORIES
49+
"${EXTERNAL_GOOGLEAPIS_SOURCE}"
50+
"${PROTO_INCLUDE_DIR}")
51+
external_googleapis_set_version_and_alias(orgpolicy_protos)
52+
target_link_libraries(
53+
google_cloud_cpp_orgpolicy_protos
54+
PUBLIC #
55+
google-cloud-cpp::api_annotations_protos
56+
google-cloud-cpp::api_client_protos
57+
google-cloud-cpp::api_field_behavior_protos
58+
google-cloud-cpp::api_http_protos
59+
google-cloud-cpp::api_resource_protos
60+
google-cloud-cpp::type_expr_protos)
61+
62+
file(
63+
GLOB source_files
64+
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
65+
"*.h" "*.cc" "internal/*.h" "internal/*.cc")
66+
list(SORT source_files)
67+
add_library(google_cloud_cpp_orgpolicy ${source_files})
68+
target_include_directories(
69+
google_cloud_cpp_orgpolicy
70+
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
71+
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
72+
$<INSTALL_INTERFACE:include>)
73+
target_link_libraries(
74+
google_cloud_cpp_orgpolicy
75+
PUBLIC google-cloud-cpp::grpc_utils google-cloud-cpp::common
76+
google-cloud-cpp::orgpolicy_protos)
77+
google_cloud_cpp_add_common_options(google_cloud_cpp_orgpolicy)
78+
set_target_properties(
79+
google_cloud_cpp_orgpolicy
80+
PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-orgpolicy
81+
VERSION "${PROJECT_VERSION}" SOVERSION
82+
"${PROJECT_VERSION_MAJOR}")
83+
target_compile_options(google_cloud_cpp_orgpolicy
84+
PUBLIC ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG})
85+
86+
add_library(google-cloud-cpp::experimental-orgpolicy ALIAS
87+
google_cloud_cpp_orgpolicy)
88+
89+
# Create a header-only library for the mocks. We use a CMake `INTERFACE` library
90+
# for these, a regular library would not work on macOS (where the library needs
91+
# at least one .o file). Unfortunately INTERFACE libraries are a bit weird in
92+
# that they need absolute paths for their sources.
93+
file(
94+
GLOB relative_mock_files
95+
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
96+
"mocks/*.h")
97+
list(SORT relative_mock_files)
98+
set(mock_files)
99+
foreach (file IN LISTS relative_mock_files)
100+
list(APPEND mock_files "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
101+
endforeach ()
102+
add_library(google_cloud_cpp_orgpolicy_mocks INTERFACE)
103+
target_sources(google_cloud_cpp_orgpolicy_mocks INTERFACE ${mock_files})
104+
target_link_libraries(
105+
google_cloud_cpp_orgpolicy_mocks
106+
INTERFACE google-cloud-cpp::experimental-orgpolicy GTest::gmock_main
107+
GTest::gmock GTest::gtest)
108+
set_target_properties(
109+
google_cloud_cpp_orgpolicy_mocks
110+
PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-orgpolicy_mocks)
111+
target_include_directories(
112+
google_cloud_cpp_orgpolicy_mocks
113+
INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
114+
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
115+
$<INSTALL_INTERFACE:include>)
116+
target_compile_options(google_cloud_cpp_orgpolicy_mocks
117+
INTERFACE ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG})
118+
119+
# Get the destination directories based on the GNU recommendations.
120+
include(GNUInstallDirs)
121+
122+
# Export the CMake targets to make it easy to create configuration files.
123+
install(
124+
EXPORT google_cloud_cpp_orgpolicy-targets
125+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_orgpolicy"
126+
COMPONENT google_cloud_cpp_development)
127+
128+
# Install the libraries and headers in the locations determined by
129+
# GNUInstallDirs
130+
install(
131+
TARGETS google_cloud_cpp_orgpolicy google_cloud_cpp_orgpolicy_protos
132+
EXPORT google_cloud_cpp_orgpolicy-targets
133+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
134+
COMPONENT google_cloud_cpp_runtime
135+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
136+
COMPONENT google_cloud_cpp_runtime
137+
NAMELINK_SKIP
138+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
139+
COMPONENT google_cloud_cpp_development)
140+
# With CMake-3.12 and higher we could avoid this separate command (and the
141+
# duplication).
142+
install(
143+
TARGETS google_cloud_cpp_orgpolicy google_cloud_cpp_orgpolicy_protos
144+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
145+
COMPONENT google_cloud_cpp_development
146+
NAMELINK_ONLY
147+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
148+
COMPONENT google_cloud_cpp_development)
149+
150+
google_cloud_cpp_install_proto_library_protos(
151+
"google_cloud_cpp_orgpolicy_protos" "${EXTERNAL_GOOGLEAPIS_SOURCE}")
152+
google_cloud_cpp_install_proto_library_headers(
153+
"google_cloud_cpp_orgpolicy_protos")
154+
google_cloud_cpp_install_headers("google_cloud_cpp_orgpolicy"
155+
"include/google/cloud/orgpolicy")
156+
google_cloud_cpp_install_headers("google_cloud_cpp_orgpolicy_mocks"
157+
"include/google/cloud/orgpolicy")
158+
159+
# Setup global variables used in the following *.in files.
160+
set(GOOGLE_CLOUD_CONFIG_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
161+
set(GOOGLE_CLOUD_CONFIG_VERSION_MINOR ${PROJECT_VERSION_MINOR})
162+
set(GOOGLE_CLOUD_CONFIG_VERSION_PATCH ${PROJECT_VERSION_PATCH})
163+
set(GOOGLE_CLOUD_PC_NAME "The Organization Policy API C++ Client Library")
164+
set(GOOGLE_CLOUD_PC_DESCRIPTION
165+
"Provides C++ APIs to use the Organization Policy API.")
166+
set(GOOGLE_CLOUD_PC_LIBS "-lgoogle_cloud_cpp_orgpolicy")
167+
string(CONCAT GOOGLE_CLOUD_PC_REQUIRES "google_cloud_cpp_grpc_utils"
168+
" google_cloud_cpp_common" " google_cloud_cpp_orgpolicy_protos")
169+
170+
# Create and install the pkg-config files.
171+
configure_file("${PROJECT_SOURCE_DIR}/google/cloud/orgpolicy/config.pc.in"
172+
"google_cloud_cpp_orgpolicy.pc" @ONLY)
173+
install(
174+
FILES "${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_orgpolicy.pc"
175+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
176+
COMPONENT google_cloud_cpp_development)
177+
178+
# Create and install the CMake configuration files.
179+
include(CMakePackageConfigHelpers)
180+
configure_file("config.cmake.in" "google_cloud_cpp_orgpolicy-config.cmake"
181+
@ONLY)
182+
write_basic_package_version_file(
183+
"google_cloud_cpp_orgpolicy-config-version.cmake"
184+
VERSION ${PROJECT_VERSION}
185+
COMPATIBILITY ExactVersion)
186+
187+
install(
188+
FILES
189+
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_orgpolicy-config.cmake"
190+
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_orgpolicy-config-version.cmake"
191+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_orgpolicy"
192+
COMPONENT google_cloud_cpp_development)
193+
194+
external_googleapis_install_pc("google_cloud_cpp_orgpolicy_protos"
195+
"${PROJECT_SOURCE_DIR}/external/googleapis")

0 commit comments

Comments
 (0)