diff --git a/README-CN.md b/README-CN.md index 548bbd9..3c87e34 100644 --- a/README-CN.md +++ b/README-CN.md @@ -3,10 +3,10 @@ # Alibaba Cloud Credentials for Go [![Latest Stable Version](https://badge.fury.io/gh/aliyun%2Fcredentials-go.svg)](https://badge.fury.io/gh/aliyun%2Fcredentials-go) -[![Go Report Card](https://goreportcard.com/badge/github.com/aliyun/credentials-go)](https://goreportcard.com/report/github.com/aliyun/credentials-go) +[![Go](https://github.com/aliyun/credentials-go/actions/workflows/go.yml/badge.svg)](https://github.com/aliyun/credentials-go/actions/workflows/go.yml) [![codecov](https://codecov.io/gh/aliyun/credentials-go/branch/master/graph/badge.svg)](https://codecov.io/gh/aliyun/credentials-go) [![License](https://poser.pugx.org/alibabacloud/credentials/license)](https://packagist.org/packages/alibabacloud/credentials) -[![Go](https://github.com/aliyun/credentials-go/actions/workflows/go.yml/badge.svg)](https://github.com/aliyun/credentials-go/actions/workflows/go.yml) +[![Go Report Card](https://goreportcard.com/badge/github.com/aliyun/credentials-go)](https://goreportcard.com/report/github.com/aliyun/credentials-go) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/aliyun/credentials-go/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/aliyun/credentials-go/?branch=master) ![Alibaba Cloud Logo](https://aliyunsdk-pages.alicdn.com/icons/AlibabaCloud.svg) @@ -17,7 +17,7 @@ Alibaba Cloud Credentials for Go 是帮助 GO 开发者管理凭据的工具。 ## 要求 -- 请确保你的系统安装了不低于 1.10.x 版本的 Go 环境。 +- 请确保你的系统安装了 1.12.x 或更新版本的 Go 环境。 ## 安装 @@ -27,12 +27,6 @@ Alibaba Cloud Credentials for Go 是帮助 GO 开发者管理凭据的工具。 go get -u github.com/aliyun/credentials-go ``` -如果你使用 `dep` 来管理你的依赖包,你可以使用以下命令: - -```sh -dep ensure -add github.com/aliyun/credentials-go -``` - ## 快速使用 在您开始之前,您需要注册阿里云帐户并获取您的[凭证](https://usercenter.console.aliyun.com/#/manage/ak)。 @@ -59,11 +53,11 @@ func main(){ // AccessKeySecret of your account SetAccessKeySecret("AccessKeySecret") - akCredential, err := credentials.NewCredential(config) + provider, err := credentials.NewCredential(config) if err != nil { return } - credential, err := cred.GetCredential() + credential, err := provider.GetCredential() accessKeyId := credential.AccessKeyId accessSecret := credential.AccessKeySecret credentialType := credential.Type @@ -93,12 +87,12 @@ func main() { // Temporary Security Token SetSecurityToken("SecurityToken") - stsCredential, err := credentials.NewCredential(config) + provider, err := credentials.NewCredential(config) if err != nil { return } - credential, err := stsCredential.GetCredential() + credential, err := provider.GetCredential() accessKeyId := credential.AccessKeyId accessSecret := credential.AccessKeySecret securityToken := credential.SecurityToken @@ -130,12 +124,13 @@ func main() { SetPolicy("Policy"). SetRoleArn("RoleArn"). SetSessionExpiration(3600) - oidcCredential, err := credentials.NewCredential(config) + + provider, err := credentials.NewCredential(config) if err != nil { return } - credential, err := oidcCredential.GetCredential() + credential, err := provider.GetCredential() accessKeyId := credential.AccessKeyId accessSecret := credential.AccessKeySecret securityToken := credential.SecurityToken @@ -173,11 +168,11 @@ func main(){ // Not required, limit the Valid time of STS Token SetRoleSessionExpiration(3600) - arnCredential, err := credentials.NewCredential(config) + provider, err := credentials.NewCredential(config) if err != nil { return } - credential, err := arnCredential.GetCredential() + credential, err := provider.GetCredential() accessKeyId := credential.AccessKeyId accessSecret := credential.AccessKeySecret securityToken := credential.SecurityToken @@ -198,12 +193,16 @@ import ( func main(){ config := new(credentials.Config).SetType("credentials_uri").SetURL("http://127.0.0.1") - uriCredential, err := credentials.NewCredential(config) + provider, err := credentials.NewCredential(config) + if err != nil { + return + } + + credential, err := provider.GetCredential() if err != nil { return } - credential, err := uriCredential.GetCredential() accessKeyId := credential.AccessKeyId accessSecret := credential.AccessKeySecret securityToken := credential.SecurityToken @@ -233,12 +232,12 @@ func main(){ // `EnableIMDSv2` is optional and is recommended to be turned on. It can be replaced by setting environment variable: ALIBABA_CLOUD_ECS_IMDSV2_ENABLE SetEnableIMDSv2(true) - ecsCredential, err := credentials.NewCredential(config) + provider, err := credentials.NewCredential(config) if err != nil { return } - credential, err := ecsCredential.GetCredential() + credential, err := provider.GetCredential() accessKeyId := credential.AccessKeyId accessSecret := credential.AccessKeySecret securityToken := credential.SecurityToken @@ -266,12 +265,15 @@ func main(){ // BearerToken of your account SetBearerToken("BearerToken") - bearerCredential, err := credentials.NewCredential(config) + provider, err := credentials.NewCredential(config) if err != nil { return } - credential, err := bearerCredential.GetCredential() + credential, err := provider.GetCredential() + if err != nil { + return + } bearerToken := credential.BearerToken credentialType := credential.Type diff --git a/README.md b/README.md index 7f0449d..35b2f79 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,10 @@ English | [简体中文](README-CN.md) # Alibaba Cloud Credentials for Go [![Latest Stable Version](https://badge.fury.io/gh/aliyun%2Fcredentials-go.svg)](https://badge.fury.io/gh/aliyun%2Fcredentials-go) -[![Go Report Card](https://goreportcard.com/badge/github.com/aliyun/credentials-go)](https://goreportcard.com/report/github.com/aliyun/credentials-go) +[![Go](https://github.com/aliyun/credentials-go/actions/workflows/go.yml/badge.svg)](https://github.com/aliyun/credentials-go/actions/workflows/go.yml) [![codecov](https://codecov.io/gh/aliyun/credentials-go/branch/master/graph/badge.svg)](https://codecov.io/gh/aliyun/credentials-go) [![License](https://poser.pugx.org/alibabacloud/credentials/license)](https://packagist.org/packages/alibabacloud/credentials) -[![Go](https://github.com/aliyun/credentials-go/actions/workflows/go.yml/badge.svg)](https://github.com/aliyun/credentials-go/actions/workflows/go.yml) +[![Go Report Card](https://goreportcard.com/badge/github.com/aliyun/credentials-go)](https://goreportcard.com/report/github.com/aliyun/credentials-go) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/aliyun/credentials-go/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/aliyun/credentials-go/?branch=master) ![Alibaba Cloud Logo](https://aliyunsdk-pages.alicdn.com/icons/AlibabaCloud.svg) @@ -17,7 +17,7 @@ This document introduces how to obtain and use Alibaba Cloud Credentials for Go. ## Requirements -- It's necessary for you to make sure your system have installed a Go environment which is new than 1.10.x. +- It's necessary for you to make sure your system have installed a Go environment which is 1.12.x or newer. ## Installation @@ -27,12 +27,6 @@ Use `go get` to install SDK: go get -u github.com/aliyun/credentials-go ``` -If you use `dep` to manage your dependence, you can use the following command: - -```sh -dep ensure -add github.com/aliyun/credentials-go -``` - ## Quick Examples Before you begin, you need to sign up for an Alibaba Cloud account and retrieve your [Credentials](https://usercenter.console.aliyun.com/#/manage/ak). @@ -45,9 +39,9 @@ Setup access_key credential through [User Information Management][ak], it have f ```go import ( - "fmt" + "fmt" - "github.com/aliyun/credentials-go/credentials" + "github.com/aliyun/credentials-go/credentials" ) func main(){ @@ -59,11 +53,16 @@ func main(){ // AccessKeySecret of your account SetAccessKeySecret("AccessKeySecret") - akCredential, err := credentials.NewCredential(config) + provider, err := credentials.NewCredential(config) + if err != nil { + return + } + + credential, err := provider.GetCredential() if err != nil { return } - credential, err := cred.GetCredential() + accessKeyId := credential.AccessKeyId accessSecret := credential.AccessKeySecret credentialType := credential.Type @@ -93,12 +92,16 @@ func main() { // Temporary Security Token SetSecurityToken("SecurityToken") - stsCredential, err := credentials.NewCredential(config) + provider, err := credentials.NewCredential(config) + if err != nil { + return + } + + credential, err := provider.GetCredential() if err != nil { return } - credential, err := stsCredential.GetCredential() accessKeyId := credential.AccessKeyId accessSecret := credential.AccessKeySecret securityToken := credential.SecurityToken @@ -131,12 +134,16 @@ func main() { SetPolicy("Policy"). SetRoleArn("RoleArn"). SetSessionExpiration(3600) - oidcCredential, err := credentials.NewCredential(config) + provider, err := credentials.NewCredential(config) + if err != nil { + return + } + + credential, err := provider.GetCredential() if err != nil { return } - credential, err := oidcCredential.GetCredential() accessKeyId := credential.AccessKeyId accessSecret := credential.AccessKeySecret securityToken := credential.SecurityToken @@ -152,9 +159,9 @@ By specifying [RAM Role][RAM Role], the credential will be able to automatically ```go import ( - "fmt" + "fmt" - "github.com/aliyun/credentials-go/credentials" + "github.com/aliyun/credentials-go/credentials" ) func main(){ @@ -174,11 +181,15 @@ func main(){ // Not required, limit the Valid time of STS Token SetRoleSessionExpiration(3600) - arnCredential, err := credentials.NewCredential(config) + provider, err := credentials.NewCredential(config) if err != nil { return } - credential, err := arnCredential.GetCredential() + credential, err := provider.GetCredential() + if err != nil { + return + } + accessKeyId := credential.AccessKeyId accessSecret := credential.AccessKeySecret securityToken := credential.SecurityToken @@ -198,13 +209,19 @@ import ( ) func main(){ - config := new(credentials.Config).SetType("credentials_uri").SetURL("http://127.0.0.1") - uriCredential, err := credentials.NewCredential(config) + config := new(credentials.Config). + SetType("credentials_uri"). + SetURL("http://127.0.0.1") + provider, err := credentials.NewCredential(config) + if err != nil { + return + } + + credential, err := provider.GetCredential() if err != nil { return } - credential, err := uriCredential.GetCredential() accessKeyId := credential.AccessKeyId accessSecret := credential.AccessKeySecret securityToken := credential.SecurityToken @@ -226,7 +243,7 @@ import ( ) func main(){ - config := new(credentials.Config). + config := new(credentials.Config). // Which type of credential you want SetType("ecs_ram_role"). // `roleName` is optional. It will be retrieved automatically if not set. It is highly recommended to set it up to reduce requests @@ -234,12 +251,12 @@ func main(){ // `EnableIMDSv2` is optional and is recommended to be turned on. It can be replaced by setting environment variable: ALIBABA_CLOUD_ECS_IMDSV2_ENABLE SetEnableIMDSv2(true) - ecsCredential, err := credentials.NewCredential(config) + provider, err := credentials.NewCredential(config) if err != nil { return } - credential, err := ecsCredential.GetCredential() + credential, err := provider.GetCredential() accessKeyId := credential.AccessKeyId accessSecret := credential.AccessKeySecret securityToken := credential.SecurityToken @@ -267,12 +284,12 @@ func main(){ // BearerToken of your account SetBearerToken("BearerToken") - bearerCredential, err := credentials.NewCredential(config) + provider, err := credentials.NewCredential(config) if err != nil { return } - credential, err := bearerCredential.GetCredential() + credential, err := provider.GetCredential() bearerToken := credential.BearerToken credentialType := credential.Type