kcrypt-challenger/cmd/discovery/main.go

54 lines
1.0 KiB
Go
Raw Normal View History

2022-10-09 22:32:56 +00:00
package main
import (
"fmt"
"os"
"github.com/kairos-io/kairos-challenger/cmd/discovery/client"
2025-05-06 09:18:50 +00:00
"github.com/kairos-io/kairos-sdk/kcrypt/bus"
"github.com/kairos-io/tpm-helpers"
2025-05-06 09:18:50 +00:00
"github.com/mudler/go-pluggable"
2022-10-09 22:32:56 +00:00
)
func main() {
2025-05-06 09:18:50 +00:00
if len(os.Args) >= 2 && isEventDefined(os.Args[1]) {
c, err := client.NewClient()
checkErr(err)
checkErr(c.Start())
return
2022-10-09 22:32:56 +00:00
}
pubhash, err := tpm.GetPubHash()
checkErr(err)
2022-10-09 22:32:56 +00:00
fmt.Print(pubhash)
}
func checkErr(err error) {
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
2025-05-06 09:18:50 +00:00
// 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
}
}