Commit f192317d authored by Eric Johnson's avatar Eric Johnson

Automatically sign periscope embed requests based on data

Note: Needs an PERISCOPE_EMBED_API_KEY env var set locally or in CI (secretly)
parent 8745bc08
Pipeline #86469684 failed with stages
in 17 minutes and 36 seconds
......@@ -24,6 +24,9 @@ gem 'sassc'
gem 'stringex'
gem 'countries'
# OpenSSL for signing periscope URLs with SHA256 HMAC
gem 'openssl'
# Replacement of therubyracer
gem 'mini_racer', '~> 0.2'
......
......@@ -94,6 +94,7 @@ GEM
i18n (0.9.5)
concurrent-ruby (~> 1.0)
i18n_data (0.8.0)
ipaddr (1.2.2)
jaro_winkler (1.5.2)
kramdown (1.17.0)
launchy (2.4.3)
......@@ -166,6 +167,8 @@ GEM
nokogiri (1.10.4)
mini_portile2 (~> 2.4.0)
oj (3.7.9)
openssl (2.1.2)
ipaddr
padrino-helpers (0.13.3.4)
i18n (~> 0.6, >= 0.6.7)
padrino-support (= 0.13.3.4)
......@@ -269,6 +272,7 @@ DEPENDENCIES
middleman-syntax
mini_racer (~> 0.2)
nokogiri (>= 1.10.4)
openssl
rake (~> 12.3)
rspec (~> 3.5)
rss (~> 0.2.8)
......
......@@ -191,7 +191,11 @@
health:
level: 2
reason: We are recalibrating to set headcount based on senior leadership guidance. We need to establish new goal and expectations relative to current growth plans. With additional vacation and starts in August original metric dropped below 8.
periscope_embed_url: https://www.periscopedata.com/api/embedded_dashboard?data=%7B%22chart%22%3A+6114177%2C+%22dashboard%22%3A+463858%2C+%22embed%22%3A+%22v2%22%2C+%22border%22%3A+%22off%22%7D&signature=58a92d0ef5116c2ef4d0f901fd0174ca4b8bf44910c79261b4f0cdac2ff9661d
periscope_data:
chart: 6114177
dashboard: 463858
embed: v2
border: off
next_steps:
- "Health: What we need to do next to improve metric - compare to the future trend of hiring/onboarding rates."
- "Maturity: Establish new bar with historical data and manage"
......
require 'open-uri'
require 'nokogiri'
require 'CGI'
require 'OpenSSL'
module CustomHelpers
def icon(icon, cssclass = "", attrs = {})
......@@ -129,6 +131,21 @@ module CustomHelpers
partial('includes/performance_indicators.html.erb', locals: { key_performance_indicators: kpis, regular_performance_indicators: rpis })
end
def signed_periscope_url(data)
path = '/api/embedded_dashboard'
json = data.to_json
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), ENV['PERISCOPE_EMBED_API_KEY'], path + '?data=' + CGI.escape(json))
URI::HTTPS.build(
host: 'www.periscopedata.com',
path: path,
query: {
data: json,
signature: signature
}.to_query
)
end
def font_url(current_page)
fonts = ["Source+Sans+Pro:200,300,400,500,600,700"]
......
......@@ -16,6 +16,15 @@
<embed width="100%" height="100%" src="<%= performance_indicator.periscope_embed_url %>">
<% end %>
<% if performance_indicator.periscope_data %>
<b>Periscope chart</b>
<% if ENV['PERISCOPE_EMBED_API_KEY'] %>
<embed width="100%" height="100%" src="<%= signed_periscope_url(performance_indicator.periscope_data) %>">
<% else %>
<p>You must set a <code>PERISCOPE_EMBED_API_KEY</code> environment variable to render this chart.</p>
<% end %>
<% end %>
<b>Health: <%= color_code_health(performance_indicator.health.level) %></b>
<p><%= performance_indicator.health.reason %></p>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment