Begin api-key functionality on backend

This commit is contained in:
Tuan Dang
2022-12-25 12:45:43 -05:00
parent 2513250993
commit d869968f88
9 changed files with 658 additions and 35 deletions
+63
View File
@@ -0,0 +1,63 @@
import { Schema, model, Types } from 'mongoose';
import { ENV_DEV, ENV_TESTING, ENV_STAGING, ENV_PROD } from '../variables';
// TODO: add scopes
export interface IAPIKey {
name: string;
workspace: string;
environment: string;
expiresAt: Date;
prefix: string;
apiKeyHash: string;
encryptedKey: string;
iv: string;
tag: string;
}
const apiKeySchema = new Schema<IAPIKey>(
{
name: {
type: String,
required: true
},
workspace: {
type: String
},
environment: {
type: String,
enum: [ENV_DEV, ENV_TESTING, ENV_STAGING, ENV_PROD]
},
expiresAt: {
type: Date
},
prefix: {
type: String,
required: true
},
apiKeyHash: {
type: String,
unique: true,
required: true
},
encryptedKey: {
type: String,
select: true
},
iv: {
type: String,
select: true
},
tag: {
type: String,
select: true
}
},
{
timestamps: true
}
);
const APIKey = model<IAPIKey>('APIKey', apiKeySchema);
export default APIKey;
+4 -1
View File
@@ -14,6 +14,7 @@ import Token, { IToken } from './token';
import User, { IUser } from './user';
import UserAction, { IUserAction } from './userAction';
import Workspace, { IWorkspace } from './workspace';
import APIKey, { IAPIKey } from './apiKey';
export {
BackupPrivateKey,
@@ -47,5 +48,7 @@ export {
UserAction,
IUserAction,
Workspace,
IWorkspace
IWorkspace,
APIKey,
IAPIKey,
};