web47core 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0df839ec2a6e7d78c8ef4e250179643a359e0b5723b35992ab4dfda76ccd1886
4
- data.tar.gz: 31b961889cc2bf8748da8b2ea26d050a20fed870adfdcc68a5e8bce1f0e67409
3
+ metadata.gz: e4fa89fdcd38c923f6fde1827baa6d3237f43120e9e82c25f9c13cc7817e580a
4
+ data.tar.gz: d25bd53993294c31e1a6f89ce6cffe76c38bd0058411c97c2f4027418a37be43
5
5
  SHA512:
6
- metadata.gz: 3fe114893789eee1c74a7f0c8870c4669feb38d8d67010b9425634b20910c7bce0bbd5825c3f0fe3e65eb4f58fabf8c49b390b868fa6f0c8bb8ee3821fcf7c4d
7
- data.tar.gz: ba5626fdb74f667f55c992d84253026e8a50679552d7c4447d3832cfcbe05bbe26e84c4900ed23159a7cdc873149b6769e6d27aee559312f1aeedcfb0dcfc26f
6
+ metadata.gz: 1b9b6f4ed7fef7b154e7622f664c2c93bfbd6e26524523befd9b764d3d1f72525b06243b91e8c3fac057230dfff5f659017db4893b123665353e994c3cee2dad
7
+ data.tar.gz: ca8ecfac41f5bd5df4d766d48ad6823550d7fbbb62413c3820011edb151e59d5557edd18f4e967507a539fcd2731bd8198e5b352f3f6c546d95d376d034316e9
@@ -4,62 +4,36 @@
4
4
  # Return the status of the server
5
5
  #
6
6
  class StatusController < ActionController::Base
7
- protect_from_forgery with: :exception
8
7
  #
9
8
  # Main (and only) page
10
9
  #
11
10
  def index
12
- components = { mongo: mongo_status,
13
- redis: redis_status,
14
- jobs: delayed_jobs_status,
15
- cron_job_servers: cron_job_servers_status,
16
- workers: workers_status }
11
+ components = { mongo: mongo_status, redis: redis_status, job_count: job_count_status, cron_job: cron_job_status }
17
12
 
18
13
  respond_to do |format|
19
- format.html { render :index, locals: { components: ui_decorators(components) }, layout: false }
14
+ format.html { render :index, locals: { components: components }, layout: false }
20
15
  format.json { render json: components.to_json }
21
- format.text { render plain: components.flatten, status: text_status(components) }
16
+ format.text do
17
+ overall = components.collect { |_key, item| item[:success] }.all?
18
+ render plain: components.flatten, status: overall ? 200 : 500
19
+ end
22
20
  end
23
21
  end
24
22
 
25
23
  private
26
24
 
27
- #
28
- # Return the status of the key components, mongo, redis
29
- #
30
- def text_status(components)
31
- components[:mongo][:success] && components[:redis][:success] ? 200 : 500
32
- rescue StandardError
33
- 500
34
- end
35
-
36
- #
37
- # Add UI decorators for HTML formatting
38
- #
39
- def ui_decorators(components)
40
- components.each do |key, values|
41
- if values[:success]
42
- components[key][:icon_name] = 'check_circle'
43
- components[key][:icon_color] = 'green-text'
44
- else
45
- components[key][:icon_name] = 'error'
46
- components[key][:icon_color] = 'red-text'
47
- end
48
- end
49
- end
50
-
51
25
  #
52
26
  # Report an error for the check
53
27
  #
54
- def report_error(error, metrics = {})
55
- metrics.merge(success: false, message: error.message)
28
+ def report_error(error)
29
+ { success: false, icon_name: 'error', icon_color: 'red-text', message: error.message }
56
30
  end
57
31
 
58
32
  #
59
33
  # Report a success for the check
60
34
  #
61
- def report_success(message, metrics = {})
62
- metrics.merge(success: true, message: message)
35
+ def report_success(message)
36
+ { success: true, icon_name: 'check_circle', icon_color: 'green-text', message: message }
63
37
  end
64
38
 
65
39
  #
@@ -68,9 +42,9 @@ class StatusController < ActionController::Base
68
42
  def mongo_status
69
43
  raise 'Mongo not available' if SystemConfiguration.count.zero?
70
44
 
71
- report_success "#{SystemConfiguration.count} Configs", count: SystemConfiguration.count
45
+ report_success "#{SystemConfiguration.count} Configs"
72
46
  rescue StandardError => error
73
- report_error error, count: 0
47
+ report_error(error)
74
48
  end
75
49
 
76
50
  #
@@ -81,53 +55,32 @@ class StatusController < ActionController::Base
81
55
  Rails.cache.write 'redis-status-check', value
82
56
  raise 'Redis not available' unless value.eql?(Rails.cache.fetch('redis-status-check'))
83
57
 
84
- report_success 'Redis Available', count: 1
58
+ report_success 'Redis Available'
85
59
  rescue StandardError => error
86
- report_error(error, count: 0)
60
+ report_error(error)
87
61
  end
88
62
 
89
63
  #
90
64
  # Job Count
91
65
  #
92
- def delayed_jobs_status
93
- count = Delayed::Backend::Mongoid::Job.count
94
- report_success "#{count} Jobs", count: count
66
+ def job_count_status
67
+ report_success "#{Delayed::Backend::Mongoid::Job.count} Jobs"
95
68
  rescue StandardError => error
96
69
  report_error(error)
97
70
  end
98
71
 
99
72
  #
100
- # Cron job primary status
73
+ # Cron job status
101
74
  #
102
- def cron_job_servers_status
103
- server = cron_job_server
75
+ def cron_job_status
76
+ server = Cron::Server.primary_server
104
77
  raise 'No primary server' if server.blank?
105
78
 
106
79
  server_info = "#{server.host_name}(#{server.pid}), last check in #{server.last_check_in_at}"
107
80
  raise "Primary Server is DEAD: #{server_info}" if server.dead?
108
81
 
109
- report_success "Primary Server is alive: #{server_info}",
110
- primary_count: 1,
111
- total_count: Cron::Server.count
82
+ report_success "Primary Server is alive: #{server_info}"
112
83
  rescue StandardError => error
113
- report_error(error, primary_count: 0, total_count: Cron::Server.count)
114
- end
115
-
116
- #
117
- # Desired and current worker status for servers
118
- #
119
- def workers_status
120
- server = cron_job_server
121
- raise 'No primary server' if server.blank? || server.dead?
122
-
123
- report_success "Workers #{server.desired_server_count}/ #{server.current_server_count}",
124
- desired_count: server.desired_server_count,
125
- current_count: server.current_server_count
126
- rescue StandardError => error
127
- report_error(error, desired_count: 0, current_count: 0)
128
- end
129
-
130
- def cron_job_server
131
- @cron_job_server ||= Cron::Server.primary_server
84
+ report_error(error)
132
85
  end
133
86
  end
@@ -91,4 +91,8 @@ module CoreHelper
91
91
  def edit_model_path(model)
92
92
  model_action_path(model, :edit)
93
93
  end
94
+
95
+ def current_user
96
+ User.new
97
+ end
94
98
  end
@@ -7,7 +7,7 @@
7
7
  %meta{ name: 'apple-mobile-web-app-status-bar-style', content: 'black'}
8
8
  = stylesheet_link_tag 'https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css'
9
9
  = stylesheet_link_tag 'https://fonts.googleapis.com/icon?family=Material+Icons'
10
- %title="#{Rails.env} Status"
10
+ %title "#{Rails.env} Status"
11
11
  %body{ style: 'background-color: #006064;'}
12
12
  %header
13
13
  %main
@@ -6,7 +6,7 @@
6
6
  module RestfulController
7
7
  #
8
8
  # Render a JSON response with the results and status passed in. The payload will include
9
- # an MD5 hash along with the response for validation.
9
+ # an SHA1 hash along with the response for validation.
10
10
  #
11
11
  def render_json_response(success = true, results = {}, status_code = :ok)
12
12
  results[:success] = success
@@ -29,6 +29,10 @@ module RestfulController
29
29
  # Create a hash of the string contents
30
30
  #
31
31
  def hash(str)
32
- Digest::MD5.hexdigest(str)
32
+ if SystemConfiguration.fips_mode?
33
+ Digest::SHA2.hexdigest(str)
34
+ else
35
+ Digest::MD5.hexdigest(str)
36
+ end
33
37
  end
34
38
  end
@@ -20,6 +20,7 @@ module CoreSystemConfiguration
20
20
  # Fields
21
21
  #
22
22
  field :environment, type: String, default: 'test'
23
+ field :fips_mode, type: String, default: false
23
24
  # SMTP configuration
24
25
  field :default_email, type: String, default: 'support@app47.com'
25
26
  field :support_email, type: String, default: 'support@app47.com'
@@ -76,7 +76,12 @@ module EmailAble
76
76
  # Return the gravatar URL based on email address
77
77
  #
78
78
  def gravatar_url(size = '32', default = 'mm')
79
- "https://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(email)}?s=#{size}&d=#{default}"
79
+ self.email ||= 'noone@abc.com'
80
+ if SystemConfiguration.fips_mode?
81
+ "https://www.gravatar.com/avatar/#{Digest::SHA2.hexdigest(email)}?s=#{size}&d=#{default}"
82
+ else
83
+ "https://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(email)}?s=#{size}&d=#{default}"
84
+ end
80
85
  end
81
86
 
82
87
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Web47core
4
- VERSION = '0.6.1'
4
+ VERSION = '0.6.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web47core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Schroeder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-14 00:00:00.000000000 Z
11
+ date: 2020-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport