Files
kairos-agent/cmd/agent/rotate.go
Ettore Di Giacinto 1a03c96235 art: Refactor out config sections
Now there is a `install` section in the config that has the fields that previously where in `c3os` but
were actually only used during install phase.

Also the k3s and c3os config were moved to the provider instead that in the global config.
2022-07-16 20:47:55 +00:00

41 lines
902 B
Go

package main
import (
machine "github.com/c3os-io/c3os/internal/machine"
"github.com/c3os-io/c3os/internal/provider"
providerConfig "github.com/c3os-io/c3os/internal/provider/config"
config "github.com/c3os-io/c3os/pkg/config"
)
func rotate(configDir []string, newToken, apiAddress, rootDir string, restart bool) error {
if err := config.ReplaceToken(configDir, newToken); err != nil {
return err
}
c, err := config.Scan(config.Directories(configDir...))
if err != nil {
return err
}
providerCfg := &providerConfig.Config{}
err = c.Unmarshal(providerCfg)
if err != nil {
return err
}
err = provider.SetupVPN(machine.EdgeVPNDefaultInstance, apiAddress, rootDir, false, providerCfg)
if err != nil {
return err
}
if restart {
svc, err := machine.EdgeVPN(machine.EdgeVPNDefaultInstance, rootDir)
if err != nil {
return err
}
return svc.Restart()
}
return nil
}