rainforest_auth 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/rainforest/auth.rb +48 -0
  2. metadata +94 -0
@@ -0,0 +1,48 @@
1
+ #
2
+ # Rainforest Authenitcation
3
+ #
4
+ #
5
+ # @author Russell Smith <russ@rainforestqa.com>
6
+ # @copyright CLDRDR Inc, 2013
7
+
8
+ require 'openssl'
9
+ require 'json'
10
+ require 'awesome_print'
11
+
12
+ class RainforestAuth
13
+
14
+ attr_reader :key
15
+
16
+ def initialize key
17
+ @key = key
18
+ self
19
+ end
20
+
21
+ # Return a signature for a command and specified options
22
+ def sign command, options
23
+ OpenSSL::HMAC.hexdigest(digest, @key, merge_data(command, options))
24
+ end
25
+
26
+ # Verify a digest vs command and options
27
+ def verify digest, command, options
28
+ digest == sign(command, options)
29
+ end
30
+
31
+ # Run a block if valid
32
+ def run_if_valid digest, command, options, &block
33
+ if verify digest, command, options
34
+ block.call command, options
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def digest
41
+ OpenSSL::Digest::Digest.new 'sha1'
42
+ end
43
+
44
+ def merge_data command, options
45
+ {command: command, options: options}.to_json
46
+ end
47
+
48
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rainforest_auth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Russell Smith
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: simplecov
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Signs / Authenticates messages
63
+ email: russ@rainforestqa.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - lib/rainforest/auth.rb
69
+ homepage: https://www.rainforestqa.com/
70
+ licenses: []
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 1.8.24
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Authentication of messages for Rainforest webhooks
93
+ test_files: []
94
+ has_rdoc: