firefighter 0.3.0 → 1.0.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 +4 -4
- data/.irbrc +2 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +5 -5
- data/README.md +14 -7
- data/lib/firefighter/identitytoolkit.rb +6 -17
- data/lib/firefighter/realtime_database.rb +13 -5
- data/lib/firefighter/token_generator.rb +11 -0
- data/lib/firefighter/version.rb +1 -1
- data/lib/firefighter/web.rb +18 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e59705f22a9b567e07bf80e9d387438f0c0fe71e2391ad458c539e77ff171315
|
4
|
+
data.tar.gz: 1e2e037a988975496867adc5cabfc92dcf80e34f7bf0edff0b972c2cd53f9cf0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70b26c9dd3ec6604e6c253efe6be6c9852df907ec2b0d5950a68b3783fa1ae9305ed4d60b0300389835f13eb6fa7df2e26f1eecde3233ca7f374c3269b1eb087
|
7
|
+
data.tar.gz: 32ad43adeada0906f1a8da8bfcc11266d41407163485cb70b7fe8f1726426d6f6716214b7387d1ba5f4d4c6679e81206ce784fe5765c36dae1d105b5d51ffc18
|
data/.irbrc
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
### 1.0.0
|
4
|
+
|
5
|
+
- adds `Firefighter::RealtimeDatabase#listen` (experimental)
|
6
|
+
- moves `Firefighter::RealtimeDatabase#fetch_access_token` to `Firefighter::TokenGenerator#fetch_access_token` (breaking)
|
7
|
+
|
8
|
+
### 0.3.0
|
9
|
+
|
10
|
+
- adds `Firefighter::RealtimeDatabase#delete`
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
firefighter (0.
|
4
|
+
firefighter (0.3.0)
|
5
5
|
http (~> 3.0)
|
6
6
|
jwt (~> 2.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
addressable (2.
|
11
|
+
addressable (2.6.0)
|
12
12
|
public_suffix (>= 2.0.2, < 4.0)
|
13
13
|
byebug (10.0.2)
|
14
14
|
crack (0.4.3)
|
@@ -16,7 +16,7 @@ GEM
|
|
16
16
|
diff-lcs (1.3)
|
17
17
|
domain_name (0.5.20180417)
|
18
18
|
unf (>= 0.0.5, < 1.0.0)
|
19
|
-
hashdiff (0.3.
|
19
|
+
hashdiff (0.3.8)
|
20
20
|
http (3.3.0)
|
21
21
|
addressable (~> 2.3)
|
22
22
|
http-cookie (~> 1.0)
|
@@ -42,13 +42,13 @@ GEM
|
|
42
42
|
diff-lcs (>= 1.2.0, < 2.0)
|
43
43
|
rspec-support (~> 3.8.0)
|
44
44
|
rspec-support (3.8.0)
|
45
|
-
safe_yaml (1.0.
|
45
|
+
safe_yaml (1.0.5)
|
46
46
|
timecop (0.9.1)
|
47
47
|
unf (0.1.4)
|
48
48
|
unf_ext
|
49
49
|
unf_ext (0.0.7.5)
|
50
50
|
vcr (4.0.0)
|
51
|
-
webmock (3.
|
51
|
+
webmock (3.5.1)
|
52
52
|
addressable (>= 2.3.6)
|
53
53
|
crack (>= 0.3.2)
|
54
54
|
hashdiff
|
data/README.md
CHANGED
@@ -36,9 +36,9 @@ account = identitytoolkit.signup('test@test.de', 'totalgeheimespasswort')
|
|
36
36
|
account = identitytoolkit.account_info(account['idToken'])
|
37
37
|
|
38
38
|
accounts = identitytoolkit.download_accounts
|
39
|
+
```
|
39
40
|
|
40
|
-
|
41
|
-
|
41
|
+
```ruby
|
42
42
|
# Firefighter::RealtimeDatabase
|
43
43
|
# from_env uses environment variables:
|
44
44
|
# - FIREBASE_WEB_DB_NAME
|
@@ -55,6 +55,13 @@ list = realtime_database.read("some-path/list")
|
|
55
55
|
|
56
56
|
realtime_database.delete("some-path/list")
|
57
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
|
58
65
|
# Firefighter::TokenGenerator
|
59
66
|
# from_env uses environment variables:
|
60
67
|
# - FIREBASE_SERVICE_ACCOUNT_EMAIL
|
@@ -66,6 +73,8 @@ access_token = token_generator.create_access_token
|
|
66
73
|
custom_token = token_generator.create_custom_token('someUid', data: {some: 'payload'})
|
67
74
|
|
68
75
|
payload = token_generator.read_token(custom_token)
|
76
|
+
|
77
|
+
token = token_generator.fetch_access_token
|
69
78
|
```
|
70
79
|
|
71
80
|
## Development
|
@@ -76,14 +85,12 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
76
85
|
|
77
86
|
## Contributing
|
78
87
|
|
79
|
-
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.
|
80
89
|
|
81
90
|
## Code of Conduct
|
82
91
|
|
83
|
-
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).
|
84
93
|
|
85
94
|
## Changelog
|
86
95
|
|
87
|
-
|
88
|
-
|
89
|
-
- adds `Firefighter::RealtimeDatabase#delete`
|
96
|
+
[code of conduct](https://github.com/penseo/firefighter/blob/master/CHANGELOG.md)
|
@@ -10,10 +10,9 @@ module Firefighter
|
|
10
10
|
new(config)
|
11
11
|
end
|
12
12
|
|
13
|
-
def initialize(api_key:, service_account_email
|
13
|
+
def initialize(api_key:, service_account_email:)
|
14
14
|
@api_key = api_key
|
15
15
|
@service_account_email = service_account_email
|
16
|
-
@token_generator = token_generator
|
17
16
|
end
|
18
17
|
|
19
18
|
def signup(email, password)
|
@@ -36,24 +35,14 @@ module Firefighter
|
|
36
35
|
call(:post, url, data)
|
37
36
|
end
|
38
37
|
|
39
|
-
def download_accounts
|
40
|
-
url = endpoint('downloadAccount')
|
41
|
-
|
42
|
-
headers = {Authorization: "Bearer #{fetch_access_token}" }
|
43
|
-
|
38
|
+
def download_accounts(access_token = TokenGenerator.from_env.fetch_access_token)
|
44
39
|
users = []
|
40
|
+
|
41
|
+
headers = {Authorization: "Bearer #{access_token}" }
|
42
|
+
url = endpoint('downloadAccount')
|
45
43
|
paginate(url, headers: headers) { |data| users << data['users'] }
|
46
|
-
users.flatten.compact
|
47
|
-
end
|
48
44
|
|
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']
|
45
|
+
users.flatten.compact
|
57
46
|
end
|
58
47
|
|
59
48
|
private
|
@@ -15,6 +15,19 @@ module Firefighter
|
|
15
15
|
@db_secret = db_secret
|
16
16
|
end
|
17
17
|
|
18
|
+
def listen(path)
|
19
|
+
url = endpoint(path)
|
20
|
+
sse(url) do |connection, event, payload|
|
21
|
+
data = JSON.parse(payload)
|
22
|
+
yield connection, event, data['path'], data['data']
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def read(path)
|
27
|
+
url = endpoint(path)
|
28
|
+
call(:get, url)
|
29
|
+
end
|
30
|
+
|
18
31
|
def write(path, data)
|
19
32
|
url = endpoint(path)
|
20
33
|
call(:put, url, data)
|
@@ -25,11 +38,6 @@ module Firefighter
|
|
25
38
|
call(:post, url, data)
|
26
39
|
end
|
27
40
|
|
28
|
-
def read(path)
|
29
|
-
url = endpoint(path)
|
30
|
-
call(:get, url)
|
31
|
-
end
|
32
|
-
|
33
41
|
def delete(path)
|
34
42
|
url = endpoint(path)
|
35
43
|
call(:delete, url)
|
@@ -3,6 +3,8 @@ 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
|
config = {
|
8
10
|
service_account_email: ENV['FIREBASE_SERVICE_ACCOUNT_EMAIL'],
|
@@ -17,6 +19,15 @@ module Firefighter
|
|
17
19
|
@private_key = OpenSSL::PKey::RSA.new(service_account_private_key)
|
18
20
|
end
|
19
21
|
|
22
|
+
def fetch_access_token
|
23
|
+
url = 'https://accounts.google.com/o/oauth2/token'
|
24
|
+
data = {
|
25
|
+
assertion: create_access_token,
|
26
|
+
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer'
|
27
|
+
}
|
28
|
+
response = call(:post, url, data)
|
29
|
+
response['access_token']
|
30
|
+
end
|
20
31
|
|
21
32
|
def create_access_token(expiration: 60 * 60)
|
22
33
|
now_seconds = Time.now.to_i
|
data/lib/firefighter/version.rb
CHANGED
data/lib/firefighter/web.rb
CHANGED
@@ -8,6 +8,24 @@ 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
|
13
31
|
when :get
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: firefighter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- phoet
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -133,6 +133,7 @@ files:
|
|
133
133
|
- ".gitignore"
|
134
134
|
- ".irbrc"
|
135
135
|
- ".rspec"
|
136
|
+
- CHANGELOG.md
|
136
137
|
- CODE_OF_CONDUCT.md
|
137
138
|
- Gemfile
|
138
139
|
- Gemfile.lock
|