Class: Cogy::CogyController

Inherits:
ApplicationController show all
Defined in:
app/controllers/cogy/cogy_controller.rb

Instance Method Summary collapse

Instance Method Details

#commandObject

GET <mount_path>/cmd/:cmd/:user

The command endpoint is the one that the cogy executable (see github.com/skroutz/cogy-bundle hits. It executes the requested Cogy::Command and responds back the result, which is then printed to the user by the cogy executable.

See github.com/skroutz/cogy-bundle.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/cogy/cogy_controller.rb', line 13

def command
  cmd = params[:cmd]
  args = request.query_parameters.select { |k,_| k =~ /\Acog_argv_/ }.values
  opts = request.query_parameters.select { |k,_| k =~ /\Acog_opt_/ }
    .transform_keys { |k| k.sub("cog_opt_", "") }
  cogy_env = request.query_parameters.select { |k,_| k =~ /\Acogy_/ }
  user = params[:user]

  begin
    if (command = Cogy.commands[cmd])
      context = Context.new(args, opts, user, cogy_env)
      render text: context.run!(command)
    else
      render status: 404, text: "The command '#{cmd}' does not exist."
    end
  rescue => e
    @user = user
    @cmd = cmd
    @exception = e
    respond_to do |format|
      format.any do
        render "/cogy/error.text.erb", content_type: "text/plain", status: 500
      end
    end
  end
end

#inventoryObject

GET <mount_path>/inventory

The inventory endpoint, is essentially the bundle config in YAML format, which is installable by Cog. It is typically installed by the ‘cogy:install` command (see github.com/skroutz/cogy-bundle).



45
46
47
# File 'app/controllers/cogy/cogy_controller.rb', line 45

def inventory
  render text: Cogy.bundle_config.to_yaml, content_type: "application/x-yaml"
end