-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.ts
87 lines (78 loc) · 2.09 KB
/
index.ts
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
import { Headers } from "node-fetch";
export async function retrieveRequestFromStdin<T extends any>(): Promise<T> {
return new Promise<T>((resolve, reject) => {
let inputRaw = "";
process.stdin.on("data", (chunk) => inputRaw += chunk);
process.stdin.on("end", async () => {
try {
const json = JSON.parse(inputRaw) as T;
resolve(json);
} catch (e) {
reject(e);
}
});
});
}
export function createFetchHeaders<R extends CheckRequest>(request: R): Headers {
const headers = new Headers();
if (request.source.basic_auth_username && request.source.basic_auth_password) {
const basicAuthUsername = request.source.basic_auth_username;
const basicAuthPassword = request.source.basic_auth_password;
headers.append("Authorization", `Basic ${new Buffer(basicAuthUsername + ":" + basicAuthPassword).toString("base64")}`);
}
return headers;
}
interface Request {
source: {
server_url: string
chart_name: string
version_range?: string
basic_auth_username?: string
basic_auth_password?: string
harbor_api?: boolean
}
}
export interface CheckRequest extends Request {
version?: {
version: string
digest: string
}
}
export type CheckResponse = {
version: string
digest: string
}[];
export interface InRequest extends CheckRequest {
version: {
version: string,
digest: string
},
params: {
target_basename?: string
}
}
export interface InResponse {
version: {
version: string
digest: string
}
metadata: {
name: string
value: string
}[]
}
export interface OutRequest extends Request {
params: {
chart: string
sign?: boolean
key_data?: string
key_file?: string
key_passphrase?: string
version?: string
version_file?: string
force?: boolean
dependency_update?: boolean
}
}
export interface OutResponse extends InResponse {
}