Merge remote-tracking branch 'origin/local-ss' into local-ss
# Conflicts: # agent-operator/CmiiMinioOperator.go # agent-operator/CmiiMinioOperator_test.go
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func BasicDownloadFileHTTP(downloadUrl string, proxyUrl string, proxyUser string, proxyPass string, desFile string) (downloadOk bool, resultLog []string) {
|
||||
@@ -69,24 +71,42 @@ func BasicDownloadFileHTTP(downloadUrl string, proxyUrl string, proxyUser string
|
||||
return true, resultLog
|
||||
}
|
||||
|
||||
// quick sort function
|
||||
func splitTest() {
|
||||
|
||||
bucketName := "123"
|
||||
suffix := ""
|
||||
if strings.Contains(bucketName, "/") {
|
||||
splitN := strings.SplitN(bucketName, "/", 2)
|
||||
bucketName = splitN[0]
|
||||
if !strings.HasSuffix(splitN[1], "/") {
|
||||
splitN[1] = splitN[1] + "/"
|
||||
}
|
||||
suffix = splitN[1]
|
||||
|
||||
}
|
||||
|
||||
fmt.Println(bucketName)
|
||||
fmt.Println(suffix)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
splitTest()
|
||||
|
||||
//socksProxyUrl := "socks5://192.168.35.71:22888"
|
||||
httpProxyUrl := "http://192.168.35.71:22808"
|
||||
downloadOk, resultLog := BasicDownloadFileHTTP(
|
||||
"https://happybirthday.107421.xyz/octopus-agent/octopus-agent_linux_amd64_2024-03-29-17-47-14",
|
||||
httpProxyUrl,
|
||||
"zeaslity",
|
||||
"password",
|
||||
"octopus-agent_linux_1232",
|
||||
)
|
||||
if downloadOk {
|
||||
println("File downloaded successfully")
|
||||
} else {
|
||||
for _, log := range resultLog {
|
||||
println(log)
|
||||
}
|
||||
}
|
||||
//httpProxyUrl := "http://192.168.35.71:22808"
|
||||
//downloadOk, resultLog := BasicDownloadFileHTTP(
|
||||
// "https://happybirthday.107421.xyz/octopus-agent/octopus-agent_linux_amd64_2024-03-29-17-47-14",
|
||||
// httpProxyUrl,
|
||||
// "zeaslity",
|
||||
// "password",
|
||||
// "octopus-agent_linux_1232",
|
||||
//)
|
||||
//if downloadOk {
|
||||
// println("File downloaded successfully")
|
||||
//} else {
|
||||
// for _, log := range resultLog {
|
||||
// println(log)
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,16 @@ type CmiiMinioOperator struct {
|
||||
OctopusBucketName string
|
||||
}
|
||||
|
||||
var DefaultCmiiMinioOperator = newInstance()
|
||||
|
||||
func newInstance() *CmiiMinioOperator {
|
||||
op := &CmiiMinioOperator{}
|
||||
|
||||
op.buildCmiiMinioOperator()
|
||||
|
||||
return op
|
||||
}
|
||||
|
||||
const (
|
||||
DefaultLocalEndpoint = "10.250.0.100:9000"
|
||||
DefaultPublicEndpoint = "42.192.52.227:9000"
|
||||
@@ -28,7 +38,7 @@ const (
|
||||
DefaultOctopusBucketName = "octopus"
|
||||
)
|
||||
|
||||
func (op CmiiMinioOperator) buildCmiiMinioOperator() {
|
||||
func (op *CmiiMinioOperator) buildCmiiMinioOperator() {
|
||||
|
||||
var err error
|
||||
if op.LocalClient == nil {
|
||||
@@ -49,7 +59,7 @@ func (op CmiiMinioOperator) buildCmiiMinioOperator() {
|
||||
|
||||
if op.DemoClient == nil {
|
||||
// 初始化Minio客户端对象。
|
||||
op.DemoClient, err = minio.New(DemoEndpoint, DefaultAccessKeyID, DefaultSecretAccessKey, false)
|
||||
op.DemoClient, err = minio.New(DemoEndpoint, DefaultAccessKeyID, DefaultSecretAccessKey, true)
|
||||
if err != nil {
|
||||
log.ErrorF("[buildCmiiMinioOperator] - build for DemoClient error ! => %s", err.Error())
|
||||
}
|
||||
@@ -58,46 +68,45 @@ func (op CmiiMinioOperator) buildCmiiMinioOperator() {
|
||||
log.DebugF("[buildCmiiMinioOperator] - build client success !")
|
||||
}
|
||||
|
||||
func (op CmiiMinioOperator) UploadToLocalOctopus(filePath, fileName string) bool {
|
||||
op.buildCmiiMinioOperator()
|
||||
func (op *CmiiMinioOperator) UploadToLocalOctopus(filePath, fileName string) bool {
|
||||
return op.uploadToOctopus(op.LocalClient, filePath, fileName)
|
||||
}
|
||||
|
||||
func (op CmiiMinioOperator) UploadToPublicOctopus(filePath, fileName string) bool {
|
||||
func (op *CmiiMinioOperator) UploadToPublicOctopus(filePath, fileName string) bool {
|
||||
|
||||
op.buildCmiiMinioOperator()
|
||||
return op.uploadToOctopus(op.PublicClient, filePath, fileName)
|
||||
}
|
||||
|
||||
func (op CmiiMinioOperator) UploadToDemo(bucketName, filePath, fileName string) bool {
|
||||
func (op *CmiiMinioOperator) UploadToDemo(bucketName, filePath, fileName string) bool {
|
||||
|
||||
op.buildCmiiMinioOperator()
|
||||
return op.uploadToOss(op.DemoClient, bucketName, filePath, fileName)
|
||||
}
|
||||
|
||||
func (op CmiiMinioOperator) uploadToOctopus(client *minio.Client, filePath, fileName string) bool {
|
||||
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 {
|
||||
func (op *CmiiMinioOperator) uploadToOss(client *minio.Client, bucketName, filePath, fileName string) bool {
|
||||
|
||||
if !strings.HasSuffix(filePath, "/") {
|
||||
filePath += "/"
|
||||
}
|
||||
|
||||
// 打开要上传的文件
|
||||
//file, err := os.Open(filePath + fileName)
|
||||
//if err != nil {
|
||||
// log.ErrorF("[uploadToOss] - file %s open error! %s", filePath+fileName, err.Error())
|
||||
//}
|
||||
//defer file.Close()
|
||||
realFileName := fileName
|
||||
// 解析bucket上传的真实名称
|
||||
if strings.Contains(bucketName, "/") {
|
||||
splitN := strings.SplitN(bucketName, "/", 2)
|
||||
bucketName = splitN[0]
|
||||
if !strings.HasSuffix(splitN[1], "/") {
|
||||
splitN[1] = splitN[1] + "/"
|
||||
}
|
||||
realFileName = splitN[1] + fileName
|
||||
}
|
||||
|
||||
// 使用PutObject上传文件
|
||||
n, err := client.FPutObject(bucketName, fileName, filePath, minio.PutObjectOptions{
|
||||
ContentType: "application/octet-stream",
|
||||
})
|
||||
//n, err := client.PutObject(bucketName, fileName, file, -1, minio.PutObjectOptions{})
|
||||
// realFileName ==> tmp/123/123.txt
|
||||
n, err := client.FPutObject(bucketName, realFileName, filePath+fileName, minio.PutObjectOptions{})
|
||||
if err != nil {
|
||||
log.ErrorF("[uploadToOss] - upload %s error %s", filePath+fileName, err.Error())
|
||||
return false
|
||||
|
||||
@@ -3,8 +3,7 @@ package main
|
||||
import "testing"
|
||||
|
||||
func TestCmiiMinioOperator_UploadToDemo(t *testing.T) {
|
||||
operator := &CmiiMinioOperator{}
|
||||
|
||||
operator.UploadToDemo("cmlc-installation/tmp/", " C:\\Users\\wddsh\\Downloads", "")
|
||||
DefaultCmiiMinioOperator.UploadToDemo("cmlc-installation", "/home/wdd/Downloads/", "go1.22.1.linux-amd64.tar.gz")
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user