poweradmin

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Copyright (c) 2026 Contentways SPDX-License-Identifier: MIT

Copyright (c) 2026 Contentways SPDX-License-Identifier: MIT

Copyright (c) 2026 Contentways SPDX-License-Identifier: MIT

Copyright (c) 2026 Contentways SPDX-License-Identifier: MIT

Copyright (c) 2026 Contentways SPDX-License-Identifier: MIT

Copyright (c) 2026 Contentways SPDX-License-Identifier: MIT

Copyright (c) 2026 Contentways SPDX-License-Identifier: MIT

Copyright (c) 2026 Contentways SPDX-License-Identifier: MIT

Copyright (c) 2026 Contentways SPDX-License-Identifier: MIT

Copyright (c) 2026 Contentways SPDX-License-Identifier: MIT

Copyright (c) 2026 Contentways SPDX-License-Identifier: MIT

Copyright (c) 2026 Contentways SPDX-License-Identifier: MIT

Copyright (c) 2026 Contentways SPDX-License-Identifier: MIT

Copyright (c) 2026 Contentways SPDX-License-Identifier: MIT

Copyright (c) 2026 Contentways SPDX-License-Identifier: MIT

Copyright (c) 2026 Contentways SPDX-License-Identifier: MIT

Copyright (c) 2026 Contentways SPDX-License-Identifier: MIT

Index

Constants

View Source
const Version = "1.1.0"

Version is the current version of the poweradmin-go SDK.

Variables

This section is empty.

Functions

func DefaultBackoff

func DefaultBackoff(attempt int) time.Duration

DefaultBackoff is exponential with ±25% jitter, hard-capped at 10s. attempt 0 → ~100ms, 1 → ~200ms, 2 → ~400ms, 3 → ~800ms, ..., ≤ 10s.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound reports whether err is a 404 Not Found API error.

func RecordToSchema

func RecordToSchema(r Record) schema.Record

func ZoneToSchema

func ZoneToSchema(z Zone) schema.Zone

Types

type APIError

type APIError struct {
	StatusCode int
	Message    string
	Details    string
}

APIError represents an error returned by the Poweradmin API.

func (*APIError) Error

func (e *APIError) Error() string

type Backoff

type Backoff func(attempt int) time.Duration

Backoff returns the delay before the next retry attempt. attempt is the zero-based index of the *next* attempt (0 = first retry).

type BulkRecordOperation

type BulkRecordOperation struct {
	Action   string
	RecordID int
	Name     string
	Type     string
	Content  string
	TTL      int
	Priority int
	Disabled bool
}

BulkRecordOperation represents a single operation in a bulk records request. Action is one of "create", "update", "delete". RecordID is required for update/delete; Name/Type/Content are required for create.

type BulkRecordsResult

type BulkRecordsResult struct {
	Created int
	Updated int
	Deleted int
	Failed  int
	Errors  []string
}

BulkRecordsResult is the outcome of a bulk records call. The API reports per-action counts rather than a single success/failure tally.

type Client

type Client struct {

	// Per-resource clients
	Zone               IZoneClient
	ZoneTemplate       IZoneTemplateClient
	Record             IRecordClient
	RRSet              IRRSetClient
	User               IUserClient
	Group              IGroupClient
	Permission         IPermissionClient
	PermissionTemplate IPermissionTemplateClient
	// contains filtered or unexported fields
}

Client is the Poweradmin API client. Create one via NewClient.

func NewClient

func NewClient(opts ...Option) (*Client, error)

NewClient creates a new Poweradmin API client. At minimum, WithBaseURL and either WithAPIKey or WithBasicAuth must be provided.

type Group

type Group struct {
	ID          int
	Name        string
	Description string
	PermTemplID int
	MemberCount int
	ZoneCount   int
	CreatedAt   string
}

Group represents a Poweradmin user group.

func GroupFromSchema

func GroupFromSchema(s schema.Group) Group

type GroupClient

type GroupClient struct {
	// contains filtered or unexported fields
}

GroupClient provides access to the group-related Poweradmin API endpoints.

func (*GroupClient) AddMember

func (g *GroupClient) AddMember(ctx context.Context, groupID, userID int) (*Response, error)

AddMember adds a user to a group.

func (*GroupClient) AddZone

func (g *GroupClient) AddZone(ctx context.Context, groupID, zoneID int) (*Response, error)

AddZone associates a zone with a group.

func (*GroupClient) All

func (g *GroupClient) All(ctx context.Context) ([]*Group, error)

All returns all [Group]s across all pages.

func (*GroupClient) Create

func (g *GroupClient) Create(ctx context.Context, opts GroupCreateOpts) (int, *Response, error)

Create creates a new Group and returns the new ID.

func (*GroupClient) Delete

func (g *GroupClient) Delete(ctx context.Context, id int) (*Response, error)

Delete deletes the Group with the given ID.

func (*GroupClient) GetByID

func (g *GroupClient) GetByID(ctx context.Context, id int) (*Group, *Response, error)

GetByID returns a single Group by ID.

func (*GroupClient) GetByName

func (g *GroupClient) GetByName(ctx context.Context, name string) (*Group, *Response, error)

GetByName returns a single Group by name. Paginates the list endpoint and matches client-side.

func (*GroupClient) List

func (g *GroupClient) List(ctx context.Context, opts ListOpts) ([]*Group, *Response, error)

List returns one page of [Group]s.

func (*GroupClient) Members

func (g *GroupClient) Members(ctx context.Context, id int) ([]*GroupMember, *Response, error)

Members returns the [GroupMember]s of a group.

func (*GroupClient) RemoveMember

func (g *GroupClient) RemoveMember(ctx context.Context, groupID, userID int) (*Response, error)

RemoveMember removes a user from a group.

func (*GroupClient) RemoveZone

func (g *GroupClient) RemoveZone(ctx context.Context, groupID, zoneID int) (*Response, error)

RemoveZone disassociates a zone from a group.

func (*GroupClient) Update

func (g *GroupClient) Update(ctx context.Context, id int, opts GroupUpdateOpts) (*Group, *Response, error)

Update updates an existing Group and returns the updated state.

func (*GroupClient) Zones

func (g *GroupClient) Zones(ctx context.Context, id int) ([]*GroupZone, *Response, error)

Zones returns the zones associated with a group.

type GroupCreateOpts

type GroupCreateOpts struct {
	Name        string
	Description string
	PermTemplID int
}

GroupCreateOpts configures a group creation request.

type GroupMember

type GroupMember struct {
	UserID   int
	Username string
	JoinedAt string
}

GroupMember represents a member of a group.

func GroupMemberFromSchema

func GroupMemberFromSchema(s schema.GroupMember) GroupMember

type GroupUpdateOpts

type GroupUpdateOpts struct {
	Name        string
	Description *string
}

GroupUpdateOpts configures a group update request. Description is a *string so an empty description can be sent explicitly.

type GroupZone

type GroupZone struct {
	ZoneID   int
	ZoneName string
	ZoneType string
}

GroupZone represents a zone associated with a group.

func GroupZoneFromSchema

func GroupZoneFromSchema(s schema.GroupZone) GroupZone

type IGroupClient

type IGroupClient interface {
	// GetByName returns a single [Group] by name.
	// Paginates the list endpoint and matches client-side.
	GetByName(ctx context.Context, name string) (*Group, *Response, error)
	// GetByID returns a single [Group] by ID.
	GetByID(ctx context.Context, id int) (*Group, *Response, error)
	// List returns one page of [Group]s.
	List(ctx context.Context, opts ListOpts) ([]*Group, *Response, error)
	// All returns all [Group]s across all pages.
	All(ctx context.Context) ([]*Group, error)
	// Create creates a new [Group] and returns the new ID.
	Create(ctx context.Context, opts GroupCreateOpts) (int, *Response, error)
	// Update updates an existing [Group] and returns the updated state.
	Update(ctx context.Context, id int, opts GroupUpdateOpts) (*Group, *Response, error)
	// Delete deletes the [Group] with the given ID.
	Delete(ctx context.Context, id int) (*Response, error)
	// Members returns the [GroupMember]s of a group.
	Members(ctx context.Context, id int) ([]*GroupMember, *Response, error)
	// AddMember adds a user to a group.
	AddMember(ctx context.Context, groupID, userID int) (*Response, error)
	// RemoveMember removes a user from a group.
	RemoveMember(ctx context.Context, groupID, userID int) (*Response, error)
	// Zones returns the zones associated with a group.
	Zones(ctx context.Context, id int) ([]*GroupZone, *Response, error)
	// AddZone associates a zone with a group.
	AddZone(ctx context.Context, groupID, zoneID int) (*Response, error)
	// RemoveZone disassociates a zone from a group.
	RemoveZone(ctx context.Context, groupID, zoneID int) (*Response, error)
}

IGroupClient ...

type IPermissionClient

type IPermissionClient interface {
	// GetByID returns a single [Permission] by ID.
	GetByID(ctx context.Context, id int) (*Permission, *Response, error)
	// List returns one page of [Permission]s.
	List(ctx context.Context, opts ListOpts) ([]*Permission, *Response, error)
	// All returns all [Permission]s across all pages.
	All(ctx context.Context) ([]*Permission, error)
}

IPermissionClient ...

type IPermissionTemplateClient

type IPermissionTemplateClient interface {
	// GetByName returns a single [PermissionTemplate] by name.
	// Falls back to a list scan since there is no dedicated by-name endpoint.
	// Note: list responses do not include the full permission list — call
	// [PermissionTemplateClient.GetByID] on the result to get permissions.
	GetByName(ctx context.Context, name string) (*PermissionTemplate, *Response, error)
	// GetByID returns a single [PermissionTemplate] with its full permission list.
	GetByID(ctx context.Context, id int) (*PermissionTemplate, *Response, error)
	// List returns all [PermissionTemplate]s. The permission list is typically not
	// populated in list responses — use [PermissionTemplateClient.GetByID] for that.
	List(ctx context.Context) ([]*PermissionTemplate, *Response, error)
	// Create creates a new [PermissionTemplate].
	Create(ctx context.Context, opts PermissionTemplateOpts) (*PermissionTemplate, *Response, error)
	// Update updates an existing [PermissionTemplate].
	Update(ctx context.Context, id int, opts PermissionTemplateOpts) (*PermissionTemplate, *Response, error)
	// Delete deletes a [PermissionTemplate].
	Delete(ctx context.Context, id int) (*Response, error)
}

IPermissionTemplateClient ...

type IRRSetClient

type IRRSetClient interface {
	// Get returns a single [RRSet] identified by name and type within a zone.
	Get(ctx context.Context, zoneID int, name, recordType string) (*RRSet, *Response, error)
	// List returns all [RRSet]s in a zone.
	List(ctx context.Context, zoneID int) ([]*RRSet, *Response, error)
	// Upsert creates or replaces an [RRSet] via PUT. The API treats this as an
	// idempotent create-or-update on (name, type) within the zone.
	Upsert(ctx context.Context, zoneID int, opts RRSetUpsertOpts) (*Response, error)
	// Delete deletes the [RRSet] identified by name and type within a zone.
	Delete(ctx context.Context, zoneID int, name, recordType string) (*Response, error)
}

IRRSetClient ...

type IRecordClient

type IRecordClient interface {
	// GetByID returns a single [Record] by zone and record ID.
	GetByID(ctx context.Context, zoneID int, recordID int64) (*Record, *Response, error)
	// List returns one page of [Record]s for the given zone.
	// Use [RecordListOpts] with Type set to filter by record type.
	List(ctx context.Context, zoneID int, opts RecordListOpts) ([]*Record, *Response, error)
	// All returns all [Record]s in a zone across all pages.
	All(ctx context.Context, zoneID int) ([]*Record, error)
	// Create creates a new [Record] in the given zone and returns the new ID.
	Create(ctx context.Context, zoneID int, opts RecordCreateOpts) (int64, *Response, error)
	// Update updates an existing [Record] and returns the updated state.
	Update(ctx context.Context, zoneID int, recordID int64, opts RecordUpdateOpts) (*Record, *Response, error)
	// Delete deletes the [Record] with the given ID.
	Delete(ctx context.Context, zoneID int, recordID int64) (*Response, error)
	// Bulk executes multiple record operations atomically against the given zone.
	Bulk(ctx context.Context, zoneID int, ops []BulkRecordOperation) (*BulkRecordsResult, *Response, error)
}

IRecordClient ...

type IUserClient

type IUserClient interface {
	// GetByName returns a single [User] by username.
	// Paginates the list endpoint server-side and matches client-side; the API
	// has no dedicated username lookup.
	GetByName(ctx context.Context, username string) (*User, *Response, error)
	// GetByID returns a single [User] by ID.
	GetByID(ctx context.Context, id int) (*User, *Response, error)
	// List returns one page of [User]s.
	List(ctx context.Context, opts ListOpts) ([]*User, *Response, error)
	// All returns all [User]s across all pages.
	All(ctx context.Context) ([]*User, error)
	// Create creates a new [User] and returns the new ID.
	Create(ctx context.Context, opts UserCreateOpts) (int, *Response, error)
	// Update updates an existing [User] and returns the updated state.
	Update(ctx context.Context, id int, opts UserUpdateOpts) (*User, *Response, error)
	// Delete deletes the [User] with the given ID.
	Delete(ctx context.Context, id int) (*Response, error)
	// SetPermissionTemplate assigns a permission template to a user via PATCH.
	// This is a partial update; other user fields are untouched.
	SetPermissionTemplate(ctx context.Context, id, permTemplID int) (*Response, error)
}

IUserClient ...

type IZoneClient

type IZoneClient interface {
	// GetByID returns a single [Zone] by its numeric ID.
	GetByID(ctx context.Context, id int) (*Zone, *Response, error)
	// GetByName returns a single [Zone] by its DNS name.
	// Performs a list + linear search across all pages — no dedicated API endpoint exists.
	GetByName(ctx context.Context, name string) (*Zone, *Response, error)
	// List returns one page of [Zone]s.
	// Note: /v2/zones wraps the array under data.zones — unlike the other list
	// endpoints in this API. The wrapper is unmarshalled here so callers see a
	// plain slice.
	List(ctx context.Context, opts ListOpts) ([]*Zone, *Response, error)
	// All returns all [Zone]s across all pages.
	All(ctx context.Context) ([]*Zone, error)
	// Create creates a new [Zone] and returns the new ID.
	// Call [ZoneClient.GetByID] to fetch the full object.
	Create(ctx context.Context, opts ZoneCreateOpts) (int, *Response, error)
	// Update updates an existing [Zone] and returns the updated state.
	Update(ctx context.Context, id int, opts ZoneUpdateOpts) (*Zone, *Response, error)
	// Delete deletes the [Zone] with the given ID.
	Delete(ctx context.Context, id int) (*Response, error)
	// Owners returns all owners of the zone.
	Owners(ctx context.Context, zoneID int) ([]*ZoneOwner, *Response, error)
	// AddOwner adds a single user as owner of the zone.
	AddOwner(ctx context.Context, zoneID, userID int) (*Response, error)
	// AddOwners adds multiple users as owners in a single request.
	AddOwners(ctx context.Context, zoneID int, userIDs []int) (*Response, error)
	// RemoveOwner removes a user from the zone's owners.
	RemoveOwner(ctx context.Context, zoneID, userID int) (*Response, error)
}

IZoneClient ...

type IZoneTemplateClient

type IZoneTemplateClient interface {
	// GetByName returns a single [ZoneTemplate] by name.
	// The template endpoint is not paginated, so this is a single-page scan.
	GetByName(ctx context.Context, name string) (*ZoneTemplate, *Response, error)
	// GetByID returns a single [ZoneTemplate].
	GetByID(ctx context.Context, id int) (*ZoneTemplate, *Response, error)
	// List returns all [ZoneTemplate]s.
	List(ctx context.Context) ([]*ZoneTemplate, *Response, error)
	// Create creates a new [ZoneTemplate].
	Create(ctx context.Context, opts ZoneTemplateCreateOpts) (*ZoneTemplate, *Response, error)
	// Update updates an existing [ZoneTemplate].
	Update(ctx context.Context, id int, opts ZoneTemplateUpdateOpts) (*ZoneTemplate, *Response, error)
	// Delete deletes a [ZoneTemplate].
	Delete(ctx context.Context, id int) (*Response, error)
	// Records returns all records belonging to the template.
	Records(ctx context.Context, templateID int) ([]*ZoneTemplateRecord, *Response, error)
	// GetRecord returns a single template record.
	GetRecord(ctx context.Context, templateID, recordID int) (*ZoneTemplateRecord, *Response, error)
	// CreateRecord adds a record to a template.
	CreateRecord(ctx context.Context, templateID int, opts ZoneTemplateRecordOpts) (*ZoneTemplateRecord, *Response, error)
	// UpdateRecord replaces a template record.
	UpdateRecord(ctx context.Context, templateID, recordID int, opts ZoneTemplateRecordOpts) (*ZoneTemplateRecord, *Response, error)
	// DeleteRecord removes a record from a template.
	DeleteRecord(ctx context.Context, templateID, recordID int) (*Response, error)
}

IZoneTemplateClient ...

type ListOpts

type ListOpts struct {
	Page    int
	PerPage int
}

ListOpts controls pagination for List operations. A zero value requests the API's default page and size.

type Option

type Option func(*Client)

Option configures a Client.

func WithAPIKey

func WithAPIKey(key string) Option

WithAPIKey configures Bearer token / X-API-Key authentication. This is the recommended authentication method.

func WithAPIVersion

func WithAPIVersion(version string) Option

WithAPIVersion overrides the API version prefix (default: "v2").

func WithBaseURL

func WithBaseURL(u string) Option

WithBaseURL sets the base URL of the Poweradmin instance. Trailing slashes are stripped.

poweradmin.WithBaseURL("https://dns.example.com")

func WithBasicAuth

func WithBasicAuth(username, password string) Option

WithBasicAuth configures HTTP basic authentication.

func WithDebugWriter

func WithDebugWriter(w io.Writer) Option

WithDebugWriter enables HTTP request/response logging to w. One line is written per request with method, path, status code, and duration. Suitable destinations: os.Stderr, a *log.Logger via log.Writer(), or any io.Writer your application wires up (e.g. slog backed by a buffer).

func WithHTTPClient

func WithHTTPClient(hc *http.Client) Option

WithHTTPClient replaces the default http.Client. Use this to inject a custom transport, proxy, or test double.

func WithInsecure

func WithInsecure() Option

WithInsecure disables TLS certificate verification. Do not use in production. Clones the existing transport if one is set so other settings are preserved.

func WithRetry

func WithRetry(maxAttempts int) Option

WithRetry enables automatic retry on transient failures (network errors, HTTP 429, and 5xx). maxAttempts is the total number of attempts including the initial one — values < 2 disable retrying. Backoff defaults to DefaultBackoff; override via WithRetryBackoff.

func WithRetryBackoff

func WithRetryBackoff(fn Backoff) Option

WithRetryBackoff sets a custom backoff strategy. Only takes effect if WithRetry has also been called.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the HTTP client timeout (default: 30s).

type Pagination

type Pagination struct {
	Page     int
	PerPage  int
	Total    int
	LastPage int
}

Pagination is the domain-level representation of pagination metadata.

type Permission

type Permission struct {
	ID    int
	Name  string
	Descr string
}

Permission represents a Poweradmin permission.

func PermissionFromSchema

func PermissionFromSchema(s schema.Permission) Permission

type PermissionClient

type PermissionClient struct {
	// contains filtered or unexported fields
}

PermissionClient provides access to the permission-related Poweradmin API endpoints.

func (*PermissionClient) All

func (p *PermissionClient) All(ctx context.Context) ([]*Permission, error)

All returns all [Permission]s across all pages.

func (*PermissionClient) GetByID

func (p *PermissionClient) GetByID(ctx context.Context, id int) (*Permission, *Response, error)

GetByID returns a single Permission by ID.

func (*PermissionClient) List

func (p *PermissionClient) List(ctx context.Context, opts ListOpts) ([]*Permission, *Response, error)

List returns one page of [Permission]s.

type PermissionTemplate

type PermissionTemplate struct {
	ID           int
	Name         string
	Descr        string
	TemplateType string // "user" or "group"
	Permissions  []Permission
}

PermissionTemplate represents a named bundle of permissions that can be assigned to a user or group.

type PermissionTemplateClient

type PermissionTemplateClient struct {
	// contains filtered or unexported fields
}

PermissionTemplateClient provides access to the permission-template endpoints.

func (*PermissionTemplateClient) Create

Create creates a new PermissionTemplate.

func (*PermissionTemplateClient) Delete

func (c *PermissionTemplateClient) Delete(ctx context.Context, id int) (*Response, error)

Delete deletes a PermissionTemplate.

func (*PermissionTemplateClient) GetByID

GetByID returns a single PermissionTemplate with its full permission list.

func (*PermissionTemplateClient) GetByName

GetByName returns a single PermissionTemplate by name. Falls back to a list scan since there is no dedicated by-name endpoint. Note: list responses do not include the full permission list — call PermissionTemplateClient.GetByID on the result to get permissions.

func (*PermissionTemplateClient) List

List returns all [PermissionTemplate]s. The permission list is typically not populated in list responses — use PermissionTemplateClient.GetByID for that.

func (*PermissionTemplateClient) Update

Update updates an existing PermissionTemplate.

type PermissionTemplateOpts

type PermissionTemplateOpts struct {
	Name         string
	Descr        string
	TemplateType string // "user" (default) or "group"
	Permissions  []int  // permission IDs to assign
}

PermissionTemplateOpts configures a create or update request.

type RRSet

type RRSet struct {
	Name    string
	Type    string
	TTL     int
	Records []RRSetRecord
}

RRSet represents a DNS Resource Record Set. RRSets group all records that share the same name and type within a zone. The Poweradmin API identifies them by (name, type) — there is no numeric ID.

func RRSetFromSchema

func RRSetFromSchema(s schema.RRSet) RRSet

type RRSetClient

type RRSetClient struct {
	// contains filtered or unexported fields
}

RRSetClient provides access to the rrset-related Poweradmin API endpoints.

func (*RRSetClient) Delete

func (r *RRSetClient) Delete(ctx context.Context, zoneID int, name, recordType string) (*Response, error)

Delete deletes the RRSet identified by name and type within a zone.

func (*RRSetClient) Get

func (r *RRSetClient) Get(ctx context.Context, zoneID int, name, recordType string) (*RRSet, *Response, error)

Get returns a single RRSet identified by name and type within a zone.

func (*RRSetClient) List

func (r *RRSetClient) List(ctx context.Context, zoneID int) ([]*RRSet, *Response, error)

List returns all [RRSet]s in a zone.

func (*RRSetClient) Upsert

func (r *RRSetClient) Upsert(ctx context.Context, zoneID int, opts RRSetUpsertOpts) (*Response, error)

Upsert creates or replaces an RRSet via PUT. The API treats this as an idempotent create-or-update on (name, type) within the zone.

type RRSetRecord

type RRSetRecord struct {
	Content  string
	Priority int
	Disabled bool
}

RRSetRecord is one entry within an RRSet.

type RRSetUpsertOpts

type RRSetUpsertOpts struct {
	Name    string
	Type    string
	TTL     int
	Records []RRSetRecord
}

RRSetUpsertOpts configures a PUT request that creates or replaces an RRSet.

type Record

type Record struct {
	ID       int64
	ZoneID   int64
	Name     string
	Type     string
	Content  string
	TTL      int
	Priority int
	Disabled bool
	Auth     bool // authoritative flag (managed by PowerDNS)
}

Record represents a DNS record in Poweradmin.

func RecordFromSchema

func RecordFromSchema(s schema.Record) Record

type RecordClient

type RecordClient struct {
	// contains filtered or unexported fields
}

RecordClient provides access to the record-related Poweradmin API endpoints.

func (*RecordClient) All

func (r *RecordClient) All(ctx context.Context, zoneID int) ([]*Record, error)

All returns all [Record]s in a zone across all pages.

func (*RecordClient) Bulk

Bulk executes multiple record operations atomically against the given zone.

func (*RecordClient) Create

func (r *RecordClient) Create(ctx context.Context, zoneID int, opts RecordCreateOpts) (int64, *Response, error)

Create creates a new Record in the given zone and returns the new ID.

func (*RecordClient) Delete

func (r *RecordClient) Delete(ctx context.Context, zoneID int, recordID int64) (*Response, error)

Delete deletes the Record with the given ID.

func (*RecordClient) GetByID

func (r *RecordClient) GetByID(ctx context.Context, zoneID int, recordID int64) (*Record, *Response, error)

GetByID returns a single Record by zone and record ID.

func (*RecordClient) List

func (r *RecordClient) List(ctx context.Context, zoneID int, opts RecordListOpts) ([]*Record, *Response, error)

List returns one page of [Record]s for the given zone. Use RecordListOpts with Type set to filter by record type.

func (*RecordClient) Update

func (r *RecordClient) Update(ctx context.Context, zoneID int, recordID int64, opts RecordUpdateOpts) (*Record, *Response, error)

Update updates an existing Record and returns the updated state.

type RecordCreateOpts

type RecordCreateOpts struct {
	Name      string
	Type      string
	Content   string
	TTL       int
	Priority  int
	Disabled  bool
	CreatePTR bool
}

RecordCreateOpts configures a record creation request.

type RecordListOpts

type RecordListOpts struct {
	ListOpts
	Type string // optional record-type filter (e.g. "A", "MX")
}

RecordListOpts adds a record-type filter on top of the standard pagination options.

type RecordUpdateOpts

type RecordUpdateOpts struct {
	Name     string
	Type     string
	Content  string
	TTL      *int
	Priority *int
	Disabled *bool
}

RecordUpdateOpts configures a record update request. Pointer fields are only sent when non-nil.

type Response

type Response struct {
	*http.Response
	Meta ResponseMeta
}

Response wraps http.Response with parsed metadata extracted from the Poweradmin API envelope (currently: pagination).

type ResponseMeta

type ResponseMeta struct {
	Pagination *Pagination
}

ResponseMeta holds parsed metadata that accompanied an API response.

type User

type User struct {
	ID          int
	Username    string
	Fullname    string
	Email       string
	Description string
	Active      bool
	PermTempl   int
	UseLdap     bool
	IsAdmin     bool
	Permissions []string
	ZoneCount   int
	CreatedAt   string
	UpdatedAt   string
}

User represents a Poweradmin user.

func UserFromSchema

func UserFromSchema(s schema.User) User

type UserClient

type UserClient struct {
	// contains filtered or unexported fields
}

UserClient provides access to the user-related Poweradmin API endpoints.

func (*UserClient) All

func (u *UserClient) All(ctx context.Context) ([]*User, error)

All returns all [User]s across all pages.

func (*UserClient) Create

func (u *UserClient) Create(ctx context.Context, opts UserCreateOpts) (int, *Response, error)

Create creates a new User and returns the new ID.

func (*UserClient) Delete

func (u *UserClient) Delete(ctx context.Context, id int) (*Response, error)

Delete deletes the User with the given ID.

func (*UserClient) GetByID

func (u *UserClient) GetByID(ctx context.Context, id int) (*User, *Response, error)

GetByID returns a single User by ID.

func (*UserClient) GetByName

func (u *UserClient) GetByName(ctx context.Context, username string) (*User, *Response, error)

GetByName returns a single User by username. Paginates the list endpoint server-side and matches client-side; the API has no dedicated username lookup.

func (*UserClient) List

func (u *UserClient) List(ctx context.Context, opts ListOpts) ([]*User, *Response, error)

List returns one page of [User]s.

func (*UserClient) SetPermissionTemplate

func (u *UserClient) SetPermissionTemplate(ctx context.Context, id, permTemplID int) (*Response, error)

SetPermissionTemplate assigns a permission template to a user via PATCH. This is a partial update; other user fields are untouched.

func (*UserClient) Update

func (u *UserClient) Update(ctx context.Context, id int, opts UserUpdateOpts) (*User, *Response, error)

Update updates an existing User and returns the updated state.

type UserCreateOpts

type UserCreateOpts struct {
	Username    string
	Password    string
	Fullname    string
	Email       string
	Description string
	Active      bool
	PermTempl   int
	UseLdap     bool
}

UserCreateOpts configures a user creation request.

type UserUpdateOpts

type UserUpdateOpts struct {
	Username    string
	Password    string
	Fullname    string
	Email       string
	Description string
	Active      *bool
	PermTempl   int
	UseLdap     *bool
}

UserUpdateOpts configures a user update request.

type Zone

type Zone struct {
	ID           int
	Name         string
	Type         ZoneType
	Masters      string
	Account      string
	Description  string
	SOASerial    int
	DNSSECSigned bool
}

Zone represents a DNS zone in Poweradmin.

func ZoneFromSchema

func ZoneFromSchema(s schema.Zone) Zone

type ZoneClient

type ZoneClient struct {
	// contains filtered or unexported fields
}

ZoneClient provides access to the zone-related Poweradmin API endpoints.

func (*ZoneClient) AddOwner

func (z *ZoneClient) AddOwner(ctx context.Context, zoneID, userID int) (*Response, error)

AddOwner adds a single user as owner of the zone.

func (*ZoneClient) AddOwners

func (z *ZoneClient) AddOwners(ctx context.Context, zoneID int, userIDs []int) (*Response, error)

AddOwners adds multiple users as owners in a single request.

func (*ZoneClient) All

func (z *ZoneClient) All(ctx context.Context) ([]*Zone, error)

All returns all [Zone]s across all pages.

func (*ZoneClient) Create

func (z *ZoneClient) Create(ctx context.Context, opts ZoneCreateOpts) (int, *Response, error)

Create creates a new Zone and returns the new ID. Call ZoneClient.GetByID to fetch the full object.

func (*ZoneClient) Delete

func (z *ZoneClient) Delete(ctx context.Context, id int) (*Response, error)

Delete deletes the Zone with the given ID.

func (*ZoneClient) GetByID

func (z *ZoneClient) GetByID(ctx context.Context, id int) (*Zone, *Response, error)

GetByID returns a single Zone by its numeric ID.

func (*ZoneClient) GetByName

func (z *ZoneClient) GetByName(ctx context.Context, name string) (*Zone, *Response, error)

GetByName returns a single Zone by its DNS name. Performs a list + linear search across all pages — no dedicated API endpoint exists.

func (*ZoneClient) List

func (z *ZoneClient) List(ctx context.Context, opts ListOpts) ([]*Zone, *Response, error)

List returns one page of [Zone]s. Note: /v2/zones wraps the array under data.zones — unlike the other list endpoints in this API. The wrapper is unmarshalled here so callers see a plain slice.

func (*ZoneClient) Owners

func (z *ZoneClient) Owners(ctx context.Context, zoneID int) ([]*ZoneOwner, *Response, error)

Owners returns all owners of the zone.

func (*ZoneClient) RemoveOwner

func (z *ZoneClient) RemoveOwner(ctx context.Context, zoneID, userID int) (*Response, error)

RemoveOwner removes a user from the zone's owners.

func (*ZoneClient) Update

func (z *ZoneClient) Update(ctx context.Context, id int, opts ZoneUpdateOpts) (*Zone, *Response, error)

Update updates an existing Zone and returns the updated state.

type ZoneCreateOpts

type ZoneCreateOpts struct {
	Name        string
	Type        ZoneType
	Masters     string
	Account     string
	Description string
	Template    string
}

ZoneCreateOpts configures a zone creation request.

type ZoneOwner

type ZoneOwner struct {
	UserID   int
	Username string
	Fullname string
}

ZoneOwner represents a user who owns a zone.

type ZoneTemplate

type ZoneTemplate struct {
	ID          int
	Name        string
	Description string
	Owner       int
	IsGlobal    bool
	ZonesLinked int
}

ZoneTemplate represents a Poweradmin zone template.

type ZoneTemplateClient

type ZoneTemplateClient struct {
	// contains filtered or unexported fields
}

ZoneTemplateClient provides access to the zone-template endpoints.

func (*ZoneTemplateClient) Create

Create creates a new ZoneTemplate.

func (*ZoneTemplateClient) CreateRecord

func (c *ZoneTemplateClient) CreateRecord(ctx context.Context, templateID int, opts ZoneTemplateRecordOpts) (*ZoneTemplateRecord, *Response, error)

CreateRecord adds a record to a template.

func (*ZoneTemplateClient) Delete

func (c *ZoneTemplateClient) Delete(ctx context.Context, id int) (*Response, error)

Delete deletes a ZoneTemplate.

func (*ZoneTemplateClient) DeleteRecord

func (c *ZoneTemplateClient) DeleteRecord(ctx context.Context, templateID, recordID int) (*Response, error)

DeleteRecord removes a record from a template.

func (*ZoneTemplateClient) GetByID

func (c *ZoneTemplateClient) GetByID(ctx context.Context, id int) (*ZoneTemplate, *Response, error)

GetByID returns a single ZoneTemplate.

func (*ZoneTemplateClient) GetByName

func (c *ZoneTemplateClient) GetByName(ctx context.Context, name string) (*ZoneTemplate, *Response, error)

GetByName returns a single ZoneTemplate by name. The template endpoint is not paginated, so this is a single-page scan.

func (*ZoneTemplateClient) GetRecord

func (c *ZoneTemplateClient) GetRecord(ctx context.Context, templateID, recordID int) (*ZoneTemplateRecord, *Response, error)

GetRecord returns a single template record.

func (*ZoneTemplateClient) List

List returns all [ZoneTemplate]s.

func (*ZoneTemplateClient) Records

func (c *ZoneTemplateClient) Records(ctx context.Context, templateID int) ([]*ZoneTemplateRecord, *Response, error)

Records returns all records belonging to the template.

func (*ZoneTemplateClient) Update

Update updates an existing ZoneTemplate.

func (*ZoneTemplateClient) UpdateRecord

func (c *ZoneTemplateClient) UpdateRecord(ctx context.Context, templateID, recordID int, opts ZoneTemplateRecordOpts) (*ZoneTemplateRecord, *Response, error)

UpdateRecord replaces a template record.

type ZoneTemplateCreateOpts

type ZoneTemplateCreateOpts struct {
	Name        string
	Description string
	IsGlobal    bool
}

ZoneTemplateCreateOpts configures a template creation request.

type ZoneTemplateRecord

type ZoneTemplateRecord struct {
	ID       int
	Name     string
	Type     string
	Content  string
	TTL      int
	Priority int
}

ZoneTemplateRecord is a record entry within a ZoneTemplate. Placeholders like [ZONE], [NS1], [SERIAL] are expanded at zone creation time.

type ZoneTemplateRecordOpts

type ZoneTemplateRecordOpts struct {
	Name     string
	Type     string
	Content  string
	TTL      int
	Priority int
}

ZoneTemplateRecordOpts configures a template-record create/update.

type ZoneTemplateUpdateOpts

type ZoneTemplateUpdateOpts struct {
	Name        string
	Description string
	IsGlobal    bool
}

ZoneTemplateUpdateOpts configures a template update.

type ZoneType

type ZoneType string

ZoneType represents the type of a DNS zone.

const (
	ZoneTypeMaster ZoneType = "MASTER"
	ZoneTypeSlave  ZoneType = "SLAVE"
	ZoneTypeNative ZoneType = "NATIVE"
)

type ZoneUpdateOpts

type ZoneUpdateOpts struct {
	Type        *ZoneType
	Masters     *string
	Account     *string
	Description *string
}

ZoneUpdateOpts configures a zone update request. Only non-nil pointer fields are sent to the API.

Directories

Path Synopsis
Package schema contains the raw JSON types that map 1:1 to the Poweradmin API.
Package schema contains the raw JSON types that map 1:1 to the Poweradmin API.

Jump to

Keyboard shortcuts

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