mirror of
https://github.com/go-acme/lego
synced 2026-03-14 22:45:48 +01:00
wip: remove previous implementation
This commit is contained in:
parent
20e269dd30
commit
2371ed37cd
3 changed files with 5 additions and 163 deletions
|
|
@ -134,7 +134,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
|
|||
return fmt.Errorf("bluecatv2: %w", err)
|
||||
}
|
||||
|
||||
zone, err := d.findZoneAlt(ctx, info.EffectiveFQDN)
|
||||
zone, err := d.findZone(ctx, info.EffectiveFQDN)
|
||||
if err != nil {
|
||||
return fmt.Errorf("bluecatv2: %w", err)
|
||||
}
|
||||
|
|
@ -221,9 +221,10 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
|
|||
return d.config.PropagationTimeout, d.config.PollingInterval
|
||||
}
|
||||
|
||||
func (d *DNSProvider) findZoneAlt(ctx context.Context, fqdn string) (*internal.ZoneResource, error) {
|
||||
func (d *DNSProvider) findZone(ctx context.Context, fqdn string) (*internal.ZoneResource, error) {
|
||||
for name := range dns01.UnFqdnDomainsSeq(fqdn) {
|
||||
opts := &internal.CollectionOptions{
|
||||
Fields: "id,absoluteName,configuration.id,configuration.name,view.id,view.name",
|
||||
Filter: internal.And(
|
||||
internal.Eq("absoluteName", name),
|
||||
internal.Eq("configuration.name", d.config.ConfigName),
|
||||
|
|
@ -246,90 +247,3 @@ func (d *DNSProvider) findZoneAlt(ctx context.Context, fqdn string) (*internal.Z
|
|||
|
||||
return nil, fmt.Errorf("no zone found for fqdn: %s", fqdn)
|
||||
}
|
||||
|
||||
func (d *DNSProvider) findZone(ctx context.Context, fqdn string) (*internal.ZoneResource, error) {
|
||||
configuration, err := d.findConfiguration(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
view, err := d.findConfigurationView(ctx, configuration.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
zone, err := d.findViewZone(ctx, view.ID, fqdn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return zone, nil
|
||||
}
|
||||
|
||||
func (d *DNSProvider) findConfiguration(ctx context.Context) (*internal.CommonResource, error) {
|
||||
options := internal.CollectionOptions{
|
||||
Filter: internal.Eq("name", d.config.ConfigName).String(),
|
||||
}
|
||||
|
||||
configurations, err := d.client.RetrieveConfigurations(ctx, &options)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("retrieve configurations: %w", err)
|
||||
}
|
||||
|
||||
if len(configurations) == 0 {
|
||||
return nil, fmt.Errorf("zero configuration found with name: %s", d.config.ConfigName)
|
||||
}
|
||||
|
||||
for _, configuration := range configurations {
|
||||
if configuration.Name == d.config.ConfigName {
|
||||
return &configuration, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("no configuration found with name: %s", d.config.ConfigName)
|
||||
}
|
||||
|
||||
func (d *DNSProvider) findConfigurationView(ctx context.Context, configurationID int64) (*internal.CommonResource, error) {
|
||||
options := internal.CollectionOptions{
|
||||
Filter: internal.Eq("name", d.config.ViewName).String(),
|
||||
}
|
||||
|
||||
views, err := d.client.RetrieveConfigurationViews(ctx, configurationID, &options)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("retrieve views: %w", err)
|
||||
}
|
||||
|
||||
if len(views) == 0 {
|
||||
return nil, fmt.Errorf("zero view found with name: %s", d.config.ViewName)
|
||||
}
|
||||
|
||||
for _, view := range views {
|
||||
if view.Name == d.config.ViewName {
|
||||
return &view, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("no view found with name: %s", d.config.ViewName)
|
||||
}
|
||||
|
||||
func (d *DNSProvider) findViewZone(ctx context.Context, viewID int64, fqdn string) (*internal.ZoneResource, error) {
|
||||
for name := range dns01.UnFqdnDomainsSeq(fqdn) {
|
||||
options := internal.CollectionOptions{
|
||||
Filter: internal.Eq("absoluteName", name).String(),
|
||||
}
|
||||
|
||||
zones, err := d.client.RetrieveViewZones(ctx, viewID, &options)
|
||||
if err != nil {
|
||||
// TODO(ldez) maybe add a log in v5.
|
||||
continue
|
||||
}
|
||||
|
||||
for _, zone := range zones {
|
||||
if zone.AbsoluteName == name {
|
||||
return &zone, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("no zone found for fqdn: %s", fqdn)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -264,78 +264,6 @@ func mockBuilder() *servermock.Builder[*DNSProvider] {
|
|||
}
|
||||
|
||||
func TestDNSProvider_Present(t *testing.T) {
|
||||
t.Skip("wip on alt")
|
||||
|
||||
provider := mockBuilder().
|
||||
Route("POST /api/v2/sessions",
|
||||
servermock.ResponseFromInternal("postSession.json"),
|
||||
servermock.CheckRequestJSONBodyFromInternal("postSession-request.json"),
|
||||
).
|
||||
Route("GET /api/v2/configurations",
|
||||
servermock.ResponseFromInternal("configurations.json"),
|
||||
servermock.CheckQueryParameter().Strict().
|
||||
With("filter", "name:eq('myConfiguration')"),
|
||||
).
|
||||
Route("GET /api/v2/configurations/12345/views",
|
||||
servermock.ResponseFromInternal("views.json"),
|
||||
servermock.CheckQueryParameter().Strict().
|
||||
With("filter", "name:eq('myView')"),
|
||||
).
|
||||
Route("GET /api/v2/views/12345/zones",
|
||||
http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||
filter := req.URL.Query().Get("filter")
|
||||
|
||||
if filter == internal.Eq("absoluteName", "example.com").String() {
|
||||
servermock.ResponseFromInternal("zones.json").ServeHTTP(rw, req)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
servermock.ResponseFromInternal("error.json").
|
||||
WithStatusCode(http.StatusNotFound).ServeHTTP(rw, req)
|
||||
}),
|
||||
).
|
||||
Route("POST /api/v2/zones/12345/resourceRecords",
|
||||
servermock.ResponseFromInternal("postZoneResourceRecord.json"),
|
||||
servermock.CheckRequestJSONBodyFromInternal("postZoneResourceRecord-request.json"),
|
||||
).
|
||||
Route("POST /api/v2/zones/12345/deployments",
|
||||
servermock.ResponseFromInternal("postZoneDeployment.json").
|
||||
WithStatusCode(http.StatusCreated),
|
||||
servermock.CheckRequestJSONBodyFromInternal("postZoneDeployment-request.json"),
|
||||
).
|
||||
Build(t)
|
||||
|
||||
err := provider.Present("example.com", "abc", "123d==")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestDNSProvider_CleanUp(t *testing.T) {
|
||||
t.Skip("wip on alt")
|
||||
|
||||
provider := mockBuilder().
|
||||
Route("POST /api/v2/sessions",
|
||||
servermock.ResponseFromInternal("postSession.json"),
|
||||
servermock.CheckRequestJSONBodyFromInternal("postSession-request.json"),
|
||||
).
|
||||
Route("DELETE /api/v2/resourceRecords/12345",
|
||||
servermock.ResponseFromInternal("deleteResourceRecord.json"),
|
||||
).
|
||||
Route("POST /api/v2/zones/456789/deployments",
|
||||
servermock.ResponseFromInternal("postZoneDeployment.json").
|
||||
WithStatusCode(http.StatusCreated),
|
||||
servermock.CheckRequestJSONBodyFromInternal("postZoneDeployment-request.json"),
|
||||
).
|
||||
Build(t)
|
||||
|
||||
provider.zoneIDs["abc"] = 456789
|
||||
provider.recordIDs["abc"] = 12345
|
||||
|
||||
err := provider.CleanUp("example.com", "abc", "123d==")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestDNSProvider_Present_alt(t *testing.T) {
|
||||
provider := mockBuilder().
|
||||
Route("POST /api/v2/sessions",
|
||||
servermock.ResponseFromInternal("postSession.json"),
|
||||
|
|
@ -380,7 +308,7 @@ func TestDNSProvider_Present_alt(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestDNSProvider_CleanUp_alt(t *testing.T) {
|
||||
func TestDNSProvider_CleanUp(t *testing.T) {
|
||||
provider := mockBuilder().
|
||||
Route("POST /api/v2/sessions",
|
||||
servermock.ResponseFromInternal("postSession.json"),
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ type Collection[T any] struct {
|
|||
}
|
||||
|
||||
type CollectionOptions struct {
|
||||
// https://docs.bluecatnetworks.com/r/Address-Manager-RESTful-v2-API-Guide/Referencing-fields/9.6.0
|
||||
// https://docs.bluecatnetworks.com/r/Address-Manager-RESTful-v2-API-Guide/Fields/9.6.0
|
||||
Fields string `url:"fields,omitempty"`
|
||||
|
||||
// https://docs.bluecatnetworks.com/r/Address-Manager-RESTful-v2-API-Guide/Pagination/9.6.0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue