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

View file

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