@annexfour/cli 1.0.0 → 1.0.1

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.
Files changed (2) hide show
  1. package/bin/index.js +43 -25
  2. package/package.json +1 -1
package/bin/index.js CHANGED
@@ -15,35 +15,40 @@ program
15
15
  .description('AnnexFour Compliance Scanner Wrapper')
16
16
  .version('1.0.0');
17
17
 
18
+ // Helper for creating config
19
+ async function performLogin() {
20
+ console.log("--- Annexfour Global Login ---");
21
+ console.log("Please paste your API Token (generated in Settings -> Developer).");
22
+
23
+ const answers = await inquirer.prompt([
24
+ {
25
+ type: 'password',
26
+ name: 'token',
27
+ message: 'API Token:',
28
+ mask: '*',
29
+ validate: (input) => input.startsWith('anx_') ? true : "Token must start with 'anx_'"
30
+ }
31
+ ]);
32
+
33
+ try {
34
+ if (!fs.existsSync(CONFIG_DIR)) {
35
+ fs.mkdirSync(CONFIG_DIR, { recursive: true });
36
+ }
37
+ fs.writeFileSync(CONFIG_FILE, JSON.stringify({ token: answers.token }, null, 2));
38
+ console.log(`\n[+] Success! Token saved to ${CONFIG_FILE}`);
39
+ return answers.token;
40
+ } catch (error) {
41
+ console.error("Error saving config:", error.message);
42
+ process.exit(1);
43
+ }
44
+ }
45
+
18
46
  program
19
47
  .command('login')
20
48
  .description('Authenticate with Annexfour Platform')
21
49
  .action(async () => {
22
- console.log("--- Annexfour Global Login ---");
23
- console.log("Please paste your API Token (generated in Settings -> Developer).");
24
-
25
- // Check if inquirer supports password masks correctly in this environment, otherwise fallback
26
- const answers = await inquirer.prompt([
27
- {
28
- type: 'password',
29
- name: 'token',
30
- message: 'API Token:',
31
- mask: '*',
32
- validate: (input) => input.startsWith('anx_') ? true : "Token must start with 'anx_'"
33
- }
34
- ]);
35
-
36
- try {
37
- if (!fs.existsSync(CONFIG_DIR)) {
38
- fs.mkdirSync(CONFIG_DIR, { recursive: true });
39
- }
40
- fs.writeFileSync(CONFIG_FILE, JSON.stringify({ token: answers.token }, null, 2));
41
- console.log(`\n[+] Success! Token saved to ${CONFIG_FILE}`);
42
- console.log("You can now run 'npx @annexfour/cli scan' without arguments.");
43
- } catch (error) {
44
- console.error("Error saving config:", error.message);
45
- process.exit(1);
46
- }
50
+ await performLogin();
51
+ console.log("You can now run 'npx @annexfour/cli scan' without arguments.");
47
52
  });
48
53
 
49
54
  program
@@ -65,6 +70,19 @@ program
65
70
  process.exit(1);
66
71
  }
67
72
 
73
+ // 2. Check Authentication
74
+ let token = options.token;
75
+ if (!token) {
76
+ // Check config file
77
+ if (fs.existsSync(CONFIG_FILE)) {
78
+ // Good, docker will pick it up via mount
79
+ } else {
80
+ console.log("[!] No API Token found. Please authenticate to continue.");
81
+ await performLogin();
82
+ // Token is now saved, docker will pick it up via mount
83
+ }
84
+ }
85
+
68
86
  const scanPath = targetPath ? path.resolve(targetPath) : process.cwd();
69
87
 
70
88
  // Construct Docker arguments
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@annexfour/cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "AnnexFour Compliance Scanner CLI Wrapper",
5
5
  "main": "bin/index.js",
6
6
  "bin": {