Added auth for private servers #7
29
index.js
29
index.js
@ -90,12 +90,11 @@ async function postCode() {
|
||||
|
||||
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) => {
|
||||
core.info(`Key: ${key}`);
|
||||
});
|
||||
|
||||
core.info(files_to_push);
|
||||
|
||||
const login_arguments = {
|
||||
token: token,
|
||||
username: username,
|
||||
@ -106,20 +105,34 @@ async function postCode() {
|
||||
path: path,
|
||||
};
|
||||
|
||||
core.info(`Trying to upload the following files to ${branch}:`);
|
||||
Object.keys(login_arguments).forEach((key) => {
|
||||
core.info(`Key: ${key}`);
|
||||
});
|
||||
core.info("login_arguments:");
|
||||
core.info(JSON.stringify(login_arguments, null, 2));
|
||||
|
||||
const errorMessage = validateAuthentication(token, username, password);
|
||||
if (errorMessage) {
|
||||
core.error(errorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
const api = new ScreepsAPI(login_arguments);
|
||||
let api = new ScreepsAPI(login_arguments);
|
||||
if (token) {
|
||||
const response = await api.code.set(branch, files_to_push);
|
||||
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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user