Skip to content

Commit 7668c9a

Browse files
authored
Merge pull request #189 from dappnode/dapplion/release-fixes
v0.2.8 Release fixes
2 parents 63c689f + 7535179 commit 7668c9a

16 files changed

Lines changed: 42 additions & 247 deletions

build/src/src/api/routes.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ export interface Routes {
88
*/
99
addDevice: (kwargs: { id: string }) => Promise<void>;
1010

11+
/**
12+
* Returns the credentials file (.ovpn) for device `id`
13+
* @param id "new-device"
14+
*/
15+
getCredFile({ id }: { id: string }): Promise<string>;
16+
1117
/**
1218
* Creates a new OpenVPN credentials file, encrypted.
1319
* The filename is the (16 chars short) result of hashing the generated salt in the db,
@@ -43,12 +49,6 @@ export interface Routes {
4349
*/
4450
resetDevice: (kwargs: { id: string }) => Promise<void>;
4551

46-
/**
47-
* Gives/removes admin rights to the provided device id.
48-
* @param id Device id name
49-
*/
50-
toggleAdmin: (kwargs: { id: string }) => Promise<void>;
51-
5252
/**
5353
* Returns a list of the existing devices, with the admin property
5454
*/
@@ -57,12 +57,12 @@ export interface Routes {
5757

5858
export const routesData: { [P in keyof Routes]: {} } = {
5959
addDevice: {},
60+
getCredFile: {},
6061
getDeviceCredentials: {},
6162
getMasterAdminCred: {},
6263
getStatus: {},
6364
removeDevice: {},
6465
resetDevice: {},
65-
toggleAdmin: {},
6666
listDevices: {}
6767
};
6868

build/src/src/calls/getCredFile.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { getClient } from "../openvpn";
2+
3+
/**
4+
* Returns the credentials file (.ovpn) for device `id`
5+
* @param id "new-device"
6+
*/
7+
export async function getCredFile({ id }: { id: string }): Promise<string> {
8+
return await getClient(id);
9+
}

build/src/src/calls/getMasterAdminCred.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { addDevice } from "./addDevice";
2-
import { toggleAdmin } from "./toggleAdmin";
32
import { MAIN_ADMIN_NAME } from "../params";
43
import { logs } from "../logs";
54
import { getDeviceCredentials } from "./getDeviceCredentials";
@@ -19,7 +18,6 @@ export async function getMasterAdminCred(): Promise<VpnDeviceCredentials> {
1918
logs.info(`User ${MAIN_ADMIN_NAME} already exists`);
2019
} else {
2120
await addDevice({ id: MAIN_ADMIN_NAME });
22-
await toggleAdmin({ id: MAIN_ADMIN_NAME });
2321
}
2422
} catch (e) {
2523
if (!e.message.includes("exist"))

build/src/src/calls/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
export * from "./addDevice";
2+
export * from "./getCredFile";
23
export * from "./getDeviceCredentials";
34
export * from "./getMasterAdminCred";
45
export * from "./getStatus";
56
export * from "./getVersionData";
67
export * from "./listDevices";
78
export * from "./removeDevice";
89
export * from "./resetDevice";
9-
export * from "./toggleAdmin";

build/src/src/calls/listDevices.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
1-
import { getUserList, getCCD } from "../openvpn";
2-
import { VpnDevice, OpenVpnCCDItem } from "../types";
1+
import { getUserList } from "../openvpn";
2+
import { VpnDevice } from "../types";
33

44
/**
55
* Returns a list of the existing devices, with the admin property
66
*/
77
export async function listDevices(): Promise<VpnDevice[]> {
88
const userList = await getUserList();
9-
const ccd = getCCD();
10-
11-
const ccdById = ccd.reduce(
12-
(byId, device) => {
13-
return { ...byId, [device.cn]: device };
14-
},
15-
{} as { [id: string]: OpenVpnCCDItem }
16-
);
179

1810
return userList.map(user => ({
19-
id: user,
20-
admin: Boolean(ccdById[user]),
21-
ip: (ccdById[user] || {}).ip || ""
11+
id: user
2212
}));
2313
}

build/src/src/calls/removeDevice.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
import { getUserList, getCCD, removeClient } from "../openvpn";
1+
import { getUserList, removeClient } from "../openvpn";
22
import { MAIN_ADMIN_NAME } from "../params";
33

4+
export const REMOVE_MAIN_ADMIN_ERROR = "Cannot remove the main admin user";
5+
46
/**
57
* Removes the device with the provided id, if exists.
68
* @param id "new-device"
79
*/
810
export async function removeDevice({ id }: { id: string }): Promise<void> {
911
const deviceArray = await getUserList();
10-
const ccdArray = getCCD();
11-
12-
if (ccdArray.find(c => c.cn === id))
13-
throw Error("You cannot remove an admin user");
1412

1513
if (id === MAIN_ADMIN_NAME) {
16-
throw Error("Cannot remove the main admin user");
14+
throw Error(REMOVE_MAIN_ADMIN_ERROR);
1715
}
1816

1917
if (!deviceArray.includes(id)) {

build/src/src/calls/toggleAdmin.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

build/src/src/openvpn/admin.ts

Lines changed: 0 additions & 46 deletions
This file was deleted.

build/src/src/openvpn/getCCD.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

build/src/src/openvpn/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
export * from "./admin";
21
export * from "./buildClient";
3-
export * from "./getCCD";
42
export * from "./getClient";
53
export * from "./getUserList";
64
export * from "./openvpnBinary";

0 commit comments

Comments
 (0)