Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/util/db-schema/api-keys.ts
1447 views
1
import { Table } from "./types";
2
import { CREATED_BY, ID } from "./crm";
3
4
export type Action = "get" | "delete" | "create" | "edit";
5
6
export interface ApiKey {
7
id: number;
8
account_id: string;
9
created: Date;
10
hash?: string; // usually NOT available
11
trunc: string;
12
project_id?: string; // only for project api keys
13
expire?: Date;
14
name: string;
15
last_active?: Date;
16
secret?: string; // only when initially creating the key (and never in database)
17
}
18
19
Table({
20
name: "api_keys",
21
fields: {
22
id: ID,
23
account_id: CREATED_BY, // who made this api key
24
expire: {
25
type: "timestamp",
26
desc: "When this api key expires and is automatically deleted.",
27
},
28
created: {
29
type: "timestamp",
30
desc: "When this api key was created.",
31
},
32
hash: {
33
type: "string",
34
pg_type: "VARCHAR(173)",
35
desc: "Hash of the api key. This is the same hash as for user passwords, which is 1000 iterations of sha512 with salt of length 32.",
36
},
37
name: {
38
type: "string",
39
pg_type: "VARCHAR(128)",
40
desc: "user defined name of this key",
41
},
42
trunc: {
43
type: "string",
44
pg_type: "VARCHAR(16)",
45
desc: "Truncated version of the actual api key, suitable for display to remind user which key it is.",
46
},
47
project_id: {
48
type: "uuid",
49
desc: "Optional uuid of the project that this api key applies to. If not set, api key is global.",
50
},
51
last_active: {
52
type: "timestamp",
53
desc: "When this api key was last used.",
54
},
55
},
56
rules: {
57
primary_key: "id",
58
pg_indexes: [
59
"((created IS NOT NULL))",
60
"((account_id IS NOT NULL))",
61
"project_id",
62
],
63
},
64
});
65
66