// todo: remove or add clone support ConnectionSettings::ConnectionSettings(const mongo::MongoURI& uri, bool isClone) : _connectionName(defaultNameConnection), _host(defaultServerHost), _port(port), _imported(false), _sshSettings(new SshSettings()), _sslSettings(new SslSettings()), _isReplicaSet((uri.type() == mongo::ConnectionString::ConnectionType::SET)), _replicaSetSettings(new ReplicaSetSettings(uri)), _clone(isClone), _uuid(QUuid::createUuid().toString()) // todo { if (!uri.getServers().empty()) { _host = uri.getServers().front().host(); _port = uri.getServers().front().port(); } auto str = std::string(uri.getOptions().getStringField("ssl")); auto sslEnabled = ("true" == str); if (sslEnabled) { _sslSettings->enableSSL(true); _sslSettings->setAllowInvalidCertificates(true); } auto credential = new CredentialSettings(); credential->setUserName(uri.getUser()); credential->setUserPassword(uri.getPassword()); credential->setDatabaseName(uri.getDatabase()); if (!credential->userName().empty() && !credential->userPassword().empty()) { // todo: credential->setEnabled(true); } addCredential(credential); }
ConnectionSettings::ConnectionSettings(QVariantMap map) : QObject(), _serverPort(map.value("serverPort").toInt()), _serverHost(QtUtils::toStdString<std::string>(map.value("serverHost").toString())), _defaultDatabase(QtUtils::toStdString<std::string>(map.value("defaultDatabase").toString())), _connectionName(QtUtils::toStdString<std::string>(map.value("connectionName").toString())) { QVariantList list = map.value("credentials").toList(); foreach(QVariant var, list) { CredentialSettings *credential = new CredentialSettings(var.toMap()); addCredential(credential); }
/** * Discards current state and applies state from 'source' ConnectionSettings. */ void ConnectionSettings::apply(const ConnectionSettings *source) { setConnectionName(source->connectionName()); setServerHost(source->serverHost()); setServerPort(source->serverPort()); setDefaultDatabase(source->defaultDatabase()); setImported(source->imported()); setReplicaSet(source->isReplicaSet()); clearCredentials(); QList<CredentialSettings *> cred = source->credentials(); for (QList<CredentialSettings *>::iterator it = cred.begin(); it != cred.end(); ++it) { addCredential((*it)->clone()); } _sshSettings.reset(source->sshSettings()->clone()); _sslSettings.reset(source->sslSettings()->clone()); _replicaSetSettings.reset(source->_replicaSetSettings->clone()); //#ifdef MONGO_SSL // setSslInfo(source->sslInfo()); //#endif }
void ConnectionSettings::fromVariant(const QVariantMap &map) { setConnectionName(QtUtils::toStdString(map.value("connectionName").toString())); setServerHost(QtUtils::toStdString(map.value("serverHost").toString().left(maxLength))); setServerPort(map.value("serverPort").toInt()); setDefaultDatabase(QtUtils::toStdString(map.value("defaultDatabase").toString())); setReplicaSet(map.value("isReplicaSet").toBool()); QVariantList list = map.value("credentials").toList(); for (QVariantList::const_iterator it = list.begin(); it != list.end(); ++it) { QVariant var = *it; CredentialSettings *credential = new CredentialSettings(var.toMap()); addCredential(credential); } if (map.contains("ssh")) { _sshSettings->fromVariant(map.value("ssh").toMap()); } if (map.contains("ssl")) { _sslSettings->fromVariant(map.value("ssl").toMap()); } if (isReplicaSet()) { _replicaSetSettings->fromVariant(map.value("replicaSet").toMap()); } // If UUID has never been created or is empty, create a new one. Otherwise load the existing. if (!map.contains("uuid") || map.value("uuid").toString().isEmpty()) _uuid = QUuid::createUuid().toString(); else _uuid = map.value("uuid").toString(); //#ifdef MONGO_SSL // ,SSLInfo(map.value("sslEnabled").toBool(),QtUtils::toStdString(map.value("sslPemKeyFile").toString())) //#endif }