1
0
Fork 0
mirror of https://github.com/actions/setup-node synced 2025-04-09 10:25:52 +00:00

update to add auth contents instead

This commit is contained in:
Edward Romero 2020-06-23 21:39:34 -04:00
parent 6b401096b5
commit 4a5dd826b6
2 changed files with 10 additions and 20 deletions

15
dist/index.js vendored
View file

@ -4714,7 +4714,7 @@ function configAuthentication(registryUrl, alwaysAuth) {
});
}
exports.configAuthentication = configAuthentication;
function getAuthToken(authUrl, authUser, authPass) {
function getAuthContents(authUrl, authUser, authPass) {
return __awaiter(this, void 0, void 0, function* () {
let bh = new am.BasicCredentialHandler(authUser, authPass);
let httpClient = new hc.HttpClient('registry-auth', [bh], {
@ -4727,11 +4727,7 @@ function getAuthToken(authUrl, authUser, authPass) {
* we will parse it by using indexes
*/
let body = yield response.readBody();
const startIndex = body.indexOf('_auth') + 8;
const endIndex = body.indexOf('\n');
const authToken = body.substring(startIndex, endIndex);
console.log(authToken);
return authToken;
return body;
});
}
function writeRegistryToFile(registryUrl, fileLocation, alwaysAuth) {
@ -4758,7 +4754,7 @@ function writeRegistryToFile(registryUrl, fileLocation, alwaysAuth) {
}
});
}
let nodeAuthToken;
let authContents;
// Check if auth url provided
const authUrl = core.getInput('auth-url');
if (authUrl) {
@ -4766,7 +4762,7 @@ function writeRegistryToFile(registryUrl, fileLocation, alwaysAuth) {
// Check if username and password/token provided
const authUser = core.getInput('auth-user');
const authPassword = core.getInput('auth-password');
nodeAuthToken = yield getAuthToken(authUrl, authUser, authPassword);
authContents = yield getAuthContents(authUrl, authUser, authPassword);
}
// Remove http: or https: from front of registry.
let authString = registryUrl.replace(/(^\w+:|^)/, '') + "_authToken=${NODE_AUTH_TOKEN}";
@ -4777,8 +4773,7 @@ function writeRegistryToFile(registryUrl, fileLocation, alwaysAuth) {
const alwaysAuthString = `always-auth=${alwaysAuth}`;
if (scope && includeBothRegistries === "true") {
const registryStringNoScope = `registry=${registryUrl}`;
const authToken = `_auth=${nodeAuthToken}`;
newContents += `${registryStringNoScope}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}${os.EOL}${authToken}`;
newContents += `${registryStringNoScope}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}${os.EOL}${authContents}`;
}
else {
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;

View file

@ -21,7 +21,7 @@ export async function configAuthentication(
await writeRegistryToFile(registryUrl, npmrc, alwaysAuth);
}
async function getAuthToken(
async function getAuthContents(
authUrl: string,
authUser: string,
authPass: string
@ -40,11 +40,7 @@ async function getAuthToken(
* we will parse it by using indexes
*/
let body: string = await response.readBody();
const startIndex = body.indexOf('_auth') + 8;
const endIndex = body.indexOf('\n');
const authToken = body.substring(startIndex, endIndex);
console.log(authToken);
return authToken;
return body;
}
async function writeRegistryToFile(
@ -76,7 +72,7 @@ async function writeRegistryToFile(
});
}
let nodeAuthToken;
let authContents;
// Check if auth url provided
const authUrl: string = core.getInput('auth-url');
if (authUrl) {
@ -84,7 +80,7 @@ async function writeRegistryToFile(
// Check if username and password/token provided
const authUser: string = core.getInput('auth-user');
const authPassword: string = core.getInput('auth-password');
nodeAuthToken = await getAuthToken(authUrl, authUser, authPassword);
authContents = await getAuthContents(authUrl, authUser, authPassword);
}
// Remove http: or https: from front of registry.
@ -101,8 +97,7 @@ async function writeRegistryToFile(
const alwaysAuthString: string = `always-auth=${alwaysAuth}`;
if(scope && includeBothRegistries === "true") {
const registryStringNoScope = `registry=${registryUrl}`;
const authToken = `_auth=${nodeAuthToken}`
newContents += `${registryStringNoScope}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}${os.EOL}${authToken}`;
newContents += `${registryStringNoScope}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}${os.EOL}${authContents}`;
} else {
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
}