power-compass 0.6.1 → 0.7.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 +4 -4
- data/app/components/concerns/compass/config_props.rb +17 -7
- data/app/controllers/compass/info_controller.rb +19 -2
- data/app/controllers/concerns/compass/cors.rb +1 -1
- data/config/routes.rb +3 -0
- data/lib/compass/configuration/client.rb +25 -0
- data/lib/compass/configuration.rb +14 -1
- data/lib/compass/engine.rb +1 -1
- data/lib/compass/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 431d772b417bd2496c132fafa4ab6daa644ff347dfcd93be3f9b71ad08937851
|
|
4
|
+
data.tar.gz: e10fdf20cefaa3aac21d9737c42f22a12c3f666ee3b72901d0ad97cbd8af2e5e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fa9cf9b5b30bea0622fc00717f39fe33aa2bbcec48531e7ae3b4e260acee138a2ab4d1e3ecd05d38508efe635ca2e7753077bc2cbe5f23871d6cf5d9c72f5a78
|
|
7
|
+
data.tar.gz: c4b4686f64fafb15f12a2e0419ae6785cda3e09792aec553388d95c1582c18a6839ea140c6045be47b11fa0b741c1d3a22bd25364a878ae1632d3858f9f715f4
|
|
@@ -7,18 +7,28 @@ module Compass
|
|
|
7
7
|
module ConfigProps
|
|
8
8
|
extend ActiveSupport::Concern
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
included do
|
|
11
|
+
prop :context_id
|
|
12
|
+
prop :backends
|
|
13
|
+
prop :auth_backend
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def context_id
|
|
18
|
+
prop(:context_id).presence || instance_exec(&Compass.config.context_id)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def backends
|
|
22
|
+
prop(:backends).presence || Compass.config.client.backends
|
|
23
|
+
end
|
|
15
24
|
|
|
16
|
-
|
|
17
|
-
|
|
25
|
+
def auth_backend
|
|
26
|
+
prop(:auth_backend).presence || Compass::Engine.routes.url_helpers.root_path
|
|
27
|
+
end
|
|
18
28
|
end
|
|
19
29
|
|
|
20
30
|
def compass_props
|
|
21
|
-
{ backends:
|
|
31
|
+
{ authBackend: auth_backend, backends: backends, contextId: context_id }
|
|
22
32
|
end
|
|
23
33
|
end
|
|
24
34
|
end
|
|
@@ -3,13 +3,30 @@ module Compass
|
|
|
3
3
|
#
|
|
4
4
|
# @private
|
|
5
5
|
class InfoController < ApplicationController
|
|
6
|
-
skip_before_action :validate_context
|
|
6
|
+
skip_before_action :validate_context, only: :index
|
|
7
7
|
|
|
8
8
|
def index
|
|
9
9
|
render json: {
|
|
10
10
|
version: Compass::VERSION,
|
|
11
|
-
backends: Compass.config.backends
|
|
11
|
+
backends: Compass.config.client.backends
|
|
12
12
|
}
|
|
13
13
|
end
|
|
14
|
+
|
|
15
|
+
def auth
|
|
16
|
+
expiration = Compass.config.client.auth_expires_at&.call(**current_context)
|
|
17
|
+
token = Compass.config.client.auth_token&.call(**current_context)
|
|
18
|
+
|
|
19
|
+
if expiration&.future?
|
|
20
|
+
expires_in(expiration - Time.now)
|
|
21
|
+
else
|
|
22
|
+
expires_now
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
if token.present?
|
|
26
|
+
render json: { Authorization: "Bearer #{token}" }
|
|
27
|
+
else
|
|
28
|
+
render json: {}
|
|
29
|
+
end
|
|
30
|
+
end
|
|
14
31
|
end
|
|
15
32
|
end
|
|
@@ -24,7 +24,7 @@ module Compass
|
|
|
24
24
|
|
|
25
25
|
parsed_origin = URI.parse(request.headers["Origin"])
|
|
26
26
|
|
|
27
|
-
Compass.config.backends.any? do |backend|
|
|
27
|
+
Compass.config.client.backends.any? do |backend|
|
|
28
28
|
backend_uri = URI.parse(backend) rescue nil
|
|
29
29
|
parsed_origin.scheme == backend_uri&.scheme &&
|
|
30
30
|
parsed_origin.host == backend_uri&.host &&
|
data/config/routes.rb
CHANGED
|
@@ -17,4 +17,7 @@ Compass::Engine.routes.draw do
|
|
|
17
17
|
|
|
18
18
|
get ":context_id/notifications", to: "notification#index", as: :notifications
|
|
19
19
|
options ":context_id/notifications", to: "notification#cors"
|
|
20
|
+
|
|
21
|
+
get ":context_id/auth", to: "info#auth", as: :auth
|
|
22
|
+
options ":context_id/auth", to: "info#cors"
|
|
20
23
|
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Compass
|
|
2
|
+
module Configuration::Client
|
|
3
|
+
include ActiveSupport::Configurable
|
|
4
|
+
|
|
5
|
+
# Backends configuration
|
|
6
|
+
#
|
|
7
|
+
# I.e.:
|
|
8
|
+
# config.client.backends = [ "http://localhost:3000/compass" ]
|
|
9
|
+
#
|
|
10
|
+
config_accessor :backends, default: Set.new
|
|
11
|
+
|
|
12
|
+
# Authentication configuration
|
|
13
|
+
#
|
|
14
|
+
# I.e.:
|
|
15
|
+
# config.client.auth_token = -> { "1234567890" }
|
|
16
|
+
# config.client.auth_expires_at = -> { 1.hour.from_now }
|
|
17
|
+
#
|
|
18
|
+
# @return [Proc] The authentication token proc.
|
|
19
|
+
config_accessor :auth_token, default: ->(**) { }
|
|
20
|
+
|
|
21
|
+
# Proc to determine the authentication expiration time.
|
|
22
|
+
# @return [Proc] The authentication expiration time proc.
|
|
23
|
+
config_accessor :auth_expires_at, default: ->(**) { }
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -23,6 +23,7 @@ module Compass
|
|
|
23
23
|
module Configuration
|
|
24
24
|
extend ::ActiveSupport::Concern
|
|
25
25
|
|
|
26
|
+
autoload :Client, "compass/configuration/client"
|
|
26
27
|
autoload :Menu, "compass/configuration/menu"
|
|
27
28
|
autoload :Search, "compass/configuration/search"
|
|
28
29
|
autoload :Notification, "compass/configuration/notification"
|
|
@@ -32,16 +33,28 @@ module Compass
|
|
|
32
33
|
included do
|
|
33
34
|
include ActiveSupport::Configurable
|
|
34
35
|
|
|
36
|
+
# Backend context authentication and context identification
|
|
35
37
|
config_accessor :authenticate, default: -> { false }
|
|
36
38
|
config_accessor :context, default: -> { {} }
|
|
37
39
|
config_accessor :context_id, default: -> { }
|
|
38
|
-
config_accessor :backends, default: Set.new
|
|
39
40
|
config_accessor :modified_at, default: -> { }
|
|
40
41
|
|
|
42
|
+
# Client configuration
|
|
43
|
+
config_accessor :client, default: Compass::Configuration::Client
|
|
44
|
+
|
|
45
|
+
# Menu configuration
|
|
41
46
|
config_accessor :menu, default: Compass::Configuration::Menu
|
|
47
|
+
|
|
48
|
+
# Search configuration
|
|
42
49
|
config_accessor :search, default: Compass::Configuration::Search
|
|
50
|
+
|
|
51
|
+
# Notification configuration
|
|
43
52
|
config_accessor :notification, default: Compass::Configuration::Notification
|
|
53
|
+
|
|
54
|
+
# Layout configuration
|
|
44
55
|
config_accessor :layout, default: Compass::Configuration::Layout
|
|
56
|
+
|
|
57
|
+
# Breadcrumb configuration
|
|
45
58
|
config_accessor :breadcrumb, default: Compass::Configuration::Breadcrumb
|
|
46
59
|
end
|
|
47
60
|
end
|
data/lib/compass/engine.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Compass
|
|
|
11
11
|
config.compass = Compass.config
|
|
12
12
|
|
|
13
13
|
config.try(:after_routes_loaded) do
|
|
14
|
-
Compass.config.backends << Compass::Engine.routes.url_helpers.root_path
|
|
14
|
+
Compass.config.client.backends << Compass::Engine.routes.url_helpers.root_path
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
config.paths["app"].skip_autoload!
|
data/lib/compass/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: power-compass
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Carlos Palhares
|
|
@@ -106,6 +106,7 @@ files:
|
|
|
106
106
|
- lib/compass/breadcrumb/middleware.rb
|
|
107
107
|
- lib/compass/configuration.rb
|
|
108
108
|
- lib/compass/configuration/breadcrumb.rb
|
|
109
|
+
- lib/compass/configuration/client.rb
|
|
109
110
|
- lib/compass/configuration/layout.rb
|
|
110
111
|
- lib/compass/configuration/menu.rb
|
|
111
112
|
- lib/compass/configuration/notification.rb
|