fix(pkg/config): SecretManagement.UnmarshalJSON error omits unsupported type
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 1.4k
- Forks
- 364
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 84
Description
What happened:
In SecretManagement.UnmarshalJSON, when an unsupported type is provided, the error message does not include the invalid type value.
In the default branch, the code uses s.Type in the error message, but s.Type has not been assigned from the parsed value (g.Type) yet. Because of that, the printed type is empty:
**
unsupported secret management type:
This exists in both packages:
pkg/config/piped.gopkg/configv1/piped.go
Relevant code:
switch g.Type {
case model.SecretManagementTypeKeyPair:
s.Type = model.SecretManagementTypeKeyPair
// ...
case model.SecretManagementTypeGCPKMS:
s.Type = model.SecretManagementTypeGCPKMS
// ...
default:
err = fmt.Errorf("unsupported secret management type: %s", s.Type) // bug: s.Type is still empty
}
Suggested fix: use g.Type instead of s.Type in the default branch in both pkg/config and pkg/configv1.
How to reproduce it:
Unmarshal a SecretManagement config with an unknown type:
data := []byte(`{"type":"UNKNOWN_TYPE","config":{}}`)
var s config.SecretManagement
err := json.Unmarshal(data, &s)
fmt.Println(err)
Actual output:
unsupported secret management type:
Environment:
piped version: master
control-plane version: master
Others: reproduced on current master
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in pkg/config/piped.go and pkg/configv1/piped.go, focusing on the default branches of SecretManagement.UnmarshalJSON. Reproduce the issue with the provided UNKNOWN_TYPE JSON input and verify that both packages report the unsupported type value in the error rather than an empty value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- devops
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100