dns.go raw

   1  // Package dns provides access to the Akamai DNS V2 APIs
   2  //
   3  // See: https://techdocs.akamai.com/edge-dns/reference/edge-dns-api
   4  package dns
   5  
   6  import (
   7  	"context"
   8  	"errors"
   9  	"net/http"
  10  
  11  	"github.com/akamai/AkamaiOPEN-edgegrid-golang/v11/pkg/session"
  12  )
  13  
  14  var (
  15  	// ErrStructValidation is returned when given struct validation failed.
  16  	ErrStructValidation = errors.New("struct validation")
  17  )
  18  
  19  type (
  20  	// DNS is the dns api interface
  21  	DNS interface {
  22  		// Authorities
  23  
  24  		// GetAuthorities provides a list of structured read-only list of name servers.
  25  		//
  26  		// See: https://techdocs.akamai.com/edge-dns/reference/get-data-authorities
  27  		GetAuthorities(context.Context, GetAuthoritiesRequest) (*GetAuthoritiesResponse, error)
  28  
  29  		// GetNameServerRecordList provides a list of name server records.
  30  		//
  31  		// See: https://techdocs.akamai.com/edge-dns/reference/get-data-authorities
  32  		GetNameServerRecordList(context.Context, GetNameServerRecordListRequest) ([]string, error)
  33  
  34  		// ListGroups returns group list associated with particular user
  35  		//
  36  		// See: https://techdocs.akamai.com/edge-dns/reference/get-data-groups
  37  		ListGroups(context.Context, ListGroupRequest) (*ListGroupResponse, error)
  38  
  39  		// Data
  40  
  41  		// GetRdata retrieves record rdata, e.g. target.
  42  		GetRdata(ctx context.Context, params GetRdataRequest) ([]string, error)
  43  		// ProcessRdata process rdata.
  44  		ProcessRdata(context.Context, []string, string) []string
  45  		// ParseRData parses rdata. returning map.
  46  		ParseRData(context.Context, string, []string) map[string]interface{}
  47  
  48  		// Recordsets
  49  
  50  		// GetRecordSets retrieves record sets with Query Args. No formatting of arg values.
  51  		//
  52  		// See: https://techdocs.akamai.com/edge-dns/reference/get-zones-zone-recordsets
  53  		GetRecordSets(context.Context, GetRecordSetsRequest) (*GetRecordSetsResponse, error)
  54  		// CreateRecordSets creates multiple record sets.
  55  		//
  56  		// See: https://techdocs.akamai.com/edge-dns/reference/post-zones-zone-recordsets
  57  		CreateRecordSets(context.Context, CreateRecordSetsRequest) error
  58  		// UpdateRecordSets replaces list of record sets.
  59  		//
  60  		// See: https://techdocs.akamai.com/edge-dns/reference/put-zones-zone-recordsets
  61  		UpdateRecordSets(context.Context, UpdateRecordSetsRequest) error
  62  
  63  		// GetRecordList retrieves recordset list based on type.
  64  		//
  65  		// See: https://techdocs.akamai.com/edge-dns/reference/get-zones-zone-recordsets
  66  		GetRecordList(context.Context, GetRecordListRequest) (*GetRecordListResponse, error)
  67  
  68  		// Records
  69  
  70  		// GetRecord retrieves a recordset and returns as RecordBody.
  71  		//
  72  		// See:  https://techdocs.akamai.com/edge-dns/reference/get-zone-name-type
  73  		GetRecord(context.Context, GetRecordRequest) (*GetRecordResponse, error)
  74  		// CreateRecord creates recordset.
  75  		//
  76  		// See: https://techdocs.akamai.com/edge-dns/reference/post-zones-zone-names-name-types-type
  77  		CreateRecord(context.Context, CreateRecordRequest) error
  78  		// DeleteRecord removes recordset.
  79  		//
  80  		// See: https://techdocs.akamai.com/edge-dns/reference/delete-zone-name-type
  81  		DeleteRecord(context.Context, DeleteRecordRequest) error
  82  		// UpdateRecord replaces the recordset.
  83  		//
  84  		// See: https://techdocs.akamai.com/edge-dns/reference/put-zones-zone-names-name-types-type
  85  		UpdateRecord(context.Context, UpdateRecordRequest) error
  86  
  87  		// TSIGKeys
  88  
  89  		// ListTSIGKeys lists the TSIG keys used by zones that you are allowed to manage.
  90  		//
  91  		// See: https://techdocs.akamai.com/edge-dns/reference/get-keys
  92  		ListTSIGKeys(context.Context, ListTSIGKeysRequest) (*ListTSIGKeysResponse, error)
  93  		// GetTSIGKeyZones retrieves DNS Zones using TSIG key.
  94  		//
  95  		// See: https://techdocs.akamai.com/edge-dns/reference/post-keys-used-by
  96  		GetTSIGKeyZones(context.Context, GetTSIGKeyZonesRequest) (*GetTSIGKeyZonesResponse, error)
  97  		// GetTSIGKeyAliases retrieves a DNS Zone's aliases.
  98  		//
  99  		// See: https://techdocs.akamai.com/edge-dns/reference/get-zones-zone-key-used-by
 100  		GetTSIGKeyAliases(context.Context, GetTSIGKeyAliasesRequest) (*GetTSIGKeyAliasesResponse, error)
 101  		// UpdateTSIGKeyBulk updates Bulk Zones TSIG key.
 102  		//
 103  		// See: https://techdocs.akamai.com/edge-dns/reference/post-keys-bulk-update
 104  		UpdateTSIGKeyBulk(context.Context, UpdateTSIGKeyBulkRequest) error
 105  		// GetTSIGKey retrieves a TSIG key for zone.
 106  		//
 107  		// See: https://techdocs.akamai.com/edge-dns/reference/get-zones-zone-key
 108  		GetTSIGKey(context.Context, GetTSIGKeyRequest) (*GetTSIGKeyResponse, error)
 109  		// DeleteTSIGKey deletes TSIG key for zone.
 110  		//
 111  		// See: https://techdocs.akamai.com/edge-dns/reference/delete-zones-zone-key
 112  		DeleteTSIGKey(context.Context, DeleteTSIGKeyRequest) error
 113  		// UpdateTSIGKey updates TSIG key for zone.
 114  		//
 115  		// See: https://techdocs.akamai.com/edge-dns/reference/put-zones-zone-key
 116  		UpdateTSIGKey(context.Context, UpdateTSIGKeyRequest) error
 117  
 118  		// Zones
 119  
 120  		// ListZones retrieves a list of all zones user can access.
 121  		//
 122  		// See: https://techdocs.akamai.com/edge-dns/reference/get-zones
 123  		ListZones(context.Context, ListZonesRequest) (*ZoneListResponse, error)
 124  
 125  		// GetZone retrieves Zone metadata.
 126  		//
 127  		// See: https://techdocs.akamai.com/edge-dns/reference/get-zone
 128  		GetZone(context.Context, GetZoneRequest) (*GetZoneResponse, error)
 129  		//GetChangeList retrieves Zone changelist.
 130  		//
 131  		// See: https://techdocs.akamai.com/edge-dns/reference/get-changelists-zone
 132  		GetChangeList(context.Context, GetChangeListRequest) (*GetChangeListResponse, error)
 133  		// GetMasterZoneFile retrieves master zone file.
 134  		//
 135  		// See: https://techdocs.akamai.com/edge-dns/reference/get-zones-zone-zone-file
 136  		GetMasterZoneFile(context.Context, GetMasterZoneFileRequest) (string, error)
 137  		// PostMasterZoneFile updates master zone file.
 138  		//
 139  		// See: https://techdocs.akamai.com/edge-dns/reference/post-zones-zone-zone-file
 140  		PostMasterZoneFile(context.Context, PostMasterZoneFileRequest) error
 141  		// CreateZone creates new zone.
 142  		//
 143  		// See: https://techdocs.akamai.com/edge-dns/reference/post-zone
 144  		CreateZone(context.Context, CreateZoneRequest) error
 145  		// SaveChangeList creates a new Change List based on the most recent version of a zone.
 146  		//
 147  		// See: https://techdocs.akamai.com/edge-dns/reference/post-changelists
 148  		SaveChangeList(context.Context, SaveChangeListRequest) error
 149  		// SubmitChangeList submits changelist for the Zone to create default NS SOA records.
 150  		//
 151  		// See: https://techdocs.akamai.com/edge-dns/reference/post-changelists-zone-submit
 152  		SubmitChangeList(context.Context, SubmitChangeListRequest) error
 153  		// UpdateZone updates zone.
 154  		//
 155  		// See: https://techdocs.akamai.com/edge-dns/reference/put-zone
 156  		UpdateZone(context.Context, UpdateZoneRequest) error
 157  
 158  		// GetZoneNames retrieves a list of a zone's record names.
 159  		//
 160  		// See: https://techdocs.akamai.com/edge-dns/reference/get-zone-names
 161  		GetZoneNames(context.Context, GetZoneNamesRequest) (*GetZoneNamesResponse, error)
 162  		// GetZoneNameTypes retrieves a zone name's record types.
 163  		//
 164  		// See: https://techdocs.akamai.com/edge-dns/reference/get-zone-name-types
 165  		GetZoneNameTypes(context.Context, GetZoneNameTypesRequest) (*GetZoneNameTypesResponse, error)
 166  		// CreateBulkZones submits create bulk zone request.
 167  		//
 168  		// See: https://techdocs.akamai.com/edge-dns/reference/post-zones-create-requests
 169  		CreateBulkZones(context.Context, CreateBulkZonesRequest) (*CreateBulkZonesResponse, error)
 170  		// DeleteBulkZones submits delete bulk zone request.
 171  		//
 172  		// See: https://techdocs.akamai.com/edge-dns/reference/post-zones-delete-requests
 173  		DeleteBulkZones(context.Context, DeleteBulkZonesRequest) (*DeleteBulkZonesResponse, error)
 174  		// GetBulkZoneCreateStatus retrieves submit request status.
 175  		//
 176  		// See: https://techdocs.akamai.com/edge-dns/reference/get-zones-create-requests-requestid
 177  		GetBulkZoneCreateStatus(context.Context, GetBulkZoneCreateStatusRequest) (*GetBulkZoneCreateStatusResponse, error)
 178  		//GetBulkZoneDeleteStatus retrieves submit request status.
 179  		//
 180  		// See: https://techdocs.akamai.com/edge-dns/reference/get-zones-delete-requests-requestid
 181  		GetBulkZoneDeleteStatus(context.Context, GetBulkZoneDeleteStatusRequest) (*GetBulkZoneDeleteStatusResponse, error)
 182  		// GetBulkZoneCreateResult retrieves create request result.
 183  		//
 184  		// See: https://techdocs.akamai.com/edge-dns/reference/get-zones-create-requests-requestid-result
 185  		GetBulkZoneCreateResult(ctx context.Context, request GetBulkZoneCreateResultRequest) (*GetBulkZoneCreateResultResponse, error)
 186  		// GetBulkZoneDeleteResult retrieves delete request result.
 187  		//
 188  		// See: https://techdocs.akamai.com/edge-dns/reference/get-zones-delete-requests-requestid-result
 189  		GetBulkZoneDeleteResult(context.Context, GetBulkZoneDeleteResultRequest) (*GetBulkZoneDeleteResultResponse, error)
 190  		// GetZonesDNSSecStatus returns the current DNSSEC status for one or more zones.
 191  		//
 192  		// See: https://techdocs.akamai.com/edge-dns/reference/post-zones-dns-sec-status
 193  		GetZonesDNSSecStatus(context.Context, GetZonesDNSSecStatusRequest) (*GetZonesDNSSecStatusResponse, error)
 194  	}
 195  
 196  	dns struct {
 197  		session.Session
 198  	}
 199  
 200  	// Option defines a DNS option
 201  	Option func(*dns)
 202  
 203  	// ClientFunc is a dns client new method, this can used for mocking
 204  	ClientFunc func(sess session.Session, opts ...Option) DNS
 205  )
 206  
 207  // Client returns a new dns Client instance with the specified controller
 208  func Client(sess session.Session, opts ...Option) DNS {
 209  	d := &dns{
 210  		Session: sess,
 211  	}
 212  
 213  	for _, opt := range opts {
 214  		opt(d)
 215  	}
 216  	return d
 217  }
 218  
 219  // Exec overrides the session.Exec to add dns options
 220  func (d *dns) Exec(r *http.Request, out interface{}, in ...interface{}) (*http.Response, error) {
 221  	return d.Session.Exec(r, out, in...)
 222  }
 223