Restore settings preferences and simplify services editor
This commit is contained in:
@@ -15,7 +15,7 @@ describe('render3proxyConfig', () => {
|
||||
|
||||
expect(config).toContain('socks -p1080 -u2');
|
||||
expect(config).toContain('socks -p2080 -u2');
|
||||
expect(config).toContain('admin -p8081 -s');
|
||||
expect(config).not.toContain('admin -p');
|
||||
expect(config).toContain('allow night-shift,ops-east');
|
||||
expect(config).toContain('allow lab-unlimited,burst-user');
|
||||
});
|
||||
|
||||
@@ -198,10 +198,6 @@ function renderUserCredential(user: ProxyUserRecord): string {
|
||||
}
|
||||
|
||||
function renderServiceCommand(service: ProxyServiceRecord): string {
|
||||
if (service.command === 'admin') {
|
||||
return `admin -p${service.port} -s`;
|
||||
}
|
||||
|
||||
if (service.command === 'socks') {
|
||||
return `socks -p${service.port} -u2`;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,14 @@ export class StateStore {
|
||||
|
||||
try {
|
||||
const raw = await fs.readFile(this.statePath, 'utf8');
|
||||
return JSON.parse(raw) as ControlPlaneState;
|
||||
const state = JSON.parse(raw) as ControlPlaneState;
|
||||
const migrated = migrateLegacyAdminServices(state);
|
||||
|
||||
if (migrated !== state) {
|
||||
await this.write(migrated);
|
||||
}
|
||||
|
||||
return migrated;
|
||||
} catch (error) {
|
||||
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {
|
||||
throw error;
|
||||
@@ -28,3 +35,28 @@ export class StateStore {
|
||||
await fs.writeFile(this.statePath, `${JSON.stringify(state, null, 2)}\n`, 'utf8');
|
||||
}
|
||||
}
|
||||
|
||||
function migrateLegacyAdminServices(state: ControlPlaneState): ControlPlaneState {
|
||||
const legacyServiceIds = new Set(
|
||||
state.system.services
|
||||
.filter((service) => (service as { command?: unknown }).command === 'admin')
|
||||
.map((service) => service.id),
|
||||
);
|
||||
|
||||
if (legacyServiceIds.size === 0) {
|
||||
return state;
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
service: {
|
||||
...state.service,
|
||||
lastEvent: 'Legacy admin service removed from stored panel state',
|
||||
},
|
||||
userRecords: state.userRecords.filter((user) => !legacyServiceIds.has(user.serviceId)),
|
||||
system: {
|
||||
...state.system,
|
||||
services: state.system.services.filter((service) => !legacyServiceIds.has(service.id)),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user