Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
lib/tasks: added the portus:create_registry task
Browse files Browse the repository at this point in the history
Moreover, the portus:create_user taks has now a check preventing to create
users if there is no registry.

Fixes #1036

Signed-off-by: Miquel Sabaté Solà <[email protected]>
  • Loading branch information
mssola committed Aug 31, 2016
1 parent bf04374 commit ec0d006
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions lib/tasks/portus.rake
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,63 @@ namespace :portus do
)
end

desc "Create a registry"
task :create_registry, [:name, :hostname, :use_ssl, :external] => :environment do |_, args|
if args.count != 3 && args.count != 4
puts "There are 3 required arguments and an optional one"
exit(-1)
end

args.each do |k, v|
if v.empty? && k != :external
puts "You have to provide a value for `#{k}'"
exit(-1)
end
end

if Registry.count > 0
puts "There is already a registry configured!"
exit(-1)
end

registry = Registry.new(
name: args[:name],
hostname: args[:hostname],
use_ssl: args[:use_ssl],
external_hostname: args[:external]
)
msg = registry.reachable?
unless msg.empty?
puts "\nRegistry not reachable:\n#{registry.inspect}\n#{msg}\n"
exit(-1)
end
registry.save
end

desc "Create a user"
task :create_user, [:username, :email, :password, :admin] => :environment do |_, args|
if args.count != 4
puts "There are 4 required arguments"
exit(-1)
end

args.each do |k, v|
if v.empty?
puts "You have to provide a value for `#{k}'"
exit(-1)
end
end

unless Registry.any?
puts <<HERE
ERROR: There is no registry on the DB! You can either call the portus:create_registry
task, or log in as an administrator into Portus and fill in the form that
will be presented to you.
HERE
exit(-1)
end

u = User.create!(
username: args["username"],
password: args["password"],
Expand Down

0 comments on commit ec0d006

Please sign in to comment.