Class: FakeS3::CLI

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

Instance Method Summary collapse

Instance Method Details

#serverObject



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
58
59
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
87
88
89
90
91
# File 'lib/fakes3/cli.rb', line 25

def server
  license_key = options[:license]
  if license_key.nil?
    license_message = """
======================
As of version 1.3, Fake S3 requires a license key passed with --license YOUR_LICENSE_KEY.
Please fix this before September 18, 2018.
You can get a license at:
https://supso.org/projects/fake-s3
======================

"""
    licensing_required = Time.now > Time.utc(2018, 9, 19)
    if licensing_required
      abort license_message
    else
      warn license_message
    end
  end
  
  store = nil
  if options[:root]
    root = File.expand_path(options[:root])
    # TODO Do some sanity checking here
    store = FileStore.new(root, !!options[:quiet])
  end

  if store.nil?
    abort "You must specify a root to use a file store (the current default)"
  end

  hostname = 's3.amazonaws.com'
  if options[:hostname]
    hostname = options[:hostname]
    # In case the user has put a port on the hostname
    if hostname =~ /:(\d+)/
      hostname = hostname.split(":")[0]
    end
  end

  if options[:limit]
    begin
      store.rate_limit = options[:limit]
    rescue
      abort $!.message
    end
  end

  cors_options = {}
  cors_options['allow_origin'] = options[:corsorigin] if options[:corsorigin]
  cors_options['allow_methods'] = options[:corsmethods] if options[:corsmethods]
  cors_options['preflight_allow_headers'] = options[:corspreflightallowheaders] if options[:corspreflightallowheaders]
  cors_options['post_put_allow_headers'] = options[:corspostputallowheaders] if options[:corspostputallowheaders]
  cors_options['expose_headers'] = options[:corsexposeheaders] if options[:corsexposeheaders]

  address = options[:address]
  ssl_cert_path = options[:sslcert]
  ssl_key_path = options[:sslkey]

  if (ssl_cert_path.nil? && !ssl_key_path.nil?) || (!ssl_cert_path.nil? && ssl_key_path.nil?)
    abort "If you specify an SSL certificate you must also specify an SSL certificate key"
  end

  puts "Loading Fake S3 with #{root} on port #{options[:port]} with hostname #{hostname}" unless options[:quiet]
  server = FakeS3::Server.new(address,options[:port],store,hostname,ssl_cert_path,ssl_key_path, quiet: !!options[:quiet], cors_options: cors_options)
  server.serve
end

#versionObject



94
95
96
97
98
99
100
101
# File 'lib/fakes3/cli.rb', line 94

def version
  puts <<"EOF"
======================
FakeS3 #{FakeS3::VERSION}

Copyright 2012, Curtis Spencer (@jubos)
EOF
end