forked from Phuong39/cf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
439 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package huawei | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/teamssix/cf/cmd" | ||
) | ||
|
||
func init() { | ||
cmd.RootCmd.AddCommand(huaweiCmd) | ||
} | ||
|
||
var huaweiCmd = &cobra.Command{ | ||
Use: "huawei", | ||
Short: "执行与华为云相关的操作 (Perform Huawei Cloud related operations)", | ||
Long: "执行与华为云相关的操作 (Perform Huawei Cloud related operations)", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package huawei | ||
|
||
import ( | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/teamssix/cf/pkg/cloud/huawei/huaweiobs" | ||
) | ||
|
||
var ( | ||
obsLsRegion string | ||
obsLsFlushCache bool | ||
obsLsObjectNumber string | ||
) | ||
|
||
func init() { | ||
huaweiCmd.AddCommand(obsCmd) | ||
obsCmd.AddCommand(obsLsCmd) | ||
|
||
obsLsCmd.Flags().StringVarP(&obsLsObjectNumber, "number", "n", "all", "指定列出对象的数量 (Specify the number of objects to list)") | ||
obsLsCmd.Flags().StringVarP(&obsLsRegion, "region", "r", "all", "指定区域 ID (Specify region ID)") | ||
obsLsCmd.Flags().BoolVar(&obsLsFlushCache, "flushCache", false, "刷新缓存,不使用缓存数据 (Refresh the cache without using cached data)") | ||
|
||
} | ||
|
||
var obsCmd = &cobra.Command{ | ||
Use: "obs", | ||
Short: "执行与对象存储相关的操作 (Perform obs-related operations)", | ||
Long: "执行与对象存储相关的操作 (Perform obs-related operations)", | ||
} | ||
|
||
var obsLsCmd = &cobra.Command{ | ||
Use: "ls", | ||
Short: "列出所有的存储桶 (List all buckets)", | ||
Long: "列出所有的存储桶 (List all buckets)", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
log.Debugf("obsLsRegion: %s, obsLsFlushCache: %v", obsLsRegion, obsLsFlushCache) | ||
huaweiobs.PrintBucketsList(obsLsRegion, obsLsFlushCache, obsLsObjectNumber) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package huaweiobs | ||
|
||
import ( | ||
"github.com/huaweicloud/huaweicloud-sdk-go-obs/obs" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/teamssix/cf/pkg/util/cmdutil" | ||
"github.com/teamssix/cf/pkg/util/errutil" | ||
"os" | ||
) | ||
|
||
func obsClient(region string) *obs.ObsClient { | ||
var ( | ||
obsClient *obs.ObsClient | ||
err error | ||
) | ||
config := cmdutil.GetConfig("huawei") | ||
if config.AccessKeyId == "" { | ||
log.Warnln("需要先配置访问密钥 (Access Key need to be configured first)") | ||
os.Exit(0) | ||
return nil | ||
} else { | ||
if region == "all" { | ||
region = "cn-north-1" | ||
} | ||
if config.STSToken == "" { | ||
obsClient, err = obs.New(config.AccessKeyId, config.AccessKeySecret, "https://obs."+region+".myhuaweicloud.com") | ||
} else { | ||
obsClient, err = obs.New(config.AccessKeyId, config.AccessKeySecret, "https://obs."+region+".myhuaweicloud.com", obs.WithSecurityToken(config.STSToken)) | ||
} | ||
if err == nil { | ||
log.Traceln("obs Client 连接成功 (obs Client connection successful)") | ||
} else { | ||
errutil.HandleErr(err) | ||
} | ||
return obsClient | ||
} | ||
} |
Oops, something went wrong.