Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat(infisical-pg): made api key backward compat

Akhil Mohandeab700716d8
diff --git a/backend-pg/src/db/migrations/20231207105059_api-key.ts b/backend-pg/src/db/migrations/20231207105059_api-key.ts
index 4758973dad..bb65ffadfd 100644
--- a/backend-pg/src/db/migrations/20231207105059_api-key.ts
+++ b/backend-pg/src/db/migrations/20231207105059_api-key.ts
@@ -7,7 +7,7 @@ export async function up(knex: Knex): Promise<void> {
const isTablePresent = await knex.schema.hasTable(TableName.ApiKey);
if (!isTablePresent) {
await knex.schema.createTable(TableName.ApiKey, (t) => {
- t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid());
+ t.string("id", 36).primary().defaultTo(knex.fn.uuid());
t.string("name").notNullable();
t.datetime("lastUsed");
t.datetime("expiresAt");
diff --git a/backend-pg/src/db/schemas/api-keys.ts b/backend-pg/src/db/schemas/api-keys.ts
index 32e5ef6c89..c3f384a5af 100644
--- a/backend-pg/src/db/schemas/api-keys.ts
+++ b/backend-pg/src/db/schemas/api-keys.ts
@@ -8,7 +8,7 @@ import { z } from "zod";
import { TImmutableDBKeys } from "./models";
export const ApiKeysSchema = z.object({
- id: z.string().uuid(),
+ id: z.string(),
name: z.string(),
lastUsed: z.date().nullable().optional(),
expiresAt: z.date().nullable().optional(),
diff --git a/pg-migrator/src/index.ts b/pg-migrator/src/index.ts
index df4cd927f3..aec6b424e6 100644
--- a/pg-migrator/src/index.ts
+++ b/pg-migrator/src/index.ts
@@ -536,15 +536,13 @@ const main = async () => {
postgresTableName: TableName.ApiKey,
returnKeys: ["id"],
preProcessing: async (doc) => {
- const id = uuidV4();
-
const userId = await userKv.get(doc.user.toString()).catch(() => null);
if (!userId) return;
// expired tokens can be removed
if (new Date(doc.expiresAt) < new Date()) return;
return {
- id,
+ id: doc._id.toString(),
userId,
name: doc.name,
lastUsed: doc.lastUsed,
diff --git a/pg-migrator/src/models/apiKeyData.ts b/pg-migrator/src/models/apiKeyData.ts
index 67a962b25c..ac6a09358f 100644
--- a/pg-migrator/src/models/apiKeyData.ts
+++ b/pg-migrator/src/models/apiKeyData.ts
@@ -1,39 +1,39 @@
import { Schema, Types, model } from "mongoose";
export interface IAPIKeyData {
- name: string;
- user: Types.ObjectId;
- lastUsed: Date;
- expiresAt: Date;
- secretHash: string;
+ _id: Types.ObjectId;
+ name: string;
+ user: Types.ObjectId;
+ lastUsed: Date;
+ expiresAt: Date;
+ secretHash: string;
}
const apiKeyDataSchema = new Schema<IAPIKeyData>(
- {
- name: {
- type: String,
- required: true,
- },
- user: {
- type: Schema.Types.ObjectId,
- ref: "User",
- required: true,
- },
- lastUsed: {
- type: Date,
- },
- expiresAt: {
- type: Date,
- },
- secretHash: {
- type: String,
- required: true,
-
- },
- },
- {
- timestamps: true,
- }
+ {
+ name: {
+ type: String,
+ required: true,
+ },
+ user: {
+ type: Schema.Types.ObjectId,
+ ref: "User",
+ required: true,
+ },
+ lastUsed: {
+ type: Date,
+ },
+ expiresAt: {
+ type: Date,
+ },
+ secretHash: {
+ type: String,
+ required: true,
+ },
+ },
+ {
+ timestamps: true,
+ },
);
-export const APIKeyData = model<IAPIKeyData>("APIKeyData", apiKeyDataSchema);
\ No newline at end of file
+export const APIKeyData = model<IAPIKeyData>("APIKeyData", apiKeyDataSchema);
diff --git a/pg-migrator/src/schemas/api-keys.ts b/pg-migrator/src/schemas/api-keys.ts
index 32e5ef6c89..c3f384a5af 100644
--- a/pg-migrator/src/schemas/api-keys.ts
+++ b/pg-migrator/src/schemas/api-keys.ts
@@ -8,7 +8,7 @@ import { z } from "zod";
import { TImmutableDBKeys } from "./models";
export const ApiKeysSchema = z.object({
- id: z.string().uuid(),
+ id: z.string(),
name: z.string(),
lastUsed: z.date().nullable().optional(),
expiresAt: z.date().nullable().optional(),