Implement Harbor gateway device ecosystem support
This commit is contained in:
@@ -7,6 +7,9 @@ interface DeviceInventoryPort {
|
||||
snapshot(): unknown;
|
||||
refresh(): Promise<unknown>;
|
||||
update(deviceId: string, patch: Record<string, unknown>, expectedRevision: unknown): unknown;
|
||||
createTag(name: unknown, expectedRevision: unknown): unknown;
|
||||
renameTag(tagId: string, name: unknown, expectedRevision: unknown): unknown;
|
||||
deleteTag(tagId: string, expectedRevision: unknown): unknown;
|
||||
resetTraffic(expectedRevision: unknown): Promise<unknown>;
|
||||
setPolicy(deviceId: string, mode: unknown, expectedRevision: unknown): Promise<unknown>;
|
||||
}
|
||||
@@ -18,6 +21,7 @@ interface DeviceInventoryRouteDependencies {
|
||||
|
||||
const DEVICE_PATH = /^\/api\/devices\/(dev_[a-f0-9]{16})$/;
|
||||
const DEVICE_POLICY_PATH = /^\/api\/devices\/(dev_[a-f0-9]{16})\/policy$/;
|
||||
const DEVICE_TAG_PATH = /^\/api\/device-tags\/(tag_[a-f0-9]{16})$/;
|
||||
|
||||
export function createDeviceInventoryRoute(dependencies: DeviceInventoryRouteDependencies) {
|
||||
return {
|
||||
@@ -49,6 +53,35 @@ export function createDeviceInventoryRoute(dependencies: DeviceInventoryRouteDep
|
||||
return true;
|
||||
}
|
||||
|
||||
if (pathname === '/api/device-tags') {
|
||||
if (!dependencies.deviceInventory || req.method !== 'POST') {
|
||||
throw new HarborError('ENDPOINT_NOT_FOUND');
|
||||
}
|
||||
const body = await dependencies.readBody(req);
|
||||
sendJson(
|
||||
res,
|
||||
200,
|
||||
dependencies.deviceInventory.createTag(body.name, body.expectedRevision),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
const tagMatch = pathname.match(DEVICE_TAG_PATH);
|
||||
if (tagMatch) {
|
||||
if (!dependencies.deviceInventory || !['PUT', 'DELETE'].includes(req.method || '')) {
|
||||
throw new HarborError('ENDPOINT_NOT_FOUND');
|
||||
}
|
||||
const body = await dependencies.readBody(req);
|
||||
sendJson(
|
||||
res,
|
||||
200,
|
||||
req.method === 'PUT'
|
||||
? dependencies.deviceInventory.renameTag(tagMatch[1], body.name, body.expectedRevision)
|
||||
: dependencies.deviceInventory.deleteTag(tagMatch[1], body.expectedRevision),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
const deviceMatch = pathname.match(DEVICE_PATH);
|
||||
if (deviceMatch) {
|
||||
if (!dependencies.deviceInventory || req.method !== 'PUT') {
|
||||
|
||||
Reference in New Issue
Block a user