12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- package domainservice
- import (
- "Cold_Logistic/internal/pkg/common/global"
- "Cold_Logistic/internal/pkg/common/options"
- sts "github.com/tencentyun/qcloud-cos-sts-sdk/go"
- myCos "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/objectStore/cos"
- "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/errors"
- )
- // GetCosTempKey 获取临时秘钥
- func GetCosTempKey(keyPath string) (res *global.Credentials, err error) {
- storage := options.OptInstance.Storage
- cosStore, err := myCos.NewCosObjectStore(storage.CosStorageOptions)
- if err != nil {
- return res, errors.WithStackOnce(err)
- }
- credentials, err := cosStore.GetTmpCredential(keyPath)
- if err != nil {
- return res, errors.WithStackOnce(err)
- }
- res = &global.Credentials{}
- res.BaseUrl = storage.CosStorageOptions.BaseURL
- res.Bucket = storage.CosStorageOptions.Bucket
- res.Region = storage.CosStorageOptions.Region
- res.StartTime = credentials.StartTime
- res.ExpiredTime = credentials.ExpiredTime
- res.TmpSecretKey = credentials.Credentials.TmpSecretKey
- res.TmpSecretID = credentials.Credentials.TmpSecretID
- res.SessionToken = credentials.Credentials.SessionToken
- return res, nil
- }
- func GetCosTempManyKey(keyPaths []string) (res *global.Credentials, err error) {
- storage := options.OptInstance.Storage
- cosStore, err := myCos.NewCosObjectStore(storage.CosStorageOptions)
- if err != nil {
- return res, errors.WithStackOnce(err)
- }
- credentials, err := cosStore.GetManyTmpCredentialForDirKeyPath(keyPaths)
- if err != nil {
- return res, errors.WithStackOnce(err)
- }
- res = &global.Credentials{}
- res.BaseUrl = storage.CosStorageOptions.BaseURL
- res.Bucket = storage.CosStorageOptions.Bucket
- res.Region = storage.CosStorageOptions.Region
- res.StartTime = credentials.StartTime
- res.ExpiredTime = credentials.ExpiredTime
- res.TmpSecretKey = credentials.Credentials.TmpSecretKey
- res.TmpSecretID = credentials.Credentials.TmpSecretID
- res.SessionToken = credentials.Credentials.SessionToken
- return res, nil
- }
- func GetCosPathTempKey(keyPath string, durationSecond int64) (res *global.Credentials, err error) {
- storage := options.OptInstance.Storage
- cosStore, err := myCos.NewCosObjectStore(storage.CosStorageOptions)
- if err != nil {
- return res, errors.WithStackOnce(err)
- }
- credentials, err := cosStore.GetTmpCredentialForDirKeyPath(keyPath, func(credentialOptions *sts.CredentialOptions) {
- if durationSecond > 0 {
- credentialOptions.DurationSeconds = durationSecond
- }
- })
- if err != nil {
- return res, errors.WithStackOnce(err)
- }
- res = &global.Credentials{}
- res.BaseUrl = storage.CosStorageOptions.BaseURL
- res.Bucket = storage.CosStorageOptions.Bucket
- res.Region = storage.CosStorageOptions.Region
- res.StartTime = credentials.StartTime
- res.ExpiredTime = credentials.ExpiredTime
- res.TmpSecretKey = credentials.Credentials.TmpSecretKey
- res.TmpSecretID = credentials.Credentials.TmpSecretID
- res.SessionToken = credentials.Credentials.SessionToken
- return res, nil
- }
|