Compare commits

..

2 Commits

Author SHA1 Message Date
amery 3d7d74ac6b jpictl: initial env command [WIP]
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-08-21 21:56:07 +00:00
amery 9bfa63a0d9 zones: WriteEnv() [WIP]
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-08-21 21:55:16 +00:00
5 changed files with 36 additions and 48 deletions
+27
View File
@@ -0,0 +1,27 @@
package main
import (
"os"
"github.com/spf13/cobra"
"git.jpi.io/amery/jpictl/pkg/zones"
)
// Command
var envCmd = &cobra.Command{
Use: "env",
Short: "generates environment variables for shell scripts",
RunE: func(_ *cobra.Command, _ []string) error {
m, err := zones.New(cfg.Base, cfg.Domain)
if err != nil {
return err
}
return m.WriteEnv(os.Stdout)
},
}
func init() {
rootCmd.AddCommand(envCmd)
}
+9
View File
@@ -0,0 +1,9 @@
// Package zones abstracts the cluster zones
package zones
import "io"
// WriteEnv generates environment variables for shell scripts
func (*Zones) WriteEnv(io.Writer) error {
return nil
}
-18
View File
@@ -1,9 +1,7 @@
package zones
import (
"net/netip"
"strconv"
"strings"
"sync"
)
@@ -14,8 +12,6 @@ type Machine struct {
zone *Zone
id int
Name string
PublicAddresses []netip.Addr
}
func (m *Machine) String() string {
@@ -42,17 +38,3 @@ func (m *Machine) ID() int {
return m.id
}
// FullName returns the Name of the machine including domain name
func (m *Machine) FullName() string {
if domain := m.zone.zones.domain; domain != "" {
var s = []string{
m.Name,
domain,
}
return strings.Join(s, ".")
}
return m.Name
}
-26
View File
@@ -1,26 +0,0 @@
package zones
import (
"context"
"net/netip"
"time"
)
func (m *Machine) lookupNetIP() ([]netip.Addr, error) {
timeout := 2 * time.Second
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
return m.zone.zones.resolver.LookupNetIP(ctx, "ip", m.FullName())
}
func (m *Machine) updatePublicAddresses() error {
addrs, err := m.lookupNetIP()
if err != nil {
return err
}
m.PublicAddresses = addrs
return nil
}
-4
View File
@@ -43,10 +43,6 @@ func (z *Zone) scan() error {
Name: e.Name(),
}
if err := m.updatePublicAddresses(); err != nil {
return err
}
z.Machines = append(z.Machines, m)
}
}