summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2018-10-08 14:25:37 -0700
committerKiran Kamineni <kiran.k.kamineni@intel.com>2018-10-08 15:29:56 -0700
commite3e7be41330b3cdb15aef2d0c69ec09377ded69f (patch)
treec80f787ace060a03f3c359cc68bded8c1d53bf3f
parent513d6baa67fe8ba8b192132f7efea1467df660ad (diff)
Fix bug in directory read with json files
The cmdline tool to preload json files is reading from CWD instead of using the provided commandline dir. Issue-ID: AAF-544 Change-Id: I8af23f0556ff678c33223e6f6acac402a39dd662 Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
-rw-r--r--sms-service/src/preload/preload.go16
1 files changed, 11 insertions, 5 deletions
diff --git a/sms-service/src/preload/preload.go b/sms-service/src/preload/preload.go
index cbf345f..af6e1f6 100644
--- a/sms-service/src/preload/preload.go
+++ b/sms-service/src/preload/preload.go
@@ -28,7 +28,6 @@ import (
"net/http"
"net/url"
"path/filepath"
- "strconv"
"strings"
"time"
@@ -213,19 +212,26 @@ func main() {
"Path to the CA Certificate file")
serviceurl := flag.String("serviceurl", "https://aaf-sms.onap",
"Url for the SMS Service")
- serviceport := flag.Int("serviceport", 10443,
+ serviceport := flag.String("serviceport", "10443",
"Service port if its different than the default")
jsondir := flag.String("jsondir", ".",
"Folder containing json files to upload")
flag.Parse()
+ //Clear all trailing/leading spaces from incoming strings
+ *cacert = strings.TrimSpace(*cacert)
+ *serviceurl = strings.TrimSpace(*serviceurl)
+ *serviceport = strings.TrimSpace(*serviceport)
+ *jsondir = strings.TrimSpace(*jsondir)
+
files, err := ioutil.ReadDir(*jsondir)
if err != nil {
log.Fatal(pkgerrors.Cause(err))
}
- serviceURL, err := url.Parse(*serviceurl + ":" + strconv.Itoa(*serviceport))
+ //URL validity is checked here
+ serviceURL, err := url.Parse(*serviceurl + ":" + *serviceport)
if err != nil {
log.Fatal(pkgerrors.Cause(err))
}
@@ -239,8 +245,8 @@ func main() {
for _, file := range files {
if filepath.Ext(file.Name()) == ".json" {
- fmt.Println("Processing ", file.Name())
- d, err := processJSONFile(file.Name())
+ fmt.Println("Processing ", filepath.Join(*jsondir, file.Name()))
+ d, err := processJSONFile(filepath.Join(*jsondir, file.Name()))
if err != nil {
log.Printf("Error Reading %s : %s", file.Name(), pkgerrors.Cause(err))
continue