sophos_central_api 0.2.0 → 0.2.1
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/CHANGELOG.md +3 -0
- data/README.md +5 -5
- data/lib/sophos/authentication.rb +21 -16
- data/lib/sophos/error.rb +2 -2
- data/lib/sophos/pagination.rb +5 -1
- data/lib/sophos/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a26247b4f61c367498ff21c935dcd319058384b1684f10c220f6f7700eaa0095
|
4
|
+
data.tar.gz: b6975aedaa003656add82f3fbddc4c15c8f66048faebbc16987ae23e7102a5ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afdda664f2c0982cc6ae3be738da6f8df8156a8a4287e73c3fc64058e6b6639b31066b17b0f6ea263613c753267902f3a91121f5478eab13ce5ef9e6f2f2bc59
|
7
|
+
data.tar.gz: b77d24174658993217761df3341585db908e973710e4d91eb63f8cad023e295ae83be4c9158bb810397d9ae8bd8f69ab31019afc2d1d4ae6f652c1b5654fe38d
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -27,7 +27,7 @@ Or install it yourself as:
|
|
27
27
|
|
28
28
|
Before you start making the requests to API provide the client id and client secret and email/password using the configuration wrapping.
|
29
29
|
|
30
|
-
```
|
30
|
+
```ruby
|
31
31
|
require 'sophos_central_api'
|
32
32
|
|
33
33
|
Sophos.configure do |config|
|
@@ -46,7 +46,7 @@ end
|
|
46
46
|
|
47
47
|
## Resources
|
48
48
|
### Authentication
|
49
|
-
```
|
49
|
+
```ruby
|
50
50
|
# setup configuration
|
51
51
|
#
|
52
52
|
client.login
|
@@ -58,7 +58,7 @@ client.login
|
|
58
58
|
|
59
59
|
### Partner
|
60
60
|
Endpoint for partner related requests
|
61
|
-
```
|
61
|
+
```ruby
|
62
62
|
roles = client.roles
|
63
63
|
```
|
64
64
|
|
@@ -76,7 +76,7 @@ roles = client.roles
|
|
76
76
|
### Common
|
77
77
|
This is the OAS 3.0 specification for the Common API in Sophos Central.
|
78
78
|
|
79
|
-
```
|
79
|
+
```ruby
|
80
80
|
@client = Sophos.client()
|
81
81
|
@client.login
|
82
82
|
:
|
@@ -96,7 +96,7 @@ tenant = @client.tenant(id)
|
|
96
96
|
|
97
97
|
### Endpoints
|
98
98
|
Returns endpoint for a provided tenant
|
99
|
-
```
|
99
|
+
```ruby
|
100
100
|
@client = Sophos.client()
|
101
101
|
@client.login
|
102
102
|
:
|
@@ -17,18 +17,13 @@ module Sophos
|
|
17
17
|
request.body = URI.encode_www_form( api_access_token_params )
|
18
18
|
end
|
19
19
|
api_process_token(response.body)
|
20
|
-
|
20
|
+
setup_connection
|
21
21
|
# use default endpoint and replace it with global endpoint
|
22
|
-
|
23
|
-
|
24
|
-
self.partner_id = partner.id
|
25
|
-
self.endpoint = partner.apiHosts.global
|
26
|
-
self.connection_options = { headers: { 'X-partner-id': self.partner_id } }
|
27
|
-
else
|
28
|
-
raise AuthenticationError.new 'Partner id not returned; response ' + response.to_s
|
29
|
-
end
|
22
|
+
self.access_token
|
23
|
+
|
30
24
|
rescue Faraday::UnauthorizedError => e
|
31
|
-
|
25
|
+
|
26
|
+
raise AuthenticationError.new 'Unauthorized; response ' + e.to_s
|
32
27
|
end
|
33
28
|
alias login auth_token
|
34
29
|
|
@@ -44,13 +39,23 @@ module Sophos
|
|
44
39
|
end
|
45
40
|
|
46
41
|
def api_process_token(response)
|
47
|
-
|
48
|
-
self.token_type
|
49
|
-
self.refresh_token
|
50
|
-
self.token_expires
|
51
|
-
raise AuthenticationError.new 'Could not find valid access_token; response ' + response.to_s if at.nil? || at.empty?
|
42
|
+
self.access_token = response['access_token']
|
43
|
+
self.token_type = response['token_type']
|
44
|
+
self.refresh_token = response['refresh_token']
|
45
|
+
self.token_expires = response['expires_in']
|
52
46
|
|
53
|
-
|
47
|
+
raise AuthenticationError.new 'Could not find valid access_token; response ' + response.to_s if self.access_token.nil? || self.access_token.empty?
|
48
|
+
end
|
49
|
+
|
50
|
+
def setup_connection
|
51
|
+
partner = self.get( "/whoami/v1" )
|
52
|
+
if 'partner'.eql?(partner.idType) && partner.id
|
53
|
+
self.partner_id = partner.id
|
54
|
+
self.endpoint = partner.apiHosts.global
|
55
|
+
self.connection_options = { headers: { 'X-partner-id': self.partner_id } }
|
56
|
+
else
|
57
|
+
raise AuthenticationError.new 'Partner id not returned; response ' + partner.to_s
|
58
|
+
end
|
54
59
|
end
|
55
60
|
end
|
56
61
|
end
|
data/lib/sophos/error.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Sophos
|
2
2
|
|
3
|
-
# Generic error to be able to rescue all
|
3
|
+
# Generic error to be able to rescue all Sophos errors
|
4
4
|
class SophosError < StandardError; end
|
5
5
|
|
6
|
-
# Raised when
|
6
|
+
# Raised when Sophos not configured correctly
|
7
7
|
class ConfigurationError < SophosError; end
|
8
8
|
|
9
9
|
# Error when authentication fails
|
data/lib/sophos/pagination.rb
CHANGED
@@ -24,10 +24,13 @@ module Sophos
|
|
24
24
|
# ignore page size
|
25
25
|
@page_size = page_size
|
26
26
|
@total = @current = 1
|
27
|
+
@nextKey = nil
|
27
28
|
end
|
28
29
|
|
29
30
|
def page_options
|
30
|
-
{ 'page': @current, 'pageSize': @page_size, 'pageTotal': true }
|
31
|
+
options = { 'page': @current, 'pageSize': @page_size, 'pageTotal': true }
|
32
|
+
options = options.merge({ 'pageFromKey': @nextKey }) if @current > 1
|
33
|
+
options
|
31
34
|
end
|
32
35
|
|
33
36
|
def next_page!(data)
|
@@ -40,6 +43,7 @@ module Sophos
|
|
40
43
|
else
|
41
44
|
@current += 1
|
42
45
|
end
|
46
|
+
@nextKey = pages['nextKey'] if pages['nextKey']
|
43
47
|
else
|
44
48
|
# no page info so assume single page request
|
45
49
|
@total = 0
|
data/lib/sophos/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sophos_central_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janco Tanis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
141
|
- !ruby/object:Gem::Version
|
142
142
|
version: '0'
|
143
143
|
requirements: []
|
144
|
-
rubygems_version: 3.2.
|
144
|
+
rubygems_version: 3.2.3
|
145
145
|
signing_key:
|
146
146
|
specification_version: 4
|
147
147
|
summary: A Ruby wrapper for the Sophos Central REST APIs (readonly)
|