Skip to content

Commit 61e7daa

Browse files
committed
Apply suggestions from review comments
1 parent 9387460 commit 61e7daa

File tree

2 files changed

+82
-60
lines changed

2 files changed

+82
-60
lines changed

opencti_rock/rockcraft.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ parts:
7575
- rustup
7676
override-build: |
7777
craftctl default
78-
cd opencti-platform/opencti-front//
78+
cd opencti-platform/opencti-front
7979
yarn install
8080
yarn build:standalone
8181
mkdir -p $CRAFT_PART_INSTALL/opt/opencti

src/charm.py

Lines changed: 81 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -178,57 +178,13 @@ def _reconcile_raw(self) -> None:
178178
"""
179179
self._init_peer_relation()
180180
self._check()
181-
worker_service: ops.pebble.ServiceDict = {
182-
"override": "replace",
183-
"command": "python3 worker.py",
184-
"working-dir": "/opt/opencti-worker",
185-
"environment": {
186-
"OPENCTI_URL": "http://localhost:8080",
187-
"OPENCTI_TOKEN": self._get_peer_secret(self._PEER_SECRET_ADMIN_TOKEN_SECRET_FIELD),
188-
"WORKER_LOG_LEVEL": "info",
189-
},
190-
"after": ["platform"],
191-
"requires": ["platform"],
192-
}
193181
health_check_token = self._get_peer_secret(
194182
self._PEER_SECRET_HEALTH_ACCESS_KEY_SECRET_FIELD
195183
)
196184
health_check_url = f"http://localhost:8080/health?health_access_key={health_check_token}"
197185
self._container.add_layer(
198186
"opencti",
199-
layer=ops.pebble.LayerDict(
200-
summary="OpenCTI platform/worker",
201-
description="OpenCTI platform/worker",
202-
services={
203-
"charm-callback": {
204-
"override": "replace",
205-
"command": f"bash {self._install_callback_script(health_check_url)}",
206-
},
207-
"platform": {
208-
"override": "replace",
209-
"command": "node build/back.js",
210-
"working-dir": "/opt/opencti",
211-
"environment": {
212-
"NODE_OPTIONS": "--max-old-space-size=8096",
213-
"NODE_ENV": "production",
214-
"PYTHONUNBUFFERED": "1",
215-
"APP__PORT": "8080",
216-
"APP__APP_LOGS__LOGS_LEVEL": "info",
217-
"PROVIDERS__LOCAL__STRATEGY": "LocalStrategy",
218-
"APP__TELEMETRY__METRICS__ENABLED": "true",
219-
**self._gen_secret_env(),
220-
**self._prepare_opensearch_env(),
221-
**self._gen_rabbitmq_env(),
222-
**self._gen_redis_env(),
223-
**self._gen_s3_env(),
224-
**self._gen_ingress_env(),
225-
},
226-
},
227-
"worker-0": worker_service,
228-
"worker-1": worker_service,
229-
"worker-2": worker_service,
230-
},
231-
),
187+
layer=self._gen_pebble_service_plan(health_check_url),
232188
combine=True,
233189
)
234190
self._container.replan()
@@ -241,27 +197,93 @@ def _reconcile_raw(self) -> None:
241197
self._container.stop("charm-callback")
242198
self._container.add_layer(
243199
label="opencti",
244-
layer=ops.pebble.LayerDict(
245-
summary="OpenCTI platform/worker",
246-
description="OpenCTI platform/worker",
247-
checks={
248-
"platform": {
249-
"override": "replace",
250-
"level": "ready",
251-
"http": {"url": health_check_url},
252-
"period": "1m",
253-
"timeout": "5s",
254-
"threshold": 5,
255-
}
256-
},
257-
),
200+
layer=self._gen_pebble_check_plan(health_check_url),
258201
combine=True,
259202
)
260203
self._container.replan()
261204
self._container.start("worker-0")
262205
self._container.start("worker-1")
263206
self._container.start("worker-2")
264207

208+
def _gen_pebble_service_plan(self, health_check_url: str) -> ops.pebble.LayerDict:
209+
"""Generate the service part of OpenCTI pebble plan.
210+
211+
Args:
212+
health_check_url: OpenCTI health check URL
213+
214+
Returns:
215+
The service part of OpenCTI pebble plan
216+
"""
217+
worker_service: ops.pebble.ServiceDict = {
218+
"override": "replace",
219+
"command": "python3 worker.py",
220+
"working-dir": "/opt/opencti-worker",
221+
"environment": {
222+
"OPENCTI_URL": "http://localhost:8080",
223+
"OPENCTI_TOKEN": self._get_peer_secret(self._PEER_SECRET_ADMIN_TOKEN_SECRET_FIELD),
224+
"WORKER_LOG_LEVEL": "info",
225+
},
226+
"after": ["platform"],
227+
"requires": ["platform"],
228+
}
229+
return ops.pebble.LayerDict(
230+
summary="OpenCTI platform/worker",
231+
description="OpenCTI platform/worker",
232+
services={
233+
"charm-callback": {
234+
"override": "replace",
235+
"command": f"bash {self._install_callback_script(health_check_url)}",
236+
},
237+
"platform": {
238+
"override": "replace",
239+
"command": "node build/back.js",
240+
"working-dir": "/opt/opencti",
241+
"environment": {
242+
"NODE_OPTIONS": "--max-old-space-size=8096",
243+
"NODE_ENV": "production",
244+
"PYTHONUNBUFFERED": "1",
245+
"APP__PORT": "8080",
246+
"APP__APP_LOGS__LOGS_LEVEL": "info",
247+
"PROVIDERS__LOCAL__STRATEGY": "LocalStrategy",
248+
"APP__TELEMETRY__METRICS__ENABLED": "true",
249+
**self._gen_secret_env(),
250+
**self._prepare_opensearch_env(),
251+
**self._gen_rabbitmq_env(),
252+
**self._gen_redis_env(),
253+
**self._gen_s3_env(),
254+
**self._gen_ingress_env(),
255+
},
256+
},
257+
"worker-0": worker_service,
258+
"worker-1": worker_service,
259+
"worker-2": worker_service,
260+
},
261+
)
262+
263+
def _gen_pebble_check_plan(self, health_check_url: str) -> ops.pebble.LayerDict:
264+
"""Generate the check part of OpenCTI pebble plan.
265+
266+
Args:
267+
health_check_url: OpenCTI health check URL
268+
269+
Returns:
270+
The check part of OpenCTI pebble plan
271+
"""
272+
return ops.pebble.LayerDict(
273+
summary="OpenCTI platform/worker",
274+
description="OpenCTI platform/worker",
275+
checks={
276+
"platform": {
277+
"override": "replace",
278+
"level": "ready",
279+
"http": {"url": health_check_url},
280+
"period": "1m",
281+
"timeout": "5s",
282+
"threshold": 5,
283+
}
284+
},
285+
)
286+
265287
def _install_callback_script(self, health_check_url: str) -> pathlib.Path:
266288
"""Install platform startup callback script for noticing the charm on start.
267289

0 commit comments

Comments
 (0)