diff options
author | Sascha Grunert <sgrunert@suse.com> | 2019-09-05 16:58:06 +0200 |
---|---|---|
committer | Sascha Grunert <sgrunert@suse.com> | 2019-09-05 16:58:08 +0200 |
commit | f66a2069f1b26ff9987b008ba4b0c91ac3b682cc (patch) | |
tree | 1219ee0e7b87494eaf2c6ace56d4ecada0dc4a39 /vendor/github.com/openshift/api/config/v1/stringsource.go | |
parent | b962b1e3538312f145aea0cf5546ae31f35f635f (diff) | |
download | podman-f66a2069f1b26ff9987b008ba4b0c91ac3b682cc.tar.gz podman-f66a2069f1b26ff9987b008ba4b0c91ac3b682cc.tar.bz2 podman-f66a2069f1b26ff9987b008ba4b0c91ac3b682cc.zip |
Update buildah to v1.11.0
Vendor in the latest changes for buildah to apply the implemented
features here as well.
Signed-off-by: Sascha Grunert <sgrunert@suse.com>
Diffstat (limited to 'vendor/github.com/openshift/api/config/v1/stringsource.go')
-rw-r--r-- | vendor/github.com/openshift/api/config/v1/stringsource.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/vendor/github.com/openshift/api/config/v1/stringsource.go b/vendor/github.com/openshift/api/config/v1/stringsource.go new file mode 100644 index 000000000..6a5718c1d --- /dev/null +++ b/vendor/github.com/openshift/api/config/v1/stringsource.go @@ -0,0 +1,31 @@ +package v1 + +import "encoding/json" + +// UnmarshalJSON implements the json.Unmarshaller interface. +// If the value is a string, it sets the Value field of the StringSource. +// Otherwise, it is unmarshaled into the StringSourceSpec struct +func (s *StringSource) UnmarshalJSON(value []byte) error { + // If we can unmarshal to a simple string, just set the value + var simpleValue string + if err := json.Unmarshal(value, &simpleValue); err == nil { + s.Value = simpleValue + return nil + } + + // Otherwise do the full struct unmarshal + return json.Unmarshal(value, &s.StringSourceSpec) +} + +// MarshalJSON implements the json.Marshaller interface. +// If the StringSource contains only a string Value (or is empty), it is marshaled as a JSON string. +// Otherwise, the StringSourceSpec struct is marshaled as a JSON object. +func (s *StringSource) MarshalJSON() ([]byte, error) { + // If we have only a cleartext value set, do a simple string marshal + if s.StringSourceSpec == (StringSourceSpec{Value: s.Value}) { + return json.Marshal(s.Value) + } + + // Otherwise do the full struct marshal of the externalized bits + return json.Marshal(s.StringSourceSpec) +} |