Cherry pick v1.7 into master
This commit is contained in:
parent
a09dfa3ce1
commit
b6498cdcbc
73 changed files with 6573 additions and 186 deletions
21
vendor/github.com/smueller18/goinwx/LICENSE
generated
vendored
Normal file
21
vendor/github.com/smueller18/goinwx/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2017 Andrew
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
54
vendor/github.com/smueller18/goinwx/account.go
generated
vendored
Normal file
54
vendor/github.com/smueller18/goinwx/account.go
generated
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
package goinwx
|
||||
|
||||
const (
|
||||
methodAccountLogin = "account.login"
|
||||
methodAccountLogout = "account.logout"
|
||||
methodAccountLock = "account.lock"
|
||||
methodAccountUnlock = "account.unlock"
|
||||
)
|
||||
|
||||
type AccountService interface {
|
||||
Login() error
|
||||
Logout() error
|
||||
Lock() error
|
||||
Unlock(tan string) error
|
||||
}
|
||||
|
||||
type AccountServiceOp struct {
|
||||
client *Client
|
||||
}
|
||||
|
||||
var _ AccountService = &AccountServiceOp{}
|
||||
|
||||
func (s *AccountServiceOp) Login() error {
|
||||
req := s.client.NewRequest(methodAccountLogin, map[string]interface{}{
|
||||
"user": s.client.Username,
|
||||
"pass": s.client.Password,
|
||||
})
|
||||
|
||||
_, err := s.client.Do(*req)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *AccountServiceOp) Logout() error {
|
||||
req := s.client.NewRequest(methodAccountLogout, nil)
|
||||
|
||||
_, err := s.client.Do(*req)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *AccountServiceOp) Lock() error {
|
||||
req := s.client.NewRequest(methodAccountLock, nil)
|
||||
|
||||
_, err := s.client.Do(*req)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *AccountServiceOp) Unlock(tan string) error {
|
||||
req := s.client.NewRequest(methodAccountUnlock, map[string]interface{}{
|
||||
"tan": tan,
|
||||
})
|
||||
|
||||
_, err := s.client.Do(*req)
|
||||
return err
|
||||
}
|
150
vendor/github.com/smueller18/goinwx/contact.go
generated
vendored
Normal file
150
vendor/github.com/smueller18/goinwx/contact.go
generated
vendored
Normal file
|
@ -0,0 +1,150 @@
|
|||
package goinwx
|
||||
|
||||
import (
|
||||
"github.com/fatih/structs"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
const (
|
||||
methodContactInfo = "contact.info"
|
||||
methodContactList = "contact.list"
|
||||
methodContactCreate = "contact.create"
|
||||
methodContactDelete = "contact.delete"
|
||||
methodContactUpdate = "contact.update"
|
||||
)
|
||||
|
||||
type ContactService interface {
|
||||
Create(*ContactCreateRequest) (int, error)
|
||||
Update(*ContactUpdateRequest) error
|
||||
Delete(int) error
|
||||
Info(int) (*ContactInfoResponse, error)
|
||||
List(string) (*ContactListResponse, error)
|
||||
}
|
||||
|
||||
type ContactServiceOp struct {
|
||||
client *Client
|
||||
}
|
||||
|
||||
var _ ContactService = &ContactServiceOp{}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
type ContactInfoResponse struct {
|
||||
Contact Contact `mapstructure:"contact"`
|
||||
}
|
||||
|
||||
type ContactListResponse struct {
|
||||
Count int
|
||||
Contacts []Contact `mapstructure:"contact"`
|
||||
}
|
||||
|
||||
func (s *ContactServiceOp) Create(request *ContactCreateRequest) (int, error) {
|
||||
req := s.client.NewRequest(methodContactCreate, structs.Map(request))
|
||||
|
||||
resp, err := s.client.Do(*req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var result map[string]int
|
||||
err = mapstructure.Decode(*resp, &result)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result["id"], nil
|
||||
}
|
||||
|
||||
func (s *ContactServiceOp) Delete(roId int) error {
|
||||
req := s.client.NewRequest(methodContactDelete, map[string]interface{}{
|
||||
"id": roId,
|
||||
})
|
||||
|
||||
_, err := s.client.Do(*req)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *ContactServiceOp) Update(request *ContactUpdateRequest) error {
|
||||
req := s.client.NewRequest(methodContactUpdate, structs.Map(request))
|
||||
|
||||
_, err := s.client.Do(*req)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *ContactServiceOp) Info(contactId int) (*ContactInfoResponse, error) {
|
||||
var requestMap = make(map[string]interface{})
|
||||
requestMap["wide"] = 1
|
||||
|
||||
if contactId != 0 {
|
||||
requestMap["id"] = contactId
|
||||
}
|
||||
|
||||
req := s.client.NewRequest(methodContactInfo, requestMap)
|
||||
|
||||
resp, err := s.client.Do(*req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result ContactInfoResponse
|
||||
err = mapstructure.Decode(*resp, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (s *ContactServiceOp) List(search string) (*ContactListResponse, error) {
|
||||
var requestMap = make(map[string]interface{})
|
||||
|
||||
if search != "" {
|
||||
requestMap["search"] = search
|
||||
}
|
||||
req := s.client.NewRequest(methodContactList, requestMap)
|
||||
|
||||
resp, err := s.client.Do(*req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result ContactListResponse
|
||||
err = mapstructure.Decode(*resp, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
303
vendor/github.com/smueller18/goinwx/domain.go
generated
vendored
Normal file
303
vendor/github.com/smueller18/goinwx/domain.go
generated
vendored
Normal file
|
@ -0,0 +1,303 @@
|
|||
package goinwx
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/structs"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
const (
|
||||
methodDomainCheck = "domain.check"
|
||||
methodDomainCreate = "domain.create"
|
||||
methodDomainDelete = "domain.delete"
|
||||
methodDomainGetPrices = "domain.getPrices"
|
||||
methodDomainGetRules = "domain.getRules"
|
||||
methodDomainInfo = "domain.info"
|
||||
methodDomainList = "domain.list"
|
||||
methodDomainLog = "domain.log"
|
||||
methodDomainPush = "domain.push"
|
||||
methodDomainRenew = "domain.renew"
|
||||
methodDomainRestore = "domain.restore"
|
||||
methodDomainStats = "domain.stats"
|
||||
methodDomainTrade = "domain.trade"
|
||||
methodDomainTransfer = "domain.transfer"
|
||||
methodDomainTransferOut = "domain.transferOut"
|
||||
methodDomainUpdate = "domain.update"
|
||||
methodDomainWhois = "domain.whois"
|
||||
)
|
||||
|
||||
type DomainService interface {
|
||||
Check(domains []string) ([]DomainCheckResponse, error)
|
||||
Register(request *DomainRegisterRequest) (*DomainRegisterResponse, error)
|
||||
Delete(domain string, scheduledDate time.Time) error
|
||||
Info(domain string, roId int) (*DomainInfoResponse, error)
|
||||
GetPrices(tlds []string) ([]DomainPriceResponse, error)
|
||||
List(*DomainListRequest) (*DomainList, error)
|
||||
Whois(domain string) (string, error)
|
||||
}
|
||||
|
||||
type DomainServiceOp struct {
|
||||
client *Client
|
||||
}
|
||||
|
||||
var _ DomainService = &DomainServiceOp{}
|
||||
|
||||
type domainCheckResponseRoot struct {
|
||||
Domains []DomainCheckResponse `mapstructure:"domain"`
|
||||
}
|
||||
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"`
|
||||
}
|
||||
|
||||
type domainPriceResponseRoot struct {
|
||||
Prices []DomainPriceResponse `mapstructure:"price"`
|
||||
}
|
||||
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"`
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
type DomainRegisterResponse struct {
|
||||
RoId int
|
||||
Price float32
|
||||
Currency string
|
||||
}
|
||||
|
||||
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 string `mapstructure:"noDelegation"`
|
||||
Contacts map[string]Contact `mapstructure:"contact"`
|
||||
}
|
||||
|
||||
type Contact struct {
|
||||
RoId int
|
||||
Id string
|
||||
Type string
|
||||
Name string
|
||||
Org string
|
||||
Street string
|
||||
City string
|
||||
PostalCode string `mapstructure:"pc"`
|
||||
StateProvince string `mapstructure:"sp"`
|
||||
Country string `mapstructure:"cc"`
|
||||
Phone string `mapstructure:"voice"`
|
||||
Fax string
|
||||
Email string
|
||||
Remarks string
|
||||
Protection string
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
type DomainList struct {
|
||||
Count int
|
||||
Domains []DomainInfoResponse `mapstructure:"domain"`
|
||||
}
|
||||
|
||||
func (s *DomainServiceOp) Check(domains []string) ([]DomainCheckResponse, error) {
|
||||
req := s.client.NewRequest(methodDomainCheck, map[string]interface{}{
|
||||
"domain": domains,
|
||||
"wide": "2",
|
||||
})
|
||||
|
||||
resp, err := s.client.Do(*req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
root := new(domainCheckResponseRoot)
|
||||
err = mapstructure.Decode(*resp, &root)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return root.Domains, nil
|
||||
}
|
||||
|
||||
func (s *DomainServiceOp) GetPrices(tlds []string) ([]DomainPriceResponse, error) {
|
||||
req := s.client.NewRequest(methodDomainGetPrices, map[string]interface{}{
|
||||
"tld": tlds,
|
||||
"vat": false,
|
||||
})
|
||||
|
||||
resp, err := s.client.Do(*req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
root := new(domainPriceResponseRoot)
|
||||
err = mapstructure.Decode(*resp, &root)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return root.Prices, nil
|
||||
}
|
||||
|
||||
func (s *DomainServiceOp) Register(request *DomainRegisterRequest) (*DomainRegisterResponse, error) {
|
||||
req := s.client.NewRequest(methodDomainCreate, structs.Map(request))
|
||||
|
||||
resp, err := s.client.Do(*req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result DomainRegisterResponse
|
||||
err = mapstructure.Decode(*resp, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (s *DomainServiceOp) Delete(domain string, scheduledDate time.Time) error {
|
||||
req := s.client.NewRequest(methodDomainDelete, map[string]interface{}{
|
||||
"domain": domain,
|
||||
"scDate": scheduledDate.Format(time.RFC3339),
|
||||
})
|
||||
|
||||
_, err := s.client.Do(*req)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *DomainServiceOp) Info(domain string, roId int) (*DomainInfoResponse, error) {
|
||||
req := s.client.NewRequest(methodDomainInfo, map[string]interface{}{
|
||||
"domain": domain,
|
||||
"wide": "2",
|
||||
})
|
||||
if roId != 0 {
|
||||
req.Args["roId"] = roId
|
||||
}
|
||||
|
||||
resp, err := s.client.Do(*req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result DomainInfoResponse
|
||||
err = mapstructure.Decode(*resp, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fmt.Println("Response", result)
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (s *DomainServiceOp) List(request *DomainListRequest) (*DomainList, error) {
|
||||
if request == nil {
|
||||
return nil, errors.New("Request can't be nil")
|
||||
}
|
||||
requestMap := structs.Map(request)
|
||||
requestMap["wide"] = "2"
|
||||
|
||||
req := s.client.NewRequest(methodDomainList, requestMap)
|
||||
|
||||
resp, err := s.client.Do(*req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result DomainList
|
||||
err = mapstructure.Decode(*resp, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (s *DomainServiceOp) Whois(domain string) (string, error) {
|
||||
req := s.client.NewRequest(methodDomainWhois, map[string]interface{}{
|
||||
"domain": domain,
|
||||
})
|
||||
|
||||
resp, err := s.client.Do(*req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var result map[string]string
|
||||
err = mapstructure.Decode(*resp, &result)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return result["whois"], nil
|
||||
}
|
133
vendor/github.com/smueller18/goinwx/goinwx.go
generated
vendored
Normal file
133
vendor/github.com/smueller18/goinwx/goinwx.go
generated
vendored
Normal file
|
@ -0,0 +1,133 @@
|
|||
package goinwx
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"github.com/kolo/xmlrpc"
|
||||
)
|
||||
|
||||
const (
|
||||
libraryVersion = "0.4.0"
|
||||
APIBaseUrl = "https://api.domrobot.com/xmlrpc/"
|
||||
APISandboxBaseUrl = "https://api.ote.domrobot.com/xmlrpc/"
|
||||
APILanguage = "eng"
|
||||
)
|
||||
|
||||
// Client manages communication with INWX API.
|
||||
type Client struct {
|
||||
// HTTP client used to communicate with the INWX API.
|
||||
RPCClient *xmlrpc.Client
|
||||
|
||||
// Base URL for API requests.
|
||||
BaseURL *url.URL
|
||||
|
||||
// API username
|
||||
Username string
|
||||
|
||||
// API password
|
||||
Password string
|
||||
|
||||
// User agent for client
|
||||
APILanguage string
|
||||
|
||||
// Services used for communicating with the API
|
||||
Account AccountService
|
||||
Domains DomainService
|
||||
Nameservers NameserverService
|
||||
Contacts ContactService
|
||||
}
|
||||
|
||||
type ClientOptions struct {
|
||||
Sandbox bool
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
ServiceMethod string
|
||||
Args map[string]interface{}
|
||||
}
|
||||
|
||||
// Response is a INWX API response. This wraps the standard http.Response returned from INWX.
|
||||
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"`
|
||||
}
|
||||
|
||||
// An ErrorResponse reports the error caused by an API request
|
||||
type ErrorResponse struct {
|
||||
Code int `xmlrpc:"code"`
|
||||
Message string `xmlrpc:"msg"`
|
||||
ReasonCode string `xmlrpc:"reasonCode"`
|
||||
Reason string `xmlrpc:"reason"`
|
||||
}
|
||||
|
||||
// NewClient returns a new INWX API client.
|
||||
func NewClient(username, password string, opts *ClientOptions) *Client {
|
||||
var useSandbox bool
|
||||
if opts != nil {
|
||||
useSandbox = opts.Sandbox
|
||||
}
|
||||
|
||||
var baseURL *url.URL
|
||||
|
||||
if useSandbox {
|
||||
baseURL, _ = url.Parse(APISandboxBaseUrl)
|
||||
} else {
|
||||
baseURL, _ = url.Parse(APIBaseUrl)
|
||||
}
|
||||
|
||||
rpcClient, _ := xmlrpc.NewClient(baseURL.String(), nil)
|
||||
|
||||
client := &Client{RPCClient: rpcClient,
|
||||
BaseURL: baseURL,
|
||||
Username: username,
|
||||
Password: password,
|
||||
}
|
||||
|
||||
client.Account = &AccountServiceOp{client: client}
|
||||
client.Domains = &DomainServiceOp{client: client}
|
||||
client.Nameservers = &NameserverServiceOp{client: client}
|
||||
client.Contacts = &ContactServiceOp{client: client}
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
// NewRequest creates an API request.
|
||||
func (c *Client) NewRequest(serviceMethod string, args map[string]interface{}) *Request {
|
||||
if args != nil {
|
||||
args["lang"] = APILanguage
|
||||
}
|
||||
|
||||
return &Request{ServiceMethod: serviceMethod, Args: args}
|
||||
}
|
||||
|
||||
// Do sends an API request and returns the API response.
|
||||
func (c *Client) Do(req Request) (*map[string]interface{}, error) {
|
||||
var resp Response
|
||||
err := c.RPCClient.Call(req.ServiceMethod, req.Args, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &resp.ResponseData, CheckResponse(&resp)
|
||||
}
|
||||
|
||||
func (r *ErrorResponse) Error() string {
|
||||
if r.Reason != "" {
|
||||
return fmt.Sprintf("(%d) %s. Reason: (%s) %s",
|
||||
r.Code, r.Message, r.ReasonCode, r.Reason)
|
||||
}
|
||||
return fmt.Sprintf("(%d) %s", r.Code, r.Message)
|
||||
}
|
||||
|
||||
// CheckResponse checks the API response for errors, and returns them if present.
|
||||
func CheckResponse(r *Response) error {
|
||||
if c := r.Code; c >= 1000 && c <= 1500 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &ErrorResponse{Code: r.Code, Message: r.Message, Reason: r.Reason, ReasonCode: r.ReasonCode}
|
||||
}
|
275
vendor/github.com/smueller18/goinwx/nameserver.go
generated
vendored
Normal file
275
vendor/github.com/smueller18/goinwx/nameserver.go
generated
vendored
Normal file
|
@ -0,0 +1,275 @@
|
|||
package goinwx
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/structs"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
const (
|
||||
methodNameserverCheck = "nameserver.check"
|
||||
methodNameserverCreate = "nameserver.create"
|
||||
methodNameserverCreateRecord = "nameserver.createRecord"
|
||||
methodNameserverDelete = "nameserver.delete"
|
||||
methodNameserverDeleteRecord = "nameserver.deleteRecord"
|
||||
methodNameserverInfo = "nameserver.info"
|
||||
methodNameserverList = "nameserver.list"
|
||||
methodNameserverUpdate = "nameserver.update"
|
||||
methodNameserverUpdateRecord = "nameserver.updateRecord"
|
||||
)
|
||||
|
||||
type NameserverService interface {
|
||||
Check(domain string, nameservers []string) (*NameserverCheckResponse, error)
|
||||
Create(*NameserverCreateRequest) (int, error)
|
||||
Info(*NameserverInfoRequest) (*NamserverInfoResponse, error)
|
||||
List(domain string) (*NamserverListResponse, error)
|
||||
CreateRecord(*NameserverRecordRequest) (int, error)
|
||||
UpdateRecord(recId int, request *NameserverRecordRequest) error
|
||||
DeleteRecord(recId int) error
|
||||
FindRecordById(recId int) (*NameserverRecord, *NameserverDomain, error)
|
||||
}
|
||||
|
||||
type NameserverServiceOp struct {
|
||||
client *Client
|
||||
}
|
||||
|
||||
var _ NameserverService = &NameserverServiceOp{}
|
||||
|
||||
type NameserverCheckResponse struct {
|
||||
Details []string
|
||||
Status string
|
||||
}
|
||||
|
||||
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 int `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"`
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
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"`
|
||||
Prio int `structs:"prio,omitempty"`
|
||||
}
|
||||
|
||||
type NamserverInfoResponse struct {
|
||||
RoId int
|
||||
Domain string
|
||||
Type string
|
||||
MasterIp string
|
||||
LastZoneCheck time.Time
|
||||
SlaveDns interface{}
|
||||
SOAserial string
|
||||
Count int
|
||||
Records []NameserverRecord `mapstructure:"record"`
|
||||
}
|
||||
|
||||
type NameserverRecord struct {
|
||||
Id int
|
||||
Name string
|
||||
Type string
|
||||
Content string
|
||||
Ttl int
|
||||
Prio int
|
||||
UrlRedirectType string
|
||||
UrlRedirectTitle string
|
||||
UrlRedirectDescription string
|
||||
UrlRedirectKeywords string
|
||||
UrlRedirectFavIcon string
|
||||
}
|
||||
|
||||
type NamserverListResponse struct {
|
||||
Count int
|
||||
Domains []NameserverDomain `mapstructure:"domains"`
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
func (s *NameserverServiceOp) Check(domain string, nameservers []string) (*NameserverCheckResponse, error) {
|
||||
req := s.client.NewRequest(methodNameserverCheck, map[string]interface{}{
|
||||
"domain": domain,
|
||||
"ns": nameservers,
|
||||
})
|
||||
|
||||
resp, err := s.client.Do(*req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result NameserverCheckResponse
|
||||
err = mapstructure.Decode(*resp, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (s *NameserverServiceOp) Info(request *NameserverInfoRequest) (*NamserverInfoResponse, error) {
|
||||
req := s.client.NewRequest(methodNameserverInfo, structs.Map(request))
|
||||
|
||||
resp, err := s.client.Do(*req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var result NamserverInfoResponse
|
||||
err = mapstructure.Decode(*resp, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (s *NameserverServiceOp) List(domain string) (*NamserverListResponse, error) {
|
||||
requestMap := map[string]interface{}{
|
||||
"domain": "*",
|
||||
"wide": 2,
|
||||
}
|
||||
if domain != "" {
|
||||
requestMap["domain"] = domain
|
||||
}
|
||||
req := s.client.NewRequest(methodNameserverList, requestMap)
|
||||
|
||||
resp, err := s.client.Do(*req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var result NamserverListResponse
|
||||
err = mapstructure.Decode(*resp, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (s *NameserverServiceOp) Create(request *NameserverCreateRequest) (int, error) {
|
||||
req := s.client.NewRequest(methodNameserverCreate, structs.Map(request))
|
||||
|
||||
resp, err := s.client.Do(*req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var result map[string]int
|
||||
err = mapstructure.Decode(*resp, &result)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result["roId"], nil
|
||||
}
|
||||
|
||||
func (s *NameserverServiceOp) CreateRecord(request *NameserverRecordRequest) (int, error) {
|
||||
req := s.client.NewRequest(methodNameserverCreateRecord, structs.Map(request))
|
||||
|
||||
resp, err := s.client.Do(*req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var result map[string]int
|
||||
err = mapstructure.Decode(*resp, &result)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return result["id"], nil
|
||||
}
|
||||
|
||||
func (s *NameserverServiceOp) UpdateRecord(recId int, request *NameserverRecordRequest) error {
|
||||
if request == nil {
|
||||
return errors.New("Request can't be nil")
|
||||
}
|
||||
requestMap := structs.Map(request)
|
||||
requestMap["id"] = recId
|
||||
|
||||
req := s.client.NewRequest(methodNameserverUpdateRecord, requestMap)
|
||||
|
||||
_, err := s.client.Do(*req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *NameserverServiceOp) DeleteRecord(recId int) error {
|
||||
req := s.client.NewRequest(methodNameserverDeleteRecord, map[string]interface{}{
|
||||
"id": recId,
|
||||
})
|
||||
|
||||
_, err := s.client.Do(*req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *NameserverServiceOp) FindRecordById(recId int) (*NameserverRecord, *NameserverDomain, error) {
|
||||
listResp, err := s.client.Nameservers.List("")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
for _, domainItem := range listResp.Domains {
|
||||
resp, err := s.client.Nameservers.Info(&NameserverInfoRequest{RoId: domainItem.RoId})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
for _, record := range resp.Records {
|
||||
if record.Id == recId {
|
||||
return &record, &domainItem, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil, fmt.Errorf("couldn't find INWX Record for id %d", recId)
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue