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

build(node): update client library version in samples metadata #1356

Merged
merged 10 commits into from
Apr 20, 2022
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
52 changes: 52 additions & 0 deletions synthtool/languages/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2018 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.

import json
from pathlib import Path
import re


def update_library_version(version: str, root_dir: str):
"""
Rewrites all metadata files in ./samples/generated to the version number argument

"""
root_dir_path = Path(root_dir)

snippet_metadata_files = get_sample_metadata_files(root_dir_path)
for file in snippet_metadata_files:
with open(file, "r+") as f:
data = json.load(f)
data["clientLibrary"]["version"] = version
f.seek(0)
json.dump(data, f, indent=4)
f.truncate()


def get_sample_metadata_files(dir: Path):
"""
Walks through samples/generated to find all snippet metadata files, appends them to a list

Returns:
A list of all metadata files.
"""
metadata_files = []
for path_object in dir.glob("**/*"):
if path_object.is_file():
if re.search(r"snippet_metadata", str(path_object)):
metadata_files.append(str(Path.resolve(path_object)))
if path_object.is_dir():
get_sample_metadata_files(path_object)

return metadata_files
5 changes: 5 additions & 0 deletions synthtool/languages/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
from typing import Any, Dict, List, Optional, Callable
import logging
import shutil
from synthtool.languages import common

_REQUIRED_FIELDS = ["name", "repository", "engines"]
_TOOLS_DIRECTORY = "/synthtool"
_GENERATED_SAMPLES_DIRECTORY = "./samples/generated"


def read_metadata():
Expand Down Expand Up @@ -338,6 +340,9 @@ def owlbot_main(
templates = common_templates.node_library(source_location="build/src")
s_copy([templates], excludes=templates_excludes)

library_version = template_metadata()["version"]
common.update_library_version(library_version, _GENERATED_SAMPLES_DIRECTORY)


if __name__ == "__main__":
owlbot_main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{
"clientLibrary": {
"name": "nodejs-asset",
"version": "0.1.0",
"language": "TYPESCRIPT",
"apis": [
{
"id": "google.cloud.asset.v1p1beta1",
"version": "v1"
}
]
},
"snippets": [
{
"regionTag": "cloudasset_v1p1beta1_generated_AssetService_SearchAllResources_async",
"title": "AssetService searchAllResources Sample",
"origin": "API_DEFINITION",
"description": " Searches all the resources under a given accessible CRM scope (project/folder/organization). This RPC gives callers especially admins the ability to search all the resources under a scope, even if they don't have .get permission of all the resources. Callers should have cloud.assets.SearchAllResources permission on the requested scope, otherwise it will be rejected.",
"canonical": true,
"file": "asset_service.search_all_resources.js",
"language": "JAVASCRIPT",
"segments": [
{
"start": 25,
"end": 87,
"type": "FULL"
}
],
"clientMethod": {
"shortName": "SearchAllResources",
"fullName": "google.cloud.asset.v1p1beta1.AssetService.SearchAllResources",
"async": true,
"parameters": [
{
"name": "scope",
"type": "TYPE_STRING"
},
{
"name": "query",
"type": "TYPE_STRING"
},
{
"name": "asset_types",
"type": "TYPE_STRING[]"
},
{
"name": "page_size",
"type": "TYPE_INT32"
},
{
"name": "page_token",
"type": "TYPE_STRING"
},
{
"name": "order_by",
"type": "TYPE_STRING"
}
],
"resultType": ".google.cloud.asset.v1p1beta1.SearchAllResourcesResponse",
"client": {
"shortName": "AssetServiceClient",
"fullName": "google.cloud.asset.v1p1beta1.AssetServiceClient"
},
"method": {
"shortName": "SearchAllResources",
"fullName": "google.cloud.asset.v1p1beta1.AssetService.SearchAllResources",
"service": {
"shortName": "AssetService",
"fullName": "google.cloud.asset.v1p1beta1.AssetService"
}
}
}
},
{
"regionTag": "cloudasset_v1p1beta1_generated_AssetService_SearchAllIamPolicies_async",
"title": "AssetService searchAllIamPolicies Sample",
"origin": "API_DEFINITION",
"description": " Searches all the IAM policies under a given accessible CRM scope (project/folder/organization). This RPC gives callers especially admins the ability to search all the IAM policies under a scope, even if they don't have .getIamPolicy permission of all the IAM policies. Callers should have cloud.assets.SearchAllIamPolicies permission on the requested scope, otherwise it will be rejected.",
"canonical": true,
"file": "asset_service.search_all_iam_policies.js",
"language": "JAVASCRIPT",
"segments": [
{
"start": 25,
"end": 78,
"type": "FULL"
}
],
"clientMethod": {
"shortName": "SearchAllIamPolicies",
"fullName": "google.cloud.asset.v1p1beta1.AssetService.SearchAllIamPolicies",
"async": true,
"parameters": [
{
"name": "scope",
"type": "TYPE_STRING"
},
{
"name": "query",
"type": "TYPE_STRING"
},
{
"name": "page_size",
"type": "TYPE_INT32"
},
{
"name": "page_token",
"type": "TYPE_STRING"
}
],
"resultType": ".google.cloud.asset.v1p1beta1.SearchAllIamPoliciesResponse",
"client": {
"shortName": "AssetServiceClient",
"fullName": "google.cloud.asset.v1p1beta1.AssetServiceClient"
},
"method": {
"shortName": "SearchAllIamPolicies",
"fullName": "google.cloud.asset.v1p1beta1.AssetService.SearchAllIamPolicies",
"service": {
"shortName": "AssetService",
"fullName": "google.cloud.asset.v1p1beta1.AssetService"
}
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{
"clientLibrary": {
"name": "nodejs-asset",
"version": "0.1.0",
"language": "TYPESCRIPT",
"apis": [
{
"id": "google.cloud.asset.v1p1beta1",
"version": "v2"
}
]
},
"snippets": [
{
"regionTag": "cloudasset_v1p1beta1_generated_AssetService_SearchAllResources_async",
"title": "AssetService searchAllResources Sample",
"origin": "API_DEFINITION",
"description": " Searches all the resources under a given accessible CRM scope (project/folder/organization). This RPC gives callers especially admins the ability to search all the resources under a scope, even if they don't have .get permission of all the resources. Callers should have cloud.assets.SearchAllResources permission on the requested scope, otherwise it will be rejected.",
"canonical": true,
"file": "asset_service.search_all_resources.js",
"language": "JAVASCRIPT",
"segments": [
{
"start": 25,
"end": 87,
"type": "FULL"
}
],
"clientMethod": {
"shortName": "SearchAllResources",
"fullName": "google.cloud.asset.v1p1beta1.AssetService.SearchAllResources",
"async": true,
"parameters": [
{
"name": "scope",
"type": "TYPE_STRING"
},
{
"name": "query",
"type": "TYPE_STRING"
},
{
"name": "asset_types",
"type": "TYPE_STRING[]"
},
{
"name": "page_size",
"type": "TYPE_INT32"
},
{
"name": "page_token",
"type": "TYPE_STRING"
},
{
"name": "order_by",
"type": "TYPE_STRING"
}
],
"resultType": ".google.cloud.asset.v1p1beta1.SearchAllResourcesResponse",
"client": {
"shortName": "AssetServiceClient",
"fullName": "google.cloud.asset.v1p1beta1.AssetServiceClient"
},
"method": {
"shortName": "SearchAllResources",
"fullName": "google.cloud.asset.v1p1beta1.AssetService.SearchAllResources",
"service": {
"shortName": "AssetService",
"fullName": "google.cloud.asset.v1p1beta1.AssetService"
}
}
}
},
{
"regionTag": "cloudasset_v1p1beta1_generated_AssetService_SearchAllIamPolicies_async",
"title": "AssetService searchAllIamPolicies Sample",
"origin": "API_DEFINITION",
"description": " Searches all the IAM policies under a given accessible CRM scope (project/folder/organization). This RPC gives callers especially admins the ability to search all the IAM policies under a scope, even if they don't have .getIamPolicy permission of all the IAM policies. Callers should have cloud.assets.SearchAllIamPolicies permission on the requested scope, otherwise it will be rejected.",
"canonical": true,
"file": "asset_service.search_all_iam_policies.js",
"language": "JAVASCRIPT",
"segments": [
{
"start": 25,
"end": 78,
"type": "FULL"
}
],
"clientMethod": {
"shortName": "SearchAllIamPolicies",
"fullName": "google.cloud.asset.v1p1beta1.AssetService.SearchAllIamPolicies",
"async": true,
"parameters": [
{
"name": "scope",
"type": "TYPE_STRING"
},
{
"name": "query",
"type": "TYPE_STRING"
},
{
"name": "page_size",
"type": "TYPE_INT32"
},
{
"name": "page_token",
"type": "TYPE_STRING"
}
],
"resultType": ".google.cloud.asset.v1p1beta1.SearchAllIamPoliciesResponse",
"client": {
"shortName": "AssetServiceClient",
"fullName": "google.cloud.asset.v1p1beta1.AssetServiceClient"
},
"method": {
"shortName": "SearchAllIamPolicies",
"fullName": "google.cloud.asset.v1p1beta1.AssetService.SearchAllIamPolicies",
"service": {
"shortName": "AssetService",
"fullName": "google.cloud.asset.v1p1beta1.AssetService"
}
}
}
}
]
}
Loading