|
@@ -2,12 +2,70 @@ package services
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
+ "eta/eta_api/utils"
|
|
|
"fmt"
|
|
|
"github.com/minio/minio-go/v7"
|
|
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
|
|
+ "io/ioutil"
|
|
|
"log"
|
|
|
+ "net/http"
|
|
|
+ "strings"
|
|
|
)
|
|
|
|
|
|
+func GetMinIOSTSToken() (item *Token, err error) {
|
|
|
+ // MinIO服务的访问信息
|
|
|
+ item = new(Token)
|
|
|
+ //useSSL := false
|
|
|
+ //if utils.MinIoUseSSL == "true" {
|
|
|
+ // useSSL = true
|
|
|
+ //}
|
|
|
+ // 创建MinIO客户端
|
|
|
+ //minioClient, err := minio.New(utils.MinIoEndpoint, &minio.Options{
|
|
|
+ // Creds: credentials.NewStaticV4(utils.MinIoAccessKeyId, utils.MinIoAccessKeySecret, ""),
|
|
|
+ // Secure: useSSL,
|
|
|
+ //})
|
|
|
+ //if err != nil {
|
|
|
+ // return nil, err
|
|
|
+ //}
|
|
|
+ // 设置STS凭证请求参数
|
|
|
+ //policy := `{
|
|
|
+ // "Version": "2012-10-17",
|
|
|
+ // "Statement": [
|
|
|
+ // {
|
|
|
+ // "Sid": "",
|
|
|
+ // "Effect": "Allow",
|
|
|
+ // "Principal": {"AWS": "arn:aws:iam::1234567890:root"},
|
|
|
+ // "Action": "s3:GetObject",
|
|
|
+ // "Resource": "arn:aws:s3:::<YourBucketName>/*"
|
|
|
+ // }
|
|
|
+ // ]
|
|
|
+ //}`
|
|
|
+ //expiry := time.Hour * 24 // STS凭证的过期时间
|
|
|
+ //获取STS凭证
|
|
|
+ //stsCredentials, err := minioClient.PresignedPutObject(context.Background(), "etastatic", "myobject", expiry)
|
|
|
+ //if err != nil {
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ item.AccessKeyId = utils.MinIoAccessKeyId
|
|
|
+ item.SecretKeyId = utils.MinIoAccessKeySecret
|
|
|
+ item.Endpoint = utils.MinIoEndpoint
|
|
|
+ item.ImgHost = utils.MinIoImghost
|
|
|
+ item.Bucketname = utils.MinIoBucketname
|
|
|
+ item.UseSSL = utils.MinIoUseSSL
|
|
|
+ item.RegionId = utils.MinIoRegion
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+type Token struct {
|
|
|
+ AccessKeyId string
|
|
|
+ SecretKeyId string
|
|
|
+ RegionId string
|
|
|
+ Bucketname string
|
|
|
+ Endpoint string
|
|
|
+ ImgHost string
|
|
|
+ UseSSL string
|
|
|
+}
|
|
|
+
|
|
|
func UploadMinIo() {
|
|
|
ctx := context.Background()
|
|
|
endpoint := "8.136.199.33:9000/"
|
|
@@ -40,7 +98,7 @@ func UploadMinIo() {
|
|
|
} else {
|
|
|
log.Printf("Successfully created %s\n", bucketName)
|
|
|
}
|
|
|
- buckets,err := minioClient.ListBuckets(ctx)
|
|
|
+ buckets, err := minioClient.ListBuckets(ctx)
|
|
|
for _, bucket := range buckets {
|
|
|
fmt.Println(bucket)
|
|
|
}
|
|
@@ -57,3 +115,22 @@ func UploadMinIo() {
|
|
|
|
|
|
log.Printf("Successfully uploaded %s of size %d\n", objectName, info.Size)
|
|
|
}
|
|
|
+
|
|
|
+func HttpPost(url, postData string, params ...string) ([]byte, error) {
|
|
|
+ body := ioutil.NopCloser(strings.NewReader(postData))
|
|
|
+ client := &http.Client{}
|
|
|
+ req, err := http.NewRequest("POST", url, body)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ contentType := "application/x-www-form-urlencoded;charset=utf-8"
|
|
|
+ if len(params) > 0 && params[0] != "" {
|
|
|
+ contentType = params[0]
|
|
|
+ }
|
|
|
+ req.Header.Set("Content-Type", contentType)
|
|
|
+ resp, err := client.Do(req)
|
|
|
+ defer resp.Body.Close()
|
|
|
+ b, err := ioutil.ReadAll(resp.Body)
|
|
|
+ fmt.Println("HttpPost:" + string(b))
|
|
|
+ return b, err
|
|
|
+}
|