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-20 13:41:06 +02:00
|
|
|
GrpcPort string `yaml:"gRPCPort"`
|
2023-10-25 19:34:38 +02:00
|
|
|
AdvertiseRoutes bool `yaml:"advertiseRoutes"`
|
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 {
|
2023-10-24 01:12:38 +02:00
|
|
|
logging.Log.WriteErrorf("Read file error: %s\n", err.Error())
|
2023-10-01 20:01:35 +02:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = yaml.Unmarshal(yamlBytes, &conf)
|
|
|
|
|
|
|
|
if err != nil {
|
2023-10-24 01:12:38 +02:00
|
|
|
logging.Log.WriteErrorf("Unmarshal error: %s\n", err.Error())
|
2023-10-01 20:01:35 +02:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &conf, nil
|
|
|
|
}
|