refactor: reuse safeDockerLoginCommand from registry.ts instead of duplicating shEscape

This commit is contained in:
lear
2026-03-04 12:45:57 +03:00
parent 7185047eb7
commit d2fabc998d
2 changed files with 7 additions and 11 deletions

View File

@@ -16,7 +16,7 @@ function shEscape(s: string | undefined): string {
return `'${s.replace(/'/g, `'\\''`)}'`;
}
function safeDockerLoginCommand(
export function safeDockerLoginCommand(
registry: string | undefined,
user: string | undefined,
pass: string | undefined,

View File

@@ -23,7 +23,7 @@ import { findDeploymentById } from "./deployment";
import type { Mount } from "./mount";
import type { Port } from "./port";
import type { Project } from "./project";
import type { Registry } from "./registry";
import { type Registry, safeDockerLoginCommand } from "./registry";
export const createRollback = async (
input: z.infer<typeof createRollbackSchema>,
@@ -175,10 +175,11 @@ const dockerLoginForRegistry = async (
registry: Registry,
serverId?: string | null,
) => {
const escapedRegistry = shEscape(registry.registryUrl);
const escapedUser = shEscape(registry.username);
const escapedPassword = shEscape(registry.password);
const loginCommand = `printf %s ${escapedPassword} | docker login ${escapedRegistry} -u ${escapedUser} --password-stdin`;
const loginCommand = safeDockerLoginCommand(
registry.registryUrl,
registry.username,
registry.password,
);
if (serverId) {
await execAsyncRemote(serverId, loginCommand);
@@ -187,11 +188,6 @@ const dockerLoginForRegistry = async (
}
};
function shEscape(s: string | undefined): string {
if (!s) return "''";
return `'${s.replace(/'/g, `'\\''`)}'`;
}
const rollbackApplication = async (
appName: string,
image: string,