Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-grgt committed Dec 30, 2024
1 parent ff6222d commit 93a5e0b
Show file tree
Hide file tree
Showing 47 changed files with 10,318 additions and 568 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23.2'

- name: Build
run: go build -v ./... -tags prd

- name: Test
run: go test -v ./... -tags prd
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/ktea.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions .run/ktea prd.run.xml

This file was deleted.

60 changes: 26 additions & 34 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ import (
"os"
)

type SASLProtocol string

type AuthMethod int

type SecurityProtocol string

const (
NoneAuthMethod AuthMethod = 0
PLAIN_TEXT SASLProtocol = "PLAIN_TEXT"
SSL SASLProtocol = "SSL"
NoneAuthMethod AuthMethod = 0
SASLAuthMethod AuthMethod = 1
SSLSecurityProtocol SecurityProtocol = "SSL"
PlaintextSecurityProtocol SecurityProtocol = "PLAIN_TEXT"
)

type SASLConfig struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
Protocol SASLProtocol `yaml:"protocol"`
Username string `yaml:"username"`
Password string `yaml:"password"`
SecurityProtocol SecurityProtocol `yaml:"securityProtocol"`
}

type Cluster struct {
Expand All @@ -41,12 +42,15 @@ func (c *Config) HasEnvs() bool {
}

type RegistrationDetails struct {
Name string
Active bool
Color string
Host string
AuthMethod AuthMethod
NewName *string
Name string
Active bool
Color string
Host string
AuthMethod AuthMethod
SecurityProtocol SecurityProtocol
NewName *string
Username string
Password string
}

type ClusterDeletedMsg struct {
Expand All @@ -73,7 +77,14 @@ func (c *Config) RegisterCluster(details RegistrationDetails) tea.Msg {
Active: details.Active,
Color: details.Color,
BootstrapServers: []string{details.Host},
SASLConfig: nil,
}

if details.AuthMethod == SASLAuthMethod {
cluster.SASLConfig = &SASLConfig{
Username: details.Username,
Password: details.Password,
SecurityProtocol: details.SecurityProtocol,
}
}

// did the newly registered cluster update an existing one
Expand Down Expand Up @@ -191,25 +202,6 @@ func New(configIO ConfigIO) *Config {
}
config.configIO = configIO
return config

//&Config{
//Clusters: []Cluster{
// {
// Name: "local",
// BootstrapServers: []string{"localhost:9092"},
// SASLConfig: nil,
// },
//},
//BootstrapServers: []string{"pkc-lq8gm.westeurope.azure.confluent.cloud:9092"},
//SASLConfig: &SASLConfig{
// Username: "4QZMEH5YM4CVIRXV",
// Password: "aH/ocyFo3MyXAHlsoNiWqHjpoJFAXK/ksP958HGuBgtcMXlz94HlNUx11+sMEAOW",
// Protocol: SSL,
//},
//BootstrapServers:
// []string{"localhost"},
//},
//}
}

func ReLoadConfig() tea.Msg {
Expand Down
24 changes: 24 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,30 @@ import (

func TestConfig(t *testing.T) {

t.Run("Registering a SASL_SSL cluster", func(t *testing.T) {
// given
config := New(&InMemoryConfigIO{})

// when
config.RegisterCluster(RegistrationDetails{
Name: "prd",
Color: "#880808",
Active: true,
Host: "localhost:9092",
AuthMethod: SASLAuthMethod,
Username: "john",
Password: "test123",
SecurityProtocol: SSLSecurityProtocol,
})

// then
assert.Equal(t, config.Clusters[0].Color, "#880808")
assert.Equal(t, config.Clusters[0].BootstrapServers, []string{"localhost:9092"})
assert.Equal(t, config.Clusters[0].SASLConfig.SecurityProtocol, SSLSecurityProtocol)
assert.Equal(t, config.Clusters[0].SASLConfig.Username, "john")
assert.Equal(t, config.Clusters[0].SASLConfig.Password, "test123")
})

t.Run("Registering an existing cluster updates it", func(t *testing.T) {
// given
config := New(&InMemoryConfigIO{})
Expand Down
Loading

0 comments on commit 93a5e0b

Please sign in to comment.