Skip to content

Commit

Permalink
fix: keystore generation output
Browse files Browse the repository at this point in the history
  • Loading branch information
squakez committed Jan 30, 2025
1 parent 971e1cb commit 5fb423b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/controller/integrationplatform/kamelets.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ const (
kamelVersionAnnotation = "camel.apache.org/version"
)

// installKameletCatalog installs the version Apache Kamelet Catalog into the specified namespace. It returns the number of Kamelets installed and errored
// if successful.
// installKameletCatalog installs the version Apache Kamelet Catalog into the specified namespace.
// It returns the number of Kamelets installed and errored if successful.
func installKameletCatalog(ctx context.Context, c client.Client, platform *v1.IntegrationPlatform, version string) (int, int, error) {
// Prepare proper privileges for Kamelets installed globally
if err := prepareKameletsPermissions(ctx, c, platform.Namespace); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/util/jvm/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const (
var (
logger = log.WithName("keytool")

loggerInfo = func(s string) string { logger.Info(s); return "" }
loggerError = func(s string) string { logger.Error(nil, s); return "" }
loggerInfo = func(s string) string { logger.Info(s); return s }
loggerError = func(s string) string { logger.Error(nil, s); return s }
)

func GenerateKeystore(ctx context.Context, keystoreDir, keystoreName, keystorePass string, data [][]byte) error {
Expand All @@ -49,7 +49,7 @@ func GenerateKeystore(ctx context.Context, keystoreDir, keystoreName, keystorePa
cmd.Stdin = bytes.NewReader(data)
// keytool logs info messages to stderr, as stdout is used to output results,
// otherwise it logs error messages to stdout.
err := util.RunAndLog(ctx, cmd, loggerError, loggerInfo)
err := util.RunAndLog(ctx, cmd, loggerInfo, loggerError)
if err != nil {
return err
}
Expand All @@ -66,7 +66,7 @@ func GenerateKeystore(ctx context.Context, keystoreDir, keystoreName, keystorePa
cmd.Dir = keystoreDir
// keytool logs info messages to stderr, as stdout is used to output results,
// otherwise it logs error messages to stdout.
err := util.RunAndLog(ctx, cmd, loggerError, loggerInfo)
err := util.RunAndLog(ctx, cmd, loggerInfo, loggerError)
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/util/jvm/keystore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"testing"

"github.com/apache/camel-k/v2/pkg/util"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand All @@ -38,10 +39,12 @@ func TestGenerateKeystore(t *testing.T) {
data = [][]byte{{0}, {1}}
err = GenerateKeystore(ctx, "", "/tmp/keystore", NewKeystorePassword(), data)
require.Error(t, err)
assert.Equal(t, "keytool error: java.io.IOException: keystore password was incorrect: exit status 1", err.Error())

// Incorrect password format
err = GenerateKeystore(ctx, "", "/tmp/keystore", "", data)
require.Error(t, err)
assert.Equal(t, "Illegal option: /tmp/keystore: exit status 1", err.Error())

testFileExists, _ := util.FileExists("/tmp/keystore")
if testFileExists {
Expand Down

0 comments on commit 5fb423b

Please sign in to comment.