feat(provider): интерфейс Provider, Credentials, Zone
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/vasyakrg/dns-autoresolver/internal/diff"
|
||||
"github.com/vasyakrg/dns-autoresolver/internal/model"
|
||||
)
|
||||
|
||||
// Credentials holds the secret used to authenticate against a provider.
|
||||
// For Selectel this is the project-scoped token sent as X-Auth-Token.
|
||||
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(ctx context.Context, creds Credentials, zoneID string, cs diff.Changeset) error
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/vasyakrg/dns-autoresolver/internal/diff"
|
||||
"github.com/vasyakrg/dns-autoresolver/internal/model"
|
||||
)
|
||||
|
||||
// stubProvider проверяет, что интерфейс реализуем.
|
||||
type stubProvider struct{}
|
||||
|
||||
func (stubProvider) Name() string { return "stub" }
|
||||
func (stubProvider) ListZones(context.Context, Credentials) ([]Zone, error) {
|
||||
return []Zone{{ID: "1", Name: "example.com."}}, nil
|
||||
}
|
||||
func (stubProvider) GetRecords(context.Context, Credentials, string) ([]model.Record, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (stubProvider) ApplyChanges(context.Context, Credentials, string, diff.Changeset) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestProviderInterfaceSatisfied(t *testing.T) {
|
||||
var p Provider = stubProvider{}
|
||||
zs, err := p.ListZones(context.Background(), Credentials{Secret: "x"})
|
||||
if err != nil || len(zs) != 1 || zs[0].Name != "example.com." {
|
||||
t.Fatalf("unexpected: %v %v", zs, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user