Skip to content

Commit 0eb9697

Browse files
authored
fix: Solve crash on error retrieving user falco rules (#162)
1 parent 8611ed3 commit 0eb9697

File tree

3 files changed

+62
-50
lines changed

3 files changed

+62
-50
lines changed

.github/workflows/ci-master-scheduled.yml

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: CI - Master - Scheduled
33
on:
44
schedule:
55
- cron: "0 1 * * *" # 1 AM everyday https://crontab.guru/#0_1_*_*_*
6+
workflow_dispatch:
67

78
jobs:
89
scheduled-test:
@@ -18,62 +19,62 @@ jobs:
1819
- "3.9"
1920
runs-on: ubuntu-latest
2021
steps:
21-
- uses: actions/checkout@v2
22+
- uses: actions/checkout@v2
2223

23-
- uses: actions/setup-python@v2
24-
with:
25-
python-version: ${{ matrix.python_version }}
24+
- uses: actions/setup-python@v2
25+
with:
26+
python-version: ${{ matrix.python_version }}
2627

27-
- name: Install Poetry
28-
run: python -m pip install poetry poetry-dynamic-versioning
28+
- name: Install Poetry
29+
run: python -m pip install poetry poetry-dynamic-versioning
2930

30-
- uses: actions/cache@v2
31-
name: Cache Poetry dependencies
32-
with:
33-
path: |
34-
~/.cache
35-
~/.local/share/virtualenvs/
36-
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
37-
restore-keys: |
38-
${{ runner.os }}-poetry-
31+
- uses: actions/cache@v2
32+
name: Cache Poetry dependencies
33+
with:
34+
path: |
35+
~/.cache
36+
~/.local/share/virtualenvs/
37+
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
38+
restore-keys: |
39+
${{ runner.os }}-poetry-
3940
40-
- name: Get dependencies
41-
run: poetry install
41+
- name: Get dependencies
42+
run: poetry install
4243

43-
- name: Lint
44-
continue-on-error: true
45-
run: |
46-
# stop the build if there are Python syntax errors or undefined names
47-
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
48-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
49-
poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
44+
- name: Lint
45+
continue-on-error: true
46+
run: |
47+
# 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
49+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
50+
poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
5051
51-
- name: Travis Test - Start agent
52-
id: start_agent
53-
env:
54-
PYTHON_SDC_TEST_ACCESS_KEY: ${{ secrets.STAGING_AGENT_KEY }}
55-
run: |
56-
sudo apt-get install linux-headers-$(uname -r) dkms gcc-multilib g++-multilib
57-
./test/start_agent.sh
52+
- name: Travis Test - Start agent
53+
id: start_agent
54+
env:
55+
PYTHON_SDC_TEST_ACCESS_KEY: ${{ secrets.STAGING_AGENT_KEY }}
56+
run: |
57+
sudo apt-get install linux-headers-$(uname -r) dkms gcc-multilib g++-multilib
58+
./test/start_agent.sh
5859
59-
- name: Travis Test - Install dependencies
60-
run: |
61-
poetry build
62-
python -m pip install $(find dist -iname "*.whl" | head -1)
60+
- name: Travis Test - Install dependencies
61+
run: |
62+
poetry build
63+
python -m pip install $(find dist -iname "*.whl" | head -1)
6364
64-
- name: Travis Test - Secure APIs
65-
env:
66-
PYTHON_SDC_TEST_API_TOKEN: ${{ secrets.STAGING_SECURE_API_TOKEN }}
67-
run: ./test/test_secure_apis.sh
65+
- name: Travis Test - Secure APIs
66+
env:
67+
PYTHON_SDC_TEST_API_TOKEN: ${{ secrets.STAGING_SECURE_API_TOKEN }}
68+
run: ./test/test_secure_apis.sh
6869

69-
- name: Test in staging
70-
env:
71-
SDC_MONITOR_TOKEN: ${{ secrets.STAGING_MONITOR_API_TOKEN }}
72-
SDC_SECURE_TOKEN: ${{ secrets.STAGING_SECURE_API_TOKEN }}
73-
SDC_MONITOR_URL: "https://app-staging.sysdigcloud.com"
74-
SDC_SECURE_URL: "https://secure-staging.sysdig.com"
75-
run: poetry run mamba -f documentation
70+
- name: Test in staging
71+
env:
72+
SDC_MONITOR_TOKEN: ${{ secrets.STAGING_MONITOR_API_TOKEN }}
73+
SDC_SECURE_TOKEN: ${{ secrets.STAGING_SECURE_API_TOKEN }}
74+
SDC_MONITOR_URL: "https://app-staging.sysdigcloud.com"
75+
SDC_SECURE_URL: "https://secure-staging.sysdig.com"
76+
run: poetry run mamba -f documentation
7677

77-
- name: Travis Test - Stop agent
78-
run: ./test/stop_agent.sh
79-
if: steps.start_agent.outcome == 'success'
78+
- name: Travis Test - Stop agent
79+
run: ./test/stop_agent.sh
80+
if: steps.start_agent.outcome == 'success'

sdcclient/_secure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def get_user_falco_rules(self):
6565
`examples/get_secure_user_falco_rules.py <https://github.com/draios/python-sdc-client/blob/master/examples/get_secure_user_falco_rules.py>`_
6666
'''
6767
ok, res = self._get_user_falco_rules()
68-
return res if not ok else [True, res["customFalcoRulesFiles"]["files"][0]["variants"][0]["content"]]
68+
return [False, res] if not ok else [True, res["customFalcoRulesFiles"]["files"][0]["variants"][0]["content"]]
6969

7070
def _get_user_falco_rules(self):
7171
res = self.http.get(self.url + '/api/settings/falco/customRulesFiles', headers=self.hdrs, verify=self.ssl_verify)

specs/secure/custom_rules_spec.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818
expect((ok, res)).to(be_successful_api_call)
1919
expect(res).to(start_with("####################\n# Your custom rules!\n####################\n"))
2020

21+
with context("when the credentials are not valid"):
22+
with it("can't be retrieved"):
23+
self.client = SdSecureClient(sdc_url=os.getenv("SDC_SECURE_URL", "https://secure.sysdig.com"),
24+
token="foo-bar")
25+
26+
ok, res = self.client.get_user_falco_rules()
27+
28+
expect((ok, res)).to_not(be_successful_api_call)
29+
expect(res).to(equal("Bad credentials"))
30+
31+
2132
with it("can push custom rules"):
2233
_, previous_rules = self.client.get_user_falco_rules()
2334
empty_rules = self.empty_falco_rules()

0 commit comments

Comments
 (0)