export interface DockerConfigJson { auths : { [ registry ] : { username ? : string ; password ? : string ; auth ? : string ; } ; } ; } export function parseDockerAuthConfig ( str ) { return str ? JSON . parse ( str ) : { } ; } export function getCredentials ( tag , { auths } ) { if ( ! auths ) { return ; } const fragments = tag . split ( '/' ) ; let registry ; if ( fragments && fragments . length > 1 ) { registry = fragments [ 0 ] ; } if ( ! registry ) { return { } ; } const credentials = auths [ registry ] ; if ( ! credentials ) { return { } ; } if ( credentials . username || credentials . password ) { return { username : credentials . username , password : credentials . password } ; } if ( ! credentials . auth ) { return { } ; } const [ username , password ] = Buffer . from ( credentials . auth , 'base64' ) . toString ( ) . split ( ':' ) ; return { username , password } ; }