Skip to content

Commit

Permalink
refactor(iam): move iam_v2_policy_protos to a separate lib (#12413)
Browse files Browse the repository at this point in the history
  • Loading branch information
scotthart authored Aug 29, 2023
1 parent 09d5f05 commit 4d0271b
Show file tree
Hide file tree
Showing 15 changed files with 151 additions and 33 deletions.
1 change: 1 addition & 0 deletions ci/cloudbuild/builds/cmake-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ expected_dirs+=(
./lib64/cmake/google_cloud_cpp_googleapis
./lib64/cmake/google_cloud_cpp_grafeas
./lib64/cmake/google_cloud_cpp_grpc_utils
./lib64/cmake/google_cloud_cpp_iam_policy
./lib64/cmake/google_cloud_cpp_mocks
./lib64/cmake/google_cloud_cpp_oauth2
./lib64/cmake/google_cloud_cpp_opentelemetry
Expand Down
2 changes: 1 addition & 1 deletion ci/cloudbuild/builds/lib/features.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function features::libraries() {
function features::list_full() {
local feature_list
mapfile -t feature_list < <(features::libraries)
feature_list+=(experimental-opentelemetry experimental-storage-grpc grafeas)
feature_list+=(experimental-opentelemetry experimental-storage-grpc grafeas iam_policy)
printf "%s\n" "${feature_list[@]}" | sort -u
}

Expand Down
1 change: 1 addition & 0 deletions cmake/CompileProtos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ function (google_cloud_cpp_load_protodeps var file)
# such dependencies, but they do happen.
set(target_substitutions
"grafeas_v1_grafeas_protos\;grafeas_protos"
"iam_v2_policy_protos\;iam_policy_protos"
"identity_accesscontextmanager_v1_accesscontextmanager_protos\;accesscontextmanager_protos"
"cloud_osconfig_v1_osconfig_protos\;osconfig_protos"
"cloud_documentai_v1_documentai_protos\;documentai_protos")
Expand Down
8 changes: 7 additions & 1 deletion cmake/GoogleCloudCppFeatures.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,17 @@ function (google_cloud_cpp_enable_deps)
if (contentwarehouse IN_LIST enabled_features)
list(INSERT enabled_features 0 documentai)
endif ()
if (iam IN_LIST enabled_features)
list(INSERT enabled_features 0 iam_policy)
endif ()
if (policytroubleshooter IN_LIST enabled_features)
list(INSERT enabled_features 0 iam_policy)
endif ()
if (pubsublite IN_LIST enabled_features)
list(INSERT enabled_features 0 pubsub)
endif ()
if (pubsub IN_LIST enabled_features)
list(INSERT enabled_features 0 iam)
list(INSERT enabled_features 0 iam_policy iam)
endif ()
if (experimental-storage-grpc IN_LIST GOOGLE_CLOUD_CPP_ENABLE)
list(INSERT enabled_features 0 storage)
Expand Down
9 changes: 9 additions & 0 deletions external/googleapis/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ set(EXTERNAL_GOOGLEAPIS_PROTO_FILES
# does not appear in protolists/asset.list. In addition, it is not compiled
# by any other library. So, added manually.
"google/cloud/orgpolicy/v1/orgpolicy.proto"
"google/iam/v1/iam_policy.proto"
"google/iam/v1/options.proto"
"google/iam/v1/policy.proto"
"google/longrunning/operations.proto"
"google/rpc/code.proto"
"google/rpc/context/attribute_context.proto"
Expand Down Expand Up @@ -209,6 +212,9 @@ if (GOOGLE_CLOUD_CPP_USE_INSTALLED_COMMON)
return()
endif ()

# Avoid adding new proto libraries to this list as these libraries are always
# installed, regardless of whether or not they are needed. See #8022 for more
# details.
set(external_googleapis_installed_libraries_list
# cmake-format: sort
google_cloud_cpp_cloud_common_common_protos
Expand Down Expand Up @@ -238,6 +244,9 @@ set(PROTO_FILES_WITH_DEPENDENCIES
"google/api/quota.proto"
"google/api/service.proto"
"google/api/usage.proto"
"google/iam/v1/iam_policy.proto"
"google/iam/v1/options.proto"
"google/iam/v1/policy.proto"
"google/rpc/status.proto")

# For some directories *most* (but not all) the proto files are simple enough
Expand Down
2 changes: 0 additions & 2 deletions external/googleapis/protodeps/iam.deps
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
@com_google_googleapis//google/iam/v1:iam_policy_proto
@com_google_googleapis//google/iam/v1:options_proto
@com_google_googleapis//google/iam/v1:policy_proto
@com_google_googleapis//google/longrunning:operations_proto
@com_google_googleapis//google/rpc:status_proto
@com_google_googleapis//google/type:expr_proto
4 changes: 2 additions & 2 deletions external/googleapis/protodeps/iam_policy.deps
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
@com_google_googleapis//google/api:field_behavior_proto
@com_google_googleapis//google/api:http_proto
@com_google_googleapis//google/api:launch_stage_proto
@com_google_googleapis//google/api:resource_proto
@com_google_googleapis//google/iam/v1:policy_proto
@com_google_googleapis//google/longrunning:operations_proto
@com_google_googleapis//google/rpc:status_proto
@com_google_googleapis//google/type:expr_proto
2 changes: 0 additions & 2 deletions external/googleapis/protolists/iam.list
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@
@com_google_googleapis//google/iam/admin/v1:iam.proto
@com_google_googleapis//google/iam/credentials/v1:common.proto
@com_google_googleapis//google/iam/credentials/v1:iamcredentials.proto
@com_google_googleapis//google/iam/v2:deny.proto
@com_google_googleapis//google/iam/v2:policy.proto
6 changes: 2 additions & 4 deletions external/googleapis/protolists/iam_policy.list
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
@com_google_googleapis//google/iam/v1/logging:audit_data.proto
@com_google_googleapis//google/iam/v1:iam_policy.proto
@com_google_googleapis//google/iam/v1:options.proto
@com_google_googleapis//google/iam/v1:policy.proto
@com_google_googleapis//google/iam/v2:deny.proto
@com_google_googleapis//google/iam/v2:policy.proto
9 changes: 2 additions & 7 deletions external/googleapis/update_libraries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,13 @@ declare -A -r LIBRARIES=(
["iam"]="$(
printf ",%s" \
"@com_google_googleapis//google/iam/credentials/v1:credentials_cc_grpc" \
"@com_google_googleapis//google/iam/admin/v1:admin_cc_grpc" \
"@com_google_googleapis//google/iam/v2:iam_cc_grpc"

This comment has been minimized.

Copy link
@dbolduc

dbolduc Aug 30, 2023

Member

FWIW, I think this was a breaking change. (Of the same variety as we are making for #8022).

Customers who used to link against google_cloud_cpp_iam_protos without building our IAM client library no longer have the google::iam::v2::* symbols.

There is nothing that links google_cloud_cpp_iam_protos to the new google_cloud_cpp_iam_policy_protos.

"@com_google_googleapis//google/iam/admin/v1:admin_cc_grpc"
)"
# We already have libraries, different from `iam_protos` that compile
# the protos defined in the following entry. Thus, we cannot merge
# the following entry into the existing `iam` entry, that would
# introduce either ODR-violations, or break backwards compatibility.
["iam_policy"]="$(
printf ",%s" \
"@com_google_googleapis//google/iam/v1:iam_cc_grpc" \
"@com_google_googleapis//google/iam/v1/logging:logging_cc_grpc"
)"
["iam_policy"]="@com_google_googleapis//google/iam/v2:iam_cc_grpc"
["iap"]="@com_google_googleapis//google/cloud/iap/v1:iap_cc_grpc"
["ids"]="@com_google_googleapis//google/cloud/ids/v1:ids_cc_grpc"
["kms"]="$(
Expand Down
24 changes: 10 additions & 14 deletions google/cloud/iam/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ foreach (dir IN LISTS service_dirs)
endforeach ()

include(GoogleCloudCppDoxygen)
google_cloud_cpp_doxygen_targets("iam" DEPENDS cloud-docs
google-cloud-cpp::iam_protos)
set(GOOGLE_CLOUD_CPP_DOXYGEN_EXTRA_INCLUDES
"${PROJECT_BINARY_DIR}/google/cloud/iam_policy")
google_cloud_cpp_doxygen_targets(
"iam" DEPENDS cloud-docs google-cloud-cpp::iam_protos
google-cloud-cpp::iam_v1_policy_protos google-cloud-cpp::iam_policy_protos)

include(GoogleCloudCppCommon)

Expand All @@ -53,7 +56,8 @@ target_include_directories(
target_link_libraries(
google_cloud_cpp_iam
PUBLIC google-cloud-cpp::grpc_utils google-cloud-cpp::common
google-cloud-cpp::iam_protos google-cloud-cpp::iam_v1_policy_protos)
google-cloud-cpp::iam_protos google-cloud-cpp::iam_v1_policy_protos
google-cloud-cpp::iam_policy_protos)
google_cloud_cpp_add_common_options(google_cloud_cpp_iam)
set_target_properties(
google_cloud_cpp_iam
Expand Down Expand Up @@ -125,16 +129,7 @@ install(
COMPONENT google_cloud_cpp_runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT google_cloud_cpp_runtime
NAMELINK_SKIP
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT google_cloud_cpp_development)
# With CMake-3.12 and higher we could avoid this separate command (and the
# duplication).
install(
TARGETS google_cloud_cpp_iam
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT google_cloud_cpp_development
NAMELINK_ONLY
NAMELINK_COMPONENT google_cloud_cpp_runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT google_cloud_cpp_development)

Expand All @@ -149,7 +144,8 @@ google_cloud_cpp_add_pkgconfig(
"Provides C++ APIs to access Google Cloud IAM."
"google_cloud_cpp_grpc_utils"
"google_cloud_cpp_common"
"google_cloud_cpp_iam_protos")
"google_cloud_cpp_iam_protos"
"google_cloud_cpp_iam_policy_protos")

# Create and install the CMake configuration files.
include(CMakePackageConfigHelpers)
Expand Down
1 change: 1 addition & 0 deletions google/cloud/iam/config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

include(CMakeFindDependencyMacro)
# google_cloud_cpp_googleapis finds both gRPC and Protobuf, no need to load them here.
find_dependency(google_cloud_cpp_iam_policy)
find_dependency(google_cloud_cpp_googleapis)
find_dependency(google_cloud_cpp_common)
find_dependency(google_cloud_cpp_grpc_utils)
Expand Down
80 changes: 80 additions & 0 deletions google/cloud/iam_policy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# ~~~
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ~~~

include(GoogleapisConfig)

include(GoogleCloudCppCommon)

include(CompileProtos)
google_cloud_cpp_find_proto_include_dir(PROTO_INCLUDE_DIR)
google_cloud_cpp_load_protolist(
iam_policy_list
"${PROJECT_SOURCE_DIR}/external/googleapis/protolists/iam_policy.list")
google_cloud_cpp_load_protodeps(
iam_policy_deps
"${PROJECT_SOURCE_DIR}/external/googleapis/protodeps/iam_policy.deps")
google_cloud_cpp_grpcpp_library(
google_cloud_cpp_iam_policy_protos ${iam_policy_list}
PROTO_PATH_DIRECTORIES "${EXTERNAL_GOOGLEAPIS_SOURCE}"
"${PROTO_INCLUDE_DIR}")
external_googleapis_set_version_and_alias(iam_policy_protos)
target_link_libraries(google_cloud_cpp_iam_policy_protos
PUBLIC ${iam_policy_deps})

# Get the destination directories based on the GNU recommendations.
include(GNUInstallDirs)

# Export the CMake targets to make it easy to create configuration files.
install(
EXPORT google_cloud_cpp_iam_policy-targets
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_iam_policy"
COMPONENT google_cloud_cpp_development)

# Install the libraries and headers in the locations determined by
# GNUInstallDirs
install(
TARGETS google_cloud_cpp_iam_policy_protos
EXPORT google_cloud_cpp_iam_policy-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT google_cloud_cpp_runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT google_cloud_cpp_runtime
NAMELINK_COMPONENT google_cloud_cpp_runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT google_cloud_cpp_development)

google_cloud_cpp_install_proto_library_protos(
"google_cloud_cpp_iam_policy_protos" "${EXTERNAL_GOOGLEAPIS_SOURCE}")
google_cloud_cpp_install_proto_library_headers(
"google_cloud_cpp_iam_policy_protos")

# Create and install the CMake configuration files.
include(CMakePackageConfigHelpers)
configure_file("config.cmake.in" "google_cloud_cpp_iam_policy-config.cmake"
@ONLY)
write_basic_package_version_file(
"google_cloud_cpp_iam_policy-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY ExactVersion)

install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_iam_policy-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_iam_policy-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_iam_policy"
COMPONENT google_cloud_cpp_development)

external_googleapis_install_pc("google_cloud_cpp_iam_policy_protos")
13 changes: 13 additions & 0 deletions google/cloud/iam_policy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# IAM Policy Proto Libraries

Several Google Cloud Platform services use the IAM Policy APIs and protocol
buffer definitions. This directory contains CMake targets to generate the C++
libraries corresponding to this code. Customers are not expected to use these
libraries directly (though they might), instead we recommend using the idiomatic
C++ libraries for the GCP services.

Please note that the Google Cloud C++ client libraries do **not** follow
[Semantic Versioning](https://semver.org/).

For detailed instructions on how to build and install this library, see the
top-level [README](/README.md#building-and-installing).
22 changes: 22 additions & 0 deletions google/cloud/iam_policy/config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

include(CMakeFindDependencyMacro)
# google_cloud_cpp_googleapis finds both gRPC and Protobuf, no need to load them here.
find_dependency(google_cloud_cpp_googleapis)
find_dependency(google_cloud_cpp_common)
find_dependency(google_cloud_cpp_grpc_utils)
find_dependency(absl)

include("${CMAKE_CURRENT_LIST_DIR}/google_cloud_cpp_iam_policy-targets.cmake")

0 comments on commit 4d0271b

Please sign in to comment.