zones: move Machine.ReadFile to a dedicated machine_file.go

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-08-23 18:12:06 +00:00
parent c81b782b26
commit 86075eb47f
2 changed files with 29 additions and 25 deletions
-25
View File
@@ -1,10 +1,7 @@
package zones
import (
"fmt"
"io/fs"
"net/netip"
"path/filepath"
"strings"
)
@@ -36,28 +33,6 @@ func (m *Machine) FullName() string {
return m.Name
}
// ReadFile reads a file from the machine's config directory
func (m *Machine) ReadFile(name string, args ...any) ([]byte, error) {
base := m.zone.zones.dir
fullName := m.getFilename(name, args...)
return fs.ReadFile(base, fullName)
}
func (m *Machine) getFilename(name string, args ...any) string {
if len(args) > 0 {
name = fmt.Sprintf(name, args...)
}
s := []string{
m.zone.Name,
m.Name,
name,
}
return filepath.Join(s...)
}
// IsGateway tells if the Machine is a ring0 gateway
func (m *Machine) IsGateway() bool {
_, ok := m.getRingInfo(0)
+29
View File
@@ -0,0 +1,29 @@
package zones
import (
"fmt"
"io/fs"
"path/filepath"
)
// ReadFile reads a file from the machine's config directory
func (m *Machine) ReadFile(name string, args ...any) ([]byte, error) {
base := m.zone.zones.dir
fullName := m.getFilename(name, args...)
return fs.ReadFile(base, fullName)
}
func (m *Machine) getFilename(name string, args ...any) string {
if len(args) > 0 {
name = fmt.Sprintf(name, args...)
}
s := []string{
m.zone.Name,
m.Name,
name,
}
return filepath.Join(s...)
}