Class: Piedesaint::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/piedesaint/cli.rb

Overview

The CLI class encapsulates the behavior of Piedesaint when it is invoked as a command-line utility. This allows other programs to embed Piedesaint and preserve its command-line semantics.

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



12
13
# File 'lib/piedesaint/cli.rb', line 12

def initialize
end

Instance Method Details

#cert(cert_subject = 'CN=Piedesaint') ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/piedesaint/cli.rb', line 54

def cert ( cert_subject = 'CN=Piedesaint' )
  key, cert = create_ssl_artifacts

  FileUtils.mkdir_p ".piedesaint"
  FileUtils.cd ".piedesaint" do
    FileUtils.mkdir_p "ssl"
    FileUtils.cd "ssl" do
      open 'server.key', 'w' do |io| io.write key.to_pem end
      open 'server.crt', 'w' do |io| io.write cert.to_pem end
    end
  end
end

#executeObject



15
16
17
18
19
# File 'lib/piedesaint/cli.rb', line 15

def execute
  load_config
  piedesanto = Piedesaint.new @config
  piedesanto.start
end

#init(parameters = []) ⇒ Object



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
# File 'lib/piedesaint/cli.rb', line 21

def init ( parameters = [] )
  if File.exist?(".piedesaint")
    abort "Configuration already exists at #{Dir.pwd}/.piedesaint"
  end
  key, cert = create_ssl_artifacts

  FileUtils.mkdir_p ".piedesaint"
  FileUtils.cd ".piedesaint" do
    FileUtils.mkdir_p "ssl"
    FileUtils.cd "ssl" do
      open 'server.key', 'w' do |io| io.write key.to_pem end
      open 'server.crt', 'w' do |io| io.write cert.to_pem end
    end

    config = { host: "0.0.0.0",
                http_port: 8080,
                https_port: 9292,
                key: File.join(".", ".piedesaint", "ssl", "server.key" ),
                cert: File.join(".", ".piedesaint", "ssl", "server.crt" ),
                username: "user",
                password: "password",
                freshness: 3600,
                metastore: 'file:/tmp/rack/meta',
                entitystore: 'file:/tmp/rack/body',
                tar: true,
                folders: parameters }

    open 'config', 'w' do |io| io.write config.to_yaml end
  end

  puts "Configuration created at #{Dir.pwd}/.piedesaint"
end