Drop kcrypt, use sdk (#120)

This commit is contained in:
Itxaka
2025-05-06 11:18:50 +02:00
committed by GitHub
parent 5787d7fa47
commit ddd65746f0
5 changed files with 63 additions and 51 deletions

View File

@@ -10,7 +10,7 @@ import (
"github.com/jaypipes/ghw/pkg/block"
"github.com/kairos-io/kairos-challenger/pkg/constants"
"github.com/kairos-io/kairos-challenger/pkg/payload"
"github.com/kairos-io/kcrypt/pkg/bus"
"github.com/kairos-io/kairos-sdk/kcrypt/bus"
"github.com/kairos-io/tpm-helpers"
"github.com/mudler/go-pluggable"
"github.com/mudler/yip/pkg/utils"

View File

@@ -2,10 +2,16 @@ package client
import (
"github.com/kairos-io/kairos-sdk/collector"
kconfig "github.com/kairos-io/kcrypt/pkg/config"
"gopkg.in/yaml.v3"
)
// There are the directories under which we expect to find kairos configuration.
// When we are booted from an iso (during installation), configuration is expected
// under `/oem`. When we are booting an installed system (in initramfs phase),
// the path is `/sysroot/oem`.
// When we run the challenger in hooks, we may have the config under /tmp/oem
var confScanDirs = []string{"/oem", "/sysroot/oem", "/tmp/oem"}
type Client struct {
Config Config
}
@@ -27,7 +33,7 @@ func unmarshalConfig() (Config, error) {
var result Config
o := &collector.Options{NoLogs: true, MergeBootCMDLine: false}
if err := o.Apply(collector.Directories(append(kconfig.ConfigScanDirs, "/tmp/oem")...)); err != nil {
if err := o.Apply(collector.Directories(confScanDirs...)); err != nil {
return result, err
}

View File

@@ -5,12 +5,13 @@ import (
"os"
"github.com/kairos-io/kairos-challenger/cmd/discovery/client"
"github.com/kairos-io/kcrypt/pkg/bus"
"github.com/kairos-io/kairos-sdk/kcrypt/bus"
"github.com/kairos-io/tpm-helpers"
"github.com/mudler/go-pluggable"
)
func main() {
if len(os.Args) >= 2 && bus.IsEventDefined(os.Args[1]) {
if len(os.Args) >= 2 && isEventDefined(os.Args[1]) {
c, err := client.NewClient()
checkErr(err)
checkErr(c.Start())
@@ -28,3 +29,25 @@ func checkErr(err error) {
os.Exit(1)
}
}
// isEventDefined checks whether an event is defined in the bus.
// It accepts strings or EventType, returns a boolean indicating that
// the event was defined among the events emitted by the bus.
func isEventDefined(i interface{}) bool {
checkEvent := func(e pluggable.EventType) bool {
if e == bus.EventDiscoveryPassword {
return true
}
return false
}
switch f := i.(type) {
case string:
return checkEvent(pluggable.EventType(f))
case pluggable.EventType:
return checkEvent(f)
default:
return false
}
}