-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ability to download the calculation by id or value #2
Conversation
cmd/ccboc/main.go
Outdated
|
||
fileName := fmt.Sprintf("%0.1f___%0.1f", teff, logG) | ||
|
||
file, err := os.Create(fileName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, here we should check the error. Second, this will create the file in the current directory. We should have a default location for the downloaded results. Maybe in the same path where we create the configs for this tool?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somehow, I am unable to create the file in another directory. Tried all sorts of functions, different permission..
os.Chdir is not doing the same thing as terminal for me. Couldnt find anything that would help me solve this.
'~/.config/ccboc' nor any other is not working. Only in $pwd. I even tried to jump between the $pwd but that didnt work either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be related to your environment only. I guess permissions? You should be able to write in the ~/.config/ccboc
since we already wrote the configuration files.
cmd/ccboc/main.go
Outdated
|
||
_, err = file.WriteString(string(body)) | ||
if err != nil { | ||
logrus.WithError(err).Fatal("Couldn't write the calculation into the file.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message is wrong. Those data are not a calculation
but bytes from a tar file.
cmd/ccboc/main.go
Outdated
args := os.Args | ||
calcID := args[len(args)-1] | ||
|
||
fmt.Println(globalConfig.APIURL + "/calculations/results/" + calcID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debugging leftover too?
cmd/ccboc/main.go
Outdated
logrus.WithFields(logrus.Fields{"message": responseError.Message, "status_code": responseError.StatusCode}).Fatal("errors occurred") | ||
} | ||
|
||
file, err := os.Create(calcID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. The file is a tar.gz
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also you are not checking the error here.
cmd/ccboc/main.go
Outdated
|
||
defer file.Close() | ||
|
||
_, err = file.WriteString(string(body)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file.Write(body)
b6ff85a
to
bd1cd78
Compare
Hi, |
cmd/ccboc/main.go
Outdated
if path != "" { | ||
defaultPath = filepath.Join(path, filepath.Base(key)) | ||
} else { | ||
defaultPath = filepath.Join("~/.config/ccboc/", filepath.Base("text.txt")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should try to get the $HOME
path like
user, err := user.Current()
if err != nil {
logrus.WithError(err).Fatal("couldn't get $HOME directory from current user")
}
home := user.HomeDir
Also, filepath.Base("text.txt")
will always return text.txt
but it is also wrong since the file will never be just a text file.
cmd/ccboc/main.go
Outdated
} | ||
|
||
if _, err := os.Stat(defaultPath); os.IsNotExist(err) { | ||
logrus.WithError(err).Fatal("The desired file path does not exist.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us have a better error message here. Also, I think it will be better to just print a warning here and then download the file to the default path.
cmd/ccboc/main.go
Outdated
if path != "" { | ||
defaultPath = filepath.Join(path, filepath.Base(calcID)) | ||
} else { | ||
defaultPath = filepath.Join("~/.config/ccboc/", filepath.Base(calcID)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
cmd/ccboc/main.go
Outdated
@@ -222,6 +304,11 @@ func main() { | |||
Name: "logG", | |||
Usage: "specifies the logG value when creating a calculation.", | |||
}, | |||
&cli.StringFlag{ | |||
Name: "path", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
argument named path
is unclear what it does. Let us have a better name, like results-download-path
@@ -249,6 +336,20 @@ func main() { | |||
Usage: "", | |||
Action: getCalculations, | |||
}, | |||
|
|||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets just have one command that belongs in the calculation command. I would expect for the user to just type ccboc get calculation results {id}
or ccboc --logG=4.0 --teff=1000 get calculation results
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gszasz We could use your insight as a user in this one...
c5bac40
to
40cb614
Compare
@droslean Not sure about the implementation of the cli commands. Couldnt find some kind of example of this kind of thing. |
You can check the library in godoc.
Let's have some tests that can check that. |
@droslean Its just not letting me get to the headers locally. Dont know what I can do about it. error="Get "https://apiserver-vega.router.default.svc.cluster.local/calculations/results?teff=9000.0&logg=4.0\": x509: certificate signed by unknown authority" Hopefully, this isnt some stupid way to get to the headers:)
|
You still trying to reach the API server in the cluster. Why not just testing it locally? |
How do I reach it locally? I have no clue what you would mean by that.. |
Run the apiserver locally. It has the dry-run, for the get/create/delete calculations but you don't even care about that. You can just start it by pointing to your results folder, add the Example results folder structure: |
03dc837
to
b3d39ea
Compare
Hi, |
cmd/ccboc/main.go
Outdated
if path != "" { | ||
defaultPath = filepath.Join(path, filepath.Base(newKey[1])) | ||
} else { | ||
logrus.Info("Desired path to download the calculations was not included. The calculations are set to be downloaded into: $HOME/.config/ccboc/{id}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for this log. Instead, just log where we downloaded the results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think the user should know, that the path was not added properly and was not found.
cmd/ccboc/main.go
Outdated
} | ||
|
||
key := resp.Header.Get("Content-Disposition") | ||
newKey := regexp.MustCompile("=").Split(key, 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use strings.Split()
instead.
cmd/ccboc/main.go
Outdated
|
||
var defaultPath string | ||
|
||
user, err := user.Current() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just use conig.GetDefaultConfigPath()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to just have
defaultPath := path
if defaultPath == "" {
defaultPath, err = config.GetDefaultConfigPath()
if err != nil{...}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This rewrites the config file, which causes errors.
DefalultConfigName gets thrown in and generates at defaultPath.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just created a new function really which is pretty much the same thing as this one, but with different fileName.
cmd/ccboc/main.go
Outdated
defaultPath = filepath.Join(home, "/.config/ccboc/", filepath.Base(newKey[1])) | ||
} | ||
|
||
if _, err := os.Stat(defaultPath); !errors.Is(err, os.ErrNotExist) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets have a helper func that creates the results folder in the config
package
b3d39ea
to
43c64d3
Compare
pkg/config/config.go
Outdated
@@ -49,3 +50,28 @@ func GetDefaultConfigPath() (string, error) { | |||
|
|||
return filepath.Join(home, DefaultConfigPath, DefaultConfigFileName), nil | |||
} | |||
|
|||
func GetDefaultPath(fileName string) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new function is a duplicate with GetDefaultConfigPath
. Let's refactor it to get the desired location instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just had to change the name of the file, because 'DefaultConfigName' is set to 'config' and it brakes the config file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, but we still have duplicated code in this function. Instead refactor GetDefaultConfigPath
.
cmd/ccboc/main.go
Outdated
logrus.WithError(err).Fatal("Couldn't retrieve the data from headers.") | ||
} | ||
|
||
key := resp.Header.Get("Content-Disposition") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets use better names rather than key
and newKey
02b5f14
to
1c2a615
Compare
@droslean Function is refactored, variables renamed. Everything seems to be working. Exception errors handled. |
cmd/ccboc/main.go
Outdated
|
||
fileNameHeader := resp.Header.Get("Content-Disposition") | ||
splitFileNameHeader := strings.Split(fileNameHeader, "=") | ||
if len(splitFileNameHeader) == 1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Header.Get()
will return ""
if there is no header. You can make the check earlier.
pkg/config/config.go
Outdated
|
||
if defaultPath == "" { | ||
return filepath.Join(home, DefaultConfigPath, fileName), nil | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need for the else
here.
pkg/config/config.go
Outdated
logrus.Info("Desired path to download the calculations does not exist. The calculations are set to be downloaded into: $HOME/.config/ccboc/{id}") | ||
return filepath.Join(home, "/.config/ccboc/", filepath.Base(fileName)), nil | ||
} | ||
defaultPath = filepath.Join(defaultPath, filepath.Base(fileName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to manipulate this variable that was passed in the function already.
pkg/config/config.go
Outdated
return filepath.Join(home, DefaultConfigPath, fileName), nil | ||
} else { | ||
if _, err := os.Stat(defaultPath); os.IsNotExist(err) { | ||
logrus.Info("Desired path to download the calculations does not exist. The calculations are set to be downloaded into: $HOME/.config/ccboc/{id}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When logging, the user should know all the information about the problem. The desired path
is unclear here. We need to give him the exact path. Also, by handling only the not exists error, we eat all the other potential errors. Instead lets check for all errors and output the error in the screen. There is no need to fallback to the default location, since the user didn't ask for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it to errors.Is(err, os.ErrNotExist)
. Hopefully that's enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I mean we should check all the errors, and output the error to the user. Don't fall back to the default location.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, thats what I did in the latest commit. When there is an error, then we fail. I dont fall to the def. location anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but you are checking only one error case. We need to fail in any error.
2f0021c
to
e8bc6cf
Compare
pkg/config/config.go
Outdated
|
||
_, err = os.Stat(defaultPath) | ||
if err != nil { | ||
return "", fmt.Errorf("something is wrong with the download path of the calculation %v", defaultPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no reason to eat the actual error message with a something is wrong
message. We need the user to know exactly why his actions failed. We need something like:
return "", fmt.Errorf("something is wrong with the download path of the calculation %v", defaultPath) | |
return "", fmt.Errorf("couldn't stat path %s: %v", defaultPath, err) |
e8bc6cf
to
ec3289e
Compare
cmd/ccboc/main.go
Outdated
|
||
fileNameHeader := resp.Header.Get("Content-Disposition") | ||
if fileNameHeader == "" { | ||
logrus.WithError(err).Fatal("Unable to get the headers") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The log here is wrong. The err will be nil since there is no error. Also please be more detailed about which header we failed to get.
cmd/ccboc/main.go
Outdated
|
||
fileNameHeader := resp.Header.Get("Content-Disposition") | ||
if fileNameHeader == "" { | ||
logrus.WithError(err).Fatal("Unable to get the headers") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
ec3289e
to
fb3fe38
Compare
Signed-off-by: Daniel Odvarka <odvarkaadaniel@gmail.com>
fb3fe38
to
26876b2
Compare
Hi,
don't know if we want to create just some kind of txt file or something. For now I just create new file with the name of calculation or it's teff and logG values.
@droslean
Signed-off-by: Daniel Odvarka odvarkaadaniel@gmail.com