cafmal 0.24.0 → 0.25.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cafmal/auth.rb +8 -12
- data/lib/cafmal/request.rb +0 -9
- data/lib/cafmal/resource.rb +6 -6
- data/lib/cafmal/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2bc4e521a1035531524381816426e507ddb3a708
|
4
|
+
data.tar.gz: caa5300dbc3e15c6a3bc2cc96889ec9de1bf2dc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b241ea4efcec128233ad5ede36bfa64af08529f0d566076ec08452c7a75bff3097f881dcb5b01f57dfe081a6a8ee3ec12520e122e2b7c0afb20be4c9d38e6e1b
|
7
|
+
data.tar.gz: cfcb96c721b66b1b4d541b4dbcb5bf5c9ab821fafef3c97c27b57b39e0f069f434fc79e837960cc81b70a215985f4da66dfefd338910fca1386c6f392e7341b7
|
data/lib/cafmal/auth.rb
CHANGED
@@ -32,14 +32,14 @@ module Cafmal
|
|
32
32
|
def login(email = 'admin@example.com', password = 'cafmal')
|
33
33
|
credentials = {auth: {email: email, password: password}}.to_json
|
34
34
|
request_auth = Cafmal::Request::Post.new(@cafmal_api_url + '/user_token', credentials, {"Content-Type" => "application/json"})
|
35
|
-
if request_auth.code < 300
|
35
|
+
if request_auth.response.code < 300
|
36
36
|
@token = JSON.parse(request_auth.response.body)["jwt"]
|
37
37
|
@decoded_token = {}
|
38
38
|
@decoded_token['header'] = JSON.parse(Base64.decode64(@token.split('.')[0]))
|
39
39
|
@decoded_token['payload'] = JSON.parse(Base64.decode64(@token.split('.')[1]))
|
40
40
|
|
41
41
|
if (@decoded_token['payload']['role'] != 'worker' && @decoded_token['payload']['role'] != 'alerter')
|
42
|
-
team_id = JSON.parse(Cafmal::User.new(@cafmal_api_url, @token).show(@decoded_token['payload']['sub']))["team_id"]
|
42
|
+
team_id = JSON.parse(Cafmal::User.new(@cafmal_api_url, @token).show(@decoded_token['payload']['sub']).body)["team_id"]
|
43
43
|
event = Cafmal::Event.new(@cafmal_api_url, @token)
|
44
44
|
event.create({name: 'user.login', message: "#{email} has logged in.", kind: 'login', severity: 'info', team_id: team_id})
|
45
45
|
|
@@ -58,14 +58,12 @@ module Cafmal
|
|
58
58
|
decoded_token['header'] = JSON.parse(Base64.decode64(token.split('.')[0]))
|
59
59
|
decoded_token['payload'] = JSON.parse(Base64.decode64(token.split('.')[1]))
|
60
60
|
|
61
|
-
user = JSON.parse(Cafmal::User.new(@cafmal_api_url, token).show(decoded_token['payload']['sub']))
|
61
|
+
user = JSON.parse(Cafmal::User.new(@cafmal_api_url, token).show(decoded_token['payload']['sub']).body)
|
62
62
|
team_id = user["team_id"]
|
63
63
|
email = user["email"]
|
64
64
|
|
65
|
-
#@TODO if you are the last logged in user, unsilence your team alerts
|
66
|
-
|
67
65
|
# kind has to be login, as it's a label of events
|
68
|
-
event_id = JSON.parse(Cafmal::Event.new(@cafmal_api_url, token).create({name: 'user.logout', message: "#{email} has logged out.", kind: 'login', severity: 'info', team_id: team_id}))
|
66
|
+
event_id = JSON.parse(Cafmal::Event.new(@cafmal_api_url, token).create({name: 'user.logout', message: "#{email} has logged out.", kind: 'login', severity: 'info', team_id: team_id}).body)
|
69
67
|
|
70
68
|
if event_id.nil?
|
71
69
|
false
|
@@ -80,19 +78,17 @@ module Cafmal
|
|
80
78
|
def refresh(token)
|
81
79
|
headers = {"Content-Type" => "application/json", "Authorization" => "Bearer #{token}"}
|
82
80
|
credentials = {token: token}.to_json
|
83
|
-
|
84
|
-
if
|
85
|
-
@token = JSON.parse(
|
81
|
+
request_refresh = Cafmal::Request::Post.new(@cafmal_api_url + '/user_token_refresh', credentials, headers)
|
82
|
+
if request_refresh.response.code < 300
|
83
|
+
@token = JSON.parse(request_refresh.response.body)['jwt']
|
86
84
|
@decoded_token = {}
|
87
85
|
@decoded_token['header'] = JSON.parse(Base64.decode64(@token.split('.')[0]))
|
88
86
|
@decoded_token['payload'] = JSON.parse(Base64.decode64(@token.split('.')[1]))
|
89
87
|
|
90
88
|
if (@decoded_token['payload']['role'] != 'worker' && @decoded_token['payload']['role'] != 'alerter')
|
91
|
-
team_id = JSON.parse(Cafmal::User.new(@cafmal_api_url, @token).show(@decoded_token['payload']['sub']))["team_id"]
|
89
|
+
team_id = JSON.parse(Cafmal::User.new(@cafmal_api_url, @token).show(@decoded_token['payload']['sub']).body)["team_id"]
|
92
90
|
event = Cafmal::Event.new(@cafmal_api_url, @token)
|
93
91
|
event.create({name: 'user.refresh_login', message: "#{@decoded_token['payload']['email']} has refreshed his login.", kind: 'login', severity: 'info', team_id: team_id})
|
94
|
-
|
95
|
-
#@TODO silence all alerts for your team_id, set silenced_at now + 1h
|
96
92
|
end
|
97
93
|
return true
|
98
94
|
else
|
data/lib/cafmal/request.rb
CHANGED
@@ -3,45 +3,36 @@
|
|
3
3
|
module Cafmal
|
4
4
|
module Request
|
5
5
|
@response = nil
|
6
|
-
@code = nil
|
7
6
|
|
8
7
|
class Post
|
9
8
|
attr_reader :response
|
10
|
-
attr_reader :code
|
11
9
|
|
12
10
|
def initialize(url, body, headers)
|
13
11
|
@response = HTTParty.post(url, body: body, headers: headers)
|
14
|
-
@code = @response.code
|
15
12
|
end
|
16
13
|
end
|
17
14
|
|
18
15
|
class Get
|
19
16
|
attr_reader :response
|
20
|
-
attr_reader :code
|
21
17
|
|
22
18
|
def initialize(url, headers)
|
23
19
|
@response = HTTParty.get(url, headers: headers)
|
24
|
-
@code = @response.code
|
25
20
|
end
|
26
21
|
end
|
27
22
|
|
28
23
|
class Put
|
29
24
|
attr_reader :response
|
30
|
-
attr_reader :code
|
31
25
|
|
32
26
|
def initialize(url, body, headers)
|
33
27
|
@response = HTTParty.put(url, body: body, headers: headers)
|
34
|
-
@code = @response.code
|
35
28
|
end
|
36
29
|
end
|
37
30
|
|
38
31
|
class Delete
|
39
32
|
attr_reader :response
|
40
|
-
attr_reader :code
|
41
33
|
|
42
34
|
def initialize(url, body, headers)
|
43
35
|
@response = HTTParty.delete(url, body: body, headers: headers)
|
44
|
-
@code = @response.code
|
45
36
|
end
|
46
37
|
end
|
47
38
|
|
data/lib/cafmal/resource.rb
CHANGED
@@ -29,37 +29,37 @@ module Cafmal
|
|
29
29
|
def create(params)
|
30
30
|
request_create_resource = Cafmal::Request::Post.new(@cafmal_api_url + "/#{@resourcename}", params.to_json, @headers)
|
31
31
|
|
32
|
-
return request_create_resource.response
|
32
|
+
return request_create_resource.response
|
33
33
|
end
|
34
34
|
|
35
35
|
def new
|
36
36
|
request_new_resource = Cafmal::Request::Get.new(@cafmal_api_url + "/#{@resourcename}/new", @headers)
|
37
37
|
|
38
|
-
return request_new_resource.response
|
38
|
+
return request_new_resource.response
|
39
39
|
end
|
40
40
|
|
41
41
|
def list(*options)
|
42
42
|
request_list_resource = Cafmal::Request::Get.new(@cafmal_api_url + "/#{@resourcename}" + @query, @headers)
|
43
43
|
|
44
|
-
return request_list_resource.response
|
44
|
+
return request_list_resource.response
|
45
45
|
end
|
46
46
|
|
47
47
|
def show(id)
|
48
48
|
request_show_resource = Cafmal::Request::Get.new(@cafmal_api_url + "/#{@resourcename}/" + id.to_s, @headers)
|
49
49
|
|
50
|
-
return request_show_resource.response
|
50
|
+
return request_show_resource.response
|
51
51
|
end
|
52
52
|
|
53
53
|
def update(params)
|
54
54
|
request_update_resource = Cafmal::Request::Put.new(@cafmal_api_url + "/#{@resourcename}/#{params['id']}", params.to_json, @headers)
|
55
55
|
|
56
|
-
return request_update_resource.response
|
56
|
+
return request_update_resource.response
|
57
57
|
end
|
58
58
|
|
59
59
|
def destroy(params)
|
60
60
|
request_destroy_resource = Cafmal::Request::Delete.new(@cafmal_api_url + "/#{@resourcename}/#{params['id']}", params.to_json, @headers)
|
61
61
|
|
62
|
-
return request_destroy_resource.response
|
62
|
+
return request_destroy_resource.response
|
63
63
|
end
|
64
64
|
|
65
65
|
# helpers below
|
data/lib/cafmal/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cafmal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.25.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nils Bartels
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
version: '0'
|
115
115
|
requirements: []
|
116
116
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.
|
117
|
+
rubygems_version: 2.6.8
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: Create alerts from metrics and logs
|