@@ -15,9 +15,9 @@ import { KnownLanguage } from "./languages";
1515import { Logger } from "./logging" ;
1616import {
1717 Address ,
18- Credential ,
18+ RawCredential ,
1919 Registry ,
20- ValidCredential ,
20+ Credential ,
2121} from "./start-proxy/types" ;
2222import {
2323 ActionName ,
@@ -234,7 +234,7 @@ const LANGUAGE_TO_REGISTRY_TYPE: Partial<Record<KnownLanguage, string[]>> = {
234234 *
235235 * @throws A `ConfigurationError` if the `Registry` value contains neither a `url` or `host` field.
236236 */
237- function getRegistryAddress ( registry : Registry ) : Address {
237+ function getRegistryAddress ( registry : Partial < Registry > ) : Address {
238238 if ( isDefined ( registry . url ) ) {
239239 return {
240240 url : registry . url ,
@@ -261,7 +261,7 @@ export function getCredentials(
261261 registrySecrets : string | undefined ,
262262 registriesCredentials : string | undefined ,
263263 language : KnownLanguage | undefined ,
264- ) : ValidCredential [ ] {
264+ ) : Credential [ ] {
265265 const registryTypeForLanguage = language
266266 ? LANGUAGE_TO_REGISTRY_TYPE [ language ]
267267 : undefined ;
@@ -279,9 +279,9 @@ export function getCredentials(
279279 }
280280
281281 // Parse and validate the credentials
282- let parsed : Credential [ ] ;
282+ let parsed : RawCredential [ ] ;
283283 try {
284- parsed = JSON . parse ( credentialsStr ) as Credential [ ] ;
284+ parsed = JSON . parse ( credentialsStr ) as RawCredential [ ] ;
285285 } catch {
286286 // Don't log the error since it might contain sensitive information.
287287 logger . error ( "Failed to parse the credentials data." ) ;
@@ -295,12 +295,17 @@ export function getCredentials(
295295 ) ;
296296 }
297297
298- const out : ValidCredential [ ] = [ ] ;
298+ const out : Credential [ ] = [ ] ;
299299 for ( const e of parsed ) {
300300 if ( e === null || typeof e !== "object" ) {
301301 throw new ConfigurationError ( "Invalid credentials - must be an object" ) ;
302302 }
303303
304+ // The configuration must have a type.
305+ if ( ! isDefined ( e . type ) ) {
306+ throw new ConfigurationError ( "Invalid credentials - must have a type" ) ;
307+ }
308+
304309 // Mask credentials to reduce chance of accidental leakage in logs.
305310 if ( isDefined ( e . password ) ) {
306311 core . setSecret ( e . password ) ;
@@ -450,7 +455,7 @@ export async function getDownloadUrl(
450455 *
451456 * @param c The credential to convert to a string.
452457 */
453- export function credentialToStr ( c : Credential ) : string {
458+ export function credentialToStr ( c : RawCredential ) : string {
454459 return `Type: ${ c . type } ; Host: ${ c . host } ; Url: ${ c . url } Username: ${
455460 c . username
456461 } ; Password: ${ c . password !== undefined } ; Token: ${ c . token !== undefined } `;
0 commit comments