fix: Able to change postgres user password from ui
This commit is contained in:
parent
f4315144af
commit
d2f5a58f3b
@ -138,7 +138,7 @@ export async function stopDatabase(database) {
|
|||||||
return everStarted;
|
return everStarted;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updatePasswordInDb(database, user, newPassword) {
|
export async function updatePasswordInDb(database, user, newPassword, isRoot) {
|
||||||
const {
|
const {
|
||||||
id,
|
id,
|
||||||
type,
|
type,
|
||||||
@ -157,9 +157,15 @@ export async function updatePasswordInDb(database, user, newPassword) {
|
|||||||
`DOCKER_HOST=${host} docker exec ${id} mysql -u ${rootUser} -p${rootUserPassword} -e \"ALTER USER '${user}'@'%' IDENTIFIED WITH caching_sha2_password BY '${newPassword}';\"`
|
`DOCKER_HOST=${host} docker exec ${id} mysql -u ${rootUser} -p${rootUserPassword} -e \"ALTER USER '${user}'@'%' IDENTIFIED WITH caching_sha2_password BY '${newPassword}';\"`
|
||||||
);
|
);
|
||||||
} else if (type === 'postgresql') {
|
} else if (type === 'postgresql') {
|
||||||
|
if (isRoot) {
|
||||||
|
await asyncExecShell(
|
||||||
|
`DOCKER_HOST=${host} docker exec ${id} psql postgresql://postgres:${rootUserPassword}@${id}:5432/${defaultDatabase} -c "ALTER role postgres WITH PASSWORD '${newPassword}'"`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
await asyncExecShell(
|
await asyncExecShell(
|
||||||
`DOCKER_HOST=${host} docker exec ${id} psql postgresql://${dbUser}:${dbUserPassword}@${id}:5432/${defaultDatabase} -c "ALTER role ${user} WITH PASSWORD '${newPassword}'"`
|
`DOCKER_HOST=${host} docker exec ${id} psql postgresql://${dbUser}:${dbUserPassword}@${id}:5432/${defaultDatabase} -c "ALTER role ${user} WITH PASSWORD '${newPassword}'"`
|
||||||
);
|
);
|
||||||
|
}
|
||||||
} else if (type === 'mongodb') {
|
} else if (type === 'mongodb') {
|
||||||
await asyncExecShell(
|
await asyncExecShell(
|
||||||
`DOCKER_HOST=${host} docker exec ${id} mongo 'mongodb://${rootUser}:${rootUserPassword}@${id}:27017/admin?readPreference=primary&ssl=false' --eval "db.changeUserPassword('${user}','${newPassword}')"`
|
`DOCKER_HOST=${host} docker exec ${id} mongo 'mongodb://${rootUser}:${rootUserPassword}@${id}:27017/admin?readPreference=primary&ssl=false' --eval "db.changeUserPassword('${user}','${newPassword}')"`
|
||||||
|
@ -26,12 +26,12 @@
|
|||||||
>Root (postgres) User Password</label
|
>Root (postgres) User Password</label
|
||||||
>
|
>
|
||||||
<CopyPasswordField
|
<CopyPasswordField
|
||||||
readonly
|
disabled={!isRunning}
|
||||||
disabled
|
readonly={!isRunning}
|
||||||
placeholder="Generated automatically after start"
|
placeholder="Generated automatically after start"
|
||||||
id="rootUserPassword"
|
id="rootUserPassword"
|
||||||
name="rootUserPassword"
|
name="rootUserPassword"
|
||||||
value={database.rootUserPassword}
|
bind:value={database.rootUserPassword}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="grid grid-cols-2 items-center">
|
<div class="grid grid-cols-2 items-center">
|
||||||
|
@ -68,9 +68,9 @@ export const post: RequestHandler = async (event) => {
|
|||||||
const database = await db.getDatabase({ id, teamId });
|
const database = await db.getDatabase({ id, teamId });
|
||||||
if (isRunning) {
|
if (isRunning) {
|
||||||
if (database.dbUserPassword !== dbUserPassword) {
|
if (database.dbUserPassword !== dbUserPassword) {
|
||||||
await updatePasswordInDb(database, dbUser, dbUserPassword);
|
await updatePasswordInDb(database, dbUser, dbUserPassword, false);
|
||||||
} else if (database.rootUserPassword !== rootUserPassword) {
|
} else if (database.rootUserPassword !== rootUserPassword) {
|
||||||
await updatePasswordInDb(database, rootUser, rootUserPassword);
|
await updatePasswordInDb(database, rootUser, rootUserPassword, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await db.updateDatabase({
|
await db.updateDatabase({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user