Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pass mTLS certificates correctly (TypeListToStringSlice shouldn't quote special characters) #172

Merged
merged 1 commit into from
Nov 6, 2024
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
13 changes: 11 additions & 2 deletions redpanda/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,18 @@ func ConnectionTypeToString(t controlplanev1beta2.Cluster_ConnectionType) string
// TypeListToStringSlice converts a types.List to a []string, stripping
// surrounding quotes for each element.
func TypeListToStringSlice(t types.List) []string {
var s []string
if t.IsNull() {
return nil
}
s := []string{}
for _, v := range t.Elements() {
s = append(s, strings.Trim(v.String(), "\"")) // it's easier to strip the quotes than type converting until you hit something that doesn't include them
stringval, ok := v.(types.String)
if ok {
s = append(s, stringval.ValueString())
} else {
// TODO: issue #173 - ensure this is only called on types.List that actually hold strings
s = append(s, strings.Trim(v.String(), "\"")) // it's easier to strip the quotes than type converting until you hit something that doesn't include them
}
}
return s
}
Expand Down
12 changes: 11 additions & 1 deletion redpanda/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,20 @@ func TestTypeListToStringSlice(t *testing.T) {
input: StringSliceToTypeList([]string{"a", "b", "c"}),
expected: []string{"a", "b", "c"},
},
{
name: "test special character conversion",
input: StringSliceToTypeList([]string{"---BEGIN CERTIFICATE---\nhello world\n---END CERTIFICATE---\n"}),
expected: []string{"---BEGIN CERTIFICATE---\nhello world\n---END CERTIFICATE---\n"},
},
{
name: "test nil conversion",
input: StringSliceToTypeList(nil),
expected: nil,
},
{
name: "test empty conversion",
input: StringSliceToTypeList([]string{}),
expected: nil,
expected: []string{},
},
}

Expand Down