closer-cli 2.61.0 → 2.62.0

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/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [2.62.0](https://code.hfarm.dev/closer/closer/compare/v2.61.0...v2.62.0) (2023-06-20)
7
+
8
+
9
+ ### Features
10
+
11
+ * **PJX-848:** Closer CLI: comando per generare API Key ([8a2f2fb](https://code.hfarm.dev/closer/closer/commits/8a2f2fb86d81ff75ea25a933485c68da8ba874fd))
12
+
13
+
14
+
15
+
16
+
6
17
  # [2.61.0](https://code.hfarm.dev/closer/closer/compare/v2.60.2...v2.61.0) (2023-06-09)
7
18
 
8
19
  **Note:** Version bump only for package closer-cli
@@ -0,0 +1,53 @@
1
+ /* eslint-disable no-await-in-loop */
2
+ /* eslint-disable no-restricted-syntax */
3
+ /* eslint-disable no-console */
4
+ import chalk from 'chalk'
5
+ import qs from 'qs'
6
+ import axios from 'axios'
7
+
8
+ export const command = 'apikey:generate'
9
+ export const desc = 'Generate new API Key'
10
+
11
+ export function builder(yargs) {
12
+ yargs
13
+ .usage(`Usage: ${chalk.cyan('$0 apikey:generate')} [options]`)
14
+ .option('username', {
15
+ alias: 'u',
16
+ describe: 'Define username to associate',
17
+ type: 'string',
18
+ demandOption: true
19
+ })
20
+ .option('name', {
21
+ alias: 'n',
22
+ describe: 'Define API Key name',
23
+ type: 'string',
24
+ demandOption: true
25
+ })
26
+ }
27
+
28
+ export async function handler(argv) {
29
+ const query = qs.stringify({ name: argv.name, username: argv.username })
30
+
31
+ const protocol =
32
+ argv.endpoint.includes('localhost') || argv.endpoint.includes('127.0.0.1') ? 'http' : 'https'
33
+
34
+ const url = `${protocol}://${argv.endpoint}/auth/apikey?${query}`
35
+
36
+ try {
37
+ const response = await axios.post(url, {
38
+ headers: { 'x-closer-secret': argv.secretKey }
39
+ })
40
+
41
+ console.log('')
42
+ console.log(chalk.green('API Key generated successfully'))
43
+ console.log(`${chalk.bold('Key')}: ${response.data?.key}`)
44
+ console.log(`${chalk.bold('Name')}: ${response.data?.name}`)
45
+ console.log('')
46
+ process.exit(0)
47
+ } catch (e) {
48
+ console.log('')
49
+ console.log(chalk.red(`[ERROR] API Key generation gone wrong: ${e.response.data.message}`))
50
+ console.log('')
51
+ process.exit(1)
52
+ }
53
+ }
package/index.js CHANGED
@@ -7,6 +7,7 @@ import yargs from 'yargs'
7
7
  import * as ImportData from './cmds/importData.js'
8
8
  import * as ImportMedia from './cmds/importMedia.js'
9
9
  import * as ExportData from './cmds/exportData.js'
10
+ import * as ApiKeyGenerator from './cmds/apiKeyGenerate.js'
10
11
 
11
12
  console.log(chalk.bold(`\nšŸ‘œ Closer CLI (${pkg.version})\n`))
12
13
 
@@ -26,5 +27,11 @@ yargs(process.argv.slice(2))
26
27
  .command(ImportData.command, ImportData.desc, ImportData.builder, ImportData.handler)
27
28
  .command(ImportMedia.command, ImportMedia.desc, ImportMedia.builder, ImportMedia.handler)
28
29
  .command(ExportData.command, ExportData.desc, ExportData.builder, ExportData.handler)
30
+ .command(
31
+ ApiKeyGenerator.command,
32
+ ApiKeyGenerator.desc,
33
+ ApiKeyGenerator.builder,
34
+ ApiKeyGenerator.handler
35
+ )
29
36
  .help()
30
37
  .version().argv
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "closer-cli",
3
- "version": "2.61.0",
3
+ "version": "2.62.0",
4
4
  "description": "",
5
5
  "exports": "./index.js",
6
6
  "type": "module",
@@ -24,5 +24,5 @@
24
24
  "ws": "^8.0.0",
25
25
  "yargs": "^17.0.1"
26
26
  },
27
- "gitHead": "cca51e9e3f6eb1d30847654d46ea3e342becc45e"
27
+ "gitHead": "bd2d308c851279f83027181a54ac22f8d1e80679"
28
28
  }