WIP: domain listing with Gandi
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Rethinking the interface already.
This commit is contained in:
32
cli/domain/domain.go
Normal file
32
cli/domain/domain.go
Normal file
@ -0,0 +1,32 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// DomainCommand supports managing DNS entries.
|
||||
var DomainCommand = &cli.Command{
|
||||
Name: "domain",
|
||||
Usage: "Manage domains via 3rd party providers",
|
||||
Aliases: []string{"d"},
|
||||
ArgsUsage: "<domain>",
|
||||
Description: `
|
||||
This command supports managing DNS records via 3rd party providers such as
|
||||
Gandi DNS. It supports listing, creating, updating and removing all types of
|
||||
DNS records that you might need to manage for managing Co-op Cloud apps.
|
||||
|
||||
The following providers are supported:
|
||||
|
||||
Gandi DNS https://www.gandi.net
|
||||
|
||||
Any new provider can be integrated, we welcome change sets. See the underlying
|
||||
DNS library documentation for more. It supports many existing providers and
|
||||
allows to implement new provider support easily.
|
||||
|
||||
https://pkg.go.dev/github.com/libdns/libdns
|
||||
|
||||
`,
|
||||
Subcommands: []*cli.Command{
|
||||
DomainListCommand,
|
||||
},
|
||||
}
|
70
cli/domain/list.go
Normal file
70
cli/domain/list.go
Normal file
@ -0,0 +1,70 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
abraFormatter "coopcloud.tech/abra/cli/formatter"
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
gandiPkg "coopcloud.tech/abra/pkg/dns/gandi"
|
||||
"github.com/libdns/gandi"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// DomainListCommand lists domains.
|
||||
var DomainListCommand = &cli.Command{
|
||||
Name: "list",
|
||||
Usage: "List domains for a server",
|
||||
Aliases: []string{"ls"},
|
||||
ArgsUsage: "<zone>",
|
||||
Flags: []cli.Flag{
|
||||
internal.DNSProviderFlag,
|
||||
},
|
||||
Description: `
|
||||
`,
|
||||
Action: func(c *cli.Context) error {
|
||||
zone := c.Args().First()
|
||||
if zone == "" {
|
||||
internal.ShowSubcommandHelpAndError(c, errors.New("no zone provided"))
|
||||
}
|
||||
|
||||
var err error
|
||||
var provider gandi.Provider
|
||||
switch internal.DNSProvider {
|
||||
case "gandi":
|
||||
provider, err = gandiPkg.New()
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
records, err := provider.GetRecords(c.Context, zone)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
tableCol := []string{"type", "name", "value", "TTL", "priority"}
|
||||
table := abraFormatter.CreateTable(tableCol)
|
||||
|
||||
for _, record := range records {
|
||||
value := record.Value
|
||||
if len(record.Value) > 30 {
|
||||
value = fmt.Sprintf("%s...", record.Value[:30])
|
||||
}
|
||||
|
||||
table.Append([]string{
|
||||
record.Type,
|
||||
record.Name,
|
||||
value,
|
||||
record.TTL.String(),
|
||||
strconv.Itoa(record.Priority),
|
||||
})
|
||||
}
|
||||
|
||||
table.Render()
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
Reference in New Issue
Block a user