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

uuid.v4 -> crypto.randomUUID #1071

Merged
merged 3 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
20 changes: 0 additions & 20 deletions package-lock.json

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

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"swagger-ui-express": "5.0.0",
"tsoa": "5.1.1",
"unzipper": "0.10.14",
"uuid": "9.0.1",
"walk": "2.3.15",
"yargs": "17.7.2"
},
Expand All @@ -64,7 +63,6 @@
"@types/pg": "8.10.5",
"@types/sinon": "10.0.17",
"@types/swagger-jsdoc": "6.0.1",
"@types/uuid": "9.0.4",
"@types/yargs": "17.0.28",
"@typescript-eslint/eslint-plugin": "6.7.5",
"@typescript-eslint/parser": "6.7.5",
Expand Down
4 changes: 2 additions & 2 deletions src/_db/commands/reindex/postgres.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import picocolors from "picocolors";
import * as uuid from "uuid";
import util from "util";
import { randomUUID } from "crypto";

import { putAliases, getESWithoutRetry } from "../../../persistence/elasticsearch";
import PostgresEventSource from "../../persistence/PostgresEventSource";
Expand Down Expand Up @@ -78,7 +78,7 @@ export const handler = async (argv) => {

const eventSource = new PostgresEventSource(pgPool, argv.startDate, argv.endDate, argv.pageSize);

const esTempIndex = `retraced.reindex.${uuid.v4()}`;
const esTempIndex = `retraced.reindex.${randomUUID()}`;
const esTargetIndex = `retraced.${argv.projectId}.${argv.environmentId}`;
const esTargetWriteIndex = `retraced.${argv.projectId}.${argv.environmentId}.current`;

Expand Down
12 changes: 5 additions & 7 deletions src/_processor/models/action/test/select_new.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect } from "chai";
import * as uuid from "uuid";
import moment from "moment";

import getPgPool from "../../../persistence/pg";
import selectNew from "../select_new";
import { randomUUID } from "crypto";

const pgPool = getPgPool();

Expand All @@ -13,8 +13,8 @@ describe("models.action.select_new", () => {
"a.update" was first seen on 2017-03-29 at 12AM.
"a.get" was first seen on 2017-03-29 at 1AM.
"a.list" was first seen on 2017-03-30 at 12AM.`, () => {
const projectId = uuid.v4();
const environmentId = uuid.v4();
const projectId = randomUUID();
const environmentId = randomUUID();
const ref = moment.utc("2017-03-29");
const actions = [
["a.create", ref.clone().subtract(1, "hour")],
Expand All @@ -29,13 +29,11 @@ describe("models.action.select_new", () => {
`
insert into action (id, project_id, environment_id, action, first_active)
values ($1, $2, $3, $4, $5)`,
[uuid.v4(), projectId, environmentId, action, firstActive]
[randomUUID(), projectId, environmentId, action, firstActive]
)
);
});
after(() =>
pgPool.query("delete from action where project_id = $1", [projectId])
);
after(() => pgPool.query("delete from action where project_id = $1", [projectId]));

describe("searching 2017-03-29 00:00:00 to 2017-03-30 00:00:00", () => {
it('should return "a.update" and "a.get".', () => {
Expand Down
12 changes: 5 additions & 7 deletions src/_processor/models/action/test/select_stopped.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";
import * as uuid from "uuid";
import moment from "moment";
import { randomUUID } from "crypto";

import getPgPool from "../../../persistence/pg";
import selectStopped from "../select_stopped";
Expand All @@ -13,8 +13,8 @@ describe("models.action.select_stopped", () => {
"a.update" was last seen on 2017-03-29 at 12AM.
"a.get" was last seen on 2017-03-29 at 1AM.
"a.list" was last seen on 2017-03-30 at 12AM.`, () => {
const projectId = uuid.v4();
const environmentId = uuid.v4();
const projectId = randomUUID();
const environmentId = randomUUID();
const ref = moment.utc("2017-03-29");
const actions = [
["a.create", ref.clone().subtract(1, "hour")],
Expand All @@ -29,13 +29,11 @@ describe("models.action.select_stopped", () => {
`
insert into action (id, project_id, environment_id, action, last_active)
values ($1, $2, $3, $4, $5)`,
[uuid.v4(), projectId, environmentId, action, lastActive]
[randomUUID(), projectId, environmentId, action, lastActive]
)
);
});
after(() =>
pgPool.query("delete from action where project_id = $1", [projectId])
);
after(() => pgPool.query("delete from action where project_id = $1", [projectId]));

describe("searching 2017-03-29 00:00:00 to 2017-03-30 00:00:00", () => {
it('should return "a.update" and "a.get".', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/_processor/models/action/upsert.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as uuid from "uuid";
import moment from "moment";
import { PoolClient } from "pg";
import { randomUUID } from "crypto";

export default async function (opts, pg: PoolClient) {
const action = {
id: uuid.v4().replace(/-/g, ""),
id: randomUUID().replace(/-/g, ""),
project_id: opts.projectId,
environment_id: opts.environmentId,
created: moment().valueOf(),
Expand Down
26 changes: 11 additions & 15 deletions src/_processor/models/active_actor/test/select_top.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";
import * as uuid from "uuid";
import moment from "moment";
import { randomUUID } from "crypto";

import getPgPool from "../../../persistence/pg";
import selectTop from "../select_top";
Expand All @@ -12,16 +12,16 @@ describe("models.active_actor.select_top", () => {
First actor has 5 actions but none during search period.
Another actor has 1 action during search period.
Five more actors have 2 actions during search period.`, () => {
const projectId = uuid.v4();
const environmentId = uuid.v4();
const projectId = randomUUID();
const environmentId = randomUUID();
const actors = [
uuid.v4(),
uuid.v4(),
uuid.v4(),
uuid.v4(),
uuid.v4(),
uuid.v4(),
uuid.v4(),
randomUUID(),
randomUUID(),
randomUUID(),
randomUUID(),
randomUUID(),
randomUUID(),
randomUUID(),
];
const ref = moment.utc("2017-03-29");
const actions = [
Expand Down Expand Up @@ -60,11 +60,7 @@ describe("models.active_actor.select_top", () => {
)
);
});
after(() =>
pgPool.query("delete from active_actor where project_id = $1", [
projectId,
])
);
after(() => pgPool.query("delete from active_actor where project_id = $1", [projectId]));

describe("search 2017-03-29 00:00:00 to 2017-03-30 00:00:00", () => {
it("should return the counts for the five actors active during the search period", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/_processor/models/actor/upsert.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as uuid from "uuid";
import moment from "moment";
import { PoolClient } from "pg";
import { randomUUID } from "crypto";

export default async function (opts, pg: PoolClient) {
const actor = {
id: uuid.v4().replace(/-/g, ""),
id: randomUUID().replace(/-/g, ""),
foreign_id: opts.actor.id,
project_id: opts.projectId,
environment_id: opts.environmentId,
Expand Down
42 changes: 11 additions & 31 deletions src/_processor/models/environment/test/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as uuid from "uuid";
import { randomUUID } from "crypto";

import getPgPool from "../../../persistence/pg";

Expand All @@ -22,19 +22,10 @@ export function fixProject(project) {
) values
( $1, $2, $3 ),
( $4, $5, $6 )`,
[
project.prodEnvID,
"Prod",
project.id,
project.stageEnvID,
"Stage",
project.id,
]
[project.prodEnvID, "Prod", project.id, project.stageEnvID, "Stage", project.id]
)
);
after(() =>
pgPool.query(`delete from environment where project_id = $1`, [project.id])
);
after(() => pgPool.query(`delete from environment where project_id = $1`, [project.id]));

project.users.forEach((user) => {
before(() =>
Expand All @@ -48,9 +39,7 @@ export function fixProject(project) {
[user.id, user.email, user.timezone || "US/Pacific"]
)
);
after(() =>
pgPool.query(`delete from retraceduser where id = $1`, [user.id])
);
after(() => pgPool.query(`delete from retraceduser where id = $1`, [user.id]));

before(() =>
pgPool.query(
Expand All @@ -60,7 +49,7 @@ export function fixProject(project) {
) values (
$1, $2, $3
)`,
[uuid.v4(), project.id, user.id]
[randomUUID(), project.id, user.id]
)
);

Expand All @@ -73,24 +62,15 @@ export function fixProject(project) {
( $1, $2, $3, $3, 'xyz' ),
( $4, $5, $6, $6, 'xyz' )
`,
[
user.id,
project.prodEnvID,
user.prod,
user.id,
project.stageEnvID,
user.stage,
]
[user.id, project.prodEnvID, user.prod, user.id, project.stageEnvID, user.stage]
)
);
});
after(() => pgPool.query(`delete from projectuser where project_id = $1`, [project.id]));
after(() =>
pgPool.query(`delete from projectuser where project_id = $1`, [project.id])
);
after(() =>
pgPool.query(
`delete from environmentuser where environment_id in ($1, $2)`,
[project.prodEnvID, project.stageEnvID]
)
pgPool.query(`delete from environmentuser where environment_id in ($1, $2)`, [
project.prodEnvID,
project.stageEnvID,
])
);
}
Loading
Loading