Skip to content

Commit 5e98b31

Browse files
authored
refactor: Code cleanup and linting (#170)
* chore: Update dependencies * chore: Remove unused parameter * chore: Remove unused parameter * refactor: Move falco rules files to new client * refactor: Solve linter problems * ci: Force linting process in CI step
1 parent 0889150 commit 5e98b31

36 files changed

+699
-668
lines changed

.flake8

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
[flake8]
2-
ignore = E501, F821
2+
ignore = E501, F821, W504, W605, E303
33
show-source = True
4-
4+
count = True
5+
statistics = True
6+
max-line-length=127

.github/workflows/ci-pull-request.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@ jobs:
4242
run: poetry install
4343

4444
- name: Lint
45-
continue-on-error: true
4645
run: |
4746
# stop the build if there are Python syntax errors or undefined names
48-
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
47+
poetry run flake8
4948
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
5049
poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
5150

doc/conf.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#
1919
import os
2020
import sys
21-
sys.path.insert(0, os.path.abspath('..'))
2221

22+
sys.path.insert(0, os.path.abspath('..'))
2323

2424
# -- General configuration ------------------------------------------------
2525

@@ -30,7 +30,7 @@
3030
# Add any Sphinx extension module names here, as strings. They can be
3131
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3232
# ones.
33-
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.linkcode' ]
33+
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.linkcode']
3434

3535
# Add any paths that contain templates here, relative to this directory.
3636
templates_path = ['_templates']
@@ -76,7 +76,6 @@
7676
# If true, `todo` and `todoList` produce output, else they produce nothing.
7777
todo_include_todos = False
7878

79-
8079
# -- Options for HTML output ----------------------------------------------
8180

8281
# The theme to use for HTML and HTML Help pages. See the documentation for
@@ -95,13 +94,11 @@
9594
# so a file named "default.css" will overwrite the builtin "default.css".
9695
html_static_path = ['_static']
9796

98-
9997
# -- Options for HTMLHelp output ------------------------------------------
10098

10199
# Output file base name for HTML help builder.
102100
htmlhelp_basename = 'python-sdc-clientdoc'
103101

104-
105102
# -- Options for LaTeX output ---------------------------------------------
106103

107104
latex_elements = {
@@ -130,7 +127,6 @@
130127
u'Sysdig Inc.', 'manual'),
131128
]
132129

133-
134130
# -- Options for manual page output ---------------------------------------
135131

136132
# One entry per manual page. List of tuples
@@ -140,7 +136,6 @@
140136
[author], 1)
141137
]
142138

143-
144139
# -- Options for Texinfo output -------------------------------------------
145140

146141
# Grouping the document tree into Texinfo files. List of tuples
@@ -159,13 +154,12 @@ def find_line():
159154
for part in info['fullname'].split('.'):
160155
obj = getattr(obj, part)
161156
import inspect
162-
fn = inspect.getsourcefile(obj)
163157
source, lineno = inspect.findsource(obj)
164158
return lineno + 1
165159

166160
if domain != 'py' or not info['module']:
167161
return None
168-
#tag = 'master' if 'dev' in release else ('v' + release)
162+
# tag = 'master' if 'dev' in release else ('v' + release)
169163
url = "https://github.com/draios/python-sdc-client/blob/master/sdcclient/_client.py"
170164
try:
171165
return url + '#L%d' % find_line()

examples/dashboard_backup_v1_restore_v2.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@
1212
# Parse arguments
1313
#
1414
if len(sys.argv) != 5:
15-
print((
16-
'usage: %s <sysdig-v1-url> <sysdig-v1-token> <sysdig-v2-url> <sysdig-v2-token>'
17-
% sys.argv[0]))
18-
print(
19-
'You can find your token at https://app.sysdigcloud.com/#/settings/user'
20-
)
15+
print(f'usage: {sys.argv[0]} <sysdig-v1-url> <sysdig-v1-token> <sysdig-v2-url> <sysdig-v2-token>')
16+
print('You can find your token at https://app.sysdigcloud.com/#/settings/user')
2117
sys.exit(1)
2218

2319
sdc_v1_url = sys.argv[1]

examples/delete_event.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
import getopt
77
import sys
88

9-
from sdcclient import SdcClient, SdMonitorClient
9+
from sdcclient import SdMonitorClient
10+
1011

1112
#
1213
# Parse arguments
1314
#
14-
from sdcclient.monitor import EventsClientV2
1515

1616

1717
def usage():

examples/get_data_simple.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@
9292
#
9393
# Print table headers
9494
#
95-
dataToPrint = ' '.join([str(x['id']).ljust(colLen) if len(str(x['id'])) < colLen else str(x['id'])[
96-
:(colLen - 3)].ljust(
97-
colLen - 3) + '...' for x in metrics])
95+
dataToPrint = ' '.join(
96+
[str(x['id']).ljust(colLen) if len(str(x['id'])) < colLen else str(x['id'])[:(colLen - 3)].ljust(
97+
colLen - 3) + '...' for x in metrics])
9898
print(('%s %s' % ('timestamp'.ljust(colLen), dataToPrint) if sampling > 0 else dataToPrint))
9999
print('')
100100

examples/get_secure_policy_events_old.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414
# UNSUPPORTED: This script is unsupported as it is only an example from an old API version.
1515
# ===========================================================================================
1616

17-
import os
18-
import sys
17+
import getopt
1918
import json
2019
import operator
2120
import re
22-
import getopt
23-
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
21+
import sys
22+
2423
from sdcclient.secure import PolicyEventsClientOld
2524

2625

2726
def usage():
28-
print('usage: %s [-s|--summarize] [-l|--limit <limit>] <sysdig-token> [<duration sec>|<from sec> <to sec>]' % sys.argv[0])
27+
print('usage: %s [-s|--summarize] [-l|--limit <limit>] <sysdig-token> [<duration sec>|<from sec> <to sec>]' %
28+
sys.argv[0])
2929
print('-s|--summarize: group policy events by sanitized output and print by frequency')
3030
print('-l|--limit: with -s, only print the first <limit> outputs')
3131
print('You can find your token at https://secure.sysdig.com/#/settings/user')

examples/list_access_keys.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
# have Admin rights.
55
#
66

7-
import os
87
import sys
9-
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
8+
109
from sdcclient import SdcClient
1110

1211
#

examples/restore_alerts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@
8787
print(res)
8888
sys.exit(1)
8989

90-
print(('All Alerts in ' + alerts_dump_file + ' restored successfully ('
91-
+ str(created_count) + ' created, ' + str(updated_count) + ' updated)'))
90+
print(f'All Alerts in {alerts_dump_file} restored successfully '
91+
f'({str(created_count)} created, {str(updated_count)} updated)')

poetry.lock

Lines changed: 18 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)