Skip to content

Commit df7990f

Browse files
Initial commit: add all project files
1 parent 9b535f9 commit df7990f

30 files changed

+10818
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Deploy Alert Rules
2+
3+
on:
4+
push:
5+
paths:
6+
- 'workspace/**'
7+
- '.github/workflows/run_iac.yaml'
8+
9+
jobs:
10+
install-and-run:
11+
name: Install and run Last9 IaC
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
python-version: ["3.11"]
16+
17+
steps:
18+
- name: Check out code
19+
uses: actions/checkout@v2
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v4
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
28+
- name: setup python env
29+
run: |
30+
python -m venv env
31+
. ./env/bin/activate
32+
33+
- name: Install IaC
34+
env:
35+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
36+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
37+
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
38+
run: |
39+
. ./env/bin/activate
40+
./scripts/install_iac.sh
41+
42+
- name: Run IaC plan
43+
env:
44+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
45+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
46+
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
47+
AWS_ASSUME_ROLE_ARN: ${{ secrets.AWS_ASSUME_ROLE_ARN }}
48+
AWS_ASSUME_ROLE_EXTERNAL_ID: ${{ secrets.AWS_ASSUME_ROLE_EXTERNAL_ID }}
49+
LAST9_BACKUP_S3_BUCKET: ${{ secrets.LAST9_BACKUP_S3_BUCKET }}
50+
LAST9_API_CONFIG_STR: ${{ secrets.LAST9_API_CONFIG_STR }}
51+
run: |
52+
. ./env/bin/activate
53+
./scripts/run-iac.sh --run-all-files --plan
54+
55+
- name: Run IaC apply
56+
if: github.ref == 'refs/heads/main'
57+
env:
58+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
59+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
60+
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
61+
AWS_ASSUME_ROLE_ARN: ${{ secrets.AWS_ASSUME_ROLE_ARN }}
62+
AWS_ASSUME_ROLE_EXTERNAL_ID: ${{ secrets.AWS_ASSUME_ROLE_EXTERNAL_ID }}
63+
LAST9_BACKUP_S3_BUCKET: ${{ secrets.LAST9_BACKUP_S3_BUCKET }}
64+
LAST9_API_CONFIG_STR: ${{ secrets.LAST9_API_CONFIG_STR }}
65+
run: |
66+
. ./env/bin/activate
67+
./scripts/run-iac.sh --run-all-files --apply

.github/workflows/run_iac.yaml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Deploy Alert Rules
2+
3+
on:
4+
push:
5+
paths:
6+
- 'workspace/**'
7+
- '.github/workflows/run_iac.yaml'
8+
9+
jobs:
10+
install-and-run:
11+
name: Install and run Last9 IaC
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
python-version: ["3.11"]
16+
17+
steps:
18+
- name: Check out code
19+
uses: actions/checkout@v2
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v4
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
28+
- name: setup python env
29+
run: |
30+
python -m venv env
31+
. ./env/bin/activate
32+
33+
- name: Install IaC
34+
env:
35+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
36+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
37+
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
38+
run: |
39+
. ./env/bin/activate
40+
./scripts/install_iac.sh
41+
42+
- name: Run IaC plan
43+
env:
44+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
45+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
46+
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
47+
AWS_ASSUME_ROLE_ARN: ${{ secrets.AWS_ASSUME_ROLE_ARN }}
48+
AWS_ASSUME_ROLE_EXTERNAL_ID: ${{ secrets.AWS_ASSUME_ROLE_EXTERNAL_ID }}
49+
LAST9_BACKUP_S3_BUCKET: ${{ secrets.LAST9_BACKUP_S3_BUCKET }}
50+
LAST9_API_CONFIG_STR: ${{ secrets.LAST9_API_CONFIG_STR }}
51+
run: |
52+
. ./env/bin/activate
53+
./scripts/run-iac.sh --run-all-files --plan
54+
55+
- name: Run IaC apply
56+
if: github.ref == 'refs/heads/main'
57+
env:
58+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
59+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
60+
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
61+
AWS_ASSUME_ROLE_ARN: ${{ secrets.AWS_ASSUME_ROLE_ARN }}
62+
AWS_ASSUME_ROLE_EXTERNAL_ID: ${{ secrets.AWS_ASSUME_ROLE_EXTERNAL_ID }}
63+
LAST9_BACKUP_S3_BUCKET: ${{ secrets.LAST9_BACKUP_S3_BUCKET }}
64+
LAST9_API_CONFIG_STR: ${{ secrets.LAST9_API_CONFIG_STR }}
65+
run: |
66+
. ./env/bin/activate
67+
./scripts/run-iac.sh --run-all-files --apply

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
install:
2+
./scripts/iac/install.sh
3+
4+
apply:
5+
@for file in ./rules/*.yaml; do \
6+
l9iac -mf $$file -c ./config.json apply; \
7+
done
8+
9+
plan:
10+
@for file in ./rules/*.yaml; do \
11+
l9iac -mf $$file -c ./config.json plan; \
12+
done
13+

pyproject.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[tool.black]
2+
# How many characters per line to allow.
3+
line-length = 119
4+
5+
# A regular expression that matches files and directories that
6+
# should be included on recursive searches. An empty value means
7+
# all files are included regardless of the name. Use forward
8+
# slashes for directories on all platforms (Windows, too).
9+
# Exclusions are calculated first, inclusions later.
10+
11+
exclude = '''
12+
(
13+
\.git
14+
| test/
15+
)
16+
'''

scripts/.flake8

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
[flake8]
2+
# Categories of error codes you wish Flake8 to report.
3+
# B = bugbear
4+
# E = pycodestyle errors
5+
# F = flake8 pyflakes
6+
# W = pycodestyle warnings
7+
# B9 = bugbear opinions
8+
9+
# list of codes to ignore.
10+
ignore =
11+
# multiple spaces or tab after ‘,’
12+
E24,
13+
# continuation line under-indented for hanging indent
14+
E121,
15+
# closing bracket does not match indentation of opening bracket’s line
16+
E123,
17+
# continuation line over-indented for hanging indent
18+
E126,
19+
# missing whitespace around arithmetic operator
20+
E226,
21+
# "It is fairly common for developers, especially those in closed-source projects, to change the maximum line length to 100 or 120 characters."
22+
E501,
23+
# multiple statements on one line (def)
24+
E704,
25+
# line break before binary operator
26+
W503,
27+
# line break after binary operator
28+
W504
29+
30+
# maximum length of any line (with some exceptions).
31+
max-line-length = 119
32+
33+
# Show the total number of errors in report.
34+
count = True
35+
36+
# Show number of occurrences of each error/warning code in report.
37+
statistics = True
38+
39+
# Comma-separate list of glob patterns to include for checks.
40+
filename =
41+
# include all python files
42+
*.py
43+
44+
exclude =
45+
# exclude the test folder
46+
test/,
47+
48+
# Maximum allowed McCabe complexity value for a block of code.
49+
max-complexity = 18
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
# Assume the role
4+
content=$(cat -)
5+
6+
# Dump creds in output file
7+
echo export AWS_ACCESS_KEY_ID="$(echo -e "$content" | jq -r '.Credentials.AccessKeyId')"
8+
echo export AWS_SECRET_ACCESS_KEY="$(echo -e "$content" | jq -r '.Credentials.SecretAccessKey')"
9+
echo export AWS_SESSION_TOKEN="$(echo -e "$content" | jq -r '.Credentials.SessionToken')"

0 commit comments

Comments
 (0)