mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-05 10:26:35 +00:00
Add unique constraints for ssh login user and login user mapping tables
This commit is contained in:
@@ -29,6 +29,7 @@ export async function up(knex: Knex): Promise<void> {
|
|||||||
t.uuid("sshHostId").notNullable();
|
t.uuid("sshHostId").notNullable();
|
||||||
t.foreign("sshHostId").references("id").inTable(TableName.SshHost).onDelete("CASCADE");
|
t.foreign("sshHostId").references("id").inTable(TableName.SshHost).onDelete("CASCADE");
|
||||||
t.string("loginUser").notNullable(); // e.g. ubuntu, root, ec2-user, ...
|
t.string("loginUser").notNullable(); // e.g. ubuntu, root, ec2-user, ...
|
||||||
|
t.unique(["sshHostId", "loginUser"]);
|
||||||
});
|
});
|
||||||
await createOnUpdateTrigger(knex, TableName.SshHostLoginUser);
|
await createOnUpdateTrigger(knex, TableName.SshHostLoginUser);
|
||||||
}
|
}
|
||||||
@@ -41,6 +42,7 @@ export async function up(knex: Knex): Promise<void> {
|
|||||||
t.foreign("sshHostLoginUserId").references("id").inTable(TableName.SshHostLoginUser).onDelete("CASCADE");
|
t.foreign("sshHostLoginUserId").references("id").inTable(TableName.SshHostLoginUser).onDelete("CASCADE");
|
||||||
t.uuid("userId").nullable();
|
t.uuid("userId").nullable();
|
||||||
t.foreign("userId").references("id").inTable(TableName.Users).onDelete("CASCADE");
|
t.foreign("userId").references("id").inTable(TableName.Users).onDelete("CASCADE");
|
||||||
|
t.unique(["sshHostLoginUserId", "userId"]);
|
||||||
});
|
});
|
||||||
await createOnUpdateTrigger(knex, TableName.SshHostLoginUserMapping);
|
await createOnUpdateTrigger(knex, TableName.SshHostLoginUserMapping);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -188,20 +188,6 @@ export const sshHostServiceFactory = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const newSshHost = await sshHostDAL.transaction(async (tx) => {
|
const newSshHost = await sshHostDAL.transaction(async (tx) => {
|
||||||
const existingHost = await sshHostDAL.findOne(
|
|
||||||
{
|
|
||||||
projectId,
|
|
||||||
hostname
|
|
||||||
},
|
|
||||||
tx
|
|
||||||
);
|
|
||||||
|
|
||||||
if (existingHost) {
|
|
||||||
throw new BadRequestError({
|
|
||||||
message: `SSH host with hostname ${hostname} already exists`
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const host = await sshHostDAL.create(
|
const host = await sshHostDAL.create(
|
||||||
{
|
{
|
||||||
projectId,
|
projectId,
|
||||||
|
|||||||
Reference in New Issue
Block a user