- Move Server/Domain/DNSRecord/Bucket/StorageInstance/CDNInstance/Order/Error structs to internal/model/ - Provider interfaces now reference model.* types - Rainyun provider implementations import model package for data types - CLI commands updated to use model.DNSRecord directly Separates pure data structures from service contract interfaces, following hexagonal architecture: models (entities) live independently from ports (provider interfaces) and adapters (rainyun/* implementations).
101 lines
2.5 KiB
Go
101 lines
2.5 KiB
Go
package domain
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.yoresee.cc/nightstar/ry/internal/model"
|
|
"git.yoresee.cc/nightstar/ry/internal/output"
|
|
"git.yoresee.cc/nightstar/ry/internal/provider"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func Cmd(prov *provider.Provider, out **output.Printer) *cobra.Command {
|
|
domainCmd := &cobra.Command{
|
|
Use: "domain",
|
|
Short: "Manage domains",
|
|
}
|
|
|
|
domainListCmd := &cobra.Command{
|
|
Use: "list",
|
|
Short: "List domains",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
svc := (*prov).Domain()
|
|
if svc == nil {
|
|
return fmt.Errorf("domain management not supported by current provider")
|
|
}
|
|
domains, err := svc.List(cmd.Context())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return (*out).Print(domains)
|
|
},
|
|
}
|
|
|
|
dnsCmd := &cobra.Command{
|
|
Use: "dns <domain>",
|
|
Short: "Manage DNS records",
|
|
Args: cobra.MinimumNArgs(1),
|
|
}
|
|
|
|
dnsListCmd := &cobra.Command{
|
|
Use: "list",
|
|
Short: "List DNS records",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
svc := (*prov).Domain()
|
|
if svc == nil {
|
|
return fmt.Errorf("domain management not supported")
|
|
}
|
|
records, err := svc.DNSList(cmd.Context(), args[0])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return (*out).Print(records)
|
|
},
|
|
}
|
|
|
|
dnsAddCmd := &cobra.Command{
|
|
Use: "add",
|
|
Short: "Add a DNS record",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
svc := (*prov).Domain()
|
|
if svc == nil {
|
|
return fmt.Errorf("domain management not supported")
|
|
}
|
|
recType, _ := cmd.Flags().GetString("type")
|
|
name, _ := cmd.Flags().GetString("name")
|
|
value, _ := cmd.Flags().GetString("value")
|
|
ttl, _ := cmd.Flags().GetInt("ttl")
|
|
return svc.DNSAdd(cmd.Context(), args[0],
|
|
model.DNSRecord{Type: recType, Name: name, Value: value, TTL: ttl})
|
|
},
|
|
}
|
|
|
|
dnsDeleteCmd := &cobra.Command{
|
|
Use: "delete <record-id>",
|
|
Short: "Delete a DNS record",
|
|
Args: cobra.ExactArgs(2),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
svc := (*prov).Domain()
|
|
if svc == nil {
|
|
return fmt.Errorf("domain management not supported")
|
|
}
|
|
return svc.DNSDelete(cmd.Context(), args[0], args[1])
|
|
},
|
|
}
|
|
|
|
dnsAddCmd.Flags().String("type", "A", "Record type (A, CNAME, TXT)")
|
|
dnsAddCmd.Flags().String("name", "@", "Record name")
|
|
dnsAddCmd.Flags().String("value", "", "Record value")
|
|
dnsAddCmd.Flags().Int("ttl", 600, "TTL in seconds")
|
|
dnsAddCmd.MarkFlagRequired("value")
|
|
|
|
dnsCmd.AddCommand(dnsListCmd)
|
|
dnsCmd.AddCommand(dnsAddCmd)
|
|
dnsCmd.AddCommand(dnsDeleteCmd)
|
|
domainCmd.AddCommand(domainListCmd)
|
|
domainCmd.AddCommand(dnsCmd)
|
|
|
|
return domainCmd
|
|
}
|