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

This commit is contained in:
Akhil Mohan
2024-01-27 12:40:37 +05:30
parent 4d184003a8
commit deab700716
5 changed files with 35 additions and 37 deletions
+1 -3
View File
@@ -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,
+31 -31
View File
@@ -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);
export const APIKeyData = model<IAPIKeyData>("APIKeyData", apiKeyDataSchema);
+1 -1
View File
@@ -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(),