浏览代码

Fixed SSH authentication + uploads folder check

NGPixel 8 年之前
父节点
当前提交
3b5c0a9b74
共有 5 个文件被更改,包括 32 次插入15 次删除
  1. 6 0
      CHANGELOG.md
  2. 3 4
      app/data.yml
  3. 4 5
      config.sample.yml
  4. 18 5
      libs/git.js
  5. 1 1
      libs/local.js

+ 6 - 0
CHANGELOG.md

@@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file.
 This project adheres to [Semantic Versioning](http://semver.org/).
 
 ## [Unreleased]
+### Fixed
+- Fixed folder name typo during uploads folder permissions check
+- Fixed SSH authentication for Git
+
+### Changed
+- Removed separate OAuth authentication option. Select basic authentication to use tokens.
 
 ## [v1.0-beta.3] - 2017-02-10
 ### Added

+ 3 - 4
app/data.yml

@@ -22,8 +22,8 @@ defaults:
     public: false
     auth:
       local:
-        enabled: true 
-      microsoft: 
+        enabled: true
+      microsoft:
         enabled: false
       google:
         enabled: false
@@ -39,10 +39,9 @@ defaults:
         type: basic
         username: null
         password: null
-        publicKey: null
         privateKey: null
         sslVerify: true
       signature:
         name: Wiki
         email: wiki@example.com
-# ---------------------------------
+# ---------------------------------

+ 4 - 5
config.sample.yml

@@ -100,18 +100,17 @@ git:
   branch: master
   auth:
 
-    # Type: basic, oauth or ssh
+    # Type: basic or ssh
     type: ssh
 
+    # Only for Basic authentication:
     username: marty
-
-    # Password, OAuth token or private key passphrase:
     password: MartyMcFly88
 
     # Only for SSH authentication:
-    publicKey: /etc/wiki/keys/git.pem
     privateKey: /etc/wiki/keys/git.pem
+
     sslVerify: true
   signature:
     name: Marty
-    email: marty@example.com
+    email: marty@example.com

+ 18 - 5
libs/git.js

@@ -89,19 +89,32 @@ module.exports = {
       // Initialize remote
 
       let urlObj = URL.parse(appconfig.git.url)
-      urlObj.auth = appconfig.git.auth.username + ((appconfig.git.auth.type !== 'ssh') ? ':' + appconfig.git.auth.password : '')
+      if (appconfig.git.auth.type !== 'ssh') {
+        urlObj.auth = appconfig.git.auth.username + ':' + appconfig.git.auth.password
+      }
       self._url = URL.format(urlObj)
 
+      let gitConfigs = [
+        () => { return self._git.exec('config', ['--local', 'user.name', self._signature.name]) },
+        () => { return self._git.exec('config', ['--local', 'user.email', self._signature.email]) },
+        () => { return self._git.exec('config', ['--local', '--bool', 'http.sslVerify', _.toString(appconfig.git.auth.sslVerify)]) }
+      ]
+
+      if (appconfig.git.auth.type === 'ssh') {
+        gitConfigs.push(() => {
+          return self._git.exec('config', ['--local', 'core.sshCommand', 'ssh -i "' + appconfig.git.auth.privateKey + '" -o StrictHostKeyChecking=no'])
+        })
+      }
+
       return self._git.exec('remote', 'show').then((cProc) => {
         let out = cProc.stdout.toString()
         if (_.includes(out, 'origin')) {
           return true
         } else {
-          return Promise.join(
-            self._git.exec('config', ['--local', 'user.name', self._signature.name]),
-            self._git.exec('config', ['--local', 'user.email', self._signature.email])
-          ).then(() => {
+          return Promise.each(gitConfigs, fn => { return fn() }).then(() => {
             return self._git.exec('remote', ['add', 'origin', self._url])
+          }).catch(err => {
+            winston.error(err)
           })
         }
       })

+ 1 - 1
libs/local.js

@@ -114,7 +114,7 @@ module.exports = {
       fs.ensureDirSync(path.resolve(ROOTPATH, appconfig.paths.repo, './uploads'))
 
       if (os.type() !== 'Windows_NT') {
-        fs.chmodSync(path.resolve(ROOTPATH, appconfig.paths.repo, './upload'), '644')
+        fs.chmodSync(path.resolve(ROOTPATH, appconfig.paths.repo, './uploads'), '644')
       }
     } catch (err) {
       winston.error(err)