CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

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