Files
dns-autoresolver/internal/provider/provider.go
T

39 lines
1.5 KiB
Go

package provider
import (
"context"
"github.com/vasyakrg/dns-autoresolver/internal/diff"
"github.com/vasyakrg/dns-autoresolver/internal/model"
)
// Credentials holds the provider-specific secret. It is stored encrypted and,
// once decrypted, is a provider-defined value — for Selectel a JSON blob with
// the service-user credentials (see selectel.Creds).
type Credentials struct {
Secret string
}
// Zone is a provider-neutral DNS zone reference.
type Zone struct {
ID string
Name string
}
// Provider is implemented per DNS provider (Selectel first).
type Provider interface {
Name() string
ListZones(ctx context.Context, creds Credentials) ([]Zone, error)
GetRecords(ctx context.Context, creds Credentials, zoneID string) ([]model.Record, error)
// ApplyChanges MUST apply cs.Diffs in the order they are given and must
// not reorder or group them by Kind. The caller (service.Apply)
// deliberately places Delete diffs before Add/Update diffs, because some
// providers (e.g. Selectel) reject creating a CNAME on a name where a
// conflicting A record still exists. Implementations should apply diffs
// sequentially in the given order rather than batching by kind.
ApplyChanges(ctx context.Context, creds Credentials, zoneID string, cs diff.Changeset) error
// Validate checks the credentials are usable (e.g. a trial auth), so a
// bad account is rejected at creation time rather than at first import.
Validate(ctx context.Context, creds Credentials) error
}