Compare commits
4 Commits
79d1783401
...
2834326150
| Author | SHA1 | Date | |
|---|---|---|---|
| 2834326150 | |||
| d960f460b3 | |||
| b15f394199 | |||
| f225e15b2c |
@@ -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)
|
||||||
|
}
|
||||||
+22
-2
@@ -3,6 +3,7 @@ package wireguard
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -44,10 +45,29 @@ type PeerConfig struct {
|
|||||||
|
|
||||||
// EndpointAddress is a host:port pair to reach the Peer
|
// EndpointAddress is a host:port pair to reach the Peer
|
||||||
type EndpointAddress struct {
|
type EndpointAddress struct {
|
||||||
Name string
|
Host string
|
||||||
Port uint16
|
Port uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Name returns the first part of a hostname
|
||||||
|
func (ep EndpointAddress) Name() string {
|
||||||
|
before, _, _ := strings.Cut(ep.Host, ".")
|
||||||
|
return before
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ep EndpointAddress) String() string {
|
||||||
|
switch {
|
||||||
|
case ep.Host == "":
|
||||||
|
return ""
|
||||||
|
case ep.Port == 0:
|
||||||
|
return ep.Host
|
||||||
|
case !strings.ContainsRune(ep.Host, ':'):
|
||||||
|
return fmt.Sprintf("%s:%v", ep.Host, ep.Port)
|
||||||
|
default:
|
||||||
|
return fmt.Sprintf("[%s]:%v", ep.Host, ep.Port)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// FromString sets the EndpointAddress from a given "[host]:port"
|
// FromString sets the EndpointAddress from a given "[host]:port"
|
||||||
func (ep *EndpointAddress) FromString(s string) error {
|
func (ep *EndpointAddress) FromString(s string) error {
|
||||||
host, port, err := core.SplitHostPort(s)
|
host, port, err := core.SplitHostPort(s)
|
||||||
@@ -55,7 +75,7 @@ func (ep *EndpointAddress) FromString(s string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ep.Name = host
|
ep.Host = host
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case port != "":
|
case port != "":
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user