From e3e7be41330b3cdb15aef2d0c69ec09377ded69f Mon Sep 17 00:00:00 2001 From: Kiran Kamineni Date: Mon, 8 Oct 2018 14:25:37 -0700 Subject: 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 --- sms-service/src/preload/preload.go | 16 +++++++++++----- 1 file 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 -- cgit 1.2.3-korg