Skip to content

Commit

Permalink
config: bootstrap: remove single interface support
Browse files Browse the repository at this point in the history
Signed-off-by: Date Huang <[email protected]>
  • Loading branch information
tjjh89017 committed Sep 30, 2024
1 parent 7824452 commit 134696f
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 72 deletions.
2 changes: 0 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var (
)

var envs = map[string][]string{
"wg": {"WG", "WIREGUARD"},
"cloudflare.api_key": {"CF_API_KEY", "CLOUDFLARE_API_KEY"},
"cloudflare.api_email": {"CF_API_EMAIL", "CLOUDFLARE_API_EMAIL"},
"cloudflare.api_token": {"CF_API_TOKEN", "CLOUDFLARE_API_TOKEN"},
Expand Down Expand Up @@ -56,7 +55,6 @@ type Cloudflare struct {
}

type Config struct {
WireGuard string `mapstructure:"wg"`
Interfaces Interfaces `mapstructure:"interfaces"`
RefreshInterval time.Duration `mapstructure:"refresh_interval"`
Log Logger `mapstructure:"log"`
Expand Down
6 changes: 0 additions & 6 deletions internal/ctrl/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ func (ctrl *BootstrapController) Execute(ctx context.Context) {
continue
}
}

if ctrl.config.WireGuard != "" {
if err := ctrl.registerDevice(ctx, ctrl.config.WireGuard, nil); err != nil {
ctrl.logger.Error().Err(err).Str("device", ctrl.config.WireGuard).Msg("failed to register device")
}
}
}

func (ctrl *BootstrapController) registerDevice(ctx context.Context, deviceName string, peers map[string]config.Peer) error {
Expand Down
64 changes: 0 additions & 64 deletions internal/ctrl/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ctrl_test

import (
"context"
"errors"
"testing"

"github.com/rs/zerolog"
Expand All @@ -13,69 +12,6 @@ import (
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)

func TestBootstrap_WithError(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

mockWgClient := mock.NewMockWireGuardClient(mockCtrl)
mockDevices := mock.NewMockDeviceRepository(mockCtrl)
mockPeers := mock.NewMockPeerRepository(mockCtrl)
logger := zerolog.Nop()
config := &config.Config{
WireGuard: "wg0",
}

mockWgClient.EXPECT().Device("wg0").Return(nil, errors.New("device not found"))

bootstrap := ctrl.NewBootstrapController(
mockWgClient,
config,
mockDevices,
mockPeers,
&logger,
)

bootstrap.Execute(context.TODO())
}

func TestBootstrap_WithSingleInterface(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

mockWgClient := mock.NewMockWireGuardClient(mockCtrl)
mockDevices := mock.NewMockDeviceRepository(mockCtrl)
mockPeers := mock.NewMockPeerRepository(mockCtrl)
logger := zerolog.Nop()
config := &config.Config{
WireGuard: "wg0",
}

mockDevice := &wgtypes.Device{
Name: "wg0",
ListenPort: 51820,
PrivateKey: [32]byte{},
Peers: []wgtypes.Peer{
{
PublicKey: [32]byte{},
},
},
}

mockWgClient.EXPECT().Device("wg0").Return(mockDevice, nil)
mockDevices.EXPECT().Save(gomock.Any(), gomock.Any())
mockPeers.EXPECT().Save(gomock.Any(), gomock.Any())

bootstrap := ctrl.NewBootstrapController(
mockWgClient,
config,
mockDevices,
mockPeers,
&logger,
)

bootstrap.Execute(context.TODO())
}

func TestBootstrap_WithMultipleInterfaces(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
Expand Down

0 comments on commit 134696f

Please sign in to comment.