Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/confluentinc/go-editor v0.4.0
github.com/confluentinc/go-printer v0.10.0
github.com/confluentinc/mds-sdk-go v0.0.0-20190610045202-137cf78b1f6a
github.com/confluentinc/properties v0.0.0-20190814194548-42c10394a787
github.com/confluentinc/protoc-gen-ccloud v0.0.1 // indirect
github.com/confluentinc/schema-registry-sdk-go v0.0.7
github.com/dgryski/go-metro v0.0.0-20180109044635-280f6062b5bc // indirect
Expand Down Expand Up @@ -58,7 +59,6 @@ require (
github.com/kevinburke/go-bindata v3.13.0+incompatible
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/lithammer/dedent v1.1.0
github.com/magiconair/properties v1.8.1
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.8
github.com/mattn/go-runewidth v0.0.3 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ github.com/confluentinc/go-printer v0.10.0 h1:JLJOeSdJL6A0YxAK24GSuoC52sPQP/chow
github.com/confluentinc/go-printer v0.10.0/go.mod h1:bOK/pPNm4ao7bZIcRnGPGca1B64nW+lApFXHZEZ0PcM=
github.com/confluentinc/mds-sdk-go v0.0.0-20190610045202-137cf78b1f6a h1:1rhv9IcTT1xA7wO7ES4CJIK+PhuIqnFfZ2zcwoWAf3g=
github.com/confluentinc/mds-sdk-go v0.0.0-20190610045202-137cf78b1f6a/go.mod h1:ouhJcNrAtQCtywN7BHDkpnl2Aaf7lDD157IzFDNVRao=
github.com/confluentinc/properties v0.0.0-20190814194548-42c10394a787 h1:hHiVn9sDY/pZCETOV3489odsMhj8NEyiamjwhBy6TLA=
github.com/confluentinc/properties v0.0.0-20190814194548-42c10394a787/go.mod h1:e8oa6xV9gIddL04yTbRjly4s7U3Fn57PAOUMTUPibUA=
github.com/confluentinc/protoc-gen-ccloud v0.0.0-20190122202943-91a08616afd2/go.mod h1:RL4B2sjziJsuvLS6nkpqJha7026Wl3aaN4cXMSDYoc4=
github.com/confluentinc/protoc-gen-ccloud v0.0.1 h1:oTEOlStee6ln4FeKdgQevmjuma50EccP2MwplJRFR1I=
github.com/confluentinc/protoc-gen-ccloud v0.0.1/go.mod h1:pDn9xwYsW8QvxGpwJ9CaomgtYBpx7FgdonHVmCo5yRo=
Expand Down
7 changes: 0 additions & 7 deletions internal/pkg/secret/password_protection_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ const (
SECURE_CONFIG_PROVIDER = "securepass"

SECURE_CONFIG_PROVIDER_CLASS = "io.confluent.kafka.security.config.provider.SecurePassConfigProvider"

/* The properties file writer associates comments with the next property, so if the comment is the last line in the config file
the comment is deleted after performing encryption/add/update operation on the file. In order to retain the last comment we add delimiter
SECURE_CONFIG_PROVIDER_DELIMITER at the end of the config file before performing the encryption/add/update operation. This delimiter is removed
after the operations are completed.
*/
SECURE_CONFIG_PROVIDER_DELIMITER = "\nconfig.providers.securepass.delimiter = delimiter"
)

// Encryption Keys Metadata
Expand Down
18 changes: 1 addition & 17 deletions internal/pkg/secret/password_protection_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"strconv"
"strings"

"github.com/confluentinc/properties"
"github.com/jonboulle/clockwork"
"github.com/magiconair/properties"

"github.com/confluentinc/cli/internal/pkg/log"
)
Expand Down Expand Up @@ -453,11 +453,6 @@ func (c *PasswordProtectionSuite) UpdateEncryptedPasswords(configFilePath string
return err
}

// Add a delimiter key at the end of the file to retain the comments in the config file.
err = AppendDelimiter(configFilePath)
if err != nil {
return err
}
configProps, err := LoadPropertiesFile(configFilePath)
configProps.DisableExpansion = true

Expand Down Expand Up @@ -684,11 +679,6 @@ func (c *PasswordProtectionSuite) encryptConfigValues(matchProps *properties.Pro
return fmt.Errorf("failed to unwrap the data key due to invalid master key or corrupted data key.")
}

// Add a delimiter key at the end of the file to retain the last comment in the config file.
err = AppendDelimiter(configFilePath)
if err != nil {
return err
}
configProps, err := LoadPropertiesFile(configFilePath)
if err != nil {
return err
Expand Down Expand Up @@ -732,12 +722,6 @@ func (c *PasswordProtectionSuite) encryptConfigValues(matchProps *properties.Pro
return err
}

// Remove the Delimiter
err = RemoveDelimiter(configFilePath)
if err != nil {
return err
}

err = WritePropertiesFile(localSecureConfigPath, secureConfigProps, true)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/secret/password_protection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"testing"

"github.com/confluentinc/cli/internal/pkg/log"
"github.com/confluentinc/properties"
"github.com/jonboulle/clockwork"
"github.com/magiconair/properties"
"github.com/stretchr/testify/require"
)

Expand Down
38 changes: 6 additions & 32 deletions internal/pkg/secret/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"regexp"
"strings"

"github.com/magiconair/properties"
"github.com/confluentinc/properties"
)

var dataRegex = regexp.MustCompile(DATA_PATTERN)
Expand Down Expand Up @@ -41,7 +41,7 @@ func findMatchTrim(original string, re *regexp.Regexp, prefix string, suffix str
func WritePropertiesFile(path string, property *properties.Properties, writeComments bool) error {
buf := new(bytes.Buffer)
if writeComments {
_, err := property.WriteComment(buf, "# ", properties.UTF8)
_, err := property.WriteFormattedComment(buf, properties.UTF8)
if err != nil {
return err
}
Expand Down Expand Up @@ -72,7 +72,10 @@ func LoadPropertiesFile(path string) (*properties.Properties, error) {
if !DoesPathExist(path) {
return nil, fmt.Errorf("Invalid file path.")
}
property, err := properties.LoadFile(path, properties.UTF8)
loader := new(properties.Loader)
loader.Encoding = properties.UTF8
loader.PreserveFormatting = true
property, err := loader.LoadFile(path)
if err != nil {
return nil, err
}
Expand All @@ -86,32 +89,3 @@ func GenerateConfigKey(path string, key string) string {
// the server-side version will be running on a *nix variant and will thus have forward slashes to lookup the correct path
return fileName + "/" + key
}

func AppendDelimiter(path string) error {
f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0)
if err != nil {
return err
}
if _, err := f.Write([]byte(SECURE_CONFIG_PROVIDER_DELIMITER)); err != nil {
return err
}

defer f.Close()

return nil
}

func RemoveDelimiter(path string) error {
read, err := ioutil.ReadFile(path)
if err != nil {
return err
}
newContents := strings.Replace(string(read), SECURE_CONFIG_PROVIDER_DELIMITER, "", -1)

err = ioutil.WriteFile(path, []byte(newContents), 0)
if err != nil {
return err
}

return nil
}