Skip to content

Commit 3027667

Browse files
committed
Revert "fix: add logic to check for IAM RPC methods within the service before adding mixin to avoid generating duplicate methods"
This reverts commit 5759a4f.
1 parent 5759a4f commit 3027667

8 files changed

Lines changed: 28 additions & 118 deletions

File tree

core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/_iam.njk

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
IamClient is created for the client in the constructor.
66
[setIamPolicy, getIamPolicy, testIamPermission] methods are created which is calling the corresponding methods from IamClient in google-gax.
77
-#}
8-
{{ getIamPolicy() }}
9-
{{ setIamPolicy() }}
10-
{{ testIamPermissions() }}
11-
{%- endmacro -%}
12-
13-
{%- macro getIamPolicy() -%}
148
/**
159
* Gets the access control policy for a resource. Returns an empty policy
1610
* if the resource exists and does not have a policy set.
@@ -53,9 +47,7 @@
5347
):Promise<[IamProtos.google.iam.v1.Policy]> {
5448
return this.iamClient.getIamPolicy(request, options, callback);
5549
}
56-
{%- endmacro -%}
5750

58-
{%- macro setIamPolicy() -%}
5951
/**
6052
* Returns permissions that a caller has on the specified resource. If the
6153
* resource does not exist, this will return an empty set of
@@ -102,9 +94,7 @@
10294
):Promise<[IamProtos.google.iam.v1.Policy]> {
10395
return this.iamClient.setIamPolicy(request, options, callback);
10496
}
105-
{%- endmacro -%}
10697

107-
{%- macro testIamPermissions() -%}
10898
/**
10999
* Returns permissions that a caller has on the specified resource. If the
110100
* resource does not exist, this will return an empty set of

core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/_locations.njk

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
[getLocation, listLocations] methods are created which is calling the corresponding methods from LocationsClient in google-gax. Note that since the listLocations method is a paginated
77
method, we default to using listLocationsAsync for ease of use.
88
-#}
9-
{{ getLocation() }}
10-
{{ listLocationsAsync() }}
11-
{%- endmacro -%}
12-
13-
{%- macro getLocation() -%}
149
/**
1510
* Gets information about a location.
1611
*
@@ -50,9 +45,7 @@
5045
): Promise<LocationProtos.google.cloud.location.ILocation> {
5146
return this.locationsClient.getLocation(request, options, callback);
5247
}
53-
{%- endmacro -%}
5448

55-
{%- macro listLocationsAsync() -%}
5649
/**
5750
* Lists information about the supported locations for this service. Returns an iterable object.
5851
*

core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/src/$version/$service_client.ts.njk

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,18 @@ limitations under the License.
2727
{% import "../../_namer.njk" as namer -%}
2828
{{- namer.initialize(id, service) -}}
2929
{%- set autoPopulated = false -%}
30-
{%- set methodNamesStr = "|" -%}
3130
{%- for method in service.method -%}
3231
{%- if method.autoPopulatedFields|length !== 0 %}
3332
{%- set autoPopulated = true -%}
3433
{%- endif %}
35-
{%- set methodNamesStr = methodNamesStr + method.name.toCamelCase() + "|" -%}
3634
{%- endfor -%}
37-
{%- set generateIam = service.IAMPolicyMixin > 0 and ('|getIamPolicy|' not in methodNamesStr or '|setIamPolicy|' not in methodNamesStr or '|testIamPermissions|' not in methodNamesStr) -%}
38-
{%- set generateLocation = service.LocationMixin > 0 and ('|getLocation|' not in methodNamesStr or '|listLocations|' not in methodNamesStr) -%}
3935
import {% if (not api.legacyProtoLoad) and (autoPopulated === false) %}type {% endif %}* as gax from 'google-gax';
4036
import type {Callback, CallOptions, Descriptors, ClientOptions
4137
{%- if service.longRunning.length > 0 or service.LongRunningOperationsMixin > 0 %}, GrpcClientOptions{%- endif -%}
4238
{%- if service.longRunning.length > 0 or service.diregapicLRO.length > 0 %}, LROperation{%- endif -%}
4339
{%- if service.paging.length > 0 %}, PaginationCallback, GaxCall{%- endif -%}
44-
{%- if generateIam %}, IamClient, IamProtos{%- endif -%}
45-
{%- if generateLocation %}, LocationsClient, LocationProtos{%- endif -%}
40+
{%- if service.IAMPolicyMixin > 0 %}, IamClient, IamProtos{%- endif -%}
41+
{%- if service.LocationMixin > 0 %}, LocationsClient, LocationProtos{%- endif -%}
4642
} from 'google-gax';
4743
{% if service.paging.length > 0 or service.streaming.length > 0 -%}
4844
{% set importStreamJoiner = joiner(', ') -%}
@@ -97,10 +93,10 @@ export class {{ service.name }}Client {
9793
};
9894
warn: (code: string, message: string, warnType?: string) => void;
9995
innerApiCalls: {[name: string]: Function};
100-
{%- if generateIam %}
96+
{%- if service.IAMPolicyMixin > 0 %}
10197
iamClient: IamClient;
10298
{%- endif %}
103-
{%- if generateLocation %}
99+
{%- if service.LocationMixin > 0 %}
104100
locationsClient: LocationsClient;
105101
{%- endif -%}
106102
{%- if service.pathTemplates.length > 0 %}
@@ -226,11 +222,11 @@ export class {{ service.name }}Client {
226222
if (servicePath === this._servicePath) {
227223
this.auth.defaultScopes = staticMembers.{{ id.get("scopes") }};
228224
}
229-
{%- if generateIam %}
225+
{%- if service.IAMPolicyMixin > 0 %}
230226
this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts);
231227
{% endif %}
232228

233-
{%- if generateLocation %}
229+
{%- if service.LocationMixin > 0 %}
234230
this.locationsClient = new this._gaxModule.LocationsClient(
235231
this._gaxGrpc,
236232
opts
@@ -1106,24 +1102,11 @@ export class {{ service.name }}Client {
11061102
}
11071103
{%- endif %}
11081104
{%- endfor %}
1109-
{%- if generateIam %}
1110-
{%- if '|getIamPolicy|' not in methodNamesStr %}
1111-
{{ iam.getIamPolicy()}}
1112-
{%- endif %}
1113-
{%- if '|setIamPolicy|' not in methodNamesStr %}
1114-
{{ iam.setIamPolicy()}}
1115-
{%- endif %}
1116-
{%- if '|testIamPermissions|' not in methodNamesStr %}
1117-
{{ iam.testIamPermissions()}}
1118-
{%- endif %}
1105+
{%- if service.IAMPolicyMixin > 0 %}
1106+
{{ iam.iamServiceMethods()}}
11191107
{% endif -%}
1120-
{%- if generateLocation %}
1121-
{%- if '|getLocation|' not in methodNamesStr %}
1122-
{{ location.getLocation() }}
1123-
{%- endif %}
1124-
{%- if '|listLocations|' not in methodNamesStr %}
1125-
{{ location.listLocationsAsync() }}
1126-
{%- endif %}
1108+
{%- if service.LocationMixin > 0 %}
1109+
{{ location.locationServiceMethods()}}
11271110
{% endif -%}
11281111
{%- if service.LongRunningOperationsMixin > 0 %}
11291112
{{ operations.operationsServiceMethods()}}
@@ -1182,10 +1165,10 @@ export class {{ service.name }}Client {
11821165
this._log.info('ending gRPC channel');
11831166
this._terminated = true;
11841167
stub.close();
1185-
{%- if generateIam %}
1168+
{%- if service.IAMPolicyMixin > 0 %}
11861169
this.iamClient.close().catch(err => {throw err});
11871170
{%- endif %}
1188-
{%- if generateLocation %}
1171+
{%- if service.LocationMixin > 0 %}
11891172
this.locationsClient.close().catch(err => {throw err});
11901173
{%- endif %}
11911174
{%- if service.longRunning.length > 0 or service.LongRunningOperationsMixin > 0 %}

core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/test/gapic_$service_$version.ts.njk

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ limitations under the License.
2020
{{license.license(commonParameters.copyrightYear)}}
2121
{% import "../_namer.njk" as namer -%}
2222
{{- namer.initialize(id, service) -}}
23-
{%- set methodNamesStr = "|" -%}
24-
{%- for method in service.method -%}
25-
{%- set methodNamesStr = methodNamesStr + method.name.toCamelCase() + "|" -%}
26-
{%- endfor -%}
2723
import * as protos from '../protos/protos';
2824
import * as assert from 'assert';
2925
import * as sinon from 'sinon';
@@ -1093,7 +1089,6 @@ describe('{{ api.naming.version }}.{{ service.name }}Client', () => {
10931089
{%- if (service.IAMPolicyMixin) > 0 %}
10941090
{%- set IAMmethods = ['getIamPolicy', 'setIamPolicy', 'testIamPermissions'] %}
10951091
{%- for method in IAMmethods %}
1096-
{%- if ('|' + method + '|') not in methodNamesStr %}
10971092
describe('{{ method }}', () => {
10981093
it('invokes {{ method }} without error', async () => {
10991094
const client = new {{ service.name.toLowerCase() }}Module.{{ api.naming.version }}.{{ service.name }}Client(
@@ -1209,12 +1204,10 @@ describe('{{ api.naming.version }}.{{ service.name }}Client', () => {
12091204
.getCall(0).calledWith(request, expectedOptions, undefined));
12101205
});
12111206
});
1212-
{%- endif %}
12131207
{%- endfor %}
12141208
{%- endif %}
12151209
{%- if service.LocationMixin > 0 %}
1216-
{%- if '|getLocation|' not in methodNamesStr %}
1217-
{%- set method = 'getLocation' %}
1210+
{%- set method = 'getLocation' %}
12181211
describe('{{ method }}', () => {
12191212
it('invokes {{ method }} without error', async () => {
12201213
const client = new {{ service.name.toLowerCase() }}Module.{{ api.naming.version }}.{{ service.name }}Client(
@@ -1321,9 +1314,7 @@ describe('{{ api.naming.version }}.{{ service.name }}Client', () => {
13211314
.getCall(0).calledWith(request, expectedOptions, undefined));
13221315
});
13231316
});
1324-
{%- endif %}
1325-
{%- if '|listLocations|' not in methodNamesStr %}
1326-
{%- set method = 'listLocations' %}
1317+
{%- set method = 'listLocations' %}
13271318
describe('{{ method }}Async', () => {
13281319
it('uses async iteration with {{method}} without error', async () => {
13291320
const client = new {{ service.name.toLowerCase() }}Module.{{ api.naming.version }}.{{ service.name }}Client({{- util.initClientOptions(api.rest) -}});
@@ -1404,7 +1395,6 @@ describe('{{ api.naming.version }}.{{ service.name }}Client', () => {
14041395
);
14051396
});
14061397
});
1407-
{%- endif %}
14081398
{%- endif %}
14091399
{%- if (service.LongRunningOperationsMixin) > 0 %}
14101400
{%- set Operationsmethods = ['getOperation', 'cancelOperation', 'deleteOperation'] %}

core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/_iam.njk

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
IamClient is created for the client in the constructor.
66
[setIamPolicy, getIamPolicy, testIamPermission] methods are created which is calling the corresponding methods from IamClient in google-gax.
77
-#}
8-
{{ getIamPolicy() }}
9-
{{ setIamPolicy() }}
10-
{{ testIamPermissions() }}
11-
{%- endmacro -%}
12-
13-
{%- macro getIamPolicy() -%}
148
/**
159
* Gets the access control policy for a resource. Returns an empty policy
1610
* if the resource exists and does not have a policy set.
@@ -53,9 +47,7 @@
5347
):Promise<[IamProtos.google.iam.v1.Policy]> {
5448
return this.iamClient.getIamPolicy(request, options, callback);
5549
}
56-
{%- endmacro -%}
5750

58-
{%- macro setIamPolicy() -%}
5951
/**
6052
* Returns permissions that a caller has on the specified resource. If the
6153
* resource does not exist, this will return an empty set of
@@ -102,9 +94,7 @@
10294
):Promise<[IamProtos.google.iam.v1.Policy]> {
10395
return this.iamClient.setIamPolicy(request, options, callback);
10496
}
105-
{%- endmacro -%}
10697

107-
{%- macro testIamPermissions() -%}
10898
/**
10999
* Returns permissions that a caller has on the specified resource. If the
110100
* resource does not exist, this will return an empty set of

core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/_locations.njk

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
[getLocation, listLocations] methods are created which is calling the corresponding methods from LocationsClient in google-gax. Note that since the listLocations method is a paginated
77
method, we default to using listLocationsAsync for ease of use.
88
-#}
9-
{{ getLocation() }}
10-
{{ listLocationsAsync() }}
11-
{%- endmacro -%}
12-
13-
{%- macro getLocation() -%}
149
/**
1510
* Gets information about a location.
1611
*
@@ -50,9 +45,7 @@
5045
): Promise<LocationProtos.google.cloud.location.ILocation> {
5146
return this.locationsClient.getLocation(request, options, callback);
5247
}
53-
{%- endmacro -%}
5448

55-
{%- macro listLocationsAsync() -%}
5649
/**
5750
* Lists information about the supported locations for this service. Returns an iterable object.
5851
*

core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/esm/src/$version/$service_client.ts.njk

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,13 @@ limitations under the License.
2626
{% import "../../../_operations.njk" as operations -%}
2727
{% import "../../../_namer.njk" as namer -%}
2828
{{- namer.initialize(id, service) -}}
29-
{%- set methodNamesStr = "|" -%}
30-
{%- for method in service.method -%}
31-
{%- set methodNamesStr = methodNamesStr + method.name.toCamelCase() + "|" -%}
32-
{%- endfor -%}
33-
{%- set generateIam = service.IAMPolicyMixin > 0 and ('|getIamPolicy|' not in methodNamesStr or '|setIamPolicy|' not in methodNamesStr or '|testIamPermissions|' not in methodNamesStr) -%}
34-
{%- set generateLocation = service.LocationMixin > 0 and ('|getLocation|' not in methodNamesStr or '|listLocations|' not in methodNamesStr) -%}
3529
import * as gax from 'google-gax';
3630
import type {Callback, CallOptions, Descriptors, ClientOptions
3731
{%- if service.longRunning.length > 0 or service.LongRunningOperationsMixin > 0 %}, GrpcClientOptions{%- endif -%}
3832
{%- if service.longRunning.length > 0 or service.diregapicLRO.length > 0 %}, LROperation{%- endif -%}
3933
{%- if service.paging.length > 0 %}, PaginationCallback, GaxCall{%- endif -%}
40-
{%- if generateIam %}, IamClient, IamProtos{%- endif -%}
41-
{%- if generateLocation %}, LocationsClient, LocationProtos{%- endif -%}
34+
{%- if service.IAMPolicyMixin > 0 %}, IamClient, IamProtos{%- endif -%}
35+
{%- if service.LocationMixin > 0 %}, LocationsClient, LocationProtos{%- endif -%}
4236
} from 'google-gax';
4337
{% if service.paging.length > 0 or service.streaming.length > 0 -%}
4438
{% set importStreamJoiner = joiner(', ') -%}
@@ -105,10 +99,10 @@ export class {{ service.name }}Client {
10599
};
106100
warn: (code: string, message: string, warnType?: string) => void;
107101
innerApiCalls: {[name: string]: Function};
108-
{%- if generateIam %}
102+
{%- if service.IAMPolicyMixin > 0 %}
109103
iamClient: IamClient;
110104
{%- endif %}
111-
{%- if generateLocation %}
105+
{%- if service.LocationMixin > 0 %}
112106
locationsClient: LocationsClient;
113107
{%- endif -%}
114108
{%- if service.pathTemplates.length > 0 %}
@@ -235,11 +229,11 @@ export class {{ service.name }}Client {
235229
if (servicePath === this._servicePath) {
236230
this.auth.defaultScopes = staticMembers.{{ id.get("scopes") }};
237231
}
238-
{%- if generateIam %}
232+
{%- if service.IAMPolicyMixin > 0 %}
239233
this.iamClient = new this._gaxModule.IamClient(this._gaxGrpc, opts);
240234
{% endif %}
241235

242-
{%- if generateLocation %}
236+
{%- if service.LocationMixin > 0 %}
243237
this.locationsClient = new this._gaxModule.LocationsClient(
244238
this._gaxGrpc,
245239
opts
@@ -1115,24 +1109,11 @@ export class {{ service.name }}Client {
11151109
}
11161110
{%- endif %}
11171111
{%- endfor %}
1118-
{%- if generateIam %}
1119-
{%- if '|getIamPolicy|' not in methodNamesStr %}
1120-
{{ iam.getIamPolicy()}}
1121-
{%- endif %}
1122-
{%- if '|setIamPolicy|' not in methodNamesStr %}
1123-
{{ iam.setIamPolicy()}}
1124-
{%- endif %}
1125-
{%- if '|testIamPermissions|' not in methodNamesStr %}
1126-
{{ iam.testIamPermissions()}}
1127-
{%- endif %}
1112+
{%- if service.IAMPolicyMixin > 0 %}
1113+
{{ iam.iamServiceMethods()}}
11281114
{% endif -%}
1129-
{%- if generateLocation %}
1130-
{%- if '|getLocation|' not in methodNamesStr %}
1131-
{{ location.getLocation() }}
1132-
{%- endif %}
1133-
{%- if '|listLocations|' not in methodNamesStr %}
1134-
{{ location.listLocationsAsync() }}
1135-
{%- endif %}
1115+
{%- if service.LocationMixin > 0 %}
1116+
{{ location.locationServiceMethods()}}
11361117
{% endif -%}
11371118
{%- if service.LongRunningOperationsMixin > 0 %}
11381119
{{ operations.operationsServiceMethods()}}
@@ -1191,10 +1172,10 @@ export class {{ service.name }}Client {
11911172
this._log.info('ending gRPC channel');
11921173
this._terminated = true;
11931174
stub.close();
1194-
{%- if generateIam %}
1175+
{%- if service.IAMPolicyMixin > 0 %}
11951176
this.iamClient.close().catch(err => {throw err});
11961177
{%- endif %}
1197-
{%- if generateLocation %}
1178+
{%- if service.LocationMixin > 0 %}
11981179
this.locationsClient.close().catch(err => {throw err});
11991180
{%- endif %}
12001181
{%- if service.longRunning.length > 0 or service.LongRunningOperationsMixin > 0 %}

core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/esm/test/gapic_$service_$version.ts.njk

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ limitations under the License.
2020
{{license.license(commonParameters.copyrightYear)}}
2121
{% import "../../_namer.njk" as namer -%}
2222
{{- namer.initialize(id, service) -}}
23-
{%- set methodNamesStr = "|" -%}
24-
{%- for method in service.method -%}
25-
{%- set methodNamesStr = methodNamesStr + method.name.toCamelCase() + "|" -%}
26-
{%- endfor -%}
2723
// @ts-ignore
2824
import * as protos from '../../protos/protos.js';
2925
import assert from 'assert';
@@ -1099,7 +1095,6 @@ describe('{{ api.naming.version }}.{{ service.name }}Client', () => {
10991095
{%- if (service.IAMPolicyMixin) > 0 %}
11001096
{%- set IAMmethods = ['getIamPolicy', 'setIamPolicy', 'testIamPermissions'] %}
11011097
{%- for method in IAMmethods %}
1102-
{%- if ('|' + method + '|') not in methodNamesStr %}
11031098
describe('{{ method }}', () => {
11041099
it('invokes {{ method }} without error', async () => {
11051100
const client = new {{ service.name.toLowerCase() }}Module.{{ api.naming.version }}.{{ service.name }}Client(
@@ -1215,12 +1210,10 @@ describe('{{ api.naming.version }}.{{ service.name }}Client', () => {
12151210
.getCall(0).calledWith(request, expectedOptions, undefined));
12161211
});
12171212
});
1218-
{%- endif %}
12191213
{%- endfor %}
12201214
{%- endif %}
12211215
{%- if service.LocationMixin > 0 %}
1222-
{%- if '|getLocation|' not in methodNamesStr %}
1223-
{%- set method = 'getLocation' %}
1216+
{%- set method = 'getLocation' %}
12241217
describe('{{ method }}', () => {
12251218
it('invokes {{ method }} without error', async () => {
12261219
const client = new {{ service.name.toLowerCase() }}Module.{{ api.naming.version }}.{{ service.name }}Client(
@@ -1327,9 +1320,7 @@ describe('{{ api.naming.version }}.{{ service.name }}Client', () => {
13271320
.getCall(0).calledWith(request, expectedOptions, undefined));
13281321
});
13291322
});
1330-
{%- endif %}
1331-
{%- if '|listLocations|' not in methodNamesStr %}
1332-
{%- set method = 'listLocations' %}
1323+
{%- set method = 'listLocations' %}
13331324
describe('{{ method }}Async', () => {
13341325
it('uses async iteration with {{method}} without error', async () => {
13351326
const client = new {{ service.name.toLowerCase() }}Module.{{ api.naming.version }}.{{ service.name }}Client({{- util.initClientOptions(api.rest) -}});
@@ -1410,7 +1401,6 @@ describe('{{ api.naming.version }}.{{ service.name }}Client', () => {
14101401
);
14111402
});
14121403
});
1413-
{%- endif %}
14141404
{%- endif %}
14151405
{%- if (service.LongRunningOperationsMixin) > 0 %}
14161406
{%- set Operationsmethods = ['getOperation', 'cancelOperation', 'deleteOperation'] %}

0 commit comments

Comments
 (0)