add auth token setup

This commit is contained in:
Edward Romero 2020-06-23 21:23:43 -04:00
parent 27178c9780
commit 6b401096b5
2 changed files with 14 additions and 24 deletions

18
dist/index.js vendored
View file

@ -4758,8 +4758,7 @@ function writeRegistryToFile(registryUrl, fileLocation, alwaysAuth) {
} }
}); });
} }
let defaultNodeAuthToken = '${NODE_AUTH_TOKEN}'; let nodeAuthToken;
let nodeAuthToken = defaultNodeAuthToken;
// Check if auth url provided // Check if auth url provided
const authUrl = core.getInput('auth-url'); const authUrl = core.getInput('auth-url');
if (authUrl) { if (authUrl) {
@ -4770,7 +4769,7 @@ function writeRegistryToFile(registryUrl, fileLocation, alwaysAuth) {
nodeAuthToken = yield getAuthToken(authUrl, authUser, authPassword); nodeAuthToken = yield getAuthToken(authUrl, authUser, authPassword);
} }
// Remove http: or https: from front of registry. // Remove http: or https: from front of registry.
const authString = `${registryUrl.replace(/(^\w+:|^)/, '')}:_authToken=${nodeAuthToken}`; let authString = registryUrl.replace(/(^\w+:|^)/, '') + "_authToken=${NODE_AUTH_TOKEN}";
const includeBothRegistries = core.getInput('include-both-registries'); const includeBothRegistries = core.getInput('include-both-registries');
const registryString = scope const registryString = scope
? `${scope}:registry=${registryUrl}` ? `${scope}:registry=${registryUrl}`
@ -4778,7 +4777,8 @@ function writeRegistryToFile(registryUrl, fileLocation, alwaysAuth) {
const alwaysAuthString = `always-auth=${alwaysAuth}`; const alwaysAuthString = `always-auth=${alwaysAuth}`;
if (scope && includeBothRegistries === "true") { if (scope && includeBothRegistries === "true") {
const registryStringNoScope = `registry=${registryUrl}`; const registryStringNoScope = `registry=${registryUrl}`;
newContents += `${registryStringNoScope}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}${os.EOL}${authString}`; const authToken = `_auth=${nodeAuthToken}`;
newContents += `${registryStringNoScope}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}${os.EOL}${authToken}`;
} }
else { else {
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`; newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
@ -4786,14 +4786,8 @@ function writeRegistryToFile(registryUrl, fileLocation, alwaysAuth) {
console.log(newContents); console.log(newContents);
fs.writeFileSync(fileLocation, newContents); fs.writeFileSync(fileLocation, newContents);
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation); core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
console.log(nodeAuthToken); // Export empty node_auth_token so npm doesn't complain about not being able to find it
if (defaultNodeAuthToken !== nodeAuthToken) { core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX');
core.exportVariable('NODE_AUTH_TOKEN', nodeAuthToken);
}
else {
// Export empty node_auth_token so npm doesn't complain about not being able to find it
core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX');
}
}); });
} }
//# sourceMappingURL=authutil.js.map //# sourceMappingURL=authutil.js.map

View file

@ -76,8 +76,7 @@ async function writeRegistryToFile(
}); });
} }
let defaultNodeAuthToken = '${NODE_AUTH_TOKEN}'; let nodeAuthToken;
let nodeAuthToken = defaultNodeAuthToken;
// Check if auth url provided // Check if auth url provided
const authUrl: string = core.getInput('auth-url'); const authUrl: string = core.getInput('auth-url');
if (authUrl) { if (authUrl) {
@ -89,10 +88,10 @@ async function writeRegistryToFile(
} }
// Remove http: or https: from front of registry. // Remove http: or https: from front of registry.
const authString: string = `${registryUrl.replace( let authString: string = registryUrl.replace(
/(^\w+:|^)/, /(^\w+:|^)/,
'' ''
)}:_authToken=${nodeAuthToken}`; ) + "_authToken=${NODE_AUTH_TOKEN}";
const includeBothRegistries: string = core.getInput('include-both-registries'); const includeBothRegistries: string = core.getInput('include-both-registries');
const registryString: string = scope const registryString: string = scope
@ -102,7 +101,8 @@ async function writeRegistryToFile(
const alwaysAuthString: string = `always-auth=${alwaysAuth}`; const alwaysAuthString: string = `always-auth=${alwaysAuth}`;
if(scope && includeBothRegistries === "true") { if(scope && includeBothRegistries === "true") {
const registryStringNoScope = `registry=${registryUrl}`; const registryStringNoScope = `registry=${registryUrl}`;
newContents += `${registryStringNoScope}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}${os.EOL}${authString}`; const authToken = `_auth=${nodeAuthToken}`
newContents += `${registryStringNoScope}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}${os.EOL}${authToken}`;
} else { } else {
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`; newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
} }
@ -110,11 +110,7 @@ async function writeRegistryToFile(
console.log(newContents); console.log(newContents);
fs.writeFileSync(fileLocation, newContents); fs.writeFileSync(fileLocation, newContents);
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation); core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
console.log(nodeAuthToken);
if (defaultNodeAuthToken !== nodeAuthToken) { // Export empty node_auth_token so npm doesn't complain about not being able to find it
core.exportVariable('NODE_AUTH_TOKEN', nodeAuthToken) core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX');
} else {
// Export empty node_auth_token so npm doesn't complain about not being able to find it
core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX');
}
} }