Skip to content

Commit

Permalink
fix: logger logs secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
NichArchA82 committed Sep 4, 2024
1 parent f691cb7 commit 0f5597a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
9 changes: 9 additions & 0 deletions command-handler/src/util/axios-error-handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function axiosError(e) {
const errorObj = {
data: e.response.data,
status: e.response.status,
stackTrace: e.stack

}
return errorObj;
}
7 changes: 5 additions & 2 deletions command-handler/src/util/get-devices-info.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'dotenv/config';
import axios from 'axios';
import log from './logger.js';
import logger from './logger.js';
import axiosError from './axios-error-handler.js';

const log = logger();

export default async function getDevices(serverName = null) {
//get all the devices from tailscale
Expand All @@ -10,7 +13,7 @@ export default async function getDevices(serverName = null) {
}
})
.catch(error => {
log.error('Failed to get devices from tailscale', error);
log.error('Failed to get devices from tailscale', axiosError(error));
});

//loop through the devices and get a devideId, and deviceIp
Expand Down
7 changes: 5 additions & 2 deletions command-handler/src/util/get-servers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'dotenv/config';
import axios from 'axios';
import log from './logger.js';
import axiosError from './axios-error-handler.js';
import logger from './logger.js';

const log = logger();

export default async function getServer() {
const data = await axios.get('https://api.hetzner.cloud/v1/servers', {
Expand All @@ -9,7 +12,7 @@ export default async function getServer() {
}
})
.catch(error => {
log.error('Failed to get servers from hetzner', error);
log.error('Failed to get servers from hetzner', axiosError(error));
});

return data;
Expand Down
17 changes: 10 additions & 7 deletions command-handler/src/util/hetzner-servers.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import log from './logger.js';
import logger from './logger.js';
import axios from 'axios';
import 'dotenv/config';
import formatUser from './format-user.js';
import getDevices from './get-devices-info.js';
import getServer from './get-servers.js';
import axiosError from './axios-error-handler.js';
import { uniqueNamesGenerator, colors, animals } from 'unique-names-generator';

const log = logger();

const delay = (ms) => {
return new Promise(resolve => setTimeout(resolve, ms));
}
Expand Down Expand Up @@ -58,7 +61,7 @@ export default {
}
})
.catch(error => {
log.error('There was an error creating the server', error);
log.error('There was an error creating the server', axiosError(error));
});

//set 2 minute delay
Expand All @@ -80,7 +83,7 @@ export default {
}
})
.catch(error => {
console.error('There was an error setting tags in tailscale', error);
console.error('There was an error setting tags in tailscale', axiosError(error));

});
//return info for tailscale
Expand Down Expand Up @@ -115,7 +118,7 @@ export default {
}
})
.catch(error => {
log.error('Failed to delete device in tailscale', error);
log.error('Failed to delete device in tailscale', axiosError(error));
});

//delete server from hetzner
Expand All @@ -125,7 +128,7 @@ export default {
}
})
.catch(error => {
log.error('Failed to delete the server in hetzner', error);
log.error('Failed to delete the server in hetzner', axiosError(error));
});

app.client.chat.postEphemeral({
Expand Down Expand Up @@ -208,7 +211,7 @@ export default {
}
})
.catch(error => {
log.error('Error starting the server', error);
log.error('Error starting the server', axiosError(error));
app.client.chat.postEphemeral({
channel: `${body.channel.id}`,
user: `${body.user.id}`,
Expand All @@ -232,7 +235,7 @@ export default {
}
})
.catch(error => {
log.error('Error stopping the server', error);
log.error('Error stopping the server', axiosError(error));
app.client.chat.postEphemeral({
channel: `${body.channel.id}`,
user: `${body.user.id}`,
Expand Down

0 comments on commit 0f5597a

Please sign in to comment.