Skip to content

Commit db053f8

Browse files
committed
Add getCredFile RPC endpoint and print <id> command
1 parent 63c689f commit db053f8

4 files changed

Lines changed: 26 additions & 0 deletions

File tree

build/src/src/api/routes.ts

Lines changed: 7 additions & 0 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,
@@ -57,6 +63,7 @@ export interface Routes {
5763

5864
export const routesData: { [P in keyof Routes]: {} } = {
5965
addDevice: {},
66+
getCredFile: {},
6067
getDeviceCredentials: {},
6168
getMasterAdminCred: {},
6269
getStatus: {},

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/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from "./addDevice";
2+
export * from "./getCredFile";
23
export * from "./getDeviceCredentials";
34
export * from "./getMasterAdminCred";
45
export * from "./getStatus";

build/src/src/vpncli.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ yargs
6363
console.log(chalk.green(`Credentials generated for ${id}:\n${url}`));
6464
}
6565
})
66+
.command({
67+
command: "print <id>",
68+
describe: "Print config file to stdout.",
69+
builder: idArg,
70+
handler: async ({ id }) => {
71+
const credFile = await api.getCredFile({ id });
72+
console.log(credFile);
73+
}
74+
})
6675
.command({
6776
command: "add <id>",
6877
describe: "Add device.",

0 commit comments

Comments
 (0)