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

Use crypto.randomUUID() instead of uuid module #2802

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 1 addition & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@
"google-auth-library": "^9.14.2",
"jsonwebtoken": "^9.0.0",
"jwks-rsa": "^3.1.0",
"node-forge": "^1.3.1",
"uuid": "^11.0.2"
"node-forge": "^1.3.1"
},
"optionalDependencies": {
"@google-cloud/firestore": "^7.11.0",
Expand All @@ -238,7 +237,6 @@
"@types/request-promise": "^4.1.41",
"@types/sinon": "^17.0.2",
"@types/sinon-chai": "^3.0.0",
"@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^7.16.1",
"@typescript-eslint/parser": "^7.16.1",
"bcrypt": "^5.0.0",
Expand Down
11 changes: 5 additions & 6 deletions src/eventarc/eventarc-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@

import { PrefixedFirebaseError } from '../utils/error';
import { CloudEvent } from './cloudevent';
import { v4 as uuid } from 'uuid';
import * as validator from '../utils/validator';

// List of CloudEvent properties that are handled "by hand" and should be skipped by
// automatic attribute copy.
const TOP_LEVEL_CE_ATTRS: string[] =
const TOP_LEVEL_CE_ATTRS: string[] =
['id', 'type', 'specversion', 'source', 'data', 'time', 'datacontenttype', 'subject'];

export type EventarcErrorCode = 'unknown-error' | 'invalid-argument'
Expand Down Expand Up @@ -50,7 +49,7 @@ export function toCloudEventProtoFormat(ce: CloudEvent): any {
}
const out: Record<string, any> = {
'@type': 'type.googleapis.com/io.cloudevents.v1.CloudEvent',
'id': ce.id ?? uuid(),
'id': ce.id ?? crypto.randomUUID(),
'type': ce.type,
'specVersion': ce.specversion ?? '1.0',
'source': source
Expand All @@ -72,7 +71,7 @@ export function toCloudEventProtoFormat(ce: CloudEvent): any {
if (typeof ce.datacontenttype !== 'undefined') {
if (!validator.isNonEmptyString(ce.datacontenttype)) {
throw new FirebaseEventarcError(
'invalid-argument',
'invalid-argument',
"CloudEvent 'datacontenttype' if specified must be non-empty string.");
}
setAttribute(out, 'datacontenttype', {
Expand All @@ -82,7 +81,7 @@ export function toCloudEventProtoFormat(ce: CloudEvent): any {
if (ce.subject) {
if (!validator.isNonEmptyString(ce.subject)) {
throw new FirebaseEventarcError(
'invalid-argument',
'invalid-argument',
"CloudEvent 'subject' if specified must be non-empty string.");
}
setAttribute(out, 'subject', {
Expand All @@ -109,7 +108,7 @@ export function toCloudEventProtoFormat(ce: CloudEvent): any {
}
} else {
throw new FirebaseEventarcError(
'invalid-argument',
'invalid-argument',
`CloudEvent 'data' must be string or an object (which are converted to JSON), got '${typeof ce.data}'.`);
}

Expand Down
9 changes: 4 additions & 5 deletions test/unit/remote-config/condition-evaluator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
NamedCondition,
OneOfCondition,
} from '../../../src/remote-config/remote-config-api';
import { v4 as uuidv4 } from 'uuid';
import { clone } from 'lodash';
import * as crypto from 'crypto';

Expand Down Expand Up @@ -754,7 +753,7 @@ describe('ConditionEvaluator', () => {

describe('known percent condition values', () => {
// This test is useful for ensuring consistency across all places we
// evaluate percent conditions. It creates a set of 10 conditions targeting 50%
// evaluate percent conditions. It creates a set of 10 conditions targeting 50%
// with randomizationIds 0-9 and a constant `seed` value.
const conditionEvaluator = new ConditionEvaluator();

Expand Down Expand Up @@ -782,8 +781,8 @@ describe('ConditionEvaluator', () => {

testCases.map(({ randomizationId, seed, result }) => {

const idSummary = randomizationId.length > 25
? `a ${randomizationId.length} character randomizationID`
const idSummary = randomizationId.length > 25
? `a ${randomizationId.length} character randomizationID`
: `"${randomizationId}"`;

it(`should evaluate ${idSummary} with seed "${seed}" to ${result}`, () => {
Expand Down Expand Up @@ -907,7 +906,7 @@ describe('ConditionEvaluator', () => {
...clone(condition),
seed: 'seed'
};
const context = { randomizationId: uuidv4() }
const context = { randomizationId: crypto.randomUUID() }
if (conditionEvaluator.evaluateConditions([{
name: 'is_enabled',
condition: { percent: clonedCondition }
Expand Down
Loading