Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bd307db0d3 |
+13
-10
@@ -10,18 +10,21 @@ import (
|
|||||||
// WriteEnv generates environment variables for shell scripts
|
// WriteEnv generates environment variables for shell scripts
|
||||||
func (m *Zones) WriteEnv(w io.Writer) error {
|
func (m *Zones) WriteEnv(w io.Writer) error {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
var err error
|
||||||
|
|
||||||
m.writeEnvVarFn(&buf, genEnvZones, "ZONES")
|
m.writeEnvVarFn(&buf, genEnvZones, "ZONES")
|
||||||
m.ForEachZone(func(z *Zone) bool {
|
m.ForEachZone(func(z *Zone) bool {
|
||||||
m.writeEnvZone(&buf, z)
|
err = m.writeEnvZone(&buf, z)
|
||||||
return false
|
return err != nil
|
||||||
})
|
})
|
||||||
|
|
||||||
_, err := buf.WriteTo(w)
|
if err == nil {
|
||||||
|
_, err = buf.WriteTo(w)
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Zones) writeEnvZone(w io.Writer, z *Zone) {
|
func (m *Zones) writeEnvZone(w io.Writer, z *Zone) error {
|
||||||
zoneID := z.ID
|
zoneID := z.ID
|
||||||
|
|
||||||
// ZONE{zoneID}
|
// ZONE{zoneID}
|
||||||
@@ -32,14 +35,14 @@ func (m *Zones) writeEnvZone(w io.Writer, z *Zone) {
|
|||||||
|
|
||||||
// ZONE{zoneID}_GW
|
// ZONE{zoneID}_GW
|
||||||
gatewayID := getRingZeroGatewayID(z)
|
gatewayID := getRingZeroGatewayID(z)
|
||||||
if gatewayID > 0 {
|
m.writeEnvVar(w, fmt.Sprintf("%v", gatewayID), "ZONE%v_%s", zoneID, "GW")
|
||||||
m.writeEnvVar(w, fmt.Sprintf("%v", gatewayID), "ZONE%v_%s", zoneID, "GW")
|
|
||||||
|
|
||||||
// ZONE{zoneID}_IP
|
// ZONE{zoneID}_IP
|
||||||
if ip, ok := RingZeroAddress(zoneID, gatewayID); ok {
|
if ip, ok := RingZeroAddress(zoneID, gatewayID); ok {
|
||||||
m.writeEnvVar(w, ip.String(), "ZONE%v_%s", zoneID, "IP")
|
m.writeEnvVar(w, ip.String(), "ZONE%v_%s", zoneID, "IP")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Zones) writeEnvVarFn(w io.Writer, fn func(*Zones) string, name string, args ...any) {
|
func (m *Zones) writeEnvVarFn(w io.Writer, fn func(*Zones) string, name string, args ...any) {
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ package zones
|
|||||||
import (
|
import (
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Machine is a machine on a Zone
|
// A Machine is a machine on a Zone
|
||||||
type Machine struct {
|
type Machine struct {
|
||||||
|
mu sync.Mutex
|
||||||
zone *Zone
|
zone *Zone
|
||||||
ID int
|
ID int
|
||||||
Name string `toml:"name"`
|
Name string `toml:"name"`
|
||||||
@@ -41,6 +43,9 @@ func (m *Machine) IsGateway() bool {
|
|||||||
|
|
||||||
// SetGateway enables/disables a Machine ring0 integration
|
// SetGateway enables/disables a Machine ring0 integration
|
||||||
func (m *Machine) SetGateway(enabled bool) error {
|
func (m *Machine) SetGateway(enabled bool) error {
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
|
||||||
ri, found := m.getRingInfo(0)
|
ri, found := m.getRingInfo(0)
|
||||||
switch {
|
switch {
|
||||||
case !found && !enabled:
|
case !found && !enabled:
|
||||||
|
|||||||
+1
-7
@@ -3,7 +3,6 @@ package zones
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"github.com/hack-pad/hackpadfs/os"
|
"github.com/hack-pad/hackpadfs/os"
|
||||||
|
|
||||||
@@ -131,12 +130,7 @@ func NewFS(dir fs.FS, domain string) (*Zones, error) {
|
|||||||
|
|
||||||
// New builds a [Zones] tree using the given directory
|
// New builds a [Zones] tree using the given directory
|
||||||
func New(dir, domain string) (*Zones, error) {
|
func New(dir, domain string) (*Zones, error) {
|
||||||
dir, err := filepath.Abs(dir)
|
base, err := os.NewFS().Sub(dir)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
base, err := os.NewFS().Sub(dir[1:])
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user