forked from transip/gotransip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.go
132 lines (104 loc) · 4.15 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
Package gotransip implements a client for the TransIP Rest API.
This package is a complete implementation for communicating with the TransIP RestAPI.
It covers resource calls available in the TransIP RestAPI Docs and it allows your
project(s) to connect to the TransIP RestAPI easily. Using this package you can order,
update and remove products from your TransIP account.
As of version 6.0 this package is no longer compatible with TransIP SOAP API because the
library is now organized around REST. The SOAP API library versions 5.* are now deprecated
and will no longer receive future updates.
# Example
The following example uses the transip demo token in order to call the api with the test repository.
For more information about authenticating with your own credentials, see the Authentication section.
package main
import (
"github.com/assi010/gotransip/v6"
"github.com/assi010/gotransip/v6/test"
"log"
)
func main() {
// Create a new client with the default demo client config, using the demo token
client, err := gotransip.NewClient(gotransip.DemoClientConfiguration)
if err != nil {
panic(err)
}
testRepo := test.Repository{Client: client}
log.Println("Executing test call to the api server")
if err := testRepo.Test(); err != nil {
panic(err)
}
log.Println("Test successful")
}
# Authentication
If you want to tinker out with the api first without setting up your authentication,
we defined a static DemoClientConfiguration.
Which can be used to create a new client:
client, err := gotransip.NewClient(gotransip.DemoClientConfiguration)
Create a new client using a token:
client, err := gotransip.NewClient(gotransip.ClientConfiguration{
Token: "this_is_where_your_token_goes",
})
As tokens have a limited expiry time you can also request new tokens using the private key
acquired from your transip control panel:
client, err := gotransip.NewClient(gotransip.ClientConfiguration{
AccountName: "accountName",
PrivateKeyPath: "/path/to/api/private.key",
})
We also implemented a PrivateKeyReader option, for users that want to store their key elsewhere,
not on a filesystem but on X datastore:
file, err := os.Open("/path/to/api/private.key")
if err != nil {
panic(err.Error())
}
client, err := gotransip.NewClient(gotransip.ClientConfiguration{
AccountName: "accountName",
PrivateKeyReader: file,
})
# TokenCache
If you would like to keep a token between multiple client instantiations,
you can provide the client with a token cache. If the file does not exist, it creates one for you
cache, err := authenticator.NewFileTokenCache("/tmp/path/to/gotransip_token_cache")
if err != nil {
panic(err.Error())
}
client, err := gotransip.NewClient(gotransip.ClientConfiguration{
AccountName: "accountName",
PrivateKeyPath: "/path/to/api/private.key",
TokenCache: cache
})
As long as a provided TokenCache adheres to the following interface,
the client's authenticator is able to use it. This means you can also provide
your own token cacher: for example, one that caches to etcd
type TokenCache interface {
// Set will save a token by name
Set(key string, token jwt.Token) error
// Get returns a previously acquired token by name returned as jwt.Token
// jwt is a subpackage in the gotransip package
Get(key string) (jwt.Token, error)
}
# Repositories
All resource calls as can be seen on https://api.transip.nl/rest/docs.html
have been grouped in the following repositories,
these are subpackages under the gotransip package:
availabilityzone.Repository
colocation.Repository
domain.Repository
haip.Repository
invoice.Repository
ipaddress.Repository
mailservice.Repository
kubernetes.Repository
product.Repository
test.Repository
traffic.Repository
vps.BigstorageRepository
vps.BlockstorageRepository
vps.PrivateNetworkRepository
vps.Repository
Such a repository can be initialised with a client as follows:
domainRepo := domain.Repository{Client: client}
Each repository has a bunch methods you can use to call get/modify/update resources in
that specific subpackage. For example, here we get a list of domains from a transip account:
domains, err := domainRepo.GetAll()
*/
package gotransip