aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/peertube-auth.ts
diff options
context:
space:
mode:
authorbuoyantair <buoyantair@protonmail.com>2018-11-16 02:37:16 +0530
committerbuoyantair <buoyantair@protonmail.com>2018-11-16 02:37:16 +0530
commitae28cdf327d782e629379eee1999096ca2a5d74b (patch)
treebfe0d4b3a232d75161fe5bba9196553a388fc02a /server/tools/peertube-auth.ts
parentd4681c0074ba51c62a3aeb9fb3f2cd071dd21e32 (diff)
parent8cf998733496d44fa564e2e252356b871756c984 (diff)
downloadPeerTube-ae28cdf327d782e629379eee1999096ca2a5d74b.tar.gz
PeerTube-ae28cdf327d782e629379eee1999096ca2a5d74b.tar.zst
PeerTube-ae28cdf327d782e629379eee1999096ca2a5d74b.zip
Merge from upstream
Diffstat (limited to 'server/tools/peertube-auth.ts')
-rw-r--r--server/tools/peertube-auth.ts113
1 files changed, 54 insertions, 59 deletions
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 () {