kairos-agent/cmd/agent/rotate.go
Ettore Di Giacinto b2e49776a3 Split off cli into separate binaries (#37)
* 🎨 Split off cli into separate binaries

This commit splits off the cli into 3 binaries:
- agent
- cli
- provider

The provider now is a separate component that can be tested by itself
and have its own lifecycle. This paves the way to a ligher c3os variant,
HA support and other features that can be provided on runtime.

This is working, but still there are low hanging fruit to care about.

Fixes #14

* 🤖 Add provider bin to releases

* ⚙️ Handle signals

* ⚙️ Reduce buildsize footprint

* 🎨 Scan for providers also in /system/providers

* 🤖 Run goreleaser

* 🎨 Refactoring
2022-07-04 22:39:34 +02:00

34 lines
685 B
Go

package main
import (
machine "github.com/c3os-io/c3os/internal/machine"
"github.com/c3os-io/c3os/internal/vpn"
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(configDir...)
if err != nil {
return err
}
err = vpn.Setup(machine.EdgeVPNDefaultInstance, apiAddress, rootDir, false, c)
if err != nil {
return err
}
if restart {
svc, err := machine.EdgeVPN(machine.EdgeVPNDefaultInstance, rootDir)
if err != nil {
return err
}
return svc.Restart()
}
return nil
}