mirror of
https://github.com/psviderski/uncloud.git
synced 2026-10-06 13:18:58 +00:00
1 parent
d1fe23dec0
commit
5fb80e2071
1 file changed
+6
-2
+6
-2
@@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/miekg/dns"
|
||||||
"github.com/psviderski/uncloud/cmd/uc/caddy"
|
"github.com/psviderski/uncloud/cmd/uc/caddy"
|
||||||
"github.com/psviderski/uncloud/internal/cli"
|
"github.com/psviderski/uncloud/internal/cli"
|
||||||
"github.com/psviderski/uncloud/internal/machine/api/pb"
|
"github.com/psviderski/uncloud/internal/machine/api/pb"
|
||||||
@@ -32,14 +33,17 @@ func NewSetCommand() *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func set(ctx context.Context, uncli *cli.CLI, name string) error {
|
func set(ctx context.Context, uncli *cli.CLI, name string) error {
|
||||||
|
labels, ok := dns.IsDomainName(name)
|
||||||
|
if !ok || labels < 3 {
|
||||||
|
return fmt.Errorf("domain '%s' is not a valid name", name)
|
||||||
|
}
|
||||||
|
|
||||||
clusterClient, err := uncli.ConnectCluster(ctx)
|
clusterClient, err := uncli.ConnectCluster(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("connect to cluster: %w", err)
|
return fmt.Errorf("connect to cluster: %w", err)
|
||||||
}
|
}
|
||||||
defer clusterClient.Close()
|
defer clusterClient.Close()
|
||||||
|
|
||||||
// need 2 dots normally, and most be domain name.
|
|
||||||
|
|
||||||
domain, err := clusterClient.SetDomain(ctx, &pb.SetDomainRequest{Name: name})
|
domain, err := clusterClient.SetDomain(ctx, &pb.SetDomainRequest{Name: name})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if status.Convert(err).Code() == codes.AlreadyExists {
|
if status.Convert(err).Code() == codes.AlreadyExists {
|
||||||
|
|||||||
Reference in new issue
Block a user