-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.py
More file actions
131 lines (107 loc) · 2.85 KB
/
Copy pathtasks.py
File metadata and controls
131 lines (107 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# @Author: michael
# @Date: 12-Jan-2018
# @Project: Blueberry
# @Filename: fabfile.py
# @Last modified by: michael
# @Last modified time: 09-Feb-2021
# @License: GNU GPL v3
from datetime import datetime, timedelta, timezone
from invoke import task
import config as cfg
import src.api.BDD as bdd
from src.plugins.carto.Ip import Ip
my_hosts = cfg.hosts
@task
def prepare_data_test(c):
"""Creer les data nécéssaires aux tests."""
offset = timezone(timedelta(hours=2))
date = datetime.now(offset).strftime("%Y-%m-%dT%H:%M:%S.%f%z")
c.run(
"sed 's/{DATE}/"
+ date
+ "/g' src/test/data/suricata-log.temp.json > src/test/data/suricata-log.json"
)
@task
def test(c):
"""Lance test unitaire."""
prepare_data_test(c)
result = c.run("python -m pytest", warn=True)
#
@task
def test_code(c):
"""Lance code security analyse."""
result = c.run("bandit -r ./ -x *config.py,*test*.py", warn=True)
@task
def install(c):
"""Install blueberry."""
config_service(c)
config_bdd()
c.run("mkdir log")
c.run("touch log/blueberry.log")
@task
def config_service(c):
"""Configure le service Blueberry."""
c.run(
'sed -e "s/{{{{dir}}}}/{}/g" ressources/blueberry.service >> /etc/systemd/system/blueberry.service'.format(
cfg.work_dir.replace("/", "\/")
)
)
c.run("chown root: /etc/systemd/system/blueberry.service", warn=True)
def config_bdd():
"""Permet l'installation de la BDD automatise."""
try:
var = bdd.db.connect
bdd.db.create_tables([Ip])
except Exception as e:
print("=== La base SQL existe déjà ===")
print(e)
# @task(hosts=my_hosts)
# def uninstall(c):
# c.run("systemctl stop blueberry")
# c.run("rm /etc/systemd/system/blueberry.service")
#
# @task
# def commit(c):
# """Git commit."""
# c.run("git commit")
#
#
# @task
# def push(c):
# """Git push."""
# c.run("git push")
#
#
# @task
# def prepare_deploy(c):
# """Test + commit + push."""
# test(c)
# test_code(c)
# commit(c)
# push(c)
#
# @task(hosts=my_hosts)
# def deploy(c):
# """Deploy sur le serveur."""
# # prepare_deploy()
# code_dir = cfg.hosts_dir
# command = "sudo sh -c 'cd {} && git pull'".format(code_dir)
# command2 = "chown -R blueberry: {}".format(code_dir)
# c.run(command, pty=True)
# c.run(command2, pty=True)
# c.run('sudo systemctl restart blueberry', warn=True, pty=True)
#
# @task(hosts=my_hosts)
# def stop_server(c):
# """Stop le serveur."""
# c.run("sudo systemctl stop blueberry", warn=True, pty=True)
@task
def start_local(c):
"""Demarre en local."""
commande = "python3 main.py"
c.run(commande, pty=True)
#
# @task(hosts=my_hosts)
# def start_server(c):
# """Start le serveur."""
# c.run('sudo systemctl start blueberry', warn=True, pty=True)