@@ -89,46 +89,37 @@ function generateCertificateAuthority(): CertificateAuthority {
89
89
}
90
90
91
91
async function runWrapper ( ) {
92
+ // Setup logging
92
93
const tempDir = actionsUtil . getTemporaryDirectory ( ) ;
93
94
const logFilePath = path . resolve ( tempDir , "proxy.log" ) ;
94
- const input = actionsUtil . getOptionalInput ( "registry_secrets" ) || "[]" ;
95
- const credentials = JSON . parse ( input ) as Credential [ ] ;
96
- const ca = generateCertificateAuthority ( ) ;
97
- const proxy_password = actionsUtil . getOptionalInput ( "proxy_password" ) ;
98
95
core . saveState ( "proxy-log-file" , logFilePath ) ;
99
96
100
- let proxy_auth : BasicAuthCredentials | undefined = undefined ;
101
- if ( proxy_password ) {
102
- proxy_auth = {
103
- username : PROXY_USER ,
104
- password : proxy_password ,
105
- } ;
106
- }
97
+ // Get the configuration options
98
+ const credentials = getCredentials ( ) ;
99
+ const ca = generateCertificateAuthority ( ) ;
100
+ const proxyAuth = getProxyAuth ( ) ;
101
+
107
102
const proxyConfig : ProxyConfig = {
108
103
all_credentials : credentials ,
109
104
ca,
110
- proxy_auth,
105
+ proxy_auth : proxyAuth ,
111
106
} ;
107
+
108
+ // Start the Proxy
109
+ const proxyBin = await getProxyBinaryPath ( ) ;
110
+ await startProxy ( proxyBin , proxyConfig , logFilePath ) ;
111
+ }
112
+
113
+ async function startProxy ( binPath : string , config : ProxyConfig , logFilePath : string ) {
112
114
const host = "127.0.0.1" ;
113
- let proxyBin = toolcache . find ( UPDATEJOB_PROXY , UPDATEJOB_PROXY_VERSION ) ;
114
- if ( ! proxyBin ) {
115
- const temp = await toolcache . downloadTool ( UPDATEJOB_PROXY_URL ) ;
116
- const extracted = await toolcache . extractTar ( temp ) ;
117
- proxyBin = await toolcache . cacheDir (
118
- extracted ,
119
- UPDATEJOB_PROXY ,
120
- UPDATEJOB_PROXY_VERSION ,
121
- ) ;
122
- }
123
- proxyBin = path . join ( proxyBin , UPDATEJOB_PROXY ) ;
124
115
let port = 49152 ;
125
116
try {
126
117
let subprocess : ChildProcess | undefined = undefined ;
127
118
let tries = 5 ;
128
119
let subprocessError : Error | undefined = undefined ;
129
120
while ( tries -- > 0 && ! subprocess && ! subprocessError ) {
130
121
subprocess = spawn (
131
- proxyBin ,
122
+ binPath ,
132
123
[ "-addr" , `${ host } :${ port } ` , "-config" , "-" , "-logfile" , logFilePath ] ,
133
124
{
134
125
detached : true ,
@@ -149,7 +140,7 @@ async function runWrapper() {
149
140
subprocess = undefined ;
150
141
}
151
142
} ) ;
152
- subprocess . stdin ?. write ( JSON . stringify ( proxyConfig ) ) ;
143
+ subprocess . stdin ?. write ( JSON . stringify ( config ) ) ;
153
144
subprocess . stdin ?. end ( ) ;
154
145
// Wait a little to allow the proxy to start
155
146
await util . delay ( 1000 ) ;
@@ -160,12 +151,55 @@ async function runWrapper() {
160
151
core . info ( `Proxy started on ${ host } :${ port } ` ) ;
161
152
core . setOutput ( "proxy_host" , host ) ;
162
153
core . setOutput ( "proxy_port" , port . toString ( ) ) ;
163
- core . setOutput ( "proxy_ca_certificate" , ca . cert ) ;
154
+ core . setOutput ( "proxy_ca_certificate" , config . ca . cert ) ;
164
155
} catch ( error ) {
165
156
core . setFailed (
166
157
`start-proxy action failed: ${ util . wrapError ( error ) . message } ` ,
167
158
) ;
168
159
}
169
160
}
170
161
162
+ // getCredentials returns registry credentials from action inputs.
163
+ // It prefers `registries_credentials` over `registry_secrets`.
164
+ // If neither is set, it returns an empty array.
165
+ function getCredentials ( ) : Credential [ ] {
166
+ const encodedCredentials = actionsUtil . getOptionalInput ( "registries_credentials" ) ;
167
+ if ( encodedCredentials !== undefined ) {
168
+ core . info ( `Using encoded credentials.` ) ;
169
+ const credentialsStr = Buffer . from ( encodedCredentials , "base64" ) . toString ( ) ;
170
+ return JSON . parse ( credentialsStr ) as Credential [ ] ;
171
+ }
172
+ core . info ( `Using structured credentials.` ) ;
173
+ const registrySecrets = actionsUtil . getOptionalInput ( "registry_secrets" ) || "[]" ;
174
+ return JSON . parse ( registrySecrets ) as Credential [ ] ;
175
+ }
176
+
177
+ // getProxyAuth returns the authentication information for the proxy itself.
178
+ function getProxyAuth ( ) : BasicAuthCredentials | undefined {
179
+ const proxy_password = actionsUtil . getOptionalInput ( "proxy_password" ) ;
180
+ if ( proxy_password ) {
181
+ return {
182
+ username : PROXY_USER ,
183
+ password : proxy_password ,
184
+ } ;
185
+ }
186
+ return ;
187
+ }
188
+
189
+
190
+ async function getProxyBinaryPath ( ) : Promise < string > {
191
+ let proxyBin = toolcache . find ( UPDATEJOB_PROXY , UPDATEJOB_PROXY_VERSION ) ;
192
+ if ( ! proxyBin ) {
193
+ const temp = await toolcache . downloadTool ( UPDATEJOB_PROXY_URL ) ;
194
+ const extracted = await toolcache . extractTar ( temp ) ;
195
+ proxyBin = await toolcache . cacheDir (
196
+ extracted ,
197
+ UPDATEJOB_PROXY ,
198
+ UPDATEJOB_PROXY_VERSION ,
199
+ ) ;
200
+ }
201
+ proxyBin = path . join ( proxyBin , UPDATEJOB_PROXY ) ;
202
+ return proxyBin ;
203
+ }
204
+
171
205
void runWrapper ( ) ;
0 commit comments