[ Cmii ] [ Operator ] - agent operator for DCU part
This commit is contained in:
@@ -15,6 +15,7 @@ type CmiiMinioOperator struct {
|
||||
|
||||
LocalClient *minio.Client
|
||||
PublicClient *minio.Client
|
||||
DemoClient *minio.Client
|
||||
|
||||
OctopusBucketName string
|
||||
}
|
||||
@@ -22,6 +23,7 @@ type CmiiMinioOperator struct {
|
||||
const (
|
||||
DefaultLocalEndpoint = "http://10.250.0.100:9000"
|
||||
DefaultPublicEndpoint = "http://42.192.52.227:9000"
|
||||
DemoEndpoint = "https://oss.demo.uavcmlc.com:18000"
|
||||
DefaultAccessKeyID = "cmii"
|
||||
DefaultSecretAccessKey = "B#923fC7mk"
|
||||
DefaultOctopusBucketName = "octopus"
|
||||
@@ -46,6 +48,14 @@ func (op CmiiMinioOperator) buildCmiiMinioOperator() {
|
||||
}
|
||||
}
|
||||
|
||||
if op.DemoClient == nil {
|
||||
// 初始化Minio客户端对象。
|
||||
op.PublicClient, err = minio.New(DemoEndpoint, DefaultAccessKeyID, DefaultSecretAccessKey, false)
|
||||
if err != nil {
|
||||
log.ErrorF("[buildCmiiMinioOperator] - build for DemoClient error ! => %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
log.DebugF("[buildCmiiMinioOperator] - build client success !")
|
||||
}
|
||||
|
||||
@@ -60,8 +70,19 @@ func (op CmiiMinioOperator) UploadToPublicOctopus(filePath, fileName string) boo
|
||||
return op.uploadToOctopus(op.PublicClient, filePath, fileName)
|
||||
}
|
||||
|
||||
func (op CmiiMinioOperator) UploadToDemo(bucketName, filePath, fileName string) bool {
|
||||
|
||||
op.buildCmiiMinioOperator()
|
||||
return op.uploadToOss(op.PublicClient, bucketName, filePath, fileName)
|
||||
}
|
||||
|
||||
func (op CmiiMinioOperator) uploadToOctopus(client *minio.Client, filePath, fileName string) bool {
|
||||
|
||||
return op.uploadToOss(client, DefaultOctopusBucketName, filePath, fileName)
|
||||
}
|
||||
|
||||
func (op CmiiMinioOperator) uploadToOss(client *minio.Client, bucketName, filePath, fileName string) bool {
|
||||
|
||||
if !strings.HasSuffix(filePath, "/") {
|
||||
filePath += "/"
|
||||
}
|
||||
@@ -69,17 +90,17 @@ func (op CmiiMinioOperator) uploadToOctopus(client *minio.Client, filePath, file
|
||||
// 打开要上传的文件
|
||||
file, err := os.Open(filePath + fileName)
|
||||
if err != nil {
|
||||
log.ErrorF("[uploadToOctopus] - file %s open error! %s", filePath+fileName, err.Error())
|
||||
log.ErrorF("[uploadToOss] - file %s open error! %s", filePath+fileName, err.Error())
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// 使用PutObject上传文件
|
||||
n, err := client.PutObject(DefaultOctopusBucketName, fileName, file, -1, minio.PutObjectOptions{})
|
||||
n, err := client.PutObject(bucketName, fileName, file, -1, minio.PutObjectOptions{})
|
||||
if err != nil {
|
||||
log.ErrorF("[uploadToOctopus] - upload %s error %s", filePath+fileName, err.Error())
|
||||
log.ErrorF("[uploadToOss] - upload %s error %s", filePath+fileName, err.Error())
|
||||
return false
|
||||
}
|
||||
|
||||
log.InfoF("[uploadToOctopus] - uploaded %s of size %d", filePath+fileName, n)
|
||||
log.InfoF("[uploadToOss] - uploaded %s of size %d", filePath+fileName, n)
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user