Skip to content

Commit ff5e3b1

Browse files
committed
user config
1 parent d36918d commit ff5e3b1

File tree

3 files changed

+79
-12
lines changed

3 files changed

+79
-12
lines changed

src/baskerville/models/config.py

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,13 @@ class BaskervilleConfig(Config):
182182
- kafka : optional - depends on the chosen pipeline
183183
184184
"""
185-
database = None
186-
elastic = None
187-
misp = None
188-
engine = None
189-
kafka = None
190-
spark = None
185+
database: 'DatabaseConfig' = None
186+
elastic: 'ElasticConfig' = None
187+
misp: 'MispConfig' = None
188+
engine: 'EngineConfig' = None
189+
kafka: 'KafkaConfig' = None
190+
spark: 'SparkConfig' = None
191+
user_details: 'UserDetailsConfig' = None
191192

192193
def __init__(self, config):
193194
super(BaskervilleConfig, self).__init__(config)
@@ -203,6 +204,8 @@ def __init__(self, config):
203204
self.kafka = KafkaConfig(self.kafka)
204205
if self.spark:
205206
self.spark = SparkConfig(self.spark)
207+
if self.user_details:
208+
self.user_details = UserDetailsConfig(self.user_details)
206209

207210
def validate(self):
208211
logger.debug('Validating BaskervilleConfig...')
@@ -226,6 +229,10 @@ def validate(self):
226229
self.spark.validate()
227230
else:
228231
logger.debug('No spark config')
232+
if self.user_details:
233+
self.user_details.validate()
234+
else:
235+
logger.error('No user_details config')
229236

230237
self._is_validated = True
231238
self._is_valid = len(self.errors) == 0
@@ -961,9 +968,6 @@ class DataParsingConfig(Config):
961968
group_by_cols = ('client_request_host', 'client_ip')
962969
timestamp_column = '@timestamp'
963970

964-
def __init__(self, config_dict):
965-
super().__init__(config_dict)
966-
967971
def validate(self):
968972
logger.debug('Validating DataParsingConfig...')
969973
from baskerville.models.log_parsers import LOG_PARSERS
@@ -994,3 +998,31 @@ def validate(self):
994998

995999
self._is_validated = True
9961000
return self
1001+
1002+
1003+
class UserDetailsConfig(Config):
1004+
username = ''
1005+
password = ''
1006+
organization_uuid = ''
1007+
1008+
def validate(self):
1009+
logger.debug('Validating UserDetailsConfig...')
1010+
if not self.username:
1011+
self.add_error(ConfigError(
1012+
f'Please, provide a username',
1013+
['username'],
1014+
exception_type=ValueError
1015+
))
1016+
if not self.password:
1017+
self.add_error(ConfigError(
1018+
f'Please, provide a password',
1019+
['password'],
1020+
exception_type=ValueError
1021+
))
1022+
if not self.organization_uuid:
1023+
self.add_error(ConfigError(
1024+
f'Please, provide an organization_uuid',
1025+
['organization_uuid'],
1026+
exception_type=ValueError
1027+
))
1028+

src/baskerville/models/pipeline_tasks/service_provider.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,23 @@ def refresh_model(self):
7878
self.load_model_from_db()
7979

8080
def create_runtime(self):
81+
from baskerville.db.dashboard_models import User, Organization
82+
org = self.tools.session.query(Organization).filter_by(
83+
uuid=self.config.user_details.organization_uuid
84+
).first()
85+
if not org:
86+
raise ValueError(f'No such organization.')
87+
88+
user = self.tools.session.query(User).filter_by(
89+
username=self.config.user_details.username).filter_by(
90+
id_organization=org.id
91+
).first()
92+
if not user:
93+
raise ValueError(f'No such user.')
8194
self.runtime = self.tools.create_runtime(
8295
start=self.start_time,
83-
conf=self.config.engine
96+
conf=self.config.engine,
97+
id_user=user.id
8498
)
8599
self.logger.info(f'Created runtime {self.runtime.id}')
86100

src/baskerville/models/pipeline_tasks/setup_pipeline.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,33 @@
1414
GetDataLog, Predict, Challenge
1515

1616

17-
def set_up_preprocessing_pipeline(config: BaskervilleConfig):
17+
def set_up_registration_pipeline(config: BaskervilleConfig):
1818
task = [
1919
GetDataKafka(
2020
config,
2121
steps=[
22-
GenerateFeatures(config),
22+
Register(config),
23+
CacheSensitiveData(config),
24+
SendToKafka(
25+
config=config,
26+
columns=('id_client', 'uuid_request_set', 'features'),
27+
topic=config.kafka.features_topic,
28+
),
29+
RefreshCache(config)
30+
]),
31+
]
32+
33+
main_task = Task(config, task)
34+
main_task.name = 'Preprocessing Pipeline'
35+
return main_task
36+
37+
38+
def set_up_user_creation_pipeline(config: BaskervilleConfig):
39+
task = [
40+
GetDataKafka(
41+
config,
42+
steps=[
43+
Register(config),
2344
CacheSensitiveData(config),
2445
SendToKafka(
2546
config=config,

0 commit comments

Comments
 (0)