From 157628dfe1c7f1f837dc8df0e622a2d64a31c79a Mon Sep 17 00:00:00 2001 From: Hank Donnay Date: Thu, 22 Oct 2020 14:20:47 -0500 Subject: [PATCH] config: add custom config marshaling Signed-off-by: Hank Donnay --- config/auth.go | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/config/auth.go b/config/auth.go index f61850cb78..211fce72b3 100644 --- a/config/auth.go +++ b/config/auth.go @@ -26,13 +26,14 @@ type AuthKeyserver struct { API string `yaml:"api" json:"api"` Intraservice []byte `yaml:"intraservice" json:"intraservice"` } +type keyserverConfig struct { + API string `yaml:"api" json:"api"` + Intraservice string `yaml:"intraservice" json:"intraservice"` +} // UnmarshalYAML implements yaml.Unmarshaler. func (a *AuthKeyserver) UnmarshalYAML(f func(interface{}) error) error { - var m struct { - API string `yaml:"api"` - Intraservice string `yaml:"intraservice"` - } + var m keyserverConfig if err := f(&m); err != nil { return nil } @@ -45,6 +46,14 @@ func (a *AuthKeyserver) UnmarshalYAML(f func(interface{}) error) error { return nil } +// MarshalYAML implements yaml.Marshaler. +func (a *AuthKeyserver) MarshalYAML() (interface{}, error) { + return &keyserverConfig{ + API: a.API, + Intraservice: base64.StdEncoding.EncodeToString(a.Intraservice), + }, nil +} + // AuthPSK is the configuration for doing pre-shared key based authentication. // // The "Issuer" key is what the service expects to verify as the "issuer" claim. @@ -52,13 +61,14 @@ type AuthPSK struct { Key []byte `yaml:"key" json:"key"` Issuer []string `yaml:"iss" json:"iss"` } +type pskConfig struct { + Key string `yaml:"key" json:"key"` + Issuer []string `yaml:"iss" json:"iss"` +} // UnmarshalYAML implements yaml.Unmarshaler. func (a *AuthPSK) UnmarshalYAML(f func(interface{}) error) error { - var m struct { - Issuer []string `yaml:"iss" json:"iss"` - Key string `yaml:"key" json:"key"` - } + var m pskConfig if err := f(&m); err != nil { return nil } @@ -70,3 +80,11 @@ func (a *AuthPSK) UnmarshalYAML(f func(interface{}) error) error { a.Key = s return nil } + +// MarshalYAML implements yaml.Marshaler. +func (a *AuthPSK) MarshalYAML() (interface{}, error) { + return &pskConfig{ + Key: base64.StdEncoding.EncodeToString(a.Key), + Issuer: a.Issuer, + }, nil +}