<commit_before>// Copyright (C) 2020 <NAME>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

use std::net::SocketAddr;
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
use std::time::Duration;

use anyhow::Result;
use warp::filters::BoxedFilter;
use warp::{self, Filter, Future};

use crate::bookmark;
use crate::datastore::Datastore;
use crate::elastic;
use crate::eve::filters::EveBoxMetadataFilter;
use crate::eve::processor::Processor;
use crate::eve::EveReader;
use crate::logger::log;
use crate::server::session::Session;
use crate::server::AuthenticationType;
use crate::settings::Settings;
use crate::sqlite;
use crate::sqlite::configrepo::ConfigRepo;

use super::{ServerConfig, ServerContext};

pub async fn main(args: &clap::ArgMatches<'static>) -> Result<()> {
    crate::version::log_version();

    let mut settings = Settings::new(args);
    let mut config = ServerConfig::default();
    config.port = settings.get("http.port")?;
    config.host = settings.get("http.host")?;
    config.tls_enabled = settings.get_bool("http.tls.enabled")?;
    config.tls_cert_filename = settings.get_or_none("http.tls.certificate")?;
    config.tls_key_filename = settings.get_or_none("http.tls.key")?;
    config.datastore = settings.get("database.type")?;
    config.elastic_url = settings.get("database.elasticsearch.url")?;
    config.elastic_index = settings.get("database.elasticsearch.index")?;
    config.elastic_username = settings.get_or_none("database.elasticsearch.username")?;
    config.elastic_password = settings.get_or_none("database.elasticsearch.password")?;
    config.data_directory = settings.get_or_none("data-directory")?;
    config.database_retention_period = settings.get_or_none("database.retention-period")?;
    if let Ok(val) = settings.get_bool("database.elasticsearch.disable-certificate-check") {
        config.no_check_certificate = val;
    } else {
        config.no_check_certificate = settings.get_bool("no-check-certificate")?;
    }

    config.authentication_required = settings.get_bool("authentication.required")?;
    if config.authentication_required {
        if let Some(auth_type) = settings.get_or_none::<String>("authentication.type")? {
            config.authentication_type = match auth_type.as_ref() {
                "username" => AuthenticationType::Username,
                "usernamepassword" => AuthenticationType::UsernamePassword,
                _ => {
                    return Err(anyhow!("Bad authentication type: {}", auth_type));
                }<commit_msg>server: fix disabling of certificate check<commit_after>// Copyright (C) 2020 <NAME>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

use std::net::SocketAddr;
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
use std::time::Duration;

use anyhow::Result;
use warp::filters::BoxedFilter;
use warp::{self, Filter, Future};

use crate::bookmark;
use crate::datastore::Datastore;
use crate::elastic;
use crate::eve::filters::EveBoxMetadataFilter;
use crate::eve::processor::Processor;
use crate::eve::EveReader;
use crate::logger::log;
use crate::server::session::Session;
use crate::server::AuthenticationType;
use crate::settings::Settings;
use crate::sqlite;
use crate::sqlite::configrepo::ConfigRepo;

use super::{ServerConfig, ServerContext};

pub async fn main(args: &clap::ArgMatches<'static>) -> Result<()> {
    crate::version::log_version();

    let mut settings = Settings::new(args);
    let mut config = ServerConfig::default();
    config.port = settings.get("http.port")?;
    config.host = settings.get("http.host")?;
    config.tls_enabled = settings.get_bool("http.tls.enabled")?;
    config.tls_cert_filename = settings.get_or_none("http.tls.certificate")?;
    config.tls_key_filename = settings.get_or_none("http.tls.key")?;
    config.datastore = settings.get("database.type")?;
    config.elastic_url = settings.get("database.elasticsearch.url")?;
    config.elastic_index = settings.get("database.elasticsearch.index")?;
    config.elastic_username = settings.get_or_none("database.elasticsearch.username")?;
    config.elastic_password = settings.get_or_none("database.elasticsearch.password")?;
    config.data_directory = settings.get_or_none("data-directory")?;
    config.database_retention_period = settings.get_or_none("database.retention-period")?;
    if let Ok(val) = settings.get_bool("database.elasticsearch.disable-certificate-check") {
        if val {
            config.no_check_certificate = true;
        } else {
            config.no_check_certificate = settings.get_bool("no-check-certificate")?;
        }
    }

    config.authentication_required = settings.get_bool("authentication.required")?;
    if config.authentication_required {
        if let Some(auth_type) = settings.get_or_none::<String>("authentication.type")? {
            config.authentication_type = match auth_type.as_ref() {
                "username" => AuthenticationType::Username,
                "usernamepassword" => AuthenticationType::UsernamePassword,
                _ => {
                    return Err(anyhow!("Bad authentication type: {}", auth_type));
                }
{'fraction_non_alphanumeric': 0.1328015016424214, 'fraction_numerical': 0.001564210855623338, 'mean_word_length': 4.337228714524207, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3054448', 'n_tokens_mistral': 1814, 'n_tokens_neox': 1831, 'n_words': 447}