mirror of
https://github.com/Infisical/infisical.git
synced 2025-03-25 14:05:03 +00:00
Compare commits
7 Commits
daniel/api
...
fix/db-hos
Author | SHA1 | Date | |
---|---|---|---|
cb828200e1 | |||
77d068ae2c | |||
8702af671d | |||
31c0fd96ea | |||
2c539697df | |||
ae97b74933 | |||
3e6af2dae5 |
@ -9,6 +9,7 @@ import jmespath from "jmespath";
|
||||
import knex from "knex";
|
||||
|
||||
import { getConfig } from "@app/lib/config/env";
|
||||
import { getDbConnectionHost } from "@app/lib/knex";
|
||||
import { alphaNumericNanoId } from "@app/lib/nanoid";
|
||||
|
||||
import { TAssignOp, TDbProviderClients, TDirectAssignOp, THttpProviderFunction } from "../templates/types";
|
||||
@ -89,7 +90,7 @@ export const secretRotationDbFn = async ({
|
||||
const appCfg = getConfig();
|
||||
|
||||
const ssl = ca ? { rejectUnauthorized: false, ca } : undefined;
|
||||
if (host === "localhost" || host === "127.0.0.1" || appCfg.DB_CONNECTION_URI.includes(host))
|
||||
if (host === "localhost" || host === "127.0.0.1" || getDbConnectionHost(appCfg.DB_CONNECTION_URI) === host)
|
||||
throw new Error("Invalid db host");
|
||||
|
||||
const db = knex({
|
||||
|
11
backend/src/lib/knex/connection.ts
Normal file
11
backend/src/lib/knex/connection.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { URL } from "url"; // Import the URL class
|
||||
|
||||
export const getDbConnectionHost = (urlString: string) => {
|
||||
try {
|
||||
const url = new URL(urlString);
|
||||
// Split hostname and port (if provided)
|
||||
return url.hostname.split(":")[0];
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
};
|
@ -4,6 +4,7 @@ import { Tables } from "knex/types/tables";
|
||||
|
||||
import { DatabaseError } from "../errors";
|
||||
|
||||
export * from "./connection";
|
||||
export * from "./join";
|
||||
export * from "./select";
|
||||
|
||||
|
@ -150,8 +150,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
|
||||
message: "Slug must be a valid slug"
|
||||
})
|
||||
.optional()
|
||||
.describe(PROJECTS.CREATE.slug),
|
||||
organizationSlug: z.string().trim().describe(PROJECTS.CREATE.organizationSlug)
|
||||
.describe(PROJECTS.CREATE.slug)
|
||||
}),
|
||||
response: {
|
||||
200: z.object({
|
||||
@ -166,7 +165,6 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {
|
||||
actor: req.permission.type,
|
||||
actorOrgId: req.permission.orgId,
|
||||
actorAuthMethod: req.permission.authMethod,
|
||||
orgSlug: req.body.organizationSlug,
|
||||
workspaceName: req.body.projectName,
|
||||
slug: req.body.slug
|
||||
});
|
||||
|
@ -92,7 +92,6 @@ export const projectServiceFactory = ({
|
||||
* Create workspace. Make user the admin
|
||||
* */
|
||||
const createProject = async ({
|
||||
orgSlug,
|
||||
actor,
|
||||
actorId,
|
||||
actorOrgId,
|
||||
@ -100,13 +99,7 @@ export const projectServiceFactory = ({
|
||||
workspaceName,
|
||||
slug: projectSlug
|
||||
}: TCreateProjectDTO) => {
|
||||
if (!orgSlug) {
|
||||
throw new BadRequestError({
|
||||
message: "Must provide organization slug to create project"
|
||||
});
|
||||
}
|
||||
|
||||
const organization = await orgDAL.findOne({ slug: orgSlug });
|
||||
const organization = await orgDAL.findOne({ id: actorOrgId });
|
||||
|
||||
const { permission, membership: orgMembership } = await permissionService.getOrgPermission(
|
||||
actor,
|
||||
|
@ -24,7 +24,6 @@ export type TCreateProjectDTO = {
|
||||
actorAuthMethod: ActorAuthMethod;
|
||||
actorId: string;
|
||||
actorOrgId?: string;
|
||||
orgSlug: string;
|
||||
workspaceName: string;
|
||||
slug?: string;
|
||||
};
|
||||
|
@ -196,10 +196,8 @@ export default function UserInfoStep({
|
||||
|
||||
const userOrgs = await fetchOrganizations();
|
||||
|
||||
const orgSlug = userOrgs[0]?.slug;
|
||||
const orgId = userOrgs[0]?.id;
|
||||
const project = await ProjectService.initProject({
|
||||
organizationSlug: orgSlug,
|
||||
projectName: "Example Project"
|
||||
});
|
||||
|
||||
|
@ -77,18 +77,11 @@ const secretsToBeAdded = [
|
||||
* @param {String} obj.projectName - name of new project
|
||||
* @returns {Project} project - new project
|
||||
*/
|
||||
const initProjectHelper = async ({
|
||||
organizationSlug,
|
||||
projectName
|
||||
}: {
|
||||
organizationSlug: string;
|
||||
projectName: string;
|
||||
}) => {
|
||||
const initProjectHelper = async ({ projectName }: { projectName: string }) => {
|
||||
// create new project
|
||||
const {
|
||||
data: { project }
|
||||
} = await createWorkspace({
|
||||
organizationSlug,
|
||||
projectName
|
||||
});
|
||||
|
||||
|
@ -199,19 +199,17 @@ export const useGetWorkspaceIntegrations = (workspaceId: string) =>
|
||||
});
|
||||
|
||||
export const createWorkspace = ({
|
||||
organizationSlug,
|
||||
projectName
|
||||
}: CreateWorkspaceDTO): Promise<{ data: { project: Workspace } }> => {
|
||||
return apiRequest.post("/api/v2/workspace", { projectName, organizationSlug });
|
||||
return apiRequest.post("/api/v2/workspace", { projectName });
|
||||
};
|
||||
|
||||
export const useCreateWorkspace = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<{ data: { project: Workspace } }, {}, CreateWorkspaceDTO>({
|
||||
mutationFn: async ({ organizationSlug, projectName }) =>
|
||||
mutationFn: async ({ projectName }) =>
|
||||
createWorkspace({
|
||||
organizationSlug,
|
||||
projectName
|
||||
}),
|
||||
onSuccess: () => {
|
||||
@ -325,7 +323,13 @@ export const useDeleteUserFromWorkspace = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({ usernames, workspaceId }: { workspaceId: string; usernames: string[] }) => {
|
||||
mutationFn: async ({
|
||||
usernames,
|
||||
workspaceId
|
||||
}: {
|
||||
workspaceId: string;
|
||||
usernames: string[];
|
||||
}) => {
|
||||
const {
|
||||
data: { deletedMembership }
|
||||
} = await apiRequest.delete(`/api/v2/workspace/${workspaceId}/memberships`, {
|
||||
@ -391,11 +395,7 @@ export const useAddIdentityToWorkspace = () => {
|
||||
export const useUpdateIdentityWorkspaceRole = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
identityId,
|
||||
workspaceId,
|
||||
roles
|
||||
}:TUpdateWorkspaceIdentityRoleDTO)=> {
|
||||
mutationFn: async ({ identityId, workspaceId, roles }: TUpdateWorkspaceIdentityRoleDTO) => {
|
||||
const {
|
||||
data: { identityMembership }
|
||||
} = await apiRequest.patch(
|
||||
|
@ -45,7 +45,6 @@ export type TGetUpgradeProjectStatusDTO = {
|
||||
// mutation dto
|
||||
export type CreateWorkspaceDTO = {
|
||||
projectName: string;
|
||||
organizationSlug: string;
|
||||
};
|
||||
|
||||
export type RenameWorkspaceDTO = { workspaceID: string; newWorkspaceName: string };
|
||||
@ -82,16 +81,16 @@ export type TUpdateWorkspaceUserRoleDTO = {
|
||||
workspaceId: string;
|
||||
roles: (
|
||||
| {
|
||||
role: string;
|
||||
isTemporary?: false;
|
||||
}
|
||||
role: string;
|
||||
isTemporary?: false;
|
||||
}
|
||||
| {
|
||||
role: string;
|
||||
isTemporary: true;
|
||||
temporaryMode: ProjectUserMembershipTemporaryMode;
|
||||
temporaryRange: string;
|
||||
temporaryAccessStartTime: string;
|
||||
}
|
||||
role: string;
|
||||
isTemporary: true;
|
||||
temporaryMode: ProjectUserMembershipTemporaryMode;
|
||||
temporaryRange: string;
|
||||
temporaryAccessStartTime: string;
|
||||
}
|
||||
)[];
|
||||
};
|
||||
|
||||
@ -100,15 +99,15 @@ export type TUpdateWorkspaceIdentityRoleDTO = {
|
||||
workspaceId: string;
|
||||
roles: (
|
||||
| {
|
||||
role: string;
|
||||
isTemporary?: false;
|
||||
}
|
||||
role: string;
|
||||
isTemporary?: false;
|
||||
}
|
||||
| {
|
||||
role: string;
|
||||
isTemporary: true;
|
||||
temporaryMode: ProjectUserMembershipTemporaryMode;
|
||||
temporaryRange: string;
|
||||
temporaryAccessStartTime: string;
|
||||
}
|
||||
role: string;
|
||||
isTemporary: true;
|
||||
temporaryMode: ProjectUserMembershipTemporaryMode;
|
||||
temporaryRange: string;
|
||||
temporaryAccessStartTime: string;
|
||||
}
|
||||
)[];
|
||||
};
|
||||
|
@ -236,7 +236,6 @@ export const AppLayout = ({ children }: LayoutProps) => {
|
||||
project: { id: newProjectId }
|
||||
}
|
||||
} = await createWs.mutateAsync({
|
||||
organizationSlug: currentOrg.slug,
|
||||
projectName: name
|
||||
});
|
||||
|
||||
|
@ -512,7 +512,6 @@ const OrganizationPage = withPermission(
|
||||
project: { id: newProjectId }
|
||||
}
|
||||
} = await createWs.mutateAsync({
|
||||
organizationSlug: currentOrg.slug,
|
||||
projectName: name
|
||||
});
|
||||
|
||||
|
@ -9,15 +9,8 @@ class ProjectService {
|
||||
* @param {String} obj.projectName - name of new project
|
||||
* @returns {Project} project - new project
|
||||
*/
|
||||
static async initProject({
|
||||
organizationSlug,
|
||||
projectName
|
||||
}: {
|
||||
organizationSlug: string;
|
||||
projectName: string;
|
||||
}) {
|
||||
static async initProject({ projectName }: { projectName: string }) {
|
||||
return initProjectHelper({
|
||||
organizationSlug,
|
||||
projectName
|
||||
});
|
||||
}
|
||||
|
@ -189,14 +189,12 @@ export const UserInfoSSOStep = ({
|
||||
|
||||
const userOrgs = await fetchOrganizations();
|
||||
const orgId = userOrgs[0]?.id;
|
||||
const orgSlug = userOrgs[0]?.slug;
|
||||
|
||||
await selectOrganization({
|
||||
organizationId: orgId
|
||||
});
|
||||
|
||||
const project = await ProjectService.initProject({
|
||||
organizationSlug: orgSlug,
|
||||
projectName: "Example Project"
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user