@serverless-devs/s 0.0.45 → 0.1.4-18cdd23b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -21
- package/OWNERS +33 -0
- package/_config.yml +1 -0
- package/bin/s +1 -1
- package/lib/daemon/lib.js +327 -0
- package/lib/daemon/report.js +50 -0
- package/lib/daemon/update-cli.js +20 -0
- package/lib/daemon/update-component.js +21 -0
- package/lib/daemon/update-templates.js +19 -0
- package/lib/index.js +1732 -0
- package/package.json +73 -61
- package/readme.md +127 -0
- package/.eslintrc +0 -75
- package/README.md +0 -65
- package/bin/s-config +0 -2
- package/bin/s-config-add +0 -2
- package/bin/s-config-delete +0 -2
- package/bin/s-config-get +0 -3
- package/bin/s-config-update +0 -3
- package/bin/s-deploy +0 -2
- package/bin/s-gui +0 -2
- package/bin/s-init +0 -2
- package/bin/s-platform +0 -2
- package/bin/s-platform-delete +0 -2
- package/bin/s-platform-init +0 -2
- package/bin/s-platform-login +0 -2
- package/bin/s-platform-publish +0 -2
- package/bin/s-remove +0 -2
- package/bin/s-search +0 -2
- package/bin/s-set +0 -2
- package/bin/s-set-analysis +0 -2
- package/bin/s-set-language +0 -2
- package/bin/s-set-output-color +0 -2
- package/compile.tsconfig.json +0 -12
- package/configs/base.tsconfig.json +0 -25
- package/lib/command/command-manager.d.ts +0 -12
- package/lib/command/command-manager.d.ts.map +0 -1
- package/lib/command/command-manager.js +0 -144
- package/lib/command/command-manager.js.map +0 -1
- package/lib/command/index.d.ts +0 -2
- package/lib/command/index.d.ts.map +0 -1
- package/lib/command/index.js +0 -41
- package/lib/command/index.js.map +0 -1
- package/lib/component/hook.d.ts +0 -17
- package/lib/component/hook.d.ts.map +0 -1
- package/lib/component/hook.js +0 -201
- package/lib/component/hook.js.map +0 -1
- package/lib/component/index.d.ts +0 -53
- package/lib/component/index.d.ts.map +0 -1
- package/lib/component/index.js +0 -577
- package/lib/component/index.js.map +0 -1
- package/lib/config/add/add-manager.d.ts +0 -23
- package/lib/config/add/add-manager.d.ts.map +0 -1
- package/lib/config/add/add-manager.js +0 -282
- package/lib/config/add/add-manager.js.map +0 -1
- package/lib/config/add/index.d.ts +0 -2
- package/lib/config/add/index.d.ts.map +0 -1
- package/lib/config/add/index.js +0 -77
- package/lib/config/add/index.js.map +0 -1
- package/lib/config/common/common.d.ts +0 -7
- package/lib/config/common/common.d.ts.map +0 -1
- package/lib/config/common/common.js +0 -175
- package/lib/config/common/common.js.map +0 -1
- package/lib/config/delete/delete-manager.d.ts +0 -11
- package/lib/config/delete/delete-manager.d.ts.map +0 -1
- package/lib/config/delete/delete-manager.js +0 -133
- package/lib/config/delete/delete-manager.js.map +0 -1
- package/lib/config/delete/index.d.ts +0 -2
- package/lib/config/delete/index.d.ts.map +0 -1
- package/lib/config/delete/index.js +0 -77
- package/lib/config/delete/index.js.map +0 -1
- package/lib/config/get/get-manager.d.ts +0 -14
- package/lib/config/get/get-manager.d.ts.map +0 -1
- package/lib/config/get/get-manager.js +0 -205
- package/lib/config/get/get-manager.js.map +0 -1
- package/lib/config/get/index.d.ts +0 -2
- package/lib/config/get/index.d.ts.map +0 -1
- package/lib/config/get/index.js +0 -86
- package/lib/config/get/index.js.map +0 -1
- package/lib/config/index.d.ts +0 -2
- package/lib/config/index.d.ts.map +0 -1
- package/lib/config/index.js +0 -15
- package/lib/config/index.js.map +0 -1
- package/lib/config/update/index.d.ts +0 -2
- package/lib/config/update/index.d.ts.map +0 -1
- package/lib/config/update/index.js +0 -83
- package/lib/config/update/index.js.map +0 -1
- package/lib/config/update/update-manager.d.ts +0 -23
- package/lib/config/update/update-manager.d.ts.map +0 -1
- package/lib/config/update/update-manager.js +0 -208
- package/lib/config/update/update-manager.js.map +0 -1
- package/lib/constants/static-variable.d.ts +0 -12
- package/lib/constants/static-variable.d.ts.map +0 -1
- package/lib/constants/static-variable.js +0 -15
- package/lib/constants/static-variable.js.map +0 -1
- package/lib/entity.d.ts +0 -11
- package/lib/entity.d.ts.map +0 -1
- package/lib/entity.js +0 -3
- package/lib/entity.js.map +0 -1
- package/lib/error/command-error.d.ts +0 -5
- package/lib/error/command-error.d.ts.map +0 -1
- package/lib/error/command-error.js +0 -26
- package/lib/error/command-error.js.map +0 -1
- package/lib/error/config-delete-error.d.ts +0 -5
- package/lib/error/config-delete-error.d.ts.map +0 -1
- package/lib/error/config-delete-error.js +0 -26
- package/lib/error/config-delete-error.js.map +0 -1
- package/lib/error/config-error.d.ts +0 -5
- package/lib/error/config-error.d.ts.map +0 -1
- package/lib/error/config-error.js +0 -26
- package/lib/error/config-error.js.map +0 -1
- package/lib/error/config-get-error.d.ts +0 -5
- package/lib/error/config-get-error.d.ts.map +0 -1
- package/lib/error/config-get-error.js +0 -26
- package/lib/error/config-get-error.js.map +0 -1
- package/lib/error/config-update-error.d.ts +0 -5
- package/lib/error/config-update-error.d.ts.map +0 -1
- package/lib/error/config-update-error.js +0 -26
- package/lib/error/config-update-error.js.map +0 -1
- package/lib/error/init-error.d.ts +0 -5
- package/lib/error/init-error.d.ts.map +0 -1
- package/lib/error/init-error.js +0 -26
- package/lib/error/init-error.js.map +0 -1
- package/lib/error/login-error.d.ts +0 -5
- package/lib/error/login-error.d.ts.map +0 -1
- package/lib/error/login-error.js +0 -26
- package/lib/error/login-error.js.map +0 -1
- package/lib/error/platform-delete-error.d.ts +0 -5
- package/lib/error/platform-delete-error.d.ts.map +0 -1
- package/lib/error/platform-delete-error.js +0 -26
- package/lib/error/platform-delete-error.js.map +0 -1
- package/lib/error/platform-init-error.d.ts +0 -5
- package/lib/error/platform-init-error.d.ts.map +0 -1
- package/lib/error/platform-init-error.js +0 -26
- package/lib/error/platform-init-error.js.map +0 -1
- package/lib/error/platform-publish-error.d.ts +0 -5
- package/lib/error/platform-publish-error.d.ts.map +0 -1
- package/lib/error/platform-publish-error.js +0 -26
- package/lib/error/platform-publish-error.js.map +0 -1
- package/lib/error/search-error.d.ts +0 -5
- package/lib/error/search-error.d.ts.map +0 -1
- package/lib/error/search-error.js +0 -26
- package/lib/error/search-error.js.map +0 -1
- package/lib/error/serverless-error.d.ts +0 -4
- package/lib/error/serverless-error.d.ts.map +0 -1
- package/lib/error/serverless-error.js +0 -20
- package/lib/error/serverless-error.js.map +0 -1
- package/lib/error/set-analysis-error.d.ts +0 -5
- package/lib/error/set-analysis-error.d.ts.map +0 -1
- package/lib/error/set-analysis-error.js +0 -26
- package/lib/error/set-analysis-error.js.map +0 -1
- package/lib/error/set-language-error.d.ts +0 -5
- package/lib/error/set-language-error.d.ts.map +0 -1
- package/lib/error/set-language-error.js +0 -26
- package/lib/error/set-language-error.js.map +0 -1
- package/lib/gui/gui-service.d.ts +0 -11
- package/lib/gui/gui-service.d.ts.map +0 -1
- package/lib/gui/gui-service.js +0 -276
- package/lib/gui/gui-service.js.map +0 -1
- package/lib/gui/index.d.ts +0 -2
- package/lib/gui/index.d.ts.map +0 -1
- package/lib/gui/index.js +0 -67
- package/lib/gui/index.js.map +0 -1
- package/lib/init/init-manager.d.ts +0 -9
- package/lib/init/init-manager.d.ts.map +0 -1
- package/lib/init/init-manager.js +0 -171
- package/lib/init/init-manager.js.map +0 -1
- package/lib/init/init-message.d.ts +0 -6
- package/lib/init/init-message.d.ts.map +0 -1
- package/lib/init/init-message.js +0 -9
- package/lib/init/init-message.js.map +0 -1
- package/lib/init/init.d.ts +0 -2
- package/lib/init/init.d.ts.map +0 -1
- package/lib/init/init.js +0 -87
- package/lib/init/init.js.map +0 -1
- package/lib/platform/delete/index.d.ts +0 -2
- package/lib/platform/delete/index.d.ts.map +0 -1
- package/lib/platform/delete/index.js +0 -89
- package/lib/platform/delete/index.js.map +0 -1
- package/lib/platform/delete/platform-delete-manager.d.ts +0 -4
- package/lib/platform/delete/platform-delete-manager.d.ts.map +0 -1
- package/lib/platform/delete/platform-delete-manager.js +0 -100
- package/lib/platform/delete/platform-delete-manager.js.map +0 -1
- package/lib/platform/index.d.ts +0 -2
- package/lib/platform/index.d.ts.map +0 -1
- package/lib/platform/index.js +0 -25
- package/lib/platform/index.js.map +0 -1
- package/lib/platform/init/index.d.ts +0 -2
- package/lib/platform/init/index.d.ts.map +0 -1
- package/lib/platform/init/index.js +0 -70
- package/lib/platform/init/index.js.map +0 -1
- package/lib/platform/init/platform-init-manager.d.ts +0 -4
- package/lib/platform/init/platform-init-manager.d.ts.map +0 -1
- package/lib/platform/init/platform-init-manager.js +0 -24
- package/lib/platform/init/platform-init-manager.js.map +0 -1
- package/lib/platform/login/index.d.ts +0 -2
- package/lib/platform/login/index.d.ts.map +0 -1
- package/lib/platform/login/index.js +0 -68
- package/lib/platform/login/index.js.map +0 -1
- package/lib/platform/login/login-manager.d.ts +0 -15
- package/lib/platform/login/login-manager.d.ts.map +0 -1
- package/lib/platform/login/login-manager.js +0 -176
- package/lib/platform/login/login-manager.js.map +0 -1
- package/lib/platform/publish/index.d.ts +0 -2
- package/lib/platform/publish/index.d.ts.map +0 -1
- package/lib/platform/publish/index.js +0 -93
- package/lib/platform/publish/index.js.map +0 -1
- package/lib/platform/publish/platform-publish-manager.d.ts +0 -5
- package/lib/platform/publish/platform-publish-manager.d.ts.map +0 -1
- package/lib/platform/publish/platform-publish-manager.js +0 -115
- package/lib/platform/publish/platform-publish-manager.js.map +0 -1
- package/lib/plugin/index.d.ts +0 -20
- package/lib/plugin/index.d.ts.map +0 -1
- package/lib/plugin/index.js +0 -175
- package/lib/plugin/index.js.map +0 -1
- package/lib/s.d.ts +0 -2
- package/lib/s.d.ts.map +0 -1
- package/lib/s.js +0 -134
- package/lib/s.js.map +0 -1
- package/lib/search/search.d.ts +0 -2
- package/lib/search/search.d.ts.map +0 -1
- package/lib/search/search.js +0 -233
- package/lib/search/search.js.map +0 -1
- package/lib/set/analysis/index.d.ts +0 -2
- package/lib/set/analysis/index.d.ts.map +0 -1
- package/lib/set/analysis/index.js +0 -84
- package/lib/set/analysis/index.js.map +0 -1
- package/lib/set/index.d.ts +0 -2
- package/lib/set/index.d.ts.map +0 -1
- package/lib/set/index.js +0 -16
- package/lib/set/index.js.map +0 -1
- package/lib/set/language/index.d.ts +0 -2
- package/lib/set/language/index.d.ts.map +0 -1
- package/lib/set/language/index.js +0 -73
- package/lib/set/language/index.js.map +0 -1
- package/lib/set/output-color/index.d.ts +0 -2
- package/lib/set/output-color/index.d.ts.map +0 -1
- package/lib/set/output-color/index.js +0 -87
- package/lib/set/output-color/index.js.map +0 -1
- package/lib/utils/analysis.d.ts +0 -12
- package/lib/utils/analysis.d.ts.map +0 -1
- package/lib/utils/analysis.js +0 -42
- package/lib/utils/analysis.js.map +0 -1
- package/lib/utils/check-version.d.ts +0 -13
- package/lib/utils/check-version.d.ts.map +0 -1
- package/lib/utils/check-version.js +0 -241
- package/lib/utils/check-version.js.map +0 -1
- package/lib/utils/command.d.ts +0 -14
- package/lib/utils/command.d.ts.map +0 -1
- package/lib/utils/command.js +0 -251
- package/lib/utils/command.js.map +0 -1
- package/lib/utils/common.d.ts +0 -4
- package/lib/utils/common.d.ts.map +0 -1
- package/lib/utils/common.js +0 -50
- package/lib/utils/common.js.map +0 -1
- package/lib/utils/download-manager.d.ts +0 -23
- package/lib/utils/download-manager.d.ts.map +0 -1
- package/lib/utils/download-manager.js +0 -302
- package/lib/utils/download-manager.js.map +0 -1
- package/lib/utils/handler-set-config.d.ts +0 -14
- package/lib/utils/handler-set-config.d.ts.map +0 -1
- package/lib/utils/handler-set-config.js +0 -122
- package/lib/utils/handler-set-config.js.map +0 -1
- package/lib/utils/i18n.d.ts +0 -3
- package/lib/utils/i18n.d.ts.map +0 -1
- package/lib/utils/i18n.js +0 -21
- package/lib/utils/i18n.js.map +0 -1
- package/lib/utils/locales/en.json +0 -9
- package/lib/utils/locales/zh.json +0 -203
- package/lib/utils/logger.d.ts +0 -18
- package/lib/utils/logger.d.ts.map +0 -1
- package/lib/utils/logger.js +0 -196
- package/lib/utils/logger.js.map +0 -1
- package/lib/utils/package-type.d.ts +0 -6
- package/lib/utils/package-type.d.ts.map +0 -1
- package/lib/utils/package-type.js +0 -10
- package/lib/utils/package-type.js.map +0 -1
- package/lib/utils/parse.d.ts +0 -26
- package/lib/utils/parse.d.ts.map +0 -1
- package/lib/utils/parse.js +0 -229
- package/lib/utils/parse.js.map +0 -1
- package/lib/utils/repo-template-entity.d.ts +0 -12
- package/lib/utils/repo-template-entity.d.ts.map +0 -1
- package/lib/utils/repo-template-entity.js +0 -3
- package/lib/utils/repo-template-entity.js.map +0 -1
- package/lib/utils/start-service.d.ts +0 -22
- package/lib/utils/start-service.d.ts.map +0 -1
- package/lib/utils/start-service.js +0 -97
- package/lib/utils/start-service.js.map +0 -1
- package/lib/utils/storage.d.ts +0 -3
- package/lib/utils/storage.d.ts.map +0 -1
- package/lib/utils/storage.js +0 -23
- package/lib/utils/storage.js.map +0 -1
- package/lib/utils/url-parser.d.ts +0 -8
- package/lib/utils/url-parser.d.ts.map +0 -1
- package/lib/utils/url-parser.js +0 -58
- package/lib/utils/url-parser.js.map +0 -1
- package/scripts/tests/deploy/parse.ts +0 -0
- package/scripts/tests/download-manager-test.ts +0 -135
- package/scripts/tests/init-manager-test.ts +0 -232
- package/scripts/tests/url-parser-test.ts +0 -44
- package/src/command/command-manager.ts +0 -83
- package/src/command/index.ts +0 -42
- package/src/component/hook.ts +0 -88
- package/src/component/index.ts +0 -433
- package/src/config/add/add-manager.ts +0 -207
- package/src/config/add/index.ts +0 -45
- package/src/config/common/common.ts +0 -186
- package/src/config/delete/delete-manager.ts +0 -51
- package/src/config/delete/index.ts +0 -38
- package/src/config/get/get-manager.ts +0 -148
- package/src/config/get/index.ts +0 -49
- package/src/config/index.ts +0 -13
- package/src/config/update/index.ts +0 -46
- package/src/config/update/update-manager.ts +0 -120
- package/src/constants/static-variable.ts +0 -12
- package/src/entity.ts +0 -10
- package/src/error/command-error.ts +0 -7
- package/src/error/config-delete-error.ts +0 -7
- package/src/error/config-error.ts +0 -7
- package/src/error/config-get-error.ts +0 -7
- package/src/error/config-update-error.ts +0 -7
- package/src/error/init-error.ts +0 -7
- package/src/error/login-error.ts +0 -7
- package/src/error/platform-delete-error.ts +0 -7
- package/src/error/platform-init-error.ts +0 -7
- package/src/error/platform-publish-error.ts +0 -7
- package/src/error/search-error.ts +0 -7
- package/src/error/serverless-error.ts +0 -17
- package/src/error/set-analysis-error.ts +0 -7
- package/src/error/set-language-error.ts +0 -7
- package/src/gui/gui-service.ts +0 -183
- package/src/gui/index.ts +0 -26
- package/src/init/init-manager.ts +0 -104
- package/src/init/init-message.ts +0 -8
- package/src/init/init.ts +0 -56
- package/src/platform/delete/index.ts +0 -46
- package/src/platform/delete/platform-delete-manager.ts +0 -46
- package/src/platform/index.ts +0 -26
- package/src/platform/init/index.ts +0 -33
- package/src/platform/init/platform-init-manager.ts +0 -17
- package/src/platform/login/index.ts +0 -25
- package/src/platform/login/login-manager.ts +0 -121
- package/src/platform/publish/index.ts +0 -52
- package/src/platform/publish/platform-publish-manager.ts +0 -69
- package/src/plugin/index.ts +0 -96
- package/src/s.ts +0 -83
- package/src/search/search.ts +0 -127
- package/src/set/analysis/index.ts +0 -45
- package/src/set/index.ts +0 -19
- package/src/set/language/index.ts +0 -39
- package/src/set/output-color/index.ts +0 -49
- package/src/utils/analysis.ts +0 -36
- package/src/utils/check-version.ts +0 -139
- package/src/utils/command.ts +0 -123
- package/src/utils/common.ts +0 -47
- package/src/utils/download-manager.ts +0 -197
- package/src/utils/handler-set-config.ts +0 -83
- package/src/utils/i18n.ts +0 -21
- package/src/utils/locales/en.json +0 -9
- package/src/utils/locales/zh.json +0 -228
- package/src/utils/logger.ts +0 -84
- package/src/utils/package-type.ts +0 -3
- package/src/utils/parse.ts +0 -176
- package/src/utils/repo-template-entity.ts +0 -14
- package/src/utils/start-service.ts +0 -64
- package/src/utils/storage.ts +0 -20
- package/src/utils/url-parser.ts +0 -60
- package/templates/application/common/publish.yaml +0 -16
- package/templates/application/common/readme.md +0 -99
- package/templates/application/common/src/index.js +0 -13
- package/templates/application/common/src/template.yaml +0 -16
- package/templates/component/common/publish.yaml +0 -24
- package/templates/component/common/readme.md +0 -386
- package/templates/component/common/src/index.js +0 -18
- package/templates/component/common/src/package.json +0 -7
- package/templates/plugin/common/publish.yaml +0 -9
- package/templates/plugin/common/readme.md +0 -128
- package/templates/plugin/common/src/index.js +0 -9
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import i18n from '../../utils/i18n';
|
|
2
|
-
|
|
3
|
-
export const providerArray: Array<string> = ['alibaba', 'baidu', 'huawei', 'aws', 'azure', 'google', 'tencent'];
|
|
4
|
-
|
|
5
|
-
export const providerObject: any = {
|
|
6
|
-
alibaba: i18n.__('Alibaba Cloud'),
|
|
7
|
-
baidu: i18n.__('Baidu Cloud'),
|
|
8
|
-
huawei: i18n.__('Huawei Cloud'),
|
|
9
|
-
aws: i18n.__('AWS Cloud'),
|
|
10
|
-
azure: i18n.__('Azure Cloud'),
|
|
11
|
-
google: i18n.__('Google Cloud'),
|
|
12
|
-
tencent: i18n.__('Tencent Cloud')
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const providerCollection: any = {
|
|
16
|
-
alibaba: [
|
|
17
|
-
{
|
|
18
|
-
type: 'input',
|
|
19
|
-
message: 'AccountID',
|
|
20
|
-
name: 'AccountID',
|
|
21
|
-
default: '' // 默认值
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
type: 'input',
|
|
25
|
-
message: 'AccessKeyID',
|
|
26
|
-
name: 'AccessKeyID',
|
|
27
|
-
default: '' // 默认值
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
type: 'input',
|
|
31
|
-
message: 'AccessKeySecret',
|
|
32
|
-
name: 'AccessKeySecret',
|
|
33
|
-
default: '' // 默认值
|
|
34
|
-
}
|
|
35
|
-
],
|
|
36
|
-
|
|
37
|
-
aws: [
|
|
38
|
-
{
|
|
39
|
-
type: 'input',
|
|
40
|
-
message: 'AccessKeyID',
|
|
41
|
-
name: 'AccessKeyID',
|
|
42
|
-
default: '' // 默认值
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
{
|
|
46
|
-
type: 'input',
|
|
47
|
-
message: 'SecretAccessKey',
|
|
48
|
-
name: 'SecretAccessKey',
|
|
49
|
-
default: '' // 默认值
|
|
50
|
-
}
|
|
51
|
-
],
|
|
52
|
-
|
|
53
|
-
huawei: [
|
|
54
|
-
{
|
|
55
|
-
type: 'input',
|
|
56
|
-
message: 'AccessKeyID',
|
|
57
|
-
name: 'AccessKeyID',
|
|
58
|
-
default: '' // 默认值
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
{
|
|
62
|
-
type: 'input',
|
|
63
|
-
message: 'SecretAccessKey',
|
|
64
|
-
name: 'SecretAccessKey',
|
|
65
|
-
default: '' // 默认值
|
|
66
|
-
}
|
|
67
|
-
],
|
|
68
|
-
|
|
69
|
-
azure: [
|
|
70
|
-
{
|
|
71
|
-
type: 'input',
|
|
72
|
-
message: 'KeyVault',
|
|
73
|
-
name: 'KeyVault',
|
|
74
|
-
default: '' // 默认值
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
{
|
|
78
|
-
type: 'input',
|
|
79
|
-
message: 'Secret',
|
|
80
|
-
name: 'Secret',
|
|
81
|
-
default: '' // 默认值
|
|
82
|
-
}
|
|
83
|
-
],
|
|
84
|
-
|
|
85
|
-
baidu: [
|
|
86
|
-
{
|
|
87
|
-
type: 'input',
|
|
88
|
-
message: 'AccessKeyID',
|
|
89
|
-
name: 'AccessKeyID',
|
|
90
|
-
default: '' // 默认值
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
{
|
|
94
|
-
type: 'input',
|
|
95
|
-
message: 'SecretAccessKey',
|
|
96
|
-
name: 'SecretAccessKey',
|
|
97
|
-
default: '' // 默认值
|
|
98
|
-
}
|
|
99
|
-
],
|
|
100
|
-
google: [
|
|
101
|
-
{
|
|
102
|
-
type: 'input',
|
|
103
|
-
message: 'AccountID',
|
|
104
|
-
name: 'AccountID',
|
|
105
|
-
default: '' // 默认值
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
{
|
|
109
|
-
type: 'input',
|
|
110
|
-
message: 'PrivateKeyData',
|
|
111
|
-
name: 'PrivateKeyData',
|
|
112
|
-
default: '' // 默认值
|
|
113
|
-
}
|
|
114
|
-
],
|
|
115
|
-
|
|
116
|
-
tencent: [
|
|
117
|
-
{
|
|
118
|
-
type: 'input',
|
|
119
|
-
message: 'AccountID',
|
|
120
|
-
name: 'AccountID',
|
|
121
|
-
default: '' // 默认值
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
type: 'input',
|
|
125
|
-
message: 'SecretID',
|
|
126
|
-
name: 'SecretID',
|
|
127
|
-
default: '' // 默认值
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
type: 'input',
|
|
131
|
-
message: 'SecretKey',
|
|
132
|
-
name: 'SecretKey',
|
|
133
|
-
default: '' // 默认值
|
|
134
|
-
}
|
|
135
|
-
]
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
export const providerAccessFormat: any = {
|
|
139
|
-
alibaba: ['AccountID', 'AccessKeyID', 'AccessKeySecret'],
|
|
140
|
-
aws: ['AccessKeyID', 'SecretAccessKey'],
|
|
141
|
-
baidu: ['AccessKeyID', 'SecretAccessKey'],
|
|
142
|
-
huawei: ['AccessKeyID', 'SecretAccessKey'],
|
|
143
|
-
azure: ['KeyVault', 'Secret'],
|
|
144
|
-
tencent: ['AccountID', 'SecretID', 'SecretKey'],
|
|
145
|
-
google: ['AccountID', 'PrivateKeyData']
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
export const checkProviderList: Array<any> = [
|
|
149
|
-
{
|
|
150
|
-
type: 'list',
|
|
151
|
-
name: 'provider',
|
|
152
|
-
message: i18n.__('Please select a provider:'),
|
|
153
|
-
choices: [
|
|
154
|
-
{ name: i18n.__('Alibaba Cloud (alibaba)'), value: 'alibaba' },
|
|
155
|
-
{ name: i18n.__('AWS (aws)'), value: 'aws' },
|
|
156
|
-
{ name: i18n.__('Azure (azure)'), value: 'azure' },
|
|
157
|
-
{ name: i18n.__('Baidu Cloud (baidu)'), value: 'baidu' },
|
|
158
|
-
{ name: i18n.__('Google Cloud (google)'), value: 'google' },
|
|
159
|
-
{ name: i18n.__('Huawei Cloud (huawei)'), value: 'huawei' },
|
|
160
|
-
{ name: i18n.__('Tencent Cloud (tencent)'), value: 'tencent' }
|
|
161
|
-
]
|
|
162
|
-
}
|
|
163
|
-
];
|
|
164
|
-
|
|
165
|
-
export function getInputData(program: any) {
|
|
166
|
-
const inputSecretCheck: any = {};
|
|
167
|
-
if (program.AccountID) {
|
|
168
|
-
inputSecretCheck['AccountID'] = program.AccountID;
|
|
169
|
-
}
|
|
170
|
-
if (program.AccessKeyID) {
|
|
171
|
-
inputSecretCheck['AccessKeyID'] = program.AccessKeyID;
|
|
172
|
-
}
|
|
173
|
-
if (program.AccessKeySecret) {
|
|
174
|
-
inputSecretCheck['AccessKeySecret'] = program.AccessKeySecret;
|
|
175
|
-
}
|
|
176
|
-
if (program.SecretID) {
|
|
177
|
-
inputSecretCheck['SecretID'] = program.SecretID;
|
|
178
|
-
}
|
|
179
|
-
if (program.SecretKey) {
|
|
180
|
-
inputSecretCheck['SecretKey'] = program.SecretKey;
|
|
181
|
-
}
|
|
182
|
-
if (program.SecretAccessKey) {
|
|
183
|
-
inputSecretCheck['SecretAccessKey'] = program.SecretAccessKey;
|
|
184
|
-
}
|
|
185
|
-
return inputSecretCheck;
|
|
186
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const os = require('os');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const yaml = require('js-yaml');
|
|
5
|
-
import logger from '../../utils/logger';
|
|
6
|
-
import { ConfigDeleteError } from '../../error/config-delete-error';
|
|
7
|
-
|
|
8
|
-
export class DeleteManager {
|
|
9
|
-
protected findProviderAliasFlag = true;
|
|
10
|
-
protected globalPath: string;
|
|
11
|
-
protected provider: string;
|
|
12
|
-
protected aliasName: string;
|
|
13
|
-
protected inputProviderAlias: string;
|
|
14
|
-
|
|
15
|
-
constructor() {
|
|
16
|
-
this.globalPath = path.join(os.homedir(), '.s/access.yaml');
|
|
17
|
-
}
|
|
18
|
-
async init(providerAlias: any) {
|
|
19
|
-
const userInformation: any = yaml.safeLoad(fs.readFileSync(this.globalPath, 'utf8'));
|
|
20
|
-
|
|
21
|
-
if (providerAlias['Provider'] && providerAlias['AliasName']) {
|
|
22
|
-
this.provider = String(providerAlias['Provider']).toLocaleLowerCase();
|
|
23
|
-
this.aliasName = String(providerAlias['AliasName']).toLocaleLowerCase();
|
|
24
|
-
this.inputProviderAlias = `${this.provider}.${this.aliasName || 'default'}`;
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
const userInformationKey: Array<string> = Object.keys(userInformation);
|
|
28
|
-
for (const item of userInformationKey) {
|
|
29
|
-
if (item === this.inputProviderAlias) {
|
|
30
|
-
delete userInformation[item];
|
|
31
|
-
this.findProviderAliasFlag = !this.findProviderAliasFlag;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
await this.isSuccessDle(userInformation);
|
|
35
|
-
} catch (err) {
|
|
36
|
-
throw new ConfigDeleteError('The configuration list is empty. You can add configuration through: s config add');
|
|
37
|
-
}
|
|
38
|
-
} else if (!providerAlias['Provider'] || !providerAlias['AliasName']) {
|
|
39
|
-
//没有一起输入provider 和alias
|
|
40
|
-
throw new ConfigDeleteError('Need to enter provider and aliasName at the same time. You can obtain the key information through: s config delete -h.');
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
async isSuccessDle(userInformation: any) {
|
|
44
|
-
if (!this.findProviderAliasFlag) {
|
|
45
|
-
await fs.writeFileSync(this.globalPath, yaml.dump(userInformation));
|
|
46
|
-
logger.success('Deletion succeeded');
|
|
47
|
-
} else {
|
|
48
|
-
throw new ConfigDeleteError('The key information is not found. You can obtain the key information through: s config get -l.');
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import * as program from 'commander';
|
|
2
|
-
import i18n from '../../utils/i18n';
|
|
3
|
-
import { DeleteManager } from './delete-manager';
|
|
4
|
-
import {ConfigError} from '../../error/config-error';
|
|
5
|
-
import {CommandError} from '../../error/command-error';
|
|
6
|
-
|
|
7
|
-
const description = i18n.__('s config delete help');
|
|
8
|
-
|
|
9
|
-
program
|
|
10
|
-
.name('s config delete')
|
|
11
|
-
.usage('[options] [name]')
|
|
12
|
-
.helpOption('-h,--help', i18n.__('Display help for command'))
|
|
13
|
-
.option(
|
|
14
|
-
'-p, --provider [name]',
|
|
15
|
-
i18n.__('The cloud service provider. [alibaba/aws/azure/baidu/google/huawei/tencent]')
|
|
16
|
-
)
|
|
17
|
-
.option(
|
|
18
|
-
'-a , --alias-name [name]',
|
|
19
|
-
i18n.__('Key pair alia, if the alias is not set, use default instead')
|
|
20
|
-
)
|
|
21
|
-
.description(description)
|
|
22
|
-
.parse(process.argv);
|
|
23
|
-
|
|
24
|
-
(async () => {
|
|
25
|
-
const providerAlias: Object = {
|
|
26
|
-
Provider: program.provider,
|
|
27
|
-
AliasName: program.aliasName
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
if (program.args.length === 0 && (program.provider == undefined || program.aliasName == undefined)) {
|
|
31
|
-
program.help();
|
|
32
|
-
} else if (program.args.length > 0) {
|
|
33
|
-
throw new ConfigError('Please input right format , You can obtain the key information through: s config delete -h.');
|
|
34
|
-
}
|
|
35
|
-
await (new DeleteManager()).init(providerAlias);
|
|
36
|
-
})().catch((err) => {
|
|
37
|
-
throw new CommandError(err.message);
|
|
38
|
-
});
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import {ConfigGetError} from '../../error/config-get-error';
|
|
2
|
-
const os = require('os');
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const yaml = require('js-yaml');
|
|
6
|
-
import { printn } from '../../utils/common';
|
|
7
|
-
import { providerObject } from '../common/common';
|
|
8
|
-
import logger from '../../utils/logger';
|
|
9
|
-
|
|
10
|
-
export class GetManager {
|
|
11
|
-
protected localPath: string = path.join(process.cwd(), '/access.yaml');
|
|
12
|
-
protected globalPath: string = path.join(os.homedir(), `.s/access.yaml`);
|
|
13
|
-
protected programArgsLength = 0;
|
|
14
|
-
protected resUserInformation: any = {};
|
|
15
|
-
protected providerAlias: string;
|
|
16
|
-
|
|
17
|
-
constructor() {
|
|
18
|
-
if (!fs.existsSync(path.join(process.cwd(), '/access.yaml'))) {
|
|
19
|
-
this.localPath = path.join(process.cwd(), '/access.yml');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (!fs.existsSync(this.globalPath)) {
|
|
23
|
-
fs.writeFileSync(this.globalPath, '');
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async initAccessData(userInput: any) {
|
|
28
|
-
await this.getManager(userInput, this.localPath);
|
|
29
|
-
await this.getManager(userInput, this.globalPath);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async getManager(userInput: any, filePath: string) {
|
|
33
|
-
try {
|
|
34
|
-
let userInformation: any;
|
|
35
|
-
try {
|
|
36
|
-
userInformation = yaml.safeLoad(fs.readFileSync(filePath, 'utf8'));
|
|
37
|
-
} catch (ex) {
|
|
38
|
-
if (filePath === this.globalPath) {
|
|
39
|
-
fs.writeFileSync(this.globalPath, '');
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (userInformation !== null) {
|
|
43
|
-
if (userInput['Provider']) {
|
|
44
|
-
const provider: string = String(userInput['Provider']).toLocaleLowerCase();
|
|
45
|
-
const userInformationKey: Array<string> = Object.keys(userInformation);
|
|
46
|
-
if (userInput['AliasName']) {
|
|
47
|
-
const aliasName: string = String(userInput['AliasName']).toLocaleLowerCase();
|
|
48
|
-
this.providerAlias = this.localPath === filePath ? aliasName : `${provider}.${aliasName}`;
|
|
49
|
-
userInformationKey.forEach((item) => {
|
|
50
|
-
if (item === this.providerAlias) {
|
|
51
|
-
this.resUserInformation[this.providerAlias] = userInformation[this.providerAlias];
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
} else {
|
|
55
|
-
userInformationKey.forEach((item) => {
|
|
56
|
-
if (this.localPath === filePath) {
|
|
57
|
-
this.resUserInformation[`project.${item}`] = userInformation[item];
|
|
58
|
-
} else if (item.split('.')[0] === provider) {
|
|
59
|
-
this.resUserInformation[item] = userInformation[item];
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
} else if (userInput['List']) {
|
|
64
|
-
for (const item in userInformation) {
|
|
65
|
-
if (filePath === this.localPath) {
|
|
66
|
-
this.resUserInformation[`project.${item}`] = userInformation[item];
|
|
67
|
-
} else {
|
|
68
|
-
this.resUserInformation[item] = userInformation[item];
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
} else {
|
|
73
|
-
if (this.localPath !== filePath) {
|
|
74
|
-
throw new ConfigGetError('Query failed : User configuration is empty');
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
} catch (ex) {
|
|
78
|
-
this.resUserInformation = {};
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
//返回单个provider.alias的值
|
|
83
|
-
async getUserSecretID(userInput: any) {
|
|
84
|
-
if (this.resUserInformation !== null) {
|
|
85
|
-
if (userInput['Provider'] && userInput['AliasName']) {
|
|
86
|
-
return this.resUserInformation[userInput['AliasName']] || this.resUserInformation[this.providerAlias];
|
|
87
|
-
}
|
|
88
|
-
// await this.initAccessData(userInput)
|
|
89
|
-
return this.resUserInformation;
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
throw new ConfigGetError('Query failed : Please input right format. You can obtain the key information through: s config get -h');
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
outputFormat(resUserInformation: any): void {
|
|
97
|
-
|
|
98
|
-
let sortUserKey: Array<string> = Object.keys(resUserInformation).sort(
|
|
99
|
-
(a: string, b: string) => {
|
|
100
|
-
if (a < b) {
|
|
101
|
-
return -1;
|
|
102
|
-
} else if (a > b) {
|
|
103
|
-
return 1;
|
|
104
|
-
}
|
|
105
|
-
return 0;
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
const sortUserKeyLength: number = sortUserKey.length;
|
|
111
|
-
for (let i = 0; i < sortUserKeyLength; i++) {
|
|
112
|
-
let provider: string = sortUserKey[i].split('.')[0];
|
|
113
|
-
let aliasName: string = sortUserKey[i].split('.')[1];
|
|
114
|
-
let resObject: any = resUserInformation[sortUserKey[i]];
|
|
115
|
-
|
|
116
|
-
if (i === 0 || sortUserKey[i - 1].split('.')[0] != sortUserKey[i].split('.')[0]) {
|
|
117
|
-
if (providerObject[provider]) {
|
|
118
|
-
logger.info(`${providerObject[provider]}(${provider})`);
|
|
119
|
-
} else {
|
|
120
|
-
logger.info(`${provider}`);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
logger.log(` `);
|
|
124
|
-
logger.info(` AliasName: ${aliasName}`);
|
|
125
|
-
// eslint-disable-next-line guard-for-in
|
|
126
|
-
for (let item in resObject) {
|
|
127
|
-
const valueOfKey = item;
|
|
128
|
-
let valueOfValue = resObject[item];
|
|
129
|
-
const valueOfValueLength: any = valueOfValue.length;
|
|
130
|
-
valueOfValue = valueOfValueLength > 6 ? valueOfValue.slice(0, 3) + printn(valueOfValueLength - 6, '*') + valueOfValue.slice(valueOfValueLength - 3, valueOfValueLength) : valueOfValue;
|
|
131
|
-
logger.info(` ${valueOfKey}: ${valueOfValue} `);
|
|
132
|
-
}
|
|
133
|
-
// for (let [valueOfKey, valueOfValue] of Object.entries(resObject)) {
|
|
134
|
-
// const valueOfValueLength: any = valueOfValue.length;
|
|
135
|
-
// valueOfValue = valueOfValueLength > 6 ? valueOfValue.slice(0, 3) + printn(valueOfValueLength - 6, '*') + valueOfValue.slice(valueOfValueLength - 3, valueOfValueLength) : valueOfValue;
|
|
136
|
-
// logger.info(` ${valueOfKey}: ${valueOfValue} `);
|
|
137
|
-
// }
|
|
138
|
-
logger.info(` `);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
consoleRes() {
|
|
142
|
-
if (Object.keys(this.resUserInformation).length > 0) {
|
|
143
|
-
this.outputFormat(this.resUserInformation);
|
|
144
|
-
} else {
|
|
145
|
-
throw new ConfigGetError('Query failed : The key information is not found. You can obtain the key information through: s config get -l');
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
package/src/config/get/index.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import * as program from 'commander';
|
|
2
|
-
import i18n from '../../utils/i18n';
|
|
3
|
-
import logger from '../../utils/logger';
|
|
4
|
-
import { ConfigError } from '../../error/config-error';
|
|
5
|
-
import { GetManager } from './get-manager';
|
|
6
|
-
import {CommandError} from '../../error/command-error';
|
|
7
|
-
|
|
8
|
-
const wrongInput = 'Get failed: Please input right format. You can obtain the key information through: s config get -h';
|
|
9
|
-
const description = i18n.__('s config get help');
|
|
10
|
-
|
|
11
|
-
program
|
|
12
|
-
.name('s config get')
|
|
13
|
-
.usage('[options] [name]')
|
|
14
|
-
.helpOption('-h, --help', i18n.__('Display help for command'))
|
|
15
|
-
.option(
|
|
16
|
-
'-p, --provider [name]',
|
|
17
|
-
i18n.__('The cloud service provider. [alibaba/aws/azure/baidu/google/huawei/tencent]')
|
|
18
|
-
)
|
|
19
|
-
.option(
|
|
20
|
-
'-a, --aliasName [name]',
|
|
21
|
-
i18n.__('Key pair alia, if the alias is not set, use default instead')
|
|
22
|
-
)
|
|
23
|
-
.option('-l, --list [name]', i18n.__('Show user configuration list'))
|
|
24
|
-
.description(description)
|
|
25
|
-
.parse(process.argv);
|
|
26
|
-
|
|
27
|
-
(async () => {
|
|
28
|
-
const providerAlias: Object = {
|
|
29
|
-
Provider: program.provider,
|
|
30
|
-
AliasName: program.aliasName,
|
|
31
|
-
List: program.list
|
|
32
|
-
};
|
|
33
|
-
if (
|
|
34
|
-
program.args.length === 0 &&
|
|
35
|
-
program.provider === undefined &&
|
|
36
|
-
!program.list
|
|
37
|
-
) {
|
|
38
|
-
program.help();
|
|
39
|
-
} else if (program.args.length > 0) {
|
|
40
|
-
logger.error(wrongInput);
|
|
41
|
-
throw new ConfigError('Query failed');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const getManager = new GetManager();
|
|
45
|
-
await getManager.initAccessData(providerAlias);
|
|
46
|
-
getManager.consoleRes();
|
|
47
|
-
})().catch((err) => {
|
|
48
|
-
throw new CommandError(err.message);
|
|
49
|
-
});
|
package/src/config/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import * as program from 'commander';
|
|
2
|
-
import i18n from '../utils/i18n';
|
|
3
|
-
|
|
4
|
-
program
|
|
5
|
-
.name('s config')
|
|
6
|
-
.usage('[commands] [options]')
|
|
7
|
-
.helpOption('-h, --help', i18n.__('Display help for command'))
|
|
8
|
-
.command('add', i18n.__('Add an account'))
|
|
9
|
-
.command('get', i18n.__('Get accounts'))
|
|
10
|
-
.command('delete', i18n.__('Delete an account'))
|
|
11
|
-
.command('update', i18n.__('Update an account'))
|
|
12
|
-
.description(i18n.__('You can configure provider accounts, including Alibaba Cloud, Baidu Cloud, Huawei Cloud, Tencent Cloud, etc.'))
|
|
13
|
-
.parse(process.argv);
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import * as program from 'commander';
|
|
2
|
-
import { getInputData } from '../common/common';
|
|
3
|
-
import i18n from '../../utils/i18n';
|
|
4
|
-
import { UpdateManager } from './update-manager';
|
|
5
|
-
import {ConfigUpdateError} from '../../error/config-update-error';
|
|
6
|
-
import {CommandError} from '../../error/command-error';
|
|
7
|
-
|
|
8
|
-
const wrongInput = 'Update failed: Please input right format. You can obtain the key information through: s config update -h';
|
|
9
|
-
const description = i18n.__('s config update help');
|
|
10
|
-
|
|
11
|
-
program
|
|
12
|
-
.name('s config update')
|
|
13
|
-
.usage('[options] [name]')
|
|
14
|
-
.helpOption('-h, --help', i18n.__('Display help for command'))
|
|
15
|
-
.option(
|
|
16
|
-
'-p, --provider [name]',
|
|
17
|
-
i18n.__('The cloud service provider. [alibaba/aws/azure/baidu/google/huawei/tencent]')
|
|
18
|
-
)
|
|
19
|
-
.option(
|
|
20
|
-
'-a , --alias-name [name]',
|
|
21
|
-
i18n.__('Key pair alia, if the alias is not set, use default instead')
|
|
22
|
-
)
|
|
23
|
-
.option('--AccountID [name]', i18n.__('Update AccountID'))
|
|
24
|
-
.option('--AccessKeyID [name]', i18n.__('Update AccessKeyID'))
|
|
25
|
-
.option('--AccessKeySecret [name]', i18n.__('Update AccessKeySecret'))
|
|
26
|
-
.option('--SecretID [name]', i18n.__('Update SecretID'))
|
|
27
|
-
.option('--SecretKey [name]', i18n.__('Update SecretKey'))
|
|
28
|
-
.option('--SecretAccessKey [name]', i18n.__('Update SecretAccessKey'))
|
|
29
|
-
.option('--KeyVault [name]', i18n.__('Update KeyVault'))
|
|
30
|
-
.option('--Secret [name]', i18n.__('Update Secret'))
|
|
31
|
-
.option('--PrivateKeyData [name]', i18n.__('Update PrivateKeyData'))
|
|
32
|
-
.description(description)
|
|
33
|
-
.parse(process.argv);
|
|
34
|
-
|
|
35
|
-
(async () => {
|
|
36
|
-
if (program.args.length === 0 && (program.provider == undefined || program.aliasName == undefined)) {
|
|
37
|
-
program.help();
|
|
38
|
-
} else if (program.args.length > 0) {
|
|
39
|
-
throw new ConfigUpdateError(wrongInput);
|
|
40
|
-
}
|
|
41
|
-
await (new UpdateManager()).updateManager(
|
|
42
|
-
{Provider: program.provider, AliasName: program.aliasName},
|
|
43
|
-
getInputData(program));
|
|
44
|
-
})().catch((err) => {
|
|
45
|
-
throw new CommandError(err.message);
|
|
46
|
-
});
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import {printn} from '../../utils/common';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const os = require('os');
|
|
5
|
-
const inquirer = require('inquirer');
|
|
6
|
-
const fs = require('fs');
|
|
7
|
-
const yaml = require('js-yaml');
|
|
8
|
-
import logger from '../../utils/logger';
|
|
9
|
-
import { ConfigUpdateError } from '../../error/config-update-error';
|
|
10
|
-
import { providerCollection, providerAccessFormat, providerObject } from '../common/common';
|
|
11
|
-
import i18n from '../../utils/i18n';
|
|
12
|
-
|
|
13
|
-
interface ConfigMap {[key: string]: any;}
|
|
14
|
-
|
|
15
|
-
export class UpdateManager {
|
|
16
|
-
protected filePath: string;
|
|
17
|
-
protected promptList: Array<any> = [];
|
|
18
|
-
protected inputProviderAlias: string;
|
|
19
|
-
protected oldSecretID: ConfigMap = {};
|
|
20
|
-
protected inputSecretData: ConfigMap = {};
|
|
21
|
-
protected userInformation: ConfigMap = {};
|
|
22
|
-
protected context: Array<string>;
|
|
23
|
-
protected provider: string;
|
|
24
|
-
protected aliasName: string;
|
|
25
|
-
constructor() {
|
|
26
|
-
// 获得当前用户目录
|
|
27
|
-
this.filePath = path.join(os.homedir(), '.s/access.yaml');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async updateManager(providerAlias: any, inputSecret: any) {
|
|
31
|
-
this.userInformation = yaml.safeLoad( fs.readFileSync(this.filePath, 'utf8'));
|
|
32
|
-
if (this.userInformation) {
|
|
33
|
-
if (providerAlias['Provider'] && providerAlias['AliasName']) {
|
|
34
|
-
this.provider = String(providerAlias['Provider']).toLocaleLowerCase();
|
|
35
|
-
this.aliasName = String(providerAlias['AliasName']).toLocaleLowerCase();
|
|
36
|
-
this.inputProviderAlias = `${this.provider}.${this.aliasName || 'default'}`;
|
|
37
|
-
|
|
38
|
-
// 检查系统配置是否含有inputProviderAlias
|
|
39
|
-
const hasProviderAlia: boolean = Object.keys(this.userInformation).includes(this.inputProviderAlias);
|
|
40
|
-
if (hasProviderAlia) {
|
|
41
|
-
if (Object.keys(inputSecret).length === 0) {
|
|
42
|
-
await this.inputSecretZero(providerAlias);
|
|
43
|
-
} else {
|
|
44
|
-
await this.inputSecretNotZero(inputSecret);
|
|
45
|
-
}
|
|
46
|
-
} else {
|
|
47
|
-
throw new ConfigUpdateError('The provider or alias information is not found. You can obtain the key information through: s config get -l');
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
throw new ConfigUpdateError('The configuration list is empty. You can add configuration through: s config add');
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
async inputSecretZero(providerAlias: any) {
|
|
55
|
-
try {
|
|
56
|
-
Object.keys(providerCollection).forEach((item) => {
|
|
57
|
-
if (item === this.provider) {
|
|
58
|
-
this.promptList = providerCollection[item];
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
} catch (err) {
|
|
62
|
-
throw new ConfigUpdateError(err.message);
|
|
63
|
-
}
|
|
64
|
-
const tempAccess = this.userInformation[`${providerAlias['Provider']}.${providerAlias['AliasName'] || 'default'}`];
|
|
65
|
-
for (let i = 0;i < this.promptList.length;i++) {
|
|
66
|
-
const tempName = this.promptList[i]['name'];
|
|
67
|
-
const valueOfValueLength = tempAccess[tempName].length;
|
|
68
|
-
tempAccess[tempName] = valueOfValueLength > 6 ? tempAccess[tempName].slice(0, 3) + printn(valueOfValueLength - 6, '*') + tempAccess[tempName].slice(valueOfValueLength - 3, valueOfValueLength) : tempAccess[tempName];
|
|
69
|
-
this.promptList[i]['default'] = tempAccess[tempName];
|
|
70
|
-
}
|
|
71
|
-
await inquirer.prompt(this.promptList).then((answers: any) => {
|
|
72
|
-
this.inputSecretData = answers;
|
|
73
|
-
});
|
|
74
|
-
await this.userInputCheck(this.inputSecretData);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async inputSecretNotZero(inputSecret: any) {
|
|
78
|
-
const hasProviderAlia: boolean = Object.keys(this.userInformation).includes(this.inputProviderAlias);
|
|
79
|
-
if (hasProviderAlia) {
|
|
80
|
-
await this.userInputCheck(inputSecret);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// 校验用户输入的信息, 并更新用户信息
|
|
85
|
-
async userInputCheck(inputSecret: any) {
|
|
86
|
-
let providerAccessFormatSecret: Array<string> = providerAccessFormat[this.provider];
|
|
87
|
-
this.oldSecretID = this.userInformation[this.inputProviderAlias];
|
|
88
|
-
Object.keys(inputSecret).forEach((item) => {
|
|
89
|
-
if (!providerAccessFormatSecret.includes(item)) {
|
|
90
|
-
throw new ConfigUpdateError('Please Input Right Secret Format: [{{providerAccessFormatSecret}}]', {providerAccessFormatSecret: providerAccessFormatSecret});
|
|
91
|
-
} else if (providerAccessFormatSecret.includes(item) && inputSecret[item]) {
|
|
92
|
-
this.oldSecretID[item] = inputSecret[item];
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
this.userInformation[this.inputProviderAlias] = this.oldSecretID;
|
|
97
|
-
await this.writeFileWay(this.filePath, this.userInformation);
|
|
98
|
-
this.output();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async writeFileWay(filePath: string, text: ConfigMap) {
|
|
102
|
-
try {
|
|
103
|
-
await fs.writeFileSync(filePath, yaml.dump(text));
|
|
104
|
-
} catch (err) {
|
|
105
|
-
throw new ConfigUpdateError(err.message);
|
|
106
|
-
}
|
|
107
|
-
logger.success('Update succeeded.');
|
|
108
|
-
}
|
|
109
|
-
output() {
|
|
110
|
-
logger.log('');
|
|
111
|
-
logger.info(i18n.__(' Provider: {{provider}}', { provider: `${providerObject[this.provider]}(${this.provider})`}));
|
|
112
|
-
if (this.aliasName) {
|
|
113
|
-
logger.info(i18n.__(' Alias: {{alias}}', { alias: this.aliasName }));
|
|
114
|
-
}
|
|
115
|
-
for (const item in this.oldSecretID) {
|
|
116
|
-
logger.info(` ${item}: ${this.oldSecretID[item]}`);
|
|
117
|
-
}
|
|
118
|
-
logger.log('');
|
|
119
|
-
}
|
|
120
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export const SERVERLESS_HOST = 'https://tool.serverlessfans.com';
|
|
2
|
-
export const SERVERLESS_API = 'https://tool.serverlessfans.com/api';
|
|
3
|
-
|
|
4
|
-
export const SERVERLESS_CHECK_VERSION = SERVERLESS_HOST + '/version';
|
|
5
|
-
export const SERVERLESS_GET_PACKAGE_PROVIDER = SERVERLESS_API + '/package/object/provider';
|
|
6
|
-
export const SERVERLESS_GET_APP_INFO_URL = SERVERLESS_API + '/package/get/object/url';
|
|
7
|
-
export const SERVERLESS_DELETE_PACKAGE_URL = SERVERLESS_API + '/package/object';
|
|
8
|
-
export const SERVERLESS_LOGIN_URL = SERVERLESS_API + '/user/login';
|
|
9
|
-
export const SERVERLESS_SEARCH_URL = SERVERLESS_API + '/package/object';
|
|
10
|
-
export const SERVERLESS_CHECK_COMPONENT_VERSION = SERVERLESS_API + '/package/object/version';
|
|
11
|
-
export const TEMPLATE_FILE = 'template.yaml';
|
|
12
|
-
export const PROCESS_ENV_TEMPLATE_NAME = 'templateFile';
|
package/src/entity.ts
DELETED