Skip to content

Commit d337b88

Browse files
sofislBenjamin E. Coe
andauthored
build(node): update client library version in samples metadata (#1356)
* build(node): add feat in node post-processor to add client library version number in snippet metadata Co-authored-by: Benjamin E. Coe <[email protected]>
1 parent b1777ce commit d337b88

5 files changed

Lines changed: 380 additions & 0 deletions

File tree

synthtool/languages/common.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright 2018 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+
import json
16+
from pathlib import Path
17+
import re
18+
19+
20+
def update_library_version(version: str, root_dir: str):
21+
"""
22+
Rewrites all metadata files in ./samples/generated to the version number argument
23+
24+
"""
25+
root_dir_path = Path(root_dir)
26+
27+
snippet_metadata_files = get_sample_metadata_files(root_dir_path)
28+
for file in snippet_metadata_files:
29+
with open(file, "r+") as f:
30+
data = json.load(f)
31+
data["clientLibrary"]["version"] = version
32+
f.seek(0)
33+
json.dump(data, f, indent=4)
34+
f.truncate()
35+
36+
37+
def get_sample_metadata_files(dir: Path):
38+
"""
39+
Walks through samples/generated to find all snippet metadata files, appends them to a list
40+
41+
Returns:
42+
A list of all metadata files.
43+
"""
44+
metadata_files = []
45+
for path_object in dir.glob("**/*"):
46+
if path_object.is_file():
47+
if re.search(r"snippet_metadata", str(path_object)):
48+
metadata_files.append(str(Path.resolve(path_object)))
49+
if path_object.is_dir():
50+
get_sample_metadata_files(path_object)
51+
52+
return metadata_files

synthtool/languages/node.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
from typing import Any, Dict, List, Optional, Callable
2424
import logging
2525
import shutil
26+
from synthtool.languages import common
2627

2728
_REQUIRED_FIELDS = ["name", "repository", "engines"]
2829
_TOOLS_DIRECTORY = "/synthtool"
30+
_GENERATED_SAMPLES_DIRECTORY = "./samples/generated"
2931

3032

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

343+
library_version = template_metadata()["version"]
344+
common.update_library_version(library_version, _GENERATED_SAMPLES_DIRECTORY)
345+
341346

342347
if __name__ == "__main__":
343348
owlbot_main()
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
{
2+
"clientLibrary": {
3+
"name": "nodejs-asset",
4+
"version": "0.1.0",
5+
"language": "TYPESCRIPT",
6+
"apis": [
7+
{
8+
"id": "google.cloud.asset.v1p1beta1",
9+
"version": "v1"
10+
}
11+
]
12+
},
13+
"snippets": [
14+
{
15+
"regionTag": "cloudasset_v1p1beta1_generated_AssetService_SearchAllResources_async",
16+
"title": "AssetService searchAllResources Sample",
17+
"origin": "API_DEFINITION",
18+
"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.",
19+
"canonical": true,
20+
"file": "asset_service.search_all_resources.js",
21+
"language": "JAVASCRIPT",
22+
"segments": [
23+
{
24+
"start": 25,
25+
"end": 87,
26+
"type": "FULL"
27+
}
28+
],
29+
"clientMethod": {
30+
"shortName": "SearchAllResources",
31+
"fullName": "google.cloud.asset.v1p1beta1.AssetService.SearchAllResources",
32+
"async": true,
33+
"parameters": [
34+
{
35+
"name": "scope",
36+
"type": "TYPE_STRING"
37+
},
38+
{
39+
"name": "query",
40+
"type": "TYPE_STRING"
41+
},
42+
{
43+
"name": "asset_types",
44+
"type": "TYPE_STRING[]"
45+
},
46+
{
47+
"name": "page_size",
48+
"type": "TYPE_INT32"
49+
},
50+
{
51+
"name": "page_token",
52+
"type": "TYPE_STRING"
53+
},
54+
{
55+
"name": "order_by",
56+
"type": "TYPE_STRING"
57+
}
58+
],
59+
"resultType": ".google.cloud.asset.v1p1beta1.SearchAllResourcesResponse",
60+
"client": {
61+
"shortName": "AssetServiceClient",
62+
"fullName": "google.cloud.asset.v1p1beta1.AssetServiceClient"
63+
},
64+
"method": {
65+
"shortName": "SearchAllResources",
66+
"fullName": "google.cloud.asset.v1p1beta1.AssetService.SearchAllResources",
67+
"service": {
68+
"shortName": "AssetService",
69+
"fullName": "google.cloud.asset.v1p1beta1.AssetService"
70+
}
71+
}
72+
}
73+
},
74+
{
75+
"regionTag": "cloudasset_v1p1beta1_generated_AssetService_SearchAllIamPolicies_async",
76+
"title": "AssetService searchAllIamPolicies Sample",
77+
"origin": "API_DEFINITION",
78+
"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.",
79+
"canonical": true,
80+
"file": "asset_service.search_all_iam_policies.js",
81+
"language": "JAVASCRIPT",
82+
"segments": [
83+
{
84+
"start": 25,
85+
"end": 78,
86+
"type": "FULL"
87+
}
88+
],
89+
"clientMethod": {
90+
"shortName": "SearchAllIamPolicies",
91+
"fullName": "google.cloud.asset.v1p1beta1.AssetService.SearchAllIamPolicies",
92+
"async": true,
93+
"parameters": [
94+
{
95+
"name": "scope",
96+
"type": "TYPE_STRING"
97+
},
98+
{
99+
"name": "query",
100+
"type": "TYPE_STRING"
101+
},
102+
{
103+
"name": "page_size",
104+
"type": "TYPE_INT32"
105+
},
106+
{
107+
"name": "page_token",
108+
"type": "TYPE_STRING"
109+
}
110+
],
111+
"resultType": ".google.cloud.asset.v1p1beta1.SearchAllIamPoliciesResponse",
112+
"client": {
113+
"shortName": "AssetServiceClient",
114+
"fullName": "google.cloud.asset.v1p1beta1.AssetServiceClient"
115+
},
116+
"method": {
117+
"shortName": "SearchAllIamPolicies",
118+
"fullName": "google.cloud.asset.v1p1beta1.AssetService.SearchAllIamPolicies",
119+
"service": {
120+
"shortName": "AssetService",
121+
"fullName": "google.cloud.asset.v1p1beta1.AssetService"
122+
}
123+
}
124+
}
125+
}
126+
]
127+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
{
2+
"clientLibrary": {
3+
"name": "nodejs-asset",
4+
"version": "0.1.0",
5+
"language": "TYPESCRIPT",
6+
"apis": [
7+
{
8+
"id": "google.cloud.asset.v1p1beta1",
9+
"version": "v2"
10+
}
11+
]
12+
},
13+
"snippets": [
14+
{
15+
"regionTag": "cloudasset_v1p1beta1_generated_AssetService_SearchAllResources_async",
16+
"title": "AssetService searchAllResources Sample",
17+
"origin": "API_DEFINITION",
18+
"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.",
19+
"canonical": true,
20+
"file": "asset_service.search_all_resources.js",
21+
"language": "JAVASCRIPT",
22+
"segments": [
23+
{
24+
"start": 25,
25+
"end": 87,
26+
"type": "FULL"
27+
}
28+
],
29+
"clientMethod": {
30+
"shortName": "SearchAllResources",
31+
"fullName": "google.cloud.asset.v1p1beta1.AssetService.SearchAllResources",
32+
"async": true,
33+
"parameters": [
34+
{
35+
"name": "scope",
36+
"type": "TYPE_STRING"
37+
},
38+
{
39+
"name": "query",
40+
"type": "TYPE_STRING"
41+
},
42+
{
43+
"name": "asset_types",
44+
"type": "TYPE_STRING[]"
45+
},
46+
{
47+
"name": "page_size",
48+
"type": "TYPE_INT32"
49+
},
50+
{
51+
"name": "page_token",
52+
"type": "TYPE_STRING"
53+
},
54+
{
55+
"name": "order_by",
56+
"type": "TYPE_STRING"
57+
}
58+
],
59+
"resultType": ".google.cloud.asset.v1p1beta1.SearchAllResourcesResponse",
60+
"client": {
61+
"shortName": "AssetServiceClient",
62+
"fullName": "google.cloud.asset.v1p1beta1.AssetServiceClient"
63+
},
64+
"method": {
65+
"shortName": "SearchAllResources",
66+
"fullName": "google.cloud.asset.v1p1beta1.AssetService.SearchAllResources",
67+
"service": {
68+
"shortName": "AssetService",
69+
"fullName": "google.cloud.asset.v1p1beta1.AssetService"
70+
}
71+
}
72+
}
73+
},
74+
{
75+
"regionTag": "cloudasset_v1p1beta1_generated_AssetService_SearchAllIamPolicies_async",
76+
"title": "AssetService searchAllIamPolicies Sample",
77+
"origin": "API_DEFINITION",
78+
"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.",
79+
"canonical": true,
80+
"file": "asset_service.search_all_iam_policies.js",
81+
"language": "JAVASCRIPT",
82+
"segments": [
83+
{
84+
"start": 25,
85+
"end": 78,
86+
"type": "FULL"
87+
}
88+
],
89+
"clientMethod": {
90+
"shortName": "SearchAllIamPolicies",
91+
"fullName": "google.cloud.asset.v1p1beta1.AssetService.SearchAllIamPolicies",
92+
"async": true,
93+
"parameters": [
94+
{
95+
"name": "scope",
96+
"type": "TYPE_STRING"
97+
},
98+
{
99+
"name": "query",
100+
"type": "TYPE_STRING"
101+
},
102+
{
103+
"name": "page_size",
104+
"type": "TYPE_INT32"
105+
},
106+
{
107+
"name": "page_token",
108+
"type": "TYPE_STRING"
109+
}
110+
],
111+
"resultType": ".google.cloud.asset.v1p1beta1.SearchAllIamPoliciesResponse",
112+
"client": {
113+
"shortName": "AssetServiceClient",
114+
"fullName": "google.cloud.asset.v1p1beta1.AssetServiceClient"
115+
},
116+
"method": {
117+
"shortName": "SearchAllIamPolicies",
118+
"fullName": "google.cloud.asset.v1p1beta1.AssetService.SearchAllIamPolicies",
119+
"service": {
120+
"shortName": "AssetService",
121+
"fullName": "google.cloud.asset.v1p1beta1.AssetService"
122+
}
123+
}
124+
}
125+
}
126+
]
127+
}

0 commit comments

Comments
 (0)