sophos_central_api 0.1.0 → 0.1.2
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/.env.template +1 -0
- data/CHANGELOG.md +5 -0
- data/README.md +21 -1
- data/lib/sophos/client/partner.rb +0 -27
- data/lib/sophos/client.rb +15 -2
- data/lib/sophos/configuration.rb +27 -0
- data/lib/sophos/version.rb +1 -1
- data/lib/sophos_central_api.rb +1 -24
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed2be4896987431b40e0fc3b01f61addc9b58485aa3f1157493dadb070a792e2
|
4
|
+
data.tar.gz: 848756dcc5fd520b1f5584acad7a9a318caf569cfd4bbef377b9e646fbc6c5f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0e6aff68a24b83ae099fbb6d4273dc3cfa918b36223fefca96951b51f352081c50bfeef5f246205daf0ec98281a837f32390d151704340e2f048193479a2bf8
|
7
|
+
data.tar.gz: 5aec805aaf3ab8988af7dc8adc50fb4e41564e94bf1cfdfa1fd05b6251bd7ac6a0af0a87fc94b1e619e408b5e1e8266d8ddfa3d86fd2a92bb4dd39c2112731d1
|
data/.env.template
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -70,6 +70,27 @@ roles = client.roles
|
|
70
70
|
|.billing_usage(year, month) |/partner/v1/billing-usage/{year}/{month}|
|
71
71
|
|
72
72
|
|
73
|
+
### Common
|
74
|
+
This is the OAS 3.0 specification for the Common API in Sophos Central.
|
75
|
+
|
76
|
+
```
|
77
|
+
@client = Sophos.client()
|
78
|
+
@client.login
|
79
|
+
:
|
80
|
+
tenant = @client.tenant(id)
|
81
|
+
# create client for tenant
|
82
|
+
@client.client(tenant).endpoints
|
83
|
+
|
84
|
+
```
|
85
|
+
|
86
|
+
|Resource|API endpoint|
|
87
|
+
|:--|:--|
|
88
|
+
|.alerts, .alert(id) |.../alerts/|
|
89
|
+
|.directory_user_groups, .directory_user_groups(id) |.../directory/user-groups|
|
90
|
+
|.directory_user_group_users(id) |.../directory/user-groups/{id}/users|
|
91
|
+
|.directory_users, .directory_user(id) |.../directory/users|
|
92
|
+
|.directory_user_groups(id) |.../directory/users/{id}/groups|
|
93
|
+
|
73
94
|
### Endpoints
|
74
95
|
Returns endpoint for a provided tenant
|
75
96
|
```
|
@@ -83,7 +104,6 @@ tenant = @client.tenant(id)
|
|
83
104
|
|
84
105
|
|Resource|API endpoint|
|
85
106
|
|:--|:--|
|
86
|
-
|
87
107
|
|.downloads |.../downloads/|
|
88
108
|
|.endpoint_groups, .endpoint_group(id) |.../endpoint-groupss/|
|
89
109
|
|.migrations, .migration(id) |.../migrations|
|
@@ -7,28 +7,6 @@ module Sophos
|
|
7
7
|
# @see https://developer.sophos.com/docs/partner-v1/1/overview
|
8
8
|
module Partner
|
9
9
|
|
10
|
-
def self.__def_partner_call(method, id_field = nil)
|
11
|
-
if id_field
|
12
|
-
self.send(:define_method, method) do |id = nil|
|
13
|
-
url = partner_url(method)
|
14
|
-
if id
|
15
|
-
get(partner_url("#{method}/#{id}"))
|
16
|
-
else
|
17
|
-
get_paged(url)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
# strip trailing 's'
|
21
|
-
singular = method.to_s.chop.to_sym
|
22
|
-
self.send(:define_method, singular) do |id, params = nil|
|
23
|
-
get(partner_url("#{method}/#{id}", params))
|
24
|
-
end
|
25
|
-
else
|
26
|
-
self.send(:define_method, method) do
|
27
|
-
get_paged(partner_url(method))
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
10
|
# @see https://developer.sophos.com/docs/partner-v1/1/routes/tenants/get
|
33
11
|
Helper::def_api_call :tenants, Helper::partner_url(:tenants), true
|
34
12
|
|
@@ -61,11 +39,6 @@ module Sophos
|
|
61
39
|
get_paged(Helper::partner_url("billing/usage/#{year}/#{month}"), params)
|
62
40
|
end
|
63
41
|
|
64
|
-
private
|
65
|
-
|
66
|
-
def __partner_url(method, id = nil)
|
67
|
-
"/partner/v1/#{method}"
|
68
|
-
end
|
69
42
|
end
|
70
43
|
end
|
71
44
|
end
|
data/lib/sophos/client.rb
CHANGED
@@ -9,12 +9,25 @@ module Sophos
|
|
9
9
|
class Client < API
|
10
10
|
require File.expand_path('client/partner', __dir__)
|
11
11
|
|
12
|
+
# get client to access api host for given tenant
|
13
|
+
# @return [TenantClient]
|
14
|
+
def client(tenant)
|
15
|
+
tenant_client(tenant.apiHost, tenant.id) if tenant
|
16
|
+
end
|
17
|
+
|
18
|
+
# get teannt client to access api host for given tenant id
|
19
|
+
# @return [TenantClient]
|
12
20
|
def tenant_client( api_host, tenant_id )
|
13
|
-
|
21
|
+
# create client and copy access_token and set default headers
|
22
|
+
TenantClient.new(self.config.merge({
|
23
|
+
access_token: access_token,
|
24
|
+
endpoint: api_host,
|
25
|
+
tenant_id: tenant_id,
|
26
|
+
connection_options: { headers: { 'X-Tenant-ID': tenant_id } }
|
27
|
+
}))
|
14
28
|
end
|
15
29
|
|
16
30
|
include Sophos::Client::Partner
|
17
|
-
|
18
31
|
end
|
19
32
|
|
20
33
|
# Wrapper for the Sophos Central REST API for tenant related calls
|
data/lib/sophos/configuration.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'wrapi'
|
2
|
+
require File.expand_path('version', __dir__)
|
3
|
+
require File.expand_path('pagination', __dir__)
|
2
4
|
|
3
5
|
module Sophos
|
4
6
|
# Defines constants and methods related to configuration
|
@@ -11,10 +13,35 @@ module Sophos
|
|
11
13
|
# @private
|
12
14
|
attr_accessor *VALID_OPTIONS_KEYS
|
13
15
|
|
16
|
+
DEFAULT_ENDPOINT = 'https://api.central.sophos.com'.freeze
|
17
|
+
DEFAULT_ID_ENDPOINT = 'https://id.sophos.com'.freeze
|
18
|
+
DEFAULT_UA = "Sophos Ruby API wrapper #{Sophos::VERSION}".freeze
|
19
|
+
DEFAULT_PAGINATION = Sophos::RequestPagination::PagesPagination
|
20
|
+
DEFAULT_PAGE_SIZE = 100
|
21
|
+
|
22
|
+
# When this module is extended, set all configuration options to their default values
|
23
|
+
def self.extended(base)
|
24
|
+
base.reset
|
25
|
+
end
|
26
|
+
|
27
|
+
# Create a hash of options and their values
|
28
|
+
def options
|
29
|
+
VALID_OPTIONS_KEYS.inject({}) do |option, key|
|
30
|
+
option.merge!(key => send(key))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
14
34
|
# Reset all configuration options to defaults
|
15
35
|
def reset
|
16
36
|
super
|
17
37
|
self.partner_id = nil
|
38
|
+
self.tenant_id = nil
|
39
|
+
|
40
|
+
self.endpoint = DEFAULT_ENDPOINT
|
41
|
+
self.id_endpoint = DEFAULT_ID_ENDPOINT
|
42
|
+
self.user_agent = DEFAULT_UA
|
43
|
+
self.page_size = DEFAULT_PAGE_SIZE
|
44
|
+
self.pagination_class = DEFAULT_PAGINATION
|
18
45
|
end
|
19
46
|
end
|
20
47
|
end
|
data/lib/sophos/version.rb
CHANGED
data/lib/sophos_central_api.rb
CHANGED
@@ -1,37 +1,14 @@
|
|
1
1
|
require "wrapi"
|
2
2
|
require File.expand_path('sophos/api', __dir__)
|
3
3
|
require File.expand_path('sophos/client', __dir__)
|
4
|
-
require File.expand_path('sophos/pagination', __dir__)
|
5
|
-
require File.expand_path('sophos/version', __dir__)
|
6
4
|
|
7
5
|
module Sophos
|
8
6
|
extend Configuration
|
9
7
|
extend WrAPI::RespondTo
|
10
8
|
|
11
|
-
DEFAULT_ENDPOINT = 'https://api.central.sophos.com'.freeze
|
12
|
-
DEFAULT_ID_ENDPOINT = 'https://id.sophos.com'.freeze
|
13
|
-
DEFAULT_UA = "Sophos Ruby API wrapper #{Sophos::VERSION}".freeze
|
14
|
-
DEFAULT_PAGINATION = Sophos::RequestPagination::PagesPagination
|
15
|
-
DEFAULT_PAGE_SIZE = 100
|
16
|
-
|
17
9
|
#
|
18
10
|
# @return [Sophos::Client]
|
19
11
|
def self.client(options = {})
|
20
|
-
Sophos::Client.new
|
21
|
-
endpoint: DEFAULT_ENDPOINT,
|
22
|
-
id_endpoint: DEFAULT_ID_ENDPOINT,
|
23
|
-
user_agent: DEFAULT_UA,
|
24
|
-
page_size: DEFAULT_PAGE_SIZE,
|
25
|
-
pagination_class: DEFAULT_PAGINATION
|
26
|
-
}.merge(options))
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.reset
|
30
|
-
super
|
31
|
-
self.endpoint = DEFAULT_ENDPOINT
|
32
|
-
self.id_endpoint = DEFAULT_ID_ENDPOINT
|
33
|
-
self.user_agent = DEFAULT_UA
|
34
|
-
self.page_size = DEFAULT_PAGE_SIZE
|
35
|
-
self.pagination_class = DEFAULT_PAGINATION
|
12
|
+
Sophos::Client.new
|
36
13
|
end
|
37
14
|
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.1.
|
4
|
+
version: 0.1.2
|
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-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|