def try_update()

in connectors/agent/config.py [0:0]


    def try_update(self, connector_id, service_type, output_unit):
        """Try update the configuration and see if it changed.

        This method takes the check-in event data (connector_id, service_type and output) coming
        from Agent and checks if config needs an update.

        If update is needed, configuration is updated and method returns True. If no update is needed
        the method returns False.
        """

        source = output_unit.config.source

        # TODO: find a good link to what this object is.
        has_hosts = source.fields.get("hosts")
        has_api_key = source.fields.get("api_key")
        has_basic_auth = source.fields.get("username") and source.fields.get("password")

        assumed_configuration = {}

        # Connector-related
        assumed_configuration["connectors"] = [
            {
                "connector_id": connector_id,
                "service_type": service_type,
            }
        ]

        # Log-related
        assumed_configuration["service"] = {}
        assumed_configuration["service"]["log_level"] = output_unit.log_level

        # Auth-related
        if has_hosts and (has_api_key or has_basic_auth):
            es_creds = {"host": source["hosts"][0]}

            if source.fields.get("api_key"):
                logger.debug("Found api_key")
                api_key = source["api_key"]
                # if beats_logstash_format we need to base64 the key
                if ":" in api_key:
                    api_key = base64.b64encode(api_key.encode()).decode()

                es_creds["api_key"] = api_key
            elif source.fields.get("username") and source.fields.get("password"):
                logger.debug("Found username and passowrd")
                es_creds["username"] = source["username"]
                es_creds["password"] = source["password"]
            else:
                msg = "Invalid Elasticsearch credentials"
                raise ValueError(msg)

            assumed_configuration["elasticsearch"] = es_creds

        if self.config_changed(assumed_configuration):
            logger.debug("Changes detected for connectors-relevant configurations")
            # This is a partial update.
            # Agent can send different data in updates.
            # For example, updating only log_level will not send credentials.
            # Thus we don't overwrite configuration, we only update fields that
            # were received
            self.specific_config.update(assumed_configuration)
            return True

        logger.debug("No changes detected for connectors-relevant configurations")
        return False