Skip to content

dpavlotzky/transip

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

TransIP API

Small library in Golang that implements:

  • DomainService/getDomainNames
  • DomainService/getInfo
  • DomainService/batchGetInfo
  • DomainService/setDnsEntries

If you need other methods on the TransIP API be free to fork my code and I'll merge it with love. :)

Why use this library instead of writing own:

  • 'Correctly' implementing __nonce because there's no uniqid in Golang;
  • Correctly implementing signature, RSA Private key signing of cookie signature (unittests included);
  • Tokenized XML-parser to keep data structures free of clutter (stripping SOAP envelopes);

Example code

Get info for a domain

package main

import (
	"github.com/mpdroog/transip"
	"github.com/mpdroog/transip/creds"
	"fmt"
)

func printDomainInfo(username, privKeyPath string) error {
	creds := creds.Client{
		Login:     username,
		ReadWrite: false,
	}
	if err := creds.SetPrivateKeyFromPath(privKeyPath); err != nil {
		return fmt.Errorf("could not load private key from path %s: %s",
			privKeyPath, err)
	}
    	
	domainService := transip.DomainService{creds}
	domain, err := domainService.Domain("example.com")
	if err != nil {
		return err
	}
	fmt.Printf("\t%+v\n\n", domain)
    return nil
}

Get a list of domain names and return all of their details

package main

import (
	"github.com/mpdroog/transip"
	"github.com/mpdroog/transip/creds"
	"fmt"
)

func printDomainNames(username, privKeyPath string) error {
	creds := creds.Client{
		Login:     username,
		ReadWrite: false,
	}
	if err := creds.SetPrivateKeyFromPath(privKeyPath); err != nil {
		return fmt.Errorf("could not load private key from path %s: %s",
			privKeyPath, err)
	}
    	
	domainService := transip.DomainService{creds}
	domainNames, err := domainService.DomainNames()
	if err != nil {
		return err
	}
	domains, err := domainService.Domains(domainNames.Item)
	if err != nil {
		return err
	}
	fmt.Printf("Managed domains:\n")
	for _, domain := range domains {
		fmt.Printf("★ %s\n", domain.Name)
		fmt.Printf("\t%+v\n\n", domain)
	}

	return nil
}

Overwrite a domain's DNS entries

package main

import (
	"github.com/mpdroog/transip"
	"github.com/mpdroog/transip/creds"
	"github.com/mpdroog/transip/soap"
	"fmt"
)

func overWriteDnsEntries(username, privKeyPath, domain string) error {
	creds := creds.Client{
		Login:     username,
		ReadWrite: true,
	}
	if err := creds.SetPrivateKeyFromPath(privKeyPath); err != nil {
		return fmt.Errorf("could not load private key from path %s: %s",
	    		privKeyPath, err)
	}

	// 360 = 6min (TTL in seconds)
	recordSet := []soap.DomainDNSentry{
		{Name: "@", Expire: 360, Type: "A", Content: "127.0.0.1"},
	}

	domainService := transip.DomainService{creds}
	err := domainService.SetDNSEntries(domain, recordSet)
	return err
}

About

TransIP API in Golang

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%