qredisclient
connectionconfig.h
1 #pragma once
2 #include <QString>
3 #include <QList>
4 #include <QVariantHash>
5 #include <QJsonObject>
6 #include <QSslCertificate>
7 
8 namespace RedisClient {
9 
10 class Connection;
11 
17 {
18 public:
19  static const uint DEFAULT_REDIS_PORT = 6379;
20  static const uint DEFAULT_SSH_PORT = 22;
21  static const uint DEFAULT_TIMEOUT_IN_MS = 60000;
22 
23 public:
30  ConnectionConfig(const QString & host = "", const QString & auth = "",
31  const uint port = DEFAULT_REDIS_PORT, const QString & name = "");
32  ConnectionConfig & operator = (const ConnectionConfig & other);
33  ConnectionConfig(const QVariantHash& options);
34 
35  QString name() const;
36  QString host() const;
37  QString auth() const;
38  uint port() const;
39 
40  void setName(QString name);
41  void setAuth(QString auth);
42  void setHost(QString host);
43  void setPort(uint port);
44 
45  bool isNull() const;
46  bool useAuth() const;
47  bool isValid() const;
48 
49  /*
50  * Timeouts in ms
51  */
52  uint executeTimeout() const;
53  uint connectionTimeout() const;
54 
55  void setExecutionTimeout(uint timeout);
56  void setConnectionTimeout(uint timeout);
57  void setTimeouts(uint connectionTimeout, uint commandExecutionTimeout);
58 
59  /*
60  * SSL settings
61  * NOTE: SSL over SSH tunnel is not supported!
62  */
63  bool useSsl() const;
64  void setSsl(bool enabled);
65  QList<QSslCertificate> sslCaCertificates() const;
66  QString sslCaCertPath() const;
67  QString sslPrivateKeyPath() const;
68  QString sslLocalCertPath() const;
69 
70  void setSslCaCertPath(QString path);
71  void setSslPrivateKeyPath(QString path);
72  void setSslLocalCertPath(QString path);
73  void setSslSettigns(QString sslCaCertPath,
74  QString sslPrivateKeyPath = "",
75  QString sslLocalCertPath = "");
76 
77  /*
78  * SSH Tunnel settings
79  */
80  bool useSshTunnel() const;
81  bool isSshPasswordUsed() const;
82  QString sshPassword() const;
83  QString sshUser() const;
84  QString sshHost() const;
85  uint sshPort() const;
86 
91  QString getSshPrivateKey() const;
92  QString getSshPrivateKeyPath() const;
93 
94  void setSshPassword(QString pass);
95  void setSshHost(QString host);
96  void setSshPrivateKeyPath(QString path);
97  void setSshUser(QString user);
98  void setSshPort(uint port);
99 
108  void setSshTunnelSettings(QString host, QString user, QString pass,
109  uint port = DEFAULT_SSH_PORT,
110  QString sshPrivatekeyPath = "");
111 
112  /*
113  * Convert config to JSON
114  */
115  QJsonObject toJsonObject();
116  static ConnectionConfig fromJsonObject(const QJsonObject& config);
117 
118  /*
119  * Following methods used internally in Connection class
120  */
121  QWeakPointer<Connection> getOwner() const;
122  void setOwner(QWeakPointer<Connection>);
123 
124  QVariantHash getInternalParameters() const;
125 
126 protected:
127  /*
128  * Extension API
129  * Use following methods to implement custom wrappers
130  * around ConnectionConfig class
131  */
132  template <class T> inline T param(const QString& p) const
133  {
134  if (m_parameters.contains(p)) return m_parameters[p].value<T>();
135  return T();
136  }
137 
138  template <class T> inline void setParam(const QString& key, T p)
139  {
140  m_parameters.insert(key, p);
141  }
142 
143  QString getValidPathFromParameter(const QString& param) const;
144 
145 protected:
146  QWeakPointer<Connection> m_owner;
147  QVariantHash m_parameters;
148 };
149 }
Definition: command.h:8
QString getSshPrivateKey() const
getSshPrivateKey from specified path
Definition: connectionconfig.cpp:230
The ConnectionConfig class Supports loading settigns from JSON objects.
Definition: connectionconfig.h:16
ConnectionConfig(const QString &host="", const QString &auth="", const uint port=DEFAULT_REDIS_PORT, const QString &name="")
Default constructor for local connections.
Definition: connectionconfig.cpp:5
void setSshTunnelSettings(QString host, QString user, QString pass, uint port=DEFAULT_SSH_PORT, QString sshPrivatekeyPath="")
setSshTunnelSettings - Set SSH settings
Definition: connectionconfig.cpp:174