Skip to content

Commit

Permalink
Merge pull request #100 from dfpc-coe/marti
Browse files Browse the repository at this point in the history
Remove Marti Connection Endpoints
  • Loading branch information
ingalls authored Feb 9, 2024
2 parents e8074ad + 34534a8 commit 9fd534f
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 274 deletions.
19 changes: 2 additions & 17 deletions api/routes/marti-mission-logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ export default async function router(schema: any, config: Config) {
auth: 'user',
':name': 'string',
description: 'Helper API to add a log to a mission',
query: {
type: 'object',
properties: {
connection: {
type: 'integer'
},
}
},
body: {
type: 'object',
required: ['content'],
Expand All @@ -41,15 +33,8 @@ export default async function router(schema: any, config: Config) {
try {
const user = await Auth.as_user(config.models, req);

let auth;
let creatorUid;
if (req.query.connection) {
auth = (await config.models.Connection.from(parseInt(String(req.query.connection)))).auth;
creatorUid = `CloudTAK-Conn-${req.query.connection}`;
} else {
auth = (await config.models.Profile.from(user.email)).auth;
creatorUid = user.email;
}
const auth = (await config.models.Profile.from(user.email)).auth;
const creatorUid = user.email;
const api = await TAKAPI.init(new URL(String(config.server.api)), new APIAuthCertificate(auth.cert, auth.key));

const mission = await api.MissionLog.create(req.params.name, {
Expand Down
101 changes: 18 additions & 83 deletions api/routes/marti-mission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ export default async function router(schema: any, config: Config) {
query: {
type: 'object',
properties: {
connection: {
type: 'integer'
},
password: {
type: 'boolean',
default: false,
Expand All @@ -44,13 +41,8 @@ export default async function router(schema: any, config: Config) {
try {
await Auth.is_auth(config.models, req);

let auth;
if (req.query.connection) {
auth = (await config.models.Connection.from(parseInt(String(req.query.connection)))).auth;
} else {
const user = await Auth.as_user(config.models, req);
auth = (await config.models.Profile.from(user.email)).auth;
}
const user = await Auth.as_user(config.models, req);
const auth = (await config.models.Profile.from(user.email)).auth;
const api = await TAKAPI.init(new URL(String(config.server.api)), new APIAuthCertificate(auth.cert, auth.key));

const query = {};
Expand All @@ -71,9 +63,6 @@ export default async function router(schema: any, config: Config) {
query: {
type: 'object',
properties: {
connection: {
type: 'integer'
},
creatorUid: {
type: 'string'
},
Expand All @@ -87,13 +76,8 @@ export default async function router(schema: any, config: Config) {
try {
await Auth.is_auth(config.models, req);

let auth;
if (req.query.connection) {
auth = (await config.models.Connection.from(parseInt(String(req.query.connection)))).auth;
} else {
const user = await Auth.as_user(config.models, req);
auth = (await config.models.Profile.from(user.email)).auth;
}
const user = await Auth.as_user(config.models, req);
const auth = (await config.models.Profile.from(user.email)).auth;
const api = await TAKAPI.init(new URL(String(config.server.api)), new APIAuthCertificate(auth.cert, auth.key));

const query = {};
Expand All @@ -115,7 +99,6 @@ export default async function router(schema: any, config: Config) {
type: 'object',
additionalProperties: false,
properties: {
connection: { type: 'integer' },
creatorUid: { type: 'string' },
group: { type: 'array', items: { type: 'string' } },
description: { type: 'string' },
Expand All @@ -138,13 +121,8 @@ export default async function router(schema: any, config: Config) {
try {
await Auth.is_auth(config.models, req);

let auth;
if (req.query.connection) {
auth = (await config.models.Connection.from(parseInt(String(req.query.connection)))).auth;
} else {
const user = await Auth.as_user(config.models, req);
auth = (await config.models.Profile.from(user.email)).auth;
}
const user = await Auth.as_user(config.models, req);
const auth = (await config.models.Profile.from(user.email)).auth;
const api = await TAKAPI.init(new URL(String(config.server.api)), new APIAuthCertificate(auth.cert, auth.key));

const query: any = {};
Expand All @@ -164,9 +142,6 @@ export default async function router(schema: any, config: Config) {
query: {
type: 'object',
properties: {
connection: {
type: 'integer'
},
passwordProtected: {
type: 'boolean',
default: false,
Expand All @@ -187,13 +162,8 @@ export default async function router(schema: any, config: Config) {
try {
await Auth.is_auth(config.models, req);

let auth;
if (req.query.connection) {
auth = (await config.models.Connection.from(parseInt(String(req.query.connection)))).auth;
} else {
const user = await Auth.as_user(config.models, req);
auth = (await config.models.Profile.from(user.email)).auth;
}
const user = await Auth.as_user(config.models, req);
const auth = (await config.models.Profile.from(user.email)).auth;
const api = await TAKAPI.init(new URL(String(config.server.api)), new APIAuthCertificate(auth.cert, auth.key));

const query = {};
Expand All @@ -211,13 +181,6 @@ export default async function router(schema: any, config: Config) {
auth: 'user',
':name': 'string',
description: 'List contacts associated with a mission',
query: {
type: 'object',
additionalProperties: false,
properties: {
connection: { type: 'integer' },
}
},
res: {
type: 'array',
items: {
Expand All @@ -239,13 +202,8 @@ export default async function router(schema: any, config: Config) {
try {
await Auth.is_auth(config.models, req);

let auth;
if (req.query.connection) {
auth = (await config.models.Connection.from(parseInt(String(req.query.connection)))).auth;
} else {
const user = await Auth.as_user(config.models, req);
auth = (await config.models.Profile.from(user.email)).auth;
}
const user = await Auth.as_user(config.models, req);
const auth = (await config.models.Profile.from(user.email)).auth;
const api = await TAKAPI.init(new URL(String(config.server.api)), new APIAuthCertificate(auth.cert, auth.key));

const missions = await api.Mission.contacts(String(req.params.name));
Expand Down Expand Up @@ -274,23 +232,12 @@ export default async function router(schema: any, config: Config) {
res: 'res.Marti.json'
}, async (req: AuthRequest, res: Response) => {
try {
let auth;
let creatorUid;
if (req.query.connection) {
const connection = await config.models.Connection.from(parseInt(String(req.query.connection)));

await Auth.is_auth(config.models, req);

auth = connection.auth;
creatorUid = `CloudTAK-Conn-${req.query.connection}`;
} else {
await Auth.is_auth(config.models, req);
await Auth.is_auth(config.models, req);

const user = await Auth.as_user(config.models, req);
const profile = await config.models.Profile.from(user.email);
auth = profile.auth;
creatorUid = profile.username;
}
const user = await Auth.as_user(config.models, req);
const profile = await config.models.Profile.from(user.email);
const auth = profile.auth;
const creatorUid = profile.username;

const name = String(req.query.name);

Expand Down Expand Up @@ -324,26 +271,14 @@ export default async function router(schema: any, config: Config) {
':name': 'string',
':hash': 'string',
description: 'Delete an upload by hash',
query: {
type: 'object',
additionalProperties: false,
properties: {
connection: { type: 'integer' },
}
},
res: 'res.Marti.json'
}, async (req: AuthRequest, res: Response) => {
try {
await Auth.is_auth(config.models, req);

let auth;
if (req.query.connection) {
auth = (await config.models.Connection.from(parseInt(String(req.query.connection)))).auth;
} else {
const user = await Auth.as_user(config.models, req);
const profile = await config.models.Profile.from(user.email);
auth = profile.auth;
}
const user = await Auth.as_user(config.models, req);
const profile = await config.models.Profile.from(user.email);
const auth = profile.auth;

const name = String(req.query.name);

Expand Down
Loading

0 comments on commit 9fd534f

Please sign in to comment.