Giter Site home page Giter Site logo

aliyun-sts-go-sdk's Introduction

Replacement for https://github.com/baiyubin/aliyun-sts-go-sdk

At least until baiyubin#3 is merged.

Alibaba Cloud STS SDK for Go

GitHub Version Build Status Coverage Status Software License

关于

阿里云STS(Security Token Service) 是为阿里云账号(或RAM用户)提供短期访问权限管理的云服务。通过STS,您可以为联盟用户(您的本地账号系统所管理的用户)颁发一个自定义时效和访问权限的访问凭证。联盟用户可以使用STS短期访问凭证直接调用阿里云服务API,或登录阿里云管理控制台操作被授权访问的资源。

如果您需要快速掌握阿里云账号管理体系,请参看云栖社区

版本

  • 当前版本:1.0.0

运行环境

  • Go 1.5及以上

安装方法

  • 执行命令 go get github.com/baiyubin/aliyun-sts-go-sdk/sts

使用方法

package main

import (
	"fmt"
	"os"

	"github.com/baiyubin/aliyun-sts-go-sdk/sts"
)

func handleError(err error) {
	fmt.Println(err)
	os.Exit(-1)
}

const (
	accessKeyID     = "<AccessKeyID>"
	accessKeySecret = "<AccessKeySecret>"
	roleArn         = "<RoleArn>"
	sessionName     = "sts_demo"
)

func main() {
	stsClient := sts.NewClient(accessKeyID, accessKeySecret, roleArn, sessionName)

	resp, err := stsClient.AssumeRole(3600)
	if err != nil {
		handleError(err)
	}

	fmt.Printf("Credentials:\n")
	fmt.Printf("    AccessKeyID:%s\n", resp.Credentials.AccessKeyId)
	fmt.Printf("    AccessKeySecret:%s\n", resp.Credentials.AccessKeySecret)
	fmt.Printf("    SecurityToken:%s\n", resp.Credentials.SecurityToken)
	fmt.Printf("    Expiration:%s\n", resp.Credentials.Expiration)
}

作者

协议

aliyun-sts-go-sdk's People

Contributors

baiyubin2020 avatar sagikazarmark avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.