Skip to content

Commit 6efe115

Browse files
authored
Merge pull request #40 from kubevirt-ui/main
update
2 parents 1b1bc06 + ba87c35 commit 6efe115

File tree

7 files changed

+360
-145
lines changed

7 files changed

+360
-145
lines changed

.github/workflows/ci_checks.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ jobs:
1313
name: build
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@v2
17-
- uses: actions/setup-go@v4
16+
- uses: actions/checkout@v6
17+
- uses: actions/setup-go@v6
1818
with:
19-
go-version: '1.23.0'
20-
19+
go-version-file:
20+
go.mod
21+
2122
- name: Build
2223
run: go build .
2324
- name: Run Unit Tests
24-
run: go test .
25+
run: go test ./...
2526

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.23
1+
FROM golang:1.24
22

33
COPY . /app
44
WORKDIR /app

config/config.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package config
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"math"
7+
"strconv"
8+
"strings"
9+
)
10+
11+
type Config struct {
12+
TLS TLSConfig
13+
}
14+
15+
type TLSConfig struct {
16+
minTLSVersion uint16
17+
tlsCipherSuites []uint16
18+
}
19+
20+
var (
21+
minTLSVersionFlag = flag.Uint("tls-min-version", 0, "The minimum TLS version to use")
22+
tlsCipherSuitesFlag = flag.String("tls-cipher-suites", "", "A comma-separated list of cipher suites to use")
23+
)
24+
25+
func GetConfig() (*Config, error) {
26+
cfg := &Config{}
27+
28+
if *minTLSVersionFlag > 0 {
29+
if *minTLSVersionFlag > math.MaxUint16 {
30+
return nil, fmt.Errorf("the --tls-min-version flag is with a wrong value: %d is lager than the max allowed value of %d", *minTLSVersionFlag, math.MaxUint16)
31+
}
32+
33+
cfg.TLS.minTLSVersion = uint16(*minTLSVersionFlag)
34+
}
35+
36+
if *tlsCipherSuitesFlag != "" {
37+
ciphers := strings.Split(*tlsCipherSuitesFlag, ",")
38+
tlsCipherSuites := make([]uint16, 0, len(ciphers))
39+
40+
for _, cipherStr := range ciphers {
41+
cipherStr = strings.TrimSpace(cipherStr)
42+
cipher, err := strconv.ParseUint(cipherStr, 10, 16)
43+
if err != nil {
44+
return nil, fmt.Errorf("can't parse cipher %q; %w", cipherStr, err)
45+
}
46+
47+
tlsCipherSuites = append(tlsCipherSuites, uint16(cipher))
48+
}
49+
50+
cfg.TLS.tlsCipherSuites = tlsCipherSuites
51+
}
52+
53+
return cfg, nil
54+
}
55+
56+
func (cfg *Config) GetMinTLSVersion() uint16 {
57+
return cfg.TLS.minTLSVersion
58+
}
59+
60+
func (cfg *Config) GetTLSCipherSuites() []uint16 {
61+
return cfg.TLS.tlsCipherSuites
62+
}

config/config_test.go

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
package config
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"math"
7+
"reflect"
8+
"testing"
9+
)
10+
11+
func TestGetTLSCipherSuites(t *testing.T) {
12+
for _, tc := range []struct {
13+
name string
14+
flagVal string
15+
want []uint16
16+
}{
17+
{name: "valid input", flagVal: "1,2,3,4", want: []uint16{1, 2, 3, 4}},
18+
{name: "no flag", flagVal: "", want: nil},
19+
{name: "max val", flagVal: fmt.Sprintf("%d", math.MaxUint16), want: []uint16{math.MaxUint16}},
20+
} {
21+
t.Run(tc.flagVal, func(t *testing.T) {
22+
err := setFlags("0", tc.flagVal)
23+
if err != nil {
24+
t.Fatal(err)
25+
}
26+
27+
cfg, err := GetConfig()
28+
if err != nil {
29+
t.Fatal(err)
30+
}
31+
32+
if got, want := cfg.GetTLSCipherSuites(), tc.want; !reflect.DeepEqual(got, want) {
33+
t.Errorf("GetTLSCipherSuites() = %v, want %v", got, want)
34+
}
35+
})
36+
}
37+
}
38+
39+
func TestWrongGetTLSCipherSuites_tooLarge(t *testing.T) {
40+
err := setFlags("0", fmt.Sprintf("%d", math.MaxUint16+1))
41+
if err != nil {
42+
t.Fatal(err)
43+
}
44+
45+
_, err = GetConfig()
46+
if err == nil {
47+
t.Fatal("error should have errored")
48+
}
49+
50+
t.Logf("got expected error: %v", err)
51+
}
52+
53+
func TestWrongGetTLSCipherSuites_negative(t *testing.T) {
54+
err := setFlags("0", "-42")
55+
if err != nil {
56+
t.Fatal(err)
57+
}
58+
59+
_, err = GetConfig()
60+
if err == nil {
61+
t.Fatal("error should have errored")
62+
}
63+
64+
t.Logf("got expected error: %v", err)
65+
}
66+
67+
func TestWrongGetTLSCipherSuites_notNum(t *testing.T) {
68+
err := setFlags("0", "not a number")
69+
if err != nil {
70+
t.Fatal(err)
71+
}
72+
73+
_, err = GetConfig()
74+
if err == nil {
75+
t.Fatal("error should have errored")
76+
}
77+
78+
t.Logf("got expected error: %v", err)
79+
}
80+
81+
func TestWrongGetTLSCipherSuites_float(t *testing.T) {
82+
err := setFlags("0", "1.42")
83+
if err != nil {
84+
t.Fatal(err)
85+
}
86+
87+
_, err = GetConfig()
88+
if err == nil {
89+
t.Fatal("error should have errored")
90+
}
91+
92+
t.Logf("got expected error: %v", err)
93+
}
94+
95+
func TestGetMinTLSVersion(t *testing.T) {
96+
for _, tc := range []struct {
97+
name string
98+
flagVal string
99+
want uint16
100+
}{
101+
{name: "valid input", flagVal: "42", want: 42},
102+
{name: "no flag", flagVal: "0", want: 0},
103+
{name: "max val", flagVal: fmt.Sprintf("%d", math.MaxUint16), want: math.MaxUint16},
104+
} {
105+
t.Run(tc.flagVal, func(t *testing.T) {
106+
err := setFlags(tc.flagVal, "")
107+
if err != nil {
108+
t.Fatal(err)
109+
}
110+
111+
cfg, err := GetConfig()
112+
if err != nil {
113+
t.Fatal(err)
114+
}
115+
116+
if got, want := cfg.GetMinTLSVersion(), tc.want; !reflect.DeepEqual(got, want) {
117+
t.Errorf("GetMinTLSVersion() = %d, want %d", got, want)
118+
}
119+
})
120+
}
121+
}
122+
123+
func TestWrongGetMinTLSVersion_tooLarge(t *testing.T) {
124+
err := setFlags(fmt.Sprintf("%d", math.MaxUint16+1), "")
125+
if err != nil {
126+
t.Fatal(err)
127+
}
128+
129+
_, err = GetConfig()
130+
if err == nil {
131+
t.Fatal("error should have errored")
132+
}
133+
134+
t.Logf("got expected error: %v", err)
135+
}
136+
137+
func setFlags(minVer, ciphers string) error {
138+
err := flag.Set("tls-min-version", minVer)
139+
if err != nil {
140+
return err
141+
}
142+
err = flag.Set("tls-cipher-suites", ciphers)
143+
if err != nil {
144+
return err
145+
}
146+
147+
return nil
148+
}

go.mod

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,50 @@
11
module github.com/kubevirt-ui/kubevirt-apiserver-proxy
22

3-
go 1.23.0
4-
5-
toolchain go1.23.4
3+
go 1.24.0
64

75
require (
8-
github.com/chenyahui/gin-cache v1.8.1
9-
github.com/gin-contrib/gzip v0.0.6
10-
github.com/gin-gonic/gin v1.9.1
11-
github.com/gorilla/websocket v1.5.0
12-
github.com/tidwall/gjson v1.14.4
13-
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df
6+
github.com/chenyahui/gin-cache v1.10.0
7+
github.com/gin-contrib/gzip v1.2.5
8+
github.com/gin-gonic/gin v1.11.0
9+
github.com/gorilla/websocket v1.5.3
10+
github.com/tidwall/gjson v1.18.0
11+
golang.org/x/exp v0.0.0-20260112195511-716be5621a96
1412
)
1513

1614
require (
17-
github.com/bytedance/sonic v1.10.0-rc3 // indirect
18-
github.com/cespare/xxhash/v2 v2.1.2 // indirect
19-
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
20-
github.com/chenzhuoyu/iasm v0.9.0 // indirect
15+
github.com/bytedance/gopkg v0.1.3 // indirect
16+
github.com/bytedance/sonic v1.14.2 // indirect
17+
github.com/bytedance/sonic/loader v0.4.0 // indirect
18+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
19+
github.com/cloudwego/base64x v0.1.6 // indirect
2120
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
22-
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
23-
github.com/gin-contrib/sse v0.1.0 // indirect
21+
github.com/gabriel-vasile/mimetype v1.4.12 // indirect
22+
github.com/gin-contrib/sse v1.1.0 // indirect
2423
github.com/go-playground/locales v0.14.1 // indirect
2524
github.com/go-playground/universal-translator v0.18.1 // indirect
26-
github.com/go-playground/validator/v10 v10.14.1 // indirect
25+
github.com/go-playground/validator/v10 v10.30.1 // indirect
2726
github.com/go-redis/redis/v8 v8.11.5 // indirect
28-
github.com/goccy/go-json v0.10.2 // indirect
27+
github.com/goccy/go-json v0.10.5 // indirect
28+
github.com/goccy/go-yaml v1.19.2 // indirect
2929
github.com/jellydator/ttlcache/v2 v2.11.1 // indirect
3030
github.com/json-iterator/go v1.1.12 // indirect
31-
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
32-
github.com/leodido/go-urn v1.2.4 // indirect
33-
github.com/mattn/go-isatty v0.0.19 // indirect
31+
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
32+
github.com/leodido/go-urn v1.4.0 // indirect
33+
github.com/mattn/go-isatty v0.0.20 // indirect
3434
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
3535
github.com/modern-go/reflect2 v1.0.2 // indirect
36-
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
37-
github.com/tidwall/match v1.1.1 // indirect
36+
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
37+
github.com/quic-go/qpack v0.6.0 // indirect
38+
github.com/quic-go/quic-go v0.59.0 // indirect
39+
github.com/tidwall/match v1.2.0 // indirect
3840
github.com/tidwall/pretty v1.2.1 // indirect
3941
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
40-
github.com/ugorji/go/codec v1.2.11 // indirect
41-
golang.org/x/arch v0.4.0 // indirect
42-
golang.org/x/crypto v0.36.0 // indirect
43-
golang.org/x/net v0.37.0 // indirect
44-
golang.org/x/sync v0.12.0 // indirect
45-
golang.org/x/sys v0.31.0 // indirect
46-
golang.org/x/text v0.23.0 // indirect
47-
google.golang.org/protobuf v1.34.2 // indirect
48-
gopkg.in/yaml.v3 v3.0.1 // indirect
42+
github.com/ugorji/go/codec v1.3.1 // indirect
43+
golang.org/x/arch v0.23.0 // indirect
44+
golang.org/x/crypto v0.47.0 // indirect
45+
golang.org/x/net v0.49.0 // indirect
46+
golang.org/x/sync v0.19.0 // indirect
47+
golang.org/x/sys v0.40.0 // indirect
48+
golang.org/x/text v0.33.0 // indirect
49+
google.golang.org/protobuf v1.36.11 // indirect
4950
)

0 commit comments

Comments
 (0)