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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de42982e7073acef13887732efb277b3f24e31fcf34552f7857100edc20b99a2
4
- data.tar.gz: 40425c2083e372ea6434f86723209ddd1673a1055ca8fc26e9bac997fb961305
3
+ metadata.gz: a26247b4f61c367498ff21c935dcd319058384b1684f10c220f6f7700eaa0095
4
+ data.tar.gz: b6975aedaa003656add82f3fbddc4c15c8f66048faebbc16987ae23e7102a5ba
5
5
  SHA512:
6
- metadata.gz: 4c3655439d962b32baef1e85a1ec31e4442c103472a82d0a2388d271fccde35c2fadb43088fd07db5ef3676d99331cea568f4019f61705b54a88577a7f97e073
7
- data.tar.gz: 47cc68a252b5ad954f6bb6b48aae862b27e48ab35e0bacdb8c1fb605dd4d322d2af1325ec5457bef5ad6c970d20ac5f01c23e30705bd41f50c58a0c0e55c208b
6
+ metadata.gz: afdda664f2c0982cc6ae3be738da6f8df8156a8a4287e73c3fc64058e6b6639b31066b17b0f6ea263613c753267902f3a91121f5478eab13ce5ef9e6f2f2bc59
7
+ data.tar.gz: b77d24174658993217761df3341585db908e973710e4d91eb63f8cad023e295ae83be4c9158bb810397d9ae8bd8f69ab31019afc2d1d4ae6f652c1b5654fe38d
data/CHANGELOG.md CHANGED
@@ -11,3 +11,6 @@
11
11
 
12
12
  ## [0.2.0] - 2024-02-20
13
13
  - Configuration and authentication exceptions changed
14
+
15
+ ## [0.2.1] - 2024-07-17
16
+ - Fix issue with paging for endpoints
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
- partner = self.get( "/whoami/v1" )
23
- if 'partner'.eql?(partner.idType) && partner.id
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
- raise AuthenticationError.new 'Unauthorized; response ' + e.to_s
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
- at = self.access_token = response['access_token']
48
- self.token_type = response['token_type']
49
- self.refresh_token = response['refresh_token']
50
- self.token_expires = response['expires_in']
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
- at
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 Zabbix errors
3
+ # Generic error to be able to rescue all Sophos errors
4
4
  class SophosError < StandardError; end
5
5
 
6
- # Raised when Zabbix not configured correctly
6
+ # Raised when Sophos not configured correctly
7
7
  class ConfigurationError < SophosError; end
8
8
 
9
9
  # Error when authentication fails
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sophos
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
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.0
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-02-20 00:00:00.000000000 Z
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.12
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)