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

fail gracefully on inspec compliance profiles when bad token is provided #930

Merged
merged 2 commits into from
Aug 18, 2016

Conversation

vjeffrey
Copy link

just a quick fix to handle inspec compliance profiles when an incorrect token has been previously provided.
screen shot 2016-08-17 at 12 18 02 pm
@chris-rock

@@ -36,6 +36,7 @@ def self.profiles(config)
end
end.flatten
else
puts '401 Unauthorized. Please check your token.'
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure the only case where data == '' is a 401? My first impression when reading this code is that I'm a bit surprised that this isn't a case statement on the http response code. Also, if possible it feels like this is a case where we would want to exit with a non-zero exit status.

Copy link
Author

Choose a reason for hiding this comment

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

good point, thanks!! ya, i'll rework this a bit later -- a case statement on the http response code sounds like the right thing to do there

Copy link
Contributor

Choose a reason for hiding this comment

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

agree with @stevendanna we should check the http code

puts '401 Unauthorized. Please check your token.'
[]
else
puts response_code
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 add a message that indicates an error. I assume most users do not know http codes by heart ;-)

Copy link
Author

Choose a reason for hiding this comment

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

oops, ya! i'll add it :)

@vjeffrey
Copy link
Author

i'm getting some odd travis failures on ubuntu.... :(

else
puts response_code, 'An error occured'
Copy link
Author

Choose a reason for hiding this comment

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

is this ok? @chris-rock or were you thinking something else/more specific?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not familiar with the compliance API, but response.message will typically be filled with the error message that the server sent back, so you might try something like:

puts "An unexpected error occurred (HTTP #{response_code}): #{response.message}"

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool idea @stevendanna

Copy link
Contributor

Choose a reason for hiding this comment

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

In addition to that the API class should not do any output. Only the cli class should do that. therefore we need to return the message as the other methods do it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Only the cli class should do that. therefore we need to return the message as the other methods do it.

👍 On this. I was going to potentially recommending creating a custom exception that you could raise in the case of an HTTP error. The exception can contain the message the cli class should print on rescue. However, I noticed that this code base stays away from exceptions for the most part.

Copy link
Author

@vjeffrey vjeffrey Aug 18, 2016

Choose a reason for hiding this comment

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

oooh nice! thanks! i'll add the message stuff and have the api class the return the message so the cli class can take care of the output :)

Copy link
Contributor

Choose a reason for hiding this comment

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

@stevendanna the whole API implementation needs a refactor, because I want to merge it with the content in our audit cookbook. But lets not address this in that iteration

@chris-rock chris-rock force-pushed the vj/fix-cli-profiles-output-bad-token branch from d4afa0b to cf784de Compare August 18, 2016 17:40
@chris-rock chris-rock merged commit a2cbe6e into master Aug 18, 2016
@chris-rock chris-rock deleted the vj/fix-cli-profiles-output-bad-token branch August 18, 2016 17:54
@chris-rock chris-rock modified the milestone: 0.31.0 Aug 18, 2016
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.

None yet

4 participants