Continue work on API key

This commit is contained in:
Tuan Dang
2022-12-25 19:19:56 -05:00
parent d869968f88
commit 888d28d6b9
6 changed files with 131 additions and 39 deletions
@@ -1,12 +1,12 @@
import { Schema, model, Types } from 'mongoose';
import { ENV_DEV, ENV_TESTING, ENV_STAGING, ENV_PROD } from '../variables';
// TODO: add scopes
export interface IAPIKey {
export interface IAPIKeyData {
name: string;
workspace: string;
environment: string;
workspaces: {
workspace: Types.ObjectId,
environments: string[]
}[];
expiresAt: Date;
prefix: string;
apiKeyHash: string;
@@ -15,19 +15,22 @@ export interface IAPIKey {
tag: string;
}
const apiKeySchema = new Schema<IAPIKey>(
const apiKeyDataSchema = new Schema<IAPIKeyData>(
{
name: {
type: String,
required: true
},
workspace: {
type: String
},
environment: {
type: String,
enum: [ENV_DEV, ENV_TESTING, ENV_STAGING, ENV_PROD]
},
workspaces: [{
workspace: {
type: Schema.Types.ObjectId,
ref: 'Workspace'
},
environments: [{
type: String,
enum: [ENV_DEV, ENV_TESTING, ENV_STAGING, ENV_PROD]
}]
}],
expiresAt: {
type: Date
},
@@ -58,6 +61,6 @@ const apiKeySchema = new Schema<IAPIKey>(
}
);
const APIKey = model<IAPIKey>('APIKey', apiKeySchema);
const APIKeyData = model<IAPIKeyData>('APIKeyData', apiKeyDataSchema);
export default APIKey;
export default APIKeyData;
+3 -3
View File
@@ -14,7 +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';
import APIKeyData, { IAPIKeyData } from './apiKeyData';
export {
BackupPrivateKey,
@@ -49,6 +49,6 @@ export {
IUserAction,
Workspace,
IWorkspace,
APIKey,
IAPIKey,
APIKeyData,
IAPIKeyData,
};