feat: domain/storage/billing/config cmds + rainyun domain/storage/billing services
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var billingCmd = &cobra.Command{
|
||||
Use: "billing",
|
||||
Short: "Billing and orders",
|
||||
}
|
||||
|
||||
var ordersCmd = &cobra.Command{
|
||||
Use: "orders",
|
||||
Short: "List orders",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
svc := prov.Billing()
|
||||
if svc == nil {
|
||||
return fmt.Errorf("billing not supported by current provider")
|
||||
}
|
||||
orders, err := svc.Orders(cmd.Context())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return out.Print(orders)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
billingCmd.AddCommand(ordersCmd)
|
||||
rootCmd.AddCommand(billingCmd)
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.yoresee.cc/nightstar/ry/internal/config"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var configCmd = &cobra.Command{
|
||||
Use: "config",
|
||||
Short: "Manage ry configuration",
|
||||
}
|
||||
|
||||
var configShowCmd = &cobra.Command{
|
||||
Use: "show",
|
||||
Short: "Show current configuration",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
fmt.Printf("Config file: %s\n", cfgPath)
|
||||
fmt.Printf("Current provider: %s\n", cfg.CurrentProvider)
|
||||
fmt.Printf("Output format: %s\n", cfg.Output)
|
||||
fmt.Println("Providers:")
|
||||
for name, pc := range cfg.Providers {
|
||||
masked := pc.APIKey
|
||||
if len(masked) > 4 {
|
||||
masked = masked[:2] + strings.Repeat("*", len(masked)-4) + masked[len(masked)-2:]
|
||||
}
|
||||
marker := " "
|
||||
if name == cfg.CurrentProvider {
|
||||
marker = "*"
|
||||
}
|
||||
fmt.Printf(" %s %s: api_key=%s\n", marker, name, masked)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var configSetCmd = &cobra.Command{
|
||||
Use: "set <key> <value>",
|
||||
Short: "Set a config value",
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
key, value := args[0], args[1]
|
||||
switch key {
|
||||
case "output":
|
||||
cfg.Output = value
|
||||
default:
|
||||
return fmt.Errorf("unknown config key: %s", key)
|
||||
}
|
||||
if err := config.Save(cfgPath, cfg); err != nil {
|
||||
return fmt.Errorf("save config: %w", err)
|
||||
}
|
||||
fmt.Printf("Set %s = %s\n", key, value)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var configPathCmd = &cobra.Command{
|
||||
Use: "path",
|
||||
Short: "Print config file path",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
fmt.Println(cfgPath)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
configCmd.AddCommand(configShowCmd)
|
||||
configCmd.AddCommand(configSetCmd)
|
||||
configCmd.AddCommand(configPathCmd)
|
||||
rootCmd.AddCommand(configCmd)
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.yoresee.cc/nightstar/ry/internal/provider"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var domainCmd = &cobra.Command{
|
||||
Use: "domain",
|
||||
Short: "Manage domains",
|
||||
}
|
||||
|
||||
var 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)
|
||||
},
|
||||
}
|
||||
|
||||
var dnsCmd = &cobra.Command{
|
||||
Use: "dns <domain>",
|
||||
Short: "Manage DNS records",
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
}
|
||||
|
||||
var 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)
|
||||
},
|
||||
}
|
||||
|
||||
var 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],
|
||||
provider.DNSRecord{Type: recType, Name: name, Value: value, TTL: ttl})
|
||||
},
|
||||
}
|
||||
|
||||
var 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])
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
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)
|
||||
rootCmd.AddCommand(domainCmd)
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var storageCmd = &cobra.Command{
|
||||
Use: "storage",
|
||||
Short: "Manage object storage",
|
||||
}
|
||||
|
||||
var storageListCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List storage instances",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
svc := prov.Storage()
|
||||
if svc == nil {
|
||||
return fmt.Errorf("storage management not supported by current provider")
|
||||
}
|
||||
instances, err := svc.List(cmd.Context())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return out.Print(instances)
|
||||
},
|
||||
}
|
||||
|
||||
var bucketCmd = &cobra.Command{
|
||||
Use: "bucket <instance-id>",
|
||||
Short: "Manage buckets",
|
||||
Args: cobra.ExactArgs(1),
|
||||
}
|
||||
|
||||
var bucketListCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List buckets",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
svc := prov.Storage()
|
||||
if svc == nil {
|
||||
return fmt.Errorf("storage management not supported")
|
||||
}
|
||||
buckets, err := svc.BucketList(cmd.Context(), args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return out.Print(buckets)
|
||||
},
|
||||
}
|
||||
|
||||
var bucketCreateCmd = &cobra.Command{
|
||||
Use: "create <name>",
|
||||
Short: "Create a bucket",
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
svc := prov.Storage()
|
||||
if svc == nil {
|
||||
return fmt.Errorf("storage management not supported")
|
||||
}
|
||||
if err := svc.BucketCreate(cmd.Context(), args[0], args[1]); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Bucket %q created\n", args[1])
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
bucketCmd.AddCommand(bucketListCmd)
|
||||
bucketCmd.AddCommand(bucketCreateCmd)
|
||||
storageCmd.AddCommand(storageListCmd)
|
||||
storageCmd.AddCommand(bucketCmd)
|
||||
rootCmd.AddCommand(storageCmd)
|
||||
}
|
||||
Reference in New Issue
Block a user