Skip to content

Commit 6762416

Browse files
committed
feat: [config] etcd connection add button size
1 parent c1bb44d commit 6762416

File tree

8 files changed

+79
-4
lines changed

8 files changed

+79
-4
lines changed

Diff for: .gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,7 @@ bin/
4545
### Fleet ###
4646
.fleet/
4747
/.fleet/settings.json
48+
49+
### Etcd Demo ###
50+
**/*.csr
51+
**/*.pem

Diff for: assets/etcd/Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.PHONY: run members
2+
3+
run:
4+
docker compose up -d
5+
members:
6+
etcdctl --endpoints=https://127.0.0.1:42379 --user root --password hillstone --cacert assets/etcd/cfssl/ca.pem --key assets/etcd/cfssl/client-key.pem --cert assets/etcd/cfssl/client.pem member list

Diff for: assets/etcd/Readme.md

+13-3
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,33 @@
44

55
### Download cfssl
66

7+
#### Linux
8+
79
```bash
810
mkdir ~/bin
911
curl -s -L -o ~/bin/cfssl https://pkg.cfssl.org/R1.2/cfssl_linux-amd64
1012
curl -s -L -o ~/bin/cfssljson https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64
1113
chmod +x ~/bin/{cfssl,cfssljson}
14+
export PATH=$PATH:~/bin
15+
```
16+
17+
#### Mac
18+
19+
```bash
20+
brew install cfssl
1221
```
1322

1423
### Generate CA
1524

1625
```bash
17-
export PATH=$PATH:~/bin
18-
mkdir ~/cfssl
19-
cd ~/cfssl
26+
mkdir cfssl
27+
cd cfssl
2028
cfssl print-defaults config > ca-config.json
2129
cfssl print-defaults csr > ca-csr.json
2230
```
2331

32+
###
33+
2434
# Refer
2535

2636
https://blog.try-except.com/technology/docker_etcd_cluster_ssl.html

Diff for: assets/etcd/docker-compose.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
version: '2'
2+
3+
services:
4+
node1:
5+
image: 'bitnami/etcd:latest'
6+
environment:
7+
- "ETCD_NAME=node1"
8+
- "ETCD_ROOT_PASSWORD=hillstone"
9+
- "ETCD_CLIENT_CERT_AUTH=true"
10+
- "ETCD_PEER_CLIENT_CERT_AUTH=true"
11+
- "ETCD_ADVERTISE_CLIENT_URLS=https://192.168.0.81:42379"
12+
- "ETCD_INITIAL_ADVERTISE_PEER_URLS=https://192.168.0.81:42380"
13+
- "ETCD_LISTEN_CLIENT_URLS=https://0.0.0.0:2379"
14+
- "ETCD_LISTEN_PEER_URLS=https://0.0.0.0:2380"
15+
- "ETCD_INITIAL_CLUSTER_TOKEN=etcd_cluster"
16+
- "ETCD_INITIAL_CLUSTER=node1=https://192.168.0.81:42380"
17+
- "ETCD_INITIAL_CLUSTER_STATE=new"
18+
- "ETCD_DATA_DIR=/opt/bitnami/etcd/data"
19+
- "ETCD_TRUSTED_CA_FILE=/opt/bitnami/etcd/conf/ca.pem"
20+
- "ETCD_KEY_FILE=/opt/bitnami/etcd/conf/server-key.pem"
21+
- "ETCD_CERT_FILE=/opt/bitnami/etcd/conf/server.pem"
22+
- "ETCD_PEER_TRUSTED_CA_FILE=/opt/bitnami/etcd/conf/ca.pem"
23+
- "ETCD_PEER_KEY_FILE=/opt/bitnami/etcd/conf/peer-key.pem"
24+
- "ETCD_PEER_CERT_FILE=/opt/bitnami/etcd/conf/peer.pem"
25+
volumes:
26+
- ./cfssl/ca.pem:/opt/bitnami/etcd/conf/ca.pem
27+
- ./cfssl/node1.pem:/opt/bitnami/etcd/conf/peer.pem
28+
- ./cfssl/node1-key.pem:/opt/bitnami/etcd/conf/peer-key.pem
29+
- ./cfssl/server.pem:/opt/bitnami/etcd/conf/server.pem
30+
- ./cfssl/server-key.pem:/opt/bitnami/etcd/conf/server-key.pem
31+
- ./cfssl/client-key.pem:/opt/bitnami/etcd/client-key.pem
32+
- ./cfssl/client.pem:/opt/bitnami/etcd/client.pem
33+
ports:
34+
- "42379:2379"
35+
- "42380:2380"

Diff for: src/main/kotlin/com/github/tsonglew/etcdhelper/client/impl/EtcdClient.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class EtcdClient(
6464

6565
try {
6666
val clientBuilder = Client.builder().endpoints(*etcdUrls!!)
67-
if (user.isNotEmpty() && password?.isNotEmpty() == true) {
67+
if (etcdConnectionInfo.enableAuth == true) {
6868
clientBuilder.user(bytesOf(user)).password(bytesOf(password))
6969
}
7070
client = clientBuilder.build()

Diff for: src/main/kotlin/com/github/tsonglew/etcdhelper/common/EtcdConnectionInfo.kt

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import java.util.*
3434
data class EtcdConnectionInfo(
3535
var endpoints: String,
3636
var username: String,
37+
var enableAuth: Boolean? = false,
3738
var id: String? = null,
3839
var name: String? = null,
3940
var tlsEnabled: Boolean? = false,
@@ -56,6 +57,7 @@ data class EtcdConnectionInfo(
5657
fun update(etcdConnectionInfo: EtcdConnectionInfo): EtcdConnectionInfo {
5758
endpoints = etcdConnectionInfo.endpoints
5859
username = etcdConnectionInfo.username
60+
enableAuth = etcdConnectionInfo.enableAuth
5961
name = etcdConnectionInfo.name
6062
tlsEnabled = etcdConnectionInfo.tlsEnabled
6163
tlsClientCert = etcdConnectionInfo.tlsClientCert

Diff for: src/main/kotlin/com/github/tsonglew/etcdhelper/component/ConnectionHostPortRowPanel.kt

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.github.tsonglew.etcdhelper.component
22

33
import com.intellij.icons.AllIcons
44
import com.intellij.ui.components.JBTextField
5+
import java.awt.Dimension
56
import java.awt.FlowLayout
67
import javax.swing.JButton
78
import javax.swing.JLabel
@@ -18,6 +19,7 @@ class ConnectionHostPortRowPanel(
1819
private val hostInputText = JBTextField(host, 15)
1920
private val portInputText = JBTextField(port, 5)
2021
private val addRowBtn = JButton(AllIcons.General.Add).also {
22+
it.preferredSize = Dimension(30, 30)
2123
addRowBtnAction?.also { _ ->
2224
it.addActionListener {
2325
addRowBtnAction()
@@ -26,6 +28,7 @@ class ConnectionHostPortRowPanel(
2628
}
2729
}
2830
private val delRowBtn = JButton(AllIcons.General.Remove).also {
31+
it.preferredSize = Dimension(30, 30)
2932
delRowBtnAction?.also { _ ->
3033
it.addActionListener {
3134
delRowBtnAction()

Diff for: src/main/kotlin/com/github/tsonglew/etcdhelper/dialog/EtcdConnectionSettingsDialog.kt

+15
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ class EtcdConnectionSettingsDialog(
5656
private val remarkTextField = JBTextField("", 20)
5757
private val usernameTextField = JBTextField("", 20)
5858
private val passwordTextField = JPasswordField("", 20)
59+
private val enableAuthCheckBox = JCheckBox().apply {
60+
addActionListener {
61+
updateEnableAuthCheckBoxStatus()
62+
}
63+
}
5964

6065
// How to Build Jectd Client for One TLS Secured Etcd Cluster:
6166
// https://github.com/etcd-io/jetcd/blob/main/docs/SslConfig.md
@@ -76,6 +81,7 @@ class EtcdConnectionSettingsDialog(
7681
remarkTextField.text = name
7782
usernameTextField.text = username
7883
passwordTextField.text = PasswordUtil.retrievePassword(id!!)
84+
enableAuthCheckBox.isSelected = enableAuth ?: false
7985
title = "Edit Connection"
8086

8187
while (endpointPanel!!.components.size > 1) {
@@ -96,12 +102,18 @@ class EtcdConnectionSettingsDialog(
96102
tlsClientKey?.let { tlsClientKeyBtn.text = tlsClientKey!! }
97103
tlsClientCert?.let { tlsClientCertBtn.text = tlsClientCert!! }
98104
}
105+
updateEnableAuthCheckBoxStatus()
99106
updateTlsCheckBoxStatus()
100107
bindFileChooserAction(tlsCaCertBtn)
101108
bindFileChooserAction(tlsClientKeyBtn)
102109
bindFileChooserAction(tlsClientCertBtn)
103110
}
104111

112+
private fun updateEnableAuthCheckBoxStatus() {
113+
usernameTextField.isEnabled = enableAuthCheckBox.isSelected
114+
passwordTextField.isEnabled = enableAuthCheckBox.isSelected
115+
}
116+
105117
private fun updateTlsCheckBoxStatus() {
106118
tlsCaCertBtn.isEnabled = tlsCheckBox.isSelected
107119
tlsClientKeyBtn.isEnabled = tlsCheckBox.isSelected
@@ -134,6 +146,8 @@ class EtcdConnectionSettingsDialog(
134146

135147
centerPanel = panel {
136148
row("Connection Name:") { cell(remarkTextField) }
149+
separator("Authentication")
150+
row("Enable Auth:") { cell(enableAuthCheckBox) }
137151
row("Username:") { cell(usernameTextField) }
138152
row("Password:") { cell(passwordTextField) }
139153
separator("SSL/TLS Configuration")
@@ -173,6 +187,7 @@ class EtcdConnectionSettingsDialog(
173187
return EtcdConnectionInfo(
174188
connAddr,
175189
usernameTextField.text,
190+
enableAuthCheckBox.isSelected,
176191
etcdConnectionInfo?.id,
177192
remarkTextField.text.ifBlank { connAddr },
178193
tlsCheckBox.isSelected,

0 commit comments

Comments
 (0)