transip / gotransip Goto Github PK
View Code? Open in Web Editor NEWTransIP API client for Go
License: MIT License
TransIP API client for Go
License: MIT License
When testing my updated version of k8s/external-dns I ran into the issue that the timezone Europe/Amsterdam could not be found. This is because the minimal image doesn't include timezone data.
At https://github.com/transip/gotransip/blob/master/rest/response.go#L46 we try to load the time in the Europe/Amsterdam zone. Are we sure the date is printed in that zone. It would be much better to have the time in UTC if that is the case.
For Go module libraries with major version >= 2, the major version is required to be part of the module path. See rules here: https://github.com/golang/go/wiki/Modules#semantic-import-versioning
Since v5
is not part of the URL for this library, I can't install it. I can only install versions of the library that predate your usage of go.mod
, so the latest version available to me is v5.8.2
.
I'm getting API errors (HTTP 500) running domain.setDNSEntries
with that version of the library, though, so I'm kinda stuck at this point.
Any ideas?
go.mod
module github.com/korijn/test
go 1.13
require (
github.com/transip/gotransip v5.18.0
)
$ go mod download
go: finding github.com/transip/gotransip v5.18.0
go: finding github.com/transip/gotransip v5.18.0
go: errors parsing go.mod:
C:\Users\korij\dev\test\go.mod:7: require github.com/transip/gotransip: version "v5.18.0" invalid: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v5
Leaving the entry out of go.mod
and letting go pull in the library on its own when running go build .
installs an outdated version:
github.com/transip/gotransip v5.8.2+incompatible // indirect
$ go version
go version go1.13.1 windows/amd64
Whenever the IsCustomerLocked
boolean on the VPS is set to true
, I'm unable to update it back to false
. I am however able to set it back to false
by sending a plain API request from Postman/cURL or via the frontend.
On the other hand, when IsCustomerLocked
is set to false
, I am able to update it into true
just fine.
...
vps, _ := vpsRepo.GetByName("example-vps1")
fmt.Printf("Current lock status: %t \n", vps.IsCustomerLocked)
fmt.Printf("Locking VPS: %s \n", vps.Description)
vps.IsCustomerLocked = true
vpsRepo.Update(vps)
...
...
vps, _ := vpsRepo.GetByName("example-vps1")
fmt.Printf("Current lock status: %t \n", vps.IsCustomerLocked)
fmt.Printf("Unlocking VPS: %s \n", vps.Description)
vps.IsCustomerLocked = false
vpsRepo.Update(vps)
...
The VPS should be back in an unlocked state, where IsCustomerLocked
would be false
.
IsCustomerLocked
stays in a true state and is impossible to set back to false
from the gotransip API client.
I'm unsure what exactly is causing this issue, but the fact that a regular cURL command does allow me to set IsCustomerLocked
back to false makes me suspect an issue in the implementation of the VPS Repository Update function.
I'd like to limit the validity of the token to the whitelisted IP's and a shorter amount of time than 1 day.
Add "Whitelisted" and "Expiry" fields to "ClientConfiguration"
Cannot register domain name.
client, _ := gotransip.NewSOAPClient(gotransip.ClientConfig{.....})
err := domain.Register(client, "example.com")
Domain name is registred
SOAP Fault 204: Exception received from JSON Server: Invalid API signature, signature does not match the request.
Looking at the code here:
https://github.com/transip/gotransip/blob/master/domain/api.go#L126
It seems a domain name as string is passed as SOAP argument.
Where as the spec seems to indicate a Domain object is required:
https://api.transip.nl/docs/transip.nl/source-class-Transip_DomainService.html#307-318
This is a general question related to the API - I'm not sure where general requests could go (other than [email protected]), so I'm posting it here.
When issuing certificates with Let's Encrypt I'm using the TransIP API to e.g. create the needed CNAME and TXT records. But the API has access to my full range of domains and services. E.g. I cannot limit API access to just access a particular domain or even better: just a certain type of actions with a particular domain (e.g. just updating TXT records of example.org).
Such granular control would make it much more useful because I would be able to leave my credentials at different hosts where a possible attack would only expose a very limited set of features.
When looking at the domain actions (which is what I'm using mostly) the current implementation only allows manipulation of the full zone (basically overwriting the whole zone). Although this seems straightforward it gives most users much more control that they would need to have.
Wondering if there is a place to suggest ideas for a possible v6.0 of the API?
I've written a DNS provider plugin for the lego package to do a DNS-01 challenge for Let's Encrypt. It's currently slated to use the 5.8 release, but unfortunately there are several issues with that release (API errors that vanish when using master which generaters also much clearer errors). I see 5.8 is 13 commits behind master - would it be possible to create a new updated release?
I'm packaging this library for Fedora, and I discovered that the tests fail on 32bit architectures. Specifically they failed on i686 and armv7hl.
cd vps
go test
(this may or may not need Fedora's build flags such as -buildmode pie
to reproduce, I can't confirm as I don't have this hardware and can only trigger the error in Fedora build)all tests pass
Testing: "/builddir/build/BUILD/gotransip-5.8.1/_build/src/github.com/transip/gotransip/vps"
+ GOPATH=/builddir/build/BUILD/gotransip-5.8.1/_build:/usr/share/gocode
+ go test -buildmode pie -compiler gc -ldflags '-extldflags '\''-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld '\'''
--- FAIL: TestGetTrafficInformationForVps (0.00s)
api_test.go:213:
Error Trace: api_test.go:213
Error: Not equal:
expected: 2483004356
actual : 2147483647
Test: TestGetTrafficInformationForVps
api_test.go:214:
Error Trace: api_test.go:214
Error: Not equal:
expected: 4380854877
actual : 2147483647
Test: TestGetTrafficInformationForVps
api_test.go:215:
Error Trace: api_test.go:215
Error: Not equal:
expected: 1073741824000
actual : 2147483647
Test: TestGetTrafficInformationForVps
--- FAIL: TestGetPooledTrafficInformation (0.00s)
api_test.go:231:
Error Trace: api_test.go:231
Error: Not equal:
expected: 128356924407
actual : 2147483647
Test: TestGetPooledTrafficInformation
api_test.go:232:
Error Trace: api_test.go:232
Error: Not equal:
expected: 200639805776
actual : 2147483647
Test: TestGetPooledTrafficInformation
api_test.go:233:
Error Trace: api_test.go:233
Error: Not equal:
expected: 16106127360000
actual : 2147483647
Test: TestGetPooledTrafficInformation
FAIL
I'm generating tokens with an expiry of 30 minutes. I noticed that I got multiple tokens created despite the token being in the cache. After investigating, I found the lib assumes time can skew as much as half an hour. This results in every token I just generated to immediately be invalidated.
There also seems to be some rate limiting going on, as request fail lots of times with tokens generated in quick succession.
To have the token usable for (close to) the configured expiry
Non-expired token invalidated immediately
Lower the expirationSkew
to a more sensible value (where I see "sensible" as a reasonable and acceptable expected time skew). Having a more-or-less synchronised time is not exactly rocket-science for a few decades now.
I suggest 1/2 the minimum allowed expiry, if such thing exists. A few second up to 60 sec otherwise. Or make it (package-wide) configurable instead of const.
To be understandable by go module, the tags must follow semver
The tags v5.8
, v5.13
, v5.14
are not supported.
module github.com/yourusername/project
go 1.12
require (
github.com/transip/gotransip v5.14
)
Run go mod tidy
module github.com/yourusername/project
go 1.12
require (
github.com/transip/gotransip v5.14.0
)
module github.com/yourusername/project
go 1.12
require (
github.com/transip/gotransip v0.0.0-20190614113603-efb64632cab7
)
Add tags without remove the previous tags:
v5.8.0
on v5.8
v5.13.0
on v5.13
v5.14.0
on v5.14
git tag v5.8.0 v5.8
git tag v5.13.0 v5.13
git tag v5.14.0 v5.14
git push --tags
I'm trying to create a Golang project using golang/dep, and I'm trying to install this project as a dependency. But I get errors, because the code uses github.com/transip/gotransip/v6
, but that directory isn't found (obviously).
dep init
dep ensure -add github.com/transip/[email protected]
When the dependency has been added, dep
will install the dependency in the vendor
directory and I can import github.com/transip/gotransip
and use it.
I get the following errors (and some more, but they're the same as the last 3):
Fetching sources...
Solving failure: No versions of github.com/transip/gotransip met constraints:
v6.0.3: "github.com/transip/gotransip" imports "github.com/transip/gotransip/v6/authenticator", which contains malformed code: no package exists at "github.com/transip/gotransip/v6/authenticator"
v6.0.2: Could not introduce github.com/transip/[email protected], as it is not allowed by constraint ^6.0.3 from project github.com/vedicium/dehydrated-transip-dns01-go.
v6.0.1: Could not introduce github.com/transip/[email protected], as it is not allowed by constraint ^6.0.3 from project github.com/vedicium/dehydrated-transip-dns01-go.
v6.0.0: Could not introduce github.com/transip/[email protected], as it is not allowed by constraint ^6.0.3 from project github.com/vedicium/dehydrated-transip-dns01-go.
It looks like it crashes because it can't find github.com/transip/gotransip/v6/authenticator
. Probably because it's found in github.com/transip/gotransip/authenticator
and not in the v6 directory.
The imports should probably be changed to the root directory (github.com/transip/gotransip
. I understand the v6
is used, but isn't it better if you want to use the SOAP API, you just have to install the V5 version?
The terraform provider https://github.com/kevinvalk/terraform-provider-transip is using gotransip and I just added automatic CI building. Because of the golang crossplatform support, I decided to just compile for all different platforms from Linux.
However, the time.LoadLocation
method does not work well when cross compiling from Linux to Windows (this is related to #31). Hence, whenever you use the gotransip library that calls int time.LoadLocation
, you will get the error: "The system cannot find the path specified.".
GOOS=windows GOARCH=amd64 go build
package main
import (
"log"
"github.com/transip/gotransip/v6"
"github.com/transip/gotransip/v6/domain"
)
func main() {
client, err := gotransip.NewClient(gotransip.DemoClientConfiguration)
if err != nil {
panic(err.Error())
}
name := "transipdemo.be"
repository := domain.Repository{Client: client}
domain, err := repository.GetByDomainName(name)
if err != nil {
log.Printf("failed to lookup domain %q: %s", name, err)
}
log.Printf("Domain: %v", domain)
}
Note: cross compiling from Windows to Linux seems to work
2020/06/12 17:41:34 Domain: {[] ########## 0001-01-01 00:00:00 +0000 UTC false false false transipdemo.be 2011-04-29 00:00:00 +0200 CEST 2021-04-29 00:00:00 +0200 CEST}
2020/06/12 17:41:08 failed to lookup domain "transipdemo.be": The system cannot find the path specified.
2020/06/12 17:41:08 Domain: {[] ########## 0001-01-01 00:00:00 +0000 UTC false false false transipdemo.be 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC}
After some googling I found two issues having similar problems
The proper fix would be to transfer times from the back-end in UTC and just keep it in UTC. If the user of the library would like to present times in local time it is up to them to print it for a specific timezone. In that case time.Parse
can be used instead of time.ParseInlocation
(see https://golang.org/pkg/time/#Parse).
Second best fix would be transfer times from the back-end with timezone information. Then once again time.Parse
can be used instead of time.ParseInlocation
(see https://golang.org/pkg/time/#Parse).
If that is difficult (because all times are saved in Europe/Amsterdam in the back-end), then I guess the best thing would be to just create a fixed timezone instead of using LoadLocation
loc := time.FixedZone("CEST", 2*60*60)
t, _ := time.ParseInLocation(`"2006-01-02"`, `"2011-04-29"`, loc)
fmt.Println(t)
I created a patch that resolves this using the "worst" of the suggestions: https://gist.github.com/kevinvalk/02a4f78abe7a9705b3404f0992b55df8
Unable to order a Vps without addons.
Running the following code results in a panic: SOAP Fault 204: Exception received from JSON Server: Invalid API signature, signature does not match the request.
:
package main
import (
"github.com/transip/gotransip"
"github.com/transip/gotransip/vps"
)
func main() {
// create new TransIP API SOAP client
c, err := gotransip.NewSOAPClient(gotransip.ClientConfig{
AccountName: "accountname",
PrivateKeyPath: "/path/to/private/key",
})
if err != nil {
panic(err.Error())
}
// order a VPS
productName := "vps-bladevps-x1"
addons := []string{}
operatingSystemName := "ubuntu-18.04"
hostname := "hostname"
err = vps.OrderVps(c, productName, addons, operatingSystemName, hostname)
if err != nil {
panic(err.Error())
}
}
If a non-existing addon (addons := []string{'nonexisting'}
) is specified the client will successfully order the Vps.
Should be able to order a Vps without having to add addons.
Ordering a Vps without addons results in a panic: SOAP Fault 204: Exception received from JSON Server: Invalid API signature, signature does not match the request.
.
n/a
I've developed a terraform provider using this library (https://github.com/aequitas/terraform-provider-transip) and was wondering if there is any effort doing on in porting this library to the REST API? I'd like to switch to using the REST API because of some of its feature.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.