Skip to content

Commit 31f8b26

Browse files
authored
Merge pull request #96 from Worvast/master
[3.4.1]
2 parents 8e5c4e5 + 7766436 commit 31f8b26

File tree

15 files changed

+201
-120
lines changed

15 files changed

+201
-120
lines changed

CHANGELOG.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,24 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77

8-
## [3.3.7] -
8+
## [3.4.1] - 2020-11-03
9+
### Added
10+
* Info about use custom CA for verify certificates in client
11+
12+
### Fixed
13+
* Client problems with default "From" key for queries
14+
* Socket closes are more gently now, fixed problems with loss events
15+
16+
### Changed
17+
* Updated message when overwrite sec_level to show only when create Sender
18+
* Updated test for bad credentials. Now api returns error in signature validation
19+
20+
## [3.4.0] - 2020-08-06
21+
### Added
22+
* Support to use in lookup fields lists: ints, booleans and floats. Not necessary send all with str type.
23+
* More documentation in lookup readme
24+
25+
## [3.3.7] - 2020-07-16
926
### Fixed
1027
* Problem in list_to_headers when pass key but not key_index
1128
* Count of sended events when zip=True
@@ -54,7 +71,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
5471
* Functions to change buffer size and compression_level of Sender
5572
* Support for zip, buffer and compression_level flags in Sender CLI
5673

57-
5874
### Changed
5975
* SSL Server support to adapt it from python 3.5 to python 3.8
6076
* SSL Send data tests

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
[![master Build Status](https://travis-ci.com/DevoInc/python-sdk.svg?branch=master)](https://travis-ci.com/DevoInc/python-sdk) [![LICENSE](https://img.shields.io/dub/l/vibe-d.svg)](https://github.com/DevoInc/python-sdk/blob/master/LICENSE)
33

4-
[![wheel](https://img.shields.io/badge/wheel-yes-brightgreen.svg)](https://pypi.org/project/devo-sdk/) [![version](https://img.shields.io/badge/version-3.3.7-blue.svg)](https://pypi.org/project/devo-sdk/) [![python](https://img.shields.io/badge/python-3.5%20%7C%203.6%20%7C%203.7%20%7C%203.8-blue.svg)](https://pypi.org/project/devo-sdk/)
4+
[![wheel](https://img.shields.io/badge/wheel-yes-brightgreen.svg)](https://pypi.org/project/devo-sdk/) [![version](https://img.shields.io/badge/version-3.4.1-blue.svg)](https://pypi.org/project/devo-sdk/) [![python](https://img.shields.io/badge/python-3.5%20%7C%203.6%20%7C%203.7%20%7C%203.8-blue.svg)](https://pypi.org/project/devo-sdk/)
55

66

77
# Devo Python SDK

devo/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__description__ = 'Devo Python Library.'
22
__url__ = 'http://www.devo.com'
3-
__version__ = "3.3.7"
3+
__version__ = "3.4.1"
44
__author__ = 'Devo'
55
__author_email__ = 'support@devo.com'
66
__license__ = 'MIT'

devo/api/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
ERROR_MSGS = {
2828
"no_query": "Error: Not query provided.",
2929
"no_auth": "Client dont have key&secret or auth token/jwt",
30-
"no_endpoint": "Endpoint 'address' not found"
30+
"no_endpoint": "Endpoint 'address' not found",
31+
"to_but_no_from": "If you use end dates for the query 'to' it is "
32+
"necessary to use start date 'from'"
3133
}
3234

3335

devo/api/scripts/client_cli.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,20 @@ def query(**kwargs):
7474
return
7575
exit()
7676

77-
dates = {}
78-
if "to" in config.keys():
79-
dates["from"] = config['from']
80-
if "to" in config.keys():
81-
dates["to"] = config['to']
82-
if "timeZone" in config.keys():
83-
dates['timeZone'] = config['timeZone']
77+
if "from" in config.keys():
78+
dates = {'from': config['from']}
79+
if "to" in config.keys():
80+
dates["to"] = config['to']
81+
if "timeZone" in config.keys():
82+
dates['timeZone'] = config['timeZone']
83+
elif "to" in config.keys():
84+
print_error(ERROR_MSGS['to_but_no_from'], show_help=True)
85+
exit()
86+
else:
87+
if "timeZone" in config.keys():
88+
dates = {'timeZone': config['timeZone']}
89+
else:
90+
dates = None
8491

8592
reponse = api.query(query=config['query'], dates=dates)
8693

devo/sender/data.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def __init__(self, address=None):
8989
try:
9090
self.address = address
9191
self.hostname = socket.gethostname()
92+
self.sec_level = None
9293
except Exception as error:
9394
raise DevoSenderException(
9495
"DevoSenderConfigTCP|Can't create TCP config: "
@@ -131,8 +132,16 @@ def __init__(self, config=None, con_type=None,
131132
get_log(handler=get_stream_handler(
132133
msg_format='%(asctime)s|%(levelname)s|Devo-Sender|%(message)s'))
133134

134-
self.socket = None
135135
self._sender_config = config
136+
137+
if self._sender_config.sec_level is not None:
138+
self.logger.warning("Openssl's default security "
139+
"level has been overwritten to "
140+
"{}.".format(self.
141+
_sender_config.
142+
sec_level))
143+
144+
self.socket = None
136145
self.reconnection = 0
137146
self.debug = debug
138147
self.socket_timeout = timeout
@@ -201,11 +210,6 @@ def __connect_ssl(self):
201210
cafile=self._sender_config.chain)
202211

203212
if self._sender_config.sec_level is not None:
204-
self.logger.warning("Openssl's default security "
205-
"level has been overwritten to "
206-
"{}.".format(self.
207-
_sender_config.
208-
sec_level))
209213
context.set_ciphers(
210214
"DEFAULT@SECLEVEL={!s}"
211215
.format(self._sender_config.sec_level))
@@ -340,6 +344,7 @@ def close(self):
340344
Forces socket closure
341345
"""
342346
if self.socket is not None:
347+
self.socket.shutdown(2)
343348
self.socket.close()
344349
self.socket = None
345350

devo/sender/lookup.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def send_data(self, row='', delete=False):
260260
261261
>>>row = Lookup.list_to_fields(fields, "23")
262262
>>>obj.send_data(row)
263-
:param row: row to send
263+
:param row: row t o send
264264
:param delete: True or False. Its true, delete row with same key
265265
:return:
266266
"""
@@ -404,10 +404,14 @@ def clean_field(field=None):
404404
:param str field: field for clean
405405
:return str: cleaned field
406406
"""
407+
if not isinstance(field, (str, bytes)):
408+
return field
409+
407410
field = field.strip()
408-
if not Lookup.is_number(field):
409-
field = '"%s"' % field
410-
return field
411+
if Lookup.is_number(field):
412+
return field
413+
414+
return '"%s"' % field
411415

412416
@staticmethod
413417
def is_number(text=""):

docs/api/api.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,25 @@ You can revert it with:
164164
api.verify_certificates(True)
165165
```
166166

167+
## Use custom CA to verify
168+
For customs servers, and custom certificates, you can use custom CA for verity that certificates.
169+
You can put CA cert path instead of "False" or "True"
170+
171+
```python
172+
from devo.api import Client, ClientConfig
173+
174+
175+
api = Client(auth= {"key":"myapikey", "secret":"myapisecret"},
176+
address="https://apiv2-eu.devo.com/search/query")
177+
api.verify_certificates("/path/to/cafile.ca")
178+
```
179+
180+
You can revert it with:
181+
182+
```python
183+
api.verify_certificates(True)
184+
```
185+
167186
## Processors flags:
168187

169188
By default, you receive response in str/bytes (Depends of your python version) direct from Socket, and you need manipulate the data.

docs/api/destination_email.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ API have a email destination to send query results by email.
44

55
## How to use
66

7-
As any query you must to add 'query', 'from' and 'to' date params. But It's not necessary add mode.type parameter because all response format will be csv. In a future will have support for more format, **if you need more format please request us**.
7+
As any query you must to add 'query', 'from' and 'to' date params. But It's not necessary add mode.type parameter
8+
because all response format will be csv. In a future will have support for more format,
9+
**if you need more format please request us**.
810

911
To use 'email' destination you must add destination parameter with type 'email' (see example).
1012

@@ -29,29 +31,27 @@ To use 'email' destination you must add destination parameter with type 'email'
2931

3032
## Example
3133

32-
```python
33-
from devo.api import Client
34-
35-
api = Client(key="myapikey",
36-
secret="myapisecret",
37-
url="https://apiv2-eu.devo.com/search/query",
38-
user="user@devo.com",
39-
app_name="testing app")
40-
41-
42-
response = api.query("from siem.logtrust.web.activity select *",
43-
dates={"from":"yesterday()", "to": "now()"},
44-
destination= {
45-
"type":"email",
46-
"params":{
47-
"email.to":"email@domain.com",
48-
"email.subject":"Api v2 Test",
49-
"retention.time":300000,
50-
"format":"gzip",
51-
},
52-
})
34+
```pyton
35+
api = Client(auth={"key": "myapikey",
36+
"secret": "myapisecret"},
37+
address="https://apiv2-eu.devo.com/search/query",
38+
config=ClientConfig(response="json", stream=False, processor=JSON,
39+
destination={
40+
"type": "email",
41+
"params": {
42+
"email.to": "user@devo.com",
43+
"email.subject": "Api v2 Test",
44+
"format": "gzip",
45+
},
46+
}))
47+
48+
49+
response = api.query("from siem.logtrust.web.activity select * limit 10",
50+
dates={"from": "yesterday()", "to": "now()"})
51+
5352
```
5453

54+
5555
## Result
5656

5757
Send a email with a zip/gzip file with the results.

docs/api/destination_redis.md

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,40 +31,39 @@ This destination have 2 modes:
3131

3232
### Example
3333

34-
```python
35-
from devo.api import Client
36-
37-
api = Client(key="myapikey",
38-
secret="myapisecret",
39-
url="https://apiv2-eu.devo.com/search/query",
40-
user="user@devo.com",
41-
app_name="testing app")
42-
43-
44-
response = api.query("from siem.logtrust.web.activity select *",
45-
dates={"from":"yesterday()", "to": "now()"},
46-
destination= {
47-
"type":"email",
48-
"params":{
49-
"friendlyName":"redis-rresino-154q",
50-
"description": "description of task",
51-
"expireIn": 30000,
52-
"keyFields": [{
53-
"name": "domain",
54-
"type": "str"
55-
}, {
56-
"name": "username",
57-
"type": "str"
58-
}],
59-
"valueFields": [{
60-
"name": "domain",
61-
"type": "str"
62-
}, {
63-
"name": "username",
64-
"type": "str"
65-
}]
66-
},
67-
})
34+
35+
```pyton
36+
api = Client(auth={"key": "myapikey",
37+
"secret": "myapisecret"},
38+
address="https://apiv2-eu.devo.com/search/query",
39+
config=ClientConfig(response="json", stream=False, processor=JSON,
40+
destination= {
41+
"type":"redis",
42+
"params":{
43+
"friendlyName":"redis-rresino-154q",
44+
"description": "description of task",
45+
"expireIn": 30000,
46+
"keyFields": [{
47+
"name": "domain",
48+
"type": "str"
49+
}, {
50+
"name": "username",
51+
"type": "str"
52+
}],
53+
"valueFields": [{
54+
"name": "domain",
55+
"type": "str"
56+
}, {
57+
"name": "username",
58+
"type": "str"
59+
}]
60+
},
61+
}))
62+
63+
64+
response = api.query("from siem.logtrust.web.activity select * limit 10",
65+
dates={"from": "yesterday()", "to": "now()"})
66+
6867
```
6968

7069
## Results
@@ -147,4 +146,4 @@ fields in object;
147146
"error": []
148147
}
149148
}
150-
```
149+
```

0 commit comments

Comments
 (0)