sophos_central_api 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile +1 -0
- data/README.md +6 -3
- data/Rakefile +8 -0
- data/bin/cc-test-reporter.exe +0 -0
- data/lib/sophos/authentication.rb +7 -2
- data/lib/sophos/client/endpoint.rb +4 -4
- data/lib/sophos/client/helper.rb +9 -19
- data/lib/sophos/client/partner.rb +3 -3
- data/lib/sophos/configuration.rb +1 -1
- data/lib/sophos/error.rb +11 -0
- data/lib/sophos/version.rb +1 -1
- data/lib/sophos_central_api.rb +1 -1
- data/sophos_central_api.gemspec +1 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de42982e7073acef13887732efb277b3f24e31fcf34552f7857100edc20b99a2
|
4
|
+
data.tar.gz: 40425c2083e372ea6434f86723209ddd1673a1055ca8fc26e9bac997fb961305
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c3655439d962b32baef1e85a1ec31e4442c103472a82d0a2388d271fccde35c2fadb43088fd07db5ef3676d99331cea568f4019f61705b54a88577a7f97e073
|
7
|
+
data.tar.gz: 47cc68a252b5ad954f6bb6b48aae862b27e48ab35e0bacdb8c1fb605dd4d322d2af1325ec5457bef5ad6c970d20ac5f01c23e30705bd41f50c58a0c0e55c208b
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
# Sophos Central Partner API
|
2
|
+
[![Version](https://img.shields.io/gem/v/sophos_central_api.svg)](https://rubygems.org/gems/sophos_central_api)
|
3
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/0e0c212559aad49a915c/maintainability)](https://codeclimate.com/github/jancotanis/sophos/maintainability)
|
4
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/0e0c212559aad49a915c/test_coverage)](https://codeclimate.com/github/jancotanis/sophos/test_coverage)
|
2
5
|
|
3
6
|
This is a wrapper for the Sophos Central Partner API. You can see the API endpoints here https://developer.sophos.com/getting-started
|
4
7
|
|
@@ -9,7 +12,7 @@ Currently only the GET requests to customers, endpoints and alerts are implement
|
|
9
12
|
Add this line to your application's Gemfile:
|
10
13
|
|
11
14
|
```ruby
|
12
|
-
gem '
|
15
|
+
gem 'sophos_central_api'
|
13
16
|
```
|
14
17
|
|
15
18
|
And then execute:
|
@@ -18,14 +21,14 @@ And then execute:
|
|
18
21
|
|
19
22
|
Or install it yourself as:
|
20
23
|
|
21
|
-
$ gem install
|
24
|
+
$ gem install sophos_central_api
|
22
25
|
|
23
26
|
## Usage
|
24
27
|
|
25
28
|
Before you start making the requests to API provide the client id and client secret and email/password using the configuration wrapping.
|
26
29
|
|
27
30
|
```
|
28
|
-
require '
|
31
|
+
require 'sophos_central_api'
|
29
32
|
|
30
33
|
Sophos.configure do |config|
|
31
34
|
config.client_id = ENV["SOPHOS_CLIENT_ID"]
|
data/Rakefile
CHANGED
@@ -1,12 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'bundler/gem_tasks'
|
4
|
+
require 'dotenv'
|
4
5
|
require 'rake/testtask'
|
5
6
|
|
7
|
+
Dotenv.load
|
8
|
+
|
9
|
+
system './bin/cc-test-reporter before-build'
|
10
|
+
|
6
11
|
Rake::TestTask.new(:test) do |t|
|
7
12
|
t.libs << 'test'
|
8
13
|
t.libs << 'lib'
|
9
14
|
t.test_files = FileList['test/**/*_test.rb']
|
15
|
+
at_exit do
|
16
|
+
system './bin/cc-test-reporter after-build'
|
17
|
+
end
|
10
18
|
end
|
11
19
|
|
12
20
|
require 'rubocop/rake_task'
|
Binary file
|
@@ -1,5 +1,7 @@
|
|
1
|
+
require 'faraday'
|
1
2
|
require 'json'
|
2
3
|
require 'uri'
|
4
|
+
require File.expand_path('error', __dir__)
|
3
5
|
|
4
6
|
module Sophos
|
5
7
|
# Deals with authentication flow and stores it within global configuration
|
@@ -8,6 +10,7 @@ module Sophos
|
|
8
10
|
# Authorize to the Sophos portal and return access_token
|
9
11
|
# @see https://developer.sophos.com/getting-started
|
10
12
|
def auth_token(options = {})
|
13
|
+
raise ConfigurationError.new 'Client id and/or secret not configured' unless client_id && client_secret
|
11
14
|
# use id endpoint instead of global api
|
12
15
|
response = connection.post(id_endpoint+'/api/v2/oauth2/token') do |request|
|
13
16
|
request.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
@@ -22,8 +25,10 @@ module Sophos
|
|
22
25
|
self.endpoint = partner.apiHosts.global
|
23
26
|
self.connection_options = { headers: { 'X-partner-id': self.partner_id } }
|
24
27
|
else
|
25
|
-
raise
|
28
|
+
raise AuthenticationError.new 'Partner id not returned; response ' + response.to_s
|
26
29
|
end
|
30
|
+
rescue Faraday::UnauthorizedError => e
|
31
|
+
raise AuthenticationError.new 'Unauthorized; response ' + e.to_s
|
27
32
|
end
|
28
33
|
alias login auth_token
|
29
34
|
|
@@ -43,7 +48,7 @@ module Sophos
|
|
43
48
|
self.token_type = response['token_type']
|
44
49
|
self.refresh_token = response['refresh_token']
|
45
50
|
self.token_expires = response['expires_in']
|
46
|
-
raise
|
51
|
+
raise AuthenticationError.new 'Could not find valid access_token; response ' + response.to_s if at.nil? || at.empty?
|
47
52
|
|
48
53
|
at
|
49
54
|
end
|
@@ -11,23 +11,23 @@ module Sophos
|
|
11
11
|
Helper::def_api_call :downloads, Helper::endpoint_url(:downloads)
|
12
12
|
|
13
13
|
# @see https://developer.sophos.com/docs/endpoint-v1/1/routes/endpoint-groups/get
|
14
|
-
Helper::def_api_call :endpoint_groups, Helper::endpoint_url(:endpoint_groups),
|
14
|
+
Helper::def_api_call :endpoint_groups, Helper::endpoint_url(:endpoint_groups), :endpoint_group
|
15
15
|
def endpoint_group_endpoints(group_id)
|
16
16
|
get_paged Helper::endpoint_url("endpoint-groups/#{group_id}/endpoints")
|
17
17
|
end
|
18
18
|
|
19
19
|
# @see https://developer.sophos.com/docs/endpoint-v1/1/routes/migrations/get
|
20
|
-
Helper::def_api_call :migrations, Helper::endpoint_url(:migrations),
|
20
|
+
Helper::def_api_call :migrations, Helper::endpoint_url(:migrations), :migration
|
21
21
|
def migration_endpoints(migration_id)
|
22
22
|
get_paged Helper::endpoint_url("migrations/#{migration_id}/endpoints")
|
23
23
|
end
|
24
24
|
|
25
25
|
# @see https://developer.sophos.com/docs/endpoint-v1/1/routes/policies/get
|
26
|
-
Helper::def_api_call :policies, Helper::endpoint_url(:policies),
|
26
|
+
Helper::def_api_call :policies, Helper::endpoint_url(:policies), :policy
|
27
27
|
|
28
28
|
# Get all the endpoints for the specified tenant. No endpoint method defined as this clashes with api endpoint method
|
29
29
|
# @see https://developer.sophos.com/docs/endpoint-v1/1/routes/endpoints/get
|
30
|
-
Helper::def_api_call :endpoints, Helper::endpoint_url(:endpoints)
|
30
|
+
Helper::def_api_call :endpoints, Helper::endpoint_url(:endpoints)
|
31
31
|
def endpoint_isolation(endpoint_id)
|
32
32
|
get Helper::endpoint_url("endpoints/#{endpoint_id}/isolation")
|
33
33
|
end
|
data/lib/sophos/client/helper.rb
CHANGED
@@ -8,26 +8,17 @@ module Sophos
|
|
8
8
|
method_name.to_s.gsub('_', '-')
|
9
9
|
end
|
10
10
|
|
11
|
-
def self.
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
"/common/v1/#{sanitize(method)}"
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.endpoint_url(method)
|
21
|
-
"/endpoint/v1/#{sanitize(method)}"
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.partner_url(method)
|
25
|
-
"/partner/v1/#{sanitize(method)}"
|
11
|
+
def self.common_url(method) self.url('common', method); end
|
12
|
+
def self.endpoint_url(method) self.url('endpoint', method); end
|
13
|
+
def self.partner_url(method) self.url('partner', method); end
|
14
|
+
|
15
|
+
def self.url(api,method)
|
16
|
+
"/#{api}/v1/#{sanitize(method)}"
|
26
17
|
end
|
27
18
|
|
28
19
|
# generate end point for 'endpoint' and 'endpoints'
|
29
|
-
def self.def_api_call(method, url,
|
30
|
-
if
|
20
|
+
def self.def_api_call(method, url, singular_method = nil, paged = true)
|
21
|
+
if singular_method
|
31
22
|
self.send(:define_method, method) do |id = nil, params = {}|
|
32
23
|
if id
|
33
24
|
get("#{url}/#{id}", params)
|
@@ -36,8 +27,7 @@ module Sophos
|
|
36
27
|
end
|
37
28
|
end
|
38
29
|
# strip trailing 's'
|
39
|
-
|
40
|
-
self.send(:define_method, singlr) do |id, params = {}|
|
30
|
+
self.send(:define_method, singular_method) do |id, params = {}|
|
41
31
|
get("#{url}/#{id}", params)
|
42
32
|
end
|
43
33
|
else
|
@@ -8,13 +8,13 @@ module Sophos
|
|
8
8
|
module Partner
|
9
9
|
|
10
10
|
# @see https://developer.sophos.com/docs/partner-v1/1/routes/tenants/get
|
11
|
-
Helper::def_api_call :tenants, Helper::partner_url(:tenants),
|
11
|
+
Helper::def_api_call :tenants, Helper::partner_url(:tenants), :tenant
|
12
12
|
|
13
13
|
# @see https://developer.sophos.com/docs/partner-v1/1/routes/roles/get
|
14
|
-
Helper::def_api_call :roles, Helper::partner_url(:roles),
|
14
|
+
Helper::def_api_call :roles, Helper::partner_url(:roles), :role
|
15
15
|
|
16
16
|
# @see https://developer.sophos.com/docs/partner-v1/1/routes/admins/get
|
17
|
-
Helper::def_api_call :admins, Helper::partner_url(:admins),
|
17
|
+
Helper::def_api_call :admins, Helper::partner_url(:admins), :admin
|
18
18
|
|
19
19
|
# Get the list of role assignments for given admin.
|
20
20
|
# @see https://developer.sophos.com/docs/partner-v1/1/routes/admins/%7BadminId%7D/role-assignments/get
|
data/lib/sophos/configuration.rb
CHANGED
@@ -7,7 +7,7 @@ module Sophos
|
|
7
7
|
module Configuration
|
8
8
|
include WrAPI::Configuration
|
9
9
|
|
10
|
-
# An array of additional valid keys in the options hash when configuring a
|
10
|
+
# An array of additional valid keys in the options hash when configuring a [Sophos::API]
|
11
11
|
VALID_OPTIONS_KEYS = (WrAPI::Configuration::VALID_OPTIONS_KEYS + [:partner_id, :tenant_id, :id_endpoint]).freeze
|
12
12
|
|
13
13
|
# @private
|
data/lib/sophos/error.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
module Sophos
|
2
|
+
|
3
|
+
# Generic error to be able to rescue all Zabbix errors
|
4
|
+
class SophosError < StandardError; end
|
5
|
+
|
6
|
+
# Raised when Zabbix not configured correctly
|
7
|
+
class ConfigurationError < SophosError; end
|
8
|
+
|
9
|
+
# Error when authentication fails
|
10
|
+
class AuthenticationError < SophosError; end
|
11
|
+
end
|
data/lib/sophos/version.rb
CHANGED
data/lib/sophos_central_api.rb
CHANGED
data/sophos_central_api.gemspec
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.
|
4
|
+
version: 0.2.0
|
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-
|
11
|
+
date: 2024-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rubocop
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,6 +106,7 @@ files:
|
|
92
106
|
- Gemfile
|
93
107
|
- README.md
|
94
108
|
- Rakefile
|
109
|
+
- bin/cc-test-reporter.exe
|
95
110
|
- lib/sophos/api.rb
|
96
111
|
- lib/sophos/authentication.rb
|
97
112
|
- lib/sophos/client.rb
|
@@ -100,6 +115,7 @@ files:
|
|
100
115
|
- lib/sophos/client/helper.rb
|
101
116
|
- lib/sophos/client/partner.rb
|
102
117
|
- lib/sophos/configuration.rb
|
118
|
+
- lib/sophos/error.rb
|
103
119
|
- lib/sophos/pagination.rb
|
104
120
|
- lib/sophos/version.rb
|
105
121
|
- lib/sophos_central_api.rb
|