@sustaina/iam-middleware
v1.0.3
Published
add these line in ```kustomization.yaml``` file in ```*-deploy``` repository ``` patch: |- - op: add path: ... value: - secretRef: name: your-secret - secretRef: name: iam-middleware-dev-secret # <
Readme
@sustaina/iam-middleware
For CD
add these line in kustomization.yaml file in *-deploy repository
patch: |-
- op: add
path: ...
value:
- secretRef:
name: your-secret
- secretRef:
name: iam-middleware-dev-secret # <--- add this
# change dev to -> sit / uatnow you good to go.
Example Usage
import "dotenv/config";
import fastify from "fastify";
import pino from "pino";
import { AuthMiddleware } from "./auth/AuthMiddleware";
import { ImplementModeMiddleware } from "./auth/ImplementModeMiddleware";
const logger = pino({
level: process.env.LOG_LEVEL || "info",
transport: { target: "pino-pretty", options: { colorize: true } },
});
async function createApp() {
const app = fastify();
const authMiddleware = new AuthMiddleware();
const implementMode = new ImplementModeMiddleware();
// Register standardized routes
await app.register(
async (appInstance) => {
appInstance.get(
"/test",
{
preHandler: [
authMiddleware.authenticate.bind(authMiddleware), // required for implementMode.authorise and authMiddleware.permissionGuard
implementMode.authorise.bind(implementMode),
authMiddleware.permissionGuard([{ access: "canRead", subProgram: "test" }]).bind(authMiddleware),
],
},
async (request, reply) => {
return reply.send({
success: true,
});
}
);
},
{ prefix: "/api/v1" }
);
return app;
}
