ops 1.1.0 → 1.2.0

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
- SHA1:
3
- metadata.gz: c5858a2e0dde21d89b70cb34b9e96ca51829443c
4
- data.tar.gz: d502e55582d6d4ff4b027c7f5dc507c2f1816da4
2
+ SHA256:
3
+ metadata.gz: cfa4c11946baaa93a8d4683795a32c455ec879214e7275b7b58a9d5bcc7c93a0
4
+ data.tar.gz: dde535ba99c5a2772a154a791d6199c57d27e7b9ebc5feb7257aad070fa14404
5
5
  SHA512:
6
- metadata.gz: eb1b3cafc156a9da0719726ca846d84c74d1ab2da4fd0689573a640515878413538d33688f113a1d25fa2a9d8360fb4d4b9933ce640281ad8178ff4639fabff4
7
- data.tar.gz: f70c5bcdb1be85cf20d36064a72035301f75a2f1bef054838924c710915e27691dc25200c5bd816d370543fea98c88a1138217f8b3fdf32e2fae877c617071d4
6
+ metadata.gz: 4da7f53d6755daf5d6d9118846018bf71f85129d584271577ebe9bc96d8339ec8d6337a44ad01415c31a2b8bf333f71a9060dbdcbf102d2023f9ce02e2a3c21b
7
+ data.tar.gz: a776b7876b2528378e8f49ce8421b6e2ed7789226c69c14d1e607fab354ddd57e121000062f92e1e23511d2068e03e35f261a88915ca632db0f3cd86f70dbd5e
data/README.md CHANGED
@@ -8,22 +8,23 @@ This gem provides standardized support for obtaining environment, version, and h
8
8
  <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
9
9
  **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
10
10
 
11
- - [Installation](#installation)
12
- - [For Rails apps:](#for-rails-apps)
13
- - [For Sinatra apps:](#for-sinatra-apps)
14
- - [Adding Custom Heartbeats](#adding-custom-heartbeats)
15
- - [The Configuration Service Adapter (Optional)](#the-configuration-service-adapter-optional)
16
- - [Running tests](#running-tests)
11
+ - [Ops](#ops)
12
+ - [Installation](#installation)
13
+ - [For Rails apps:](#for-rails-apps)
14
+ - [For Sinatra apps:](#for-sinatra-apps)
15
+ - [Adding Custom Heartbeats](#adding-custom-heartbeats)
16
+ - [The Configuration Service Adapter (Optional)](#the-configuration-service-adapter-optional)
17
+ - [Running tests](#running-tests)
17
18
 
18
19
  <!-- END doctoc generated TOC please keep comment here to allow auto update -->
19
20
 
20
21
 
21
22
  **You will likely want to block or restrict access to the following routes:**
22
23
 
23
- Route | Notes
24
- --------------| -----
25
- `/ops/env` | Exposes all of your environment variables (e.g. any API keys set as environment variables) to the public
26
- `/ops/config` | Exposes all of your configuration keys and values to the public (if you're using a configuration service).
24
+ | Route | Notes |
25
+ | ------------- | ---------------------------------------------------------------------------------------------------------- |
26
+ | `/ops/env` | Exposes all of your environment variables (e.g. any API keys set as environment variables) to the public |
27
+ | `/ops/config` | Exposes all of your configuration keys and values to the public (if you're using a configuration service). |
27
28
 
28
29
  Typical usage:
29
30
 
data/lib/ops/revision.rb CHANGED
@@ -1,6 +1,8 @@
1
+ require 'yaml'
2
+
1
3
  module Ops
2
4
  class Revision
3
- attr_writer :branch_source
5
+ attr_reader :file_root
4
6
 
5
7
  def initialize(new_headers = {}, opts = Ops.config)
6
8
  @file_root = opts.file_root.to_s # convert to string in case they pass us a Pathname
@@ -8,114 +10,52 @@ module Ops
8
10
  @headers = new_headers
9
11
  end
10
12
 
11
- def version_or_branch
12
- @version ||= if version_file?
13
- chomp(version_file).gsub('^{}', '')
14
- elsif development? && branch_source.call =~ /^\* (.*)$/
15
- Regexp.last_match(1)
16
- else
17
- 'Unknown (VERSION file is missing)'
18
- end
19
- end
20
-
21
- def previous_versions
22
- @previous_versions ||= get_previous_by_time
23
- end
24
-
25
- def get_previous_by_time
26
- get_previous_versions.sort_by { |a| a[:time] }
27
- end
28
-
29
- def get_previous_versions
30
- Dir["#{path}/../*"].each_with_object([]) do |dir, array|
31
- next if dir =~ /#{current_dir}$/
32
- version, revision = File.join(dir, 'VERSION'), File.join(dir, 'REVISION')
33
- array << stats_hash(version: version, revision: revision) if File.exist?(version) && File.exist?(revision)
34
- end
35
- end
36
-
37
- def path
38
- File.absolute_path file_root
39
- end
40
-
41
- def current_dir
42
- file_root.split('/').last
43
- end
44
-
45
- def stats_hash(files)
46
- { version: get_version(files[:version]),
47
- revision: get_revision(files[:revision]),
48
- time: get_time(files[:revision]) }
49
- end
50
-
51
- def get_version(file)
52
- chomp(file).gsub('^{}', '')
53
- end
13
+ attr_reader :environment
54
14
 
55
- def get_revision(file)
56
- chomp file
15
+ def headers
16
+ @headers.select { |k, v| k.match(/^[-A-Z_].*$/) }
57
17
  end
58
18
 
59
- def chomp(file)
60
- File.read(file).chomp
19
+ def info
20
+ @info ||= build_info.merge(deploy_info)
61
21
  end
62
22
 
63
- def get_time(file)
64
- File.stat(file).mtime
23
+ def previous_info
24
+ @previous_info ||= previous_build_info.merge(previous_deploy_info)
65
25
  end
66
26
 
67
- attr_reader :file_root
68
-
69
- attr_reader :environment
70
-
71
- def development?
72
- environment == 'development'
73
- end
74
-
75
- def version_file
76
- @version_file ||= File.join(file_root, 'VERSION')
77
- end
27
+ private
78
28
 
79
- def version_file?
80
- File.exist? version_file
29
+ def build_info
30
+ info_from_file('BUILD-INFO')
81
31
  end
82
32
 
83
- def revision_file
84
- @revision_file ||= File.join(file_root, 'REVISION')
33
+ def previous_build_info
34
+ info_from_file('PREVIOUS-BUILD-INFO')
85
35
  end
86
36
 
87
- def revision_file?
88
- File.exist? revision_file
37
+ def deploy_info
38
+ info_from_file('DEPLOY-INFO')
89
39
  end
90
40
 
91
- def deploy_date
92
- @deploy_date ||= if version_file?
93
- get_time version_file
94
- elsif development?
95
- 'Live'
96
- else
97
- 'Unknown (VERSION file is missing)'
98
- end
41
+ def previous_deploy_info
42
+ info_from_file('PREVIOUS-DEPLOY-INFO')
99
43
  end
100
44
 
101
- def last_commit
102
- @last_commit ||= if revision_file?
103
- chomp revision_file
104
- elsif development? && `git show` =~ /^commit (.*)$/
105
- Regexp.last_match(1)
106
- else
107
- 'Unknown (REVISION file is missing)'
108
- end
45
+ def info_from_file(name)
46
+ if file_exists?(name)
47
+ parse_info_file(name)
48
+ else
49
+ {name.downcase.gsub('-', '_') => "No #{name} file found"}
50
+ end
109
51
  end
110
52
 
111
- def headers
112
- @headers.select { |k, v| k.match(/^[-A-Z_].*$/) }
53
+ def parse_info_file(filename)
54
+ YAML.safe_load(File.read(File.join(file_root, filename))) if file_exists?(filename)
113
55
  end
114
56
 
115
- private
116
-
117
- def branch_source
118
- @branch_source ||= -> { `git branch` }
57
+ def file_exists?(file_name)
58
+ File.exist?(File.join(file_root, file_name))
119
59
  end
120
60
  end
121
61
  end
@@ -1,25 +1,4 @@
1
1
  <div class="container">
2
- <div class="spacer"></div>
3
- <div id="version">
4
- <div class="label">
5
- <%= "#{app_name} Version" %>
6
- </div>
7
- <div class="value">
8
- <%= version_link @version.version_or_branch %>
9
- </div>
10
- </div>
11
- <div class="spacer"></div>
12
- <div id="date">
13
- <div class="label">Date Deployed</div>
14
- <div class="value"><%= @version.deploy_date %></div>
15
- </div>
16
- <div class="spacer"></div>
17
- <div id="commit">
18
- <div class="label">Last Commit</div>
19
- <div class="value">
20
- <%= commit_link(@version.last_commit)%>
21
- </div>
22
- </div>
23
2
  <div class="spacer"></div>
24
3
  <div id="host">
25
4
  <div class="label">Host</div>
@@ -31,33 +10,31 @@
31
10
  <div class="value"><%= @version.environment %></div>
32
11
  </div>
33
12
  <div class="spacer"></div>
34
- <div id="previous_versions">
35
- <div class="label">Previous Versions</div>
36
- <div class="value">
37
- <% unless @previous_versions.empty? %>
38
- <table>
39
- <tr class="header">
40
- <td>Time</td>
41
- <td>Version</td>
42
- <td>Commit</td>
43
- </tr>
44
- <% @previous_versions.each_with_index do |version, i| %>
45
- <tr class="<%= i%2==0 ? 'even' : nil %>">
46
- <td>
47
- <%= version[:time].strftime('%x %X') %>
48
- </td>
49
- <td>
50
- <%= version_link(version[:version]) %>
51
- </td>
52
- <td>
53
- <%= commit_link(version[:revision]) %>
54
- </td>
55
- </tr>
56
- <% end %>
57
- </table>
58
- <% end %>
13
+ <h3>Current Deploy Info</h3>
14
+ <% @version.info.each do |key, value| %>
15
+ <div class="spacer"></div>
16
+ <div>
17
+ <div class="label">
18
+ <%= key.to_s.gsub('_',' ').capitalize %>
19
+ </div>
20
+ <div class="value">
21
+ <%= value %>
22
+ </div>
59
23
  </div>
60
- </div>
24
+ <% end %>
25
+ <div class="spacer"></div>
26
+ <h3>Previous Deploy Info</h3>
27
+ <% @version.previous_info.each do |key, value| %>
28
+ <div class="spacer"></div>
29
+ <div>
30
+ <div class="label">
31
+ <%= key.to_s.gsub('_',' ').capitalize %>
32
+ </div>
33
+ <div class="value">
34
+ <%= value %>
35
+ </div>
36
+ </div>
37
+ <% end %>
61
38
  <div class="spacer"></div>
62
39
  <div id="headers">
63
40
  <div class="label">Headers</div>
data/lib/ops/server.rb CHANGED
@@ -4,9 +4,7 @@ require 'json'
4
4
 
5
5
  module Ops
6
6
  class Server < Sinatra::Base
7
- dir = File.dirname(File.expand_path('', __FILE__))
8
- set :views, "#{dir}/server/views"
9
- # set :views, File.dirname(File.expand_path('/../server/views', __FILE__))
7
+ set :views, "#{File.dirname(File.expand_path('', __FILE__))}/server/views"
10
8
 
11
9
  helpers Ops::Helpers
12
10
 
@@ -14,11 +12,10 @@ module Ops
14
12
  env.each_with_object({}) { |(k, v), headers| headers[k] = v }
15
13
  end
16
14
 
17
- def jsonified_version(version, previous_versions, headers)
15
+ def jsonified_version(version, headers)
18
16
  JSON.generate(
19
- version: version.version_or_branch,
20
- revision: version.last_commit,
21
- previous_versions: previous_versions,
17
+ info: version.info,
18
+ previous_info: version.previous_info,
22
19
  headers: headers
23
20
  )
24
21
  end
@@ -34,12 +31,11 @@ module Ops
34
31
 
35
32
  get '/version/?:format?', provides: %i(html json) do
36
33
  @version = Revision.new(request_headers)
37
- @previous_versions = @version.previous_versions
38
34
  @headers = @version.headers
39
35
 
40
36
  if json_request?
41
37
  content_type 'application/json'
42
- return jsonified_version(@version, @previous_versions, @headers)
38
+ return jsonified_version(@version, @headers)
43
39
  end
44
40
 
45
41
  erb :version
data/lib/ops/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ops
2
- VERSION = '1.1.0'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ops
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Pelz-Sherman
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-08-23 00:00:00.000000000 Z
14
+ date: 2022-10-20 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: json
@@ -83,8 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  requirements: []
86
- rubyforge_project:
87
- rubygems_version: 2.4.5.1
86
+ rubygems_version: 3.1.6
88
87
  signing_key:
89
88
  specification_version: 4
90
89
  summary: Provide ops info endpoints.