lib/fakes3/cli.rb in fakes3-1.2.1 vs lib/fakes3/cli.rb in fakes3-1.3.0
- old
+ new
@@ -13,12 +13,37 @@
method_option :hostname, :type => :string, :aliases => '-H', :desc => "The root name of the host. Defaults to s3.amazonaws.com."
method_option :quiet, :type => :boolean, :aliases => '-q', :desc => "Quiet; do not write anything to standard output."
method_option :limit, :aliases => '-l', :type => :string, :desc => 'Rate limit for serving (ie. 50K, 1.0M)'
method_option :sslcert, :type => :string, :desc => 'Path to SSL certificate'
method_option :sslkey, :type => :string, :desc => 'Path to SSL certificate key'
+ method_option :corsorigin, :type => :string, :desc => 'Access-Control-Allow-Origin header return value'
+ method_option :corsmethods, :type => :string, :desc => 'Access-Control-Allow-Methods header return value'
+ method_option :corspreflightallowheaders, :type => :string, :desc => 'Access-Control-Allow-Headers header return value for preflight OPTIONS requests'
+ method_option :corspostputallowheaders, :type => :string, :desc => 'Access-Control-Allow-Headers header return value for POST and PUT requests'
+ method_option :corsexposeheaders, :type => :string, :desc => 'Access-Control-Expose-Headers header return value'
+ method_option :license, :type => :string, :desc => 'Your license key, available at https://supso.org/projects/fake-s3'
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])
@@ -43,19 +68,26 @@
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 FakeS3 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])
+ 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
desc "version", "Report the current fakes3 version"
def version