firefighter 0.2.1 → 1.3.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 +5 -5
- data/.circleci/config.yml +1 -1
- data/.irbrc +8 -0
- data/CHANGELOG.md +22 -0
- data/Gemfile.lock +44 -42
- data/LICENSE.txt +21 -0
- data/README.md +65 -6
- data/firefighter.gemspec +8 -8
- data/lib/firefighter/identitytoolkit.rb +18 -20
- data/lib/firefighter/realtime_database.rb +28 -8
- data/lib/firefighter/token_generator.rb +13 -3
- data/lib/firefighter/version.rb +1 -1
- data/lib/firefighter/web.rb +23 -2
- metadata +34 -32
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 00b94b5878f703b6332b33493fe3c09ed2b9860a8d402952ce91fd047640ee67
         | 
| 4 | 
            +
              data.tar.gz: 586bb23666589a122d0722b9772e0d850d27fca12c49eb9ddf70ffd52cc47c3d
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 0ba9000e62c3baf013389f774faee390fff31fce12deb119e53d269ff300a7630ac20a10c1de2badb4b9936c24db602b6d13a336c98f017210b25dfda72156b0
         | 
| 7 | 
            +
              data.tar.gz: 356363578224f2e8a95959a7f3a4ce1d770f0f74abd9e13ecbb645950db304fe8c2acaeacde444d6b9e34fcf1aa8b40297d03b191701cc63af1d6e96e1ebf02a
         | 
    
        data/.circleci/config.yml
    CHANGED
    
    
    
        data/.irbrc
    ADDED
    
    
    
        data/CHANGELOG.md
    ADDED
    
    | @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            # Changelog
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            ### 1.3.0
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            - adds db_host for realtime database to enable different hosting locations
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            ### 1.2.0
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            - adds `Firefighter::Identitytoolkit#verify_password`
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            ### 1.1.0
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            - compatibility with ruby 2.7.1
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            ### 1.0.0
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            - adds `Firefighter::RealtimeDatabase#listen` (experimental)
         | 
| 18 | 
            +
            - moves `Firefighter::RealtimeDatabase#fetch_access_token` to `Firefighter::TokenGenerator#fetch_access_token` (breaking)
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            ### 0.3.0
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            - adds `Firefighter::RealtimeDatabase#delete`
         | 
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -1,70 +1,72 @@ | |
| 1 1 | 
             
            PATH
         | 
| 2 2 | 
             
              remote: .
         | 
| 3 3 | 
             
              specs:
         | 
| 4 | 
            -
                firefighter ( | 
| 5 | 
            -
                  http ( | 
| 6 | 
            -
                  jwt ( | 
| 4 | 
            +
                firefighter (1.3.0)
         | 
| 5 | 
            +
                  http (> 3.0)
         | 
| 6 | 
            +
                  jwt (> 2.0)
         | 
| 7 7 |  | 
| 8 8 | 
             
            GEM
         | 
| 9 9 | 
             
              remote: https://rubygems.org/
         | 
| 10 10 | 
             
              specs:
         | 
| 11 | 
            -
                addressable (2. | 
| 12 | 
            -
                  public_suffix (>= 2.0.2, <  | 
| 13 | 
            -
                byebug ( | 
| 11 | 
            +
                addressable (2.7.0)
         | 
| 12 | 
            +
                  public_suffix (>= 2.0.2, < 5.0)
         | 
| 13 | 
            +
                byebug (11.1.3)
         | 
| 14 14 | 
             
                crack (0.4.3)
         | 
| 15 15 | 
             
                  safe_yaml (~> 1.0.0)
         | 
| 16 | 
            -
                diff-lcs (1. | 
| 17 | 
            -
                domain_name (0.5. | 
| 16 | 
            +
                diff-lcs (1.4.4)
         | 
| 17 | 
            +
                domain_name (0.5.20190701)
         | 
| 18 18 | 
             
                  unf (>= 0.0.5, < 1.0.0)
         | 
| 19 | 
            -
                 | 
| 20 | 
            -
                 | 
| 19 | 
            +
                ffi (1.13.1)
         | 
| 20 | 
            +
                ffi-compiler (1.0.1)
         | 
| 21 | 
            +
                  ffi (>= 1.0.0)
         | 
| 22 | 
            +
                  rake
         | 
| 23 | 
            +
                hashdiff (1.0.1)
         | 
| 24 | 
            +
                http (4.4.1)
         | 
| 21 25 | 
             
                  addressable (~> 2.3)
         | 
| 22 26 | 
             
                  http-cookie (~> 1.0)
         | 
| 23 | 
            -
                  http-form_data (~> 2. | 
| 24 | 
            -
                   | 
| 27 | 
            +
                  http-form_data (~> 2.2)
         | 
| 28 | 
            +
                  http-parser (~> 1.2.0)
         | 
| 25 29 | 
             
                http-cookie (1.0.3)
         | 
| 26 30 | 
             
                  domain_name (~> 0.5)
         | 
| 27 | 
            -
                http-form_data (2. | 
| 28 | 
            -
                 | 
| 29 | 
            -
             | 
| 30 | 
            -
                 | 
| 31 | 
            -
                 | 
| 32 | 
            -
                 | 
| 33 | 
            -
             | 
| 34 | 
            -
                  rspec- | 
| 35 | 
            -
                  rspec- | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 31 | 
            +
                http-form_data (2.3.0)
         | 
| 32 | 
            +
                http-parser (1.2.1)
         | 
| 33 | 
            +
                  ffi-compiler (>= 1.0, < 2.0)
         | 
| 34 | 
            +
                jwt (2.2.1)
         | 
| 35 | 
            +
                public_suffix (4.0.5)
         | 
| 36 | 
            +
                rake (13.0.1)
         | 
| 37 | 
            +
                rspec (3.9.0)
         | 
| 38 | 
            +
                  rspec-core (~> 3.9.0)
         | 
| 39 | 
            +
                  rspec-expectations (~> 3.9.0)
         | 
| 40 | 
            +
                  rspec-mocks (~> 3.9.0)
         | 
| 41 | 
            +
                rspec-core (3.9.2)
         | 
| 42 | 
            +
                  rspec-support (~> 3.9.3)
         | 
| 43 | 
            +
                rspec-expectations (3.9.2)
         | 
| 39 44 | 
             
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 40 | 
            -
                  rspec-support (~> 3. | 
| 41 | 
            -
                rspec-mocks (3. | 
| 45 | 
            +
                  rspec-support (~> 3.9.0)
         | 
| 46 | 
            +
                rspec-mocks (3.9.1)
         | 
| 42 47 | 
             
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 43 | 
            -
                  rspec-support (~> 3. | 
| 44 | 
            -
                rspec-support (3. | 
| 45 | 
            -
                safe_yaml (1.0. | 
| 48 | 
            +
                  rspec-support (~> 3.9.0)
         | 
| 49 | 
            +
                rspec-support (3.9.3)
         | 
| 50 | 
            +
                safe_yaml (1.0.5)
         | 
| 46 51 | 
             
                timecop (0.9.1)
         | 
| 47 52 | 
             
                unf (0.1.4)
         | 
| 48 53 | 
             
                  unf_ext
         | 
| 49 | 
            -
                unf_ext (0.0.7. | 
| 50 | 
            -
                vcr ( | 
| 51 | 
            -
                webmock (3. | 
| 54 | 
            +
                unf_ext (0.0.7.7)
         | 
| 55 | 
            +
                vcr (6.0.0)
         | 
| 56 | 
            +
                webmock (3.8.3)
         | 
| 52 57 | 
             
                  addressable (>= 2.3.6)
         | 
| 53 58 | 
             
                  crack (>= 0.3.2)
         | 
| 54 | 
            -
                  hashdiff
         | 
| 59 | 
            +
                  hashdiff (>= 0.4.0, < 2.0.0)
         | 
| 55 60 |  | 
| 56 61 | 
             
            PLATFORMS
         | 
| 57 62 | 
             
              ruby
         | 
| 58 63 |  | 
| 59 64 | 
             
            DEPENDENCIES
         | 
| 60 | 
            -
              bundler | 
| 65 | 
            +
              bundler
         | 
| 61 66 | 
             
              byebug
         | 
| 62 67 | 
             
              firefighter!
         | 
| 63 | 
            -
              rake | 
| 64 | 
            -
              rspec | 
| 65 | 
            -
              timecop | 
| 66 | 
            -
              vcr | 
| 67 | 
            -
              webmock | 
| 68 | 
            -
             | 
| 69 | 
            -
            BUNDLED WITH
         | 
| 70 | 
            -
               1.16.1
         | 
| 68 | 
            +
              rake
         | 
| 69 | 
            +
              rspec
         | 
| 70 | 
            +
              timecop
         | 
| 71 | 
            +
              vcr
         | 
| 72 | 
            +
              webmock
         | 
    
        data/LICENSE.txt
    ADDED
    
    | @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            The MIT License (MIT)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Copyright (c) 2017 phoet
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining a copy
         | 
| 6 | 
            +
            of this software and associated documentation files (the "Software"), to deal
         | 
| 7 | 
            +
            in the Software without restriction, including without limitation the rights
         | 
| 8 | 
            +
            to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         | 
| 9 | 
            +
            copies of the Software, and to permit persons to whom the Software is
         | 
| 10 | 
            +
            furnished to do so, subject to the following conditions:
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            The above copyright notice and this permission notice shall be included in
         | 
| 13 | 
            +
            all copies or substantial portions of the Software.
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         | 
| 16 | 
            +
            IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         | 
| 17 | 
            +
            FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         | 
| 18 | 
            +
            AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         | 
| 19 | 
            +
            LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         | 
| 20 | 
            +
            OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
         | 
| 21 | 
            +
            THE SOFTWARE.
         | 
    
        data/README.md
    CHANGED
    
    | @@ -2,9 +2,9 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            Talk to Firebase API from Ruby:
         | 
| 4 4 |  | 
| 5 | 
            -
            - signup
         | 
| 6 | 
            -
            - read, write, add data
         | 
| 7 | 
            -
            - generate JWT tokens for token-auth
         | 
| 5 | 
            +
            - identity: signup, account_info, accounts_download, verify_password
         | 
| 6 | 
            +
            - realtime: read, listen, write, add, delete data
         | 
| 7 | 
            +
            - tokens: generate JWT tokens for token-auth
         | 
| 8 8 |  | 
| 9 9 | 
             
            ## Installation
         | 
| 10 10 |  | 
| @@ -24,7 +24,62 @@ Or install it yourself as: | |
| 24 24 |  | 
| 25 25 | 
             
            ## Usage
         | 
| 26 26 |  | 
| 27 | 
            -
             | 
| 27 | 
            +
            ```ruby
         | 
| 28 | 
            +
            # Firefighter::Identitytoolkit
         | 
| 29 | 
            +
            # from_env uses environment variables:
         | 
| 30 | 
            +
            # - FIREBASE_WEB_API_KEY
         | 
| 31 | 
            +
            # - FIREBASE_SERVICE_ACCOUNT_EMAIL
         | 
| 32 | 
            +
            identitytoolkit = Firefighter::Identitytoolkit.from_env
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            account = identitytoolkit.signup('test@test.de', 'totalgeheimespasswort')
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            account = identitytoolkit.account_info(account['idToken'])
         | 
| 37 | 
            +
             | 
| 38 | 
            +
            accounts = identitytoolkit.download_accounts
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            account = identitytoolkit.verify_password('test@test.de', 'totalgeheimespasswort')
         | 
| 41 | 
            +
            ```
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            ```ruby
         | 
| 44 | 
            +
            # Firefighter::RealtimeDatabase
         | 
| 45 | 
            +
            # from_env uses environment variables:
         | 
| 46 | 
            +
            # - FIREBASE_WEB_DB_NAME
         | 
| 47 | 
            +
            # - FIREBASE_WEB_DB_SECRET
         | 
| 48 | 
            +
            # - FIREBASE_WEB_DB_HOST (defaults to host for us-central1)
         | 
| 49 | 
            +
             | 
| 50 | 
            +
            realtime_database = Firefighter::RealtimeDatabase.from_env
         | 
| 51 | 
            +
             | 
| 52 | 
            +
            realtime_database.write("some-path/key", {some: 'data'})
         | 
| 53 | 
            +
             | 
| 54 | 
            +
            hash = realtime_database.read("some-path/key")
         | 
| 55 | 
            +
             | 
| 56 | 
            +
            realtime_database.add("some-path/list", {some: 'data'})
         | 
| 57 | 
            +
             | 
| 58 | 
            +
            list = realtime_database.read("some-path/list")
         | 
| 59 | 
            +
             | 
| 60 | 
            +
            realtime_database.delete("some-path/list")
         | 
| 61 | 
            +
             | 
| 62 | 
            +
            realtime_database.listen("some-test/write/") do |connection, event, path, data|
         | 
| 63 | 
            +
              puts event, path, data
         | 
| 64 | 
            +
              connection.close
         | 
| 65 | 
            +
            end
         | 
| 66 | 
            +
            ```
         | 
| 67 | 
            +
             | 
| 68 | 
            +
            ```ruby
         | 
| 69 | 
            +
            # Firefighter::TokenGenerator
         | 
| 70 | 
            +
            # from_env uses environment variables:
         | 
| 71 | 
            +
            # - FIREBASE_SERVICE_ACCOUNT_EMAIL
         | 
| 72 | 
            +
            # - FIREBASE_SERVICE_ACCOUNT_PRIVATE_KEY
         | 
| 73 | 
            +
            token_generator = Firefighter::TokenGenerator.from_env
         | 
| 74 | 
            +
             | 
| 75 | 
            +
            access_token = token_generator.create_access_token
         | 
| 76 | 
            +
             | 
| 77 | 
            +
            custom_token = token_generator.create_custom_token('someUid', data: {some: 'payload'})
         | 
| 78 | 
            +
             | 
| 79 | 
            +
            payload = token_generator.read_token(custom_token)
         | 
| 80 | 
            +
             | 
| 81 | 
            +
            token = token_generator.fetch_access_token
         | 
| 82 | 
            +
            ```
         | 
| 28 83 |  | 
| 29 84 | 
             
            ## Development
         | 
| 30 85 |  | 
| @@ -34,8 +89,12 @@ To install this gem onto your local machine, run `bundle exec rake install`. To | |
| 34 89 |  | 
| 35 90 | 
             
            ## Contributing
         | 
| 36 91 |  | 
| 37 | 
            -
            Bug reports and pull requests are welcome on GitHub at https://github.com/ | 
| 92 | 
            +
            Bug reports and pull requests are welcome on GitHub at https://github.com/penseo/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 93 |  | 
| 39 94 | 
             
            ## Code of Conduct
         | 
| 40 95 |  | 
| 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/ | 
| 96 | 
            +
            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/penseo/firefighter/blob/master/CODE_OF_CONDUCT.md).
         | 
| 97 | 
            +
             | 
| 98 | 
            +
            ## Changelog
         | 
| 99 | 
            +
             | 
| 100 | 
            +
            [changelog](https://github.com/penseo/firefighter/blob/master/CHANGELOG.md)
         | 
    
        data/firefighter.gemspec
    CHANGED
    
    | @@ -28,13 +28,13 @@ Gem::Specification.new do |spec| | |
| 28 28 | 
             
              spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
         | 
| 29 29 | 
             
              spec.require_paths = ["lib"]
         | 
| 30 30 |  | 
| 31 | 
            -
              spec.add_dependency "http", " | 
| 32 | 
            -
              spec.add_dependency "jwt", " | 
| 31 | 
            +
              spec.add_dependency "http", "> 3.0"
         | 
| 32 | 
            +
              spec.add_dependency "jwt", "> 2.0"
         | 
| 33 33 |  | 
| 34 | 
            -
              spec.add_development_dependency "bundler" | 
| 35 | 
            -
              spec.add_development_dependency "rake" | 
| 36 | 
            -
              spec.add_development_dependency "rspec" | 
| 37 | 
            -
              spec.add_development_dependency "vcr" | 
| 38 | 
            -
              spec.add_development_dependency "webmock" | 
| 39 | 
            -
              spec.add_development_dependency "timecop" | 
| 34 | 
            +
              spec.add_development_dependency "bundler"
         | 
| 35 | 
            +
              spec.add_development_dependency "rake"
         | 
| 36 | 
            +
              spec.add_development_dependency "rspec"
         | 
| 37 | 
            +
              spec.add_development_dependency "vcr"
         | 
| 38 | 
            +
              spec.add_development_dependency "webmock"
         | 
| 39 | 
            +
              spec.add_development_dependency "timecop"
         | 
| 40 40 | 
             
            end
         | 
| @@ -3,17 +3,25 @@ module Firefighter | |
| 3 3 | 
             
                include Web
         | 
| 4 4 |  | 
| 5 5 | 
             
                def self.from_env
         | 
| 6 | 
            -
                   | 
| 6 | 
            +
                  new(
         | 
| 7 7 | 
             
                    api_key: ENV['FIREBASE_WEB_API_KEY'],
         | 
| 8 8 | 
             
                    service_account_email: ENV['FIREBASE_SERVICE_ACCOUNT_EMAIL'],
         | 
| 9 | 
            -
                   | 
| 10 | 
            -
                  new(config)
         | 
| 9 | 
            +
                  )
         | 
| 11 10 | 
             
                end
         | 
| 12 11 |  | 
| 13 | 
            -
                def initialize(api_key:, service_account_email | 
| 12 | 
            +
                def initialize(api_key:, service_account_email:)
         | 
| 14 13 | 
             
                  @api_key = api_key
         | 
| 15 14 | 
             
                  @service_account_email = service_account_email
         | 
| 16 | 
            -
             | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def verify_password(email, password)
         | 
| 18 | 
            +
                  url = endpoint('verifyPassword')
         | 
| 19 | 
            +
                  data = {
         | 
| 20 | 
            +
                    email: email,
         | 
| 21 | 
            +
                    password: password,
         | 
| 22 | 
            +
                    returnSecureToken: true
         | 
| 23 | 
            +
                  }
         | 
| 24 | 
            +
                  call(:post, url, data)
         | 
| 17 25 | 
             
                end
         | 
| 18 26 |  | 
| 19 27 | 
             
                def signup(email, password)
         | 
| @@ -36,24 +44,14 @@ module Firefighter | |
| 36 44 | 
             
                  call(:post, url, data)
         | 
| 37 45 | 
             
                end
         | 
| 38 46 |  | 
| 39 | 
            -
                def download_accounts
         | 
| 40 | 
            -
                  url = endpoint('downloadAccount')
         | 
| 41 | 
            -
             | 
| 42 | 
            -
                  headers = {Authorization: "Bearer #{fetch_access_token}" }
         | 
| 43 | 
            -
             | 
| 47 | 
            +
                def download_accounts(access_token = TokenGenerator.from_env.fetch_access_token)
         | 
| 44 48 | 
             
                  users = []
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                  headers = {Authorization: "Bearer #{access_token}" }
         | 
| 51 | 
            +
                  url = endpoint('downloadAccount')
         | 
| 45 52 | 
             
                  paginate(url, headers: headers) { |data| users << data['users'] }
         | 
| 46 | 
            -
                  users.flatten.compact
         | 
| 47 | 
            -
                end
         | 
| 48 53 |  | 
| 49 | 
            -
             | 
| 50 | 
            -
                  url = 'https://accounts.google.com/o/oauth2/token'
         | 
| 51 | 
            -
                  data = {
         | 
| 52 | 
            -
                    assertion: @token_generator.create_access_token,
         | 
| 53 | 
            -
                    grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer'
         | 
| 54 | 
            -
                  }
         | 
| 55 | 
            -
                  response = call(:post, url, data)
         | 
| 56 | 
            -
                  response['access_token']
         | 
| 54 | 
            +
                  users.flatten.compact
         | 
| 57 55 | 
             
                end
         | 
| 58 56 |  | 
| 59 57 | 
             
                private
         | 
| @@ -3,16 +3,36 @@ module Firefighter | |
| 3 3 | 
             
                include Web
         | 
| 4 4 |  | 
| 5 5 | 
             
                def self.from_env
         | 
| 6 | 
            -
                   | 
| 6 | 
            +
                  new(
         | 
| 7 7 | 
             
                    db_name: ENV['FIREBASE_WEB_DB_NAME'],
         | 
| 8 | 
            -
                    db_secret: ENV['FIREBASE_WEB_DB_SECRET']
         | 
| 9 | 
            -
             | 
| 10 | 
            -
                   | 
| 8 | 
            +
                    db_secret: ENV['FIREBASE_WEB_DB_SECRET'],
         | 
| 9 | 
            +
                    db_host: ENV['FIREBASE_WEB_DB_HOST'] || DEFAULT_DB_HOST,
         | 
| 10 | 
            +
                  )
         | 
| 11 11 | 
             
                end
         | 
| 12 12 |  | 
| 13 | 
            -
                 | 
| 13 | 
            +
                DB_HOSTS = {
         | 
| 14 | 
            +
                  'us-central1' => 'firebaseio.com',
         | 
| 15 | 
            +
                  'europe-west1' => 'europe-west1.firebasedatabase.app',
         | 
| 16 | 
            +
                }
         | 
| 17 | 
            +
                DEFAULT_DB_HOST = DB_HOSTS['us-central1']
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def initialize(db_name:, db_secret:, db_host: DEFAULT_DB_HOST)
         | 
| 14 20 | 
             
                  @db_name = db_name
         | 
| 15 21 | 
             
                  @db_secret = db_secret
         | 
| 22 | 
            +
                  @db_host = db_host
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                def listen(path)
         | 
| 26 | 
            +
                  url = endpoint(path)
         | 
| 27 | 
            +
                  sse(url) do |connection, event, payload|
         | 
| 28 | 
            +
                    data = JSON.parse(payload)
         | 
| 29 | 
            +
                    yield connection, event, data['path'], data['data']
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                def read(path)
         | 
| 34 | 
            +
                  url = endpoint(path)
         | 
| 35 | 
            +
                  call(:get, url)
         | 
| 16 36 | 
             
                end
         | 
| 17 37 |  | 
| 18 38 | 
             
                def write(path, data)
         | 
| @@ -25,15 +45,15 @@ module Firefighter | |
| 25 45 | 
             
                  call(:post, url, data)
         | 
| 26 46 | 
             
                end
         | 
| 27 47 |  | 
| 28 | 
            -
                def  | 
| 48 | 
            +
                def delete(path)
         | 
| 29 49 | 
             
                  url = endpoint(path)
         | 
| 30 | 
            -
                  call(: | 
| 50 | 
            +
                  call(:delete, url)
         | 
| 31 51 | 
             
                end
         | 
| 32 52 |  | 
| 33 53 | 
             
                private
         | 
| 34 54 |  | 
| 35 55 | 
             
                def endpoint(path)
         | 
| 36 | 
            -
                  "https://#{@db_name} | 
| 56 | 
            +
                  "https://#{@db_name}.#{@db_host}/#{path}.json?auth=#{@db_secret}"
         | 
| 37 57 | 
             
                end
         | 
| 38 58 | 
             
              end
         | 
| 39 59 | 
             
            end
         | 
| @@ -3,12 +3,13 @@ require 'jwt' | |
| 3 3 | 
             
            # https://firebase.google.com/docs/auth/admin/create-custom-tokens
         | 
| 4 4 | 
             
            module Firefighter
         | 
| 5 5 | 
             
              class TokenGenerator
         | 
| 6 | 
            +
                include Web
         | 
| 7 | 
            +
             | 
| 6 8 | 
             
                def self.from_env
         | 
| 7 | 
            -
                   | 
| 9 | 
            +
                  new(
         | 
| 8 10 | 
             
                    service_account_email: ENV['FIREBASE_SERVICE_ACCOUNT_EMAIL'],
         | 
| 9 11 | 
             
                    service_account_private_key: ENV['FIREBASE_SERVICE_ACCOUNT_PRIVATE_KEY'],
         | 
| 10 | 
            -
                   | 
| 11 | 
            -
                  new(config)
         | 
| 12 | 
            +
                  )
         | 
| 12 13 | 
             
                end
         | 
| 13 14 |  | 
| 14 15 | 
             
                def initialize(service_account_email:, service_account_private_key:, algorithm: 'RS256')
         | 
| @@ -17,6 +18,15 @@ module Firefighter | |
| 17 18 | 
             
                  @private_key = OpenSSL::PKey::RSA.new(service_account_private_key)
         | 
| 18 19 | 
             
                end
         | 
| 19 20 |  | 
| 21 | 
            +
                def fetch_access_token
         | 
| 22 | 
            +
                  url = 'https://accounts.google.com/o/oauth2/token'
         | 
| 23 | 
            +
                  data = {
         | 
| 24 | 
            +
                    assertion: create_access_token,
         | 
| 25 | 
            +
                    grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer'
         | 
| 26 | 
            +
                  }
         | 
| 27 | 
            +
                  response = call(:post, url, data)
         | 
| 28 | 
            +
                  response['access_token']
         | 
| 29 | 
            +
                end
         | 
| 20 30 |  | 
| 21 31 | 
             
                def create_access_token(expiration: 60 * 60)
         | 
| 22 32 | 
             
                  now_seconds = Time.now.to_i
         | 
    
        data/lib/firefighter/version.rb
    CHANGED
    
    
    
        data/lib/firefighter/web.rb
    CHANGED
    
    | @@ -8,10 +8,31 @@ module Firefighter | |
| 8 8 | 
             
                  @logger ||= Logger.new(STDOUT)
         | 
| 9 9 | 
             
                end
         | 
| 10 10 |  | 
| 11 | 
            +
                def sse(url, headers = {})
         | 
| 12 | 
            +
                  response = HTTP.get(url, headers: headers.merge(Accept: 'text/event-stream'))
         | 
| 13 | 
            +
                  if response.status == 200
         | 
| 14 | 
            +
                    body = response.body
         | 
| 15 | 
            +
                    while part = body.readpartial do
         | 
| 16 | 
            +
                      part = part.to_s.strip
         | 
| 17 | 
            +
                      next if part.empty?
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                      lines = part.split("\n")
         | 
| 20 | 
            +
                      event = lines.grep(/event: (.+)/) { $1 }[0]
         | 
| 21 | 
            +
                      payload = lines.grep(/data: (.+)/) { $1 }[0]
         | 
| 22 | 
            +
                      yield response.connection, event, payload
         | 
| 23 | 
            +
                    end
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
                ensure
         | 
| 26 | 
            +
                  response.connection.close if response
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 11 29 | 
             
                def call(method, url, data = {}, headers = {})
         | 
| 12 | 
            -
                   | 
| 30 | 
            +
                  case method
         | 
| 31 | 
            +
                  when :get
         | 
| 13 32 | 
             
                    response = HTTP.get(url, headers: headers)
         | 
| 14 | 
            -
                   | 
| 33 | 
            +
                  when :delete
         | 
| 34 | 
            +
                    response = HTTP.delete(url, headers: headers)
         | 
| 35 | 
            +
                  when :form
         | 
| 15 36 | 
             
                    response = HTTP.send(:post, url, form: data, headers: headers)
         | 
| 16 37 | 
             
                  else
         | 
| 17 38 | 
             
                    response = HTTP.send(method, url, json: data, headers: headers)
         | 
    
        metadata
    CHANGED
    
    | @@ -1,127 +1,127 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: firefighter
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version:  | 
| 4 | 
            +
              version: 1.3.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - phoet
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2021-01-05 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: http
         | 
| 15 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 16 | 
             
                requirements:
         | 
| 17 | 
            -
                - - " | 
| 17 | 
            +
                - - ">"
         | 
| 18 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 19 | 
             
                    version: '3.0'
         | 
| 20 20 | 
             
              type: :runtime
         | 
| 21 21 | 
             
              prerelease: false
         | 
| 22 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 23 | 
             
                requirements:
         | 
| 24 | 
            -
                - - " | 
| 24 | 
            +
                - - ">"
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 26 | 
             
                    version: '3.0'
         | 
| 27 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 28 | 
             
              name: jwt
         | 
| 29 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 30 | 
             
                requirements:
         | 
| 31 | 
            -
                - - " | 
| 31 | 
            +
                - - ">"
         | 
| 32 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 33 | 
             
                    version: '2.0'
         | 
| 34 34 | 
             
              type: :runtime
         | 
| 35 35 | 
             
              prerelease: false
         | 
| 36 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 37 | 
             
                requirements:
         | 
| 38 | 
            -
                - - " | 
| 38 | 
            +
                - - ">"
         | 
| 39 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 40 | 
             
                    version: '2.0'
         | 
| 41 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 42 | 
             
              name: bundler
         | 
| 43 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 44 | 
             
                requirements:
         | 
| 45 | 
            -
                - - " | 
| 45 | 
            +
                - - ">="
         | 
| 46 46 | 
             
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            -
                    version: ' | 
| 47 | 
            +
                    version: '0'
         | 
| 48 48 | 
             
              type: :development
         | 
| 49 49 | 
             
              prerelease: false
         | 
| 50 50 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 51 | 
             
                requirements:
         | 
| 52 | 
            -
                - - " | 
| 52 | 
            +
                - - ">="
         | 
| 53 53 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            -
                    version: ' | 
| 54 | 
            +
                    version: '0'
         | 
| 55 55 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 56 56 | 
             
              name: rake
         | 
| 57 57 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 58 | 
             
                requirements:
         | 
| 59 | 
            -
                - - " | 
| 59 | 
            +
                - - ">="
         | 
| 60 60 | 
             
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            -
                    version: ' | 
| 61 | 
            +
                    version: '0'
         | 
| 62 62 | 
             
              type: :development
         | 
| 63 63 | 
             
              prerelease: false
         | 
| 64 64 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 65 | 
             
                requirements:
         | 
| 66 | 
            -
                - - " | 
| 66 | 
            +
                - - ">="
         | 
| 67 67 | 
             
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            -
                    version: ' | 
| 68 | 
            +
                    version: '0'
         | 
| 69 69 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 70 70 | 
             
              name: rspec
         | 
| 71 71 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 72 | 
             
                requirements:
         | 
| 73 | 
            -
                - - " | 
| 73 | 
            +
                - - ">="
         | 
| 74 74 | 
             
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            -
                    version: ' | 
| 75 | 
            +
                    version: '0'
         | 
| 76 76 | 
             
              type: :development
         | 
| 77 77 | 
             
              prerelease: false
         | 
| 78 78 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 79 | 
             
                requirements:
         | 
| 80 | 
            -
                - - " | 
| 80 | 
            +
                - - ">="
         | 
| 81 81 | 
             
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            -
                    version: ' | 
| 82 | 
            +
                    version: '0'
         | 
| 83 83 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 84 84 | 
             
              name: vcr
         | 
| 85 85 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 86 86 | 
             
                requirements:
         | 
| 87 | 
            -
                - - " | 
| 87 | 
            +
                - - ">="
         | 
| 88 88 | 
             
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            -
                    version: ' | 
| 89 | 
            +
                    version: '0'
         | 
| 90 90 | 
             
              type: :development
         | 
| 91 91 | 
             
              prerelease: false
         | 
| 92 92 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 93 | 
             
                requirements:
         | 
| 94 | 
            -
                - - " | 
| 94 | 
            +
                - - ">="
         | 
| 95 95 | 
             
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            -
                    version: ' | 
| 96 | 
            +
                    version: '0'
         | 
| 97 97 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 98 98 | 
             
              name: webmock
         | 
| 99 99 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 100 100 | 
             
                requirements:
         | 
| 101 | 
            -
                - - " | 
| 101 | 
            +
                - - ">="
         | 
| 102 102 | 
             
                  - !ruby/object:Gem::Version
         | 
| 103 | 
            -
                    version: ' | 
| 103 | 
            +
                    version: '0'
         | 
| 104 104 | 
             
              type: :development
         | 
| 105 105 | 
             
              prerelease: false
         | 
| 106 106 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 107 107 | 
             
                requirements:
         | 
| 108 | 
            -
                - - " | 
| 108 | 
            +
                - - ">="
         | 
| 109 109 | 
             
                  - !ruby/object:Gem::Version
         | 
| 110 | 
            -
                    version: ' | 
| 110 | 
            +
                    version: '0'
         | 
| 111 111 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 112 112 | 
             
              name: timecop
         | 
| 113 113 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 114 114 | 
             
                requirements:
         | 
| 115 | 
            -
                - - " | 
| 115 | 
            +
                - - ">="
         | 
| 116 116 | 
             
                  - !ruby/object:Gem::Version
         | 
| 117 | 
            -
                    version: '0 | 
| 117 | 
            +
                    version: '0'
         | 
| 118 118 | 
             
              type: :development
         | 
| 119 119 | 
             
              prerelease: false
         | 
| 120 120 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 121 121 | 
             
                requirements:
         | 
| 122 | 
            -
                - - " | 
| 122 | 
            +
                - - ">="
         | 
| 123 123 | 
             
                  - !ruby/object:Gem::Version
         | 
| 124 | 
            -
                    version: '0 | 
| 124 | 
            +
                    version: '0'
         | 
| 125 125 | 
             
            description: Firebase API Wrapper
         | 
| 126 126 | 
             
            email:
         | 
| 127 127 | 
             
            - phoetmail@googlemail.com
         | 
| @@ -131,10 +131,13 @@ extra_rdoc_files: [] | |
| 131 131 | 
             
            files:
         | 
| 132 132 | 
             
            - ".circleci/config.yml"
         | 
| 133 133 | 
             
            - ".gitignore"
         | 
| 134 | 
            +
            - ".irbrc"
         | 
| 134 135 | 
             
            - ".rspec"
         | 
| 136 | 
            +
            - CHANGELOG.md
         | 
| 135 137 | 
             
            - CODE_OF_CONDUCT.md
         | 
| 136 138 | 
             
            - Gemfile
         | 
| 137 139 | 
             
            - Gemfile.lock
         | 
| 140 | 
            +
            - LICENSE.txt
         | 
| 138 141 | 
             
            - README.md
         | 
| 139 142 | 
             
            - Rakefile
         | 
| 140 143 | 
             
            - bin/console
         | 
| @@ -165,8 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 165 168 | 
             
                - !ruby/object:Gem::Version
         | 
| 166 169 | 
             
                  version: '0'
         | 
| 167 170 | 
             
            requirements: []
         | 
| 168 | 
            -
             | 
| 169 | 
            -
            rubygems_version: 2.6.13
         | 
| 171 | 
            +
            rubygems_version: 3.0.3
         | 
| 170 172 | 
             
            signing_key: 
         | 
| 171 173 | 
             
            specification_version: 4
         | 
| 172 174 | 
             
            summary: Firebase API Wrapper
         |