-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplatform.js
90 lines (76 loc) · 1.91 KB
/
platform.js
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
import { createClient } from "webdav";
import logger from "./logger";
/**
* Fetches the platforms JSON from the OEM Share.
* @param {string} username - The username of the OEM.
* @returns {Promise<Platform[]>} - The platforms.
**/
async function fetch(username) {
const password = Bun.env.WEBDAV_PASSWORD;
if (!password) {
throw new Error("env WEBDAV_PASSWORD is not set");
}
const platforms_path = `https://oem-share.canonical.com/share/${username}/Platforms`;
const client = createClient(platforms_path, { username, password });
const bytes = await client.getFileContents("platform-tracker.json");
const platforms = JSON.parse(bytes.toString());
return platforms.map(p => new Platform(p));
}
/** A wrapper around the platform JSON. */
export class Platform {
#inner;
/**
* Override the code name of the platform.
* @type {string}
**/
#codeName;
constructor(inner) {
this.#inner = inner;
this.#codeName = null;
}
get name() {
const KEY = "Platform";
return this.#inner[KEY];
}
get altName() {
const KEY = "Code_Name";
return this.#inner[KEY];
}
get altNames() {
return [this.name, this.altName];
}
set codeName(value) {
this.#codeName = value;
}
get codeName() {
const KEY = "Canonical_Platform_Code_name";
return this.#codeName || this.#inner[KEY];
}
get status() {
const KEY = "Status";
return this.#inner[KEY];
}
get isActive() {
const VALUES = ["In-Flight", "Pipeline"];
return VALUES.includes(this.status);
}
get tag() {
const KEYS = [
"Official_Tag",
"LP_tag_short",
];
for (const key of KEYS) {
const value = this.#inner[key];
if (value) {
logger.info(`key: ${key} value: ${value}`);
return value;
}
}
return this.codeName;
}
get engineer() {
const KEY = "Canonical_Eng";
return this.#inner[KEY];
}
}
export default fetch;