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

feat: add UUID autogeneration for fields listed as autoPopulate in service.yaml #1511

Merged
merged 40 commits into from
Jan 31, 2024

Conversation

sofisl
Copy link
Contributor

@sofisl sofisl commented Jan 4, 2024

No description provided.

@sofisl sofisl requested review from a team as code owners January 4, 2024 03:49
@sofisl
Copy link
Contributor Author

sofisl commented Jan 9, 2024

@alexander-fenster, I think the failing tests are due to gapic-tools not recognizing the field_info.proto. Once we publish a new version of gax with the new version of nodejs-proto-files, I can also update gapic-tools and I think it will just work.

@alexander-fenster
Copy link
Contributor

Let me review this after #1503 gets in.

@@ -22,6 +22,7 @@ import type {Callback, CallOptions, Descriptors, ClientOptions, GrpcClientOption

import * as protos from '../../protos/protos';
import jsonProtos = require('../../protos/protos.json');
import * as crypto from 'crypto';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This immediately disqualifies the library from the browser or any other non-Node.js usage. One way to solve this would be to move everything that needs crypto to google-gax and export it from there, and in gax, make it similar to https://github.com/googleapis/google-auth-library-nodejs/tree/main/src/crypto to use either Node.js crypto or window.crypto.subtle, whichever is available.

Also, I don't see any crypto usage in this particular file, which probably means that this import should be conditional.

@@ -607,6 +608,9 @@ export class {{ service.name }}Client {
{%- endif %}
]>|void {
request = request || {};
{% for field in method.autoPopulatedFields %}if (!request.{{ field.toCamelCase() }}) {
request.{{ field.toCamelCase() }} = crypto.randomUUID();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it compatible with browser, we have two options: either use uuid module instead of crypto (which will force us make uuid a dependency for all libraries), or - probably better - export a createUUID() function from gax, and have it there instead.

@@ -74,6 +75,7 @@ export interface MethodDescriptorProto

export interface ServiceDescriptorProto
extends protos.google.protobuf.IServiceDescriptorProto {
getAutoPopulatedFields: MethodDescriptorProto[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this field actually used anywhere? I see the function getAutoPopulatedFields but I don't see if this added field is accessed anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REmoved!

@@ -459,6 +461,9 @@ export class EchoClient {
protos.google.showcase.v1beta1.IEchoRequest|undefined, {}|undefined
]>|void {
request = request || {};
if (!request.requestId) {
request.requestId = gax.makeUUID();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we have a generated unit test that would check that this code is actually executed? It would be similar to an existing test that makes a request, but in a stub, it can check that the field was indeed assigned to some UUID. Similar to

.

@sofisl sofisl merged commit e731e91 into main Jan 31, 2024
27 checks passed
@sofisl sofisl deleted the addUUID branch January 31, 2024 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants