1212 PodmanMount ,
1313 PodmanMountType ,
1414)
15+ from interactem .core .nats .config import NatsMode , get_nats_config
1516
1617from ._vector_template import VECTOR_CONFIG_TEMPLATE
1718
1819logger = get_logger ()
20+ VECTOR_NATS_CREDS_TARGET = "/nats.creds"
1921
2022
2123class Settings (BaseSettings ):
@@ -43,7 +45,7 @@ class Settings(BaseSettings):
4345 ALWAYS_PULL_IMAGES : bool = False
4446
4547 # Vector configuration
46- VECTOR_AGGREGATOR_ADDR : str | None = None
48+ VECTOR_ENABLED : bool = True
4749 LOG_DIR : Path = Path ("~/.interactem/logs" ).expanduser ().resolve ()
4850 VECTOR_CONFIG_PATH : Path | None = None
4951 OPERATOR_EXTRA_ENV : dict [str , str ] = Field (default_factory = dict , exclude = True )
@@ -125,15 +127,40 @@ def vector_mounts(self) -> list[PodmanMount]:
125127 target = "/etc/vector/vector.yaml" ,
126128 )
127129 log_mount = self .log_mount
130+ mounts = [config_mount ]
128131 if log_mount :
129- return [config_mount , log_mount ]
130- return [config_mount ]
132+ mounts .append (log_mount )
133+ creds_mount = self .vector_creds_mount
134+ if creds_mount :
135+ mounts .append (creds_mount )
136+ return mounts
137+
138+ @property
139+ def vector_creds_mount (self ) -> PodmanMount | None :
140+ creds_path = self .nats_creds_file
141+ if not creds_path :
142+ return None
143+ return PodmanMount (
144+ type = PodmanMountType .bind ,
145+ source = str (creds_path ),
146+ target = VECTOR_NATS_CREDS_TARGET ,
147+ )
148+
149+ @property
150+ def nats_creds_file (self ) -> Path | None :
151+ try :
152+ nats_cfg = get_nats_config ()
153+ except ValueError :
154+ return None
155+ if nats_cfg .NATS_SECURITY_MODE != NatsMode .CREDS :
156+ return None
157+ return nats_cfg .NATS_CREDS_FILE
131158
132159 def generate_vector_config (self ) -> Path | None :
133160 """Generates a vector config file and returns path to it"""
134161
135- if not self .VECTOR_AGGREGATOR_ADDR :
136- logger .warning ("VECTOR_AGGREGATOR_ADDR not set , skipping log aggregation." )
162+ if not self .VECTOR_ENABLED :
163+ logger .warning ("VECTOR_ENABLED is false , skipping log aggregation." )
137164 return None
138165
139166 if not self .LOG_DIR .exists ():
@@ -144,7 +171,8 @@ def generate_vector_config(self) -> Path | None:
144171 vector_yaml = templ .render (
145172 logs_dir = LOGS_DIR_IN_CONTAINER ,
146173 agent_id = self .ID ,
147- vector_addr = self .VECTOR_AGGREGATOR_ADDR ,
174+ nats_url = str (self .NATS_SERVER_URL_IN_CONTAINER ),
175+ nats_creds_path = VECTOR_NATS_CREDS_TARGET ,
148176 )
149177 output_path = self .LOG_DIR / "vector.yaml"
150178 with open (output_path , "w" ) as f :
0 commit comments