aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/tests/cli/peertube.ts2
-rw-r--r--server/tools/peertube-auth.ts113
-rwxr-xr-xserver/tools/peertube.ts2
3 files changed, 57 insertions, 60 deletions
diff --git a/server/tests/cli/peertube.ts b/server/tests/cli/peertube.ts
index 65cb05a1a..7a712bc4e 100644
--- a/server/tests/cli/peertube.ts
+++ b/server/tests/cli/peertube.ts
@@ -44,6 +44,8 @@ describe('Test CLI wrapper', function () {
44 }) 44 })
45 45
46 after(async function () { 46 after(async function () {
47 this.timeout(10000)
48
47 await execCLI(cmd + ` auth del ${server.url}`) 49 await execCLI(cmd + ` auth del ${server.url}`)
48 50
49 killallServers([ server ]) 51 killallServers([ server ])
diff --git a/server/tools/peertube-auth.ts b/server/tools/peertube-auth.ts
index 33438811e..a962944a4 100644
--- a/server/tools/peertube-auth.ts
+++ b/server/tools/peertube-auth.ts
@@ -5,34 +5,25 @@ import { getSettings, writeSettings, netrc } from './cli'
5import { isHostValid } from '../helpers/custom-validators/servers' 5import { isHostValid } from '../helpers/custom-validators/servers'
6import { isUserUsernameValid } from '../helpers/custom-validators/users' 6import { isUserUsernameValid } from '../helpers/custom-validators/users'
7 7
8function delInstance (url: string) { 8async function delInstance (url: string) {
9 return new Promise((res, rej): void => { 9 const settings = await getSettings()
10 getSettings() 10
11 .then(async (settings) => { 11 settings.remotes.splice(settings.remotes.indexOf(url))
12 settings.remotes.splice(settings.remotes.indexOf(url)) 12 await writeSettings(settings)
13 await writeSettings(settings) 13
14 delete netrc.machines[url] 14 delete netrc.machines[url]
15 netrc.save() 15 await netrc.save()
16 res()
17 })
18 .catch(err => rej(err))
19 })
20} 16}
21 17
22async function setInstance (url: string, username: string, password: string) { 18async function setInstance (url: string, username: string, password: string) {
23 return new Promise((res, rej): void => { 19 const settings = await getSettings()
24 getSettings() 20 if (settings.remotes.indexOf(url) === -1) {
25 .then(async settings => { 21 settings.remotes.push(url)
26 if (settings.remotes.indexOf(url) === -1) { 22 }
27 settings.remotes.push(url) 23 await writeSettings(settings)
28 } 24
29 await writeSettings(settings) 25 netrc.machines[url] = { login: username, password }
30 netrc.machines[url] = { login: username, password } 26 await netrc.save()
31 netrc.save()
32 res()
33 })
34 .catch(err => rej(err))
35 })
36} 27}
37 28
38function isURLaPeerTubeInstance (url: string) { 29function isURLaPeerTubeInstance (url: string) {
@@ -71,56 +62,60 @@ program
71 required: true 62 required: true
72 } 63 }
73 } 64 }
74 }, (_, result) => { 65 }, async (_, result) => {
75 setInstance(result.url, result.username, result.password) 66 await setInstance(result.url, result.username, result.password)
67
68 process.exit(0)
76 }) 69 })
77 }) 70 })
78 71
79program 72program
80 .command('del <url>') 73 .command('del <url>')
81 .description('unregisters a remote instance') 74 .description('unregisters a remote instance')
82 .action((url) => { 75 .action(async url => {
83 delInstance(url) 76 await delInstance(url)
77
78 process.exit(0)
84 }) 79 })
85 80
86program 81program
87 .command('list') 82 .command('list')
88 .description('lists registered remote instances') 83 .description('lists registered remote instances')
89 .action(() => { 84 .action(async () => {
90 getSettings() 85 const settings = await getSettings()
91 .then(settings => { 86 const table = new Table({
92 const table = new Table({ 87 head: ['instance', 'login'],
93 head: ['instance', 'login'], 88 colWidths: [30, 30]
94 colWidths: [30, 30] 89 })
95 }) 90 netrc.loadSync()
96 netrc.loadSync() 91 settings.remotes.forEach(element => {
97 settings.remotes.forEach(element => { 92 table.push([
98 table.push([ 93 element,
99 element, 94 netrc.machines[element].login
100 netrc.machines[element].login 95 ])
101 ]) 96 })
102 }) 97
103 98 console.log(table.toString())
104 console.log(table.toString()) 99
105 }) 100 process.exit(0)
106 }) 101 })
107 102
108program 103program
109 .command('set-default <url>') 104 .command('set-default <url>')
110 .description('set an existing entry as default') 105 .description('set an existing entry as default')
111 .action((url) => { 106 .action(async url => {
112 getSettings() 107 const settings = await getSettings()
113 .then(settings => { 108 const instanceExists = settings.remotes.indexOf(url) !== -1
114 const instanceExists = settings.remotes.indexOf(url) !== -1 109
115 110 if (instanceExists) {
116 if (instanceExists) { 111 settings.default = settings.remotes.indexOf(url)
117 settings.default = settings.remotes.indexOf(url) 112 await writeSettings(settings)
118 writeSettings(settings) 113
119 } else { 114 process.exit(0)
120 console.log('<url> is not a registered instance.') 115 } else {
121 process.exit(-1) 116 console.log('<url> is not a registered instance.')
122 } 117 process.exit(-1)
123 }) 118 }
124 }) 119 })
125 120
126program.on('--help', function () { 121program.on('--help', function () {
diff --git a/server/tools/peertube.ts b/server/tools/peertube.ts
index c8b9fa744..5d3ab2815 100755
--- a/server/tools/peertube.ts
+++ b/server/tools/peertube.ts
@@ -58,7 +58,7 @@ if (!process.argv.slice(2).length) {
58 ,"\\/ 58 ,"\\/
59 _,.__/"\\/_ (the CLI for red chocobos) 59 _,.__/"\\/_ (the CLI for red chocobos)
60 / \\) "./, ". 60 / \\) "./, ".
61 --/---"---" "-) )---- by Chocobozzz et al.`) 61 --/---"---" "-) )---- by Chocobozzz et al.\n`)
62} 62}
63 63
64getSettings() 64getSettings()