Documentation
¶
Overview ¶
Package czds implements a client to the CZDS REST API using both the documented and undocumented API endpoints.
The CZDS (Centralized Zone Data Service) allows authorized users to access DNS zone files for top-level domains (TLDs). This package provides a complete Go client for downloading zone files, managing access requests, and checking request status.
Basic Usage ¶
Create a client and authenticate:
client := czds.NewClient("username", "password")
ctx := context.Background()
err := client.AuthenticateWithContext(ctx)
if err != nil {
log.Fatal(err)
}
Downloading Zone Files ¶
Download all available zones:
ctx := context.Background()
links, err := client.GetLinksWithContext(ctx)
if err != nil {
log.Fatal(err)
}
for _, link := range links {
err := client.DownloadZoneWithContext(ctx, link, "zones/")
if err != nil {
log.Printf("Failed to download %s: %v", link, err)
}
}
Download a specific zone to a writer:
ctx := context.Background()
var buf bytes.Buffer
bytesWritten, err := client.DownloadZoneToWriterWithContext(ctx, zoneURL, &buf)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Downloaded %d bytes\n", bytesWritten)
Managing Zone Requests ¶
Request access to new zones:
ctx := context.Background()
err := client.RequestTLDsWithContext(ctx, []string{"com", "org"}, "Research purposes")
if err != nil {
log.Fatal(err)
}
Check request status:
ctx := context.Background()
requests, err := client.GetAllRequestsWithContext(ctx, "")
if err != nil {
log.Fatal(err)
}
for _, req := range requests {
fmt.Printf("Zone: %s, Status: %s\n", req.TLD, req.Status)
}
Extend existing requests:
ctx := context.Background()
err := client.ExtendTLDWithContext(ctx, "com")
if err != nil {
log.Fatal(err)
}
Context Support ¶
All operations support context for cancellation and timeouts:
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
err := client.AuthenticateWithContext(ctx)
if err != nil {
log.Fatal(err)
}
links, err := client.GetLinksWithContext(ctx)
if err != nil {
log.Fatal(err)
}
Error Handling ¶
The client automatically handles authentication token refresh during long-running operations. Network errors and API errors are returned as standard Go errors:
if err := client.DownloadZoneWithContext(ctx, url, path); err != nil {
if strings.Contains(err.Error(), "403") {
log.Println("Access denied - check your permissions")
} else if strings.Contains(err.Error(), "network") {
log.Println("Network error - retrying...")
} else {
log.Printf("Unexpected error: %v", err)
}
}
For more detailed examples and API documentation, see the individual function documentation.
Index ¶
- Constants
- type CancelRequestSubmission
- type Client
- func (c *Client) Authenticate() errordeprecated
- func (c *Client) AuthenticateWithContext(ctx context.Context) error
- func (c *Client) CancelRequest(cancel *CancelRequestSubmission) (*RequestsInfo, error)deprecated
- func (c *Client) CancelRequestWithContext(ctx context.Context, cancel *CancelRequestSubmission) (*RequestsInfo, error)
- func (c *Client) DownloadAllRequests(output io.Writer) errordeprecated
- func (c *Client) DownloadAllRequestsWithContext(ctx context.Context, output io.Writer) error
- func (c *Client) DownloadZone(url, destinationPath string) errordeprecated
- func (c *Client) DownloadZoneToWriter(url string, dest io.Writer) (int64, error)deprecated
- func (c *Client) DownloadZoneToWriterWithContext(ctx context.Context, url string, dest io.Writer) (int64, error)
- func (c *Client) DownloadZoneWithContext(ctx context.Context, url, destinationPath string) error
- func (c *Client) ExtendAllTLDs() ([]string, error)deprecated
- func (c *Client) ExtendAllTLDsExcept(except []string) ([]string, error)deprecated
- func (c *Client) ExtendAllTLDsExceptWithContext(ctx context.Context, except []string) ([]string, error)
- func (c *Client) ExtendAllTLDsWithContext(ctx context.Context) ([]string, error)
- func (c *Client) ExtendTLD(tld string) errordeprecated
- func (c *Client) ExtendTLDWithContext(ctx context.Context, tld string) error
- func (c *Client) GetAllRequests(status string) ([]Request, error)deprecated
- func (c *Client) GetAllRequestsWithContext(ctx context.Context, status string) ([]Request, error)
- func (c *Client) GetDownloadInfo(url string) (*DownloadInfo, error)deprecated
- func (c *Client) GetDownloadInfoWithContext(ctx context.Context, url string) (*DownloadInfo, error)
- func (c *Client) GetLinks() ([]string, error)deprecated
- func (c *Client) GetLinksWithContext(ctx context.Context) ([]string, error)
- func (c *Client) GetRequestInfo(requestID string) (*RequestsInfo, error)deprecated
- func (c *Client) GetRequestInfoWithContext(ctx context.Context, requestID string) (*RequestsInfo, error)
- func (c *Client) GetRequests(filter *RequestsFilter) (*RequestsResponse, error)deprecated
- func (c *Client) GetRequestsWithContext(ctx context.Context, filter *RequestsFilter) (*RequestsResponse, error)
- func (c *Client) GetTLDStatus() ([]TLDStatus, error)deprecated
- func (c *Client) GetTLDStatusWithContext(ctx context.Context) ([]TLDStatus, error)
- func (c *Client) GetTerms() (*Terms, error)deprecated
- func (c *Client) GetTermsWithContext(ctx context.Context) (*Terms, error)
- func (c *Client) GetZoneRequestID(zone string) (string, error)deprecated
- func (c *Client) GetZoneRequestIDWithContext(ctx context.Context, zone string) (string, error)
- func (c *Client) RequestAllTLDs(reason string) ([]string, error)deprecated
- func (c *Client) RequestAllTLDsExcept(reason string, except []string) ([]string, error)deprecated
- func (c *Client) RequestAllTLDsExceptWithContext(ctx context.Context, reason string, except []string) ([]string, error)
- func (c *Client) RequestAllTLDsWithContext(ctx context.Context, reason string) ([]string, error)
- func (c *Client) RequestExtension(requestID string) (*RequestsInfo, error)deprecated
- func (c *Client) RequestExtensionWithContext(ctx context.Context, requestID string) (*RequestsInfo, error)
- func (c *Client) RequestTLDs(tlds []string, reason string) errordeprecated
- func (c *Client) RequestTLDsWithContext(ctx context.Context, tlds []string, reason string) error
- func (c *Client) SetLogger(l Logger)
- func (c *Client) SubmitRequest(request *RequestSubmission) errordeprecated
- func (c *Client) SubmitRequestWithContext(ctx context.Context, request *RequestSubmission) error
- type Credentials
- type DownloadInfo
- type FtpDetails
- type HistoryEntry
- type Logger
- type Request
- type RequestSubmission
- type RequestsFilter
- type RequestsInfo
- type RequestsPagination
- type RequestsResponse
- type RequestsSort
- type TLDStatus
- type Terms
Constants ¶
const ( // AuthURL is the production URL endpoint for authentication AuthURL = "https://account-api.icann.org/api/authenticate" // BaseURL is the production URL endpoint for the API BaseURL = "https://czds-api.icann.org" // TestAuthURL is the testing URL endpoint for authentication TestAuthURL = "https://account-api-test.icann.org/api/authenticate" // TestBaseURL is the testing URL endpoint for the API TestBaseURL = "https://czds-api-test.icann.org" )
const ( RequestAll = "" RequestSubmitted = "Submitted" RequestPending = "Pending" RequestApproved = "Approved" RequestDenied = "Denied" RequestRevoked = "Revoked" RequestExpired = "Expired" RequestCanceled = "Canceled" )
Filters for RequestsFilter.Status Statuses for RequestStatus.Status
const ( SortAsc = "asc" SortDesc = "desc" )
Filters for RequestsSort.Direction
const ( SortByTLD = "tld" SortByStatus = "status" SortByLastUpdated = "last_updated" SortByExpiration = "expired" SortByCreated = "created" SortByAutoRenew = "auto_renew" )
Filters for RequestsSort.Field
const ( StatusAvailable = "available" StatusSubmitted = "submitted" StatusPending = "pending" StatusApproved = "approved" StatusDenied = "denied" StatusExpired = "expired" StatusCanceled = "canceled" StatusRevoked = "revoked" )
Status from TLDStatus.CurrentStatus and RequestsInfo.Status
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CancelRequestSubmission ¶ added in v1.0.6
type CancelRequestSubmission struct {
RequestID string `json:"integrationId"` // This is effectively 'requestId'
TLDName string `json:"tldName"`
}
CancelRequestSubmission contains request cancellation arguments passed to CancelRequest()
type Client ¶
type Client struct {
HTTPClient *http.Client
AuthURL string
BaseURL string
// UserAgent is the User-Agent header value sent with HTTP requests.
// If empty, no User-Agent header will be set.
UserAgent string
Creds Credentials
// contains filtered or unexported fields
}
Client stores all session information for czds authentication and manages token renewal
func NewClient ¶
NewClient returns a new instance of the CZDS Client with the default production URLs
func (*Client) Authenticate
deprecated
Authenticate tests the client's credentials and gets an authentication token from the server. Calling this is optional. All other functions will check the auth state on their own first and authenticate if necessary. This function uses a background context.
Deprecated: Use AuthenticateWithContext for context cancellation support.
func (*Client) AuthenticateWithContext ¶ added in v1.3.0
AuthenticateWithContext authenticates the client with CZDS using the provided credentials. It obtains and stores an authentication token that will be used for subsequent API calls. The operation can be cancelled using the provided context.
func (*Client) CancelRequest
deprecated
added in
v1.0.6
func (c *Client) CancelRequest(cancel *CancelRequestSubmission) (*RequestsInfo, error)
CancelRequest cancels a pending zone access request. Only requests in pending status can be cancelled.
Deprecated: Use CancelRequestWithContext for context cancellation support.
func (*Client) CancelRequestWithContext ¶ added in v1.3.0
func (c *Client) CancelRequestWithContext(ctx context.Context, cancel *CancelRequestSubmission) (*RequestsInfo, error)
CancelRequestWithContext cancels a pending zone access request. Only requests in pending status can be cancelled.
func (*Client) DownloadAllRequests
deprecated
DownloadAllRequests downloads a CSV report of all zone requests to the provided writer. This corresponds to the "Download All Requests" button on the CZDS portal.
Deprecated: Use DownloadAllRequestsWithContext for context cancellation support.
func (*Client) DownloadAllRequestsWithContext ¶ added in v1.3.0
DownloadAllRequestsWithContext downloads a CSV report of all zone requests to the provided writer. This corresponds to the "Download All Requests" button on the CZDS portal.
func (*Client) DownloadZone
deprecated
DownloadZone downloads a zone file from the given URL and saves it to the specified file path. The URL should be retrieved from GetLinks(). If an error occurs, any partially downloaded file is removed.
Deprecated: Use DownloadZoneWithContext for context cancellation support.
func (*Client) DownloadZoneToWriter
deprecated
DownloadZoneToWriter downloads a zone file from the given URL and writes it to the provided io.Writer. It returns the number of bytes written and any error encountered.
Deprecated: Use DownloadZoneToWriterWithContext for context cancellation support.
func (*Client) DownloadZoneToWriterWithContext ¶ added in v1.3.0
func (c *Client) DownloadZoneToWriterWithContext(ctx context.Context, url string, dest io.Writer) (int64, error)
DownloadZoneToWriterWithContext downloads a zone file from the given URL and writes it to the provided io.Writer. It returns the number of bytes written and any error encountered. The download can be cancelled using the provided context.
func (*Client) DownloadZoneWithContext ¶ added in v1.3.0
DownloadZoneWithContext downloads a zone file from the given URL and saves it to the specified file path. The operation can be cancelled using the provided context. If an error occurs, any partially downloaded file is removed.
func (*Client) ExtendAllTLDs
deprecated
added in
v1.2.0
func (*Client) ExtendAllTLDsExcept
deprecated
added in
v1.2.12
ExtendAllTLDsExcept requests extensions for all extensible TLDs, excluding any TLDs listed in the except parameter. It returns the list of TLDs for which extensions were requested.
Deprecated: Use ExtendAllTLDsExceptWithContext for context cancellation support.
func (*Client) ExtendAllTLDsExceptWithContext ¶ added in v1.3.0
func (c *Client) ExtendAllTLDsExceptWithContext(ctx context.Context, except []string) ([]string, error)
ExtendAllTLDsExceptWithContext requests extensions for all extensible TLDs, excluding any TLDs listed in the except parameter. It returns the list of TLDs for which extensions were requested.
func (*Client) ExtendAllTLDsWithContext ¶ added in v1.3.0
ExtendAllTLDsWithContext is a helper function to request extensions for all extensible TLDs. It returns the list of TLDs for which extensions were requested.
func (*Client) ExtendTLD
deprecated
added in
v1.2.0
func (*Client) ExtendTLDWithContext ¶ added in v1.3.0
ExtendTLDWithContext is a helper function that requests an extension for the specified TLD. The TLD must have an approved request that is marked as extensible.
func (*Client) GetAllRequests
deprecated
added in
v1.2.0
GetAllRequests returns all zone requests with the specified status. Status should be one of the constant czds.Status* strings. Warning: for a large number of results, may be slow as it handles pagination automatically.
Deprecated: Use GetAllRequestsWithContext for context cancellation support.
func (*Client) GetAllRequestsWithContext ¶ added in v1.3.0
GetAllRequestsWithContext retrieves all zone requests with the specified status. It handles pagination automatically to return the complete list of requests.
func (*Client) GetDownloadInfo
deprecated
func (c *Client) GetDownloadInfo(url string) (*DownloadInfo, error)
GetDownloadInfo retrieves metadata about a zone file download without downloading the file itself. It performs a HEAD request to get information like file size, last modified time, and filename.
Deprecated: Use GetDownloadInfoWithContext for context cancellation support.
func (*Client) GetDownloadInfoWithContext ¶ added in v1.3.0
GetDownloadInfoWithContext retrieves metadata about a zone file download without downloading the file itself. It performs a HEAD request to get information like file size, last modified time, and filename. The operation can be cancelled using the provided context.
func (*Client) GetLinks
deprecated
func (*Client) GetLinksWithContext ¶ added in v1.3.0
GetLinksWithContext retrieves all zone download links available to the authenticated user. It returns a slice of URLs that can be used with the download functions. The operation can be cancelled using the provided context.
func (*Client) GetRequestInfo
deprecated
func (c *Client) GetRequestInfo(requestID string) (*RequestsInfo, error)
GetRequestInfo gets detailed information about a particular request and its timeline. It retrieves comprehensive request details as seen on the CZDS dashboard page "https://czds.icann.org/zone-requests/{ID}".
Deprecated: Use GetRequestInfoWithContext for context cancellation support.
func (*Client) GetRequestInfoWithContext ¶ added in v1.3.0
func (c *Client) GetRequestInfoWithContext(ctx context.Context, requestID string) (*RequestsInfo, error)
GetRequestInfoWithContext retrieves detailed information about a specific zone access request, including its status timeline and history. The operation can be cancelled using the provided context.
func (*Client) GetRequests
deprecated
func (c *Client) GetRequests(filter *RequestsFilter) (*RequestsResponse, error)
GetRequests retrieves zone access requests based on the provided filter criteria. It supports pagination and filtering by status, as seen on the CZDS dashboard page "https://czds.icann.org/zone-requests/all".
Deprecated: Use GetRequestsWithContext for context cancellation support.
func (*Client) GetRequestsWithContext ¶ added in v1.3.0
func (c *Client) GetRequestsWithContext(ctx context.Context, filter *RequestsFilter) (*RequestsResponse, error)
GetRequestsWithContext retrieves zone access requests based on the provided filter criteria. It supports pagination and filtering by status. The operation can be cancelled using the provided context.
func (*Client) GetTLDStatus
deprecated
func (*Client) GetTLDStatusWithContext ¶ added in v1.3.0
GetTLDStatusWithContext retrieves the current status of all TLDs and their availability for requesting. It returns a slice of TLDStatus containing information about each TLD.
func (*Client) GetTerms
deprecated
GetTerms gets the current terms and conditions from the CZDS portal. The terms are retrieved from "https://czds.icann.org/terms-and-conditions" and are required to accept when submitting a new zone access request.
Deprecated: Use GetTermsWithContext for context cancellation support.
func (*Client) GetTermsWithContext ¶ added in v1.3.0
GetTermsWithContext retrieves the current terms and conditions from the CZDS portal. This information is required when submitting new zone access requests.
func (*Client) GetZoneRequestID
deprecated
added in
v1.2.0
func (*Client) GetZoneRequestIDWithContext ¶ added in v1.3.0
GetZoneRequestIDWithContext retrieves the most recent request ID for the specified zone. It searches through paginated results to find the request for the given zone name.
func (*Client) RequestAllTLDs
deprecated
func (*Client) RequestAllTLDsExcept
deprecated
added in
v1.2.12
RequestAllTLDsExcept requests access to all available TLDs with the provided reason, excluding the TLDs listed in the except parameter. It returns the list of TLDs that were requested.
Deprecated: Use RequestAllTLDsExceptWithContext for context cancellation support.
func (*Client) RequestAllTLDsExceptWithContext ¶ added in v1.3.0
func (c *Client) RequestAllTLDsExceptWithContext(ctx context.Context, reason string, except []string) ([]string, error)
RequestAllTLDsExceptWithContext requests access to all available TLDs with the provided reason, excluding the TLDs listed in the except parameter. It returns the list of TLDs that were requested.
func (*Client) RequestAllTLDsWithContext ¶ added in v1.3.0
RequestAllTLDsWithContext is a helper function to request access to all available TLDs with the provided reason. It returns the list of TLDs that were requested.
func (*Client) RequestExtension
deprecated
added in
v1.2.0
func (c *Client) RequestExtension(requestID string) (*RequestsInfo, error)
RequestExtension submits a request to extend access for a zone request. Extensions can only be requested for approved requests expiring within 30 days.
Deprecated: Use RequestExtensionWithContext for context cancellation support.
func (*Client) RequestExtensionWithContext ¶ added in v1.3.0
func (c *Client) RequestExtensionWithContext(ctx context.Context, requestID string) (*RequestsInfo, error)
RequestExtensionWithContext submits a request to extend access for a zone request. Extensions can only be requested for approved requests expiring within 30 days.
func (*Client) RequestTLDs
deprecated
RequestTLDs is a helper function that requests access to the specified TLDs with the provided reason. The TLDs should be marked as available for request from GetTLDStatus(). It automatically retrieves the current terms and conditions before submitting the request.
Deprecated: Use RequestTLDsWithContext for context cancellation support.
func (*Client) RequestTLDsWithContext ¶ added in v1.3.0
RequestTLDsWithContext is a helper function that requests access to the specified TLDs with the provided reason. It automatically retrieves the current terms and conditions before submitting the request.
func (*Client) SetLogger ¶ added in v1.2.9
SetLogger enables verbose printing for most API calls with the provided logger. Defaults to nil/off.
func (*Client) SubmitRequest
deprecated
func (c *Client) SubmitRequest(request *RequestSubmission) error
SubmitRequest submits a new request for access to specified zones. The request must include valid terms and conditions version and reason.
Deprecated: Use SubmitRequestWithContext for context cancellation support.
func (*Client) SubmitRequestWithContext ¶ added in v1.3.0
func (c *Client) SubmitRequestWithContext(ctx context.Context, request *RequestSubmission) error
SubmitRequestWithContext submits a new request for access to specified zones. The request must include valid terms and conditions version and reason.
type Credentials ¶
Credentials used by the czds.Client
func (Credentials) GoString ¶ added in v1.3.0
func (c Credentials) GoString() string
GoString returns a Go-syntax representation with password redacted, used by %#v and %+v formatting.
func (Credentials) String ¶ added in v1.3.0
func (c Credentials) String() string
String returns a string representation of credentials with the password redacted for security.
type DownloadInfo ¶
DownloadInfo contains information from the HEAD request from a DownloadLink
type FtpDetails ¶
type FtpDetails struct {
PrivateDataError bool `json:"privateDataError"`
}
FtpDetails contains FTP information for RequestsInfo.
type HistoryEntry ¶
type HistoryEntry struct {
Timestamp time.Time `json:"timestamp"`
Action string `json:"action"`
Comment string `json:"comment"`
}
HistoryEntry contains a timestamp and description of an action that happened for a RequestsInfo. For example: requested, expired, approved, etc.
type Logger ¶ added in v1.2.9
Logger specifies the methods required for the verbose logger for the API
type Request ¶
type Request struct {
RequestID string `json:"requestId"`
TLD string `json:"tld"`
ULabel string `json:"ulable"` // ULabel contains UTF-8 decoded punycode (API appears to have a typo in the field name)
Status string `json:"status"` // Status should be set to one of the Request* constants
Created time.Time `json:"created"`
LastUpdated time.Time `json:"last_updated"`
Expired time.Time `json:"expired"` // Expired time; epoch 0 means no expiration set
SFTP bool `json:"sftp"`
AutoRenew bool `json:"auto_renew"`
}
Request holds information about a request in RequestsResponse from GetRequests()
type RequestSubmission ¶
type RequestSubmission struct {
AllTLDs bool `json:"allTlds"`
TLDNames []string `json:"tldNames"`
Reason string `json:"reason"`
TcVersion string `json:"tcVersion"` // terms and conditions revision version
AdditionalFTPIps []string `json:"additionalFtfIps,omitempty"`
}
RequestSubmission contains the information required to submit a new request with SubmitRequest()
type RequestsFilter ¶
type RequestsFilter struct {
Status string `json:"status"` // should be set to one of the Request* constants
Filter string `json:"filter"` // zone name search
Pagination RequestsPagination `json:"pagination"`
Sort RequestsSort `json:"sort"`
}
RequestsFilter is used to set what results should be returned by GetRequests
type RequestsInfo ¶
type RequestsInfo struct {
RequestID string `json:"requestId"`
TLD *TLDStatus `json:"tld"`
FtpIps []string `json:"ftpips"`
Status string `json:"status"` // should be set to one of the Status* constants
TcVersion string `json:"tcVersion"`
Created time.Time `json:"created"`
RequestIP string `json:"requestIp"`
Reason string `json:"reason"`
LastUpdated time.Time `json:"last_updated"`
Cancellable bool `json:"cancellable"`
Extensible bool `json:"extensible"`
ExtensionInProcess bool `json:"extensionInProcess"`
AutoRenew bool `json:"auto_renew"`
Expired time.Time `json:"expired"` // Note: epoch 0 means no expiration set.
History []HistoryEntry `json:"history"`
FtpDetails *FtpDetails `json:"ftpDetails"`
PrivateDataError bool `json:"privateDataError"`
}
RequestsInfo contains the detailed information about a particular zone request returned by GetRequestInfo()
type RequestsPagination ¶
RequestsPagination sets the page size and offset for paginated results for RequestsFilter
type RequestsResponse ¶
type RequestsResponse struct {
Requests []Request `json:"requests"`
TotalRequests int64 `json:"totalRequests"`
}
RequestsResponse holds Requests from GetRequests() and total number of requests that match the query but may not be returned due to pagination
type RequestsSort ¶
RequestsSort sets which field and direction the results for the RequestsFilter request should be returned with
type TLDStatus ¶
type TLDStatus struct {
TLD string `json:"tld"`
ULabel string `json:"ulable"` // ULabel contains UTF-8 decoded punycode (API appears to have a typo in the field name)
CurrentStatus string `json:"currentStatus"` // CurrentStatus should be set to one of the Status* constants
SFTP bool `json:"sftp"`
}
TLDStatus is information about a particular TLD returned from GetTLDStatus() or included in RequestsInfo
Directories
¶
| Path | Synopsis |
|---|---|
|
Package main provides the czds command-line tool for interacting with ICANN's Centralized Zone Data Service (CZDS).
|
Package main provides the czds command-line tool for interacting with ICANN's Centralized Zone Data Service (CZDS). |
|
webhook
Package webhook provides a generic HTTP webhook client for batch download approval and notifications.
|
Package webhook provides a generic HTTP webhook client for batch download approval and notifications. |
|
Package jwt defines the JWT types used by the CZDS authentication API.
|
Package jwt defines the JWT types used by the CZDS authentication API. |