Added auth for private servers (#7)
All checks were successful
Lint / pre-commit Linting (push) Successful in 45s

Reviewed-on: #7
Co-authored-by: Philipp Horstenkamp <philipp@horstenkamp.de>
Co-committed-by: Philipp Horstenkamp <philipp@horstenkamp.de>
This commit is contained in:
Philipp Horstenkamp 2023-11-26 22:24:16 +01:00 committed by Philipp Horstenkamp
parent 6f5729c12a
commit e7678a5f66

View File

@ -90,12 +90,11 @@ async function postCode() {
const files_to_push = await readFilesIntoDict(pattern, prefix); const files_to_push = await readFilesIntoDict(pattern, prefix);
core.info(`Trying to upload the following files to ${branch}:`);
Object.keys(files_to_push).forEach((key) => { Object.keys(files_to_push).forEach((key) => {
core.info(`Key: ${key}`); core.info(`Key: ${key}`);
}); });
core.info(files_to_push);
const login_arguments = { const login_arguments = {
token: token, token: token,
username: username, username: username,
@ -106,20 +105,34 @@ async function postCode() {
path: path, path: path,
}; };
core.info(`Trying to upload the following files to ${branch}:`); core.info("login_arguments:");
Object.keys(login_arguments).forEach((key) => { core.info(JSON.stringify(login_arguments, null, 2));
core.info(`Key: ${key}`);
});
const errorMessage = validateAuthentication(token, username, password); const errorMessage = validateAuthentication(token, username, password);
if (errorMessage) { if (errorMessage) {
core.error(errorMessage); core.error(errorMessage);
return; return;
} }
let api = new ScreepsAPI(login_arguments);
const api = new ScreepsAPI(login_arguments); if (token) {
const response = await api.code.set(branch, files_to_push); const response = await api.code.set(branch, files_to_push);
core.info(JSON.stringify(response, null, 2)); core.info(JSON.stringify(response, null, 2));
console.log(`Code set successfully to ${branch}`);
} else {
let response;
core.info(`Logging in as user ${username}`);
response = await Promise.resolve()
.then(() => api.auth(username, password, login_arguments))
.then(() => {
api.code.set(branch, files_to_push);
})
.then(() => {
console.log(`Code set successfully to ${branch}`);
})
.catch((err) => {
console.error("Error:", err);
});
}
} }
postCode(); postCode();