2014-05-08 15:34:26 +04:00
|
|
|
require "devops-client/handler/handler"
|
|
|
|
|
require "devops-client/options/key_options"
|
|
|
|
|
require "json"
|
|
|
|
|
require "devops-client/output/key"
|
|
|
|
|
|
|
|
|
|
class Key < Handler
|
2015-04-14 15:29:02 +03:00
|
|
|
|
|
|
|
|
output_with Output::Key
|
2014-05-08 15:34:26 +04:00
|
|
|
|
|
|
|
|
def initialize(host, def_options={})
|
2015-04-14 15:29:02 +03:00
|
|
|
@host, @options = host, def_options
|
2014-05-08 15:34:26 +04:00
|
|
|
@options_parser = KeyOptions.new(ARGV, def_options)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def handle
|
2018-04-04 22:44:39 +03:00
|
|
|
@command, @options, @args = @options_parser.parse_options_for!
|
|
|
|
|
extract_parameters
|
|
|
|
|
case @command
|
2015-04-14 15:29:02 +03:00
|
|
|
when :list
|
2014-05-08 15:34:26 +04:00
|
|
|
list_handler
|
|
|
|
|
output
|
2015-04-14 15:29:02 +03:00
|
|
|
when :delete
|
|
|
|
|
delete_handler
|
|
|
|
|
when :add
|
|
|
|
|
add_handler
|
2014-05-08 15:34:26 +04:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-14 15:29:02 +03:00
|
|
|
def add_handler
|
2018-04-04 22:44:39 +03:00
|
|
|
content = File.read(@file)
|
2014-05-08 15:34:26 +04:00
|
|
|
q = {
|
2018-04-04 22:44:39 +03:00
|
|
|
"key_name" => @key_name,
|
|
|
|
|
"file_name" => File.basename(@file),
|
2014-05-08 15:34:26 +04:00
|
|
|
"content" => content
|
|
|
|
|
}
|
2018-04-04 22:44:39 +03:00
|
|
|
json = JSON.pretty_generate(q)
|
|
|
|
|
post_body "/key", json if question(I18n.t("handler.key.question.create")){puts json}
|
2014-05-08 15:34:26 +04:00
|
|
|
end
|
|
|
|
|
|
2015-04-14 15:29:02 +03:00
|
|
|
def delete_handler
|
2018-04-04 22:44:39 +03:00
|
|
|
delete "/key/#{@key_name}" if question(I18n.t("handler.key.question.delete", :name => @key_name))
|
2014-05-08 15:34:26 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def list_handler
|
|
|
|
|
@list = get("/keys")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|