aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/helpers/core-utils.ts2
-rw-r--r--server/tools/cli.ts47
-rw-r--r--server/tools/peertube-auth.ts4
3 files changed, 31 insertions, 22 deletions
diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts
index 531ccfba9..0ec45eb2e 100644
--- a/server/helpers/core-utils.ts
+++ b/server/helpers/core-utils.ts
@@ -153,7 +153,7 @@ function isProdInstance () {
153} 153}
154 154
155function getAppNumber () { 155function getAppNumber () {
156 return process.env.NODE_APP_INSTANCE 156 return process.env.NODE_APP_INSTANCE || ''
157} 157}
158 158
159// --------------------------------------------------------------------------- 159// ---------------------------------------------------------------------------
diff --git a/server/tools/cli.ts b/server/tools/cli.ts
index 7036ae3ec..671b56ed0 100644
--- a/server/tools/cli.ts
+++ b/server/tools/cli.ts
@@ -73,14 +73,13 @@ function getRemoteObjectOrDie (
73): { url: string, username: string, password: string } { 73): { url: string, username: string, password: string } {
74 const options = program.opts() 74 const options = program.opts()
75 75
76 const manualOptionMode = options.url || options.username || options.password 76 function exitIfNoOptions (options: string[], errorPrefix: string = '') {
77
78 // Check parameters validity
79 if (manualOptionMode || settings.remotes.length === 0 || Object.keys(netrc.machines).length === 0) {
80 let exit = false 77 let exit = false
81 78
82 for (const key of [ 'url', 'username', 'password' ]) { 79 for (const key of options) {
83 if (!options[key]) { 80 if (!options[key]) {
81 if (exit === false && errorPrefix) console.error(errorPrefix)
82
84 console.error(`--${key} field is required`) 83 console.error(`--${key} field is required`)
85 exit = true 84 exit = true
86 } 85 }
@@ -89,26 +88,36 @@ function getRemoteObjectOrDie (
89 if (exit) process.exit(-1) 88 if (exit) process.exit(-1)
90 } 89 }
91 90
92 if (!manualOptionMode) { 91 // If username or password are specified, both are mandatory
93 let url: string = options.url 92 if (options.username || options.password) {
94 let username: string = options.username 93 exitIfNoOptions([ 'username', 'password' ])
95 let password: string = options.password 94 }
96 95
97 if (!url && settings.default !== -1) url = settings.remotes[settings.default] 96 // If no available machines, url, username and password args are mandatory
97 if (Object.keys(netrc.machines).length === 0) {
98 exitIfNoOptions([ 'url', 'username', 'password' ], 'No account found in netrc')
99 }
98 100
99 const machine = netrc.machines[url] 101 if (settings.remotes.length === 0 || settings.default === -1) {
102 exitIfNoOptions([ 'url' ], 'No default instance found')
103 }
100 104
101 if (!username && machine) username = machine.login 105 let url: string = options.url
102 if (!password && machine) password = machine.password 106 let username: string = options.username
107 let password: string = options.password
103 108
104 return { url, username, password } 109 if (!url && settings.default !== -1) url = settings.remotes[settings.default]
105 }
106 110
107 return { 111 const machine = netrc.machines[url]
108 url: options.url, 112 if ((!username || !password) && !machine) {
109 username: options.username, 113 console.error('Cannot find existing configuration for %s.', url)
110 password: options.password 114 process.exit(-1)
111 } 115 }
116
117 if (!username && machine) username = machine.login
118 if (!password && machine) password = machine.password
119
120 return { url, username, password }
112} 121}
113 122
114function buildCommonVideoOptions (command: Command) { 123function buildCommonVideoOptions (command: Command) {
diff --git a/server/tools/peertube-auth.ts b/server/tools/peertube-auth.ts
index f8ac8b2ab..051156d66 100644
--- a/server/tools/peertube-auth.ts
+++ b/server/tools/peertube-auth.ts
@@ -47,7 +47,7 @@ function stripExtraneousFromPeerTubeUrl (url: string) {
47 ? url.indexOf('/', 8) 47 ? url.indexOf('/', 8)
48 : url.length 48 : url.length
49 49
50 return url.substr(0, urlLength) 50 return url.substring(0, urlLength)
51} 51}
52 52
53program 53program
@@ -89,7 +89,7 @@ program
89 // Check credentials 89 // Check credentials
90 try { 90 try {
91 // Strip out everything after the domain:port. 91 // Strip out everything after the domain:port.
92 // @see https://github.com/Chocobozzz/PeerTube/issues/3520 92 // See https://github.com/Chocobozzz/PeerTube/issues/3520
93 result.url = stripExtraneousFromPeerTubeUrl(result.url) 93 result.url = stripExtraneousFromPeerTubeUrl(result.url)
94 94
95 const server = buildServer(result.url) 95 const server = buildServer(result.url)