grnds-looker-hmac 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b4b3290ae1a93dc669e4a66a17144535a4296808
4
+ data.tar.gz: b7378ec4b8ab422ca944da294b6ebcecce05ac8e
5
+ SHA512:
6
+ metadata.gz: f0a4aa1836835ad5a0898b972376234e86904ebf8ceee751ce2e26cec6b00489dc5a3c5fed8f411ff7ab0e75cfc664575ced6f9a9ff26a3b6e65485261909b79
7
+ data.tar.gz: b521736b8d04dbae73125dda4e4cd095f0f77591a7adc40907f2cad44e543d5f3bf9df4570b7804366198f76e116351b662437689c7958971fc8959c3b8c8516
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ /.idea/
16
+ grnds-looker-hmac-*.gem
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in grnds-looker-hmac.gemspec
4
+ gemspec
5
+
6
+ gem 'rspec'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Bradley Johnson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ # Grnds::Looker::Hmac
2
+
3
+ Looker message authentication code helper for Grandrounds
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'grnds-looker-hmac'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install grnds-looker-hmac
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ #first set your LOOKER_EMBED_SECRET env var
25
+
26
+ config = {
27
+ :host => 'grandroundsstage.looker.com',
28
+ :embed_path => '/embed/sso/dashboards/uat/uat_01',
29
+ :path_root => '/login/embed/',
30
+ :external_user_id => '57',
31
+ :first_name => 'Kenneth',
32
+ :last_name => 'Berland',
33
+ :permissions => ["see_dashboards", "see_looks", "access_data"],
34
+ :models => ['uat']
35
+ }
36
+
37
+ signer = Grnds::Looker::Hmac::SignedUrlGenerator.new(config)
38
+ signedUrl = signer.getUrl
39
+ ```
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it ( https://github.com/[my-github-username]/grnds-looker-hmac/fork )
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'grnds/looker/hmac/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "grnds-looker-hmac"
8
+ spec.version = Grnds::Looker::Hmac::VERSION
9
+ spec.authors = ["Bradley Johnson"]
10
+ spec.email = ["brad@grio.com"]
11
+ spec.date = %q{2014-08-22}
12
+ spec.summary = %q{Generates looker signed urls}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,78 @@
1
+ require "grnds/looker/hmac/version"
2
+ require 'cgi'
3
+ require 'securerandom'
4
+ require 'base64'
5
+ require 'json'
6
+ require 'openssl'
7
+
8
+ module Grnds
9
+ module Looker
10
+ module Hmac
11
+ class SignedUrlGenerator
12
+
13
+ def initialize(config)
14
+ @config = config
15
+ end
16
+
17
+ def getUrl()
18
+
19
+ secret = ENV['LOOKER_EMBED_SECRET']
20
+
21
+ json_external_user_id = @config[:external_user_id].to_json
22
+ json_first_name = @config[:first_name].to_json
23
+ json_last_name = @config[:last_name].to_json
24
+ json_permissions = @config[:permissions].to_json
25
+ json_models = @config[:models].to_json
26
+ json_access_filters = {}.to_json
27
+
28
+ path = @config[:path_root] + CGI.escape(@config[:embed_path])
29
+
30
+ json_session_length = 60.to_json
31
+ json_force_logout_login = true.to_json
32
+
33
+ json_current_time = Time.now.to_i.to_json
34
+ json_nonce = SecureRandom.hex(16).to_json
35
+
36
+ string_to_sign = ''
37
+ string_to_sign += @config[:host] + "\n"
38
+ string_to_sign += path + "\n"
39
+ string_to_sign += json_nonce + "\n"
40
+ string_to_sign += json_current_time + "\n"
41
+ string_to_sign += json_session_length + "\n"
42
+ string_to_sign += json_external_user_id + "\n"
43
+ string_to_sign += json_permissions + "\n"
44
+ string_to_sign += json_models + "\n"
45
+ string_to_sign += json_access_filters
46
+
47
+ signature = Base64.encode64(
48
+ OpenSSL::HMAC.digest(
49
+ OpenSSL::Digest::Digest.new('sha1'),
50
+ secret,
51
+ string_to_sign.force_encoding('utf-8'))).strip
52
+
53
+ query_params = {
54
+ nonce: json_nonce,
55
+ time: json_current_time,
56
+ session_length: json_session_length,
57
+ external_user_id: json_external_user_id,
58
+ permissions: json_permissions,
59
+ models: json_models,
60
+ access_filters: json_access_filters,
61
+ first_name: json_first_name,
62
+ last_name: json_last_name,
63
+ force_logout_login: json_force_logout_login,
64
+ signature: signature
65
+ }
66
+
67
+ query_items = []
68
+ query_params.each_pair do |k,v|
69
+ query_items << k.to_s + "=" + CGI.escape(v)
70
+ end
71
+
72
+ query_string = query_items.join('&')
73
+ "https://" + @config[:host] + path + '?' + query_string + "\n"
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,7 @@
1
+ module Grnds
2
+ module Looker
3
+ module Hmac
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grnds-looker-hmac
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bradley Johnson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description:
42
+ email:
43
+ - brad@grio.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - grnds-looker-hmac.gemspec
54
+ - lib/grnds/looker/hmac.rb
55
+ - lib/grnds/looker/hmac/version.rb
56
+ homepage: ''
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.4.1
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Generates looker signed urls
80
+ test_files: []