forked from p15670423/monkey
Merge pull request #2012 from guardicore/1999-remove-send-config-error
1999 remove send config error
This commit is contained in:
commit
825f559370
|
@ -14,7 +14,6 @@ HIDDEN_FIELD_REPLACEMENT_CONTENT = "hidden"
|
||||||
|
|
||||||
class Configuration(object):
|
class Configuration(object):
|
||||||
def from_kv(self, formatted_data):
|
def from_kv(self, formatted_data):
|
||||||
unknown_items = []
|
|
||||||
for key, value in list(formatted_data.items()):
|
for key, value in list(formatted_data.items()):
|
||||||
if key.startswith("_"):
|
if key.startswith("_"):
|
||||||
continue
|
continue
|
||||||
|
@ -22,11 +21,8 @@ class Configuration(object):
|
||||||
continue
|
continue
|
||||||
if hasattr(self, key):
|
if hasattr(self, key):
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
else:
|
|
||||||
unknown_items.append(key)
|
|
||||||
if not self.max_depth:
|
if not self.max_depth:
|
||||||
self.max_depth = self.depth
|
self.max_depth = self.depth
|
||||||
return unknown_items
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def hide_sensitive_info(config_dict):
|
def hide_sensitive_info(config_dict):
|
||||||
|
|
|
@ -185,7 +185,7 @@ class ControlClient(object):
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
unknown_variables = WormConfiguration.from_kv(reply.json().get("config"))
|
WormConfiguration.from_kv(reply.json().get("config"))
|
||||||
formatted_config = pformat(
|
formatted_config = pformat(
|
||||||
WormConfiguration.hide_sensitive_info(WormConfiguration.as_dict())
|
WormConfiguration.hide_sensitive_info(WormConfiguration.as_dict())
|
||||||
)
|
)
|
||||||
|
@ -200,28 +200,6 @@ class ControlClient(object):
|
||||||
)
|
)
|
||||||
raise Exception("Couldn't load from from server's configuration, aborting. %s" % exc)
|
raise Exception("Couldn't load from from server's configuration, aborting. %s" % exc)
|
||||||
|
|
||||||
if unknown_variables:
|
|
||||||
ControlClient.send_config_error()
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def send_config_error():
|
|
||||||
if not WormConfiguration.current_server:
|
|
||||||
return
|
|
||||||
try:
|
|
||||||
requests.patch( # noqa: DUO123
|
|
||||||
f"https://{WormConfiguration.current_server}/api/agent/{GUID}",
|
|
||||||
data=json.dumps({"config_error": True}),
|
|
||||||
headers={"content-type": "application/json"},
|
|
||||||
verify=False,
|
|
||||||
proxies=ControlClient.proxies,
|
|
||||||
timeout=MEDIUM_REQUEST_TIMEOUT,
|
|
||||||
)
|
|
||||||
except Exception as exc:
|
|
||||||
logger.warning(
|
|
||||||
"Error connecting to control server %s: %s", WormConfiguration.current_server, exc
|
|
||||||
)
|
|
||||||
return {}
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_control_tunnel():
|
def create_control_tunnel():
|
||||||
if not WormConfiguration.current_server:
|
if not WormConfiguration.current_server:
|
||||||
|
|
|
@ -51,7 +51,6 @@ class Monkey(Document):
|
||||||
# (even with required=False of null=True).
|
# (even with required=False of null=True).
|
||||||
# See relevant issue: https://github.com/MongoEngine/mongoengine/issues/1904
|
# See relevant issue: https://github.com/MongoEngine/mongoengine/issues/1904
|
||||||
parent = ListField(ListField(DynamicField()))
|
parent = ListField(ListField(DynamicField()))
|
||||||
config_error = BooleanField()
|
|
||||||
critical_services = ListField(StringField())
|
critical_services = ListField(StringField())
|
||||||
pba_results = ListField()
|
pba_results = ListField()
|
||||||
ttl_ref = ReferenceField(MonkeyTtl)
|
ttl_ref = ReferenceField(MonkeyTtl)
|
||||||
|
|
|
@ -27,29 +27,6 @@ class Monkey(AbstractResource):
|
||||||
def get(self):
|
def get(self):
|
||||||
return {"config": ConfigService.format_flat_config_for_agent()}
|
return {"config": ConfigService.format_flat_config_for_agent()}
|
||||||
|
|
||||||
# Used by monkey. can't secure.
|
|
||||||
@TestTelemStore.store_exported_telem
|
|
||||||
def patch(self, guid):
|
|
||||||
|
|
||||||
# TODO: This endpoint appears to be doing 3 things, although only one of them is used
|
|
||||||
# (config_error). The WormConfiguration will be removed in #1960. We should consider
|
|
||||||
# removing this endpoint
|
|
||||||
monkey_json = json.loads(request.data)
|
|
||||||
update = {"$set": {"modifytime": datetime.now()}}
|
|
||||||
monkey = NodeService.get_monkey_by_guid(guid)
|
|
||||||
if "config_error" in monkey_json:
|
|
||||||
update["$set"]["config_error"] = monkey_json["config_error"]
|
|
||||||
|
|
||||||
if "tunnel" in monkey_json:
|
|
||||||
tunnel_host_ip = monkey_json["tunnel"].split(":")[-2].replace("//", "")
|
|
||||||
NodeService.set_monkey_tunnel(monkey["_id"], tunnel_host_ip)
|
|
||||||
|
|
||||||
ttl = create_monkey_ttl_document(DEFAULT_MONKEY_TTL_EXPIRY_DURATION_IN_SECONDS)
|
|
||||||
update["$set"]["ttl_ref"] = ttl.id
|
|
||||||
|
|
||||||
# API Spec: What is this returning? Check that it follows rules.
|
|
||||||
return mongo.db.monkey.update({"_id": monkey["_id"]}, update, upsert=False)
|
|
||||||
|
|
||||||
# Used by monkey. can't secure.
|
# Used by monkey. can't secure.
|
||||||
# Called on monkey wakeup to initialize local configuration
|
# Called on monkey wakeup to initialize local configuration
|
||||||
@TestTelemStore.store_exported_telem
|
@TestTelemStore.store_exported_telem
|
||||||
|
|
Loading…
Reference in New Issue