punk 0.3.6 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +1 -1
- data/.rubocop.yml +1091 -93
- data/.standard.yml +2 -0
- data/Gemfile +60 -60
- data/Gemfile.lock +22 -17
- data/README.md +7 -3
- data/Rakefile +9 -7
- data/VERSION +1 -1
- data/app/migrations/001_lets_punk.rb +1 -1
- data/app/routes/hello.rb +1 -1
- data/bin/punk +5 -5
- data/lib/punk.rb +7 -7
- data/lib/punk/actions/sessions/create.rb +3 -3
- data/lib/punk/actions/sessions/verify.rb +2 -2
- data/lib/punk/commands/auth.rb +4 -4
- data/lib/punk/commands/generate.rb +5 -5
- data/lib/punk/commands/http.rb +4 -4
- data/lib/punk/commands/list.rb +10 -10
- data/lib/punk/core/app.rb +41 -41
- data/lib/punk/core/boot.rb +5 -5
- data/lib/punk/core/cli.rb +3 -3
- data/lib/punk/core/commander.rb +28 -28
- data/lib/punk/core/commands.rb +8 -8
- data/lib/punk/core/env.rb +27 -27
- data/lib/punk/core/exec.rb +8 -8
- data/lib/punk/core/interface.rb +19 -19
- data/lib/punk/core/load.rb +2 -2
- data/lib/punk/core/logger.rb +3 -3
- data/lib/punk/core/monkey.rb +1 -1
- data/lib/punk/core/pry.rb +2 -2
- data/lib/punk/core/settings.rb +4 -4
- data/lib/punk/core/version.rb +1 -1
- data/lib/punk/core/worker.rb +6 -6
- data/lib/punk/framework/all.rb +8 -8
- data/lib/punk/framework/model.rb +6 -5
- data/lib/punk/framework/plugins/all.rb +1 -1
- data/lib/punk/framework/plugins/validation.rb +8 -8
- data/lib/punk/framework/service.rb +5 -3
- data/lib/punk/framework/worker.rb +3 -3
- data/lib/punk/helpers/all.rb +5 -5
- data/lib/punk/helpers/loggable.rb +3 -3
- data/lib/punk/helpers/publishable.rb +1 -1
- data/lib/punk/helpers/renderable.rb +10 -10
- data/lib/punk/helpers/validatable.rb +7 -6
- data/lib/punk/migrations/001_punk.rb +12 -12
- data/lib/punk/models/group.rb +1 -1
- data/lib/punk/models/identity.rb +1 -1
- data/lib/punk/models/session.rb +7 -7
- data/lib/punk/models/tenant.rb +1 -1
- data/lib/punk/models/user.rb +2 -2
- data/lib/punk/plugins/all.rb +2 -2
- data/lib/punk/plugins/cors.rb +2 -2
- data/lib/punk/plugins/ssl.rb +1 -1
- data/lib/punk/routes/groups.rb +1 -1
- data/lib/punk/routes/plivo.rb +1 -1
- data/lib/punk/routes/sessions.rb +2 -2
- data/lib/punk/routes/swagger.rb +2 -2
- data/lib/punk/routes/tenants.rb +1 -1
- data/lib/punk/routes/users.rb +1 -1
- data/lib/punk/services/challenge_claim.rb +5 -5
- data/lib/punk/services/generate_swagger.rb +6 -6
- data/lib/punk/services/prove_claim.rb +1 -1
- data/lib/punk/startup/cache.rb +3 -3
- data/lib/punk/startup/database.rb +4 -4
- data/lib/punk/startup/environment.rb +6 -6
- data/lib/punk/startup/logger.rb +2 -2
- data/lib/punk/startup/task.rb +5 -5
- data/lib/punk/views/fail.rb +2 -2
- data/lib/punk/views/groups/list.rb +2 -2
- data/lib/punk/views/info.rb +2 -2
- data/lib/punk/views/plivo_store.rb +2 -2
- data/lib/punk/views/sessions/list.rb +2 -2
- data/lib/punk/views/sessions/pending.rb +2 -2
- data/lib/punk/views/tenants/list.rb +2 -2
- data/lib/punk/views/users/list.rb +2 -2
- data/lib/punk/views/users/show.rb +2 -2
- data/lib/punk/workers/geocode_session_worker.rb +3 -3
- data/lib/punk/workers/identify_session_worker.rb +1 -1
- data/lib/punk/workers/send_email_worker.rb +3 -3
- data/lib/punk/workers/send_sms_worker.rb +3 -3
- data/punk.gemspec +8 -4
- data/spec/actions/groups/punk/list_groups_action_spec.rb +9 -9
- data/spec/actions/sessions/punk/clear_session_action_spec.rb +11 -11
- data/spec/actions/sessions/punk/create_session_action_spec.rb +9 -9
- data/spec/actions/sessions/punk/list_sessions_action_spec.rb +8 -8
- data/spec/actions/sessions/punk/verify_session_action_spec.rb +24 -24
- data/spec/actions/tenants/punk/list_tenants_action_spec.rb +6 -6
- data/spec/actions/users/punk/list_group_users_action_spec.rb +6 -6
- data/spec/actions/users/punk/list_tenant_users_action_spec.rb +6 -6
- data/spec/factories/group.rb +1 -1
- data/spec/factories/group_user_metadata.rb +1 -1
- data/spec/factories/identity.rb +4 -4
- data/spec/factories/session.rb +1 -1
- data/spec/factories/tenant.rb +1 -1
- data/spec/factories/tenant_user_metadata.rb +1 -1
- data/spec/factories/user.rb +1 -1
- data/spec/lib/commands/generate_spec.rb +2 -2
- data/spec/lib/commands/list_spec.rb +2 -2
- data/spec/lib/commands/swagger_spec.rb +2 -2
- data/spec/lib/engine/punk_env_spec.rb +4 -4
- data/spec/lib/engine/punk_exec_spec.rb +2 -2
- data/spec/lib/engine/punk_init_spec.rb +2 -2
- data/spec/lib/engine/punk_store_spec.rb +2 -2
- data/spec/models/punk/group_spec.rb +4 -4
- data/spec/models/punk/group_user_metadata_spec.rb +2 -2
- data/spec/models/punk/identity_spec.rb +17 -17
- data/spec/models/punk/session_spec.rb +4 -4
- data/spec/models/punk/tenant_spec.rb +3 -3
- data/spec/models/punk/tenant_user_metadata_spec.rb +2 -2
- data/spec/models/punk/user_spec.rb +9 -9
- data/spec/routes/groups/get_groups_spec.rb +4 -4
- data/spec/routes/plivo/get_plivo_spec.rb +1 -1
- data/spec/routes/sessions/delete_session_spec.rb +1 -1
- data/spec/routes/sessions/get_sessions_spec.rb +5 -5
- data/spec/routes/sessions/patch_session_spec.rb +1 -1
- data/spec/routes/sessions/post_session_spec.rb +1 -1
- data/spec/routes/swagger/get_swagger_spec.rb +1 -1
- data/spec/routes/tenants/get_tenants_spec.rb +5 -5
- data/spec/routes/users/get_users_spec.rb +6 -6
- data/spec/services/punk/challenge_claim_service_spec.rb +2 -2
- data/spec/services/punk/create_identities_service_spec.rb +1 -1
- data/spec/services/punk/generate_swagger_service_spec.rb +2 -2
- data/spec/services/punk/prove_claim_service_spec.rb +2 -2
- data/spec/services/punk/secret_service_spec.rb +2 -2
- data/spec/spec_helper.rb +27 -27
- data/spec/views/punk/plivo_store_spec.rb +2 -2
- data/spec/views/sessions/punk/list_sessions_view_spec.rb +2 -2
- data/spec/views/sessions/punk/pending_session_view_spec.rb +2 -2
- data/spec/views/tenants/punk/list_tenants_view_spec.rb +2 -2
- data/spec/views/users/punk/list_groups_view_spec.rb +2 -2
- data/spec/views/users/punk/list_users_view_spec.rb +2 -2
- data/spec/workers/punk/geocode_session_worker_spec.rb +2 -2
- data/spec/workers/punk/identify_session_worker_spec.rb +3 -3
- data/spec/workers/punk/send_email_worker_spec.rb +1 -1
- metadata +18 -3
data/lib/punk/routes/swagger.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# route: GET /swagger.json
|
4
|
-
PUNK.route(
|
4
|
+
PUNK.route("swagger") do
|
5
5
|
result = PUNK::GenerateSwaggerService.run.result
|
6
6
|
response.status = 200
|
7
|
-
response[
|
7
|
+
response["Content-Type"] = "application/json"
|
8
8
|
result
|
9
9
|
end
|
data/lib/punk/routes/tenants.rb
CHANGED
data/lib/punk/routes/users.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "rbnacl"
|
4
4
|
|
5
5
|
module PUNK
|
6
6
|
class ChallengeClaimService < Service
|
@@ -25,13 +25,13 @@ module PUNK
|
|
25
25
|
case identity.claim_type
|
26
26
|
when :email
|
27
27
|
SendEmailWorker.perform_async(
|
28
|
-
from:
|
28
|
+
from: "GroupFire Accounts <noreply@groupfire.com>",
|
29
29
|
to: identity.claim,
|
30
|
-
subject:
|
31
|
-
template:
|
30
|
+
subject: "[GroupFire] Verification Code",
|
31
|
+
template: "verify",
|
32
32
|
tags: [:auth],
|
33
33
|
variables: {
|
34
|
-
name: identity.user&.name ||
|
34
|
+
name: identity.user&.name || "New User",
|
35
35
|
secret: secret
|
36
36
|
}
|
37
37
|
)
|
@@ -3,18 +3,18 @@
|
|
3
3
|
module PUNK
|
4
4
|
class GenerateSwaggerService < Service
|
5
5
|
def process
|
6
|
-
path = File.join(PUNK.get.app.path,
|
7
|
-
raise InternalServerError,
|
8
|
-
require
|
9
|
-
require_relative
|
6
|
+
path = File.join(PUNK.get.app.path, "..", "www", "swagger.json")
|
7
|
+
raise InternalServerError, "swagger.json already exists" if File.exist?(path) && !PUNK.env.test?
|
8
|
+
require "swagger_yard"
|
9
|
+
require_relative "../helpers/swagger"
|
10
10
|
SwaggerYard.register_custom_yard_tags!
|
11
11
|
SwaggerYard.configure do |config|
|
12
12
|
config.api_version = PUNK.version
|
13
13
|
config.title = PUNK.get.app.name
|
14
14
|
config.description = PUNK.get.app.description
|
15
15
|
config.api_base_path = PUNK.get.app.url
|
16
|
-
config.controller_path = [File.join(PUNK.get.app.path,
|
17
|
-
config.model_path = [File.join(__dir__,
|
16
|
+
config.controller_path = [File.join(PUNK.get.app.path, "routes", "**", "*"), File.join(__dir__, "..", "routes", "**", "*")]
|
17
|
+
config.model_path = [File.join(__dir__, "..", "models", "**", "*"), File.join(__dir__, "..", "views", "**", "*"), File.join(PUNK.get.app.path, "models", "**", "*")]
|
18
18
|
end
|
19
19
|
spec = SwaggerYard::OpenAPI.new
|
20
20
|
blob = JSON.pretty_generate(spec.to_h)
|
data/lib/punk/startup/cache.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "dalli"
|
4
4
|
|
5
5
|
PUNK::Interface.register(:cache) do
|
6
|
-
PUNK.profile_debug(
|
7
|
-
Dalli::Client.new(PUNK.get.cache.servers.split(
|
6
|
+
PUNK.profile_debug("cache_connect", servers: PUNK.get.cache.servers) do
|
7
|
+
Dalli::Client.new(PUNK.get.cache.servers.split(","), PUNK.get.cache.options)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "sequel"
|
4
4
|
|
5
5
|
module Sequel
|
6
6
|
def self.json_parser_error_class
|
@@ -12,7 +12,7 @@ module Sequel
|
|
12
12
|
end
|
13
13
|
|
14
14
|
class Database
|
15
|
-
def log_connection_yield(sql, conn, args=nil, &block)
|
15
|
+
def log_connection_yield(sql, conn, args = nil, &block)
|
16
16
|
return unless @loggers.first
|
17
17
|
if conn && log_connection_info
|
18
18
|
@loggers.first.tagged(conn.__id__) do
|
@@ -46,8 +46,8 @@ module PUNK
|
|
46
46
|
end
|
47
47
|
|
48
48
|
PUNK::Interface.register(:db) do
|
49
|
-
PUNK.profile_debug(
|
50
|
-
pg = Sequel.connect(PUNK.get.db.url, logger: SemanticLogger[
|
49
|
+
PUNK.profile_debug("db_connect", url: PUNK.get.db.url) do
|
50
|
+
pg = Sequel.connect(PUNK.get.db.url, logger: SemanticLogger["PUNK::SQL"])
|
51
51
|
pg.extension :pg_enum, :pg_range, :pg_array, :pg_json, :pg_row, :pg_timestamptz, :pg_inet
|
52
52
|
Sequel.extension :pg_array_ops, :pg_range_ops, :pg_json_ops, :pg_row_ops, :named_timezones, :thread_local_timezones
|
53
53
|
pg
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
case PUNK.env
|
4
|
-
when
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
4
|
+
when "test", "development"
|
5
|
+
require "amazing_print"
|
6
|
+
require "byebug"
|
7
|
+
require "rubocop"
|
8
|
+
require "rubocop-rspec"
|
9
|
+
require "rubocop-sequel"
|
10
10
|
end
|
data/lib/punk/startup/logger.rb
CHANGED
@@ -10,8 +10,8 @@ if PUNK.get.log.enabled?
|
|
10
10
|
$stdout.sync = true
|
11
11
|
SemanticLogger.add_appender(io: $stdout, formatter: :color)
|
12
12
|
when :file
|
13
|
-
subdir = PUNK.task.server? ?
|
14
|
-
path = PUNK.get.log.path || File.join(PUNK.get.app.path,
|
13
|
+
subdir = PUNK.task.server? ? "." : PUNK.task
|
14
|
+
path = PUNK.get.log.path || File.join(PUNK.get.app.path, "..", "log", subdir, "#{PUNK.env}.log")
|
15
15
|
FileUtils.mkdir_p(File.dirname(path))
|
16
16
|
SemanticLogger.add_appender(file_name: path, formatter: :color)
|
17
17
|
else
|
data/lib/punk/startup/task.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
case PUNK.task
|
4
|
-
when
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
when
|
4
|
+
when "spec"
|
5
|
+
require "rspec"
|
6
|
+
require "rspec/its"
|
7
|
+
require "sidekiq/testing"
|
8
|
+
when "console"
|
9
9
|
AwesomePrint.pry! if defined?(AwesomePrint)
|
10
10
|
end
|
data/lib/punk/views/fail.rb
CHANGED
@@ -9,13 +9,13 @@ module PUNK
|
|
9
9
|
|
10
10
|
def process
|
11
11
|
logger.warn "#{message} (#{status}): #{error_messages.to_sentence}"
|
12
|
-
|
12
|
+
"fail"
|
13
13
|
end
|
14
14
|
|
15
15
|
protected
|
16
16
|
|
17
17
|
def _dir
|
18
|
-
File.join(__dir__,
|
18
|
+
File.join(__dir__, "..", "templates")
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/lib/punk/views/info.rb
CHANGED
@@ -10,13 +10,13 @@ module PUNK
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def process
|
13
|
-
require
|
13
|
+
require "ipstack"
|
14
14
|
|
15
15
|
session = Session[session_id]
|
16
16
|
return if session.blank?
|
17
17
|
|
18
18
|
ip_address = session.remote_addr.to_s
|
19
|
-
return if ip_address ==
|
19
|
+
return if ip_address == "127.0.0.1"
|
20
20
|
|
21
21
|
return if PUNK.get.ipstack.api_key.blank?
|
22
22
|
result = Ipstack::API.standard(ip_address).deep_symbolize_keys
|
@@ -42,7 +42,7 @@ module PUNK
|
|
42
42
|
}
|
43
43
|
))
|
44
44
|
|
45
|
-
session.
|
45
|
+
session.save_changes
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -17,11 +17,11 @@ module PUNK
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def process
|
20
|
-
require
|
20
|
+
require "mailgun-ruby"
|
21
21
|
|
22
22
|
client =
|
23
23
|
if !PUNK.env.test? && PUNK.get.mailgun.mock
|
24
|
-
Mailgun::Client.new(PUNK.get.mailgun.api_key,
|
24
|
+
Mailgun::Client.new(PUNK.get.mailgun.api_key, "bin.mailgun.net", PUNK.get.mailgun.postbin, ssl=false) # rubocop:disable Lint/UselessAssignment,Layout/SpaceAroundOperators
|
25
25
|
else
|
26
26
|
Mailgun::Client.new(PUNK.get.mailgun.api_key)
|
27
27
|
end
|
@@ -44,7 +44,7 @@ module PUNK
|
|
44
44
|
|
45
45
|
return unless !PUNK.env.test? && PUNK.get.mailgun.mock
|
46
46
|
|
47
|
-
require
|
47
|
+
require "launchy"
|
48
48
|
Launchy.open("http://bin.mailgun.net/#{PUNK.get.mailgun.postbin}")
|
49
49
|
end
|
50
50
|
end
|
@@ -25,13 +25,13 @@ module PUNK
|
|
25
25
|
plivo.prepend(message)
|
26
26
|
PUNK.cache.set(:plivo, plivo)
|
27
27
|
unless PUNK.env.test?
|
28
|
-
require
|
29
|
-
Launchy.open("#{PUNK.get.app.url ||
|
28
|
+
require "launchy"
|
29
|
+
Launchy.open("#{PUNK.get.app.url || "http://localhost:3000"}/plivo.html")
|
30
30
|
end
|
31
31
|
return
|
32
32
|
end
|
33
33
|
|
34
|
-
require
|
34
|
+
require "plivo"
|
35
35
|
|
36
36
|
client = Plivo::RestClient.new(PUNK.get.plivo.auth_id, PUNK.get.plivo.auth_token)
|
37
37
|
client.messages.create(PUNK.get.plivo.number, [to], body)
|
data/punk.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: punk 0.
|
5
|
+
# stub: punk 0.4.1 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "punk".freeze
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.4.1"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Lloyd Kranzky".freeze]
|
14
|
-
s.date = "2021-03-
|
14
|
+
s.date = "2021-03-05"
|
15
15
|
s.description = "".freeze
|
16
16
|
s.email = "lloyd@kranzky.com".freeze
|
17
17
|
s.executables = ["punk".freeze]
|
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
".rgignore",
|
29
29
|
".rspec",
|
30
30
|
".rubocop.yml",
|
31
|
+
".standard.yml",
|
31
32
|
"Gemfile",
|
32
33
|
"Gemfile.lock",
|
33
34
|
"LICENSE",
|
@@ -223,7 +224,7 @@ Gem::Specification.new do |s|
|
|
223
224
|
]
|
224
225
|
s.homepage = "https://github.com/kranzky/punk".freeze
|
225
226
|
s.licenses = ["Unlicense".freeze]
|
226
|
-
s.required_ruby_version = Gem::Requirement.new(">= 2.
|
227
|
+
s.required_ruby_version = Gem::Requirement.new(">= 2.6".freeze)
|
227
228
|
s.rubygems_version = "2.7.6.2".freeze
|
228
229
|
s.summary = "Punk! is an omakase web framework for rapid prototyping.".freeze
|
229
230
|
|
@@ -277,6 +278,7 @@ Gem::Specification.new do |s|
|
|
277
278
|
s.add_development_dependency(%q<amazing_print>.freeze, ["~> 1.2"])
|
278
279
|
s.add_development_dependency(%q<byebug>.freeze, ["~> 11.1"])
|
279
280
|
s.add_development_dependency(%q<launchy>.freeze, ["~> 2.5"])
|
281
|
+
s.add_development_dependency(%q<standard>.freeze, ["~> 1.0"])
|
280
282
|
else
|
281
283
|
s.add_dependency(%q<bootsnap>.freeze, ["~> 1.7"])
|
282
284
|
s.add_dependency(%q<dim>.freeze, ["~> 1.2"])
|
@@ -324,6 +326,7 @@ Gem::Specification.new do |s|
|
|
324
326
|
s.add_dependency(%q<amazing_print>.freeze, ["~> 1.2"])
|
325
327
|
s.add_dependency(%q<byebug>.freeze, ["~> 11.1"])
|
326
328
|
s.add_dependency(%q<launchy>.freeze, ["~> 2.5"])
|
329
|
+
s.add_dependency(%q<standard>.freeze, ["~> 1.0"])
|
327
330
|
end
|
328
331
|
else
|
329
332
|
s.add_dependency(%q<bootsnap>.freeze, ["~> 1.7"])
|
@@ -372,6 +375,7 @@ Gem::Specification.new do |s|
|
|
372
375
|
s.add_dependency(%q<amazing_print>.freeze, ["~> 1.2"])
|
373
376
|
s.add_dependency(%q<byebug>.freeze, ["~> 11.1"])
|
374
377
|
s.add_dependency(%q<launchy>.freeze, ["~> 2.5"])
|
378
|
+
s.add_dependency(%q<standard>.freeze, ["~> 1.0"])
|
375
379
|
end
|
376
380
|
end
|
377
381
|
|