@@ -15,60 +15,60 @@ import (
1515 "github.com/ucloud/ucloud-sdk-go/ucloud/log"
1616)
1717
18- //ConfigFilePath path of config.json
18+ // ConfigFilePath path of config.json
1919var ConfigFilePath = fmt .Sprintf ("%s/%s" , GetConfigDir (), "config.json" )
2020
21- //CredentialFilePath path of credential.json
21+ // CredentialFilePath path of credential.json
2222var CredentialFilePath = fmt .Sprintf ("%s/%s" , GetConfigDir (), "credential.json" )
2323
2424var CredentialFilePathInCloudShell = os .Getenv ("CLOUD_SHELL_CREDENTIAL_FILE" )
2525
26- //LocalFileMode file mode of $HOME/ucloud/*
26+ // LocalFileMode file mode of $HOME/ucloud/*
2727const LocalFileMode os.FileMode = 0600
2828
29- //DefaultTimeoutSec default timeout for requesting api, 15s
29+ // DefaultTimeoutSec default timeout for requesting api, 15s
3030const DefaultTimeoutSec = 15
3131
32- //DefaultMaxRetryTimes default timeout for requesting api, 15s
32+ // DefaultMaxRetryTimes default timeout for requesting api, 15s
3333const DefaultMaxRetryTimes = 3
3434
35- //DefaultBaseURL location of api server
35+ // DefaultBaseURL location of api server
3636const DefaultBaseURL = "https://api.ucloud.cn/"
3737
38- //DefaultProfile name of default profile
38+ // DefaultProfile name of default profile
3939const DefaultProfile = "default"
4040
41- //Version 版本号
42- const Version = "0.1.41 "
41+ // Version 版本号
42+ const Version = "0.1.42 "
4343
4444var UserAgent = fmt .Sprintf ("UCloud-CLI/%s" , Version )
4545
4646var InCloudShell = os .Getenv ("CLOUD_SHELL" ) == "true"
4747
48- //ConfigIns 配置实例, 程序加载时生成
48+ // ConfigIns 配置实例, 程序加载时生成
4949var ConfigIns = & AggConfig {
5050 Profile : DefaultProfile ,
5151 BaseURL : DefaultBaseURL ,
5252 Timeout : DefaultTimeoutSec ,
5353 MaxRetryTimes : sdk .Int (DefaultMaxRetryTimes ),
5454}
5555
56- //AggConfigListIns 配置列表, 进程启动时从本地文件加载
56+ // AggConfigListIns 配置列表, 进程启动时从本地文件加载
5757var AggConfigListIns = & AggConfigManager {}
5858
59- //ClientConfig 创建sdk client参数
59+ // ClientConfig 创建sdk client参数
6060var ClientConfig * sdk.Config
6161
62- //AuthCredential 创建sdk client参数
62+ // AuthCredential 创建sdk client参数
6363var AuthCredential * CredentialConfig
6464
65- //BizClient 用于调用业务接口
65+ // BizClient 用于调用业务接口
6666var BizClient * Client
6767
68- //Global 全局flag
68+ // Global 全局flag
6969var Global GlobalFlag
7070
71- //GlobalFlag 几乎所有接口都需要的参数,例如 region zone projectID
71+ // GlobalFlag 几乎所有接口都需要的参数,例如 region zone projectID
7272type GlobalFlag struct {
7373 Debug bool
7474 JSON bool
@@ -84,7 +84,7 @@ type GlobalFlag struct {
8484 MaxRetryTimes int
8585}
8686
87- //CLIConfig cli_config element
87+ // CLIConfig cli_config element
8888type CLIConfig struct {
8989 ProjectID string `json:"project_id"`
9090 Region string `json:"region"`
@@ -97,7 +97,7 @@ type CLIConfig struct {
9797 AgreeUploadLog bool `json:"agree_upload_log"`
9898}
9999
100- //CredentialConfig credential element
100+ // CredentialConfig credential element
101101type CredentialConfig struct {
102102 PublicKey string `json:"public_key"`
103103 PrivateKey string `json:"private_key"`
@@ -106,7 +106,7 @@ type CredentialConfig struct {
106106 Profile string `json:"profile"`
107107}
108108
109- //AggConfig 聚合配置 config+credential
109+ // AggConfig 聚合配置 config+credential
110110type AggConfig struct {
111111 Profile string `json:"profile"`
112112 Active bool `json:"active"`
@@ -123,7 +123,7 @@ type AggConfig struct {
123123 AgreeUploadLog bool `json:"agree_upload_log"`
124124}
125125
126- //ConfigPublicKey 输入公钥
126+ // ConfigPublicKey 输入公钥
127127func (p * AggConfig ) ConfigPublicKey () error {
128128 Cxt .Print ("Your public-key:" )
129129 _ , err := fmt .Scanf ("%s\n " , & p .PublicKey )
@@ -136,7 +136,7 @@ func (p *AggConfig) ConfigPublicKey() error {
136136 return nil
137137}
138138
139- //ConfigPrivateKey 输入私钥
139+ // ConfigPrivateKey 输入私钥
140140func (p * AggConfig ) ConfigPrivateKey () error {
141141 Cxt .Print ("Your private-key:" )
142142 _ , err := fmt .Scanf ("%s\n " , & p .PrivateKey )
@@ -149,7 +149,7 @@ func (p *AggConfig) ConfigPrivateKey() error {
149149 return nil
150150}
151151
152- //ConfigBaseURL 输入BaseURL
152+ // ConfigBaseURL 输入BaseURL
153153func (p * AggConfig ) ConfigBaseURL () error {
154154 fmt .Printf ("Default base-url(%s):" , DefaultBaseURL )
155155 _ , err := fmt .Scanf ("%s\n " , & p .BaseURL )
@@ -163,7 +163,7 @@ func (p *AggConfig) ConfigBaseURL() error {
163163 return nil
164164}
165165
166- //ConfigUploadLog agree upload log or not
166+ // ConfigUploadLog agree upload log or not
167167func (p * AggConfig ) ConfigUploadLog () error {
168168 var input string
169169 fmt .Print ("Do you agree to upload log in local file ~/.ucloud/cli.log to help ucloud-cli get better(yes|no):" )
@@ -179,7 +179,7 @@ func (p *AggConfig) ConfigUploadLog() error {
179179 return nil
180180}
181181
182- //GetClientConfig 用来生成sdkClient
182+ // GetClientConfig 用来生成sdkClient
183183func (p * AggConfig ) GetClientConfig (isDebug bool ) * sdk.Config {
184184 clientConfig := & sdk.Config {
185185 Region : p .Region ,
@@ -195,7 +195,7 @@ func (p *AggConfig) GetClientConfig(isDebug bool) *sdk.Config {
195195 return clientConfig
196196}
197197
198- //GetCredential 用来生成SDkClient
198+ // GetCredential 用来生成SDkClient
199199func (p * AggConfig ) GetCredential () * auth.Credential {
200200 return & auth.Credential {
201201 PublicKey : p .PublicKey ,
@@ -223,15 +223,15 @@ func (p *AggConfig) copyToCredentialConfig(target *CredentialConfig) {
223223 target .CSRFToken = p .CSRFToken
224224}
225225
226- //AggConfigManager 配置管理
226+ // AggConfigManager 配置管理
227227type AggConfigManager struct {
228228 activeProfile string
229229 configs map [string ]* AggConfig
230230 configFile * os.File
231231 credFile * os.File
232232}
233233
234- //NewAggConfigManager create instance
234+ // NewAggConfigManager create instance
235235func NewAggConfigManager (cfgFile , credFile * os.File ) (* AggConfigManager , error ) {
236236 manager := & AggConfigManager {
237237 configs : make (map [string ]* AggConfig ),
@@ -260,7 +260,7 @@ func NewAggConfigManager(cfgFile, credFile *os.File) (*AggConfigManager, error)
260260 return manager , nil
261261}
262262
263- //Append config to list, override if already exist the same profile
263+ // Append config to list, override if already exist the same profile
264264func (p * AggConfigManager ) Append (config * AggConfig ) error {
265265 if _ , ok := p .configs [config .Profile ]; ok {
266266 return fmt .Errorf ("profile [%s] exists already" , config .Profile )
@@ -276,7 +276,7 @@ func (p *AggConfigManager) Append(config *AggConfig) error {
276276 return p .Save ()
277277}
278278
279- //UpdateAggConfig update AggConfig append if not exist
279+ // UpdateAggConfig update AggConfig append if not exist
280280func (p * AggConfigManager ) UpdateAggConfig (config * AggConfig ) error {
281281 if _ , ok := p .configs [config .Profile ]; ! ok {
282282 return p .Append (config )
@@ -291,7 +291,7 @@ func (p *AggConfigManager) UpdateAggConfig(config *AggConfig) error {
291291 return p .Save ()
292292}
293293
294- //Load AggConfigList from local file $HOME/.ucloud/config.json+credential.json
294+ // Load AggConfigList from local file $HOME/.ucloud/config.json+credential.json
295295func (p * AggConfigManager ) Load () error {
296296 configs , err := p .parseCLIConfigs ()
297297 if err != nil {
@@ -465,7 +465,7 @@ func parseCookie(str string) (map[string]string, error) {
465465 return tokenMap , nil
466466}
467467
468- //Save configs to local file
468+ // Save configs to local file
469469func (p * AggConfigManager ) Save () error {
470470 var clics []* CLIConfig
471471 var credcs []* CredentialConfig
@@ -493,7 +493,7 @@ func (p *AggConfigManager) Save() error {
493493 return nil
494494}
495495
496- //DeleteByProfile 从AggConfigList和本地文件中删除此配置
496+ // DeleteByProfile 从AggConfigList和本地文件中删除此配置
497497func (p * AggConfigManager ) DeleteByProfile (profile string ) error {
498498 if _ , ok := p .configs [profile ]; ! ok {
499499 return fmt .Errorf ("profile: %s is not exist" , profile )
@@ -513,7 +513,7 @@ func (p *AggConfigManager) DeleteByProfile(profile string) error {
513513 return nil
514514}
515515
516- //GetProfileNameList 获取所有profiles 用于ucloud config --profile 补全
516+ // GetProfileNameList 获取所有profiles 用于ucloud config --profile 补全
517517func (p * AggConfigManager ) GetProfileNameList () []string {
518518 profiles := []string {}
519519 for _ , item := range p .configs {
@@ -522,7 +522,7 @@ func (p *AggConfigManager) GetProfileNameList() []string {
522522 return profiles
523523}
524524
525- //GetAggConfigList get all profile config
525+ // GetAggConfigList get all profile config
526526func (p * AggConfigManager ) GetAggConfigList () []AggConfig {
527527 configs := []AggConfig {}
528528 for _ , cfg := range p .configs {
@@ -531,23 +531,23 @@ func (p *AggConfigManager) GetAggConfigList() []AggConfig {
531531 return configs
532532}
533533
534- //GetAggConfigByProfile get config of specify profile
534+ // GetAggConfigByProfile get config of specify profile
535535func (p * AggConfigManager ) GetAggConfigByProfile (profile string ) (* AggConfig , bool ) {
536536 if ac , ok := p .configs [profile ]; ok {
537537 return ac , true
538538 }
539539 return nil , false
540540}
541541
542- //GetActiveAggConfig get active agg config
542+ // GetActiveAggConfig get active agg config
543543func (p * AggConfigManager ) GetActiveAggConfig () (* AggConfig , error ) {
544544 if ac , ok := p .configs [p .activeProfile ]; ok {
545545 return ac , nil
546546 }
547547 return nil , fmt .Errorf ("active profile not found. see 'ucloud config list'" )
548548}
549549
550- //GetActiveAggConfigName get active config name
550+ // GetActiveAggConfigName get active config name
551551func (p * AggConfigManager ) GetActiveAggConfigName () string {
552552 if ac , ok := p .configs [p .activeProfile ]; ok {
553553 return ac .Profile
@@ -596,7 +596,7 @@ func (p *AggConfigManager) parseCredentials() ([]CredentialConfig, error) {
596596 return credentials , nil
597597}
598598
599- //ListAggConfig ucloud --config + ucloud config list
599+ // ListAggConfig ucloud --config + ucloud config list
600600func ListAggConfig (json bool ) {
601601 aggConfigs := AggConfigListIns .GetAggConfigList ()
602602 for idx , ac := range aggConfigs {
@@ -613,7 +613,7 @@ func ListAggConfig(json bool) {
613613 }
614614}
615615
616- //LoadUserInfo 从~/.ucloud/user.json加载用户信息
616+ // LoadUserInfo 从~/.ucloud/user.json加载用户信息
617617func LoadUserInfo () (* uaccount.UserInfo , error ) {
618618 filePath := GetConfigDir () + "/user.json"
619619 if _ , err := os .Stat (filePath ); os .IsNotExist (err ) {
@@ -631,7 +631,7 @@ func LoadUserInfo() (*uaccount.UserInfo, error) {
631631 return & user , nil
632632}
633633
634- //GetUserInfo from local file and remote api
634+ // GetUserInfo from local file and remote api
635635func GetUserInfo () (* uaccount.UserInfo , error ) {
636636 user , err := LoadUserInfo ()
637637 if err == nil {
@@ -662,7 +662,7 @@ func GetUserInfo() (*uaccount.UserInfo, error) {
662662 return user , nil
663663}
664664
665- //OldConfig 0.1.7以及之前版本的配置struct
665+ // OldConfig 0.1.7以及之前版本的配置struct
666666type OldConfig struct {
667667 PublicKey string `json:"public_key"`
668668 PrivateKey string `json:"private_key"`
@@ -671,7 +671,7 @@ type OldConfig struct {
671671 ProjectID string `json:"project_id"`
672672}
673673
674- //Load 从本地文件加载配置
674+ // Load 从本地文件加载配置
675675func (p * OldConfig ) Load () error {
676676 if _ , err := os .Stat (ConfigFilePath ); os .IsNotExist (err ) {
677677 p = new (OldConfig )
@@ -715,7 +715,7 @@ func adaptOldConfig() error {
715715 return AggConfigListIns .Append (ac )
716716}
717717
718- //GetBizClient 初始化BizClient
718+ // GetBizClient 初始化BizClient
719719func GetBizClient (ac * AggConfig ) (* Client , error ) {
720720 timeout , err := time .ParseDuration (fmt .Sprintf ("%ds" , ac .Timeout ))
721721 if err != nil {
@@ -787,7 +787,7 @@ func InitConfigInCloudShell() error {
787787 return AggConfigM .Save ()
788788}
789789
790- //InitConfig 初始化配置
790+ // InitConfig 初始化配置
791791func InitConfig () {
792792 configFile , err := os .OpenFile (ConfigFilePath , os .O_CREATE | os .O_RDONLY , LocalFileMode )
793793 if err != nil && ! os .IsNotExist (err ) {
0 commit comments