Giter Site home page Giter Site logo

denverdino / aliyungo Goto Github PK

View Code? Open in Web Editor NEW
842.0 842.0 246.0 6.04 MB

Go SDK for Aliyun (Alibaba Cloud) - Golang API for ECS, OSS, DNS, SLB, RDS, RAM, MNS, STS, SLS, MQ, Push, OpenSearch, DM, Container Service etc.

License: Apache License 2.0

Go 100.00%
alibaba aliyun dns ecs go oss rds sdk slb

aliyungo's Introduction

AliyunGo: Go SDK for Aliyun Services

Build Status CircleCI Go Report Card

This is an unofficial Go SDK for Aliyun services. You are welcome for contribution.

The official SDK for Aliyun services is published. Please visit https://github.com/aliyun/alibaba-cloud-sdk-go for details

Package Structure

Quick Start

package main

import (
  "fmt"

	"github.com/denverdino/aliyungo/ecs"
)

const ACCESS_KEY_ID = "<YOUR_ID>"
const ACCESS_KEY_SECRET = "<****>"

func main() {
	client := ecs.NewClient(ACCESS_KEY_ID, ACCESS_KEY_SECRET)
	fmt.Print(client.DescribeRegions())
}

Documentation

Build and Install

go get:

go get github.com/denverdino/aliyungo

Test ECS

Modify "ecs/config_test.go"

	TestAccessKeyId     = "MY_ACCESS_KEY_ID"
	TestAccessKeySecret = "MY_ACCESS_KEY_ID"
	TestInstanceId      = "MY_INSTANCE_ID"
	TestIAmRich         = false
  • TestAccessKeyId: the Access Key Id
  • TestAccessKeySecret: the Access Key Secret.
  • TestInstanceId: the existing instance id for testing. It will be stopped and restarted during testing.
  • TestIAmRich(Optional): If it is set to true, it will perform tests to create virtual machines and disks under your account. And you will pay the bill. :-)

Under "ecs" and run

go test

Test OSS

Modify "oss/config_test.go"

	TestAccessKeyId     = "MY_ACCESS_KEY_ID"
	TestAccessKeySecret = "MY_ACCESS_KEY_ID"
	TestRegion          = oss.Beijing
	TestBucket          = "denverdino"
  • TestAccessKeyId: the Access Key Id
  • TestAccessKeySecret: the Access Key Secret.
  • TestRegion: the region of OSS for testing
  • TestBucket: the bucket name for testing

Under "oss" and run

go test

Contributors

License

This project is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.

Related projects

References

The GO API design of OSS refer the implementation from https://github.com/AdRoll/goamz

aliyungo's People

Contributors

anserhyb avatar aoxn avatar bittopaz avatar bswang avatar chainone avatar crazykev avatar demonwy avatar denverdino avatar dinos80152 avatar fredliang44 avatar gujingit avatar hb-chen avatar johnzeng avatar jzwlqx avatar mars1024 avatar menglingwei avatar mozillazg avatar pangjiping avatar pragkent avatar ringtail avatar saberrey avatar shawnpku avatar shuwei-yin avatar tg123 avatar xh4n3 avatar xiaozhu36 avatar xujinzheng avatar yarous224 avatar yufeizyf avatar zhuzhih2017 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aliyungo's Issues

Can't kill & rm machine when create fail usingi aliyunecs driver

I'm trying to use docker-machine(0.5.0rc4) with aliyunecs driver and there are some issues.
First, I started to create swarm-ecs-master but there's TLS handshake timeout error:

$ docker-machine create --driver aliyunecs --swarm --swarm-master --swarm-discovery token://42391e615c9ee3ea568c92dddf9ee7a5 --engine-insecure-registry registry.mirrors.aliyuncs.com swarm-ecs-master 
Creating CA: /Users/jie/.docker/machine/certs/ca.pem
Creating client certificate: /Users/jie/.docker/machine/certs/cert.pem
Running pre-create checks...
Creating machine...
Error creating machine: Error in driver during machine creation: Aliyun Error: Status Code -1: Code AliyunGoClientFailure: Message Get https://ecs.aliyuncs.com?xxxxxxxx(Some security info has been removed): net/http: TLS handshake timeout

Recreate is not allowed:

$ docker-machine create --driver aliyunecs --swarm --swarm-master --swarm-discovery token://42391e615c9ee3ea568c92dddf9ee7a5 --engine-insecure-registry registry.mirrors.aliyuncs.com swarm-ecs-master 
Host already exists: "swarm-ecs-master"

Then, I tried to kill it but it still got error like below:

$ docker-machine kill swarm-ecs-master
swarm-ecs-master | Unable to kill instance : Aliyun Error: Status Code 400: Code MissingParameter: Message The input parameter "InstanceId" that is mandatory for processing this request is not supplied.

Run docker-machine ls just like this:

$ docker-machine ls
error getting URL for host swarm-ecs-master: Aliyun Error: Status Code 400: Code MissingParameter: Message The input parameter "InstanceId" that is mandatory for processing this request is not supplied.
error getting state for host swarm-ecs-master: Aliyun Error: Status Code 400: Code MissingParameter: Message The input parameter "InstanceId" that is mandatory for processing this request is not supplied.
NAME               ACTIVE   DRIVER      STATE   URL   SWARM
swarm-ecs-master   -        aliyunecs   Error         swarm-ecs-master (master)

SLB添加Linstener错误

AliyunSLB DeleteSLB ERROR:
Aliyun API Error: RequestId: XXXXXXXX Status Code: 400 Code:
MissingParameter Message: The input parameter "StickySession" that is mandatory for processing this request is not supplied.

When I set the endpoint as 'bucket.oss-cn-hangzhou-internal.aliyuncs.com', the docker registry fail to start.

I use the OSS as the docker registry backend. The registry container run on the ECS, I want to connect to OSS with internal endpoint. I get the internal endpoint url from ali guide.

storage:
    oss:
        accesskeyid: xxxxxxx
        accesskeysecret: yyyyyyyy
        region: oss-cn-hangzhou
        endpoint: bucket1.oss-cn-hangzhou-internal.aliyuncs.com
        internal: true
        bucket: bucket1

When I start the registry, it error out.

2016/01/23 06:42:41 GET https://bucket1.oss-cn-hangzhou-internal.aliyuncs.com/?delimiter=&marker=&max-keys=1&prefix=test ...
panic: Get https://bucket1.oss-cn-hangzhou-internal.aliyuncs.com/?delimiter=&marker=&max-keys=1&prefix=test: x509: certificate is valid for *.oss-internal.aliyuncs.com, not registry1.oss-cn-hangzhou-internal.aliyuncs.com

不适用于2017年6月22日以后的短信接口

调用错误:
Aliyun API Error: RequestId: 5D792366-E7EA-4615-A9F7-85E0FC148EE5 Status Code: 404 Code: InvalidDayuStatus.Malformed Message: The specified dayu status is wrongly formed.
希望大神能尽快补丁

Could endpoint be passed by an argument?

// NewClient creates a new instance of ECS client
func NewClient(accessKeyId, accessKeySecret string) *Client {
	endpoint := os.Getenv("ECS_ENDPOINT")
	if endpoint == "" {
		endpoint = ECSDefaultEndpoint
	}
	return NewClientWithEndpoint(endpoint, accessKeyId, accessKeySecret)
}

Although we can set endpoint by an Environment variable, It is not convenient.

How about Variadic Functions for NewClient?

func NewClient(accessKeyId, accessKeySecret, args ...string) *Client {
	endpoint := ""
	if len(args) > 0 {
		endpoint = args[0]
	} else {
		endpoint = os.Getenv("ECS_ENDPOINT")
		if endpoint == "" {
			endpoint = ECSDefaultEndpoint
		}
	}
	return NewClientWithEndpoint(endpoint, accessKeyId, accessKeySecret)
}

ecs.LockReason unmarshal error

can not unmarshal LockReason result to ecs.LockReason struct (type string).

example response:

OperationLocks":{"LockReason":[{"LockReason":"financial"}]}

code and test cases should support go 1.2 1.3 and 1.4

$ go test
2015/06/06 22:58:33 StructArray.1. : {a 1}
2015/06/06 22:58:33 StructArray.2. : {x 2}
--- FAIL: TestISO8601Time (0.00 seconds)
    iso6801_test.go:29: Time 2015-06-06T14:58:33Z does not equal expected 2015-06-06T14:58:33Z
FAIL
exit status 1
$ go version
go version go1.3.3 linux/amd64

Two questions

Does this SDK support "append" object?

I see PutReader has parameter type "io.Reader", instead of "io.ReaderSeeker". Does it mean this method can upload data as a stream (no need wait for EOF of the data)?

ECS API: More user friendly API design

  1. Current API design is just mapping of the REST API. It will be better to provide the resource based API. E.g. instance resource, disk resource we can associate the disk resource to instance
  2. The WaitForXXX method can be simplified.
    E.g.
    func (client *Client) WaitForInstance(instanceId string, status InstanceStatus, timeout int) error
    Should be changed to something like
    func (client *Client) WaitForInstance(instanceId string, timeout int) (status InstanceStatus, err error)

The status will be the stable status E.g. Running, Stopped, etc. We need the enumeration of them.

Thanks

type RecordType 中 TTL 类型错误

源码中,代码:
type RecordType struct {
DomainName string
RecordId string
RR string
Type string
Value string
TTL int32
Priority int32
Line string
Status string
Locked bool
}

实际返回结果中,TTL为string类型,实际请求结果如下:
"DomainRecords": {
"Record": [
{
"RR": "test",
"Status": "ENABLE",
"Value": "1.1.1.1",
"RecordId": "342037109689856011",
"Type": "A",
"DomainName": "example.com",
"Locked": false,
"Line": "default",
"TTL": "600"
}
]
}

Add support for new regions; Japan, Germany, Dubai & Australia

HI,
Aliyun just released support for new regions: Japan, Germany, Dubai & Australia. Can these be added to the library.

On a side note, I tried to find the region ids for Aliyun. I could not find it from there api docs. Do you mind showing how to figure this out?

Thanks.

Aliyun registry version out of date

It prompted the below message after running 'docker pull mysql' successfully. In fact it behaves the same whatever I am pulling.

"docker.io/library/mysql: this image was pulled from a legacy registry. Important: This registry version will not be supported in future versions of docker."

I checked the configuration and found docker daemon is using registry.mirrors.aliyuncs.com as default registry. Is this registry maintained officially by Aliyun?

关于MNS

目前我需要用到MNS服务 可否有提供MNS相关的demo

SLB: can NOT get RuleId when DescribeRules

@denverdino

根据文档:https://help.aliyun.com/document_detail/35230.html?spm=5176.doc35226.6.676.mCU5KZ, 当调用DescribeRules接口时,可以拿到所有的规则列表,但是返回的列表里只有RuleName,没有RuleId

使用场景:比如我想删除某个loadbalancer配置的所有Rules:

  • 先调用DescribeRules接口拿到规则列表
  • 然后调用DeleteRules接口删除规则。

问题是DescribeRules没有返回RuleId,而DeleteRules接口又需要RuleId作参数。
cc @superxi @ddysher

Default value or zero value?

type ModifyScalingGroupArgs struct {
	ScalingGroupId               string
	ScalingGroupName             string
	ActiveScalingConfigurationId string
	MinSize                      int
	MaxSize                      int
	DefaultCooldown              int
	RemovalPolicy                common.FlattenArray
}

MinSize and MaxSize is allowed to set to 0, but the default value is also 0.
When set query value, aliyungo treat 0 as not set, this is not true sometimes.

case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
			i := field.Uint()
			if i != 0 {
				value = strconv.FormatUint(i, 10)
			}

We better use a int pointer to indicate whether is zero value or value not set

slb could not use common.PayByBandwidth

ecs use PayByBandwidth:
https://help.aliyun.com/document_detail/25499.html?spm=5176.product25365.6.235.VIlqu1

but slb use paybytraffic:
https://help.aliyun.com/document_detail/27577.html?spm=5176.product27537.6.118.R6Bqe6

So, slb could not use common.PayByBandwidth in CreateLoadBalancerArgs struct:

type CreateLoadBalancerArgs struct {
    RegionId           common.Region
    LoadBalancerName   string
    AddressType        AddressType
    VSwitchId          string
    InternetChargeType common.InternetChargeType
    Bandwidth          int
    ClientToken        string
}

I found DescribeInstances support fuzzy query, but it lacks some documents

For example, it supports this fuzzy query kube-*:

args1 := ecs.DescribeInstancesArgs{
        RegionId:     "cn-beijing",
        InstanceName: "kube-*",
        Status:       ecs.Running,
    }
    instance, _, err := client.DescribeInstances(&args1)

I got the result:

[]ecs.InstanceAttributesType{ecs.InstanceAttributesType{InstanceId:"i-25ruedcj2", InstanceName:"kube-master", ...},
ecs.InstanceAttributesType{InstanceId:"i-25zf0s2mo", InstanceName:"kube-node1",  ...},
ecs.InstanceAttributesType{InstanceId:"i-25lx43e3z", InstanceName:"kube-node2", ...},
ecs.InstanceAttributesType{InstanceId:"i-25mo0ad2d", InstanceName:"kube-node3", ...}

Is ecs default Enpoint is correct?

I saw document (https://help.aliyun.com/document_detail/25489.html?spm=5176.doc25492.6.686.RpFcit) and it said that entry point is <ecs.aliyuncs.com>.

But i see https://github.com/denverdino/aliyungo/blob/master/ecs/client.go#L20 and it is "https://ecs-cn-hangzhou.aliyuncs.com" by default.

It will lead to "Error creating machine: Error in driver during machine creation: Aliyun API Error: ... dial tcp 140.205.155.65:443: i/o timeout" when i create ecs instance.

局域网访问

请问如何在阿里云内ECS里使用OSS内网推送?

Status Code: 403: OperationDenied Message

我在调试 API 时遇到:

* aliyun_ecs_instance.test01: Failed to create instance from Image ubuntu1404_64_40G_aliaegis_20160222.vhd: Aliyun API Error: RequestId: D0CC639E-180D-4827-97CB-FC609F6C95CD Status Code: 403 Code: OperationDenied Message: The resource is out of usage.

请问该如何解决?

Proposal on improving "func shouldRetry(err error)"

I am thinking, for http errors, we may be able to check the status code to see if the request is retry-able. We have no reason to retry a request with status code 400, 403, 404.

However, as we have so many http status codes, it may be hard to check every code to tell if it is retry-able or not. I could not find any document about those http codes that are not retry-able.

Let me know if you have any comments, thanks.

SLB CreateRule接口返回500错误

请求json:

[{"RuleId":"","RuleName":"32507","Domain":"caicloud.io","Url":"","VServerGroupId":"rsp-wz9ulsi3q77ec"}]

报错:

Aliyun API Error: RequestId: 96AC3877-44F5-46C5-B6F6-D9E57CB9AAAD Status Code: 500 Code: InternalError Message: The request processing has failed due to some unknown error, exception or failure.  

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.