Skip to content

feat: support nested structs, structured arrays, and better secret value handling in config #4727

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

Merged
merged 16 commits into from
Oct 25, 2022
Prev Previous commit
Next Next commit
fix tests
  • Loading branch information
f0ssel committed Oct 24, 2022
commit cead44fabfbfaa6c70a83f98e768becc3eb2a2fd
28 changes: 23 additions & 5 deletions codersdk/deploymentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,38 @@ type DeploymentConfigField[T Flaggable] struct {
// nolint: revive
func (f *DeploymentConfigField[T]) MarshalJSON() ([]byte, error) {
if !f.Secret {
return json.Marshal(f)
return json.Marshal(struct {
Name string `json:"name"`
Usage string `json:"usage"`
Flag string `json:"flag"`
Shorthand string `json:"shorthand"`
Enterprise bool `json:"enterprise"`
Hidden bool `json:"hidden"`
Secret bool `json:"secret"`
Default T `json:"default"`
Value T `json:"value"`
}{
Name: f.Name,
Usage: f.Usage,
Flag: f.Flag,
Shorthand: f.Shorthand,
Enterprise: f.Enterprise,
Hidden: f.Hidden,
Secret: f.Secret,
Default: f.Default,
Value: f.Value,
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just marshal ourselves in this case?

json.Marshal(f)

Copy link
Contributor Author

@f0ssel f0ssel Oct 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't! I did that first and you get an infinite loop because it just calls this marshaller again. LOL

}

type SafeField[T Flaggable] struct {
return json.Marshal(struct {
Name string `json:"name"`
Usage string `json:"usage"`
Flag string `json:"flag"`
Shorthand string `json:"shorthand"`
Enterprise bool `json:"enterprise"`
Hidden bool `json:"hidden"`
Secret bool `json:"secret"`
}

return json.Marshal(SafeField[T]{
}{
Name: f.Name,
Usage: f.Usage,
Flag: f.Flag,
Expand Down