mirror of
https://github.com/kairos-io/kcrypt-challenger.git
synced 2025-09-26 13:04:30 +00:00
Fix plugin trying to run --debug
event and not logging to files
Args[0] is no longer guaranteed to be the event's name. We have a proper command now. Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
This commit is contained in:
@@ -20,9 +20,6 @@ import (
|
||||
"github.com/kairos-io/kairos-challenger/pkg/constants"
|
||||
)
|
||||
|
||||
// Because of how go-pluggable works, we can't just print to stdout
|
||||
const LOGFILE = "/tmp/kcrypt-challenger-client.log"
|
||||
|
||||
// Retry delays for different failure types
|
||||
const (
|
||||
TPMRetryDelay = 100 * time.Millisecond // Brief delay for TPM hardware busy/unavailable
|
||||
@@ -45,17 +42,12 @@ func NewClientWithLogger(logger types.KairosLogger) (*Client, error) {
|
||||
return &Client{Config: conf, Logger: logger}, nil
|
||||
}
|
||||
|
||||
func (c *Client) Start() error {
|
||||
if err := os.RemoveAll(LOGFILE); err != nil { // Start fresh
|
||||
return fmt.Errorf("removing the logfile: %w", err)
|
||||
}
|
||||
|
||||
func (c *Client) Start(eventType pluggable.EventType) error {
|
||||
factory := pluggable.NewPluginFactory()
|
||||
|
||||
// Input: bus.EventInstallPayload
|
||||
// Expected output: map[string]string{}
|
||||
factory.Add(bus.EventDiscoveryPassword, func(e *pluggable.Event) pluggable.EventResponse {
|
||||
|
||||
b := &block.Partition{}
|
||||
err := json.Unmarshal([]byte(e.Data), b)
|
||||
if err != nil {
|
||||
@@ -77,7 +69,7 @@ func (c *Client) Start() error {
|
||||
}
|
||||
})
|
||||
|
||||
return factory.Run(pluggable.EventType(os.Args[1]), os.Stdin, os.Stdout)
|
||||
return factory.Run(eventType, os.Stdin, c.Logger)
|
||||
}
|
||||
|
||||
// ❯ echo '{ "data": "{ \\"label\\": \\"LABEL\\" }"}' | sudo -E WSS_SERVER="http://localhost:8082/challenge" ./challenger "discovery.password"
|
||||
|
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/kairos-io/kairos-sdk/kcrypt/bus"
|
||||
"github.com/kairos-io/kairos-sdk/types"
|
||||
"github.com/kairos-io/tpm-helpers"
|
||||
"github.com/mudler/go-pluggable"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -187,7 +188,7 @@ with kcrypt and other tools.`, bus.EventDiscoveryPassword),
|
||||
Example: fmt.Sprintf(` # Plugin mode (for integration with kcrypt)
|
||||
echo '{"data": "{\"name\": \"/dev/sda2\", \"uuid\": \"12345-abcde\", \"label\": \"encrypted-data\"}"}' | kcrypt-discovery-challenger %s`, bus.EventDiscoveryPassword),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runPluginMode()
|
||||
return runPluginMode(bus.EventDiscoveryPassword)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -310,7 +311,7 @@ func runGetPassphrase(flags *GetFlags) error {
|
||||
}
|
||||
|
||||
// runPluginMode handles plugin event commands
|
||||
func runPluginMode() error {
|
||||
func runPluginMode(eventType pluggable.EventType) error {
|
||||
// In plugin mode, use quiet=true to log to file instead of console
|
||||
// Log level depends on debug flag, write logs to /var/log/kairos/kcrypt-discovery-challenger.log
|
||||
var logLevel string
|
||||
@@ -320,13 +321,14 @@ func runPluginMode() error {
|
||||
logLevel = "error"
|
||||
}
|
||||
|
||||
logger := types.NewKairosLogger("kcrypt-discovery-challenger", logLevel, true)
|
||||
logger := types.NewKairosLoggerWithExtraDirs("kcrypt-discovery-challenger", logLevel, true, "/var/log/kairos")
|
||||
logger.Debugf("Debug mode enabled for plugin mode")
|
||||
c, err := client.NewClientWithLogger(logger)
|
||||
if err != nil {
|
||||
return fmt.Errorf("creating client: %w", err)
|
||||
}
|
||||
|
||||
err = c.Start()
|
||||
err = c.Start(eventType)
|
||||
if err != nil {
|
||||
return fmt.Errorf("starting plugin: %w", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user