Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(oauth2): new library to create oauth2 tokens #12064

Merged
merged 6 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ cc_library(
],
)

cc_library(
name = "oauth2",
testonly = True,
deps = [
"//google/cloud/oauth2:google_cloud_cpp_oauth2",
],
)

cc_library(
name = "experimental-opentelemetry",
deps = [
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ if (GOOGLE_CLOUD_CPP_USE_INSTALLED_COMMON)
endif ()
if (GOOGLE_CLOUD_CPP_ENABLE_REST)
find_package(google_cloud_cpp_rest_internal CONFIG REQUIRED)
find_package(google_cloud_cpp_oauth2 CONFIG REQUIRED)
endif ()
if (GOOGLE_CLOUD_CPP_ENABLE_REST AND GOOGLE_CLOUD_CPP_ENABLE_GRPC)
find_package(google_cloud_cpp_rest_protobuf_internal CONFIG REQUIRED)
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions ci/cloudbuild/builds/check-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ if [ "${GOOGLE_CLOUD_CPP_CHECK_API:-}" ]; then
else
mapfile -t library_list < <(cmake -DCMAKE_MODULE_PATH="${PWD}/cmake" -P cmake/print-ga-libraries.cmake 2>&1)
# These libraries are not "features", but they are part of the public API
library_list+=("common" "grpc_utils")
library_list+=("common" "grpc_utils" "oauth2")
fi

# Uses `abi-dumper` to dump the ABI for the given library, which should
Expand All @@ -64,7 +64,7 @@ function check_abi() {
local shortlib="${library#google_cloud_cpp_}"
local public_headers="${prefix}/include/google/cloud/${shortlib}"
# These two are special
if [[ "${shortlib}" == "common" || "${shortlib}" == "grpc_utils" ]]; then
if [[ "${shortlib}" == "common" || "${shortlib}" == "grpc_utils" || "${shortlib}" == "oauth2" ]]; then
public_headers="${prefix}/include/google/cloud"
fi

Expand Down
1 change: 1 addition & 0 deletions ci/cloudbuild/builds/cmake-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ expected_dirs+=(
./lib64/cmake/google_cloud_cpp_grafeas
./lib64/cmake/google_cloud_cpp_grpc_utils
./lib64/cmake/google_cloud_cpp_mocks
./lib64/cmake/google_cloud_cpp_oauth2
./lib64/cmake/google_cloud_cpp_opentelemetry
./lib64/cmake/google_cloud_cpp_pubsub_mocks
./lib64/cmake/google_cloud_cpp_rest_internal
Expand Down
48 changes: 15 additions & 33 deletions google/cloud/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ package(default_visibility = ["//visibility:private"])
licenses(["notice"]) # Apache 2.0

load(":capture_build_info.bzl", "capture_build_info")
load(":google_cloud_cpp_common_benchmarks.bzl", "google_cloud_cpp_common_benchmarks")
load(":google_cloud_cpp_common_unit_tests.bzl", "google_cloud_cpp_common_unit_tests")
load(":google_cloud_cpp_common.bzl", "google_cloud_cpp_common_hdrs", "google_cloud_cpp_common_srcs")
load(":google_cloud_cpp_grpc_utils_benchmarks.bzl", "google_cloud_cpp_grpc_utils_benchmarks")
load(":google_cloud_cpp_grpc_utils_integration_tests.bzl", "google_cloud_cpp_grpc_utils_integration_tests")
load(":google_cloud_cpp_grpc_utils_unit_tests.bzl", "google_cloud_cpp_grpc_utils_unit_tests")
load(":google_cloud_cpp_grpc_utils.bzl", "google_cloud_cpp_grpc_utils_hdrs", "google_cloud_cpp_grpc_utils_srcs")
load(":google_cloud_cpp_mocks.bzl", "google_cloud_cpp_mocks_hdrs")
load(":google_cloud_cpp_rest_internal_benchmarks.bzl", "google_cloud_cpp_rest_internal_benchmarks")
load(":google_cloud_cpp_rest_internal_emulator_integration_tests.bzl", "google_cloud_cpp_rest_internal_emulator_integration_tests")
load(":google_cloud_cpp_rest_internal_production_integration_tests.bzl", "google_cloud_cpp_rest_internal_production_integration_tests")
load(":google_cloud_cpp_rest_internal_unit_tests.bzl", "google_cloud_cpp_rest_internal_unit_tests")
load(":google_cloud_cpp_rest_internal.bzl", "google_cloud_cpp_rest_internal_hdrs", "google_cloud_cpp_rest_internal_srcs")
load(":google_cloud_cpp_rest_protobuf_internal_unit_tests.bzl", "google_cloud_cpp_rest_protobuf_internal_unit_tests")
load(":google_cloud_cpp_rest_protobuf_internal.bzl", "google_cloud_cpp_rest_protobuf_internal_hdrs", "google_cloud_cpp_rest_protobuf_internal_srcs")

capture_build_info(
name = "generate_build_info",
Expand All @@ -42,8 +57,6 @@ config_setting(
},
)

load(":google_cloud_cpp_common.bzl", "google_cloud_cpp_common_hdrs", "google_cloud_cpp_common_srcs")

cc_library(
name = "google_cloud_cpp_common_private",
srcs = google_cloud_cpp_common_srcs + ["internal/build_info.cc"],
Expand Down Expand Up @@ -105,11 +118,6 @@ cc_library(
deps = [":google_cloud_cpp_common_private"],
)

load(
":google_cloud_cpp_common_unit_tests.bzl",
"google_cloud_cpp_common_unit_tests",
)

[cc_test(
name = test.replace("/", "_").replace(".cc", ""),
srcs = [test],
Expand All @@ -125,8 +133,6 @@ load(
],
) for test in google_cloud_cpp_common_unit_tests]

load(":google_cloud_cpp_common_benchmarks.bzl", "google_cloud_cpp_common_benchmarks")

[cc_test(
name = benchmark.replace("/", "_").replace(".cc", ""),
srcs = [benchmark],
Expand All @@ -137,8 +143,6 @@ load(":google_cloud_cpp_common_benchmarks.bzl", "google_cloud_cpp_common_benchma
],
) for benchmark in google_cloud_cpp_common_benchmarks]

load(":google_cloud_cpp_grpc_utils.bzl", "google_cloud_cpp_grpc_utils_hdrs", "google_cloud_cpp_grpc_utils_srcs")

cc_library(
name = "google_cloud_cpp_grpc_utils_private",
srcs = google_cloud_cpp_grpc_utils_srcs,
Expand Down Expand Up @@ -177,8 +181,6 @@ cc_library(
deps = [":google_cloud_cpp_grpc_utils_private"],
)

load(":google_cloud_cpp_grpc_utils_unit_tests.bzl", "google_cloud_cpp_grpc_utils_unit_tests")

[cc_test(
name = test.replace("/", "_").replace(".cc", ""),
srcs = [test],
Expand All @@ -194,8 +196,6 @@ load(":google_cloud_cpp_grpc_utils_unit_tests.bzl", "google_cloud_cpp_grpc_utils
],
) for test in google_cloud_cpp_grpc_utils_unit_tests]

load(":google_cloud_cpp_grpc_utils_integration_tests.bzl", "google_cloud_cpp_grpc_utils_integration_tests")

[cc_test(
name = test.replace("/", "_").replace(".cc", ""),
srcs = [test],
Expand All @@ -214,8 +214,6 @@ load(":google_cloud_cpp_grpc_utils_integration_tests.bzl", "google_cloud_cpp_grp
],
) for test in google_cloud_cpp_grpc_utils_integration_tests]

load(":google_cloud_cpp_grpc_utils_benchmarks.bzl", "google_cloud_cpp_grpc_utils_benchmarks")

[cc_binary(
name = test.replace("/", "_").replace(".cc", ""),
srcs = [test],
Expand All @@ -229,8 +227,6 @@ load(":google_cloud_cpp_grpc_utils_benchmarks.bzl", "google_cloud_cpp_grpc_utils
],
) for test in google_cloud_cpp_grpc_utils_benchmarks]

load(":google_cloud_cpp_mocks.bzl", "google_cloud_cpp_mocks_hdrs")

cc_library(
name = "google_cloud_cpp_mocks",
testonly = True,
Expand All @@ -245,8 +241,6 @@ cc_library(
],
)

load(":google_cloud_cpp_rest_internal.bzl", "google_cloud_cpp_rest_internal_hdrs", "google_cloud_cpp_rest_internal_srcs")

cc_library(
name = "google_cloud_cpp_rest_internal",
srcs = google_cloud_cpp_rest_internal_srcs,
Expand All @@ -271,8 +265,6 @@ cc_library(
],
)

load(":google_cloud_cpp_rest_internal_unit_tests.bzl", "google_cloud_cpp_rest_internal_unit_tests")

[cc_test(
name = test.replace("/", "_").replace(".cc", ""),
srcs = [test],
Expand All @@ -284,8 +276,6 @@ load(":google_cloud_cpp_rest_internal_unit_tests.bzl", "google_cloud_cpp_rest_in
],
) for test in google_cloud_cpp_rest_internal_unit_tests]

load(":google_cloud_cpp_rest_internal_emulator_integration_tests.bzl", "google_cloud_cpp_rest_internal_emulator_integration_tests")

[cc_test(
name = test.replace("/", "_").replace(".cc", ""),
srcs = [test],
Expand All @@ -299,8 +289,6 @@ load(":google_cloud_cpp_rest_internal_emulator_integration_tests.bzl", "google_c
],
) for test in google_cloud_cpp_rest_internal_emulator_integration_tests]

load(":google_cloud_cpp_rest_internal_production_integration_tests.bzl", "google_cloud_cpp_rest_internal_production_integration_tests")

[cc_test(
name = test.replace("/", "_").replace(".cc", ""),
srcs = [test],
Expand All @@ -314,8 +302,6 @@ load(":google_cloud_cpp_rest_internal_production_integration_tests.bzl", "google
],
) for test in google_cloud_cpp_rest_internal_production_integration_tests]

load(":google_cloud_cpp_rest_internal_benchmarks.bzl", "google_cloud_cpp_rest_internal_benchmarks")

[cc_binary(
name = benchmark.replace("/", "_").replace(".cc", ""),
srcs = [benchmark],
Expand All @@ -326,8 +312,6 @@ load(":google_cloud_cpp_rest_internal_benchmarks.bzl", "google_cloud_cpp_rest_in
],
) for benchmark in google_cloud_cpp_rest_internal_benchmarks]

load(":google_cloud_cpp_rest_protobuf_internal.bzl", "google_cloud_cpp_rest_protobuf_internal_hdrs", "google_cloud_cpp_rest_protobuf_internal_srcs")

cc_library(
name = "google_cloud_cpp_rest_protobuf_internal",
srcs = google_cloud_cpp_rest_protobuf_internal_srcs,
Expand All @@ -340,8 +324,6 @@ cc_library(
],
)

load(":google_cloud_cpp_rest_protobuf_internal_unit_tests.bzl", "google_cloud_cpp_rest_protobuf_internal_unit_tests")

[cc_test(
name = test.replace("/", "_").replace(".cc", ""),
srcs = [test],
Expand Down
1 change: 1 addition & 0 deletions google/cloud/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ endif ()

if (GOOGLE_CLOUD_CPP_ENABLE_REST)
include("${CMAKE_CURRENT_SOURCE_DIR}/google_cloud_cpp_rest_internal.cmake")
add_subdirectory(oauth2)
endif ()

if (GOOGLE_CLOUD_CPP_ENABLE_REST AND GOOGLE_CLOUD_CPP_ENABLE_GRPC)
Expand Down
42 changes: 42 additions & 0 deletions google/cloud/oauth2/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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.

package(default_visibility = ["//visibility:private"])

licenses(["notice"]) # Apache 2.0

load(":google_cloud_cpp_oauth2_unit_tests.bzl", "google_cloud_cpp_oauth2_unit_tests")
load(":google_cloud_cpp_oauth2.bzl", "google_cloud_cpp_oauth2_hdrs", "google_cloud_cpp_oauth2_srcs")

cc_library(
name = "google_cloud_cpp_oauth2",
srcs = google_cloud_cpp_oauth2_srcs,
hdrs = google_cloud_cpp_oauth2_hdrs,
visibility = ["//:__subpackages__"],
deps = [
"//:common",
"//google/cloud:google_cloud_cpp_rest_internal",
],
)

[cc_test(
name = test.replace("/", "_").replace(".cc", ""),
srcs = [test],
deps = [
":google_cloud_cpp_oauth2",
"//google/cloud/testing_util:google_cloud_cpp_testing_private",
"//google/cloud/testing_util:google_cloud_cpp_testing_rest_private",
"@com_google_googletest//:gtest_main",
],
) for test in google_cloud_cpp_oauth2_unit_tests]
110 changes: 110 additions & 0 deletions google/cloud/oauth2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# ~~~
# Copyright 2022 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(GoogleCloudCppCommon)
set(DOXYGEN_PROJECT_NAME "OAuth2 Access Token Generation Library")
set(DOXYGEN_PROJECT_BRIEF
"Create OAuth2 Access Tokens for any GCP authentication mechanism")
set(DOXYGEN_PROJECT_NUMBER "${PROJECT_VERSION}")
set(DOXYGEN_EXCLUDE_SYMBOLS "internal")

add_library(google_cloud_cpp_oauth2 # cmake-format: sort
access_token_generator.cc access_token_generator.h)
target_link_libraries(
google_cloud_cpp_oauth2 PUBLIC google-cloud-cpp::rest_internal
google-cloud-cpp::common)
google_cloud_cpp_add_common_options(google_cloud_cpp_oauth2)
target_include_directories(
google_cloud_cpp_oauth2 PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>)
target_compile_options(google_cloud_cpp_oauth2
PUBLIC ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG})
set_target_properties(
google_cloud_cpp_oauth2
PROPERTIES EXPORT_NAME "google-cloud-cpp::oauth2"
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR})
add_library(google-cloud-cpp::oauth2 ALIAS google_cloud_cpp_oauth2)

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

# Install the libraries and headers in the locations determined by
# GNUInstallDirs
install(
TARGETS google_cloud_cpp_oauth2
EXPORT google_cloud_cpp_oauth2-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_development
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT google_cloud_cpp_development)

google_cloud_cpp_install_headers(google_cloud_cpp_oauth2 include/google/cloud)

google_cloud_cpp_add_pkgconfig(
oauth2 "${DOXYGEN_PROJECT_NAME}" "${DOXYGEN_PROJECT_BRIEF}"
"google_cloud_cpp_rest_internal" "google_cloud_cpp_common")

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

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

create_bazel_config(google_cloud_cpp_oauth2 YEAR 2023)

set(google_cloud_cpp_oauth2_unit_tests # cmake-format: sort
access_token_generator_test.cc)

export_list_to_bazel("google_cloud_cpp_oauth2_unit_tests.bzl"
"google_cloud_cpp_oauth2_unit_tests" YEAR 2023)

if (NOT BUILD_TESTING)
return()
endif ()

foreach (fname IN LISTS google_cloud_cpp_oauth2_unit_tests)
google_cloud_cpp_add_executable(target "oauth2" "${fname}")
target_link_libraries(
${target}
PRIVATE google-cloud-cpp::oauth2
google_cloud_cpp_testing
google_cloud_cpp_testing_rest
google-cloud-cpp::common
GTest::gmock_main
GTest::gmock
GTest::gtest)
google_cloud_cpp_add_common_options(${target})
if (MSVC)
target_compile_options(${target} PRIVATE "/bigobj")
endif ()
add_test(NAME ${target} COMMAND ${target})
endforeach ()
Loading
Loading