-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: DNS secondary zones and zone files (#458)
* implement dns secondary zones functionalities * refactor to avoid cyclic imports * add completer pkg and zone files implementation * enable silence usage * add bats tests * make fmt * make docs * add secondary zone records list * update changelog
- Loading branch information
Showing
52 changed files
with
1,831 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package completer | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ionos-cloud/ionosctl/v6/internal/client" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/completions" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/config" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/constants" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/printer/json2table" | ||
"github.com/ionos-cloud/ionosctl/v6/internal/printer/json2table/jsonpaths" | ||
"github.com/ionos-cloud/ionosctl/v6/pkg/functional" | ||
|
||
"github.com/ionos-cloud/sdk-go-dns" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func SecondaryZonesIDs() []string { | ||
// Hack to enforce the dns-level flag default for API URL on the completions too | ||
if url := config.GetServerUrl(); url == constants.DefaultApiURL { | ||
viper.Set(constants.ArgServerUrl, "") | ||
} | ||
|
||
secondaryZones, _, err := client.Must().DnsClient.SecondaryZonesApi.SecondaryzonesGet(context.Background()).Execute() | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
secondaryZonesConverted, err := json2table.ConvertJSONToTable("items", jsonpaths.DnsSecondaryZone, secondaryZones) | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
return completions.NewCompleter( | ||
secondaryZonesConverted, "Id", | ||
).AddInfo("Name").AddInfo("State", "(%v)").ToString() | ||
} | ||
|
||
// Zones returns all zones matching the given filters | ||
func Zones(fs ...Filter) (ionoscloud.ZoneReadList, error) { | ||
// Hack to enforce the dns-level flag default for API URL on the completions too | ||
if url := config.GetServerUrl(); url == constants.DefaultApiURL { | ||
viper.Set(constants.ArgServerUrl, "") | ||
} | ||
|
||
req := client.Must().DnsClient.ZonesApi.ZonesGet(context.Background()) | ||
|
||
for _, f := range fs { | ||
var err error | ||
req, err = f(req) | ||
if err != nil { | ||
return ionoscloud.ZoneReadList{}, err | ||
} | ||
} | ||
|
||
ls, _, err := req.Execute() | ||
if err != nil { | ||
return ionoscloud.ZoneReadList{}, err | ||
} | ||
return ls, nil | ||
} | ||
|
||
func ZonesProperty[V any](f func(ionoscloud.ZoneRead) V, fs ...Filter) []V { | ||
recs, err := Zones(fs...) | ||
if err != nil { | ||
return nil | ||
} | ||
return functional.Map(*recs.Items, f) | ||
} | ||
|
||
type Filter func(request ionoscloud.ApiZonesGetRequest) (ionoscloud.ApiZonesGetRequest, error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.