firefighter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d80549aec3125f214030d98787d105c9c650c2ad
4
+ data.tar.gz: 6b36a29cf7599efa0ef62e9fbf2e88d0e6dbc78f
5
+ SHA512:
6
+ metadata.gz: 6d5edc84be85b2052aa4aacfa1dbad325726716df41a6292071a46d2fbd015a03124d59b7de0c7e71bf50d77f18aef9e83d7ca2ac7919005fa447fc379973e24
7
+ data.tar.gz: 2638acf2cd12b408f77d52c449ab59b9f4724689f4f953476af09e66029d1cde7aaeb2d35c49afe5204cecf24b5407ca42a4035d3c5d7cf19eed94ac0c0439aa
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at phoetmail@googlemail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in firefighter.gemspec
6
+ gemspec
@@ -0,0 +1,68 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ firefighter (0.1.0)
5
+ http (~> 3.0)
6
+ jwt (~> 2.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.5.2)
12
+ public_suffix (>= 2.0.2, < 4.0)
13
+ crack (0.4.3)
14
+ safe_yaml (~> 1.0.0)
15
+ diff-lcs (1.3)
16
+ domain_name (0.5.20180417)
17
+ unf (>= 0.0.5, < 1.0.0)
18
+ hashdiff (0.3.7)
19
+ http (3.3.0)
20
+ addressable (~> 2.3)
21
+ http-cookie (~> 1.0)
22
+ http-form_data (~> 2.0)
23
+ http_parser.rb (~> 0.6.0)
24
+ http-cookie (1.0.3)
25
+ domain_name (~> 0.5)
26
+ http-form_data (2.1.1)
27
+ http_parser.rb (0.6.0)
28
+ jwt (2.1.0)
29
+ public_suffix (3.0.2)
30
+ rake (10.5.0)
31
+ rspec (3.7.0)
32
+ rspec-core (~> 3.7.0)
33
+ rspec-expectations (~> 3.7.0)
34
+ rspec-mocks (~> 3.7.0)
35
+ rspec-core (3.7.1)
36
+ rspec-support (~> 3.7.0)
37
+ rspec-expectations (3.7.0)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.7.0)
40
+ rspec-mocks (3.7.0)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.7.0)
43
+ rspec-support (3.7.1)
44
+ safe_yaml (1.0.4)
45
+ timecop (0.9.1)
46
+ unf (0.1.4)
47
+ unf_ext
48
+ unf_ext (0.0.7.5)
49
+ vcr (4.0.0)
50
+ webmock (3.4.2)
51
+ addressable (>= 2.3.6)
52
+ crack (>= 0.3.2)
53
+ hashdiff
54
+
55
+ PLATFORMS
56
+ ruby
57
+
58
+ DEPENDENCIES
59
+ bundler (~> 1.16)
60
+ firefighter!
61
+ rake (~> 10.0)
62
+ rspec (~> 3.0)
63
+ timecop (~> 0.9)
64
+ vcr (~> 4.0)
65
+ webmock (~> 3.4)
66
+
67
+ BUNDLED WITH
68
+ 1.16.1
@@ -0,0 +1,41 @@
1
+ # Firefighter
2
+
3
+ Talk to Firebase API from Ruby:
4
+
5
+ - signup
6
+ - read, write, add data
7
+ - generate JWT tokens for token-auth
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'firefighter'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install firefighter
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ 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).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/phoet/firefighter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
38
+
39
+ ## Code of Conduct
40
+
41
+ Everyone interacting in the Firefighter project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/phoet/firefighter/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "firefighter"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -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,40 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "firefighter/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "firefighter"
8
+ spec.version = Firefighter::VERSION
9
+ spec.authors = ["phoet"]
10
+ spec.email = ["phoetmail@googlemail.com"]
11
+
12
+ spec.summary = %q{Firebase API Wrapper}
13
+ spec.description = %q{Firebase API Wrapper}
14
+ spec.homepage = "http://github.com/penseo/firefighter"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["allowed_push_host"] = 'https://rubygems.org'
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
25
+ f.match(%r{^(test|spec|features)/})
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency "http", "~> 3.0"
32
+ spec.add_dependency "jwt", "~> 2.0"
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.16"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rspec", "~> 3.0"
37
+ spec.add_development_dependency "timecop", "~> 0.9"
38
+ spec.add_development_dependency "vcr", "~> 4.0"
39
+ spec.add_development_dependency "webmock", "~> 3.4"
40
+ end
@@ -0,0 +1,3 @@
1
+ require "firefighter/version"
2
+ require "firefighter/realtime_database"
3
+ require "firefighter/token_generator"
@@ -0,0 +1,74 @@
1
+ require 'logger'
2
+ require 'json'
3
+ require 'http'
4
+
5
+ module Firefighter
6
+ class RealtimeDatabase
7
+ def self.from_env
8
+ config = {
9
+ api_key: ENV['FIREBASE_WEB_API_KEY'],
10
+ db_name: ENV['FIREBASE_WEB_DB_NAME'],
11
+ db_secret: ENV['FIREBASE_WEB_DB_SECRET']
12
+ }
13
+ new(config)
14
+ end
15
+
16
+ def initialize(api_key:, db_name:, db_secret:, logger: Logger.new(STDOUT))
17
+ @api_key = api_key
18
+ @db_name = db_name
19
+ @db_secret = db_secret
20
+ @logger = logger
21
+ end
22
+
23
+ def signup(email, password)
24
+ url = "https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key=#{@api_key}"
25
+ data = {
26
+ email: email,
27
+ password: password,
28
+ returnSecureToken: true
29
+ }
30
+ call(:post, url, data)
31
+ end
32
+
33
+ def write(path, data)
34
+ url = endpoint(path)
35
+ call(:put, url, data)
36
+ end
37
+
38
+ def add(path, data)
39
+ url = endpoint(path)
40
+ call(:post, url, data)
41
+ end
42
+
43
+ def read(path)
44
+ url = endpoint(path)
45
+ get(url)
46
+ end
47
+
48
+ private
49
+
50
+ def call(method, url, data)
51
+ response = HTTP.send(method, url, headers: {'Content-Type' => 'application/json'}, body: JSON.dump(data))
52
+ if response.status == 200
53
+ JSON.parse(response.body)
54
+ else
55
+ @logger.warn "firebase #{method} failed #{url} #{response.body}"
56
+ raise "firebase #{method} failed #{url} #{response.body}"
57
+ end
58
+ end
59
+
60
+ def get(url)
61
+ response = HTTP.get(url, headers: {'Content-Type' => 'application/json'})
62
+ if response.status == 200
63
+ JSON.parse(response.body)
64
+ else
65
+ @logger.warn "firebase get failed #{url} #{response.body}"
66
+ raise "firebase get failed #{url} #{response.body}"
67
+ end
68
+ end
69
+
70
+ def endpoint(path)
71
+ "https://#{@db_name}.firebaseio.com/#{path}.json?auth=#{@db_secret}"
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,41 @@
1
+ require 'jwt'
2
+
3
+ # https://firebase.google.com/docs/auth/admin/create-custom-tokens
4
+ module Firefighter
5
+ class TokenGenerator
6
+ def self.from_env
7
+ config = {
8
+ service_account_email: ENV['FIREBASE_SERVICE_ACCOUNT_EMAIL'],
9
+ private_key: OpenSSL::PKey::RSA.new(ENV['FIREBASE_PRIVATE_KEY_DATA']),
10
+ algorithm: 'RS256',
11
+ }
12
+ new(config)
13
+ end
14
+
15
+ def initialize(service_account_email:, private_key:, algorithm:, logger: Logger.new(STDOUT))
16
+ @service_account_email = service_account_email
17
+ @private_key = private_key
18
+ @algorithm = algorithm
19
+ @logger = logger
20
+ end
21
+
22
+ def create_token(uid, data: {}, expiration: 60 * 60)
23
+ now_seconds = Time.now.to_i
24
+ payload = {
25
+ iss: @service_account_email,
26
+ sub: @service_account_email,
27
+ aud: 'https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit',
28
+ iat: now_seconds,
29
+ exp: now_seconds + expiration, # Maximum expiration time is one hour
30
+ uid: uid,
31
+ data: data,
32
+ }
33
+
34
+ ::JWT.encode(payload, @private_key, @algorithm)
35
+ end
36
+
37
+ def read_token(token)
38
+ JWT.decode(token, @private_key, true, algorithm: @algorithm).first
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module Firefighter
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: firefighter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - phoet
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-07-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jwt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: timecop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.9'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.9'
97
+ - !ruby/object:Gem::Dependency
98
+ name: vcr
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '4.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '4.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.4'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.4'
125
+ description: Firebase API Wrapper
126
+ email:
127
+ - phoetmail@googlemail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - CODE_OF_CONDUCT.md
135
+ - Gemfile
136
+ - Gemfile.lock
137
+ - README.md
138
+ - Rakefile
139
+ - bin/console
140
+ - bin/setup
141
+ - firefighter.gemspec
142
+ - lib/firefighter.rb
143
+ - lib/firefighter/realtime_database.rb
144
+ - lib/firefighter/token_generator.rb
145
+ - lib/firefighter/version.rb
146
+ homepage: http://github.com/penseo/firefighter
147
+ licenses: []
148
+ metadata:
149
+ allowed_push_host: https://rubygems.org
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.6.13
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: Firebase API Wrapper
170
+ test_files: []