Skip to content
This repository has been archived by the owner on Jul 3, 2020. It is now read-only.

Commit

Permalink
Added a version controller and used proper ruby gems to gather data.
Browse files Browse the repository at this point in the history
TODO: Need to update rake tasks to use the controller on tagged releases.

Signed-off-by: Aaron Lippold <[email protected]>
  • Loading branch information
aaronlippold committed Apr 22, 2019
1 parent c553782 commit 751f551
Show file tree
Hide file tree
Showing 14 changed files with 146 additions and 17 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ end
gem 'tzinfo-data'
gem 'rubocop-performance'
gem 'tunemygc'
gem 'rugged'
gem 'git'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.4'
Expand Down
20 changes: 12 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ GEM
arel (8.0.0)
ast (2.4.0)
aws-eventstream (1.0.2)
aws-sdk (2.11.259)
aws-sdk-resources (= 2.11.259)
aws-sdk-core (2.11.259)
aws-sdk (2.11.260)
aws-sdk-resources (= 2.11.260)
aws-sdk-core (2.11.260)
aws-sigv4 (~> 1.0)
jmespath (~> 1.0)
aws-sdk-resources (2.11.259)
aws-sdk-core (= 2.11.259)
aws-sdk-resources (2.11.260)
aws-sdk-core (= 2.11.260)
aws-sigv4 (1.1.0)
aws-eventstream (~> 1.0, >= 1.0.2)
azure_graph_rbac (0.17.1)
Expand Down Expand Up @@ -140,6 +140,7 @@ GEM
faraday (>= 0.7.4, < 1.0)
ffi (1.10.0)
gibberish (2.1.0)
git (1.5.0)
gitlab (4.10.0)
httparty (~> 0.14, >= 0.14.0)
terminal-table (~> 1.5, >= 1.5.1)
Expand Down Expand Up @@ -170,7 +171,7 @@ GEM
htmlentities (4.3.4)
http-cookie (1.0.3)
domain_name (~> 0.5)
httparty (0.16.4)
httparty (0.17.0)
mime-types (~> 3.0)
multi_xml (>= 0.5.2)
httpclient (2.8.3)
Expand Down Expand Up @@ -380,7 +381,7 @@ GEM
rspec-mocks (~> 3.8.0)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.2)
rspec-expectations (3.8.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-its (1.3.0)
Expand Down Expand Up @@ -415,6 +416,7 @@ GEM
ruby_dep (1.5.0)
rubyntlm (0.6.2)
rubyzip (1.2.2)
rugged (0.28.1)
safe_yaml (1.0.5)
sassc (2.0.1)
ffi (~> 1.9)
Expand Down Expand Up @@ -519,7 +521,7 @@ GEM
execjs (>= 0.3.0, < 3)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.5)
unf_ext (0.0.7.6)
unicode-display_width (1.5.0)
unicode_utils (1.4.0)
warden (1.2.8)
Expand Down Expand Up @@ -573,6 +575,7 @@ DEPENDENCIES
email_spec (~> 2.1)
factory_bot_rails
gibberish
git
gitlab
inspec_tools (~> 1.3.0)
jbuilder (~> 2.5)
Expand Down Expand Up @@ -600,6 +603,7 @@ DEPENDENCIES
rubocop
rubocop-performance
rubocop-rspec
rugged
sassc-rails
simplecov
spring
Expand Down
57 changes: 57 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"addons": [
"mongolab",
"tunemygc"
],
"buildpacks": [
{
"url": "heroku/ruby"
}
],
"description": "InSpec Results Viewer",
"env": {
"CIPHER_PASSWORD": {
"generator": "secret"
},
"CIPHER_SALT": {
"required": true
},
"LANG": {
"required": true
},
"MONGODB_URI": {
"required": true
},
"RACK_ENV": {
"required": true
},
"RAILS_ENV": {
"required": true
},
"RAILS_LOG_TO_STDOUT": {
"required": true
},
"RAILS_SERVE_STATIC_FILES": {
"required": true
},
"RUBY_GC_TOKEN": {
"required": true
},
"SECRET_KEY_BASE": {
"generator": "secret"
},
" CIPHER_SALT": {
"generator": "secret"
}
},
"formation": {
"web": {
"quantity": 1
}
},
"name": "heimdall",
"scripts": {
},
"stack": "heroku-18"
}

3 changes: 3 additions & 0 deletions app/assets/javascripts/version.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/version.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the version controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
12 changes: 12 additions & 0 deletions app/controllers/version_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class VersionController < ApplicationController
def index
g = Git.open(Rails.root, :log => Logger.new(STDOUT))
repo = Rugged::Repository.discover(Rails.root)
version = {
version: g.describe,
branch: repo.head.name.split('/').last,
sha: repo.head.target_id
}
render json: version
end
end
2 changes: 2 additions & 0 deletions app/helpers/version_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module VersionHelper
end
7 changes: 3 additions & 4 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@
<!-- Main Footer -->
<footer class="main-footer">
<!-- To the right -->
<div class="pull-right hidden-xs">
Version: <%= Git::VERSION %>
<div class="pull-right">
<a href="https://github.com/mitre/heimdall/tree/<%= MyApp::VERSION %>"><%= MyApp::VERSION %></a> (<%= MyApp::BRANCH %>)
</div>
<!-- Default to the left -->
<strong>Copyright &copy; 2018 <a href="#">MITRE</a>.</strong> All rights reserved.
<strong>Copyright &copy; <%= Date.today.year %> <a href="http://www.mitre.org/">MITRE</a></strong>
</footer>
</div>
<!-- ./wrapper -->
Expand Down
5 changes: 5 additions & 0 deletions config/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"version": "v2.0.3-29-gc553782",
"branch": "disp_ver",
"sha": "c553782b9186500b08e7fb9e74b0a17388be4747"
}
5 changes: 0 additions & 5 deletions config/initializers/git_revision.rb

This file was deleted.

26 changes: 26 additions & 0 deletions config/initializers/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# config/initializers/version.rb

if Rails.env.development?
# we will hae to use both the `git` and `rugged` gem until
# rugged implaments `git describe`
g = Git.open(Rails.root)
repo = Rugged::Repository.discover(Rails.root)

version = {
version: g.describe,
branch: repo.head.name.split('/').last,
sha: repo.head.target_id
}

File.open('config/VERSION','w') do |f|
f.write(JSON.pretty_generate(version))
end
end

module MyApp
# Read JSON from a file, iterate over objects
parsed = JSON.parse(File.read('config/VERSION'), :symbolize_names => true)
VERSION = parsed[:version]
BRANCH = parsed[:branch]
SHA = parsed[:sha]
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Rails.application.routes.draw do
get 'version', to: 'version#index'
resources :users do
get :image, on: :member
end
Expand Down
5 changes: 5 additions & 0 deletions spec/controllers/version_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe VersionController, type: :controller do

end
15 changes: 15 additions & 0 deletions spec/helpers/version_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'rails_helper'

# Specs in this file have access to a helper object that includes
# the VersionHelper. For example:
#
# describe VersionHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe VersionHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end

0 comments on commit 751f551

Please sign in to comment.