Class: Confman::CLI
- Inherits:
-
Object
- Object
- Confman::CLI
- Defined in:
- lib/confman/cli.rb
Constant Summary collapse
- @@options =
{}
- @@opt_parser =
nil
Class Method Summary collapse
- .export ⇒ Object
- .exportall ⇒ Object
- .init ⇒ Object
- .keyd ⇒ Object
- .reset_keys ⇒ Object
- .start(args) ⇒ Object
Class Method Details
.export ⇒ Object
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/confman/cli.rb', line 106 def self.export out = [:outputfile] ? File.open([:outputfile], "w") : STDOUT begin conf_set = Confman.api.find_by_name([:name]) out.write(conf_set.to_json) rescue RestClient::ResourceNotFound Confman.logger.error("ConfSet #{@@options[:name]} not found") end end |
.exportall ⇒ Object
101 102 103 104 |
# File 'lib/confman/cli.rb', line 101 def self.exportall out = [:outputfile] ? File.open([:outputfile], "w") : STDOUT out.write(Confman.api.conf_sets) end |
.init ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/confman/cli.rb', line 60 def self.init config_hash = Confman.api.load_config || {} config_hash.symbolize_keys! %w(endpoint_url api_key secret).each do |c| if [c.to_sym].blank? puts "Please enter your #{c}: [#{config_hash[c.to_sym]}]" value = STDIN.gets.chomp unless value.blank? config_hash[c.to_sym] = value end else config_hash[c.to_sym] = [c.to_sym] end end # Write to file File.open Confman.api.config_path, "w" do |file| file.write(config_hash.to_json) end Confman.api.load_config Confman.api.reset_server_key! end |
.keyd ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/confman/cli.rb', line 92 def self.keyd Daemons.run_proc('keyd') do loop do reset_keys sleep(60) end end end |
.reset_keys ⇒ Object
88 89 90 |
# File 'lib/confman/cli.rb', line 88 def self.reset_keys Confman.access.reset_keys end |
.start(args) ⇒ Object
9 10 11 12 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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/confman/cli.rb', line 9 def self.start(args) Confman.logger.level = 2 command = args.shift begin Confman.api.load_config rescue Errno::EACCES => ex Confman.logger.error("Unable to load config: #{ex}\nPlease run 'confman init' as root to continue") exit end @@opt_parser = OptionParser.new do |opt| opt. = "Usage: confman COMMAND OPTIONS" opt.separator "" opt.separator "Commands" opt.separator " exportall -f <outputfile>: Imports all the conf sets into a file." opt.separator " export -n <name> -f <outputfile>: Imports conf_set named 'name' into a file." opt.separator " init -e <endpoint> -k <key>: Sets up config. Run this before querying the ConfMan server.(run as root)" opt.separator " reset_keys: Resets authorized keys for the current user." opt.separator " keyd: Periodically Resets authorized keys for the current user" opt.separator "" opt.separator "Options" opt.on('-k key', String, 'ConfMan API Key') do |key| [:key] = key end opt.on('-e endpoint', String, 'ConfMan API Endpoint') do |ep| [:endpoint] = ep end opt.on('-f outputfile', String, 'Output file') do |of| [:outputfile] = of end opt.on('-n name', String, 'Name') do |name| [:name] = name end end @@opt_parser.parse!(args) if command && respond_to?(command) send(command) else puts @@opt_parser end end |