goinwx

package module
v0.0.0-...-7d41a54 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2022 License: MIT Imports: 7 Imported by: 0

README

INWX Go API client

Build Status PkgGoDev Go Report Card

This go library implements some parts of the official INWX XML-RPC API.

API

package main

import (
	"log"

	"github.com/nrdcg/goinwx"
)

func main() {
	client := goinwx.NewClient("username", "password", &goinwx.ClientOptions{Sandbox: true})

	_, err := client.Account.Login()
	if err != nil {
		log.Fatal(err)
	}

	defer func() {
		if err := client.Account.Logout(); err != nil {
			log.Printf("inwx: failed to logout: %v", err)
		}
	}()

	var request = &goinwx.NameserverRecordRequest{
		Domain:  "domain.com",
		Name:    "foo.domain.com.",
		Type:    "TXT",
		Content: "aaa",
		TTL:     300,
	}

	_, err = client.Nameservers.CreateRecord(request)
	if err != nil {
		log.Fatal(err)
	}
}
Using 2FA

If it is desired to use 2FA without manual entering the TOTP every time, you must set the parameter otp-key to the secret that is shown during the setup of 2FA for you INWX account. Otherwise, you can skip totp.GenerateCode step and enter the verification code of the Google Authenticator app every time manually.

The otp-key looks something like EELTWFL55ESIHPTJAAHBCY7LXBZARUOJ.

package main

import (
	"log"
	"time"

	"github.com/nrdcg/goinwx"
	"github.com/pquerna/otp/totp"
)

func main() {
	client := goinwx.NewClient("username", "password", &goinwx.ClientOptions{Sandbox: true})

	resp, err := client.Account.Login()
	if err != nil {
		log.Fatal(err)
	}

	if resp.TFA != "GOOGLE-AUTH" {
		log.Fatal("unsupported 2 Factor Authentication")
	}

	tan, err := totp.GenerateCode("otp-key", time.Now())
	if err != nil {
		log.Fatal(err)
	}

	err = client.Account.Unlock(tan)
	if err != nil {
		log.Fatal(err)
	}

	defer func() {
		if err := client.Account.Logout(); err != nil {
			log.Printf("inwx: failed to logout: %v", err)
		}
	}()

	request := &goinwx.NameserverRecordRequest{
		Domain:  "domain.com",
		Name:    "foo.domain.com.",
		Type:    "TXT",
		Content: "aaa",
		TTL:     300,
	}

	_, err = client.Nameservers.CreateRecord(request)
	if err != nil {
		log.Fatal(err)
	}
}

Supported Features

Full API documentation can be found here.

The following parts are implemented:

  • Account
    • Login
    • Logout
    • Lock
    • Unlock (with mobile TAN)
  • Domains
    • Check
    • Register
    • Delete
    • Info
    • GetPrices
    • List
    • Whois
    • Update
  • Nameservers
    • Check
    • Create
    • Info
    • List
    • CreateRecord
    • UpdateRecord
    • DeleteRecord
    • FindRecordById
  • Contacts
    • List
    • Info
    • Create
    • Update
    • Delete

Contributions

Your contributions are very appreciated.

Documentation

Index

Constants

View Source
const (
	APIBaseURL        = "https://api.domrobot.com/xmlrpc/"
	APISandboxBaseURL = "https://api.ote.domrobot.com/xmlrpc/"
	APILanguage       = "en"
)

API information.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountService

type AccountService service

AccountService API access to Account.

func (*AccountService) Lock

func (s *AccountService) Lock() error

Lock Account lock.

func (*AccountService) Login

func (s *AccountService) Login() (*LoginResponse, error)

Login Account login.

func (*AccountService) Logout

func (s *AccountService) Logout() error

Logout Account logout.

func (*AccountService) Unlock

func (s *AccountService) Unlock(tan string) error

Unlock Account unlock.

type Client

type Client struct {
	// HTTP client used to communicate with the INWX API.
	RPCClient *xmlrpc.Client

	// Services used for communicating with the API
	Account     *AccountService
	Domains     *DomainService
	Nameservers *NameserverService
	Contacts    *ContactService
	// contains filtered or unexported fields
}

Client manages communication with INWX API.

func NewClient

func NewClient(username, password string, opts *ClientOptions) *Client

NewClient returns a new INWX API client.

func (*Client) Do

func (c *Client) Do(req *Request) (map[string]interface{}, error)

Do sends an API request and returns the API response.

func (*Client) NewRequest

func (c *Client) NewRequest(serviceMethod string, args map[string]interface{}) *Request

NewRequest creates an API request.

type ClientOptions

type ClientOptions struct {
	Sandbox bool

	// Language of the return message. (en/de/es)
	Lang string

	// Base URL for API requests (only for client testing purpose).
	BaseURL *url.URL
}

ClientOptions Options of the API client.

type Contact

type Contact struct {
	RoID          int    `mapstructure:"roId"`
	ID            string `mapstructure:"id"`
	Type          string `mapstructure:"type"`
	Name          string `mapstructure:"name"`
	Org           string `mapstructure:"org"`
	Street        string `mapstructure:"street"`
	City          string `mapstructure:"city"`
	PostalCode    string `mapstructure:"pc"`
	StateProvince string `mapstructure:"sp"`
	Country       string `mapstructure:"cc"`
	Phone         string `mapstructure:"voice"`
	Fax           string `mapstructure:"fax"`
	Email         string `mapstructure:"email"`
	Remarks       string `mapstructure:"remarks"`
	Protection    string `mapstructure:"protection"`
}

Contact API model.

type ContactCreateRequest

type ContactCreateRequest struct {
	Type          string `structs:"type"`
	Name          string `structs:"name"`
	Org           string `structs:"org,omitempty"`
	Street        string `structs:"street"`
	City          string `structs:"city"`
	PostalCode    string `structs:"pc"`
	StateProvince string `structs:"sp,omitempty"`
	CountryCode   string `structs:"cc"`
	Voice         string `structs:"voice"`
	Fax           string `structs:"fax,omitempty"`
	Email         string `structs:"email"`
	Remarks       string `structs:"remarks,omitempty"`
	Protection    bool   `structs:"protection,omitempty"`
	Testing       bool   `structs:"testing,omitempty"`
}

ContactCreateRequest API model.

type ContactInfoResponse

type ContactInfoResponse struct {
	Contact Contact `mapstructure:"contact"`
}

ContactInfoResponse API model.

type ContactListResponse

type ContactListResponse struct {
	Count    int
	Contacts []Contact `mapstructure:"contact"`
}

ContactListResponse API model.

type ContactService

type ContactService service

ContactService API access to Contact.

func (*ContactService) Create

func (s *ContactService) Create(request *ContactCreateRequest) (int, error)

Create Creates a contact.

func (*ContactService) Delete

func (s *ContactService) Delete(roID int) error

Delete Deletes a contact.

func (*ContactService) Info

func (s *ContactService) Info(contactID int) (*ContactInfoResponse, error)

Info Get information about a contact.

func (*ContactService) List

func (s *ContactService) List(search string) (*ContactListResponse, error)

List Search contacts.

func (*ContactService) Update

func (s *ContactService) Update(request *ContactUpdateRequest) error

Update Updates a contact.

type ContactUpdateRequest

type ContactUpdateRequest struct {
	ID            int    `structs:"id"`
	Name          string `structs:"name,omitempty"`
	Org           string `structs:"org,omitempty"`
	Street        string `structs:"street,omitempty"`
	City          string `structs:"city,omitempty"`
	PostalCode    string `structs:"pc,omitempty"`
	StateProvince string `structs:"sp,omitempty"`
	CountryCode   string `structs:"cc,omitempty"`
	Voice         string `structs:"voice,omitempty"`
	Fax           string `structs:"fax,omitempty"`
	Email         string `structs:"email,omitempty"`
	Remarks       string `structs:"remarks,omitempty"`
	Protection    bool   `structs:"protection,omitempty"`
	Testing       bool   `structs:"testing,omitempty"`
}

ContactUpdateRequest API model.

type DomainCheckResponse

type DomainCheckResponse struct {
	Available   int     `mapstructure:"avail"`
	Status      string  `mapstructure:"status"`
	Name        string  `mapstructure:"name"`
	Domain      string  `mapstructure:"domain"`
	TLD         string  `mapstructure:"tld"`
	CheckMethod string  `mapstructure:"checkmethod"`
	Price       float32 `mapstructure:"price"`
	CheckTime   float32 `mapstructure:"checktime"`
}

DomainCheckResponse API model.

type DomainInfoResponse

type DomainInfoResponse struct {
	RoID         int                `mapstructure:"roId"`
	Domain       string             `mapstructure:"domain"`
	DomainAce    string             `mapstructure:"domainAce"`
	Period       string             `mapstructure:"period"`
	CrDate       time.Time          `mapstructure:"crDate"`
	ExDate       time.Time          `mapstructure:"exDate"`
	UpDate       time.Time          `mapstructure:"upDate"`
	ReDate       time.Time          `mapstructure:"reDate"`
	ScDate       time.Time          `mapstructure:"scDate"`
	TransferLock int                `mapstructure:"transferLock"`
	Status       string             `mapstructure:"status"`
	AuthCode     string             `mapstructure:"authCode"`
	RenewalMode  string             `mapstructure:"renewalMode"`
	TransferMode string             `mapstructure:"transferMode"`
	Registrant   int                `mapstructure:"registrant"`
	Admin        int                `mapstructure:"admin"`
	Tech         int                `mapstructure:"tech"`
	Billing      int                `mapstructure:"billing"`
	Nameservers  []string           `mapstructure:"ns"`
	NoDelegation int                `mapstructure:"noDelegation"`
	Contacts     map[string]Contact `mapstructure:"contact"`
}

DomainInfoResponse API model.

type DomainList

type DomainList struct {
	Count   int
	Domains []DomainInfoResponse `mapstructure:"domain"`
}

DomainList API model.

type DomainListRequest

type DomainListRequest struct {
	Domain       string `structs:"domain,omitempty"`
	RoID         int    `structs:"roId,omitempty"`
	Status       int    `structs:"status,omitempty"`
	Registrant   int    `structs:"registrant,omitempty"`
	Admin        int    `structs:"admin,omitempty"`
	Tech         int    `structs:"tech,omitempty"`
	Billing      int    `structs:"billing,omitempty"`
	RenewalMode  int    `structs:"renewalMode,omitempty"`
	TransferLock int    `structs:"transferLock,omitempty"`
	NoDelegation int    `structs:"noDelegation,omitempty"`
	Tag          int    `structs:"tag,omitempty"`
	Order        int    `structs:"order,omitempty"`
	Page         int    `structs:"page,omitempty"`
	PageLimit    int    `structs:"pagelimit,omitempty"`
}

DomainListRequest API model.

type DomainPriceResponse

type DomainPriceResponse struct {
	Tld                 string  `mapstructure:"tld"`
	Currency            string  `mapstructure:"currency"`
	CreatePrice         float32 `mapstructure:"createPrice"`
	MonthlyCreatePrice  float32 `mapstructure:"monthlyCreatePrice"`
	TransferPrice       float32 `mapstructure:"transferPrice"`
	RenewalPrice        float32 `mapstructure:"renewalPrice"`
	MonthlyRenewalPrice float32 `mapstructure:"monthlyRenewalPrice"`
	UpdatePrice         float32 `mapstructure:"updatePrice"`
	TradePrice          float32 `mapstructure:"tradePrice"`
	TrusteePrice        float32 `mapstructure:"trusteePrice"`
	MonthlyTrusteePrice float32 `mapstructure:"monthlyTrusteePrice"`
	CreatePeriod        int     `mapstructure:"createPeriod"`
	TransferPeriod      int     `mapstructure:"transferPeriod"`
	RenewalPeriod       int     `mapstructure:"renewalPeriod"`
	TradePeriod         int     `mapstructure:"tradePeriod"`
}

DomainPriceResponse API model.

type DomainRegisterRequest

type DomainRegisterRequest struct {
	Domain        string   `structs:"domain"`
	Period        string   `structs:"period,omitempty"`
	Registrant    int      `structs:"registrant"`
	Admin         int      `structs:"admin"`
	Tech          int      `structs:"tech"`
	Billing       int      `structs:"billing"`
	Nameservers   []string `structs:"ns,omitempty"`
	TransferLock  string   `structs:"transferLock,omitempty"`
	RenewalMode   string   `structs:"renewalMode,omitempty"`
	WhoisProvider string   `structs:"whoisProvider,omitempty"`
	WhoisURL      string   `structs:"whoisUrl,omitempty"`
	ScDate        string   `structs:"scDate,omitempty"`
	ExtDate       string   `structs:"extDate,omitempty"`
	Asynchron     string   `structs:"asynchron,omitempty"`
	Voucher       string   `structs:"voucher,omitempty"`
	Testing       string   `structs:"testing,omitempty"`
}

DomainRegisterRequest API model.

type DomainRegisterResponse

type DomainRegisterResponse struct {
	RoID     int     `mapstructure:"roId"`
	Price    float32 `mapstructure:"price"`
	Currency string  `mapstructure:"currency"`
}

DomainRegisterResponse API model.

type DomainService

type DomainService service

DomainService API access to Domain.

func (*DomainService) Check

func (s *DomainService) Check(domains []string) ([]DomainCheckResponse, error)

Check Checks domains.

func (*DomainService) Delete

func (s *DomainService) Delete(domain string, scheduledDate time.Time) error

Delete Deletes a domain.

func (*DomainService) GetPrices

func (s *DomainService) GetPrices(tlds []string) ([]DomainPriceResponse, error)

GetPrices Gets TLDS prices.

func (*DomainService) Info

func (s *DomainService) Info(domain string, roID int) (*DomainInfoResponse, error)

Info Gets information about a domain.

func (*DomainService) List

func (s *DomainService) List(request *DomainListRequest) (*DomainList, error)

List List domains.

func (*DomainService) Register

Register Register a domain.

func (*DomainService) Update

func (s *DomainService) Update(request *DomainUpdateRequest) (float32, error)

Update Updates domain information.

func (*DomainService) Whois

func (s *DomainService) Whois(domain string) (string, error)

Whois Whois about a domains.

type DomainUpdateRequest

type DomainUpdateRequest struct {
	Domain       string   `structs:"domain"`
	Nameservers  []string `structs:"ns,omitempty"`
	TransferLock int      `structs:"transferLock,omitempty"`
	RenewalMode  string   `structs:"renewalMode,omitempty"`
	TransferMode string   `structs:"transferMode,omitempty"`
}

DomainUpdateRequest API model.

type DomainUpdateResponse

type DomainUpdateResponse struct {
	Price float32 `mapstructure:"price"`
}

DomainUpdateResponse API model.

type ErrorResponse

type ErrorResponse struct {
	Code       int    `xmlrpc:"code"`
	Message    string `xmlrpc:"msg"`
	ReasonCode string `xmlrpc:"reasonCode"`
	Reason     string `xmlrpc:"reason"`
}

An ErrorResponse reports the error caused by an API request.

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type LoginResponse

type LoginResponse struct {
	CustomerID int64  `mapstructure:"customerId"`
	AccountID  int64  `mapstructure:"accountId"`
	TFA        string `mapstructure:"tfa"`
	BuildDate  string `mapstructure:"builddate"`
	Version    string `mapstructure:"version"`
}

LoginResponse API model.

type NameserverCheckResponse

type NameserverCheckResponse struct {
	Details []string
	Status  string
}

NameserverCheckResponse API model.

type NameserverCreateRequest

type NameserverCreateRequest struct {
	Domain                 string   `structs:"domain"`
	Type                   string   `structs:"type"`
	Nameservers            []string `structs:"ns,omitempty"`
	MasterIP               string   `structs:"masterIp,omitempty"`
	Web                    string   `structs:"web,omitempty"`
	Mail                   string   `structs:"mail,omitempty"`
	SoaEmail               string   `structs:"soaEmail,omitempty"`
	URLRedirectType        string   `structs:"urlRedirectType,omitempty"`
	URLRedirectTitle       string   `structs:"urlRedirectTitle,omitempty"`
	URLRedirectDescription string   `structs:"urlRedirectDescription,omitempty"`
	URLRedirectFavIcon     string   `structs:"urlRedirectFavIcon,omitempty"`
	URLRedirectKeywords    string   `structs:"urlRedirectKeywords,omitempty"`
	Testing                bool     `structs:"testing,omitempty"`
}

NameserverCreateRequest API model.

type NameserverDomain

type NameserverDomain struct {
	RoID     int    `mapstructure:"roId"`
	Domain   string `mapstructure:"domain"`
	Type     string `mapstructure:"type"`
	MasterIP string `mapstructure:"masterIp"`
	Mail     string `mapstructure:"mail"`
	Web      string `mapstructure:"web"`
	URL      string `mapstructure:"url"`
	Ipv4     string `mapstructure:"ipv4"`
	Ipv6     string `mapstructure:"ipv6"`
}

NameserverDomain API model.

type NameserverInfoRequest

type NameserverInfoRequest struct {
	Domain   string `structs:"domain,omitempty"`
	RoID     int    `structs:"roId,omitempty"`
	RecordID int    `structs:"recordId,omitempty"`
	Type     string `structs:"type,omitempty"`
	Name     string `structs:"name,omitempty"`
	Content  string `structs:"content,omitempty"`
	TTL      int    `structs:"ttl,omitempty"`
	Priority int64  `structs:"prio,omitempty"`
}

NameserverInfoRequest API model.

type NameserverRecord

type NameserverRecord struct {
	ID                     int    `mapstructure:"id"`
	Name                   string `mapstructure:"name"`
	Type                   string `mapstructure:"type"`
	Content                string `mapstructure:"content"`
	TTL                    int    `mapstructure:"TTL"`
	URLRedirectType        string `mapstructure:"urlRedirectType"`
	URLRedirectTitle       string `mapstructure:"urlRedirectTitle"`
	URLRedirectDescription string `mapstructure:"urlRedirectDescription"`
	URLRedirectKeywords    string `mapstructure:"urlRedirectKeywords"`
	URLRedirectFavIcon     string `mapstructure:"urlRedirectFavIcon"`
}

NameserverRecord API model.

type NameserverRecordRequest

type NameserverRecordRequest struct {
	RoID                   int     `structs:"roId,omitempty"`
	Domain                 string  `structs:"domain,omitempty"`
	Type                   string  `structs:"type"`
	Content                string  `structs:"content"`
	Name                   string  `structs:"name,omitempty"`
	TTL                    int     `structs:"ttl,omitempty"`
	Priority               float64 `structs:"prio,omitempty"`
	URLRedirectType        string  `structs:"urlRedirectType,omitempty"`
	URLRedirectTitle       string  `structs:"urlRedirectTitle,omitempty"`
	URLRedirectDescription string  `structs:"urlRedirectDescription,omitempty"`
	URLRedirectFavIcon     string  `structs:"urlRedirectFavIcon,omitempty"`
	URLRedirectKeywords    string  `structs:"urlRedirectKeywords,omitempty"`
}

NameserverRecordRequest API model.

type NameserverService

type NameserverService service

NameserverService API access to Nameservers.

func (*NameserverService) Check

func (s *NameserverService) Check(domain string, nameservers []string) (*NameserverCheckResponse, error)

Check Checks a domain on nameservers.

func (*NameserverService) Create

func (s *NameserverService) Create(request *NameserverCreateRequest) (int, error)

Create Creates a nameserver.

func (*NameserverService) CreateRecord

func (s *NameserverService) CreateRecord(request *NameserverRecordRequest) (int, error)

CreateRecord Creates a DNS record.

func (*NameserverService) DeleteRecord

func (s *NameserverService) DeleteRecord(recID int) error

DeleteRecord Deletes a DNS record.

func (*NameserverService) FindRecordByID

func (s *NameserverService) FindRecordByID(recID int) (*NameserverRecord, *NameserverDomain, error)

FindRecordByID Search a DNS record by ID.

func (*NameserverService) Info

Info Gets information.

func (*NameserverService) List

List List nameservers for a domain.

func (*NameserverService) UpdateRecord

func (s *NameserverService) UpdateRecord(recID int, request *NameserverRecordRequest) error

UpdateRecord Updates a DNS record.

type NamserverInfoResponse

type NamserverInfoResponse struct {
	RoID          int                `mapstructure:"roId"`
	Domain        string             `mapstructure:"domain"`
	Type          string             `mapstructure:"type"`
	MasterIP      string             `mapstructure:"masterIp"`
	LastZoneCheck time.Time          `mapstructure:"lastZoneCheck"`
	SlaveDNS      []SlaveInfo        `mapstructure:"slaveDns"`
	SOASerial     string             `mapstructure:"SOAserial"`
	Count         int                `mapstructure:"count"`
	Records       []NameserverRecord `mapstructure:"record"`
}

NamserverInfoResponse API model.

type NamserverListResponse

type NamserverListResponse struct {
	Count   int
	Domains []NameserverDomain `mapstructure:"domains"`
}

NamserverListResponse API model.

type Request

type Request struct {
	ServiceMethod string
	Args          map[string]interface{}
}

Request The representation of an API request.

type Response

type Response struct {
	Code         int                    `xmlrpc:"code"`
	Message      string                 `xmlrpc:"msg"`
	ReasonCode   string                 `xmlrpc:"reasonCode"`
	Reason       string                 `xmlrpc:"reason"`
	ResponseData map[string]interface{} `xmlrpc:"resData"`
}

Response is a INWX API response. This wraps the standard http.Response returned from INWX.

type SlaveInfo

type SlaveInfo struct {
	Name string `mapstructure:"name"`
	IP   string `mapstructure:"ip"`
}

SlaveInfo API model.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL