From 53185ae5ed21dc1bc4471d5dbecb148e65989d9f Mon Sep 17 00:00:00 2001 From: starxg <763860000@qq.com> Date: Tue, 6 Apr 2021 10:30:47 +0800 Subject: [PATCH 1/4] Update README.md --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0c3277a..a2ec7ff 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,13 @@ # Sync Config -### For the Terminus terminal +### For the [Terminus](https://github.com/Eugeny/terminus) terminal This plugin can Sync configuration files to GitHub Gist or Gitee Gist. ![](./screenshot.png) + +--- + +Like my work? + +[![ko-fi](https://www.ko-fi.com/img/donate_sm.png)](https://ko-fi.com/huangxingguang) From 09c0093773651580c792ee7e5c06bc0647264729 Mon Sep 17 00:00:00 2001 From: huangxingguang <591269@gmail.com> Date: Wed, 7 Apr 2021 01:05:16 +0800 Subject: [PATCH 2/4] add keytar lib --- package.json | 3 +- src/services/PasswordStorage.service.ts | 33 ++++ src/settingsTab.component.ts | 22 +++ webpack.config.js | 2 + yarn.lock | 206 +++++++++++++++++++++++- 5 files changed, 257 insertions(+), 9 deletions(-) create mode 100644 src/services/PasswordStorage.service.ts diff --git a/package.json b/package.json index 063a091..32bcb90 100755 --- a/package.json +++ b/package.json @@ -44,7 +44,8 @@ "typescript": "^4.2.3", "webpack": "^5.24.4", "webpack-cli": "^4.5.0", - "axios": "^0.21.1" + "axios": "^0.21.1", + "keytar": "^7.6.0" }, "peerDependencies": { "@angular/core": "^4.0.1" diff --git a/src/services/PasswordStorage.service.ts b/src/services/PasswordStorage.service.ts new file mode 100644 index 0000000..4f58860 --- /dev/null +++ b/src/services/PasswordStorage.service.ts @@ -0,0 +1,33 @@ +import { Injectable } from '@angular/core'; +import * as keytar from 'keytar' + + +function getKey(host, port) { + let key = `ssh@${host}` + if (port) { + key = `ssh@${host}:${port}` + } + return key; +} + +/** + * https://github.com/Eugeny/terminus/blob/bd46b08c9d909603eca4f1ca149d9a2d0155117f/terminus-ssh/src/services/passwordStorage.service.ts + */ +@Injectable({ providedIn: 'root' }) +export class PasswordStorageService { + + + + async savePassword({ host, port, user, password }): Promise { + + return keytar.setPassword(getKey(host, port), user, password) + } + + async deletePassword({ host, port, user }): Promise { + await keytar.deletePassword(getKey(host, port), user) + } + + async loadPassword({ host, port, user }): Promise { + return keytar.getPassword(getKey(host, port), user) + } +} \ No newline at end of file diff --git a/src/settingsTab.component.ts b/src/settingsTab.component.ts index d879d77..25672e2 100644 --- a/src/settingsTab.component.ts +++ b/src/settingsTab.component.ts @@ -2,6 +2,8 @@ import { Component, OnInit } from '@angular/core' import { ConfigService, ElectronService, } from 'terminus-core' import { ToastrService } from 'ngx-toastr' import { getGist, syncGist } from 'api'; +import { PasswordStorageService } from 'services/PasswordStorage.service'; + /** @hidden */ @Component({ @@ -15,10 +17,30 @@ export class SyncConfigSettingsTabComponent implements OnInit { public config: ConfigService, private toastr: ToastrService, private electron: ElectronService, + private passwordStorage: PasswordStorageService, ) { } ngOnInit(): void { + // keytar.getPassword(`ssh@43.128.36.153:22`, 'root').then(d => { + // console.log(d); + // }).catch(e => { + // console.log(e); + // }) + + // keytar.setPassword(`ssh@43.128.36.153:22`, 'root', '123').then(d => { + // console.log(d); + // }).catch(e => { + // console.log(e); + // }) + this.passwordStorage.loadPassword({ + host: 'starxg.com', + port: 22, + user: 'root' + }).then(d => { + console.log(d); + }) + } private dateFormat(date: Date): any { diff --git a/webpack.config.js b/webpack.config.js index 31e343c..a37d832 100755 --- a/webpack.config.js +++ b/webpack.config.js @@ -34,6 +34,8 @@ module.exports = { ] }, externals: [ + 'keytar', + 'axios', 'fs', 'ngx-toastr', /^rxjs/, diff --git a/yarn.lock b/yarn.lock index 916b041..1061bd0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -515,6 +515,11 @@ balanced-match@^1.0.0: resolved "https://registry.npm.taobao.org/balanced-match/download/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c= +base64-js@^1.3.1: + version "1.5.1" + resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a" + integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA== + base@^0.11.1: version "0.11.2" resolved "https://registry.npm.taobao.org/base/download/base-0.11.2.tgz#7bde5ced145b6d551a90db87f83c558b4eb48a8f" @@ -540,6 +545,15 @@ big.js@^5.2.2: resolved "https://registry.npm.taobao.org/big.js/download/big.js-5.2.2.tgz#65f0af382f578bcdc742bd9c281e9cb2d7768328" integrity sha1-ZfCvOC9Xi83HQr2cKB6cstd2gyg= +bl@^4.0.3: + version "4.1.0" + resolved "https://registry.yarnpkg.com/bl/-/bl-4.1.0.tgz#451535264182bec2fbbc83a62ab98cf11d9f7b3a" + integrity sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w== + dependencies: + buffer "^5.5.0" + inherits "^2.0.4" + readable-stream "^3.4.0" + boolean@^3.0.1: version "3.0.3" resolved "https://registry.npm.taobao.org/boolean/download/boolean-3.0.3.tgz#0fee0c9813b66bef25a8a6a904bb46736d05f024" @@ -590,6 +604,14 @@ buffer-from@^1.0.0: resolved "https://registry.npm.taobao.org/buffer-from/download/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef" integrity sha1-MnE7wCj3XAL9txDXx7zsHyxgcO8= +buffer@^5.5.0: + version "5.7.1" + resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.7.1.tgz#ba62e7c13133053582197160851a8f648e99eed0" + integrity sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ== + dependencies: + base64-js "^1.3.1" + ieee754 "^1.1.13" + cache-base@^1.0.1: version "1.0.1" resolved "https://registry.npm.taobao.org/cache-base/download/cache-base-1.0.1.tgz#0a7f46416831c8b662ee36fe4e7c59d76f666ab2" @@ -699,6 +721,11 @@ character-parser@^2.1.1: dependencies: is-regex "^1.0.3" +chownr@^1.1.1: + version "1.1.4" + resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.4.tgz#6fc9d7b42d32a583596337666e7d08084da2cc6b" + integrity sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg== + chownr@^2.0.0: version "2.0.0" resolved "https://registry.npm.taobao.org/chownr/download/chownr-2.0.0.tgz#15bfbe53d2eab4cf70f18a8cd68ebe5b3cb1dece" @@ -988,6 +1015,18 @@ decompress-response@^3.3.0: dependencies: mimic-response "^1.0.0" +decompress-response@^4.2.0: + version "4.2.1" + resolved "https://registry.yarnpkg.com/decompress-response/-/decompress-response-4.2.1.tgz#414023cc7a302da25ce2ec82d0d5238ccafd8986" + integrity sha512-jOSne2qbyE+/r8G1VU+G/82LBs2Fs4LAsTiLSHOCOMZQl2OKZ6i8i4IyHemTe+/yIXOtTcRQMzPcgyhoFlqPkw== + dependencies: + mimic-response "^2.0.0" + +deep-extend@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac" + integrity sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA== + defer-to-connect@^1.0.1: version "1.1.3" resolved "https://registry.npm.taobao.org/defer-to-connect/download/defer-to-connect-1.1.3.tgz?cache=0&sync_timestamp=1614211480566&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fdefer-to-connect%2Fdownload%2Fdefer-to-connect-1.1.3.tgz#331ae050c08dcf789f8c83a7b81f0ed94f4ac591" @@ -1032,6 +1071,11 @@ delegates@^1.0.0: resolved "https://registry.npm.taobao.org/delegates/download/delegates-1.0.0.tgz#84c6e159b81904fdca59a0ef44cd870d31250f9a" integrity sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o= +detect-libc@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b" + integrity sha1-+hN8S9aY7fVc1c0CrFWfkaTEups= + detect-node@^2.0.4: version "2.0.5" resolved "https://registry.npm.taobao.org/detect-node/download/detect-node-2.0.5.tgz#9d270aa7eaa5af0b72c4c9d9b814e7f4ce738b79" @@ -1084,7 +1128,7 @@ encodeurl@^1.0.2: resolved "https://registry.npm.taobao.org/encodeurl/download/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59" integrity sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k= -end-of-stream@^1.1.0: +end-of-stream@^1.1.0, end-of-stream@^1.4.1: version "1.4.4" resolved "https://registry.npm.taobao.org/end-of-stream/download/end-of-stream-1.4.4.tgz#5ae64a5f45057baf3626ec14da0ca5e4b2431eb0" integrity sha1-WuZKX0UFe682JuwU2gyl5LJDHrA= @@ -1253,6 +1297,11 @@ expand-brackets@^2.1.4: snapdragon "^0.8.1" to-regex "^3.0.1" +expand-template@^2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/expand-template/-/expand-template-2.0.3.tgz#6e14b3fcee0f3a6340ecb57d2e8918692052a47c" + integrity sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg== + ext@^1.1.2: version "1.4.0" resolved "https://registry.npm.taobao.org/ext/download/ext-1.4.0.tgz#89ae7a07158f79d35517882904324077e4379244" @@ -1405,6 +1454,11 @@ fragment-cache@^0.2.1: dependencies: map-cache "^0.2.2" +fs-constants@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad" + integrity sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow== + fs-extra@^8.1.0: version "8.1.0" resolved "https://registry.npm.taobao.org/fs-extra/download/fs-extra-8.1.0.tgz?cache=0&sync_timestamp=1611075413359&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Ffs-extra%2Fdownload%2Ffs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0" @@ -1502,6 +1556,11 @@ getpass@^0.1.1: dependencies: assert-plus "^1.0.0" +github-from-package@0.0.0: + version "0.0.0" + resolved "https://registry.yarnpkg.com/github-from-package/-/github-from-package-0.0.0.tgz#97fb5d96bfde8973313f20e8288ef9a167fa64ce" + integrity sha1-l/tdlr/eiXMxPyDoKI75oWf6ZM4= + glob-to-regexp@^0.4.1: version "0.4.1" resolved "https://registry.npm.taobao.org/glob-to-regexp/download/glob-to-regexp-0.4.1.tgz?cache=0&sync_timestamp=1603203165288&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fglob-to-regexp%2Fdownload%2Fglob-to-regexp-0.4.1.tgz#c75297087c851b9a578bd217dd59a92f59fe546e" @@ -1687,6 +1746,11 @@ icss-utils@^5.0.0, icss-utils@^5.1.0: resolved "https://registry.npm.taobao.org/icss-utils/download/icss-utils-5.1.0.tgz?cache=0&sync_timestamp=1605801267950&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Ficss-utils%2Fdownload%2Ficss-utils-5.1.0.tgz#c6be6858abd013d768e98366ae47e25d5887b1ae" integrity sha1-xr5oWKvQE9do6YNmrkfiXViHsa4= +ieee754@^1.1.13: + version "1.2.1" + resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352" + integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA== + import-local@^3.0.2: version "3.0.2" resolved "https://registry.npm.taobao.org/import-local/download/import-local-3.0.2.tgz#a8cfd0431d1de4a2199703d003e3e62364fa6db6" @@ -1715,12 +1779,12 @@ inflight@^1.0.4: once "^1.3.0" wrappy "1" -inherits@2, inherits@^2.0.3, inherits@~2.0.3: +inherits@2, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.3: version "2.0.4" resolved "https://registry.npm.taobao.org/inherits/download/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" integrity sha1-D6LGT5MpF8NDOg3tVTY6rjdBa3w= -ini@^1.3.4: +ini@^1.3.4, ini@~1.3.0: version "1.3.8" resolved "https://registry.npm.taobao.org/ini/download/ini-1.3.8.tgz?cache=0&sync_timestamp=1607907842483&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fini%2Fdownload%2Fini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c" integrity sha1-op2kJbSIBvNHZ6Tvzjlyaa8oQyw= @@ -2001,6 +2065,14 @@ jstransformer@1.0.0: is-promise "^2.0.0" promise "^7.0.1" +keytar@^7.6.0: + version "7.6.0" + resolved "https://registry.yarnpkg.com/keytar/-/keytar-7.6.0.tgz#498e796443cb543d31722099443f29d7b5c44100" + integrity sha512-H3cvrTzWb11+iv0NOAnoNAPgEapVZnYLVHZQyxmh7jdmVfR/c0jNNFEZ6AI38W/4DeTGTaY66ZX4Z1SbfKPvCQ== + dependencies: + node-addon-api "^3.0.0" + prebuild-install "^6.0.0" + keyv@^3.0.0: version "3.1.0" resolved "https://registry.npm.taobao.org/keyv/download/keyv-3.1.0.tgz?cache=0&sync_timestamp=1600337523153&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fkeyv%2Fdownload%2Fkeyv-3.1.0.tgz#ecc228486f69991e49e9476485a5be1e8fc5c4d9" @@ -2235,6 +2307,11 @@ mimic-response@^1.0.0, mimic-response@^1.0.1: resolved "https://registry.npm.taobao.org/mimic-response/download/mimic-response-1.0.1.tgz#4923538878eef42063cb8a3e3b0798781487ab1b" integrity sha1-SSNTiHju9CBjy4o+OweYeBSHqxs= +mimic-response@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-2.1.0.tgz#d13763d35f613d09ec37ebb30bac0469c0ee8f43" + integrity sha512-wXqjST+SLt7R009ySCglWBCFpjUygmCIfD790/kVbiGmUgfYGuB14PiTd5DwVxSV4NcYHjzMkoj5LjQZwTQLEA== + minimatch@^3.0.4, minimatch@~3.0.2: version "3.0.4" resolved "https://registry.npm.taobao.org/minimatch/download/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" @@ -2242,7 +2319,7 @@ minimatch@^3.0.4, minimatch@~3.0.2: dependencies: brace-expansion "^1.1.7" -minimist@^1.1.3, minimist@^1.2.0, minimist@^1.2.5: +minimist@^1.1.3, minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.5: version "1.2.5" resolved "https://registry.npm.taobao.org/minimist/download/minimist-1.2.5.tgz?cache=0&sync_timestamp=1606706583368&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fminimist%2Fdownload%2Fminimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602" integrity sha1-Z9ZgFLZqaoqqDAg8X9WN9OTpdgI= @@ -2270,6 +2347,11 @@ mixin-deep@^1.2.0: for-in "^1.0.2" is-extendable "^1.0.1" +mkdirp-classic@^0.5.2, mkdirp-classic@^0.5.3: + version "0.5.3" + resolved "https://registry.yarnpkg.com/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz#fa10c9115cc6d8865be221ba47ee9bed78601113" + integrity sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A== + mkdirp@^0.5.1, mkdirp@^0.5.4: version "0.5.5" resolved "https://registry.npm.taobao.org/mkdirp/download/mkdirp-0.5.5.tgz#d91cefd62d1436ca0f41620e251288d420099def" @@ -2319,6 +2401,11 @@ nanomatch@^1.2.9: snapdragon "^0.8.1" to-regex "^3.0.1" +napi-build-utils@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/napi-build-utils/-/napi-build-utils-1.0.2.tgz#b1fddc0b2c46e380a0b7a76f984dd47c41a13806" + integrity sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg== + neo-async@^2.6.2: version "2.6.2" resolved "https://registry.npm.taobao.org/neo-async/download/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f" @@ -2336,6 +2423,18 @@ ngx-toastr@^8.8.0: dependencies: tslib "^1.9.0" +node-abi@^2.21.0: + version "2.21.0" + resolved "https://registry.yarnpkg.com/node-abi/-/node-abi-2.21.0.tgz#c2dc9ebad6f4f53d6ea9b531e7b8faad81041d48" + integrity sha512-smhrivuPqEM3H5LmnY3KU6HfYv0u4QklgAxfFyRNujKUzbUcYZ+Jc2EhukB9SRcD2VpqhxM7n/MIcp1Ua1/JMg== + dependencies: + semver "^5.4.1" + +node-addon-api@^3.0.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-3.1.0.tgz#98b21931557466c6729e51cb77cd39c965f42239" + integrity sha512-flmrDNB06LIl5lywUz7YlNGZH/5p0M7W28k8hzd9Lshtdh1wshD2Y+U4h9LD6KObOy1f+fEVdgprPrEymjM5uw== + node-gyp@^7.1.0: version "7.1.2" resolved "https://registry.npm.taobao.org/node-gyp/download/node-gyp-7.1.2.tgz?cache=0&sync_timestamp=1617409989400&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fnode-gyp%2Fdownload%2Fnode-gyp-7.1.2.tgz#21a810aebb187120251c3bcec979af1587b188ae" @@ -2379,6 +2478,11 @@ node-sass@^5.0.0: stdout-stream "^1.4.0" "true-case-path" "^1.0.2" +noop-logger@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/noop-logger/-/noop-logger-0.1.1.tgz#94a2b1633c4f1317553007d8966fd0e841b6a4c2" + integrity sha1-lKKxYzxPExdVMAfYlm/Q6EG2pMI= + nopt@^5.0.0: version "5.0.0" resolved "https://registry.npm.taobao.org/nopt/download/nopt-5.0.0.tgz#530942bb58a512fccafe53fe210f13a25355dc88" @@ -2416,7 +2520,7 @@ npm-run-path@^4.0.1: dependencies: path-key "^3.0.0" -npmlog@^4.0.0, npmlog@^4.1.2: +npmlog@^4.0.0, npmlog@^4.0.1, npmlog@^4.1.2: version "4.1.2" resolved "https://registry.npm.taobao.org/npmlog/download/npmlog-4.1.2.tgz#08a7f2a8bf734604779a9efa4ad5cc717abb954b" integrity sha1-CKfyqL9zRgR3mp76StXMcXq7lUs= @@ -2685,6 +2789,26 @@ postcss@^8.2.8: nanoid "^3.1.22" source-map "^0.6.1" +prebuild-install@^6.0.0: + version "6.1.1" + resolved "https://registry.yarnpkg.com/prebuild-install/-/prebuild-install-6.1.1.tgz#6754fa6c0d55eced7f9e14408ff9e4cba6f097b4" + integrity sha512-M+cKwofFlHa5VpTWub7GLg5RLcunYIcLqtY5pKcls/u7xaAb8FrXZ520qY8rkpYy5xw90tYCyMO0MP5ggzR3Sw== + dependencies: + detect-libc "^1.0.3" + expand-template "^2.0.3" + github-from-package "0.0.0" + minimist "^1.2.3" + mkdirp-classic "^0.5.3" + napi-build-utils "^1.0.1" + node-abi "^2.21.0" + noop-logger "^0.1.1" + npmlog "^4.0.1" + pump "^3.0.0" + rc "^1.2.7" + simple-get "^3.0.3" + tar-fs "^2.0.0" + tunnel-agent "^0.6.0" + prepend-http@^2.0.0: version "2.0.0" resolved "https://registry.npm.taobao.org/prepend-http/download/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897" @@ -2861,6 +2985,16 @@ randombytes@^2.1.0: dependencies: safe-buffer "^5.1.0" +rc@^1.2.7: + version "1.2.8" + resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.8.tgz#cd924bf5200a075b83c188cd6b9e211b7fc0d3ed" + integrity sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw== + dependencies: + deep-extend "^0.6.0" + ini "~1.3.0" + minimist "^1.2.0" + strip-json-comments "~2.0.1" + read-pkg-up@^1.0.1: version "1.0.1" resolved "https://registry.npm.taobao.org/read-pkg-up/download/read-pkg-up-1.0.1.tgz#9d63c13276c065918d57f002a57f40a1b643fb02" @@ -2891,6 +3025,15 @@ readable-stream@^2.0.1, readable-stream@^2.0.6, readable-stream@^2.2.2: string_decoder "~1.1.1" util-deprecate "~1.0.1" +readable-stream@^3.1.1, readable-stream@^3.4.0: + version "3.6.0" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198" + integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA== + dependencies: + inherits "^2.0.3" + string_decoder "^1.1.1" + util-deprecate "^1.0.1" + rechoir@^0.7.0: version "0.7.0" resolved "https://registry.npm.taobao.org/rechoir/download/rechoir-0.7.0.tgz#32650fd52c21ab252aa5d65b19310441c7e03aca" @@ -3047,7 +3190,7 @@ rxjs@^6.2.1: dependencies: tslib "^1.9.0" -safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.2: +safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.2, safe-buffer@~5.2.0: version "5.2.1" resolved "https://registry.npm.taobao.org/safe-buffer/download/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" integrity sha1-Hq+fqb2x/dTsdfWPnNtOa3gn7sY= @@ -3109,7 +3252,7 @@ semver-compare@^1.0.0: resolved "https://registry.npm.taobao.org/semver-compare/download/semver-compare-1.0.0.tgz#0dee216a1c941ab37e9efb1788f6afc5ff5537fc" integrity sha1-De4hahyUGrN+nvsXiPavxf9VN/w= -"semver@2 || 3 || 4 || 5": +"semver@2 || 3 || 4 || 5", semver@^5.4.1: version "5.7.1" resolved "https://registry.npm.taobao.org/semver/download/semver-5.7.1.tgz?cache=0&sync_timestamp=1616463603361&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsemver%2Fdownload%2Fsemver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" integrity sha1-qVT5Ma66UI0we78Gnv8MAclhFvc= @@ -3179,6 +3322,20 @@ signal-exit@^3.0.0, signal-exit@^3.0.3: resolved "https://registry.npm.taobao.org/signal-exit/download/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c" integrity sha1-oUEMLt2PB3sItOJTyOrPyvBXRhw= +simple-concat@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/simple-concat/-/simple-concat-1.0.1.tgz#f46976082ba35c2263f1c8ab5edfe26c41c9552f" + integrity sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q== + +simple-get@^3.0.3: + version "3.1.0" + resolved "https://registry.yarnpkg.com/simple-get/-/simple-get-3.1.0.tgz#b45be062435e50d159540b576202ceec40b9c6b3" + integrity sha512-bCR6cP+aTdScaQCnQKbPKtJOKDp/hj9EDLJo3Nw4y1QksqaovlW/bnptB6/c1e+qmNIDHRK+oXFDdEqBT8WzUA== + dependencies: + decompress-response "^4.2.0" + once "^1.3.1" + simple-concat "^1.0.0" + snapdragon-node@^2.0.1: version "2.1.1" resolved "https://registry.npm.taobao.org/snapdragon-node/download/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b" @@ -3371,6 +3528,13 @@ string-width@^3.0.0, string-width@^3.1.0: is-fullwidth-code-point "^2.0.0" strip-ansi "^5.1.0" +string_decoder@^1.1.1: + version "1.3.0" + resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e" + integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA== + dependencies: + safe-buffer "~5.2.0" + string_decoder@~1.1.1: version "1.1.1" resolved "https://registry.npm.taobao.org/string_decoder/download/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8" @@ -3418,6 +3582,11 @@ strip-indent@^1.0.1: dependencies: get-stdin "^4.0.1" +strip-json-comments@~2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a" + integrity sha1-PFMZQukIwml8DsNEhYwobHygpgo= + style-loader@^2.0.0: version "2.0.0" resolved "https://registry.npm.taobao.org/style-loader/download/style-loader-2.0.0.tgz#9669602fd4690740eaaec137799a03addbbc393c" @@ -3462,6 +3631,27 @@ tapable@^2.1.1, tapable@^2.2.0: resolved "https://registry.npm.taobao.org/tapable/download/tapable-2.2.0.tgz?cache=0&sync_timestamp=1607088855476&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Ftapable%2Fdownload%2Ftapable-2.2.0.tgz#5c373d281d9c672848213d0e037d1c4165ab426b" integrity sha1-XDc9KB2cZyhIIT0OA30cQWWrQms= +tar-fs@^2.0.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/tar-fs/-/tar-fs-2.1.1.tgz#489a15ab85f1f0befabb370b7de4f9eb5cbe8784" + integrity sha512-V0r2Y9scmbDRLCNex/+hYzvp/zyYjvFbHPNgVTKfQvVrb6guiE/fxP+XblDNR011utopbkex2nM4dHNV6GDsng== + dependencies: + chownr "^1.1.1" + mkdirp-classic "^0.5.2" + pump "^3.0.0" + tar-stream "^2.1.4" + +tar-stream@^2.1.4: + version "2.2.0" + resolved "https://registry.yarnpkg.com/tar-stream/-/tar-stream-2.2.0.tgz#acad84c284136b060dc3faa64474aa9aebd77287" + integrity sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ== + dependencies: + bl "^4.0.3" + end-of-stream "^1.4.1" + fs-constants "^1.0.0" + inherits "^2.0.3" + readable-stream "^3.1.1" + tar@^6.0.2: version "6.1.0" resolved "https://registry.npm.taobao.org/tar/download/tar-6.1.0.tgz?cache=0&sync_timestamp=1610045450553&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Ftar%2Fdownload%2Ftar-6.1.0.tgz#d1724e9bcc04b977b18d5c573b333a2207229a83" @@ -3692,7 +3882,7 @@ use@^3.1.0: resolved "https://registry.npm.taobao.org/use/download/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f" integrity sha1-1QyMrHmhn7wg8pEfVuuXP04QBw8= -util-deprecate@^1.0.2, util-deprecate@~1.0.1: +util-deprecate@^1.0.1, util-deprecate@^1.0.2, util-deprecate@~1.0.1: version "1.0.2" resolved "https://registry.npm.taobao.org/util-deprecate/download/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8= From 225fa0800a87448ff09e6a028b1b6be8cad7044a Mon Sep 17 00:00:00 2001 From: huangxingguang <591269@gmail.com> Date: Thu, 8 Apr 2021 22:56:45 +0800 Subject: [PATCH 3/4] support for sync passwords --- src/api.ts | 64 +++++++++---- .../SettingsTab.component.pug} | 0 .../SettingsTab.component.ts} | 91 ++++++++++++++----- src/index.ts | 2 +- src/services/PasswordStorage.service.ts | 25 +++-- src/settings.ts | 3 +- 6 files changed, 129 insertions(+), 56 deletions(-) rename src/{settingsTab.component.pug => components/SettingsTab.component.pug} (100%) rename src/{settingsTab.component.ts => components/SettingsTab.component.ts} (58%) diff --git a/src/api.ts b/src/api.ts index f56bc08..796409d 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,19 +1,41 @@ import axios, { AxiosResponse } from "axios"; -function resolveGist(response: AxiosResponse): any { - if (response.data.files["config.json"] && response.data.files["config.json"].content) { - return response.data.files["config.json"].content; +function resolveGist(response: AxiosResponse): Map { + + const files = response.data.files; + + if (!files || Object.keys(files).length < 1) throw 'the config file is bad.'; + + const result = new Map(); + + Reflect.ownKeys(files).forEach(e => { + const cnt = files[e].content; + if (cnt) { + result.set(e as string, cnt); + } + }); + + return result; +} + +function toFiles(configs: Map) { + const files = {}; + for (const c of configs.keys()) { + files[c] = { + content: configs.get(c) + }; } - throw 'the config file is bad.'; + + return files; } -async function syncGitee(token: string, gist: string, config: string): Promise { +async function syncGitee(token: string, gist: string, configs: Map): Promise { const url = gist ? `https://gitee.com/api/v5/gists/${gist}` : "https://gitee.com/api/v5/gists"; + + const data = { access_token: token, - files: { - "config.json": { content: config } - }, + files: toFiles(configs), description: "sync terminus config", public: false, id: gist || '' @@ -43,14 +65,12 @@ async function syncGitee(token: string, gist: string, config: string): Promise { - +async function syncGithub(token: string, gist: string, configs: Map): Promise { const url = gist ? `https://api.github.com/gists/${gist}` : "https://api.github.com/gists"; + const data = { - files: { - "config.json": { content: config } - }, + files: toFiles(configs), description: "sync terminus config", public: false }; @@ -81,13 +101,13 @@ async function syncGithub(token: string, gist: string, config: string): Promise< }); } -export function syncGist(type: string, token: string, gist: string, config: string): Promise { +export function syncGist(type: string, token: string, gist: string, configs: Map): Promise { return new Promise(async (resolve, reject) => { try { if (type === 'Gitee') { - resolve(await syncGitee(token, gist, config)); + resolve(await syncGitee(token, gist, configs)); } else if (type === 'GitHub') { - resolve(await syncGithub(token, gist, config)); + resolve(await syncGithub(token, gist, configs)); } else { throw "unknown the type " + type; } @@ -97,7 +117,7 @@ export function syncGist(type: string, token: string, gist: string, config: stri }); } -export function getGist(type: string, token: string, gist: string): Promise { +export function getGist(type: string, token: string, gist: string): Promise> { const isGithub = type === 'GitHub'; const url = isGithub ? `https://api.github.com/gists/${gist}` : `https://gitee.com/api/v5/gists/${gist}`; @@ -130,4 +150,14 @@ export function getGist(type: string, token: string, gist: string): Promise { - // console.log(d); - // }).catch(e => { - // console.log(e); - // }) - - // keytar.setPassword(`ssh@43.128.36.153:22`, 'root', '123').then(d => { - // console.log(d); - // }).catch(e => { - // console.log(e); - // }) - this.passwordStorage.loadPassword({ - host: 'starxg.com', - port: 22, - user: 'root' - }).then(d => { - console.log(d); - }) - } private dateFormat(date: Date): any { @@ -86,18 +67,38 @@ export class SyncConfigSettingsTabComponent implements OnInit { try { if (isUploading) { - this.config.store.syncConfig.gist = await syncGist(type, token, gistId, this.config.readRaw()); + + const configs = new Map(); + // config file + configs.set('config.json', this.config.readRaw()); + // ssh password + configs.set('ssh.auth.json', JSON.stringify(await this.getSSHPluginAllPasswordInfos())) + this.config.store.syncConfig.gist = await syncGist(type, token, gistId, configs); + } else { + const result = await getGist(type, token, gistId); - this.config.writeRaw(result); + + if (result.get('config.json')) { + this.config.writeRaw(result.get('config.json')); + } + + if (result.get('ssh.auth.json')) { + await this.saveSSHPluginAllPasswordInfos(JSON.parse(result.get('ssh.auth.json')) as Connection[]); + } + + if (this.config.store.syncConfig.gist !== gistId) { this.config.store.syncConfig.gist = gistId; } } + this.toastr.info('Sync succeeded', null, { timeOut: 1500 }); + this.config.store.syncConfig.lastSyncTime = this.dateFormat(new Date); + } catch (error) { this.toastr.error(error); } finally { @@ -112,7 +113,51 @@ export class SyncConfigSettingsTabComponent implements OnInit { if (type === 'GitHub') { this.electron.shell.openExternal('https://gist.github.com/' + gist) } + } + + async saveSSHPluginAllPasswordInfos(conns: Connection[]) { + if (conns.length < 1) return; + + for (const conn of conns) { + try { + await this.passwordStorage.savePassword(conn); + } catch (error) { + console.error(conn, error); + } + } + + } + + getSSHPluginAllPasswordInfos(): Promise { + + return new Promise(async (resolve) => { + + const connections = this.config.store.ssh.connections; + if (!(connections instanceof Array) || connections.length < 1) { + resolve([]); + return; + } + + const infos = []; + for (const connect of connections) { + try { + const { host, port, user } = connect; + const pwd = await this.passwordStorage.loadPassword({ host, port, user }); + if (!pwd) continue; + infos.push({ + host, port, user, + auth: { + password: pwd + } + }); + } catch (error) { + console.error(connect, error); + } + } + + resolve(infos); + }); } } diff --git a/src/index.ts b/src/index.ts index f8a204c..77dca95 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,4 @@ import { NgModule } from '@angular/core' -import { SyncConfigSettingsTabComponent } from 'settingsTab.component'; import { SettingsTabProvider } from 'terminus-settings' import { SyncConfigSettingsTabProvider } from './settings' import { CommonModule } from '@angular/common' @@ -7,6 +6,7 @@ import { FormsModule } from '@angular/forms' import { NgbModule } from '@ng-bootstrap/ng-bootstrap' import { ConfigProvider } from 'terminus-core'; import { SyncConfigProvider } from 'config'; +import { SyncConfigSettingsTabComponent } from 'components/settingsTab.component' @NgModule({ imports: [ diff --git a/src/services/PasswordStorage.service.ts b/src/services/PasswordStorage.service.ts index 4f58860..3c7341b 100644 --- a/src/services/PasswordStorage.service.ts +++ b/src/services/PasswordStorage.service.ts @@ -1,11 +1,12 @@ import { Injectable } from '@angular/core'; +import { Connection } from 'api'; import * as keytar from 'keytar' -function getKey(host, port) { - let key = `ssh@${host}` - if (port) { - key = `ssh@${host}:${port}` +function getKey(conn: Connection) { + let key = `ssh@${conn.host}` + if (conn.port) { + key = `ssh@${conn.host}:${conn.port}` } return key; } @@ -16,18 +17,16 @@ function getKey(host, port) { @Injectable({ providedIn: 'root' }) export class PasswordStorageService { - - - async savePassword({ host, port, user, password }): Promise { - - return keytar.setPassword(getKey(host, port), user, password) + async savePassword(conn: Connection): Promise { + return keytar.setPassword(getKey(conn), conn.user, conn.auth.password) } - async deletePassword({ host, port, user }): Promise { - await keytar.deletePassword(getKey(host, port), user) + async deletePassword(conn: Connection): Promise { + await keytar.deletePassword(getKey(conn), conn.user) } - async loadPassword({ host, port, user }): Promise { - return keytar.getPassword(getKey(host, port), user) + async loadPassword(conn: Connection): Promise { + return keytar.getPassword(getKey(conn), conn.user) } + } \ No newline at end of file diff --git a/src/settings.ts b/src/settings.ts index b06c0a6..64efa00 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -1,7 +1,6 @@ import { Injectable } from '@angular/core' -import { SyncConfigSettingsTabComponent } from 'settingsTab.component' +import { SyncConfigSettingsTabComponent } from 'components/settingsTab.component' import { SettingsTabProvider } from 'terminus-settings' - @Injectable() export class SyncConfigSettingsTabProvider extends SettingsTabProvider { id = 'sync-config' From 47ca4181d4dd49412bd669da3338df590df152de Mon Sep 17 00:00:00 2001 From: huangxingguang <591269@gmail.com> Date: Thu, 8 Apr 2021 23:02:08 +0800 Subject: [PATCH 4/4] 1.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 32bcb90..7cc226c 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "terminus-sync-config", - "version": "1.0.1", + "version": "1.0.2", "description": "Sync configuration files to GitHub Gist or Gitee Gist", "keywords": [ "terminus-plugin"