Skip to content
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

add output-file flag #60

Merged
merged 2 commits into from
Apr 18, 2019
Merged

add output-file flag #60

merged 2 commits into from
Apr 18, 2019

Conversation

rbren
Copy link
Contributor

@rbren rbren commented Apr 17, 2019

No description provided.

Copy link
Contributor

@robscott robscott left a comment

Choose a reason for hiding this comment

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

This looks really promising, thanks for getting this in!

main.go Outdated

client := &http.Client{}
resp, err := client.Do(req)
fmt.Println(string(y))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a call to os.Stdout.Write could be better here. https://godoc.org/os#File.Write

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

main.go Outdated
}
defer resp.Body.Close()

body, _ := ioutil.ReadAll(resp.Body)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should likely not ignore the potential error in the response from ioutil.ReadAll (https://golang.org/pkg/io/ioutil/#ReadAll)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I get for copy/pasting from Stack Overflow

k, _ := kube.CreateKubeAPI()
auditData, err := validator.RunAudit(c, k)
if err != nil {
panic(err)
}

if destination != "" {
jsonData, err := json.Marshal(auditData)
if outputURL == "" && outputFile == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this whole section be restructured to something like:

if outputURL != "" {
  # send to url
} else if outputFile != "" {
  # send to file
} else {
  # send to stdout
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's I originally had it, but

  • There's some common logic for outputURL and outputFile for serializing to JSON
  • We need to output to both file and URL in some cases (e.g. the hosted version needs this)

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 that makes a lot of sense

@rbren rbren merged commit fde119b into master Apr 18, 2019
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.

2 participants