svix 0.15.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 564e5fed87a9ec452413048f8b5a3d52ab056b0011be18a7d964fd5b6c8878f0
4
+ data.tar.gz: 882877ae573b6d1fb5d30ab5840255a53e8a8a2572910aaa90bdcc9745c56fb3
5
+ SHA512:
6
+ metadata.gz: dbbe1be93f461ca144d5617091cc65280226beaa9d7e993c803f208ba5ce2f13279d79643c1a130096ef0fddd3671c4bab5d47da935f4293ac07435acfa2ab35
7
+ data.tar.gz: 67c48bf75dc5c2953638e38ef5af181a239ff1af90d4bc01b9915ff4c054e95101a95a45adbba0f2ea90915e67a8230eadfa5f86549a454c355f612f47ba7ef6
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ svix (0.15.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.4.4)
10
+ rake (10.5.0)
11
+ rspec (3.10.0)
12
+ rspec-core (~> 3.10.0)
13
+ rspec-expectations (~> 3.10.0)
14
+ rspec-mocks (~> 3.10.0)
15
+ rspec-core (3.10.1)
16
+ rspec-support (~> 3.10.0)
17
+ rspec-expectations (3.10.1)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.10.0)
20
+ rspec-mocks (3.10.2)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.10.0)
23
+ rspec-support (3.10.2)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.17)
30
+ rake (~> 10.0)
31
+ rspec (~> 3.2)
32
+ svix!
33
+
34
+ BUNDLED WITH
35
+ 1.17.2
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Svix Ruby
2
+
3
+ Please refer to [the documentation](https://docs.svix.com) for usage instructions.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'svix'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install svix
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+
28
+ ### Run Tests
29
+
30
+ bundle exec rspec spec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/src/svix.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "json"
2
+ require "openssl"
3
+ require 'Base64'
4
+
5
+ require "svix/version"
6
+ require "svix/errors"
7
+ require "svix/webhook"
8
+ require "svix/util"
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Svix
4
+ class SvixError < StandardError
5
+ attr_reader :message
6
+
7
+ def initialize(message = nil)
8
+ @message = message
9
+ end
10
+ end
11
+
12
+ class WebhookVerificationError < SvixError
13
+ end
14
+ end
data/src/svix/util.rb ADDED
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Constant time string comparison, for fixed length strings.
4
+ # Code borrowed from ActiveSupport
5
+ # https://github.com/rails/rails/blob/75ac626c4e21129d8296d4206a1960563cc3d4aa/activesupport/lib/active_support/security_utils.rb#L33
6
+ #
7
+ # The values compared should be of fixed length, such as strings
8
+ # that have already been processed by HMAC. Raises in case of length mismatch.
9
+ module Svix
10
+ if defined?(OpenSSL.fixed_length_secure_compare)
11
+ def fixed_length_secure_compare(a, b)
12
+ OpenSSL.fixed_length_secure_compare(a, b)
13
+ end
14
+ else
15
+ def fixed_length_secure_compare(a, b)
16
+ raise ArgumentError, "string length mismatch." unless a.bytesize == b.bytesize
17
+
18
+ l = a.unpack "C#{a.bytesize}"
19
+
20
+ res = 0
21
+ b.each_byte { |byte| res |= byte ^ l.shift }
22
+ res == 0
23
+ end
24
+ end
25
+ module_function :fixed_length_secure_compare
26
+
27
+ # Secure string comparison for strings of variable length.
28
+ #
29
+ # While a timing attack would not be able to discern the content of
30
+ # a secret compared via secure_compare, it is possible to determine
31
+ # the secret length. This should be considered when using secure_compare
32
+ # to compare weak, short secrets to user input.
33
+ def secure_compare(a, b)
34
+ a.length == b.length && fixed_length_secure_compare(a, b)
35
+ end
36
+ module_function :secure_compare
37
+ end
@@ -0,0 +1,3 @@
1
+ module Svix
2
+ VERSION = "0.15.0"
3
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Svix
4
+ class Webhook
5
+ def initialize(secret)
6
+ @secret = Base64.decode64(secret)
7
+ end
8
+
9
+ def verify(payload, headers)
10
+ msgId = headers["svix-id"]
11
+ msgSignature = headers["svix-signature"]
12
+ msgTimestamp = headers["svix-timestamp"]
13
+ if !msgSignature || !msgId || !msgTimestamp
14
+ raise WebhookVerificationError, "Missing required headers"
15
+ end
16
+
17
+ toSign = "#{msgId}.#{msgTimestamp}.#{payload}"
18
+ signature = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), @secret, toSign)).strip()
19
+
20
+ passedSignatures = msgSignature.split(" ")
21
+ passedSignatures.each do |versionedSignature|
22
+ version, expectedSignature = versionedSignature.split(',', 2)
23
+ if version != "v1"
24
+ next
25
+ end
26
+ if Svix.secure_compare(signature, expectedSignature)
27
+ return JSON.parse(payload, symbolize_names: true)
28
+ end
29
+ end
30
+ raise WebhookVerificationError, "No matching signature found"
31
+ end
32
+ end
33
+ end
data/svix.gemspec ADDED
@@ -0,0 +1,43 @@
1
+
2
+ lib = File.expand_path("../src", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "svix/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "svix"
8
+ spec.version = Svix::VERSION
9
+ spec.authors = ["Svix"]
10
+ spec.email = ["support@svix.com"]
11
+ spec.license = "MIT"
12
+
13
+ spec.summary = "Ruby bindings for the Svix API"
14
+ spec.description = "Svix makes webhooks easy and reliable. " \
15
+ "Learn more at https://www.svix.com"
16
+ spec.homepage = "https://www.svix.com"
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
22
+
23
+ spec.metadata["homepage_uri"] = spec.homepage
24
+ spec.metadata["source_code_uri"] = "https://github.com/svixhq/svix-libs"
25
+ spec.metadata["changelog_uri"] = "https://github.com/svixhq/svix-libs/blob/main/ChangeLog.md"
26
+ else
27
+ raise "RubyGems 2.0 or newer is required to protect against " \
28
+ "public gem pushes."
29
+ end
30
+
31
+ # Specify which files should be added to the gem when it is released.
32
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
33
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
34
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
35
+ end
36
+ spec.bindir = "exe"
37
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38
+ spec.require_paths = ["src"]
39
+
40
+ spec.add_development_dependency "bundler", "~> 1.17"
41
+ spec.add_development_dependency "rake", "~> 10.0"
42
+ spec.add_development_dependency "rspec", "~> 3.2"
43
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: svix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.15.0
5
+ platform: ruby
6
+ authors:
7
+ - Svix
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-06-04 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.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ description: Svix makes webhooks easy and reliable. Learn more at https://www.svix.com
56
+ email:
57
+ - support@svix.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - README.md
66
+ - Rakefile
67
+ - src/svix.rb
68
+ - src/svix/errors.rb
69
+ - src/svix/util.rb
70
+ - src/svix/version.rb
71
+ - src/svix/webhook.rb
72
+ - svix.gemspec
73
+ homepage: https://www.svix.com
74
+ licenses:
75
+ - MIT
76
+ metadata:
77
+ allowed_push_host: https://rubygems.org
78
+ homepage_uri: https://www.svix.com
79
+ source_code_uri: https://github.com/svixhq/svix-libs
80
+ changelog_uri: https://github.com/svixhq/svix-libs/blob/main/ChangeLog.md
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - src
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubygems_version: 3.0.3
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Ruby bindings for the Svix API
100
+ test_files: []