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

Print Conjur version only on server startup #1590

Merged
merged 4 commits into from
Jun 7, 2020
Merged

Conversation

orenbm
Copy link
Member

@orenbm orenbm commented Jun 4, 2020

Connected to #1589

We recently started to print the Conjur version on server startup:

root@094a586bdea9:/opt/conjur-server# conjurctl server
CONJ00037I Conjur v1.7.1 starting up...
=> Booting Puma
=> Rails 5.2.4.3 application starting in production
=> Run `rails server -h` for more startup options

However, this message is written for every conjurctl command. For example:

root@094a586bdea9:/opt/conjur-server# conjurctl role retrieve-key cucumber:user:some-user
CONJ00037I Conjur v1.7.1 starting up...
error: role does not exist: cucumber:user:some-user
error: key retrieval failed

This PR changes the behaviour so that the message is printed only on server startup.

After the change, the output of conjurctl server is:

root@094a586bdea9:/opt/conjur-server# conjurctl server
Conjur v1.7.1 starting up...
=> Booting Puma
=> Rails 5.2.4.3 application starting in production
=> Run `rails server -h` for more startup options

and the output of conjurctl role is:

root@094a586bdea9:/opt/conjur-server# conjurctl role retrieve-key cucumber:user:some-user
error: role does not exist: cucumber:user:some-user
error: key retrieval failed

@orenbm orenbm requested a review from moticless June 4, 2020 10:48
@orenbm orenbm self-assigned this Jun 4, 2020
@orenbm orenbm added this to the PalmTree - sprint 2012 milestone Jun 4, 2020
moticless
moticless previously approved these changes Jun 4, 2020
@orenbm orenbm force-pushed the print-version-on-startyp branch 2 times, most recently from efa28f0 to d5c9601 Compare June 4, 2020 11:04
moticless
moticless previously approved these changes Jun 4, 2020
@@ -72,6 +72,9 @@ def test_select
end

Process.fork do
conjur_version = (File.read(File.expand_path("../VERSION", File.dirname(__FILE__)))).strip
Copy link

Choose a reason for hiding this comment

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

Don't use parentheses around a method call.

Copy link
Member

Choose a reason for hiding this comment

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

Can we use some helper variables to make this line less complex? Might solve this codeclimate warning too.

@orenbm orenbm requested a review from a team June 4, 2020 15:06
jtuttle
jtuttle previously requested changes Jun 4, 2020
CHANGELOG.md Outdated
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased
### Fixed
- The Conjur version is now printed on server startup, after running `conjurctl server`
((cyberark/conjur#1590)[https://github.com/cyberark/conjur/pull/1590])
Copy link
Member

Choose a reason for hiding this comment

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

The parens are backwards here. The issue should have square brackets and the link should have parens.

@@ -72,6 +72,9 @@ def test_select
end

Process.fork do
conjur_version = (File.read(File.expand_path("../VERSION", File.dirname(__FILE__)))).strip
Copy link
Member

Choose a reason for hiding this comment

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

Can we use some helper variables to make this line less complex? Might solve this codeclimate warning too.

izgeri
izgeri previously requested changes Jun 4, 2020
Copy link
Contributor

@izgeri izgeri left a comment

Choose a reason for hiding this comment

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

this broke a bunch of downstream projects that rely on conjurctl role retrieve-key

can we please add a test to this PR that validates that this method works (and retrieves a valid key for the specified role) so we catch changes that break it in conjur PRs instead of in downstream pipelines post-tag?

The print that we added didn't print the version only
on server startup, and actually printed it for every `conjurctl`
command. This commit changes this behaviour so the message is
printed only on server startup.
@env.each do |key, value|
ENV[key] = value
end
end
Copy link

Choose a reason for hiding this comment

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

Final newline missing.


Given(/^I set environment variable "([^"]*)" to "([^"]*)"$/) do |variable_name, variable_value|
ENV[variable_name] = variable_value
end
Copy link

Choose a reason for hiding this comment

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

Final newline missing.

@env.each do |key, value|
ENV[key] = value
end
end
Copy link

Choose a reason for hiding this comment

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

Final newline missing.

@@ -0,0 +1,8 @@
Feature: Retrieving an API key with conjurctl

# We need to be in production environment to test this
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain why we need to be in production?

Copy link
Member Author

Choose a reason for hiding this comment

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

because that's the environment our clients will be. When we are in dev env the error doesn't occur

# We need to be in production environment to test this
Scenario: Retrieve an API key
Given I set environment variable "RAILS_ENV" to "production"
And I set environment variable "CONJUR_LOG_LEVEL" to "info"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why setting the conjur_log_level is relevant here?

Copy link
Member Author

Choose a reason for hiding this comment

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

because if we are in debug mode the output will contain some junk. we change the env so we are in the expected environment of the client using this tool.

Copy link
Contributor

Choose a reason for hiding this comment

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

o.k. Since its not suppose to influence the results.
In general i want to work with relevant steps only(in this case its not critical) because if from some reason we will fail on this step we cant say "retrieve an API key" is not working.

@@ -0,0 +1,8 @@
Feature: Retrieving an API key with conjurctl
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add another test to verify we have error when the API is wrong(role does not exist).

Copy link
Member Author

Choose a reason for hiding this comment

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

done


Scenario: Retrieve an API key of a non-existing user fails
When I retrieve an API key for user "cucumber:user:non-existing-user" using conjurctl
Then the stderr includes the error "role does not exist"
Copy link
Contributor

Choose a reason for hiding this comment

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

new line is missing

@@ -0,0 +1,15 @@
require 'open3'


Copy link

Choose a reason for hiding this comment

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

Extra blank line detected.


When(/^I retrieve an API key for user "([^"]*)" using conjurctl$/) do |user_id|
command = "conjurctl role retrieve-key #{user_id}"
@conjurctl_stdout, @conjurctl_stderr, _ = Open3.capture3(command)
Copy link

Choose a reason for hiding this comment

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

Do not use trailing _s in parallel assignment. Prefer @conjurctl_stdout, @conjurctl_stderr, = Open3.capture3(command).

end

Then(/^the stderr includes the error "([^"]*)"$/) do |error|
expect(@conjurctl_stderr).to include("#{error}")
Copy link

Choose a reason for hiding this comment

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

Prefer to_s over string interpolation.

John Tuttle and others added 2 commits June 7, 2020 16:19
Some test manipulate the env so we need to revert to the original
one after each scenario.
@codeclimate
Copy link

codeclimate bot commented Jun 7, 2020

Code Climate has analyzed commit 6dded0d and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 85.6% (0.0% change).

View more on Code Climate.

Copy link
Contributor

@eladkug eladkug left a comment

Choose a reason for hiding this comment

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

Tests approved

@orenbm orenbm dismissed stale reviews from izgeri and jtuttle June 7, 2020 14:31

Added tests as requested

@orenbm orenbm merged commit 90b7e97 into master Jun 7, 2020
@orenbm orenbm deleted the print-version-on-startyp branch June 7, 2020 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants