Files
warewulf/internal/pkg/api/apiconfig/client.go
Christian Goll 9ba1aa8d63 api changes to modify unexported fields
changes can now not be done directly but must
go to SetNode or SetProfile. Although its also
now possible to access the field direclty with
GetNodePtr

Signed-off-by: Christian Goll <cgoll@suse.com>
2024-10-17 15:30:54 -04:00

43 lines
950 B
Go

package apiconfig
import (
"log"
"os"
"gopkg.in/yaml.v3"
)
// ClientApiConfig contains configuration parameters for an API server.
type ClientApiConfig struct {
// Server is the hostname or IP address of the server to connect to.
Server string `yaml:"prefix"`
// Port is the where the API server listens.
Port uint32 `yaml:"port"`
}
// ClientConfig is the full client configuration.
type ClientConfig struct {
ApiConfig ClientApiConfig `yaml:"api"`
TlsConfig TlsConfig `yaml:"tls"`
}
// NewClient loads the client config from the given configFilePath.
func NewClient(configFilePath string) (config ClientConfig, err error) {
log.Printf("Loading api client configuration from: %v\n", configFilePath)
var fileBytes []byte
fileBytes, err = os.ReadFile(configFilePath)
if err != nil {
return
}
err = yaml.Unmarshal(fileBytes, &config)
if err != nil {
return
}
log.Printf("api client config: %#v\n", config)
return
}