-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* cvm角色及ls,cp命令bug修复 * cvm角色及ls,cp命令bug修复 * cvm角色及ls,cp命令bug修复 * ls中文兼容 * url解码兼容文件夹名 * cli命令传入秘钥使用传入秘钥进行鉴权 * cli命令传入秘钥使用传入秘钥进行鉴权 * ls命令文件名换行问题处理 * v0.14.0-beta版本发布
- Loading branch information
Showing
12 changed files
with
194 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ vendor | |
|
||
coscli | ||
coscli.exe | ||
|
||
coscli.log | ||
test_clear.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package util | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
logger "github.com/sirupsen/logrus" | ||
"io/ioutil" | ||
"net/http" | ||
"os" | ||
"time" | ||
) | ||
|
||
const ( | ||
CamUrl = "http://metadata.tencentyun.com/meta-data/cam/security-credentials/" | ||
) | ||
|
||
type Data struct { | ||
TmpSecretId string `json:"TmpSecretId"` | ||
TmpSecretKey string `json:"TmpSecretKey"` | ||
ExpiredTime int `json:"ExpiredTime"` | ||
Expiration string `json:"Expiration"` | ||
Token string `json:"Token"` | ||
Code string `json:"Code"` | ||
} | ||
|
||
var data Data | ||
|
||
func CamAuth(roleName string) Data { | ||
if roleName == "" { | ||
logger.Fatalln("Get cam auth error : roleName not set") | ||
os.Exit(1) | ||
} | ||
|
||
// 创建HTTP客户端 | ||
client := &http.Client{} | ||
|
||
// 创建一个5秒的超时上下文 | ||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
defer cancel() | ||
|
||
// 创建一个HTTP GET请求并将上下文与其关联 | ||
req, err := http.NewRequest("GET", CamUrl+roleName, nil) | ||
if err != nil { | ||
logger.Fatalln("Get cam auth error : create request error", err) | ||
os.Exit(1) | ||
} | ||
req = req.WithContext(ctx) | ||
|
||
// 发起HTTP GET请求 | ||
res, err := client.Do(req) | ||
if err != nil { | ||
// 检查是否超时错误 | ||
if ctx.Err() == context.DeadlineExceeded { | ||
logger.Fatalln("Get cam auth timeout", ctx.Err()) | ||
} else { | ||
logger.Fatalln("Get cam auth error : request error", err) | ||
} | ||
os.Exit(1) | ||
} | ||
|
||
defer res.Body.Close() | ||
|
||
body, err := ioutil.ReadAll(res.Body) | ||
if err != nil { | ||
logger.Fatalln("Get cam auth error : get response error", err) | ||
os.Exit(1) | ||
} | ||
|
||
err = json.Unmarshal(body, &data) | ||
if err != nil { | ||
logger.Fatalln("Get cam auth error : auth error") | ||
os.Exit(1) | ||
} | ||
|
||
if data.Code != "Success" { | ||
logger.Fatalln("Get cam auth error : response error", err) | ||
os.Exit(1) | ||
} | ||
|
||
return data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters