diff --git a/.librarian/generator-input/client-post-processing/sub-api-versioned-namespace.yaml b/.librarian/generator-input/client-post-processing/sub-api-versioned-namespace.yaml index a3ff95bb77b6..8abb48f3e752 100644 --- a/.librarian/generator-input/client-post-processing/sub-api-versioned-namespace.yaml +++ b/.librarian/generator-input/client-post-processing/sub-api-versioned-namespace.yaml @@ -50,22 +50,6 @@ replacements: before: configmanagement_pb2 after: configmanagement_v1 count: 4 - - paths: [ - packages/google-cloud-gke-hub/google/cloud/gkehub_v1/configmanagement_v1/__init__.py - ] - before: | - from google.cloud.gkehub.configmanagement_v1 import gapic_version as package_version - after: | - from google.cloud.gkehub_v1 import gapic_version as package_version - count: 1 - - paths: [ - packages/google-cloud-gke-hub/google/cloud/gkehub_v1/multiclusteringress_v1/__init__.py - ] - before: | - from google.cloud.gkehub.multiclusteringress_v1 import gapic_version as package_version - after: | - from google.cloud.gkehub_v1 import gapic_version as package_version - count: 1 - paths: [ packages/google-cloud-gke-hub/docs/index.rst ] diff --git a/.librarian/state.yaml b/.librarian/state.yaml index 8de8a1c704a8..ac082f2b2136 100644 --- a/.librarian/state.yaml +++ b/.librarian/state.yaml @@ -4367,6 +4367,29 @@ libraries: remove_regex: - packages/google-cloud-biglake tag_format: '{id}-v{version}' + - id: google-cloud-gke-hub + version: 1.19.0 + last_generated_commit: d300b151a973ce0425ae4ad07b3de957ca31bec6 + apis: + - path: google/cloud/gkehub/v1 + - path: google/cloud/gkehub/v1beta1 + source_roots: + - packages/google-cloud-gke-hub + preserve_regex: + - packages/google-cloud-gke-hub/CHANGELOG.md + - docs/CHANGELOG.md + - docs/README.rst + - samples/README.txt + - scripts/client-post-processing + - samples/snippets/README.rst + - tests/system + - docs/gkehub_v1/configmanagement_v1 + - docs/gkehub_v1/multiclusteringress_v1 + - google/cloud/gkehub_v1/configmanagement_v1 + - google/cloud/gkehub_v1/multiclusteringress_v1 + remove_regex: + - packages/google-cloud-gke-hub + tag_format: '{id}-v{version}' - id: google-cloud-monitoring-dashboards version: 2.19.0 last_generated_commit: d300b151a973ce0425ae4ad07b3de957ca31bec6 diff --git a/packages/google-cloud-gke-hub/.OwlBot.yaml b/packages/google-cloud-gke-hub/.OwlBot.yaml deleted file mode 100644 index b0ff7877d3f6..000000000000 --- a/packages/google-cloud-gke-hub/.OwlBot.yaml +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright 2021 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 -# -# http://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. - - -deep-remove-regex: - - /owl-bot-staging - -deep-preserve-regex: - - /owl-bot-staging/google-cloud-gke-hub/v1alpha - - /owl-bot-staging/google-cloud-gke-hub/v1alpha2 - - /owl-bot-staging/google-cloud-gke-hub/v1beta/ - -deep-copy-regex: - - source: /google/cloud/gkehub/(v1)/gkehub-v1-py - dest: /owl-bot-staging/google-cloud-gke-hub/$1 - - source: /google/cloud/gkehub/(v1beta1)/gkehub-v1beta1-py - dest: /owl-bot-staging/google-cloud-gke-hub/$1 - - source: /google/cloud/gkehub/v1/multiclusteringress/multiclusteringress-v1-py/google/cloud/gkehub/(multiclusteringress_v1) - dest: /owl-bot-staging/google-cloud-gke-hub/v1/google/cloud/gkehub_v1/$1 - - source: /google/cloud/gkehub/v1/configmanagement/configmanagement-v1-py/google/cloud/gkehub/(configmanagement_v1) - dest: /owl-bot-staging/google-cloud-gke-hub/v1/google/cloud/gkehub_v1/$1 - -begin-after-commit-hash: 6a5da3f1274b088752f074da5bc9e30bd1beb27e - -api-name: google-cloud-gke-hub diff --git a/packages/google-cloud-gke-hub/scripts/fixup_configmanagement_v1_keywords.py b/packages/google-cloud-gke-hub/scripts/fixup_configmanagement_v1_keywords.py deleted file mode 100644 index 89ca15d7a5a1..000000000000 --- a/packages/google-cloud-gke-hub/scripts/fixup_configmanagement_v1_keywords.py +++ /dev/null @@ -1,175 +0,0 @@ -#! /usr/bin/env python3 -# -*- coding: utf-8 -*- -# 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 -# -# http://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. -# -import argparse -import os -import libcst as cst -import pathlib -import sys -from typing import (Any, Callable, Dict, List, Sequence, Tuple) - - -def partition( - predicate: Callable[[Any], bool], - iterator: Sequence[Any] -) -> Tuple[List[Any], List[Any]]: - """A stable, out-of-place partition.""" - results = ([], []) - - for i in iterator: - results[int(predicate(i))].append(i) - - # Returns trueList, falseList - return results[1], results[0] - - -class configmanagementCallTransformer(cst.CSTTransformer): - CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') - METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - } - - def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: - try: - key = original.func.attr.value - kword_params = self.METHOD_TO_PARAMS[key] - except (AttributeError, KeyError): - # Either not a method from the API or too convoluted to be sure. - return updated - - # If the existing code is valid, keyword args come after positional args. - # Therefore, all positional args must map to the first parameters. - args, kwargs = partition(lambda a: not bool(a.keyword), updated.args) - if any(k.keyword.value == "request" for k in kwargs): - # We've already fixed this file, don't fix it again. - return updated - - kwargs, ctrl_kwargs = partition( - lambda a: a.keyword.value not in self.CTRL_PARAMS, - kwargs - ) - - args, ctrl_args = args[:len(kword_params)], args[len(kword_params):] - ctrl_kwargs.extend(cst.Arg(value=a.value, keyword=cst.Name(value=ctrl)) - for a, ctrl in zip(ctrl_args, self.CTRL_PARAMS)) - - request_arg = cst.Arg( - value=cst.Dict([ - cst.DictElement( - cst.SimpleString("'{}'".format(name)), -cst.Element(value=arg.value) - ) - # Note: the args + kwargs looks silly, but keep in mind that - # the control parameters had to be stripped out, and that - # those could have been passed positionally or by keyword. - for name, arg in zip(kword_params, args + kwargs)]), - keyword=cst.Name("request") - ) - - return updated.with_changes( - args=[request_arg] + ctrl_kwargs - ) - - -def fix_files( - in_dir: pathlib.Path, - out_dir: pathlib.Path, - *, - transformer=configmanagementCallTransformer(), -): - """Duplicate the input dir to the output dir, fixing file method calls. - - Preconditions: - * in_dir is a real directory - * out_dir is a real, empty directory - """ - pyfile_gen = ( - pathlib.Path(os.path.join(root, f)) - for root, _, files in os.walk(in_dir) - for f in files if os.path.splitext(f)[1] == ".py" - ) - - for fpath in pyfile_gen: - with open(fpath, 'r') as f: - src = f.read() - - # Parse the code and insert method call fixes. - tree = cst.parse_module(src) - updated = tree.visit(transformer) - - # Create the path and directory structure for the new file. - updated_path = out_dir.joinpath(fpath.relative_to(in_dir)) - updated_path.parent.mkdir(parents=True, exist_ok=True) - - # Generate the updated source file at the corresponding path. - with open(updated_path, 'w') as f: - f.write(updated.code) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser( - description="""Fix up source that uses the configmanagement client library. - -The existing sources are NOT overwritten but are copied to output_dir with changes made. - -Note: This tool operates at a best-effort level at converting positional - parameters in client method calls to keyword based parameters. - Cases where it WILL FAIL include - A) * or ** expansion in a method call. - B) Calls via function or method alias (includes free function calls) - C) Indirect or dispatched calls (e.g. the method is looked up dynamically) - - These all constitute false negatives. The tool will also detect false - positives when an API method shares a name with another method. -""") - parser.add_argument( - '-d', - '--input-directory', - required=True, - dest='input_dir', - help='the input directory to walk for python files to fix up', - ) - parser.add_argument( - '-o', - '--output-directory', - required=True, - dest='output_dir', - help='the directory to output files fixed via un-flattening', - ) - args = parser.parse_args() - input_dir = pathlib.Path(args.input_dir) - output_dir = pathlib.Path(args.output_dir) - if not input_dir.is_dir(): - print( - f"input directory '{input_dir}' does not exist or is not a directory", - file=sys.stderr, - ) - sys.exit(-1) - - if not output_dir.is_dir(): - print( - f"output directory '{output_dir}' does not exist or is not a directory", - file=sys.stderr, - ) - sys.exit(-1) - - if os.listdir(output_dir): - print( - f"output directory '{output_dir}' is not empty", - file=sys.stderr, - ) - sys.exit(-1) - - fix_files(input_dir, output_dir) diff --git a/packages/google-cloud-gke-hub/scripts/fixup_multiclusteringress_v1_keywords.py b/packages/google-cloud-gke-hub/scripts/fixup_multiclusteringress_v1_keywords.py deleted file mode 100644 index 73474fa9da49..000000000000 --- a/packages/google-cloud-gke-hub/scripts/fixup_multiclusteringress_v1_keywords.py +++ /dev/null @@ -1,175 +0,0 @@ -#! /usr/bin/env python3 -# -*- coding: utf-8 -*- -# 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 -# -# http://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. -# -import argparse -import os -import libcst as cst -import pathlib -import sys -from typing import (Any, Callable, Dict, List, Sequence, Tuple) - - -def partition( - predicate: Callable[[Any], bool], - iterator: Sequence[Any] -) -> Tuple[List[Any], List[Any]]: - """A stable, out-of-place partition.""" - results = ([], []) - - for i in iterator: - results[int(predicate(i))].append(i) - - # Returns trueList, falseList - return results[1], results[0] - - -class multiclusteringressCallTransformer(cst.CSTTransformer): - CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') - METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { - } - - def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode: - try: - key = original.func.attr.value - kword_params = self.METHOD_TO_PARAMS[key] - except (AttributeError, KeyError): - # Either not a method from the API or too convoluted to be sure. - return updated - - # If the existing code is valid, keyword args come after positional args. - # Therefore, all positional args must map to the first parameters. - args, kwargs = partition(lambda a: not bool(a.keyword), updated.args) - if any(k.keyword.value == "request" for k in kwargs): - # We've already fixed this file, don't fix it again. - return updated - - kwargs, ctrl_kwargs = partition( - lambda a: a.keyword.value not in self.CTRL_PARAMS, - kwargs - ) - - args, ctrl_args = args[:len(kword_params)], args[len(kword_params):] - ctrl_kwargs.extend(cst.Arg(value=a.value, keyword=cst.Name(value=ctrl)) - for a, ctrl in zip(ctrl_args, self.CTRL_PARAMS)) - - request_arg = cst.Arg( - value=cst.Dict([ - cst.DictElement( - cst.SimpleString("'{}'".format(name)), -cst.Element(value=arg.value) - ) - # Note: the args + kwargs looks silly, but keep in mind that - # the control parameters had to be stripped out, and that - # those could have been passed positionally or by keyword. - for name, arg in zip(kword_params, args + kwargs)]), - keyword=cst.Name("request") - ) - - return updated.with_changes( - args=[request_arg] + ctrl_kwargs - ) - - -def fix_files( - in_dir: pathlib.Path, - out_dir: pathlib.Path, - *, - transformer=multiclusteringressCallTransformer(), -): - """Duplicate the input dir to the output dir, fixing file method calls. - - Preconditions: - * in_dir is a real directory - * out_dir is a real, empty directory - """ - pyfile_gen = ( - pathlib.Path(os.path.join(root, f)) - for root, _, files in os.walk(in_dir) - for f in files if os.path.splitext(f)[1] == ".py" - ) - - for fpath in pyfile_gen: - with open(fpath, 'r') as f: - src = f.read() - - # Parse the code and insert method call fixes. - tree = cst.parse_module(src) - updated = tree.visit(transformer) - - # Create the path and directory structure for the new file. - updated_path = out_dir.joinpath(fpath.relative_to(in_dir)) - updated_path.parent.mkdir(parents=True, exist_ok=True) - - # Generate the updated source file at the corresponding path. - with open(updated_path, 'w') as f: - f.write(updated.code) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser( - description="""Fix up source that uses the multiclusteringress client library. - -The existing sources are NOT overwritten but are copied to output_dir with changes made. - -Note: This tool operates at a best-effort level at converting positional - parameters in client method calls to keyword based parameters. - Cases where it WILL FAIL include - A) * or ** expansion in a method call. - B) Calls via function or method alias (includes free function calls) - C) Indirect or dispatched calls (e.g. the method is looked up dynamically) - - These all constitute false negatives. The tool will also detect false - positives when an API method shares a name with another method. -""") - parser.add_argument( - '-d', - '--input-directory', - required=True, - dest='input_dir', - help='the input directory to walk for python files to fix up', - ) - parser.add_argument( - '-o', - '--output-directory', - required=True, - dest='output_dir', - help='the directory to output files fixed via un-flattening', - ) - args = parser.parse_args() - input_dir = pathlib.Path(args.input_dir) - output_dir = pathlib.Path(args.output_dir) - if not input_dir.is_dir(): - print( - f"input directory '{input_dir}' does not exist or is not a directory", - file=sys.stderr, - ) - sys.exit(-1) - - if not output_dir.is_dir(): - print( - f"output directory '{output_dir}' does not exist or is not a directory", - file=sys.stderr, - ) - sys.exit(-1) - - if os.listdir(output_dir): - print( - f"output directory '{output_dir}' is not empty", - file=sys.stderr, - ) - sys.exit(-1) - - fix_files(input_dir, output_dir) diff --git a/packages/google-cloud-gke-hub/tests/unit/gapic/configmanagement_v1/__init__.py b/packages/google-cloud-gke-hub/tests/unit/gapic/configmanagement_v1/__init__.py deleted file mode 100644 index 89a37dc92c5a..000000000000 --- a/packages/google-cloud-gke-hub/tests/unit/gapic/configmanagement_v1/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- -# 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 -# -# http://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. -# diff --git a/packages/google-cloud-gke-hub/tests/unit/gapic/multiclusteringress_v1/__init__.py b/packages/google-cloud-gke-hub/tests/unit/gapic/multiclusteringress_v1/__init__.py deleted file mode 100644 index 89a37dc92c5a..000000000000 --- a/packages/google-cloud-gke-hub/tests/unit/gapic/multiclusteringress_v1/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- -# 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 -# -# http://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. -# diff --git a/scripts/configure_state_yaml/packages_to_onboard.yaml b/scripts/configure_state_yaml/packages_to_onboard.yaml index d9157ff5d6fe..ecc10cf36d42 100644 --- a/scripts/configure_state_yaml/packages_to_onboard.yaml +++ b/scripts/configure_state_yaml/packages_to_onboard.yaml @@ -115,6 +115,7 @@ packages_to_onboard: [ "google-cloud-geminidataanalytics", "google-cloud-gke-backup", "google-cloud-gke-connect-gateway", + "google-cloud-gke-hub", "google-cloud-gke-multicloud", "google-cloud-gsuiteaddons", "google-cloud-iam",