Class: Bitca::Main
- Inherits:
-
Object
- Object
- Bitca::Main
- Defined in:
- lib/bitca/main.rb
Class Method Summary collapse
Instance Method Summary collapse
- #generate(hostname, options) ⇒ Object
- #init ⇒ Object
-
#initialize(config_path) ⇒ Main
constructor
A new instance of Main.
- #show(hostname, options) ⇒ Object
Constructor Details
#initialize(config_path) ⇒ Main
Returns a new instance of Main.
11 12 13 14 15 16 |
# File 'lib/bitca/main.rb', line 11 def initialize(config_path) raise ConfigMissingError, "Config '#{File.(config_path)}' does not exist" unless File.exists?(config_path) @config = symbolize_keys(YAML.load_file(config_path)) @ca = CertificateAuthority.new(@config[:path], @config[:keysize], @config[:days]) @pwdgen = Pwdgen.new(@config[:path], @config[:pwdsize]) end |
Class Method Details
.print_sample_config ⇒ Object
7 8 9 |
# File 'lib/bitca/main.rb', line 7 def self.print_sample_config STDOUT.puts(File.read("#{APP_DIR}/config/sample_config.yml")) end |
Instance Method Details
#generate(hostname, options) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bitca/main.rb', line 27 def generate(hostname, ) raise "CA not initialized" unless @ca.ca_exists? unless [:pwd_only] if @ca.list.include?(hostname) && ![:force] raise "Keys for #{hostname} already exist" else @ca.genkey hostname @ca.genreq hostname @ca.sign hostname end end unless [:keys_only] if @pwdgen.list.include?(hostname) && ![:force] raise "Password for #{hostname} already exists" else @pwdgen.genpwd hostname end end end |
#init ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/bitca/main.rb', line 18 def init unless @ca.ca_exists? @ca.genca @config @pwdgen.init else raise "CA already initialized" end end |
#show(hostname, options) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/bitca/main.rb', line 49 def show(hostname, ) raise "CA not initialized" unless @ca.ca_exists? ret = {} unless [:pwd_only] if @ca.list.include?(hostname) ret.merge!(@ca.get_bundle(hostname)) else raise "Keys for #{hostname} do not exist" end end unless [:keys_only] if @pwdgen.list.include?(hostname) ret.merge!({:password => @pwdgen.getpwd(hostname)}) else raise "Password for #{hostname} does not exist" end end ret end |