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 flag to conjurctl server to skip migrations #2895

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Telemetry support
[cyberark/conjur#2854](https://github.com/cyberark/conjur/pull/2854)

### Added
- New flag to `conjurctl server` command called `--no-migrate` which allows for skipping
Copy link

Choose a reason for hiding this comment

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

Lists should be surrounded by blank lines

the database migration step when starting the server.
[cyberark/conjur#2895](https://github.com/cyberark/conjur/pull/2895)

### Fixed
- Support Authn-IAM regional requests when host value is missing from signed headers.
[cyberark/conjur#2827](https://github.com/cyberark/conjur/pull/2827)
Expand Down
7 changes: 6 additions & 1 deletion bin/conjur-cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
c.default_value(ENV['PORT'] || '80')
c.flag [ :p, :port ]

c.desc 'Skip running database migrations on start'
c.default_value false
Copy link

Choose a reason for hiding this comment

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

Use parentheses for method calls with arguments.

c.switch :'no-migrate'

c.desc 'Server bind address'
c.default_value(ENV['BIND_ADDRESS'] || '0.0.0.0')
c.arg_name :ip
Expand All @@ -55,7 +59,8 @@
password_from_stdin: options["password-from-stdin"],
file_name: options[:file],
bind_address: options[:'bind-address'],
port: options[:port]
port: options[:port],
no_migrate: options[:'no-migrate']
)
end
end
Expand Down
10 changes: 8 additions & 2 deletions bin/conjur-cli/commands/server.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# frozen_string_literal: true

require 'command_class'
require 'sequel'

# Required to use $CHILD_STATUS
require 'English'

require_relative 'db/migrate'
require_relative 'connect_database'

module Commands
Server ||= CommandClass.new(
dependencies: {
migrate_database: DB::Migrate.new
migrate_database: DB::Migrate.new,
connect_database: ConnectDatabase.new
},

inputs: %i[
Expand All @@ -19,14 +22,17 @@ module Commands
file_name
bind_address
port
no_migrate
]
) do
def call
# Ensure the database is available
# and the schema is up-to-date
@migrate_database.call(
preview: false
)
) unless @no_migrate

@connect_database.call if @no_migrate
micahlee marked this conversation as resolved.
Show resolved Hide resolved

# Create and bootstrap the initial
# Conjur account and policy
Expand Down
76 changes: 76 additions & 0 deletions spec/conjurctl/commands/server_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
require 'spec_helper'

require 'commands/server'

describe Commands::Server do

let(:account) { "demo" }
let(:password_from_stdin) { false }
let(:file_name) { nil }
let(:bind_address) { "0.0.0.0" }
let(:port) { 80 }
let(:no_migrate) { false }

let(:migrate_database) {
double('DB::Migrate').tap do |migrate|
allow(migrate).to receive(:call).with(preview: false)
end
}
let(:connect_database) {
double('ConnectDatabase').tap do |connect|
allow(connect).to receive(:call)
end
}

before do
# Squash process forking for these tests as we have not implemented a full test
# suite and it causes issues
allow(Process).to receive(:fork).and_return(nil)
allow(Process).to receive(:waitall).and_return(nil)
end

def delete_account(name)
system("conjurctl account delete #{name}")
end

after(:each) do
delete_account("demo")
end


subject do
Commands::Server.new(
migrate_database: migrate_database,
connect_database: connect_database
).call(
account: account,
password_from_stdin: password_from_stdin,
file_name: file_name,
bind_address: bind_address,
port: port,
no_migrate: no_migrate
)
end

it "performs migrations" do
expect(migrate_database).to receive(:call)

subject
end

context "With the no_migrate variable set to true" do
let(:no_migrate) { true }

it "doesn't perform migrations" do
expect(migrate_database).not_to receive(:call)

subject
end

it "connects to the database" do
expect(connect_database).to receive(:call)

subject
end
end
end