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