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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BasicDownloadFileHTTP(downloadUrl string, proxyUrl string, proxyUser string, proxyPass string, desFile string) (downloadOk bool, resultLog []string) {
|
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
|
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() {
|
func main() {
|
||||||
|
|
||||||
|
splitTest()
|
||||||
|
|
||||||
//socksProxyUrl := "socks5://192.168.35.71:22888"
|
//socksProxyUrl := "socks5://192.168.35.71:22888"
|
||||||
httpProxyUrl := "http://192.168.35.71:22808"
|
//httpProxyUrl := "http://192.168.35.71:22808"
|
||||||
downloadOk, resultLog := BasicDownloadFileHTTP(
|
//downloadOk, resultLog := BasicDownloadFileHTTP(
|
||||||
"https://happybirthday.107421.xyz/octopus-agent/octopus-agent_linux_amd64_2024-03-29-17-47-14",
|
// "https://happybirthday.107421.xyz/octopus-agent/octopus-agent_linux_amd64_2024-03-29-17-47-14",
|
||||||
httpProxyUrl,
|
// httpProxyUrl,
|
||||||
"zeaslity",
|
// "zeaslity",
|
||||||
"password",
|
// "password",
|
||||||
"octopus-agent_linux_1232",
|
// "octopus-agent_linux_1232",
|
||||||
)
|
//)
|
||||||
if downloadOk {
|
//if downloadOk {
|
||||||
println("File downloaded successfully")
|
// println("File downloaded successfully")
|
||||||
} else {
|
//} else {
|
||||||
for _, log := range resultLog {
|
// for _, log := range resultLog {
|
||||||
println(log)
|
// println(log)
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,16 @@ type CmiiMinioOperator struct {
|
|||||||
OctopusBucketName string
|
OctopusBucketName string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var DefaultCmiiMinioOperator = newInstance()
|
||||||
|
|
||||||
|
func newInstance() *CmiiMinioOperator {
|
||||||
|
op := &CmiiMinioOperator{}
|
||||||
|
|
||||||
|
op.buildCmiiMinioOperator()
|
||||||
|
|
||||||
|
return op
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DefaultLocalEndpoint = "10.250.0.100:9000"
|
DefaultLocalEndpoint = "10.250.0.100:9000"
|
||||||
DefaultPublicEndpoint = "42.192.52.227:9000"
|
DefaultPublicEndpoint = "42.192.52.227:9000"
|
||||||
@@ -28,7 +38,7 @@ const (
|
|||||||
DefaultOctopusBucketName = "octopus"
|
DefaultOctopusBucketName = "octopus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (op CmiiMinioOperator) buildCmiiMinioOperator() {
|
func (op *CmiiMinioOperator) buildCmiiMinioOperator() {
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if op.LocalClient == nil {
|
if op.LocalClient == nil {
|
||||||
@@ -49,7 +59,7 @@ func (op CmiiMinioOperator) buildCmiiMinioOperator() {
|
|||||||
|
|
||||||
if op.DemoClient == nil {
|
if op.DemoClient == nil {
|
||||||
// 初始化Minio客户端对象。
|
// 初始化Minio客户端对象。
|
||||||
op.DemoClient, err = minio.New(DemoEndpoint, DefaultAccessKeyID, DefaultSecretAccessKey, false)
|
op.DemoClient, err = minio.New(DemoEndpoint, DefaultAccessKeyID, DefaultSecretAccessKey, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorF("[buildCmiiMinioOperator] - build for DemoClient error ! => %s", err.Error())
|
log.ErrorF("[buildCmiiMinioOperator] - build for DemoClient error ! => %s", err.Error())
|
||||||
}
|
}
|
||||||
@@ -58,46 +68,45 @@ func (op CmiiMinioOperator) buildCmiiMinioOperator() {
|
|||||||
log.DebugF("[buildCmiiMinioOperator] - build client success !")
|
log.DebugF("[buildCmiiMinioOperator] - build client success !")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (op CmiiMinioOperator) UploadToLocalOctopus(filePath, fileName string) bool {
|
func (op *CmiiMinioOperator) UploadToLocalOctopus(filePath, fileName string) bool {
|
||||||
op.buildCmiiMinioOperator()
|
|
||||||
return op.uploadToOctopus(op.LocalClient, filePath, fileName)
|
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)
|
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)
|
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)
|
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, "/") {
|
if !strings.HasSuffix(filePath, "/") {
|
||||||
filePath += "/"
|
filePath += "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
// 打开要上传的文件
|
realFileName := fileName
|
||||||
//file, err := os.Open(filePath + fileName)
|
// 解析bucket上传的真实名称
|
||||||
//if err != nil {
|
if strings.Contains(bucketName, "/") {
|
||||||
// log.ErrorF("[uploadToOss] - file %s open error! %s", filePath+fileName, err.Error())
|
splitN := strings.SplitN(bucketName, "/", 2)
|
||||||
//}
|
bucketName = splitN[0]
|
||||||
//defer file.Close()
|
if !strings.HasSuffix(splitN[1], "/") {
|
||||||
|
splitN[1] = splitN[1] + "/"
|
||||||
|
}
|
||||||
|
realFileName = splitN[1] + fileName
|
||||||
|
}
|
||||||
|
|
||||||
// 使用PutObject上传文件
|
// 使用PutObject上传文件
|
||||||
n, err := client.FPutObject(bucketName, fileName, filePath, minio.PutObjectOptions{
|
// realFileName ==> tmp/123/123.txt
|
||||||
ContentType: "application/octet-stream",
|
n, err := client.FPutObject(bucketName, realFileName, filePath+fileName, minio.PutObjectOptions{})
|
||||||
})
|
|
||||||
//n, err := client.PutObject(bucketName, fileName, file, -1, minio.PutObjectOptions{})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorF("[uploadToOss] - upload %s error %s", filePath+fileName, err.Error())
|
log.ErrorF("[uploadToOss] - upload %s error %s", filePath+fileName, err.Error())
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ package main
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestCmiiMinioOperator_UploadToDemo(t *testing.T) {
|
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