pipecd
pipecd copied to clipboard
fix(pkg/config): SecretManagement.UnmarshalJSON error omits unsupported type
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
@mohammedfirdouss @Warashi I'd like to work on this