From 54127729e6b56fb1d643368f5540a7dc20e6cd32 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Tue, 7 Jun 2016 15:43:45 +0200 Subject: [PATCH] configuration: Consistency fixes Minor modification for API consistency sake: - Payload takes a blob and returns a payload - ExtractBlob return variable is called a blob Signed-off-by: Samuel Ortiz --- configuration/configuration.go | 21 ++++++++++----------- configuration/configuration_test.go | 3 +-- configuration/file.go | 4 ++-- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/configuration/configuration.go b/configuration/configuration.go index 9240b2600..c1c8de6c4 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -73,15 +73,14 @@ func discoverDriver(uriStr string) (storageType payloads.StorageType, err error) // Payload fills the payloads.Configure struct passed in 'conf' // with the values from the bytes given -func Payload(yamlConf []byte, conf *payloads.Configure) (err error) { - if yamlConf == nil { - return fmt.Errorf("Unable to retrieve configuration from empty definition") +func Payload(blob []byte) (conf payloads.Configure, err error) { + if blob == nil { + return conf, fmt.Errorf("Unable to retrieve configuration from empty definition") } - err = yaml.Unmarshal(yamlConf, &conf) - if err != nil { - return err - } - return nil + fillDefaults(&conf) + err = yaml.Unmarshal(blob, &conf) + + return conf, err } // Blob returns an array of bytes containing @@ -100,7 +99,7 @@ func Blob(conf *payloads.Configure) (blob []byte, err error) { // ExtractBlob returns a configuration payload. // It could be used by the SSNTP server or some other entity. -func ExtractBlob(uri string) (payload []byte, err error) { +func ExtractBlob(uri string) (blob []byte, err error) { var d driver driverType, err := discoverDriver(uri) if err != nil { @@ -116,9 +115,9 @@ func ExtractBlob(uri string) (payload []byte, err error) { if err != nil { return nil, err } - payload, err = Blob(&conf) + blob, err = Blob(&conf) if err != nil { return nil, err } - return payload, nil + return blob, nil } diff --git a/configuration/configuration_test.go b/configuration/configuration_test.go index f6daf7ead..e96e03107 100644 --- a/configuration/configuration_test.go +++ b/configuration/configuration_test.go @@ -162,8 +162,7 @@ func fillPayload(conf *payloads.Configure) { } func testPayload(t *testing.T, blob []byte, expectedConf payloads.Configure, positive bool) { - var conf payloads.Configure - err := Payload(blob, &conf) + conf, err := Payload(blob) // expected FAIL if positive == false && err == nil { diff --git a/configuration/file.go b/configuration/file.go index e2a8842d3..7e79ced21 100644 --- a/configuration/file.go +++ b/configuration/file.go @@ -52,8 +52,8 @@ func (f *file) fetchConfiguration(uriStr string) (conf payloads.Configure, err e if err != nil { return conf, err } - fillDefaults(&conf) - err = Payload(yamlConf, &conf) + + conf, err = Payload(yamlConf) if err != nil { return conf, err }