2023-10-01 20:01:35 +02:00
|
|
|
// conf defines configuration file parsing for golang
|
|
|
|
package conf
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
logging "github.com/tim-beatham/wgmesh/pkg/log"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
type WgMeshConfiguration struct {
|
|
|
|
CertificatePath string `yaml:"certificatePath"`
|
|
|
|
PrivateKeyPath string `yaml:"privateKeyPath"`
|
|
|
|
SkipCertVerification bool `yaml:"skipCertVerification"`
|
2023-10-02 17:03:41 +02:00
|
|
|
IfName string `yaml:"ifName"`
|
2023-10-10 21:14:40 +02:00
|
|
|
WgPort string `yaml:"wgPort"`
|
|
|
|
GrpcPort string `yaml:"grpcPort"`
|
2023-10-01 20:01:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func ParseConfiguration(filePath string) (*WgMeshConfiguration, error) {
|
|
|
|
var conf WgMeshConfiguration
|
|
|
|
|
|
|
|
yamlBytes, err := os.ReadFile(filePath)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
logging.ErrorLog.Printf("Read file error: %s\n", err.Error())
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = yaml.Unmarshal(yamlBytes, &conf)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
logging.ErrorLog.Printf("Unmarshal error: %s\n", err.Error())
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &conf, nil
|
|
|
|
}
|