Skip to content

Commit

Permalink
feat: add support for SSL connection.
Browse files Browse the repository at this point in the history
Close #41
  • Loading branch information
luin committed Dec 4, 2016
1 parent 99d2757 commit ca29384
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
3 changes: 3 additions & 0 deletions client/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ const actions = {
dispatch({ type: 'updateConnectStatus', data: 'Redis connecting...' });
if (config.ssl) {
config.tls = {
ca: config.ca,
key: config.key,
cert: config.cert
}
}
const redis = new Redis(_.assign({}, config, override, {
Expand Down
44 changes: 38 additions & 6 deletions client/components/main/Main/ConnectionSelector/Config.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ class Config extends React.Component {
if (!this.props.connect && nextProps.connect) {
this.connect();
}
const leaving =
(!this.props.favorite && nextProps.favorite) ||
(this.props.favorite && !nextProps.favorite) ||
(this.props.favorite.get('key') !== nextProps.favorite.get('key'));
if (leaving) {
this.setState({ changed: false, data: new Immutable.Map() });
if (this.props.favorite || nextProps.favorite) {
const leaving = !this.props.favorite || !nextProps.favorite ||
(this.props.favorite.get('key') !== nextProps.favorite.get('key'));
if (leaving) {
this.setState({ changed: false, data: new Immutable.Map() });
}
}
}

Expand Down Expand Up @@ -81,6 +81,33 @@ class Config extends React.Component {
}
}

renderCertInput(label, id) {
return <div className="nt-form-row">
<label htmlFor="cert">{label}:</label>
<input
type="text"
id={id}
readOnly={true}
value={this.getProp(`${id}File`)}
placeholder={`Select ${label} File (PEM)`}
/>
<button
className={'icon icon-dot-3 ssh-key'}
onClick={() => {
const win = remote.getCurrentWindow();
const files = remote.require('dialog').showOpenDialog(win, {
properties: ['openFile']
});
if (files && files.length) {
const file = files[0];
const content = fs.readFileSync(file, 'utf8');
this.setProp({ [id]: content, [`${id}File`]: file });
}
}}
></button>
</div>
}

render() {
return <div>
<div className="nt-box" style={ { width: 500, margin: '60px auto 0' } }>
Expand All @@ -104,6 +131,11 @@ class Config extends React.Component {
<label htmlFor="ssh">SSL:</label>
<input type="checkbox" id="ssl" onChange={this.handleChange.bind(this, 'ssl')} checked={this.getProp('ssl')} />
</div>
<div style={ { display: this.getProp('ssl') ? 'block' : 'none' } }>
{this.renderCertInput('Private Key', 'key')}
{this.renderCertInput('Certificate', 'cert')}
{this.renderCertInput('CA', 'ca')}
</div>
<div className="nt-form-row">
<label htmlFor="ssh">SSH Tunnel:</label>
<input type="checkbox" id="ssh" onChange={this.handleChange.bind(this, 'ssh')} checked={this.getProp('ssh')} />
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"form-generator-react": "^1.0.5",
"human-format": "^0.5.0",
"immutable": "^3.8.1",
"ioredis": "^1.11.1",
"ioredis": "^2.4.2",
"jquery": "^2.1.4",
"json-editor": "^0.7.23",
"jsonlint": "^1.6.2",
Expand Down

1 comment on commit ca29384

@camdenorrb
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you :3

Please sign in to comment.