Skip to content

Commit

Permalink
WIP: Start on network settings implementation for Ubuntu or Ubuntu Core
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrancis committed Sep 13, 2024
1 parent 3ef05a7 commit ac18d67
Show file tree
Hide file tree
Showing 8 changed files with 331 additions and 3 deletions.
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"config": "^3.3.4",
"country-list": "^2.2.0",
"csv-parse": "^4.15.3",
"dbus": "^1.0.7",
"express": "^4.17.1",
"express-fileupload": "^1.2.1",
"express-handlebars": "^5.3.5",
Expand Down Expand Up @@ -87,6 +88,7 @@
"@types/compression": "^1.7.0",
"@types/config": "0.0.38",
"@types/country-list": "^2.1.0",
"@types/dbus": "^1.0.9",
"@types/event-to-promise": "^0.7.1",
"@types/eventsource": "^1.1.6",
"@types/express": "^4.17.11",
Expand Down
1 change: 1 addition & 0 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ apps:
plugs:
- network
- network-bind
- network-manager

parts:
python-deps:
Expand Down
8 changes: 7 additions & 1 deletion src/controllers/settings_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import TunnelService from '../tunnel-service';
import * as CertificateManager from '../certificate-manager';
import pkg from '../package.json';
import { HttpErrorWithCode } from '../errors';
import { LanMode } from '../platforms/types';

function build(): express.Router {
const auth = jwtMiddleware.middleware();
Expand Down Expand Up @@ -397,7 +398,12 @@ function build(): express.Router {
});

controller.get('/network/lan', auth, (_request, response) => {
if (Platform.implemented('getLanMode')) {

if (Platform.implemented('getLanModeAsync')) {
Platform.getLanModeAsync().then((mode: LanMode) => {
response.json(mode);
});
} else if (Platform.implemented('getLanMode')) {
response.json(Platform.getLanMode());
} else {
response.status(500).send('LAN mode not implemented');
Expand Down
1 change: 1 addition & 0 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export const setDhcpServerStatus = wrapPlatform<boolean>(platform, 'setDhcpServe
export const getHostname = wrapPlatform<string>(platform, 'getHostname');
export const setHostname = wrapPlatform<boolean>(platform, 'setHostname');
export const getLanMode = wrapPlatform<LanMode>(platform, 'getLanMode');
export const getLanModeAsync = wrapPlatform<Promise<LanMode>>(platform, 'getLanModeAsync');
export const setLanMode = wrapPlatform<boolean>(platform, 'setLanMode');
export const getMacAddress = wrapPlatform<string | null>(platform, 'getMacAddress');
export const getMdnsServerStatus = wrapPlatform<boolean>(platform, 'getMdnsServerStatus');
Expand Down
9 changes: 9 additions & 0 deletions src/platforms/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ export default class BasePlatform {
throw new NotImplementedError('getLanMode');
}

/**
* Get the LAN mode and options asynchronously.
*
* @returns {Promise<LanMode>} {mode: 'static|dhcp|...', options: {...}}
*/
async getLanModeAsync(): Promise<LanMode> {
throw new NotImplementedError('getLanMode');
}

/**
* Set the LAN mode and options.
*
Expand Down
Loading

0 comments on commit ac18d67

Please sign in to comment.