@@ -114,41 +114,57 @@ type PathConfig = {
114114 readonly outDir : string
115115}
116116
117+ type DefaultPathConfig = {
118+ readonly dockerGitPath : string
119+ readonly authorizedKeysPath : string
120+ readonly envGlobalPath : string
121+ readonly envProjectPath : string
122+ readonly codexAuthPath : string
123+ }
124+
125+ const resolveNormalizedSecretsRoot = ( value : string | undefined ) : string | undefined => {
126+ const trimmed = value ?. trim ( ) ?? ""
127+ return trimmed . length === 0 ? undefined : normalizeSecretsRoot ( trimmed )
128+ }
129+
130+ const buildDefaultPathConfig = (
131+ normalizedSecretsRoot : string | undefined ,
132+ projectSlug : string
133+ ) : DefaultPathConfig =>
134+ normalizedSecretsRoot === undefined
135+ ? {
136+ dockerGitPath : defaultTemplateConfig . dockerGitPath ,
137+ authorizedKeysPath : defaultTemplateConfig . authorizedKeysPath ,
138+ envGlobalPath : defaultTemplateConfig . envGlobalPath ,
139+ envProjectPath : defaultTemplateConfig . envProjectPath ,
140+ codexAuthPath : defaultTemplateConfig . codexAuthPath
141+ }
142+ : {
143+ dockerGitPath : normalizedSecretsRoot ,
144+ authorizedKeysPath : `${ normalizedSecretsRoot } /authorized_keys` ,
145+ envGlobalPath : `${ normalizedSecretsRoot } /global.env` ,
146+ envProjectPath : `${ normalizedSecretsRoot } /${ projectSlug } .env` ,
147+ codexAuthPath : `${ normalizedSecretsRoot } /codex`
148+ }
149+
117150const resolvePaths = (
118151 raw : RawOptions ,
119152 projectSlug : string ,
120153 repoPath : string
121154) : Either . Either < PathConfig , ParseError > =>
122155 Either . gen ( function * ( _ ) {
123- const secretsRoot = raw . secretsRoot ?. trim ( )
124- const normalizedSecretsRoot = secretsRoot === undefined || secretsRoot . length === 0
125- ? undefined
126- : normalizeSecretsRoot ( secretsRoot )
127- const defaultAuthorizedKeysPath = normalizedSecretsRoot === undefined
128- ? defaultTemplateConfig . authorizedKeysPath
129- : `${ normalizedSecretsRoot } /authorized_keys`
130- const defaultDockerGitPath = normalizedSecretsRoot === undefined
131- ? defaultTemplateConfig . dockerGitPath
132- : normalizedSecretsRoot
133- const defaultEnvGlobalPath = normalizedSecretsRoot === undefined
134- ? defaultTemplateConfig . envGlobalPath
135- : `${ normalizedSecretsRoot } /global.env`
136- const defaultEnvProjectPath = normalizedSecretsRoot === undefined
137- ? defaultTemplateConfig . envProjectPath
138- : `${ normalizedSecretsRoot } /${ projectSlug } .env`
139- const defaultCodexAuthPath = normalizedSecretsRoot === undefined
140- ? defaultTemplateConfig . codexAuthPath
141- : `${ normalizedSecretsRoot } /codex`
142- const dockerGitPath = defaultDockerGitPath
156+ const normalizedSecretsRoot = resolveNormalizedSecretsRoot ( raw . secretsRoot )
157+ const defaults = buildDefaultPathConfig ( normalizedSecretsRoot , projectSlug )
158+ const dockerGitPath = defaults . dockerGitPath
143159 const authorizedKeysPath = yield * _ (
144- nonEmpty ( "--authorized-keys" , raw . authorizedKeysPath , defaultAuthorizedKeysPath )
160+ nonEmpty ( "--authorized-keys" , raw . authorizedKeysPath , defaults . authorizedKeysPath )
145161 )
146- const envGlobalPath = yield * _ ( nonEmpty ( "--env-global" , raw . envGlobalPath , defaultEnvGlobalPath ) )
162+ const envGlobalPath = yield * _ ( nonEmpty ( "--env-global" , raw . envGlobalPath , defaults . envGlobalPath ) )
147163 const envProjectPath = yield * _ (
148- nonEmpty ( "--env-project" , raw . envProjectPath , defaultEnvProjectPath )
164+ nonEmpty ( "--env-project" , raw . envProjectPath , defaults . envProjectPath )
149165 )
150166 const codexAuthPath = yield * _ (
151- nonEmpty ( "--codex-auth" , raw . codexAuthPath , defaultCodexAuthPath )
167+ nonEmpty ( "--codex-auth" , raw . codexAuthPath , defaults . codexAuthPath )
152168 )
153169 const codexSharedAuthPath = codexAuthPath
154170 const codexHome = yield * _ ( nonEmpty ( "--codex-home" , raw . codexHome , defaultTemplateConfig . codexHome ) )
0 commit comments