Skip to content

[NEXTGEN-18139] Incorrect syntax/usage of nz_azConnector command run should return error#13

Draft
Jathar-Amruta wants to merge 4 commits into
IBM:masterfrom
Jathar-Amruta:Amruta-Fix
Draft

[NEXTGEN-18139] Incorrect syntax/usage of nz_azConnector command run should return error#13
Jathar-Amruta wants to merge 4 commits into
IBM:masterfrom
Jathar-Amruta:Amruta-Fix

Conversation

@Jathar-Amruta
Copy link
Copy Markdown

@Jathar-Amruta Jathar-Amruta commented Feb 2, 2023

Problem: nz_azConnector command was not returning error even when - was not passed to flag in command.

Solution: Set check which ensures that flag is passed with - if not passed with - will return error.

Testing: Tested manually on fyre system for reported conditions and it's working fine.

@Jathar-Amruta Jathar-Amruta marked this pull request as ready for review February 2, 2023 11:08
@Jathar-Amruta Jathar-Amruta reopened this Feb 2, 2023
@Jathar-Amruta Jathar-Amruta marked this pull request as draft February 2, 2023 11:12
Signed-off-by: Amruta_Jathar <Amruta.Jathar@ibm.com>
Copy link
Copy Markdown

@aniket-s-kulkarni aniket-s-kulkarni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably run gofmt

filesuploaded++ // this is fine, since this is single threaded increment
}
}
if (*othargs.upload) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to have messed up the formatting for the next block here.

if r.err != nil {
// stopping right here so that we
// don't keep on uploading when one has failed
log.Println("Error while uploading file. Ensure azure storage account name, azure k ey and container name are correct. If error persists contact IBM suppor t team.", *r.job)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be copy paste mess up

w := io.MultiWriter(os.Stdout, filehandle)
log.SetOutput(w)
prefixStr := fmt.Sprintf("%s ", time.Now().UTC().Format("2006-01-02 15:04:05 EST")) + fmt.Sprintf("%-7s", "[INFO]")
prefixStr := fmt.Sprintf("%s ", time.Now().UTC().Format("2006-01-02 15:04:05 EST")) + fmt.Sprintf("%-7s", "[INFO]")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Comment on lines +404 to +406
fmt.Println("No arguments passed to nz_azConnector. Below is the list of valid args:")
flag.PrintDefaults()
os.Exit(1)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should run gofmt

Comment on lines +392 to +400
requiredFlags := []string{ "db","dir","npshost","storage-account","key","container",
"upload","backupset","uniqueid","logfiledir","streams","paralleljobs","blocksize"}

if flag.NFlag() == 0 {
fmt.Println("No arguments passed to nz_azConnector. Below is the list of valid args:")
for _, flagName := range requiredFlags {
if flag.Lookup(flagName).Value.String() == "" {
fmt.Printf("Error: %s Invalid flag\n", flagName)
flag.PrintDefaults()
os.Exit(1)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to first look at env variables and if not set then error out for required flags

requiredFlags := map[string]string { 
    "db" : "NZ_DATABASE", 
    "dir" : "",
    "npshost" : "NZ_HOST",
    // and so on for the rest.
};

ensureDefault := func(f string, env string) bool {
    val := flag.Lookup(f).Value
    if Value.String() == "" && env != " {
        val.Set(os.Getenv(env));
    }
    return val.String() != "";
}

for f, env := range requiredFlags {
    if !ensureDefault(f, env) {
        fmt.Fprintf(stderr, "-%s is required", f)
        os.Exit(1)
    }
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I will work on this

@Ram-Nerpagar
Copy link
Copy Markdown
Contributor

Ram-Nerpagar commented Mar 30, 2023

Thanks @aniket-s-kulkarni for your suggestion. Your Suggestion have been implemented into this PR #14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants