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 {
|
2023-10-28 17:38:25 +02:00
|
|
|
// CertificatePath is the path to the certificate to use in mTLS
|
|
|
|
CertificatePath string `yaml:"certificatePath"`
|
|
|
|
// PrivateKeypath is the path to the clients private key in mTLS
|
|
|
|
PrivateKeyPath string `yaml:"privateKeyPath"`
|
|
|
|
// CaCeritifcatePath path to the certificate of the trust certificate authority
|
|
|
|
CaCertificatePath string `yaml:"caCertificatePath"`
|
|
|
|
// SkipCertVerification specify to skip certificate verification. Should only be used
|
|
|
|
// in test environments
|
|
|
|
SkipCertVerification bool `yaml:"skipCertVerification"`
|
|
|
|
// Port to run the GrpcServer on
|
|
|
|
GrpcPort string `yaml:"gRPCPort"`
|
2023-10-26 17:53:12 +02:00
|
|
|
// AdvertiseRoutes advertises other meshes if the node is in multiple meshes
|
|
|
|
AdvertiseRoutes bool `yaml:"advertiseRoutes"`
|
2023-10-28 17:38:25 +02:00
|
|
|
// Endpoint is the IP in which this computer is publicly reachable.
|
|
|
|
// usecase is when the node has multiple IP addresses
|
|
|
|
Endpoint string `yaml:"publicEndpoint"`
|
2023-10-01 20:01:35 +02:00
|
|
|
}
|
|
|
|
|
2023-10-28 17:38:25 +02:00
|
|
|
// ParseConfiguration parses the mesh configuration
|
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
|
|
|
|
}
|