not_analytics_client 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 96e32682a9b4ec232b965ac59ff71bbe7e5d86c7f947779bb3b83cfe58d94266
4
+ data.tar.gz: 205e044696c3c520768486df92885c3a0cf840fab318b033332eb376f0a0fac9
5
+ SHA512:
6
+ metadata.gz: 19a288f89afe50118d72c27d07735924d4d1db0be62c3319a30d7af6b02eedb5397b318ab84e60c9694f31b7c06f556637a22de1ed9de2f4e028590a3f8626b3
7
+ data.tar.gz: a9ff86c62ad46da189101d760c147076df26ea0fff2e811299757d8acfb0dcfff8b9ab7c814423374cb9eeaf13fe2131cf774f6e3748c1f6b6e6033778b40352
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in not-analytics-client.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ not_analytics_client (0.2.0)
5
+ base64 (~> 0.1)
6
+ json (~> 2.5)
7
+ net-http (~> 0.1.1)
8
+ openssl (~> 2.2)
9
+ securerandom (~> 0.1)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ base64 (0.1.0)
15
+ io-wait (0.1.0)
16
+ json (2.5.1)
17
+ net-http (0.1.1)
18
+ net-protocol
19
+ uri
20
+ net-protocol (0.1.0)
21
+ io-wait
22
+ timeout
23
+ openssl (2.2.0)
24
+ rake (13.0.3)
25
+ securerandom (0.1.0)
26
+ timeout (0.1.1)
27
+ uri (0.10.1)
28
+
29
+ PLATFORMS
30
+ x86_64-linux
31
+
32
+ DEPENDENCIES
33
+ not_analytics_client!
34
+ rake (~> 13.0)
35
+
36
+ BUNDLED WITH
37
+ 2.2.3
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
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 NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <https://unlicense.org>
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # not Analytics Client
2
+
3
+ A client for [not Analytics](https://github.com/12joan/not-analytics).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'not-analytics-client', github: '12joan/not-analytics-client', branch: 'main'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ ## Usage
18
+
19
+ Instantiate a new Hit object for a given app ID.
20
+
21
+ ```ruby
22
+ hit = NotAnalyticsClient::Hit.new(
23
+ app_id: app_id,
24
+ event: '/some/path', # Optional
25
+ key: app_key, # Optional
26
+ )
27
+ ```
28
+
29
+ Send the Hit to a not Analytics server.
30
+
31
+ ```ruby
32
+ hit.post!(not_analytics_url: 'https://hit.example.com/')
33
+ # => #<Net::HTTPOK 200 OK readbody=true>
34
+ ```
35
+
36
+ Or output the JSON payload.
37
+
38
+ ```ruby
39
+ hit.payload
40
+ # => "{\"hit\":{\"app_id\":"...
41
+ ```
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'not_analytics_client'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require 'pry'
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'securerandom'
5
+ require 'net/http'
6
+
7
+ module NotAnalyticsClient
8
+ class Hit
9
+ def initialize(app_id:, event: nil, key: nil)
10
+ @app_id = app_id
11
+ @event = event
12
+ @key = key
13
+ end
14
+
15
+ def payload
16
+ {
17
+ hit: {
18
+ app_id: @app_id,
19
+ event: @event,
20
+ **auth_params,
21
+ }
22
+ }.to_json
23
+ end
24
+
25
+ def post!(not_analytics_url:)
26
+ uri = URI(not_analytics_url)
27
+
28
+ http = Net::HTTP.new(uri.host, uri.port)
29
+ http.use_ssl = uri.scheme == 'https'
30
+
31
+ request = Net::HTTP::Post.new(uri.request_uri, {
32
+ 'Content-Type' => 'application/json'
33
+ })
34
+
35
+ request.body = payload
36
+
37
+ http.request(request)
38
+ end
39
+
40
+ private
41
+
42
+ def auth_params
43
+ if @key.nil?
44
+ {}
45
+ else
46
+ nonce = SecureRandom.hex
47
+
48
+ MessageEncryptor.new(@key).encrypt_and_sign("#{nonce}:#{@event}").then do
49
+ {
50
+ nonce: nonce,
51
+ signature: _1.ciphertext,
52
+ iv: _1.iv,
53
+ auth_tag: _1.auth_tag,
54
+ }
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'openssl'
4
+ require 'base64'
5
+
6
+ module NotAnalyticsClient
7
+ MessageEncryptor = Struct.new(:key) do
8
+ def encrypt_and_sign(plain)
9
+ cipher = OpenSSL::Cipher.new('aes-256-gcm')
10
+ cipher.encrypt
11
+ cipher.key = Base64.decode64(key)
12
+ iv = cipher.random_iv
13
+ cipher.auth_data = ''
14
+ ciphertext = cipher.update(plain) + cipher.final
15
+ auth_tag = cipher.auth_tag
16
+
17
+ Struct.new(:ciphertext, :iv, :auth_tag).new(
18
+ Base64.encode64(ciphertext),
19
+ Base64.encode64(iv),
20
+ Base64.encode64(auth_tag),
21
+ )
22
+ end
23
+
24
+ def decrypt_and_verify(ciphertext, iv:, auth_tag:)
25
+ cipher = OpenSSL::Cipher.new('aes-256-gcm')
26
+ cipher.decrypt
27
+ cipher.key = Base64.decode64(key)
28
+ cipher.iv = Base64.decode64(iv)
29
+ cipher.auth_data = ''
30
+ cipher.auth_tag = Base64.decode64(auth_tag)
31
+
32
+ cipher.update(Base64.decode64(ciphertext)) + cipher.final
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NotAnalyticsClient
4
+ VERSION = '0.2.0'
5
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'not_analytics_client/version'
4
+ require_relative 'not_analytics_client/hit'
5
+ require_relative 'not_analytics_client/message_encryptor'
6
+
7
+ module NotAnalyticsClient
8
+ class Error < StandardError; end
9
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/not_analytics_client/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'not_analytics_client'
7
+ spec.version = NotAnalyticsClient::VERSION
8
+ spec.authors = ['Joe Anderson']
9
+ spec.email = ['joe@osbert.me']
10
+
11
+ spec.summary = 'Client for not-analytics'
12
+ spec.homepage = 'https://github.com/12joan/not_analytics_client'
13
+ spec.license = 'Unlicense'
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = spec.homepage
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
23
+ end
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_dependency 'openssl', '~> 2.2'
29
+ spec.add_dependency 'base64', '~> 0.1'
30
+ spec.add_dependency 'json', '~> 2.5'
31
+ spec.add_dependency 'securerandom', '~> 0.1'
32
+ spec.add_dependency 'net-http', '~> 0.1.1'
33
+
34
+ # For more information and examples about making a new gem, checkout our
35
+ # guide at: https://bundler.io/guides/creating_gem.html
36
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: not_analytics_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Joe Anderson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-03-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: openssl
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: base64
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.5'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: securerandom
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: net-http
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.1.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.1.1
83
+ description:
84
+ email:
85
+ - joe@osbert.me
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - LICENSE
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - lib/not_analytics_client.rb
99
+ - lib/not_analytics_client/hit.rb
100
+ - lib/not_analytics_client/message_encryptor.rb
101
+ - lib/not_analytics_client/version.rb
102
+ - not_analytics_client.gemspec
103
+ homepage: https://github.com/12joan/not_analytics_client
104
+ licenses:
105
+ - Unlicense
106
+ metadata:
107
+ homepage_uri: https://github.com/12joan/not_analytics_client
108
+ source_code_uri: https://github.com/12joan/not_analytics_client
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 2.3.0
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubygems_version: 3.2.22
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Client for not-analytics
128
+ test_files: []