mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
feat(infisical-pg): made api key backward compat
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user