mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 18:41:21 +00:00
feat: changed the whole api from projectid to slug
This commit is contained in:
@@ -16,7 +16,7 @@ export type TAuthMode =
|
||||
userId: string;
|
||||
tokenVersionId: string; // the session id of token used
|
||||
user: TUsers;
|
||||
orgId?: string;
|
||||
orgId: string;
|
||||
authMethod: AuthMethod;
|
||||
}
|
||||
| {
|
||||
@@ -119,7 +119,7 @@ export const injectIdentity = fp(async (server: FastifyZodProvider) => {
|
||||
userId: user.id,
|
||||
tokenVersionId,
|
||||
actor,
|
||||
orgId,
|
||||
orgId: orgId as string,
|
||||
authMethod: token.authMethod
|
||||
};
|
||||
break;
|
||||
|
||||
@@ -566,6 +566,7 @@ export const registerRoutes = async (
|
||||
dynamicSecretDAL
|
||||
});
|
||||
const dynamicSecretService = dynamicSecretServiceFactory({
|
||||
projectDAL,
|
||||
dynamicSecretQueueService,
|
||||
dynamicSecretDAL,
|
||||
dynamicSecretLeaseDAL,
|
||||
@@ -574,6 +575,7 @@ export const registerRoutes = async (
|
||||
permissionService
|
||||
});
|
||||
const dynamicSecretLeaseService = dynamicSecretLeaseServiceFactory({
|
||||
projectDAL,
|
||||
permissionService,
|
||||
dynamicSecretQueueService,
|
||||
dynamicSecretDAL,
|
||||
|
||||
@@ -7,14 +7,16 @@ import { removeTrailingSlash } from "@app/lib/fn";
|
||||
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
||||
import { AuthMode } from "@app/services/auth/auth-type";
|
||||
|
||||
import { SanitizedDynamicSecretSchema } from "../sanitizedSchemas";
|
||||
|
||||
export const registerDynamicSecretLeaseRouter = async (server: FastifyZodProvider) => {
|
||||
server.route({
|
||||
url: "/",
|
||||
method: "POST",
|
||||
schema: {
|
||||
body: z.object({
|
||||
slug: z.string(),
|
||||
projectId: z.string(),
|
||||
slug: z.string().min(1),
|
||||
projectSlug: z.string().min(1),
|
||||
ttl: z
|
||||
.string()
|
||||
.optional()
|
||||
@@ -27,7 +29,7 @@ export const registerDynamicSecretLeaseRouter = async (server: FastifyZodProvide
|
||||
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be less than a day" });
|
||||
}),
|
||||
path: z.string().trim().default("/").transform(removeTrailingSlash),
|
||||
environment: z.string()
|
||||
environment: z.string().min(1)
|
||||
}),
|
||||
response: {
|
||||
200: z.object({
|
||||
@@ -57,9 +59,9 @@ export const registerDynamicSecretLeaseRouter = async (server: FastifyZodProvide
|
||||
leaseId: z.string()
|
||||
}),
|
||||
body: z.object({
|
||||
projectId: z.string(),
|
||||
path: z.string().trim().default("/").transform(removeTrailingSlash),
|
||||
environment: z.string()
|
||||
projectSlug: z.string().min(1),
|
||||
path: z.string().min(1).trim().default("/").transform(removeTrailingSlash),
|
||||
environment: z.string().min(1)
|
||||
}),
|
||||
response: {
|
||||
200: z.object({
|
||||
@@ -100,9 +102,9 @@ export const registerDynamicSecretLeaseRouter = async (server: FastifyZodProvide
|
||||
if (valMs > daysToMillisecond(1))
|
||||
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "TTL must be less than a day" });
|
||||
}),
|
||||
projectId: z.string(),
|
||||
path: z.string().trim().default("/").transform(removeTrailingSlash),
|
||||
environment: z.string()
|
||||
projectSlug: z.string().min(1),
|
||||
path: z.string().min(1).trim().default("/").transform(removeTrailingSlash),
|
||||
environment: z.string().min(1)
|
||||
}),
|
||||
response: {
|
||||
200: z.object({
|
||||
@@ -125,34 +127,36 @@ export const registerDynamicSecretLeaseRouter = async (server: FastifyZodProvide
|
||||
});
|
||||
|
||||
server.route({
|
||||
url: "/:slug",
|
||||
url: "/:leaseId",
|
||||
method: "GET",
|
||||
schema: {
|
||||
params: z.object({
|
||||
slug: z.string()
|
||||
leaseId: z.string()
|
||||
}),
|
||||
querystring: z.object({
|
||||
projectId: z.string(),
|
||||
projectSlug: z.string().min(1),
|
||||
path: z.string().trim().default("/").transform(removeTrailingSlash),
|
||||
environment: z.string()
|
||||
environment: z.string().min(1)
|
||||
}),
|
||||
response: {
|
||||
200: z.object({
|
||||
leases: DynamicSecretLeasesSchema.array()
|
||||
lease: DynamicSecretLeasesSchema.extend({
|
||||
dynamicSecret: SanitizedDynamicSecretSchema
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
|
||||
handler: async (req) => {
|
||||
const leases = await server.services.dynamicSecretLease.listLeases({
|
||||
const lease = await server.services.dynamicSecretLease.getLeaseDetails({
|
||||
actor: req.permission.type,
|
||||
actorId: req.permission.id,
|
||||
actorAuthMethod: req.permission.authMethod,
|
||||
actorOrgId: req.permission.orgId,
|
||||
slug: req.params.slug,
|
||||
leaseId: req.params.leaseId,
|
||||
...req.query
|
||||
});
|
||||
return { leases };
|
||||
return { lease };
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import ms from "ms";
|
||||
import { z } from "zod";
|
||||
|
||||
import { DynamicSecretLeasesSchema } from "@app/db/schemas";
|
||||
import { daysToMillisecond } from "@app/lib/dates";
|
||||
import { removeTrailingSlash } from "@app/lib/fn";
|
||||
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
||||
@@ -15,7 +16,7 @@ export const registerDynamicSecretRouter = async (server: FastifyZodProvider) =>
|
||||
method: "POST",
|
||||
schema: {
|
||||
body: z.object({
|
||||
projectId: z.string(),
|
||||
projectSlug: z.string().min(1),
|
||||
provider: DynamicSecretProviderSchema,
|
||||
defaultTTL: z.string().superRefine((val, ctx) => {
|
||||
const valMs = ms(val);
|
||||
@@ -37,8 +38,8 @@ export const registerDynamicSecretRouter = async (server: FastifyZodProvider) =>
|
||||
})
|
||||
.nullable(),
|
||||
path: z.string().trim().default("/").transform(removeTrailingSlash),
|
||||
environment: z.string(),
|
||||
slug: z.string().toLowerCase()
|
||||
environment: z.string().min(1),
|
||||
slug: z.string().min(1).toLowerCase()
|
||||
}),
|
||||
response: {
|
||||
200: z.object({
|
||||
@@ -67,9 +68,9 @@ export const registerDynamicSecretRouter = async (server: FastifyZodProvider) =>
|
||||
slug: z.string()
|
||||
}),
|
||||
body: z.object({
|
||||
projectId: z.string(),
|
||||
projectSlug: z.string().min(1),
|
||||
path: z.string().trim().default("/").transform(removeTrailingSlash),
|
||||
environment: z.string(),
|
||||
environment: z.string().min(1),
|
||||
data: z.object({
|
||||
inputs: z.any().optional(),
|
||||
defaultTTL: z
|
||||
@@ -113,7 +114,7 @@ export const registerDynamicSecretRouter = async (server: FastifyZodProvider) =>
|
||||
actorOrgId: req.permission.orgId,
|
||||
slug: req.params.slug,
|
||||
path: req.body.path,
|
||||
projectId: req.body.projectId,
|
||||
projectSlug: req.body.projectSlug,
|
||||
environment: req.body.environment,
|
||||
...req.body.data
|
||||
});
|
||||
@@ -129,9 +130,9 @@ export const registerDynamicSecretRouter = async (server: FastifyZodProvider) =>
|
||||
slug: z.string()
|
||||
}),
|
||||
body: z.object({
|
||||
projectId: z.string(),
|
||||
projectSlug: z.string().min(1),
|
||||
path: z.string().trim().default("/").transform(removeTrailingSlash),
|
||||
environment: z.string()
|
||||
environment: z.string().min(1)
|
||||
}),
|
||||
response: {
|
||||
200: z.object({
|
||||
@@ -161,9 +162,9 @@ export const registerDynamicSecretRouter = async (server: FastifyZodProvider) =>
|
||||
slug: z.string()
|
||||
}),
|
||||
querystring: z.object({
|
||||
projectId: z.string(),
|
||||
projectSlug: z.string().min(1),
|
||||
path: z.string().trim().default("/").transform(removeTrailingSlash),
|
||||
environment: z.string()
|
||||
environment: z.string().min(1)
|
||||
}),
|
||||
response: {
|
||||
200: z.object({
|
||||
@@ -192,9 +193,9 @@ export const registerDynamicSecretRouter = async (server: FastifyZodProvider) =>
|
||||
method: "GET",
|
||||
schema: {
|
||||
querystring: z.object({
|
||||
projectId: z.string(),
|
||||
projectSlug: z.string().min(1),
|
||||
path: z.string().trim().default("/").transform(removeTrailingSlash),
|
||||
environment: z.string()
|
||||
environment: z.string().min(1)
|
||||
}),
|
||||
response: {
|
||||
200: z.object({
|
||||
@@ -214,4 +215,36 @@ export const registerDynamicSecretRouter = async (server: FastifyZodProvider) =>
|
||||
return { dynamicSecrets: dynamicSecretCfgs };
|
||||
}
|
||||
});
|
||||
|
||||
server.route({
|
||||
url: "/:slug/leases",
|
||||
method: "GET",
|
||||
schema: {
|
||||
params: z.object({
|
||||
slug: z.string()
|
||||
}),
|
||||
querystring: z.object({
|
||||
projectSlug: z.string().min(1),
|
||||
path: z.string().trim().default("/").transform(removeTrailingSlash),
|
||||
environment: z.string().min(1)
|
||||
}),
|
||||
response: {
|
||||
200: z.object({
|
||||
leases: DynamicSecretLeasesSchema.array()
|
||||
})
|
||||
}
|
||||
},
|
||||
onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
|
||||
handler: async (req) => {
|
||||
const leases = await server.services.dynamicSecretLease.listLeases({
|
||||
actor: req.permission.type,
|
||||
actorId: req.permission.id,
|
||||
actorAuthMethod: req.permission.authMethod,
|
||||
actorOrgId: req.permission.orgId,
|
||||
slug: req.params.slug,
|
||||
...req.query
|
||||
});
|
||||
return { leases };
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user