[NEXTGEN-18139] Incorrect syntax/usage of nz_azConnector command run should return error#13
Draft
Jathar-Amruta wants to merge 4 commits into
Draft
[NEXTGEN-18139] Incorrect syntax/usage of nz_azConnector command run should return error#13Jathar-Amruta wants to merge 4 commits into
Jathar-Amruta wants to merge 4 commits into
Conversation
Signed-off-by: Amruta_Jathar <Amruta.Jathar@ibm.com>
aniket-s-kulkarni
suggested changes
Feb 2, 2023
aniket-s-kulkarni
left a comment
There was a problem hiding this comment.
You should probably run gofmt
| filesuploaded++ // this is fine, since this is single threaded increment | ||
| } | ||
| } | ||
| if (*othargs.upload) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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]") |
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) |
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) | ||
| } |
There was a problem hiding this comment.
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)
}
}Signed-off-by: Amruta_Jathar <Amruta.Jathar@ibm.com>
Contributor
|
Thanks @aniket-s-kulkarni for your suggestion. Your Suggestion have been implemented into this PR #14 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.