Skip to content

Commit

Permalink
Attempting to fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
cheesegrits committed Dec 11, 2024
1 parent bdb544c commit 51af891
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions api/routes/connection.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Err from '@openaddresses/batch-error';
import {sql, and, inArray} from 'drizzle-orm';
import { sql, and, inArray } from 'drizzle-orm';
import Config from '../lib/config.js';
import CW from '../lib/aws/metric.js';
import Auth, {AuthResourceAccess} from '../lib/auth.js';
import {X509Certificate} from 'crypto';
import {Type} from '@sinclair/typebox'
import {StandardResponse, ConnectionResponse} from '../lib/types.js';
import {Connection} from '../lib/schema.js';
import {MachineConnConfig} from '../lib/connection-config.js';
import Auth, { AuthResourceAccess } from '../lib/auth.js';
import { X509Certificate } from 'crypto';
import { Type } from '@sinclair/typebox'
import { StandardResponse, ConnectionResponse } from '../lib/types.js';
import { Connection } from '../lib/schema.js';
import { MachineConnConfig } from '../lib/connection-config.js';
import Schema from '@openaddresses/batch-schema';
import * as Default from '../lib/limits.js';

Expand All @@ -22,15 +22,15 @@ export default async function router(schema: Schema, config: Config) {
limit: Default.Limit,
page: Default.Page,
order: Default.Order,
sort: Type.Optional(Type.String({default: 'created', enum: Object.keys(Connection)})),
sort: Type.Optional(Type.String({ default: 'created', enum: Object.keys(Connection) })),
filter: Default.Filter
}),
res: Type.Object({
total: Type.Integer(),
status: Type.Object({
dead: Type.Integer({description: 'The connection is not currently connected to a TAK server'}),
live: Type.Integer({description: 'The connection is currently connected to a TAK server'}),
unknown: Type.Integer({description: 'The status of the connection could not be determined'}),
dead: Type.Integer({ description: 'The connection is not currently connected to a TAK server' }),
live: Type.Integer({ description: 'The connection is currently connected to a TAK server' }),
unknown: Type.Integer({ description: 'The status of the connection could not be determined' }),
}),
items: Type.Array(ConnectionResponse)
})
Expand Down Expand Up @@ -64,13 +64,13 @@ export default async function router(schema: Schema, config: Config) {

const json = {
total: list.total,
status: {dead: 0, live: 0, unknown: 0},
status: { dead: 0, live: 0, unknown: 0 },
items: list.items.map((conn) => {
const {validFrom, validTo, subject} = new X509Certificate(conn.auth.cert);
const { validFrom, validTo, subject } = new X509Certificate(conn.auth.cert);

return {
status: config.conns.status(conn.id),
certificate: {validFrom, validTo, subject},
certificate: { validFrom, validTo, subject },
...conn
}
})
Expand All @@ -94,12 +94,12 @@ export default async function router(schema: Schema, config: Config) {
body: Type.Object({
name: Default.NameField,
description: Default.DescriptionField,
enabled: Type.Optional(Type.Boolean({default: true})),
agency: Type.Union([Type.Null(), Type.Optional(Type.Integer({minimum: 1}))]),
enabled: Type.Optional(Type.Boolean({ default: true })),
agency: Type.Union([Type.Null(), Type.Optional(Type.Integer({ minimum: 1 }))]),
integrationId: Type.Union([Type.Integer(), Type.Null()]),
auth: Type.Object({
key: Type.String({minLength: 1, maxLength: 4096}),
cert: Type.String({minLength: 1, maxLength: 4096})
key: Type.String({ minLength: 1, maxLength: 4096 }),
cert: Type.String({ minLength: 1, maxLength: 4096 })
})
}),
res: ConnectionResponse
Expand All @@ -122,7 +122,7 @@ export default async function router(schema: Schema, config: Config) {

if (conn.enabled) await config.conns.add(new MachineConnConfig(config, conn));

const {validFrom, validTo, subject} = new X509Certificate(conn.auth.cert);
const { validFrom, validTo, subject } = new X509Certificate(conn.auth.cert);

if (req.body.integrationId) {
if (!profile.id) throw new Err(400, null, 'External ID must be set on profile');
Expand All @@ -135,7 +135,7 @@ export default async function router(schema: Schema, config: Config) {

res.json({
status: config.conns.status(conn.id),
certificate: {validFrom, validTo, subject},
certificate: { validFrom, validTo, subject },
...conn
});
} catch (err) {
Expand All @@ -148,27 +148,27 @@ export default async function router(schema: Schema, config: Config) {
group: 'Connection',
description: 'Update a connection',
params: Type.Object({
connectionid: Type.Integer({minimum: 1})
connectionid: Type.Integer({ minimum: 1 })
}),
body: Type.Object({
name: Type.Optional(Default.NameField),
description: Type.Optional(Default.DescriptionField),
enabled: Type.Optional(Type.Boolean()),
agency: Type.Union([Type.Null(), Type.Optional(Type.Integer({minimum: 1}))]),
agency: Type.Union([Type.Null(), Type.Optional(Type.Integer({ minimum: 1 }))]),
auth: Type.Optional(Type.Object({
key: Type.String({minLength: 1, maxLength: 4096}),
cert: Type.String({minLength: 1, maxLength: 4096})
key: Type.String({ minLength: 1, maxLength: 4096 }),
cert: Type.String({ minLength: 1, maxLength: 4096 })
}))
}),
res: ConnectionResponse
}, async (req, res) => {
try {
await Auth.is_connection(config, req, {
resources: [{access: AuthResourceAccess.CONNECTION, id: req.params.connectionid}]
resources: [{ access: AuthResourceAccess.CONNECTION, id: req.params.connectionid }]
}, req.params.connectionid);

if (req.body.agency && await Auth.is_user(config, req)) {
const user = await Auth.as_user(config, req, {admin: true});
const user = await Auth.as_user(config, req, { admin: true });
if (!user) throw new Err(400, null, 'Only System Admins can change an agency once a connection is created');
}

Expand All @@ -185,11 +185,11 @@ export default async function router(schema: Schema, config: Config) {
await config.conns.add(new MachineConnConfig(config, conn));
}

const {validFrom, validTo, subject} = new X509Certificate(conn.auth.cert);
const { validFrom, validTo, subject } = new X509Certificate(conn.auth.cert);

res.json({
status: config.conns.status(conn.id),
certificate: {validFrom, validTo, subject},
certificate: { validFrom, validTo, subject },
...conn
});
} catch (err) {
Expand All @@ -202,21 +202,21 @@ export default async function router(schema: Schema, config: Config) {
group: 'Connection',
description: 'Get a connection',
params: Type.Object({
connectionid: Type.Integer({minimum: 1})
connectionid: Type.Integer({ minimum: 1 })
}),
res: ConnectionResponse
}, async (req, res) => {
try {
await Auth.is_connection(config, req, {
resources: [{access: AuthResourceAccess.CONNECTION, id: req.params.connectionid}]
resources: [{ access: AuthResourceAccess.CONNECTION, id: req.params.connectionid }]
}, req.params.connectionid);

const conn = await config.models.Connection.from(req.params.connectionid);
const {validFrom, validTo, subject} = new X509Certificate(conn.auth.cert);
const { validFrom, validTo, subject } = new X509Certificate(conn.auth.cert);

res.json({
status: config.conns.status(conn.id),
certificate: {validFrom, validTo, subject},
certificate: { validFrom, validTo, subject },
...conn
});
} catch (err) {
Expand All @@ -229,13 +229,13 @@ export default async function router(schema: Schema, config: Config) {
group: 'Connection',
description: 'Refresh a connection',
params: Type.Object({
connectionid: Type.Integer({minimum: 1})
connectionid: Type.Integer({ minimum: 1 })
}),
res: ConnectionResponse
}, async (req, res) => {
try {
await Auth.is_connection(config, req, {
resources: [{access: AuthResourceAccess.CONNECTION, id: req.params.connectionid}]
resources: [{ access: AuthResourceAccess.CONNECTION, id: req.params.connectionid }]
}, req.params.connectionid);

const conn = await config.models.Connection.from(req.params.connectionid);
Expand All @@ -249,11 +249,11 @@ export default async function router(schema: Schema, config: Config) {
await config.conns.add(new MachineConnConfig(config, conn));
}

const {validFrom, validTo, subject} = new X509Certificate(conn.auth.cert);
const { validFrom, validTo, subject } = new X509Certificate(conn.auth.cert);

res.json({
status: config.conns.status(conn.id),
certificate: {validFrom, validTo, subject},
certificate: { validFrom, validTo, subject },
...conn
});
} catch (err) {
Expand All @@ -266,7 +266,7 @@ export default async function router(schema: Schema, config: Config) {
group: 'Connection',
description: 'Delete a connection',
params: Type.Object({
connectionid: Type.Integer({minimum: 1})
connectionid: Type.Integer({ minimum: 1 })
}),
res: StandardResponse
}, async (req, res) => {
Expand Down Expand Up @@ -323,7 +323,7 @@ export default async function router(schema: Schema, config: Config) {
group: 'Connection',
description: 'Return Conn Success/Failure Stats',
params: Type.Object({
connectionid: Type.Integer({minimum: 1})
connectionid: Type.Integer({ minimum: 1 })
}),
res: Type.Object({
stats: Type.Array(Type.Object({
Expand All @@ -334,7 +334,7 @@ export default async function router(schema: Schema, config: Config) {
}, async (req, res) => {
try {
await Auth.is_connection(config, req, {
resources: [{access: AuthResourceAccess.CONNECTION, id: req.params.connectionid}]
resources: [{ access: AuthResourceAccess.CONNECTION, id: req.params.connectionid }]
}, req.params.connectionid);

const conn = await config.models.Connection.from(req.params.connectionid);
Expand All @@ -345,7 +345,7 @@ export default async function router(schema: Schema, config: Config) {
const map: Map<string, number> = new Map();

if (!stats.length) {
res.json({stats: []});
res.json({ stats: [] });
} else {
const stat = stats[0];

Expand All @@ -368,7 +368,7 @@ export default async function router(schema: Schema, config: Config) {
label: string;
success: number;
}>
} = {stats: []}
} = { stats: [] }

for (const ts of ts_arr) {
statsres.stats.push({
Expand Down

0 comments on commit 51af891

Please sign in to comment.