firefighter 0.1.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +32 -0
- data/.irbrc +8 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +45 -41
- data/LICENSE.txt +21 -0
- data/README.md +61 -6
- data/firefighter.gemspec +8 -8
- data/lib/firefighter.rb +2 -0
- data/lib/firefighter/identitytoolkit.rb +71 -0
- data/lib/firefighter/realtime_database.rb +18 -41
- data/lib/firefighter/token_generator.rb +30 -9
- data/lib/firefighter/version.rb +1 -1
- data/lib/firefighter/web.rb +49 -0
- metadata +40 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 420312cb25f6f5cb3f27499d7afdcadb775d287a28ae58cfcbb97f5156e68064
|
4
|
+
data.tar.gz: 7ae7c7e245493062b2f3c41fc2eebde026cc84bfe3714acf9f28704bba0d6eb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f56406ab531b5a04381dffe158a0442d165bf32bb7b5b1b4554a45c704f3ed8bdaedf65500e48268293760a6617e93f5f01df563b37daa0a147d2437a9a5173
|
7
|
+
data.tar.gz: 540c6aa22139f78f8f411beceb642e58ef7cbaf1184bff70cbb5a47e7f2766d23e8931fb09789acae6d7ca797c54f08d62e1c7768dcc5b75c6e1aaa8a173a473
|
@@ -0,0 +1,32 @@
|
|
1
|
+
version: 2
|
2
|
+
jobs:
|
3
|
+
build:
|
4
|
+
working_directory: ~/repo
|
5
|
+
|
6
|
+
docker:
|
7
|
+
- image: circleci/ruby:2.7
|
8
|
+
|
9
|
+
steps:
|
10
|
+
- checkout
|
11
|
+
|
12
|
+
# Download and cache dependencies
|
13
|
+
- restore_cache:
|
14
|
+
keys:
|
15
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
16
|
+
# fallback to using the latest cache if no exact match is found
|
17
|
+
- v1-dependencies-
|
18
|
+
|
19
|
+
- run:
|
20
|
+
name: install dependencies
|
21
|
+
command: |
|
22
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
23
|
+
|
24
|
+
- save_cache:
|
25
|
+
paths:
|
26
|
+
- ./vendor/bundle
|
27
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
28
|
+
|
29
|
+
- run:
|
30
|
+
name: Run tests
|
31
|
+
command: |
|
32
|
+
bundle exec rake
|
data/.irbrc
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
### 1.1.0
|
4
|
+
|
5
|
+
- compatibility with ruby 2.7.1
|
6
|
+
|
7
|
+
### 1.0.0
|
8
|
+
|
9
|
+
- adds `Firefighter::RealtimeDatabase#listen` (experimental)
|
10
|
+
- moves `Firefighter::RealtimeDatabase#fetch_access_token` to `Firefighter::TokenGenerator#fetch_access_token` (breaking)
|
11
|
+
|
12
|
+
### 0.3.0
|
13
|
+
|
14
|
+
- adds `Firefighter::RealtimeDatabase#delete`
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,68 +1,72 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
firefighter (
|
5
|
-
http (
|
6
|
-
jwt (
|
4
|
+
firefighter (1.1.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, <
|
11
|
+
addressable (2.7.0)
|
12
|
+
public_suffix (>= 2.0.2, < 5.0)
|
13
|
+
byebug (11.1.3)
|
13
14
|
crack (0.4.3)
|
14
15
|
safe_yaml (~> 1.0.0)
|
15
|
-
diff-lcs (1.
|
16
|
-
domain_name (0.5.
|
16
|
+
diff-lcs (1.4.4)
|
17
|
+
domain_name (0.5.20190701)
|
17
18
|
unf (>= 0.0.5, < 1.0.0)
|
18
|
-
|
19
|
-
|
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)
|
20
25
|
addressable (~> 2.3)
|
21
26
|
http-cookie (~> 1.0)
|
22
|
-
http-form_data (~> 2.
|
23
|
-
|
27
|
+
http-form_data (~> 2.2)
|
28
|
+
http-parser (~> 1.2.0)
|
24
29
|
http-cookie (1.0.3)
|
25
30
|
domain_name (~> 0.5)
|
26
|
-
http-form_data (2.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
rspec-
|
34
|
-
rspec-
|
35
|
-
|
36
|
-
|
37
|
-
|
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)
|
38
44
|
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
-
rspec-support (~> 3.
|
40
|
-
rspec-mocks (3.
|
45
|
+
rspec-support (~> 3.9.0)
|
46
|
+
rspec-mocks (3.9.1)
|
41
47
|
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
-
rspec-support (~> 3.
|
43
|
-
rspec-support (3.
|
44
|
-
safe_yaml (1.0.
|
48
|
+
rspec-support (~> 3.9.0)
|
49
|
+
rspec-support (3.9.3)
|
50
|
+
safe_yaml (1.0.5)
|
45
51
|
timecop (0.9.1)
|
46
52
|
unf (0.1.4)
|
47
53
|
unf_ext
|
48
|
-
unf_ext (0.0.7.
|
49
|
-
vcr (
|
50
|
-
webmock (3.
|
54
|
+
unf_ext (0.0.7.7)
|
55
|
+
vcr (6.0.0)
|
56
|
+
webmock (3.8.3)
|
51
57
|
addressable (>= 2.3.6)
|
52
58
|
crack (>= 0.3.2)
|
53
|
-
hashdiff
|
59
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
54
60
|
|
55
61
|
PLATFORMS
|
56
62
|
ruby
|
57
63
|
|
58
64
|
DEPENDENCIES
|
59
|
-
bundler
|
65
|
+
bundler
|
66
|
+
byebug
|
60
67
|
firefighter!
|
61
|
-
rake
|
62
|
-
rspec
|
63
|
-
timecop
|
64
|
-
vcr
|
65
|
-
webmock
|
66
|
-
|
67
|
-
BUNDLED WITH
|
68
|
-
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
|
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,58 @@ 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
|
+
|
41
|
+
```ruby
|
42
|
+
# Firefighter::RealtimeDatabase
|
43
|
+
# from_env uses environment variables:
|
44
|
+
# - FIREBASE_WEB_DB_NAME
|
45
|
+
# - FIREBASE_WEB_DB_SECRET
|
46
|
+
realtime_database = Firefighter::RealtimeDatabase.from_env
|
47
|
+
|
48
|
+
realtime_database.write("some-path/key", {some: 'data'})
|
49
|
+
|
50
|
+
hash = realtime_database.read("some-path/key")
|
51
|
+
|
52
|
+
realtime_database.add("some-path/list", {some: 'data'})
|
53
|
+
|
54
|
+
list = realtime_database.read("some-path/list")
|
55
|
+
|
56
|
+
realtime_database.delete("some-path/list")
|
57
|
+
|
58
|
+
realtime_database.listen("some-test/write/") do |connection, event, path, data|
|
59
|
+
puts event, path, data
|
60
|
+
connection.close
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
# Firefighter::TokenGenerator
|
66
|
+
# from_env uses environment variables:
|
67
|
+
# - FIREBASE_SERVICE_ACCOUNT_EMAIL
|
68
|
+
# - FIREBASE_SERVICE_ACCOUNT_PRIVATE_KEY
|
69
|
+
token_generator = Firefighter::TokenGenerator.from_env
|
70
|
+
|
71
|
+
access_token = token_generator.create_access_token
|
72
|
+
|
73
|
+
custom_token = token_generator.create_custom_token('someUid', data: {some: 'payload'})
|
74
|
+
|
75
|
+
payload = token_generator.read_token(custom_token)
|
76
|
+
|
77
|
+
token = token_generator.fetch_access_token
|
78
|
+
```
|
28
79
|
|
29
80
|
## Development
|
30
81
|
|
@@ -34,8 +85,12 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
34
85
|
|
35
86
|
## Contributing
|
36
87
|
|
37
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
88
|
+
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
89
|
|
39
90
|
## Code of Conduct
|
40
91
|
|
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/
|
92
|
+
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).
|
93
|
+
|
94
|
+
## Changelog
|
95
|
+
|
96
|
+
[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 "
|
38
|
-
spec.add_development_dependency "
|
39
|
-
spec.add_development_dependency "
|
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
|
data/lib/firefighter.rb
CHANGED
@@ -0,0 +1,71 @@
|
|
1
|
+
module Firefighter
|
2
|
+
class Identitytoolkit
|
3
|
+
include Web
|
4
|
+
|
5
|
+
def self.from_env
|
6
|
+
new(
|
7
|
+
api_key: ENV['FIREBASE_WEB_API_KEY'],
|
8
|
+
service_account_email: ENV['FIREBASE_SERVICE_ACCOUNT_EMAIL'],
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(api_key:, service_account_email:)
|
13
|
+
@api_key = api_key
|
14
|
+
@service_account_email = service_account_email
|
15
|
+
end
|
16
|
+
|
17
|
+
def signup(email, password)
|
18
|
+
url = endpoint('signupNewUser')
|
19
|
+
data = {
|
20
|
+
email: email,
|
21
|
+
password: password,
|
22
|
+
returnSecureToken: true
|
23
|
+
}
|
24
|
+
call(:post, url, data)
|
25
|
+
end
|
26
|
+
|
27
|
+
def account_info(id_token, local_ids: [], emails: [])
|
28
|
+
url = endpoint('getAccountInfo')
|
29
|
+
data = {
|
30
|
+
idToken: id_token,
|
31
|
+
localId: local_ids,
|
32
|
+
email: emails,
|
33
|
+
}
|
34
|
+
call(:post, url, data)
|
35
|
+
end
|
36
|
+
|
37
|
+
def download_accounts(access_token = TokenGenerator.from_env.fetch_access_token)
|
38
|
+
users = []
|
39
|
+
|
40
|
+
headers = {Authorization: "Bearer #{access_token}" }
|
41
|
+
url = endpoint('downloadAccount')
|
42
|
+
paginate(url, headers: headers) { |data| users << data['users'] }
|
43
|
+
|
44
|
+
users.flatten.compact
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def paginate(url, method: :post, headers: {}, page_size: 100, max_iterations: 1000)
|
50
|
+
next_page_token = nil
|
51
|
+
|
52
|
+
max_iterations.times do
|
53
|
+
data = {
|
54
|
+
nextPageToken: next_page_token,
|
55
|
+
maxResults: page_size,
|
56
|
+
}
|
57
|
+
data = call(method, url, data, headers)
|
58
|
+
|
59
|
+
yield data
|
60
|
+
|
61
|
+
return if data['nextPageToken']&.empty? || data['nextPageToken'] == next_page_token
|
62
|
+
|
63
|
+
next_page_token = data['nextPageToken']
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def endpoint(path)
|
68
|
+
"https://www.googleapis.com/identitytoolkit/v3/relyingparty/#{path}?key=#{@api_key}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -1,33 +1,30 @@
|
|
1
|
-
require 'logger'
|
2
|
-
require 'json'
|
3
|
-
require 'http'
|
4
|
-
|
5
1
|
module Firefighter
|
6
2
|
class RealtimeDatabase
|
3
|
+
include Web
|
4
|
+
|
7
5
|
def self.from_env
|
8
|
-
|
9
|
-
api_key: ENV['FIREBASE_WEB_API_KEY'],
|
6
|
+
new(
|
10
7
|
db_name: ENV['FIREBASE_WEB_DB_NAME'],
|
11
8
|
db_secret: ENV['FIREBASE_WEB_DB_SECRET']
|
12
|
-
|
13
|
-
new(config)
|
9
|
+
)
|
14
10
|
end
|
15
11
|
|
16
|
-
def initialize(
|
17
|
-
@api_key = api_key
|
12
|
+
def initialize(db_name:, db_secret:)
|
18
13
|
@db_name = db_name
|
19
14
|
@db_secret = db_secret
|
20
|
-
@logger = logger
|
21
15
|
end
|
22
16
|
|
23
|
-
def
|
24
|
-
url =
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
17
|
+
def listen(path)
|
18
|
+
url = endpoint(path)
|
19
|
+
sse(url) do |connection, event, payload|
|
20
|
+
data = JSON.parse(payload)
|
21
|
+
yield connection, event, data['path'], data['data']
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def read(path)
|
26
|
+
url = endpoint(path)
|
27
|
+
call(:get, url)
|
31
28
|
end
|
32
29
|
|
33
30
|
def write(path, data)
|
@@ -40,33 +37,13 @@ module Firefighter
|
|
40
37
|
call(:post, url, data)
|
41
38
|
end
|
42
39
|
|
43
|
-
def
|
40
|
+
def delete(path)
|
44
41
|
url = endpoint(path)
|
45
|
-
|
42
|
+
call(:delete, url)
|
46
43
|
end
|
47
44
|
|
48
45
|
private
|
49
46
|
|
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
47
|
def endpoint(path)
|
71
48
|
"https://#{@db_name}.firebaseio.com/#{path}.json?auth=#{@db_secret}"
|
72
49
|
end
|
@@ -3,23 +3,44 @@ 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
|
-
|
10
|
-
|
11
|
-
}
|
12
|
-
new(config)
|
11
|
+
service_account_private_key: ENV['FIREBASE_SERVICE_ACCOUNT_PRIVATE_KEY'],
|
12
|
+
)
|
13
13
|
end
|
14
14
|
|
15
|
-
def initialize(service_account_email:,
|
15
|
+
def initialize(service_account_email:, service_account_private_key:, algorithm: 'RS256')
|
16
16
|
@service_account_email = service_account_email
|
17
|
-
@private_key = private_key
|
18
17
|
@algorithm = algorithm
|
19
|
-
@
|
18
|
+
@private_key = OpenSSL::PKey::RSA.new(service_account_private_key)
|
19
|
+
end
|
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
|
30
|
+
|
31
|
+
def create_access_token(expiration: 60 * 60)
|
32
|
+
now_seconds = Time.now.to_i
|
33
|
+
payload = {
|
34
|
+
iss: @service_account_email,
|
35
|
+
scope: 'https://www.googleapis.com/auth/identitytoolkit',
|
36
|
+
aud: 'https://accounts.google.com/o/oauth2/token',
|
37
|
+
iat: now_seconds,
|
38
|
+
exp: now_seconds + expiration, # Maximum expiration time is one hour
|
39
|
+
}
|
40
|
+
::JWT.encode(payload, @private_key, @algorithm)
|
20
41
|
end
|
21
42
|
|
22
|
-
def
|
43
|
+
def create_custom_token(uid, data: {}, expiration: 60 * 60)
|
23
44
|
now_seconds = Time.now.to_i
|
24
45
|
payload = {
|
25
46
|
iss: @service_account_email,
|
data/lib/firefighter/version.rb
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'json'
|
3
|
+
require 'http'
|
4
|
+
|
5
|
+
module Firefighter
|
6
|
+
module Web
|
7
|
+
def logger
|
8
|
+
@logger ||= Logger.new(STDOUT)
|
9
|
+
end
|
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
|
+
|
29
|
+
def call(method, url, data = {}, headers = {})
|
30
|
+
case method
|
31
|
+
when :get
|
32
|
+
response = HTTP.get(url, headers: headers)
|
33
|
+
when :delete
|
34
|
+
response = HTTP.delete(url, headers: headers)
|
35
|
+
when :form
|
36
|
+
response = HTTP.send(:post, url, form: data, headers: headers)
|
37
|
+
else
|
38
|
+
response = HTTP.send(method, url, json: data, headers: headers)
|
39
|
+
end
|
40
|
+
|
41
|
+
if response.status == 200
|
42
|
+
JSON.parse(response.body)
|
43
|
+
else
|
44
|
+
logger.warn "firebase #{method} failed #{url} #{response.body}"
|
45
|
+
raise "firebase #{method} failed #{url} #{response.body}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
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.1.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: 2020-07-10 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
|
-
name:
|
84
|
+
name: vcr
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0
|
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: '0
|
96
|
+
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
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
|
-
name:
|
112
|
+
name: timecop
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
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: '
|
124
|
+
version: '0'
|
125
125
|
description: Firebase API Wrapper
|
126
126
|
email:
|
127
127
|
- phoetmail@googlemail.com
|
@@ -129,20 +129,26 @@ executables: []
|
|
129
129
|
extensions: []
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
|
+
- ".circleci/config.yml"
|
132
133
|
- ".gitignore"
|
134
|
+
- ".irbrc"
|
133
135
|
- ".rspec"
|
136
|
+
- CHANGELOG.md
|
134
137
|
- CODE_OF_CONDUCT.md
|
135
138
|
- Gemfile
|
136
139
|
- Gemfile.lock
|
140
|
+
- LICENSE.txt
|
137
141
|
- README.md
|
138
142
|
- Rakefile
|
139
143
|
- bin/console
|
140
144
|
- bin/setup
|
141
145
|
- firefighter.gemspec
|
142
146
|
- lib/firefighter.rb
|
147
|
+
- lib/firefighter/identitytoolkit.rb
|
143
148
|
- lib/firefighter/realtime_database.rb
|
144
149
|
- lib/firefighter/token_generator.rb
|
145
150
|
- lib/firefighter/version.rb
|
151
|
+
- lib/firefighter/web.rb
|
146
152
|
homepage: http://github.com/penseo/firefighter
|
147
153
|
licenses: []
|
148
154
|
metadata:
|
@@ -162,8 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
168
|
- !ruby/object:Gem::Version
|
163
169
|
version: '0'
|
164
170
|
requirements: []
|
165
|
-
|
166
|
-
rubygems_version: 2.6.13
|
171
|
+
rubygems_version: 3.1.2
|
167
172
|
signing_key:
|
168
173
|
specification_version: 4
|
169
174
|
summary: Firebase API Wrapper
|