forked from finos/git-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
119 lines (108 loc) · 3.22 KB
/
types.ts
File metadata and controls
119 lines (108 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { Action } from '../proxy/actions/Action';
import MongoDBStore from 'connect-mongo';
export type PushQuery = {
error: boolean;
blocked: boolean;
allowPush: boolean;
authorised: boolean;
type: string;
[key: string]: QueryValue;
canceled: boolean;
rejected: boolean;
};
export type RepoQuery = {
name: string;
url: string;
project: string;
[key: string]: QueryValue;
};
export type UserQuery = {
username: string;
email: string;
[key: string]: QueryValue;
};
export type QueryValue = string | boolean | number | undefined;
export type UserRole = 'canPush' | 'canAuthorise';
export class Repo {
project: string;
name: string;
url: string;
users: { canPush: string[]; canAuthorise: string[] };
_id?: string;
constructor(
project: string,
name: string,
url: string,
users?: Record<UserRole, string[]>,
_id?: string,
) {
this.project = project;
this.name = name;
this.url = url;
this.users = users ?? { canPush: [], canAuthorise: [] };
this._id = _id;
}
}
export class User {
username: string;
password: string | null; // null if oidcId is set
gitAccount: string;
email: string;
admin: boolean;
oidcId?: string | null;
displayName?: string | null;
title?: string | null;
_id?: string;
constructor(
username: string,
password: string,
gitAccount: string,
email: string,
admin: boolean,
oidcId: string | null = null,
_id?: string,
) {
this.username = username;
this.password = password;
this.gitAccount = gitAccount;
this.email = email;
this.admin = admin;
this.oidcId = oidcId ?? null;
this._id = _id;
}
}
export interface PublicUser {
username: string;
displayName: string;
email: string;
title: string;
gitAccount: string;
admin: boolean;
}
export interface Sink {
getSessionStore: () => MongoDBStore | undefined;
getPushes: (query: Partial<PushQuery>) => Promise<Action[]>;
writeAudit: (action: Action) => Promise<void>;
getPush: (id: string) => Promise<Action | null>;
deletePush: (id: string) => Promise<void>;
authorise: (id: string, attestation: any) => Promise<{ message: string }>;
cancel: (id: string) => Promise<{ message: string }>;
reject: (id: string, rejection: any) => Promise<{ message: string }>;
getRepos: (query?: Partial<RepoQuery>) => Promise<Repo[]>;
getRepo: (name: string) => Promise<Repo | null>;
getRepoByUrl: (url: string) => Promise<Repo | null>;
getRepoById: (_id: string) => Promise<Repo | null>;
createRepo: (repo: Repo) => Promise<Repo>;
addUserCanPush: (_id: string, user: string) => Promise<void>;
addUserCanAuthorise: (_id: string, user: string) => Promise<void>;
removeUserCanPush: (_id: string, user: string) => Promise<void>;
removeUserCanAuthorise: (_id: string, user: string) => Promise<void>;
deleteRepo: (_id: string) => Promise<void>;
findUser: (username: string) => Promise<User | null>;
findUserByEmail: (email: string) => Promise<User | null>;
findUserByOIDC: (oidcId: string) => Promise<User | null>;
getUsers: (query?: Partial<UserQuery>) => Promise<User[]>;
createUser: (user: User) => Promise<void>;
deleteUser: (username: string) => Promise<void>;
updateUser: (user: Partial<User>) => Promise<void>;
}