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);
|
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();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user