-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
Showing
5 changed files
with
380 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
tests/fixtures/samples/generated/v1/snippet_metadata.google.cloud.asset.v1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} |
127 changes: 127 additions & 0 deletions
127
tests/fixtures/samples/generated/v2/snippet_metadata.google.cloud.asset.v2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} |
Oops, something went wrong.