s9n-devops-agent 2.0.18-dev.1 → 2.0.18-dev.11

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.
@@ -3,11 +3,15 @@ import path from 'path';
3
3
  import { fileURLToPath } from 'url';
4
4
  import { dirname } from 'path';
5
5
 
6
+ import os from 'os';
7
+
6
8
  const __filename = fileURLToPath(import.meta.url);
7
9
  const __dirname = dirname(__filename);
8
- const rootDir = path.join(__dirname, '..');
9
10
 
10
- const CREDENTIALS_PATH = process.env.DEVOPS_CREDENTIALS_PATH || path.join(rootDir, 'local_deploy', 'credentials.json');
11
+ // Use home directory for persistent storage across package updates
12
+ const HOME_DIR = os.homedir();
13
+ const CONFIG_DIR = path.join(HOME_DIR, '.devops-agent');
14
+ const CREDENTIALS_PATH = process.env.DEVOPS_CREDENTIALS_PATH || path.join(CONFIG_DIR, 'credentials.json');
11
15
 
12
16
  // Simple obfuscation to prevent casual shoulder surfing
13
17
  // NOTE: This is NOT strong encryption. In a production environment with sensitive keys,
@@ -38,15 +42,33 @@ export class CredentialsManager {
38
42
  console.error('Failed to load credentials:', error.message);
39
43
  this.credentials = {};
40
44
  }
45
+ } else {
46
+ // Migration: Check for old local_deploy location
47
+ const oldPath = path.join(__dirname, '..', 'local_deploy', 'credentials.json');
48
+ if (fs.existsSync(oldPath)) {
49
+ try {
50
+ const rawData = fs.readFileSync(oldPath, 'utf8');
51
+ const data = JSON.parse(rawData);
52
+ // Deobfuscate sensitive values
53
+ if (data.groqApiKey) {
54
+ data.groqApiKey = deobfuscate(data.groqApiKey);
55
+ }
56
+ this.credentials = data;
57
+ // Save to new location immediately
58
+ this.save();
59
+ } catch (e) {
60
+ // Ignore migration errors
61
+ }
62
+ }
41
63
  }
42
64
  }
43
65
 
44
66
  save() {
45
67
  try {
46
- // Ensure local_deploy exists
47
- const localDeployDir = path.dirname(CREDENTIALS_PATH);
48
- if (!fs.existsSync(localDeployDir)) {
49
- fs.mkdirSync(localDeployDir, { recursive: true });
68
+ // Ensure config dir exists
69
+ const configDir = path.dirname(CREDENTIALS_PATH);
70
+ if (!fs.existsSync(configDir)) {
71
+ fs.mkdirSync(configDir, { recursive: true });
50
72
  }
51
73
 
52
74
  // Clone and obfuscate