Skip to content

Commit

Permalink
feat!: move to typescript code generation (#264)
Browse files Browse the repository at this point in the history
* update from synthtool

* move to typescript

* update synth script and run it

* convert system-test to ts

* try this

* lint

* regenerate to pick up change for path template

* update client

* gts fix

* update copyright

* 2020 copyright

* try this

* fix unit test

* re-generate

* make sample test work

* remove sample test for IAM policy

* liny

* remove doc, revert sample-test

* add iam client to kmsClient

* update sample-test

* lint

* makes samples test work

* lint

* update

* convert system-tets to ts

* rerun synthtool

* sample test

* fix

* mix-in

* update synthtool

* run synthtool & test

* test

* manual add IamClient and pass unit tests

* clean up

* npm run lint

* test samples

* manual iam_service_config

* ts client interface overload

* test

* test

* return value

* return list

* clean up

* remove console warn

* sample-test work!

* require module correctly

* synthtool change

* include all files in tarball, system-test passes

* synthtool, all tests green

* merge

* fix for system-test

* feedback

* update dependencies

* license aligned for helper.ts

* remove helper.ts, tslint from synth.py

* move script around

* add comments to iamclient & synth.py

* rename helperMethods.tmpl

* rerun ynthtool

* give auth the type

* re set up scripts in package.json

* add meaningful comment

* add comments in helperMethods.tmpl

* test

* import * as packagejson from ../package.json;

* remove any

* run synthtool
  • Loading branch information
xiaozhenliu-gg5 committed Mar 5, 2020
1 parent 0fe9f5d commit f1ce9e6
Show file tree
Hide file tree
Showing 42 changed files with 38,072 additions and 39,227 deletions.
5 changes: 3 additions & 2 deletions packages/google-cloud-kms/.gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
**/*.log
**/node_modules
.coverage
coverage
.nyc_output
docs/
out/
build/
system-test/secrets.js
system-test/*key.json
**/*.lock
**/package-lock.json
*.lock
.DS_Store
package-lock.json
__pycache__
5 changes: 4 additions & 1 deletion packages/google-cloud-kms/.jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ** This file is automatically generated by gapic-generator-typescript. **
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **

'use strict';

Expand All @@ -31,7 +34,7 @@ module.exports = {
source: {
excludePattern: '(^|\\/|\\\\)[._]',
include: [
'src',
'build/src',
'protos'
],
includePattern: '\\.js$'
Expand Down
33 changes: 33 additions & 0 deletions packages/google-cloud-kms/helperMethods.ts.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* This part will be added into src/v1/key_management_service_client.ts by synth.py.
* KMS service requires IAM client for [setIamPolicy, getIamPolicy, testIamPerssion] methods.
* But we don't support it now in micro-generators for rerouting one service to another and mix them in.
* New feature request link: [https://github.com/googleapis/gapic-generator-typescript/issues/315]
*
* So this is manually written for providing methods to the KMS client.
* IamClient is created for KMS client in the constructor using src/helper.ts.
* [setIamPolicy, getIamPolicy, testIamPerssion] methods are created which is calling the corresponding methods from IamClient in `helper.ts`.
*/

getIamPolicy(
request: protosTypes.google.iam.v1.GetIamPolicyRequest,
options: gax.CallOptions,
callback: protosTypes.google.iam.v1.IAMPolicy.GetIamPolicyCallback
) {
return this._iamClient.getIamPolicy(request, options, callback);
}
setIamPolicy(
request: protosTypes.google.iam.v1.SetIamPolicyRequest,
options: gax.CallOptions,
callback: protosTypes.google.iam.v1.IAMPolicy.SetIamPolicyCallback
) {
return this._iamClient.setIamPolicy(request, options, callback);
}
testIamPermissions(
request: protosTypes.google.iam.v1.TestIamPermissionsRequest,
options: gax.CallOptions,
callback?: protosTypes.google.iam.v1.IAMPolicy.TestIamPermissionsCallback
) {
return this._iamClient.testIamPermissions(request, options, callback);
}
}
57 changes: 34 additions & 23 deletions packages/google-cloud-kms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
"node": ">=8.10.0"
},
"repository": "googleapis/nodejs-kms",
"main": "src/index.js",
"main": "build/src/index.js",
"files": [
"protos",
"src",
"AUTHORS",
"COPYING"
"build/protos",
"build/src"
],
"keywords": [
"google apis client",
Expand All @@ -29,31 +27,44 @@
"Google Cloud Key Management Service (KMS) API"
],
"scripts": {
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../",
"test": "c8 mocha",
"lint": "eslint '**/*.js'",
"test": "c8 mocha build/test",
"samples-test": "cd samples/ && npm link ../ && npm install && npm test && cd ../",
"lint": "gts fix && eslint samples/*.js",
"fix": "gts fix && eslint --fix samples/*.js",
"prelint": "cd samples; npm link ../; npm i",
"system-test": "mocha build/system-test",
"docs": "jsdoc -c .jsdoc.js",
"system-test": "mocha system-test/ smoke-test/ --timeout 600000",
"fix": "eslint '**/*.js' --fix",
"docs-test": "linkinator docs",
"predocs-test": "npm run docs",
"prelint": "cd samples; npm link ../; npm i"
"clean": "gts clean",
"compile": "tsc -p . && cp -r protos build/",
"compile-protos": "compileProtos src",
"prepare": "npm run compile"
},
"dependencies": {
"google-gax": "^1.7.5"
"google-gax": "^1.14.2"
},
"devDependencies": {
"codecov": "^3.0.4",
"eslint": "^6.0.0",
"eslint-config-prettier": "^6.0.0",
"@types/mocha": "^7.0.2",
"@types/node": "^13.7.7",
"c8": "^7.1.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-prettier": "^3.0.0",
"jsdoc": "^3.6.2",
"jsdoc-fresh": "^1.0.1",
"jsdoc-region-tag": "^1.0.2",
"linkinator": "^2.0.0",
"mocha": "^7.0.0",
"c8": "^7.0.0",
"prettier": "^1.13.7"
"eslint-plugin-prettier": "^3.1.2",
"gts": "^1.1.2",
"jsdoc": "^3.6.3",
"jsdoc-fresh": "^1.0.2",
"jsdoc-region-tag": "^1.0.4",
"linkinator": "^2.0.3",
"mocha": "^7.1.0",
"null-loader": "^3.0.0",
"pack-n-play": "^1.0.0-2",
"power-assert": "^1.6.1",
"prettier": "^1.19.1",
"ts-loader": "^6.2.1",
"typescript": "^3.7.0",
"webpack": "^4.42.0",
"webpack-cli": "^3.3.11"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2019 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.

// This file contains stub messages for common resources in GCP.
// It is not intended to be directly generated, and is instead used by
// other tooling to be able to match common resource patterns.
syntax = "proto3";

package google.cloud;

import "google/api/resource.proto";


option (google.api.resource_definition) = {
type: "cloudresourcemanager.googleapis.com/Project"
pattern: "projects/{project}"
};


option (google.api.resource_definition) = {
type: "cloudresourcemanager.googleapis.com/Organization"
pattern: "organizations/{organization}"
};


option (google.api.resource_definition) = {
type: "cloudresourcemanager.googleapis.com/Folder"
pattern: "folders/{folder}"
};


option (google.api.resource_definition) = {
type: "cloudbilling.googleapis.com/BillingAccount"
pattern: "billingAccounts/{billing_account}"
};

option (google.api.resource_definition) = {
type: "locations.googleapis.com/Location"
pattern: "projects/{project}/locations/{location}"
};

60 changes: 43 additions & 17 deletions packages/google-cloud-kms/protos/google/iam/v1/iam_policy.proto
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 Google Inc.
// Copyright 2019 Google LLC.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -11,13 +11,18 @@
// 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.
//

syntax = "proto3";

package google.iam.v1;

import "google/api/annotations.proto";
import "google/iam/v1/options.proto";
import "google/iam/v1/policy.proto";
import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";

option cc_enable_arenas = true;
option csharp_namespace = "Google.Cloud.Iam.V1";
Expand All @@ -27,7 +32,6 @@ option java_outer_classname = "IamPolicyProto";
option java_package = "com.google.iam.v1";
option php_namespace = "Google\\Cloud\\Iam\\V1";


// ## API Overview
//
// Manages Identity and Access Management (IAM) policies.
Expand All @@ -54,61 +58,83 @@ option php_namespace = "Google\\Cloud\\Iam\\V1";
// are created and deleted implicitly with the resources to which they are
// attached.
service IAMPolicy {
option (google.api.default_host) = "iam-meta-api.googleapis.com";

// Sets the access control policy on the specified resource. Replaces any
// existing policy.
rpc SetIamPolicy(SetIamPolicyRequest) returns (Policy) {
option (google.api.http) = { post: "/v1/{resource=**}:setIamPolicy" body: "*" };
option (google.api.http) = {
post: "/v1/{resource=**}:setIamPolicy"
body: "*"
};
}

// Gets the access control policy for a resource.
// Returns an empty policy if the resource exists and does not have a policy
// set.
rpc GetIamPolicy(GetIamPolicyRequest) returns (Policy) {
option (google.api.http) = { post: "/v1/{resource=**}:getIamPolicy" body: "*" };
option (google.api.http) = {
post: "/v1/{resource=**}:getIamPolicy"
body: "*"
};
}

// Returns permissions that a caller has on the specified resource.
// If the resource does not exist, this will return an empty set of
// permissions, not a NOT_FOUND error.
//
// Note: This operation is designed to be used for building permission-aware
// UIs and command-line tools, not for authorization checking. This operation
// may "fail open" without warning.
rpc TestIamPermissions(TestIamPermissionsRequest) returns (TestIamPermissionsResponse) {
option (google.api.http) = { post: "/v1/{resource=**}:testIamPermissions" body: "*" };
option (google.api.http) = {
post: "/v1/{resource=**}:testIamPermissions"
body: "*"
};
}
}

// Request message for `SetIamPolicy` method.
message SetIamPolicyRequest {
// REQUIRED: The resource for which the policy is being specified.
// `resource` is usually specified as a path. For example, a Project
// resource is specified as `projects/{project}`.
string resource = 1;
// See the operation documentation for the appropriate value for this field.
string resource = 1 [
(google.api.field_behavior) = REQUIRED,
(google.api.resource_reference).type = "*"];

// REQUIRED: The complete policy to be applied to the `resource`. The size of
// the policy is limited to a few 10s of KB. An empty policy is a
// valid policy but certain Cloud Platform services (such as Projects)
// might reject them.
Policy policy = 2;
Policy policy = 2 [(google.api.field_behavior) = REQUIRED];
}

// Request message for `GetIamPolicy` method.
message GetIamPolicyRequest {
// REQUIRED: The resource for which the policy is being requested.
// `resource` is usually specified as a path. For example, a Project
// resource is specified as `projects/{project}`.
string resource = 1;
// See the operation documentation for the appropriate value for this field.
string resource = 1 [
(google.api.field_behavior) = REQUIRED,
(google.api.resource_reference).type = "*"];

// OPTIONAL: A `GetPolicyOptions` object for specifying options to
// `GetIamPolicy`. This field is only used by Cloud IAM.
GetPolicyOptions options = 2;
}

// Request message for `TestIamPermissions` method.
message TestIamPermissionsRequest {
// REQUIRED: The resource for which the policy detail is being requested.
// `resource` is usually specified as a path. For example, a Project
// resource is specified as `projects/{project}`.
string resource = 1;
// See the operation documentation for the appropriate value for this field.
string resource = 1[
(google.api.field_behavior) = REQUIRED,
(google.api.resource_reference).type = "*"];

// The set of permissions to check for the `resource`. Permissions with
// wildcards (such as '*' or 'storage.*') are not allowed. For more
// information see
// [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).
repeated string permissions = 2;
repeated string permissions = 2 [(google.api.field_behavior) = REQUIRED];
}

// Response message for `TestIamPermissions` method.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2017 Google Inc.
//
// 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.

syntax = "proto3";

package google.iam.v1.logging;

import "google/api/annotations.proto";
import "google/iam/v1/policy.proto";

option csharp_namespace = "Google.Cloud.Iam.V1.Logging";
option go_package = "google.golang.org/genproto/googleapis/iam/v1/logging;logging";
option java_multiple_files = true;
option java_outer_classname = "AuditDataProto";
option java_package = "com.google.iam.v1.logging";

// Audit log information specific to Cloud IAM. This message is serialized
// as an `Any` type in the `ServiceData` message of an
// `AuditLog` message.
message AuditData {
// Policy delta between the original policy and the newly set policy.
google.iam.v1.PolicyDelta policy_delta = 2;
}
Loading

0 comments on commit f1ce9e6

Please sign in to comment.