eucalypt 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab9e3dd1d0d0df1183688e146ebce87a369d4c7b13430169af4fe3e58c9a1deb
4
- data.tar.gz: 8d1811d2f5967a0ffb4de011b1422a9a3cadb8c27595a8f69108a4cacc2b5053
3
+ metadata.gz: 6fa3d16ea8245275cf420eb8ab1dc852e4c0da5f6416f53f09c6636372747806
4
+ data.tar.gz: f7e333eec6111947870dc43454517259d0ec06a42419d56b7c10022493c16e1e
5
5
  SHA512:
6
- metadata.gz: da21a8de24eae9a10d4319dc9543687b5c34cb966d0ce72b47832d005e5b08b79f024166881e8a135166fd07b9c2ec9d76d279bfb0770942f0bc76c1190c692e
7
- data.tar.gz: bbfd6801e3066443bbd0cce2059de11158ff6d96d7efad5adeddb1217527b573ae44a991ced17518a4be060d76d2d8b6d97b51bddcddec96d3b4cc206f4b7e17
6
+ metadata.gz: 00b29405bdef2c7f706f5b906cabdbd6a74b663c1a911e0b2fd82ee06dfdd28f9d489ba33609116505e907097d29b4a846f135c911f3057de1bda2675491d387
7
+ data.tar.gz: 678144c567da5a0fa49019f8a9ca50f5921ae8ddca2693c2e9455a58060ed15a9847e031a4d62ffa479ed00f30ffc806489e79e100836eff6c9894a14e67c7f7
data/eucalypt.gemspec CHANGED
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.add_runtime_dependency "string-builder", "~> 2.3"
28
28
  spec.add_runtime_dependency "activesupport", "~> 5.2"
29
29
  spec.add_runtime_dependency "activerecord", "~> 5.2"
30
+ spec.add_runtime_dependency "bcrypt", "~> 3.1"
30
31
  spec.add_runtime_dependency "front_matter_parser", "0.2.0"
31
32
  spec.add_runtime_dependency "thor", "~> 0.20"
32
33
  spec.add_runtime_dependency "sinatra", "~> 2.0", ">= 2.0.4"
@@ -32,14 +32,14 @@ module Eucalypt
32
32
  generator.controller(route: options[:route])
33
33
  generator.views
34
34
 
35
- asset_pipeline_file = File.join(directory, 'config', 'asset_pipeline.rb')
35
+ assets_file = File.join(directory, 'config', 'assets.rb')
36
36
 
37
- File.open(asset_pipeline_file) do |f|
37
+ File.open(assets_file) do |f|
38
38
  return if f.read.include? "assets.append_path Eucalypt.path 'app', 'assets', 'blog'"
39
39
  end
40
40
 
41
41
  insert_into_file(
42
- asset_pipeline_file,
42
+ assets_file,
43
43
  " assets.append_path Eucalypt.path 'app', 'assets', 'blog'\n",
44
44
  after: "set :assets, Sprockets::Environment.new\n"
45
45
  )
@@ -1,4 +1,22 @@
1
1
  require 'sinatra'
2
+ require 'bcrypt'
2
3
  class ApplicationController < Sinatra::Base
3
- get('*') { redirect '/maintenance.html' } if settings.maintenance
4
+ if settings.methods(false).include?(:maintenance)
5
+ if settings.maintenance
6
+ define_singleton_method(:maintenance) do |&block|
7
+ get '*', &block
8
+ post '*', &block
9
+ put '*', &block
10
+ patch '*', &block
11
+ delete '*', &block
12
+ options '*', &block
13
+ link '*', &block
14
+ unlink '*', &block
15
+ end
16
+ else
17
+ define_singleton_method(:maintenance) {|&block| get "/#{BCrypt::Password.create(?1)}", &block}
18
+ end
19
+ else
20
+ define_singleton_method(:maintenance) {|&block| get "/#{BCrypt::Password.create(?1)}", &block}
21
+ end
4
22
  end
@@ -0,0 +1,15 @@
1
+ require 'sinatra'
2
+ class ApplicationController < Sinatra::Base
3
+ def static(uri, *args)
4
+ if env['HTTP_VERSION'] == 'HTTP/1.1' and env["REQUEST_METHOD"] != 'GET'
5
+ status 303
6
+ else
7
+ status 302
8
+ end
9
+
10
+ # According to RFC 2616 section 14.30, "the field value consists of a
11
+ # single absolute URI"
12
+ response['Location'] = uri(uri.to_s, settings.absolute_redirects?, settings.prefixed_redirects?)
13
+ halt(*args)
14
+ end
15
+ end
@@ -1,6 +1,10 @@
1
1
  class ApplicationController < Sinatra::Base
2
2
  helpers ApplicationHelper if defined? ApplicationHelper
3
3
 
4
+ maintenance do
5
+ static '/maintenance.html'
6
+ end
7
+
4
8
  get '/' do
5
9
  erb :index
6
10
  end
@@ -5,15 +5,9 @@ Bundler.require :default, settings.environment
5
5
  Eucalypt.set_root __dir__
6
6
 
7
7
  class ApplicationController < Sinatra::Base
8
- # Set server
9
- set :server, %w[thin webrick]
10
-
11
8
  # Set core application file
12
9
  set :app_file, __FILE__
13
10
 
14
- # Set application root directory
15
- set :root, Eucalypt.root
16
-
17
11
  # Set public folder for static files
18
12
  set :public_folder, Eucalypt.path('app', 'static')
19
13
 
@@ -27,16 +21,14 @@ class ApplicationController < Sinatra::Base
27
21
  # Set default ERB template
28
22
  set :erb, layout: :'layouts/main'
29
23
 
24
+ # Set IP whitelist
25
+ set :whitelist, Eucalypt::Whitelist.new(Eucalypt.path 'config', 'whitelist')
26
+
30
27
  # Toggle maintenance mode
31
28
  disable :maintenance
32
- require 'eucalypt/core/helpers/maintenance'
33
29
 
34
30
  # Set Hanami HTML and asset helpers
35
31
  helpers Hanami::Helpers, Hanami::Assets::Helpers
36
- end
37
32
 
38
- Eucalypt.require 'config', '*.rb'
39
- Eucalypt.require 'config', 'initializers', '*.rb'
40
- Eucalypt.require 'app', 'helpers', '{application_helper.rb}'
41
- Eucalypt.require 'app', 'controllers', 'application_controller.rb'
42
- Eucalypt.require 'app', '{models,policies,helpers,controllers}', '*.rb'
33
+ require 'eucalypt/load'
34
+ end
@@ -0,0 +1,12 @@
1
+ module Eucalypt
2
+ class NotWhitelistedError < Exception
3
+ def initialize(ip)
4
+ super "IP address #{ip} not whitelisted"
5
+ end
6
+ end
7
+ class InvalidSettingTypeError < Exception
8
+ def initialize(setting, actual, classes)
9
+ super "!\nInvalid type for setting :#{setting}, got:\n\t#{actual},\nmust be one of:\n\t#{classes}"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ Eucalypt.require 'config', '*.rb'
2
+ Eucalypt.require 'config', 'initializers', '*.rb'
3
+
4
+ require 'eucalypt/core/helpers/maintenance'
5
+
6
+ Eucalypt.require 'app', 'helpers', '{application_helper.rb}'
7
+ Eucalypt.require 'app', 'controllers', 'application_controller.rb'
8
+ Eucalypt.require 'app', '{models,policies,helpers,controllers}', '*.rb'
@@ -1,3 +1,3 @@
1
1
  module Eucalypt
2
- VERSION = '0.4.2'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -0,0 +1,70 @@
1
+ require 'sinatra'
2
+ require 'bcrypt'
3
+ require_relative 'exceptions'
4
+ module Eucalypt
5
+ class Whitelist
6
+ def initialize(file)
7
+ @file = file
8
+ File.new(file, "a").close
9
+ add '::1', '127.0.0.1', '0.0.0.0'
10
+ end
11
+
12
+ def add(*to_add)
13
+ to_add.flatten.each do |ip|
14
+ next if include? ip
15
+ File.open(@file, 'a+') do |f|
16
+ lines = File.readlines(@file)
17
+ if lines.empty? || lines.all? {|line| line == "\n"}
18
+ File.open(@file, 'w') do |f1|
19
+ f1.write "#{BCrypt::Password.create(ip)}\n"
20
+ end
21
+ else
22
+ prefix = f.read.last == "\n" ? '' : "\n"
23
+ f.puts prefix + BCrypt::Password.create(ip)
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ def remove(*to_remove)
30
+ whitelist = []
31
+ hashed = File.readlines(@file).select{|ip| /\$.*/.match ip}.map(&:strip)
32
+
33
+ hashed.each do |ip|
34
+ if to_remove.flatten.any? {|request| BCrypt::Password.new(ip) == request}
35
+ next
36
+ else
37
+ whitelist << ip unless whitelist.include?(ip)
38
+ end
39
+ end
40
+
41
+ File.open(@file, 'w') {|f| f.write whitelist*("\n")<<"\n"}
42
+ end
43
+
44
+ def ips()
45
+ File.readlines(@file).map(&:strip).
46
+ select{|ip| /\$.*/.match ip}.
47
+ map {|ip| BCrypt::Password.new ip}
48
+ end
49
+
50
+ def include?(ip)
51
+ ips.any? {|whitelisted| whitelisted == ip}
52
+ end
53
+ end
54
+ end
55
+
56
+ class ApplicationController < Sinatra::Base
57
+ helpers do
58
+ def whitelisted?
59
+ case settings.whitelist
60
+ when Eucalypt::Whitelist then settings.whitelist.include?(request.ip)
61
+ when FalseClass then true
62
+ else raise Eucalypt::InvalidSettingTypeError.new(:whitelist, settings.whitelist.class, %w[FalseClass Eucalypt::Whitelist])
63
+ end
64
+ end
65
+
66
+ def ip_check()
67
+ raise Eucalypt::NotWhitelistedError.new(request.ip) unless whitelisted?
68
+ end
69
+ end
70
+ end
data/lib/eucalypt.rb CHANGED
@@ -12,5 +12,10 @@ require 'eucalypt/root'
12
12
  require 'eucalypt/list'
13
13
  require 'eucalypt/core/helpers/manifest'
14
14
  require 'eucalypt/core/helpers/partial'
15
+ require 'eucalypt/whitelist'
16
+ require 'eucalypt/core/helpers/static'
15
17
 
16
- Eucalypt::CLI.extend Eucalypt::List
18
+ Eucalypt::CLI.extend Eucalypt::List
19
+
20
+ class ApplicationController < Sinatra::Base; end
21
+ def app() ApplicationController end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eucalypt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edwin Onuonga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-25 00:00:00.000000000 Z
11
+ date: 2018-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '5.2'
125
+ - !ruby/object:Gem::Dependency
126
+ name: bcrypt
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.1'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.1'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: front_matter_parser
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -237,6 +251,7 @@ files:
237
251
  - lib/eucalypt/core/helpers/maintenance.rb
238
252
  - lib/eucalypt/core/helpers/manifest.rb
239
253
  - lib/eucalypt/core/helpers/partial.rb
254
+ - lib/eucalypt/core/helpers/static.rb
240
255
  - lib/eucalypt/core/templates/Gemfile.tt
241
256
  - lib/eucalypt/core/templates/eucalypt/.gitignore
242
257
  - lib/eucalypt/core/templates/eucalypt/.travis.yml
@@ -257,7 +272,7 @@ files:
257
272
  - lib/eucalypt/core/templates/eucalypt/app/views/layouts/main.erb
258
273
  - lib/eucalypt/core/templates/eucalypt/app/views/partials/.empty_directory
259
274
  - lib/eucalypt/core/templates/eucalypt/config.ru
260
- - lib/eucalypt/core/templates/eucalypt/config/asset_pipeline.rb
275
+ - lib/eucalypt/core/templates/eucalypt/config/assets.rb
261
276
  - lib/eucalypt/core/templates/eucalypt/config/database.yml
262
277
  - lib/eucalypt/core/templates/eucalypt/config/initializers/.empty_directory
263
278
  - lib/eucalypt/core/templates/eucalypt/config/logging.rb
@@ -273,6 +288,7 @@ files:
273
288
  - lib/eucalypt/destroy/namespaces/destroy/cli/destroy-scaffold.rb
274
289
  - lib/eucalypt/destroy/namespaces/destroy/cli/destroy.rb
275
290
  - lib/eucalypt/errors.rb
291
+ - lib/eucalypt/exceptions.rb
276
292
  - lib/eucalypt/generate/.gitkeep
277
293
  - lib/eucalypt/generate/namespaces/generate-controller/cli/generate-controller.rb
278
294
  - lib/eucalypt/generate/namespaces/generate-controller/generators/controller.rb
@@ -298,6 +314,7 @@ files:
298
314
  - lib/eucalypt/helpers/migration.rb
299
315
  - lib/eucalypt/helpers/numeric.rb
300
316
  - lib/eucalypt/list.rb
317
+ - lib/eucalypt/load.rb
301
318
  - lib/eucalypt/migration/helpers.rb
302
319
  - lib/eucalypt/migration/migration_base.tt
303
320
  - lib/eucalypt/migration/namespaces/migration-add/cli/add-column.rb
@@ -354,6 +371,7 @@ files:
354
371
  - lib/eucalypt/security/namespaces/security/cli/security.rb
355
372
  - lib/eucalypt/static.rb
356
373
  - lib/eucalypt/version.rb
374
+ - lib/eucalypt/whitelist.rb
357
375
  homepage: https://eucalypt.gitbook.io/eucalypt
358
376
  licenses:
359
377
  - MIT