Sha256: a4f05a49fd43adaff22cb9fb35f838a54df18741b36d2972ece9752e5b4074c3

Contents?: true

Size: 1003 Bytes

Versions: 3

Compression:

Stored size: 1003 Bytes

Contents

module RabbitMQ::Definition
  class Create < Command
    def initialize(client, verbose, vhosts)
      super(client, verbose)
      @vhosts = (vhosts || []).compact
      if @vhosts.empty?
        @vhosts = ask("-> What vhosts do you want to create? (comma separated list)".yellow, lambda { |str| str.split(/,\s*/) })
      end
    end

    def execute
      if FileDefinition.exists?
        Logger.error "Definition file already exists in #{FileDefinition.file_path}"
      else
        @vhosts.each do |vhost|
          Logger.progress "Creating vhost '#{vhost}'" if verbose
          client.create_vhost(vhost)
          Logger.progress "Adding permissions for '#{user}' to vhost '#{vhost}'" if verbose
          client.update_permissions_of(vhost, user, all_permissions)
        end
        Dump.run(client, false, @vhosts)
      end
    end

    private

    def all_permissions
      {
        :configure => ".*",
        :write     => ".*",
        :read       => ".*"
      }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rabbitmq-definition-0.1.2 lib/rabbitmq_definition/create.rb
rabbitmq-definition-0.1.1 lib/rabbitmq_definition/create.rb
rabbitmq-definition-0.1.0 lib/rabbitmq_definition/create.rb