Skip to content

Commit

Permalink
feat: [config] etcd connection add button size
Browse files Browse the repository at this point in the history
  • Loading branch information
tsonglew committed Sep 6, 2023
1 parent c1bb44d commit 6762416
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ bin/
### Fleet ###
.fleet/
/.fleet/settings.json

### Etcd Demo ###
**/*.csr
**/*.pem
6 changes: 6 additions & 0 deletions assets/etcd/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.PHONY: run members

run:
docker compose up -d
members:
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
16 changes: 13 additions & 3 deletions assets/etcd/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,33 @@

### Download cfssl

#### Linux

```bash
mkdir ~/bin
curl -s -L -o ~/bin/cfssl https://pkg.cfssl.org/R1.2/cfssl_linux-amd64
curl -s -L -o ~/bin/cfssljson https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64
chmod +x ~/bin/{cfssl,cfssljson}
export PATH=$PATH:~/bin
```

#### Mac

```bash
brew install cfssl
```

### Generate CA

```bash
export PATH=$PATH:~/bin
mkdir ~/cfssl
cd ~/cfssl
mkdir cfssl
cd cfssl
cfssl print-defaults config > ca-config.json
cfssl print-defaults csr > ca-csr.json
```

###

# Refer

https://blog.try-except.com/technology/docker_etcd_cluster_ssl.html
35 changes: 35 additions & 0 deletions assets/etcd/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: '2'

services:
node1:
image: 'bitnami/etcd:latest'
environment:
- "ETCD_NAME=node1"
- "ETCD_ROOT_PASSWORD=hillstone"
- "ETCD_CLIENT_CERT_AUTH=true"
- "ETCD_PEER_CLIENT_CERT_AUTH=true"
- "ETCD_ADVERTISE_CLIENT_URLS=https://192.168.0.81:42379"
- "ETCD_INITIAL_ADVERTISE_PEER_URLS=https://192.168.0.81:42380"
- "ETCD_LISTEN_CLIENT_URLS=https://0.0.0.0:2379"
- "ETCD_LISTEN_PEER_URLS=https://0.0.0.0:2380"
- "ETCD_INITIAL_CLUSTER_TOKEN=etcd_cluster"
- "ETCD_INITIAL_CLUSTER=node1=https://192.168.0.81:42380"
- "ETCD_INITIAL_CLUSTER_STATE=new"
- "ETCD_DATA_DIR=/opt/bitnami/etcd/data"
- "ETCD_TRUSTED_CA_FILE=/opt/bitnami/etcd/conf/ca.pem"
- "ETCD_KEY_FILE=/opt/bitnami/etcd/conf/server-key.pem"
- "ETCD_CERT_FILE=/opt/bitnami/etcd/conf/server.pem"
- "ETCD_PEER_TRUSTED_CA_FILE=/opt/bitnami/etcd/conf/ca.pem"
- "ETCD_PEER_KEY_FILE=/opt/bitnami/etcd/conf/peer-key.pem"
- "ETCD_PEER_CERT_FILE=/opt/bitnami/etcd/conf/peer.pem"
volumes:
- ./cfssl/ca.pem:/opt/bitnami/etcd/conf/ca.pem
- ./cfssl/node1.pem:/opt/bitnami/etcd/conf/peer.pem
- ./cfssl/node1-key.pem:/opt/bitnami/etcd/conf/peer-key.pem
- ./cfssl/server.pem:/opt/bitnami/etcd/conf/server.pem
- ./cfssl/server-key.pem:/opt/bitnami/etcd/conf/server-key.pem
- ./cfssl/client-key.pem:/opt/bitnami/etcd/client-key.pem
- ./cfssl/client.pem:/opt/bitnami/etcd/client.pem
ports:
- "42379:2379"
- "42380:2380"
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class EtcdClient(

try {
val clientBuilder = Client.builder().endpoints(*etcdUrls!!)
if (user.isNotEmpty() && password?.isNotEmpty() == true) {
if (etcdConnectionInfo.enableAuth == true) {
clientBuilder.user(bytesOf(user)).password(bytesOf(password))
}
client = clientBuilder.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import java.util.*
data class EtcdConnectionInfo(
var endpoints: String,
var username: String,
var enableAuth: Boolean? = false,
var id: String? = null,
var name: String? = null,
var tlsEnabled: Boolean? = false,
Expand All @@ -56,6 +57,7 @@ data class EtcdConnectionInfo(
fun update(etcdConnectionInfo: EtcdConnectionInfo): EtcdConnectionInfo {
endpoints = etcdConnectionInfo.endpoints
username = etcdConnectionInfo.username
enableAuth = etcdConnectionInfo.enableAuth
name = etcdConnectionInfo.name
tlsEnabled = etcdConnectionInfo.tlsEnabled
tlsClientCert = etcdConnectionInfo.tlsClientCert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.tsonglew.etcdhelper.component

import com.intellij.icons.AllIcons
import com.intellij.ui.components.JBTextField
import java.awt.Dimension
import java.awt.FlowLayout
import javax.swing.JButton
import javax.swing.JLabel
Expand All @@ -18,6 +19,7 @@ class ConnectionHostPortRowPanel(
private val hostInputText = JBTextField(host, 15)
private val portInputText = JBTextField(port, 5)
private val addRowBtn = JButton(AllIcons.General.Add).also {
it.preferredSize = Dimension(30, 30)
addRowBtnAction?.also { _ ->
it.addActionListener {
addRowBtnAction()
Expand All @@ -26,6 +28,7 @@ class ConnectionHostPortRowPanel(
}
}
private val delRowBtn = JButton(AllIcons.General.Remove).also {
it.preferredSize = Dimension(30, 30)
delRowBtnAction?.also { _ ->
it.addActionListener {
delRowBtnAction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ class EtcdConnectionSettingsDialog(
private val remarkTextField = JBTextField("", 20)
private val usernameTextField = JBTextField("", 20)
private val passwordTextField = JPasswordField("", 20)
private val enableAuthCheckBox = JCheckBox().apply {
addActionListener {
updateEnableAuthCheckBoxStatus()
}
}

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

while (endpointPanel!!.components.size > 1) {
Expand All @@ -96,12 +102,18 @@ class EtcdConnectionSettingsDialog(
tlsClientKey?.let { tlsClientKeyBtn.text = tlsClientKey!! }
tlsClientCert?.let { tlsClientCertBtn.text = tlsClientCert!! }
}
updateEnableAuthCheckBoxStatus()
updateTlsCheckBoxStatus()
bindFileChooserAction(tlsCaCertBtn)
bindFileChooserAction(tlsClientKeyBtn)
bindFileChooserAction(tlsClientCertBtn)
}

private fun updateEnableAuthCheckBoxStatus() {
usernameTextField.isEnabled = enableAuthCheckBox.isSelected
passwordTextField.isEnabled = enableAuthCheckBox.isSelected
}

private fun updateTlsCheckBoxStatus() {
tlsCaCertBtn.isEnabled = tlsCheckBox.isSelected
tlsClientKeyBtn.isEnabled = tlsCheckBox.isSelected
Expand Down Expand Up @@ -134,6 +146,8 @@ class EtcdConnectionSettingsDialog(

centerPanel = panel {
row("Connection Name:") { cell(remarkTextField) }
separator("Authentication")
row("Enable Auth:") { cell(enableAuthCheckBox) }
row("Username:") { cell(usernameTextField) }
row("Password:") { cell(passwordTextField) }
separator("SSL/TLS Configuration")
Expand Down Expand Up @@ -173,6 +187,7 @@ class EtcdConnectionSettingsDialog(
return EtcdConnectionInfo(
connAddr,
usernameTextField.text,
enableAuthCheckBox.isSelected,
etcdConnectionInfo?.id,
remarkTextField.text.ifBlank { connAddr },
tlsCheckBox.isSelected,
Expand Down

0 comments on commit 6762416

Please sign in to comment.