@@ -17,12 +17,12 @@ const PROXY_USER = "proxy_user";
17
17
const KEY_SIZE = 2048 ;
18
18
const KEY_EXPIRY_YEARS = 2 ;
19
19
20
- export type CertificateAuthority = {
20
+ type CertificateAuthority = {
21
21
cert : string ;
22
22
key : string ;
23
23
} ;
24
24
25
- export type Credential = {
25
+ type Credential = {
26
26
type : string ;
27
27
host ?: string ;
28
28
url ?: string ;
@@ -31,16 +31,12 @@ export type Credential = {
31
31
token ?: string ;
32
32
} ;
33
33
34
- function CredentialToStr ( c : Credential ) : string {
35
- return `Type: ${ c . type } ; Host: ${ c . host } ; Url: ${ c . url } Username: ${ c . username } ; Password: ${ c . password !== undefined } ; Token: ${ c . token !== undefined } `
36
- }
37
-
38
- export type BasicAuthCredentials = {
34
+ type BasicAuthCredentials = {
39
35
username : string ;
40
36
password : string ;
41
37
} ;
42
38
43
- export type ProxyConfig = {
39
+ type ProxyConfig = {
44
40
all_credentials : Credential [ ] ;
45
41
ca : CertificateAuthority ;
46
42
proxy_auth ?: BasicAuthCredentials ;
@@ -103,8 +99,8 @@ async function runWrapper() {
103
99
core . saveState ( "proxy-log-file" , proxyLogFilePath ) ;
104
100
105
101
// Get the configuration options
106
- const credentials = getCredentials ( ) ;
107
- logger . info ( `Credentials loaded for the following URLs :\n ${ credentials . map ( c => CredentialToStr ( c ) ) . join ( "\n" ) } ` ) ;
102
+ const credentials = getCredentials ( logger ) ;
103
+ logger . info ( `Credentials loaded for the following registries :\n ${ credentials . map ( c => credentialToStr ( c ) ) . join ( "\n" ) } ` ) ;
108
104
109
105
const ca = generateCertificateAuthority ( ) ;
110
106
const proxyAuth = getProxyAuth ( ) ;
@@ -173,15 +169,39 @@ async function startProxy(binPath: string, config: ProxyConfig, logFilePath: str
173
169
// getCredentials returns registry credentials from action inputs.
174
170
// It prefers `registries_credentials` over `registry_secrets`.
175
171
// If neither is set, it returns an empty array.
176
- function getCredentials ( ) : Credential [ ] {
177
- const encodedCredentials = actionsUtil . getOptionalInput ( "registries_credentials" ) ;
178
- if ( encodedCredentials !== undefined ) {
179
- const credentialsStr = Buffer . from ( encodedCredentials , "base64" ) . toString ( ) ;
180
- return JSON . parse ( credentialsStr ) as Credential [ ] ;
172
+ function getCredentials ( logger : Logger ) : Credential [ ] {
173
+ const registriesCredentials = actionsUtil . getOptionalInput ( "registries_credentials" ) ;
174
+ const registrySecrets = actionsUtil . getOptionalInput ( "registry_secrets" ) ;
175
+
176
+ var credentialsStr : string ;
177
+ if ( registriesCredentials !== undefined ) {
178
+ logger . info ( `Using registries_credentials input.` ) ;
179
+ credentialsStr = Buffer . from ( registriesCredentials , "base64" ) . toString ( ) ;
180
+ } else if ( registrySecrets !== undefined ) {
181
+ logger . info ( `Using registry_secrets input.` ) ;
182
+ credentialsStr = registrySecrets ;
183
+ } else {
184
+ logger . info ( `No credentials defined.` ) ;
185
+ return [ ] ;
181
186
}
182
- core . info ( `Using structured credentials.` ) ;
183
- const registrySecrets = actionsUtil . getOptionalInput ( "registry_secrets" ) || "[]" ;
184
- return JSON . parse ( registrySecrets ) as Credential [ ] ;
187
+
188
+ // Parse and validate the credentials
189
+ const parsed = JSON . parse ( credentialsStr ) as Credential [ ] ;
190
+ let out : Credential [ ] = [ ]
191
+ parsed . forEach ( e => {
192
+ if ( e . url === undefined && e . host === undefined ) {
193
+ throw "Invalid credentials - must specify host or url"
194
+ }
195
+ out . push ( {
196
+ type : e . type ,
197
+ host : e . host ,
198
+ url : e . url ,
199
+ username : e . username ,
200
+ password : e . password ,
201
+ token : e . token ,
202
+ } )
203
+ } ) ;
204
+ return out ;
185
205
}
186
206
187
207
// getProxyAuth returns the authentication information for the proxy itself.
@@ -212,4 +232,9 @@ async function getProxyBinaryPath(): Promise<string> {
212
232
return proxyBin ;
213
233
}
214
234
235
+ function credentialToStr ( c : Credential ) : string {
236
+ return `Type: ${ c . type } ; Host: ${ c . host } ; Url: ${ c . url } Username: ${ c . username } ; Password: ${ c . password !== undefined } ; Token: ${ c . token !== undefined } `
237
+ }
238
+
239
+
215
240
void runWrapper ( ) ;
0 commit comments