scaler updates
This commit is contained in:
@@ -10,6 +10,7 @@ import { apiReference } from "@scalar/express-api-reference";
|
|||||||
// const port = 3000;
|
// const port = 3000;
|
||||||
import type { OpenAPIV3_1 } from "openapi-types";
|
import type { OpenAPIV3_1 } from "openapi-types";
|
||||||
import { cronerActiveJobs } from "../scaler/cronerActiveJobs.spec.js";
|
import { cronerActiveJobs } from "../scaler/cronerActiveJobs.spec.js";
|
||||||
|
import { cronerStatusChange } from "../scaler/cronerStatusChange.spec.js";
|
||||||
import { prodLoginSpec } from "../scaler/login.spec.js";
|
import { prodLoginSpec } from "../scaler/login.spec.js";
|
||||||
import { prodRestartSpec } from "../scaler/prodSqlRestart.spec.js";
|
import { prodRestartSpec } from "../scaler/prodSqlRestart.spec.js";
|
||||||
import { prodStartSpec } from "../scaler/prodSqlStart.spec.js";
|
import { prodStartSpec } from "../scaler/prodSqlStart.spec.js";
|
||||||
@@ -50,6 +51,11 @@ export const openApiBase: OpenAPIV3_1.Document = {
|
|||||||
scheme: "basic",
|
scheme: "basic",
|
||||||
description: "Basic authentication using username and password",
|
description: "Basic authentication using username and password",
|
||||||
},
|
},
|
||||||
|
cookieAuth: {
|
||||||
|
type: "apiKey",
|
||||||
|
in: "cookie",
|
||||||
|
name: "better-auth.session_token",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
// schemas: {
|
// schemas: {
|
||||||
// Error: {
|
// Error: {
|
||||||
@@ -61,7 +67,12 @@ export const openApiBase: OpenAPIV3_1.Document = {
|
|||||||
// },
|
// },
|
||||||
// },.
|
// },.
|
||||||
},
|
},
|
||||||
|
// security: [
|
||||||
|
// {
|
||||||
|
// cookieAuth: [],
|
||||||
|
// basicAuth: [],
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
tags: [
|
tags: [
|
||||||
{
|
{
|
||||||
name: "Auth",
|
name: "Auth",
|
||||||
@@ -109,6 +120,7 @@ export const setupApiDocsRoutes = (baseUrl: string, app: Express) => {
|
|||||||
...prodRegisterSpec,
|
...prodRegisterSpec,
|
||||||
//...mergedDatamart,
|
//...mergedDatamart,
|
||||||
...cronerActiveJobs,
|
...cronerActiveJobs,
|
||||||
|
...cronerStatusChange,
|
||||||
|
|
||||||
// Add more specs here as you build features
|
// Add more specs here as you build features
|
||||||
},
|
},
|
||||||
@@ -144,7 +156,7 @@ export const setupApiDocsRoutes = (baseUrl: string, app: Express) => {
|
|||||||
// Clojure
|
// Clojure
|
||||||
clojure: ["clj_http"],
|
clojure: ["clj_http"],
|
||||||
// C#
|
// C#
|
||||||
csharp: ["httpclient", "restsharp"],
|
// csharp: ["httpclient", "restsharp"],
|
||||||
// Dart
|
// Dart
|
||||||
dart: ["http"],
|
dart: ["http"],
|
||||||
// F#
|
// F#
|
||||||
|
|||||||
30
backend/middleware/auth.middleware.ts
Normal file
30
backend/middleware/auth.middleware.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { fromNodeHeaders } from "better-auth/node";
|
||||||
|
import type { NextFunction, Request, Response } from "express";
|
||||||
|
import { auth } from "../utils/auth.utils.js";
|
||||||
|
|
||||||
|
export const requireAuth = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction,
|
||||||
|
) => {
|
||||||
|
// TODO: add the real auth stuff in later.
|
||||||
|
try {
|
||||||
|
const session = await auth.api.getSession({
|
||||||
|
headers: fromNodeHeaders(req.headers),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!session) {
|
||||||
|
//return res.status(401).json({ error: "Unauthorized" });
|
||||||
|
console.info("not auth of course");
|
||||||
|
}
|
||||||
|
|
||||||
|
// attach session to request for later use
|
||||||
|
(req as any).session = session;
|
||||||
|
console.info(
|
||||||
|
"Just passing the middleware and reminder that we need to add the real stuff in.",
|
||||||
|
);
|
||||||
|
next();
|
||||||
|
} catch {
|
||||||
|
return res.status(401).json({ error: "Unauthorized" });
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,10 +1,17 @@
|
|||||||
import type { Express } from "express";
|
import { type Express, Router } from "express";
|
||||||
|
import { requireAuth } from "../middleware/auth.middleware.js";
|
||||||
import restart from "./prodSqlRestart.route.js";
|
import restart from "./prodSqlRestart.route.js";
|
||||||
import start from "./prodSqlStart.route.js";
|
import start from "./prodSqlStart.route.js";
|
||||||
import stop from "./prodSqlStop.route.js";
|
import stop from "./prodSqlStop.route.js";
|
||||||
export const setupProdSqlRoutes = (baseUrl: string, app: Express) => {
|
export const setupProdSqlRoutes = (baseUrl: string, app: Express) => {
|
||||||
//setup all the routes
|
//setup all the routes
|
||||||
app.use(`${baseUrl}/api/system/prodSql`, start);
|
// Apply auth to entire router
|
||||||
app.use(`${baseUrl}/api/system/prodSql`, stop);
|
const router = Router();
|
||||||
app.use(`${baseUrl}/api/system/prodSql`, restart);
|
router.use(requireAuth);
|
||||||
|
|
||||||
|
router.use(start);
|
||||||
|
router.use(stop);
|
||||||
|
router.use(restart);
|
||||||
|
|
||||||
|
app.use(`${baseUrl}/api/system/prodSql`, router);
|
||||||
};
|
};
|
||||||
|
|||||||
94
backend/scaler/cronerStatusChange.spec.ts
Normal file
94
backend/scaler/cronerStatusChange.spec.ts
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
import type { OpenAPIV3_1 } from "openapi-types";
|
||||||
|
|
||||||
|
export const cronerStatusChange: OpenAPIV3_1.PathsObject = {
|
||||||
|
"/api/utils/croner/{status}": {
|
||||||
|
patch: {
|
||||||
|
summary: "Pauses or Resume the Job",
|
||||||
|
description:
|
||||||
|
"When sending start or stop with job name it will resume or stop the job",
|
||||||
|
tags: ["Utils"],
|
||||||
|
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
name: "status",
|
||||||
|
in: "path",
|
||||||
|
required: true,
|
||||||
|
description: "Status change",
|
||||||
|
schema: {
|
||||||
|
type: "string",
|
||||||
|
},
|
||||||
|
example: "start",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "limit",
|
||||||
|
in: "query",
|
||||||
|
required: false, // 👈 optional
|
||||||
|
description: "Maximum number of records to return",
|
||||||
|
schema: {
|
||||||
|
type: "integer",
|
||||||
|
minimum: 1,
|
||||||
|
maximum: 100,
|
||||||
|
},
|
||||||
|
example: 10,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
requestBody: {
|
||||||
|
required: true,
|
||||||
|
content: {
|
||||||
|
"application/json": {
|
||||||
|
schema: {
|
||||||
|
type: "object",
|
||||||
|
required: ["name"],
|
||||||
|
properties: {
|
||||||
|
name: {
|
||||||
|
type: "string",
|
||||||
|
example: "start",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
responses: {
|
||||||
|
"200": {
|
||||||
|
description: "Successful response",
|
||||||
|
content: {
|
||||||
|
"application/json": {
|
||||||
|
schema: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
success: { type: "boolean", example: true },
|
||||||
|
data: {
|
||||||
|
type: "object",
|
||||||
|
example: {
|
||||||
|
name: "exampleName",
|
||||||
|
value: "some value",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
description: "Bad request",
|
||||||
|
content: {
|
||||||
|
"application/json": {
|
||||||
|
schema: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
success: { type: "boolean", example: false },
|
||||||
|
message: {
|
||||||
|
type: "string",
|
||||||
|
example: "Invalid name parameter",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -3,6 +3,7 @@ import type { OpenAPIV3_1 } from "openapi-types";
|
|||||||
export const prodRestartSpec: OpenAPIV3_1.PathsObject = {
|
export const prodRestartSpec: OpenAPIV3_1.PathsObject = {
|
||||||
"/api/system/prodSql/restart": {
|
"/api/system/prodSql/restart": {
|
||||||
post: {
|
post: {
|
||||||
|
//security: [],
|
||||||
summary: "Prod restart sql connection",
|
summary: "Prod restart sql connection",
|
||||||
description: "Attempts to restart the sql connection.",
|
description: "Attempts to restart the sql connection.",
|
||||||
tags: ["System"],
|
tags: ["System"],
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ r.patch("/:status", async (req, res) => {
|
|||||||
level: "info",
|
level: "info",
|
||||||
module: "utils",
|
module: "utils",
|
||||||
subModule: "jobs",
|
subModule: "jobs",
|
||||||
message: `${name} was restarted`,
|
message: `${body.name} was restarted`,
|
||||||
data: getAllJobs(),
|
data: getAllJobs(),
|
||||||
status: 200,
|
status: 200,
|
||||||
});
|
});
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { Express } from "express";
|
import type { Express } from "express";
|
||||||
import getActiveJobs from "./cronerActiveJobs.route.js";
|
import getActiveJobs from "./cronerActiveJobs.route.js";
|
||||||
import jobStatusChange from "./cronerStatusChange.js";
|
import jobStatusChange from "./cronerStatusChange.route.js";
|
||||||
export const setupUtilsRoutes = (baseUrl: string, app: Express) => {
|
export const setupUtilsRoutes = (baseUrl: string, app: Express) => {
|
||||||
app.use(`${baseUrl}/api/utils/croner`, getActiveJobs);
|
app.use(`${baseUrl}/api/utils/croner`, getActiveJobs);
|
||||||
app.use(`${baseUrl}/api/utils/croner`, jobStatusChange);
|
app.use(`${baseUrl}/api/utils/croner`, jobStatusChange);
|
||||||
|
|||||||
Reference in New Issue
Block a user