@@ -27,6 +27,16 @@ export function safeDockerLoginCommand(
2727 return `printf %s ${ escapedPassword } | docker login ${ escapedRegistry } -u ${ escapedUser } --password-stdin` ;
2828}
2929
30+ function sanitizeRegistryError (
31+ error : unknown ,
32+ password : string | null | undefined ,
33+ ) : string {
34+ const message =
35+ error instanceof Error ? error . message : "Error with registry login" ;
36+ if ( ! password ) return message ;
37+ return message . split ( password ) . join ( "***" ) ;
38+ }
39+
3040export const createRegistry = async (
3141 input : z . infer < typeof apiCreateRegistry > ,
3242 organizationId : string ,
@@ -59,10 +69,15 @@ export const createRegistry = async (
5969 input . username ,
6070 input . password ,
6171 ) ;
62- if ( input . serverId && input . serverId !== "none" ) {
63- await execAsyncRemote ( input . serverId , loginCommand ) ;
64- } else if ( newRegistry . registryType === "cloud" ) {
65- await execAsync ( loginCommand ) ;
72+ try {
73+ if ( input . serverId && input . serverId !== "none" ) {
74+ await execAsyncRemote ( input . serverId , loginCommand ) ;
75+ } else if ( newRegistry . registryType === "cloud" ) {
76+ await execAsync ( loginCommand ) ;
77+ }
78+ } catch ( error ) {
79+ const sanitized = sanitizeRegistryError ( error , input . password ) ;
80+ throw new TRPCError ( { code : "BAD_REQUEST" , message : sanitized } ) ;
6681 }
6782
6883 return newRegistry ;
@@ -129,16 +144,24 @@ export const updateRegistry = async (
129144 } ) ;
130145 }
131146
132- if ( registryData ?. serverId && registryData ?. serverId !== "none" ) {
133- await execAsyncRemote ( registryData . serverId , loginCommand ) ;
134- } else if ( response ?. registryType === "cloud" ) {
135- await execAsync ( loginCommand ) ;
147+ try {
148+ if ( registryData ?. serverId && registryData ?. serverId !== "none" ) {
149+ await execAsyncRemote ( registryData . serverId , loginCommand ) ;
150+ } else if ( response ?. registryType === "cloud" ) {
151+ await execAsync ( loginCommand ) ;
152+ }
153+ } catch ( execError ) {
154+ throw new Error ( sanitizeRegistryError ( execError , response ?. password ) ) ;
136155 }
137156
138157 return response ;
139158 } catch ( error ) {
140159 const message =
141- error instanceof Error ? error . message : "Error updating this registry" ;
160+ error instanceof TRPCError
161+ ? error . message
162+ : error instanceof Error
163+ ? error . message
164+ : "Error updating this registry" ;
142165 throw new TRPCError ( {
143166 code : "BAD_REQUEST" ,
144167 message,
0 commit comments