Skip to content

Commit

Permalink
Merge 8932ecc into 1719872
Browse files Browse the repository at this point in the history
  • Loading branch information
winebarrel committed Jan 10, 2019
2 parents 1719872 + 8932ecc commit 31dd323
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions lib/ridgepole/cli/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,19 @@ def parse_config_file(path)
def parse_database_url(config)
uri = URI.parse(config)

raise "Invalid config: #{config.inspect}" if [uri.scheme, uri.user, uri.host, uri.path].any? { |i| i.nil? || i.empty? }
%w[scheme user host path].each do |key|
value = uri.send(key)

if value.nil? || value.empty?
key = 'database' if key == 'path'
raise "Invalid config: '#{key}' is empty: #{config.inspect}"
end
end

{
'adapter' => uri.scheme,
'username' => CGI.unescape(uri.user),
'password' => CGI.unescape(uri.password),
'password' => uri.password ? CGI.unescape(uri.password) : nil,
'host' => uri.host,
'port' => uri.port,
'database' => CGI.unescape(uri.path.sub(%r{\A/}, '')),
Expand Down
2 changes: 1 addition & 1 deletion spec/mysql/cli/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
specify do
expect do
subject
end.to raise_error 'Invalid config: "database.yml"'
end.to raise_error %(Invalid config: 'scheme' is empty: "database.yml")
end
end

Expand Down

0 comments on commit 31dd323

Please sign in to comment.