├── .github ├── CODEOWNERS ├── pull_request_template.md ├── workflows │ ├── release-drafter.yml │ └── sanity.yaml └── release-drafter.yml ├── Makefile ├── docs └── local.md ├── pkg ├── openwrt │ ├── config.go │ ├── types.go │ ├── openwrt.go │ └── openwrt_test.go ├── logger │ ├── config.go │ └── logger.go ├── router │ ├── config.go │ └── router.go ├── lucirpc │ ├── config.go │ ├── lucirpc.go │ └── lucirpc_test.go ├── config │ └── config.go └── webhook │ ├── mediatype.go │ └── webhook.go ├── internal ├── provider │ ├── config.go │ ├── provider.go │ └── provider_test.go └── mocks │ ├── lucirpc │ └── lucirpc.go │ └── openwrt │ └── openwrt.go ├── k3d.yaml ├── .gitignore ├── skaffold.yaml ├── cmd └── webhook │ ├── config.go │ └── main.go ├── example ├── services.yaml └── values.yaml ├── README.md ├── go.mod ├── LICENSE.md └── go.sum /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @renanqts -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: generate 2 | generate: 3 | go generate ./... -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | # Motivation 2 | -------------------------------------------------------------------------------- /docs/local.md: -------------------------------------------------------------------------------- 1 | # local test 2 | 3 | ### Requirements 4 | - k3d 5 | - skaffold 6 | - ko 7 | - kubectl 8 | 9 | ### How to use 10 | 11 | Create a k3d registry + cluster 12 | ``` 13 | k3d cluster create --config k3d.yaml 14 | skaffold dev 15 | ``` -------------------------------------------------------------------------------- /pkg/openwrt/config.go: -------------------------------------------------------------------------------- 1 | package openwrt 2 | 3 | import "github.com/renanqts/external-dns-openwrt-webhook/pkg/lucirpc" 4 | 5 | type Config struct { 6 | LuciRPC *lucirpc.Config `mapstructure:"lucirpc"` 7 | } 8 | 9 | func DefaultConfig() *Config { 10 | return &Config{ 11 | LuciRPC: lucirpc.DefaultConfig(), 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /internal/provider/config.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "github.com/renanqts/external-dns-openwrt-webhook/pkg/openwrt" 5 | ) 6 | 7 | type Config struct { 8 | OpenWRT *openwrt.Config `mapstructure:"openwrt"` 9 | } 10 | 11 | func DefaultConfig() *Config { 12 | return &Config{ 13 | OpenWRT: openwrt.DefaultConfig(), 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /pkg/openwrt/types.go: -------------------------------------------------------------------------------- 1 | package openwrt 2 | 3 | // DNSRecord represents a DNS record in LuciRPC 4 | type DNSRecord struct { 5 | Type string `json:".type" validate:"required"` 6 | IP string `json:"ip,omitempty"` 7 | Name string `json:"name,omitempty"` 8 | CName string `json:"cname,omitempty"` 9 | Target string `json:"target,omitempty"` 10 | } 11 | -------------------------------------------------------------------------------- /k3d.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: k3d.io/v1alpha5 3 | kind: Simple 4 | metadata: 5 | name: external-dns-openwrt-webhook 6 | options: 7 | k3s: 8 | extraArgs: 9 | - arg: --disable=traefik,metrics-server,local-storage,network-policy 10 | nodeFilters: 11 | - server:* 12 | ports: 13 | - port: 8080:8080 14 | nodeFilters: 15 | - loadbalancer -------------------------------------------------------------------------------- /pkg/logger/config.go: -------------------------------------------------------------------------------- 1 | package logger 2 | 3 | type Config struct { 4 | Level string `mapstructure:"level"` 5 | StackTrace bool `mapstructure:"stack_trace"` 6 | Encoding string `mapstructure:"encoding"` 7 | } 8 | 9 | func DefaultConfig() *Config { 10 | return &Config{ 11 | Level: "info", 12 | StackTrace: false, 13 | Encoding: "json", 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /.github/workflows/release-drafter.yml: -------------------------------------------------------------------------------- 1 | name: Release Drafter 2 | on: 3 | push: 4 | branches: 5 | - main 6 | 7 | jobs: 8 | update_release_draft: 9 | permissions: 10 | contents: write 11 | pull-requests: write 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: release-drafter/release-drafter@v6 15 | env: 16 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -------------------------------------------------------------------------------- /pkg/router/config.go: -------------------------------------------------------------------------------- 1 | package router 2 | 3 | type Gin struct { 4 | ReleaseMode bool `mapstructure:"release_mode"` 5 | } 6 | 7 | type Config struct { 8 | HealthCheckPath string `mapstructure:"healthcheck_path"` 9 | Port string `mapstructure:"port"` 10 | Gin Gin `mapstructure:"gin"` 11 | } 12 | 13 | func DefaultConfig() *Config { 14 | return &Config{ 15 | HealthCheckPath: "/ping", 16 | Port: "8888", 17 | Gin: Gin{ 18 | ReleaseMode: true, 19 | }, 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /.github/workflows/sanity.yaml: -------------------------------------------------------------------------------- 1 | name: go lint, vet, test, build 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | pull_request: 7 | branches: [ "main" ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v4 14 | - uses: actions/setup-go@v5 15 | - name: golangci 16 | uses: golangci/golangci-lint-action@v6 17 | with: 18 | version: v1.64.5 19 | 20 | - name: vet 21 | run: go vet ./... 22 | 23 | - name: test 24 | run: go test -v ./... 25 | 26 | - name: build 27 | run: go build ./... -------------------------------------------------------------------------------- /pkg/logger/logger.go: -------------------------------------------------------------------------------- 1 | package logger 2 | 3 | import ( 4 | "go.uber.org/zap" 5 | ) 6 | 7 | var Log *zap.Logger 8 | 9 | func Init(config *Config) error { 10 | zapConfig := zap.NewProductionConfig() 11 | zapConfig.DisableStacktrace = !config.StackTrace 12 | zapConfig.Encoding = config.Encoding 13 | if err := zapConfig.Level.UnmarshalText([]byte(config.Level)); err != nil { 14 | return nil 15 | } 16 | 17 | if Log != nil { 18 | _ = Log.Sync() 19 | return nil 20 | } 21 | 22 | var err error 23 | Log, err = zapConfig.Build() 24 | return err 25 | } 26 | 27 | func Set(logger *zap.Logger) { 28 | Log = logger 29 | } 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # If you prefer the allow list template instead of the deny list, see community template: 2 | # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore 3 | # 4 | # Binaries for programs and plugins 5 | *.exe 6 | *.exe~ 7 | *.dll 8 | *.so 9 | *.dylib 10 | 11 | # Test binary, built with `go test -c` 12 | *.test 13 | 14 | # Output of the go coverage tool, specifically when used with LiteIDE 15 | *.out 16 | 17 | # Dependency directories (remove the comment below to include it) 18 | # vendor/ 19 | 20 | # Go workspace file 21 | go.work 22 | go.work.sum 23 | 24 | # env file 25 | .env 26 | 27 | # local values 28 | values.yaml -------------------------------------------------------------------------------- /.github/release-drafter.yml: -------------------------------------------------------------------------------- 1 | name-template: 'v$RESOLVED_VERSION' 2 | tag-template: 'v$RESOLVED_VERSION' 3 | categories: 4 | - title: '🚀 Features' 5 | labels: 6 | - 'feat' 7 | - 'feature' 8 | - 'enhancement' 9 | - title: '🐛 Bug Fixes' 10 | labels: 11 | - 'fix' 12 | - 'bugfix' 13 | - 'bug' 14 | - title: '🧰 Maintenance' 15 | label: 'chore' 16 | change-template: '- $TITLE @$AUTHOR (#$NUMBER)' 17 | change-title-escapes: '\<*_&' 18 | version-resolver: 19 | major: 20 | labels: 21 | - 'major' 22 | minor: 23 | labels: 24 | - 'minor' 25 | patch: 26 | labels: 27 | - 'patch' 28 | default: patch 29 | template: | 30 | ## Changes 31 | 32 | $CHANGES -------------------------------------------------------------------------------- /skaffold.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: skaffold/v4beta11 3 | kind: Config 4 | metadata: 5 | name: external-dns-openwrt-webhook 6 | build: 7 | artifacts: 8 | - image: webhook 9 | ko: 10 | dir: ./cmd/webhook 11 | fromImage: gcr.io/distroless/static-debian12:nonroot 12 | deploy: 13 | helm: 14 | releases: 15 | - name: external-dns 16 | repo: https://kubernetes-sigs.github.io/external-dns 17 | remoteChart: external-dns 18 | version: 1.15.2 19 | setValueTemplates: 20 | provider: 21 | webhook: 22 | image: 23 | repository: "{{.IMAGE_REPO_webhook}}" 24 | tag: "{{.IMAGE_TAG_webhook}}" 25 | valuesFiles: 26 | - example/values.yaml 27 | manifests: 28 | rawYaml: 29 | - example/services.yaml -------------------------------------------------------------------------------- /cmd/webhook/config.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/renanqts/external-dns-openwrt-webhook/internal/provider" 5 | "github.com/renanqts/external-dns-openwrt-webhook/pkg/logger" 6 | "github.com/renanqts/external-dns-openwrt-webhook/pkg/router" 7 | ) 8 | 9 | type Config struct { 10 | ShutodwnTimeout int `mapstructure:"shutdown_timeout_seconds"` 11 | Log *logger.Config `mapstructure:"log"` 12 | Router *router.Config `mapstructure:"router"` 13 | Provider *provider.Config `mapstructure:"provider"` 14 | } 15 | 16 | func defaultConfig() *Config { 17 | return &Config{ 18 | ShutodwnTimeout: 5, 19 | Log: logger.DefaultConfig(), 20 | Router: router.DefaultConfig(), 21 | Provider: provider.DefaultConfig(), 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /example/services.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: v1 3 | kind: Service 4 | metadata: 5 | name: dummy-cname 6 | annotations: 7 | external-dns.alpha.kubernetes.io/hostname: cname.foobar.io 8 | external-dns.alpha.kubernetes.io/target: taget.foobar.io 9 | spec: 10 | type: LoadBalancer 11 | ports: 12 | - port: 8888 13 | targetPort: 8888 14 | selector: 15 | app.kubernetes.io/name: external-dns 16 | externalIPs: 17 | - 192.168.150.1 18 | --- 19 | apiVersion: v1 20 | kind: Service 21 | metadata: 22 | name: dummy-a 23 | annotations: 24 | external-dns.alpha.kubernetes.io/hostname: a.foobar.io 25 | spec: 26 | type: LoadBalancer 27 | ports: 28 | - port: 8888 29 | targetPort: 8888 30 | selector: 31 | app.kubernetes.io/name: external-dns 32 | externalIPs: 33 | - 192.168.150.2 -------------------------------------------------------------------------------- /pkg/lucirpc/config.go: -------------------------------------------------------------------------------- 1 | package lucirpc 2 | 3 | const ( 4 | defaultRpcID = 1 5 | defaultTimeout = 15 6 | defaultInsecureSkipVerify = false 7 | defaultRpcServerPort = 443 8 | defaultSSL = true 9 | ) 10 | 11 | type Auth struct { 12 | Username string `mapstructure:"username"` 13 | Password string `mapstructure:"password"` 14 | } 15 | 16 | type Config struct { 17 | Hostname string `mapstructure:"hostname"` 18 | Port int `mapstructure:"port"` 19 | SSL bool `mapstructure:"ssl"` 20 | RpcID int `mapstructure:"rpc_id"` 21 | Timeout int `mapstructure:"timeout"` 22 | InsecureSkipVerify bool `mapstructure:"insecure_skip_verify"` 23 | Auth Auth `mapstructure:"auth"` 24 | } 25 | 26 | func DefaultConfig() *Config { 27 | return &Config{ 28 | Port: defaultRpcServerPort, 29 | SSL: defaultSSL, 30 | RpcID: defaultRpcID, 31 | Timeout: defaultTimeout, 32 | InsecureSkipVerify: defaultInsecureSkipVerify, 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ExternalDNS Webhook Provider for OpenWRT 2 | 3 | [ExternalDNS](https://github.com/kubernetes-sigs/external-dns) is a Kubernetes add-on for automatically managing DNS records for Kubernetes ingresses and services by using different DNS providers. This webhook provider allows you to automate DNS records from your Kubernetes clusters into your OpenWRT router. If you like home automation like me, it should help you. 4 | 5 | For examples of creating DNS records either via CRDs or via Ingress/Service annotations, check out the [example directory](./example). 6 | 7 | ## Limitations 8 | - `DNSEndpoints` with multiple `targets` are not supported. 9 | - Supported DNS record types: `A`, `CNAME`. 10 | - Only `psert-only` policy is supported. 11 | 12 | ## Configuration Options 13 | You can find all the environment variables allowed as well as the default in the [values file](example/values.yaml#L19). 14 | The installation can be achieved via [helm chart](skaffold.yaml#L15-L26). 15 | 16 | [!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/renanqts4) 17 | -------------------------------------------------------------------------------- /pkg/config/config.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | 7 | "github.com/mitchellh/mapstructure" 8 | "github.com/spf13/viper" 9 | ) 10 | 11 | func Read(config any) error { 12 | viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) 13 | viper.AllowEmptyEnv(true) 14 | viper.AutomaticEnv() 15 | 16 | // AutomaticEnv does not work 17 | // https://github.com/spf13/viper/issues/188 18 | var defaultConfigMap map[string]interface{} 19 | if err := mapstructure.Decode(config, &defaultConfigMap); err != nil { 20 | return fmt.Errorf("failed to decode default config. Error: %w", err) 21 | } 22 | 23 | if err := viper.MergeConfigMap(defaultConfigMap); err != nil { 24 | return fmt.Errorf("failed to merge default config. Error: %w", err) 25 | } 26 | 27 | if err := viper.MergeInConfig(); err != nil { 28 | if _, ok := err.(viper.ConfigFileNotFoundError); !ok { 29 | return fmt.Errorf("failed to load config. Error: %w", err) 30 | } 31 | } 32 | 33 | if err := viper.Unmarshal(&config); err != nil { 34 | return fmt.Errorf("failed to unmarshal config. Error: %w", err) 35 | } 36 | 37 | return nil 38 | } 39 | -------------------------------------------------------------------------------- /pkg/webhook/mediatype.go: -------------------------------------------------------------------------------- 1 | package webhook 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | ) 7 | 8 | const ( 9 | mediaTypeFormat = "application/external.dns.webhook+json;" 10 | supportedMediaVersions = "1" 11 | ) 12 | 13 | var mediaTypeVersion1 = mediaTypeVersion("1") 14 | 15 | type mediaType string 16 | 17 | func mediaTypeVersion(v string) mediaType { 18 | return mediaType(mediaTypeFormat + "version=" + v) 19 | } 20 | 21 | func (m mediaType) Is(headerValue string) bool { 22 | return string(m) == headerValue 23 | } 24 | 25 | func checkAndGetMediaTypeHeaderValue(value string) (string, error) { 26 | for _, v := range strings.Split(supportedMediaVersions, ",") { 27 | if mediaTypeVersion(v).Is(value) { 28 | return v, nil 29 | } 30 | } 31 | 32 | supportedMediaTypesString := "" 33 | for i, v := range strings.Split(supportedMediaVersions, ",") { 34 | sep := "" 35 | if i < len(supportedMediaVersions)-1 { 36 | sep = ", " 37 | } 38 | supportedMediaTypesString += string(mediaTypeVersion(v)) + sep 39 | } 40 | 41 | return "", fmt.Errorf("unsupported media type version: '%s'. Supported media types are: '%s'", value, supportedMediaTypesString) 42 | } 43 | -------------------------------------------------------------------------------- /example/values.yaml: -------------------------------------------------------------------------------- 1 | logLevel: info 2 | policy: upsert-only 3 | provider: 4 | name: webhook 5 | webhook: 6 | image: 7 | repository: renanqts/external-dns-openwrt-webhook 8 | tag: v0.1.0 9 | livenessProbe: 10 | httpGet: 11 | path: /ping 12 | port: 8888 13 | initialDelaySeconds: 10 14 | timeoutSeconds: 5 15 | readinessProbe: 16 | httpGet: 17 | path: /ping 18 | port: 8888 19 | initialDelaySeconds: 10 20 | timeoutSeconds: 5 21 | # The following values are set to the default values 22 | env: 23 | - name: SHUTDOWN_TIMEOUT_SECONDS 24 | value: "5" 25 | - name: LOG_LEVEL 26 | value: info 27 | - name: LOG_STACK_TRACE 28 | value: "false" 29 | - name: LOG_ENCODING 30 | value: json 31 | - name: ROUTER_HEALTHCHECK_INTERVAL 32 | value: /ping 33 | - name: ROUTER_HEALTHCHECK_PORT 34 | value: "8888" 35 | - name: ROUTER_GIN_RELEASE_MODE 36 | value: "true" 37 | - name: PROVIDER_OPENWRT_LUCIRPC_HOSTNAME 38 | value: "192.168.1.1" 39 | - name: PROVIDER_OPENWRT_LUCIRPC_PORT 40 | value: "443" 41 | - name: PROVIDER_OPENWRT_LUCIRPC_SSL 42 | value: "true" 43 | - name: PROVIDER_OPENWRT_LUCIRPC_RPC_ID 44 | value: "1" 45 | - name: PROVIDER_OPENWRT_LUCIRPC_TIMEOUT 46 | value: "15" 47 | - name: PROVIDER_OPENWRT_LUCIRPC_INSECURE_SKIP_VERIFY 48 | value: "false" 49 | - name: PROVIDER_OPENWRT_LUCIRPC_AUTH_USERNAME 50 | value: root 51 | - name: PROVIDER_OPENWRT_LUCIRPC_AUTH_PASSWORD 52 | value: admin -------------------------------------------------------------------------------- /internal/mocks/lucirpc/lucirpc.go: -------------------------------------------------------------------------------- 1 | // Code generated by MockGen. DO NOT EDIT. 2 | // Source: github.com/renanqts/external-dns-openwrt-webhook/pkg/lucirpc (interfaces: LuciRPC) 3 | // 4 | // Generated by this command: 5 | // 6 | // mockgen -destination=../../internal/mocks/lucirpc/lucirpc.go -package=mocks . LuciRPC 7 | // 8 | 9 | // Package mocks is a generated GoMock package. 10 | package mocks 11 | 12 | import ( 13 | context "context" 14 | reflect "reflect" 15 | 16 | gomock "go.uber.org/mock/gomock" 17 | ) 18 | 19 | // MockLuciRPC is a mock of LuciRPC interface. 20 | type MockLuciRPC struct { 21 | ctrl *gomock.Controller 22 | recorder *MockLuciRPCMockRecorder 23 | isgomock struct{} 24 | } 25 | 26 | // MockLuciRPCMockRecorder is the mock recorder for MockLuciRPC. 27 | type MockLuciRPCMockRecorder struct { 28 | mock *MockLuciRPC 29 | } 30 | 31 | // NewMockLuciRPC creates a new mock instance. 32 | func NewMockLuciRPC(ctrl *gomock.Controller) *MockLuciRPC { 33 | mock := &MockLuciRPC{ctrl: ctrl} 34 | mock.recorder = &MockLuciRPCMockRecorder{mock} 35 | return mock 36 | } 37 | 38 | // EXPECT returns an object that allows the caller to indicate expected use. 39 | func (m *MockLuciRPC) EXPECT() *MockLuciRPCMockRecorder { 40 | return m.recorder 41 | } 42 | 43 | // Uci mocks base method. 44 | func (m *MockLuciRPC) Uci(arg0 context.Context, arg1 string, arg2 []string) (string, error) { 45 | m.ctrl.T.Helper() 46 | ret := m.ctrl.Call(m, "Uci", arg0, arg1, arg2) 47 | ret0, _ := ret[0].(string) 48 | ret1, _ := ret[1].(error) 49 | return ret0, ret1 50 | } 51 | 52 | // Uci indicates an expected call of Uci. 53 | func (mr *MockLuciRPCMockRecorder) Uci(arg0, arg1, arg2 any) *gomock.Call { 54 | mr.mock.ctrl.T.Helper() 55 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Uci", reflect.TypeOf((*MockLuciRPC)(nil).Uci), arg0, arg1, arg2) 56 | } 57 | -------------------------------------------------------------------------------- /pkg/router/router.go: -------------------------------------------------------------------------------- 1 | package router 2 | 3 | import ( 4 | "context" 5 | "net/http" 6 | "time" 7 | 8 | "github.com/Depado/ginprom" 9 | ginzap "github.com/gin-contrib/zap" 10 | "github.com/gin-gonic/gin" 11 | "github.com/renanqts/external-dns-openwrt-webhook/pkg/logger" 12 | "go.uber.org/zap" 13 | ) 14 | 15 | const ( 16 | metrics_namespace = "external_dns_openwrt_webhook" 17 | metrics_gin_subsystem = "gin" 18 | metrics_path = "/metrics" 19 | ) 20 | 21 | type Router struct { 22 | config *Config 23 | engine *gin.Engine 24 | srv *http.Server 25 | } 26 | 27 | func New(config *Config) (*Router, error) { 28 | if config.Gin.ReleaseMode { 29 | gin.SetMode(gin.ReleaseMode) 30 | } 31 | 32 | r := gin.New() 33 | r.Use(ginzap.GinzapWithConfig(logger.Log, &ginzap.Config{ 34 | TimeFormat: time.RFC3339, 35 | UTC: true, 36 | SkipPaths: []string{metrics_path, config.HealthCheckPath}, 37 | })) 38 | r.Use(ginzap.RecoveryWithZap(logger.Log, true)) 39 | 40 | r.GET(config.HealthCheckPath, func(c *gin.Context) { 41 | c.JSON(http.StatusOK, gin.H{}) 42 | }) 43 | 44 | p := ginprom.New( 45 | ginprom.Engine(r), 46 | ginprom.Namespace(metrics_namespace), 47 | ginprom.Subsystem(metrics_gin_subsystem), 48 | ) 49 | r.Use(p.Instrument()) 50 | 51 | return &Router{ 52 | config: config, 53 | engine: r, 54 | srv: &http.Server{ 55 | Addr: ":" + config.Port, 56 | Handler: r, 57 | }, 58 | }, nil 59 | } 60 | 61 | func (r *Router) Run() error { 62 | logger.Log.Info("starting http server", zap.String("port", r.config.Port)) 63 | if err := r.srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { 64 | return err 65 | } 66 | 67 | return nil 68 | } 69 | 70 | func (r *Router) Shutdown(ctx context.Context) error { 71 | logger.Log.Debug("shutting down http server") 72 | if err := r.srv.Shutdown(ctx); err != nil { 73 | return err 74 | } 75 | logger.Log.Info("http server stopped") 76 | return nil 77 | } 78 | 79 | func (r *Router) GetEngine() *gin.Engine { 80 | return r.engine 81 | } 82 | -------------------------------------------------------------------------------- /cmd/webhook/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "os" 6 | "os/signal" 7 | "syscall" 8 | "time" 9 | 10 | "github.com/gin-gonic/gin" 11 | "github.com/renanqts/external-dns-openwrt-webhook/internal/provider" 12 | "github.com/renanqts/external-dns-openwrt-webhook/pkg/config" 13 | "github.com/renanqts/external-dns-openwrt-webhook/pkg/logger" 14 | "github.com/renanqts/external-dns-openwrt-webhook/pkg/router" 15 | "github.com/renanqts/external-dns-openwrt-webhook/pkg/webhook" 16 | "go.uber.org/zap" 17 | ) 18 | 19 | func main() { 20 | cfg := defaultConfig() 21 | if err := config.Read(cfg); err != nil { 22 | panic(err) 23 | } 24 | 25 | if err := logger.Init(cfg.Log); err != nil { 26 | panic(err) 27 | } 28 | 29 | provider, err := provider.New(cfg.Provider) 30 | if err != nil { 31 | logger.Log.Fatal("failed to setup provider", zap.Error(err)) 32 | } 33 | 34 | router, err := router.New(cfg.Router) 35 | if err != nil { 36 | logger.Log.Fatal("failed to setup router", zap.Error(err)) 37 | } 38 | 39 | webhook := webhook.New(provider) 40 | setupRoutes(router.GetEngine(), webhook) 41 | 42 | go func() { 43 | if err = router.Run(); err != nil { 44 | logger.Log.Fatal("failed to start server", zap.Error(err)) 45 | } 46 | }() 47 | 48 | sigChan := make(chan os.Signal, 1) 49 | signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM) 50 | <-sigChan 51 | logger.Log.Info("termination signal received, shutting down...") 52 | 53 | ctx, cancel := context.WithTimeout(context.Background(), time.Duration(cfg.ShutodwnTimeout)*time.Second) 54 | if err := router.Shutdown(ctx); err != nil { 55 | logger.Log.Error("failed to shutdown server", zap.Error(err)) 56 | } 57 | 58 | cancel() 59 | <-ctx.Done() 60 | 61 | logger.Log.Info("service shutdown completed") 62 | } 63 | 64 | func setupRoutes(r *gin.Engine, webhook *webhook.Webhook) { 65 | apiGroup := r.Group("/") 66 | apiGroup.GET("/", webhook.Negotiate) 67 | apiGroup.GET("/records", webhook.Records) 68 | apiGroup.POST("/records", webhook.ApplyChanges) 69 | apiGroup.POST("/adjustendpoints", webhook.AdjustEndpoints) 70 | } 71 | -------------------------------------------------------------------------------- /internal/provider/provider.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/renanqts/external-dns-openwrt-webhook/pkg/logger" 7 | "github.com/renanqts/external-dns-openwrt-webhook/pkg/openwrt" 8 | "go.uber.org/zap" 9 | "sigs.k8s.io/external-dns/endpoint" 10 | "sigs.k8s.io/external-dns/plan" 11 | "sigs.k8s.io/external-dns/provider" 12 | ) 13 | 14 | const defaultTTL = 300 15 | 16 | type Provider struct { 17 | provider.BaseProvider 18 | 19 | openwrt openwrt.OpenWRT 20 | } 21 | 22 | func New(cfg *Config) (*Provider, error) { 23 | opwrt, err := openwrt.New(cfg.OpenWRT) 24 | if err != nil { 25 | return nil, err 26 | } 27 | 28 | return &Provider{ 29 | openwrt: opwrt, 30 | }, nil 31 | } 32 | 33 | func (p *Provider) ApplyChanges(ctx context.Context, changes *plan.Changes) error { 34 | logger.Log.Debug("apply changes", zap.Any("changes", changes)) 35 | _, err := p.openwrt.GetDNSRecords(ctx) 36 | if err != nil { 37 | return err 38 | } 39 | 40 | if err := p.openwrt.SetDNSRecords(ctx, endpoints2DNSRecords(changes.Create)); err != nil { 41 | return err 42 | } 43 | 44 | if err := p.openwrt.UpdateDNSRecords(ctx, endpoints2DNSRecords(changes.UpdateOld)); err != nil { 45 | return err 46 | } 47 | 48 | if err := p.openwrt.UpdateDNSRecords(ctx, endpoints2DNSRecords(changes.UpdateNew)); err != nil { 49 | return err 50 | } 51 | 52 | if err := p.openwrt.DeleteDNSRecords(ctx, endpoints2DNSRecords(changes.Delete)); err != nil { 53 | return err 54 | } 55 | 56 | return nil 57 | } 58 | 59 | func (p *Provider) Records(ctx context.Context) ([]*endpoint.Endpoint, error) { 60 | records, err := p.openwrt.GetDNSRecords(ctx) 61 | if err != nil { 62 | return nil, err 63 | } 64 | 65 | return dnsRecords2Endpoints(records), nil 66 | } 67 | 68 | func dnsRecords2Endpoints(dnsRecords map[string]openwrt.DNSRecord) []*endpoint.Endpoint { 69 | var endpoints []*endpoint.Endpoint 70 | 71 | for _, dnsRecord := range dnsRecords { 72 | var ep endpoint.Endpoint 73 | 74 | switch dnsRecord.Type { 75 | case "A": 76 | ep.RecordType = endpoint.RecordTypeA 77 | ep.DNSName = dnsRecord.Name 78 | ep.Targets = endpoint.Targets{dnsRecord.IP} 79 | case "CNAME": 80 | ep.RecordType = endpoint.RecordTypeCNAME 81 | ep.DNSName = dnsRecord.CName 82 | ep.Targets = endpoint.Targets{dnsRecord.Target} 83 | default: 84 | continue 85 | } 86 | 87 | ep.RecordTTL = defaultTTL 88 | endpoints = append(endpoints, &ep) 89 | } 90 | 91 | return endpoints 92 | } 93 | 94 | func endpoints2DNSRecords(endpoints []*endpoint.Endpoint) []openwrt.DNSRecord { 95 | var dnsRecords []openwrt.DNSRecord 96 | 97 | for _, ep := range endpoints { 98 | var dnsRecord openwrt.DNSRecord 99 | 100 | switch ep.RecordType { 101 | case endpoint.RecordTypeA: 102 | dnsRecord.Type = "A" 103 | dnsRecord.Name = ep.DNSName 104 | dnsRecord.IP = ep.Targets[0] 105 | case endpoint.RecordTypeCNAME: 106 | dnsRecord.Type = "CNAME" 107 | dnsRecord.CName = ep.DNSName 108 | dnsRecord.Target = ep.Targets[0] 109 | default: 110 | continue 111 | } 112 | dnsRecords = append(dnsRecords, dnsRecord) 113 | } 114 | 115 | return dnsRecords 116 | } 117 | -------------------------------------------------------------------------------- /internal/provider/provider_test.go: -------------------------------------------------------------------------------- 1 | package provider 2 | 3 | import ( 4 | "testing" 5 | 6 | . "github.com/onsi/ginkgo/v2" 7 | . "github.com/onsi/gomega" 8 | "github.com/renanqts/external-dns-openwrt-webhook/pkg/logger" 9 | "github.com/renanqts/external-dns-openwrt-webhook/pkg/openwrt" 10 | "sigs.k8s.io/external-dns/endpoint" 11 | ) 12 | 13 | func TestProvider(t *testing.T) { 14 | RegisterFailHandler(Fail) 15 | RunSpecs(t, "Provider Suite") 16 | defer GinkgoRecover() 17 | } 18 | 19 | var _ = BeforeSuite(func() { 20 | if err := logger.Init(&logger.Config{ 21 | Level: "debug", 22 | Encoding: "console", 23 | }); err != nil { 24 | panic(err) 25 | } 26 | }) 27 | 28 | var _ = AfterSuite(func() { 29 | _ = logger.Log.Sync() 30 | }) 31 | 32 | var _ = Describe("Provider Suite", func() { 33 | Context("endpoints records", func() { 34 | It("should be converted to dns records", func() { 35 | records := []struct { 36 | Name string `json:"name"` 37 | Type string `json:"type"` 38 | Target string `json:"target"` 39 | }{ 40 | { 41 | Name: "a.foobar.com", 42 | Type: "A", 43 | Target: "1.1.1.1", 44 | }, 45 | { 46 | Name: "b.foobar.com", 47 | Type: "CNAME", 48 | Target: "c.foobar.com", 49 | }, 50 | } 51 | 52 | var endpoints []*endpoint.Endpoint 53 | for _, record := range records { 54 | endpoints = append(endpoints, &endpoint.Endpoint{ 55 | DNSName: record.Name, 56 | RecordTTL: defaultTTL, 57 | RecordType: record.Type, 58 | Targets: []string{record.Target}, 59 | }) 60 | } 61 | dnsRecords := endpoints2DNSRecords(endpoints) 62 | for index, dnsRecord := range dnsRecords { 63 | switch dnsRecord.Type { 64 | case "A": 65 | Expect(dnsRecord.Name).To(Equal(records[index].Name)) 66 | Expect(dnsRecord.IP).To(Equal(records[index].Target)) 67 | case "CNAME": 68 | Expect(dnsRecord.CName).To(Equal(records[index].Name)) 69 | Expect(dnsRecord.Target).To(Equal(records[index].Target)) 70 | } 71 | } 72 | }) 73 | 74 | It("dns records to endpoint", func() { 75 | records := []struct { 76 | Name string `json:"name"` 77 | Type string `json:"type"` 78 | Target string `json:"target"` 79 | }{ 80 | { 81 | Name: "a.foobar.com", 82 | Type: "A", 83 | Target: "1.1.1.1", 84 | }, 85 | { 86 | Name: "b.foobar.com", 87 | Type: "CNAME", 88 | Target: "c.foobar.com", 89 | }, 90 | } 91 | 92 | dnsRecords := make(map[string]openwrt.DNSRecord) 93 | for _, record := range records { 94 | switch record.Type { 95 | case "A": 96 | dnsRecords[record.Name] = openwrt.DNSRecord{ 97 | Name: record.Name, 98 | Type: record.Type, 99 | IP: record.Target, 100 | } 101 | case "CNAME": 102 | dnsRecords[record.Name] = openwrt.DNSRecord{ 103 | Type: record.Type, 104 | Target: record.Target, 105 | CName: record.Name, 106 | } 107 | } 108 | } 109 | 110 | endpoints := dnsRecords2Endpoints(dnsRecords) 111 | for index, record := range records { 112 | Expect(endpoints[index].DNSName).To(Equal(record.Name)) 113 | Expect(endpoints[index].Targets[0]).To(Equal(record.Target)) 114 | Expect(endpoints[index].RecordType).To(Equal(record.Type)) 115 | } 116 | }) 117 | }) 118 | }) 119 | -------------------------------------------------------------------------------- /internal/mocks/openwrt/openwrt.go: -------------------------------------------------------------------------------- 1 | // Code generated by MockGen. DO NOT EDIT. 2 | // Source: github.com/renanqts/external-dns-openwrt-webhook/pkg/openwrt (interfaces: OpenWRT) 3 | // 4 | // Generated by this command: 5 | // 6 | // mockgen -destination=../../internal/mocks/openwrt/openwrt.go -package=mocks . OpenWRT 7 | // 8 | 9 | // Package mocks is a generated GoMock package. 10 | package mocks 11 | 12 | import ( 13 | context "context" 14 | reflect "reflect" 15 | 16 | openwrt "github.com/renanqts/external-dns-openwrt-webhook/pkg/openwrt" 17 | gomock "go.uber.org/mock/gomock" 18 | ) 19 | 20 | // MockOpenWRT is a mock of OpenWRT interface. 21 | type MockOpenWRT struct { 22 | ctrl *gomock.Controller 23 | recorder *MockOpenWRTMockRecorder 24 | isgomock struct{} 25 | } 26 | 27 | // MockOpenWRTMockRecorder is the mock recorder for MockOpenWRT. 28 | type MockOpenWRTMockRecorder struct { 29 | mock *MockOpenWRT 30 | } 31 | 32 | // NewMockOpenWRT creates a new mock instance. 33 | func NewMockOpenWRT(ctrl *gomock.Controller) *MockOpenWRT { 34 | mock := &MockOpenWRT{ctrl: ctrl} 35 | mock.recorder = &MockOpenWRTMockRecorder{mock} 36 | return mock 37 | } 38 | 39 | // EXPECT returns an object that allows the caller to indicate expected use. 40 | func (m *MockOpenWRT) EXPECT() *MockOpenWRTMockRecorder { 41 | return m.recorder 42 | } 43 | 44 | // DeleteDNSRecords mocks base method. 45 | func (m *MockOpenWRT) DeleteDNSRecords(arg0 context.Context, arg1 []openwrt.DNSRecord) error { 46 | m.ctrl.T.Helper() 47 | ret := m.ctrl.Call(m, "DeleteDNSRecords", arg0, arg1) 48 | ret0, _ := ret[0].(error) 49 | return ret0 50 | } 51 | 52 | // DeleteDNSRecords indicates an expected call of DeleteDNSRecords. 53 | func (mr *MockOpenWRTMockRecorder) DeleteDNSRecords(arg0, arg1 any) *gomock.Call { 54 | mr.mock.ctrl.T.Helper() 55 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteDNSRecords", reflect.TypeOf((*MockOpenWRT)(nil).DeleteDNSRecords), arg0, arg1) 56 | } 57 | 58 | // GetDNSRecords mocks base method. 59 | func (m *MockOpenWRT) GetDNSRecords(arg0 context.Context) (map[string]openwrt.DNSRecord, error) { 60 | m.ctrl.T.Helper() 61 | ret := m.ctrl.Call(m, "GetDNSRecords", arg0) 62 | ret0, _ := ret[0].(map[string]openwrt.DNSRecord) 63 | ret1, _ := ret[1].(error) 64 | return ret0, ret1 65 | } 66 | 67 | // GetDNSRecords indicates an expected call of GetDNSRecords. 68 | func (mr *MockOpenWRTMockRecorder) GetDNSRecords(arg0 any) *gomock.Call { 69 | mr.mock.ctrl.T.Helper() 70 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDNSRecords", reflect.TypeOf((*MockOpenWRT)(nil).GetDNSRecords), arg0) 71 | } 72 | 73 | // SetDNSRecords mocks base method. 74 | func (m *MockOpenWRT) SetDNSRecords(arg0 context.Context, arg1 []openwrt.DNSRecord) error { 75 | m.ctrl.T.Helper() 76 | ret := m.ctrl.Call(m, "SetDNSRecords", arg0, arg1) 77 | ret0, _ := ret[0].(error) 78 | return ret0 79 | } 80 | 81 | // SetDNSRecords indicates an expected call of SetDNSRecords. 82 | func (mr *MockOpenWRTMockRecorder) SetDNSRecords(arg0, arg1 any) *gomock.Call { 83 | mr.mock.ctrl.T.Helper() 84 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetDNSRecords", reflect.TypeOf((*MockOpenWRT)(nil).SetDNSRecords), arg0, arg1) 85 | } 86 | 87 | // UpdateDNSRecords mocks base method. 88 | func (m *MockOpenWRT) UpdateDNSRecords(arg0 context.Context, arg1 []openwrt.DNSRecord) error { 89 | m.ctrl.T.Helper() 90 | ret := m.ctrl.Call(m, "UpdateDNSRecords", arg0, arg1) 91 | ret0, _ := ret[0].(error) 92 | return ret0 93 | } 94 | 95 | // UpdateDNSRecords indicates an expected call of UpdateDNSRecords. 96 | func (mr *MockOpenWRTMockRecorder) UpdateDNSRecords(arg0, arg1 any) *gomock.Call { 97 | mr.mock.ctrl.T.Helper() 98 | return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateDNSRecords", reflect.TypeOf((*MockOpenWRT)(nil).UpdateDNSRecords), arg0, arg1) 99 | } 100 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/renanqts/external-dns-openwrt-webhook 2 | 3 | go 1.23.4 4 | 5 | require ( 6 | github.com/Depado/ginprom v1.8.1 7 | github.com/gin-contrib/zap v1.1.4 8 | github.com/gin-gonic/gin v1.10.0 9 | github.com/mitchellh/mapstructure v1.5.0 10 | github.com/onsi/ginkgo/v2 v2.22.2 11 | github.com/onsi/gomega v1.36.2 12 | github.com/spf13/viper v1.19.0 13 | go.uber.org/mock v0.5.0 14 | go.uber.org/zap v1.27.0 15 | sigs.k8s.io/external-dns v0.15.1 16 | ) 17 | 18 | require ( 19 | github.com/aws/aws-sdk-go-v2/service/route53 v1.46.3 // indirect 20 | github.com/aws/smithy-go v1.22.1 // indirect 21 | github.com/beorn7/perks v1.0.1 // indirect 22 | github.com/bytedance/sonic v1.12.1 // indirect 23 | github.com/bytedance/sonic/loader v0.2.0 // indirect 24 | github.com/cespare/xxhash/v2 v2.3.0 // indirect 25 | github.com/cloudwego/base64x v0.1.4 // indirect 26 | github.com/cloudwego/iasm v0.2.0 // indirect 27 | github.com/fsnotify/fsnotify v1.7.0 // indirect 28 | github.com/fxamacker/cbor/v2 v2.7.0 // indirect 29 | github.com/gabriel-vasile/mimetype v1.4.5 // indirect 30 | github.com/gin-contrib/sse v0.1.0 // indirect 31 | github.com/go-logr/logr v1.4.2 // indirect 32 | github.com/go-playground/locales v0.14.1 // indirect 33 | github.com/go-playground/universal-translator v0.18.1 // indirect 34 | github.com/go-playground/validator/v10 v10.22.0 // indirect 35 | github.com/go-task/slim-sprig/v3 v3.0.0 // indirect 36 | github.com/goccy/go-json v0.10.4 // indirect 37 | github.com/gogo/protobuf v1.3.2 // indirect 38 | github.com/google/go-cmp v0.6.0 // indirect 39 | github.com/google/gofuzz v1.2.0 // indirect 40 | github.com/google/pprof v0.0.0-20250208200701-d0013a598941 // indirect 41 | github.com/hashicorp/hcl v1.0.0 // indirect 42 | github.com/json-iterator/go v1.1.12 // indirect 43 | github.com/klauspost/compress v1.17.9 // indirect 44 | github.com/klauspost/cpuid/v2 v2.2.8 // indirect 45 | github.com/leodido/go-urn v1.4.0 // indirect 46 | github.com/magiconair/properties v1.8.7 // indirect 47 | github.com/mattn/go-isatty v0.0.20 // indirect 48 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 49 | github.com/modern-go/reflect2 v1.0.2 // indirect 50 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect 51 | github.com/pelletier/go-toml/v2 v2.2.2 // indirect 52 | github.com/prometheus/client_golang v1.20.5 // indirect 53 | github.com/prometheus/client_model v0.6.1 // indirect 54 | github.com/prometheus/common v0.55.0 // indirect 55 | github.com/prometheus/procfs v0.15.1 // indirect 56 | github.com/sagikazarmark/locafero v0.4.0 // indirect 57 | github.com/sagikazarmark/slog-shim v0.1.0 // indirect 58 | github.com/sirupsen/logrus v1.9.3 // indirect 59 | github.com/sourcegraph/conc v0.3.0 // indirect 60 | github.com/spf13/afero v1.11.0 // indirect 61 | github.com/spf13/cast v1.6.0 // indirect 62 | github.com/spf13/pflag v1.0.5 // indirect 63 | github.com/subosito/gotenv v1.6.0 // indirect 64 | github.com/twitchyliquid64/golang-asm v0.15.1 // indirect 65 | github.com/ugorji/go/codec v1.2.12 // indirect 66 | github.com/x448/float16 v0.8.4 // indirect 67 | go.uber.org/multierr v1.11.0 // indirect 68 | golang.org/x/arch v0.9.0 // indirect 69 | golang.org/x/crypto v0.33.0 // indirect 70 | golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect 71 | golang.org/x/net v0.35.0 // indirect 72 | golang.org/x/sys v0.30.0 // indirect 73 | golang.org/x/text v0.22.0 // indirect 74 | golang.org/x/tools v0.30.0 // indirect 75 | google.golang.org/protobuf v1.36.1 // indirect 76 | gopkg.in/inf.v0 v0.9.1 // indirect 77 | gopkg.in/ini.v1 v1.67.0 // indirect 78 | gopkg.in/yaml.v3 v3.0.1 // indirect 79 | k8s.io/apimachinery v0.32.0 // indirect 80 | k8s.io/klog/v2 v2.130.1 // indirect 81 | k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect 82 | sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect 83 | sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect 84 | sigs.k8s.io/yaml v1.4.0 // indirect 85 | ) 86 | -------------------------------------------------------------------------------- /pkg/lucirpc/lucirpc.go: -------------------------------------------------------------------------------- 1 | package lucirpc 2 | 3 | //go:generate mockgen -destination=../../internal/mocks/lucirpc/lucirpc.go -package=mocks . LuciRPC 4 | 5 | import ( 6 | "bytes" 7 | "context" 8 | "crypto/tls" 9 | "encoding/json" 10 | "errors" 11 | "fmt" 12 | "io" 13 | "net" 14 | "net/http" 15 | "strconv" 16 | "time" 17 | 18 | "github.com/renanqts/external-dns-openwrt-webhook/pkg/logger" 19 | "go.uber.org/zap" 20 | ) 21 | 22 | const ( 23 | rpcPath = "/cgi-bin/luci/rpc/" 24 | authPath = rpcPath + "auth" 25 | uciPath = rpcPath + "uci" 26 | 27 | methodLogin = "login" 28 | ) 29 | 30 | var ( 31 | ErrRpcLoginFail = errors.New("rpc: login fail") 32 | 33 | ErrHttpUnauthenticated = errors.New("http: Unauthenticated") 34 | ErrHttpUnauthorized = errors.New("http: Unauthorized") 35 | ErrHttpForbidden = errors.New("http: Forbidden") 36 | ) 37 | 38 | type LuciRPC interface { 39 | Uci(context.Context, string, []string) (string, error) 40 | } 41 | 42 | type Payload struct { 43 | ID int `json:"id"` 44 | Method string `json:"method"` 45 | Params []string `json:"params"` 46 | } 47 | 48 | type Response struct { 49 | ID int `json:"id"` 50 | Result interface{} `json:"result"` 51 | Error interface{} `json:"error"` 52 | } 53 | 54 | type lucirpc struct { 55 | config *Config 56 | token string 57 | httpClient *http.Client 58 | } 59 | 60 | func New(config *Config) (LuciRPC, error) { 61 | httpClient := &http.Client{ 62 | Transport: &http.Transport{ 63 | TLSClientConfig: &tls.Config{ 64 | InsecureSkipVerify: config.InsecureSkipVerify, 65 | }, 66 | Dial: (&net.Dialer{ 67 | Timeout: time.Duration(config.Timeout) * time.Second, 68 | KeepAlive: time.Duration(config.Timeout) * time.Second, 69 | }).Dial, 70 | }, 71 | } 72 | 73 | return &lucirpc{ 74 | config: config, 75 | httpClient: httpClient, 76 | }, nil 77 | } 78 | 79 | func (c *lucirpc) Uci(ctx context.Context, method string, params []string) (string, error) { 80 | return c.rpcWithAuth(ctx, uciPath, method, params) 81 | } 82 | 83 | func (c *lucirpc) auth(ctx context.Context) error { 84 | token, err := c.rpc(ctx, authPath, methodLogin, []string{c.config.Auth.Username, c.config.Auth.Password}) 85 | if err != nil { 86 | logger.Log.Error("rpc: login fail", zap.Error(err)) 87 | return err 88 | } 89 | 90 | // OpenWRT JSON RPC response of wrong username and password 91 | // {"id":1,"result":null,"error":null} 92 | if token == "null" { 93 | return ErrRpcLoginFail 94 | } 95 | 96 | c.token = token 97 | return nil 98 | } 99 | 100 | func (c *lucirpc) rpc(ctx context.Context, path, method string, params []string) (string, error) { 101 | data, err := json.Marshal(Payload{ 102 | ID: c.config.RpcID, 103 | Method: method, 104 | Params: params, 105 | }) 106 | if err != nil { 107 | logger.Log.Error("marshal fail", zap.Error(err)) 108 | return "", err 109 | } 110 | 111 | url := c.getUri(path, method) 112 | respBody, err := c.call(ctx, url, data) 113 | if err != nil { 114 | logger.Log.Error("call fail", zap.Error(err)) 115 | return "", err 116 | } 117 | 118 | var response Response 119 | if err := json.Unmarshal(respBody, &response); err != nil { 120 | logger.Log.Error("unmarshal fail", zap.Error(err)) 121 | return "", err 122 | } 123 | 124 | if response.Error != nil { 125 | return "", parseError(response.Error) 126 | } 127 | 128 | if response.Result != nil { 129 | return parseString(response.Result) 130 | } 131 | 132 | return "", nil 133 | } 134 | 135 | func (c *lucirpc) getUri(path, method string) string { 136 | logger.Log.Debug("uri", zap.String("path", path), zap.String("method", method), zap.String("token", c.token)) 137 | proto := "https://" 138 | if !c.config.SSL { 139 | proto = "http://" 140 | } 141 | 142 | url := proto + c.config.Hostname + ":" + strconv.Itoa(c.config.Port) + path 143 | if method != methodLogin && c.token != "" { 144 | url = url + "?auth=" + c.token 145 | } 146 | 147 | return url 148 | } 149 | 150 | func (c *lucirpc) call(ctx context.Context, url string, postBody []byte) ([]byte, error) { 151 | logger.Log.Debug("call", zap.String("url", url), zap.String("postBody", string(postBody))) 152 | body := bytes.NewReader(postBody) 153 | req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, body) 154 | if err != nil { 155 | return nil, err 156 | } 157 | 158 | req.Header.Set("Content-Type", "application/json") 159 | resp, err := c.httpClient.Do(req) 160 | if err != nil { 161 | return nil, err 162 | } 163 | defer resp.Body.Close() 164 | 165 | var respBody []byte 166 | respBody, err = io.ReadAll(resp.Body) 167 | if resp.StatusCode > 226 { 168 | return respBody, c.httpError(resp.StatusCode) 169 | } 170 | 171 | return respBody, err 172 | } 173 | 174 | func (c *lucirpc) httpError(code int) error { 175 | if code == 401 { 176 | return ErrHttpUnauthorized 177 | } 178 | 179 | if code == 403 { 180 | return ErrHttpForbidden 181 | } 182 | 183 | return fmt.Errorf("http status code: %d", code) 184 | } 185 | 186 | func (c *lucirpc) rpcWithAuth(ctx context.Context, path, method string, params []string) (string, error) { 187 | result, err := c.rpc(ctx, path, method, params) 188 | if err == nil { 189 | return result, nil 190 | } 191 | 192 | if err != ErrHttpUnauthorized && err != ErrHttpForbidden { 193 | return "", err 194 | } 195 | 196 | logger.Log.Info("re-authenticate") 197 | if err = c.auth(ctx); err != nil { 198 | return "", err 199 | } 200 | 201 | return c.rpc(ctx, path, method, params) 202 | } 203 | 204 | func parseString(obj interface{}) (string, error) { 205 | if obj == nil { 206 | return "", errors.New("nil object cannot be parsed") 207 | } 208 | 209 | var result string 210 | if _, ok := obj.(string); ok { 211 | result = fmt.Sprintf("%v", obj) 212 | return result, nil 213 | } 214 | 215 | jsonBytes, err := json.Marshal(obj) 216 | if err == nil { 217 | result = string(jsonBytes) 218 | } 219 | 220 | return result, err 221 | } 222 | 223 | func parseError(obj interface{}) error { 224 | result, err := parseString(obj) 225 | if err != nil { 226 | return err 227 | } 228 | 229 | return errors.New(result) 230 | } 231 | -------------------------------------------------------------------------------- /pkg/lucirpc/lucirpc_test.go: -------------------------------------------------------------------------------- 1 | package lucirpc 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "net/http" 7 | "net/http/httptest" 8 | "net/url" 9 | "strconv" 10 | "testing" 11 | 12 | . "github.com/onsi/ginkgo/v2" 13 | . "github.com/onsi/gomega" 14 | "github.com/renanqts/external-dns-openwrt-webhook/pkg/logger" 15 | ) 16 | 17 | func TestLuciRPC(t *testing.T) { 18 | RegisterFailHandler(Fail) 19 | RunSpecs(t, "Luci RPC Suite") 20 | defer GinkgoRecover() 21 | } 22 | 23 | var _ = BeforeSuite(func() { 24 | if err := logger.Init(&logger.Config{ 25 | Level: "debug", 26 | Encoding: "console", 27 | }); err != nil { 28 | panic(err) 29 | } 30 | }) 31 | 32 | var _ = AfterSuite(func() { 33 | _ = logger.Log.Sync() 34 | }) 35 | 36 | var _ = Describe("Luci RPC", func() { 37 | var ctx context.Context 38 | 39 | BeforeEach(func() { 40 | ctx = context.Background() 41 | }) 42 | 43 | Context("auth", func() { 44 | It("should be login", func() { 45 | mux := http.NewServeMux() 46 | ts := httptest.NewServer(mux) 47 | defer ts.Close() 48 | u, err := url.Parse(ts.URL) 49 | Expect(err).To(BeNil()) 50 | port, err := strconv.Atoi(u.Port()) 51 | Expect(err).To(BeNil()) 52 | hostname := u.Hostname() 53 | 54 | config := DefaultConfig() 55 | Expect(config).ToNot(BeNil()) 56 | config.SSL = false 57 | config.Hostname = hostname 58 | config.Port = port 59 | 60 | client := lucirpc{ 61 | config: config, 62 | httpClient: ts.Client(), 63 | } 64 | Expect(client).ToNot(BeNil()) 65 | 66 | mux.HandleFunc(authPath, func(w http.ResponseWriter, r *http.Request) { 67 | Expect(r.Method).To(Equal(http.MethodPost)) 68 | Expect(r.URL.Path).To(Equal(authPath)) 69 | w.WriteHeader(http.StatusAccepted) 70 | _, err = w.Write([]byte(`{"result":"foobar"}`)) 71 | Expect(err).To(BeNil()) 72 | }) 73 | 74 | err = client.auth(ctx) 75 | Expect(err).To(BeNil()) 76 | Expect(client.token).To(Equal("foobar")) 77 | }) 78 | 79 | It("should be unauthorized", func() { 80 | mux := http.NewServeMux() 81 | ts := httptest.NewServer(mux) 82 | defer ts.Close() 83 | u, err := url.Parse(ts.URL) 84 | Expect(err).To(BeNil()) 85 | port, err := strconv.Atoi(u.Port()) 86 | Expect(err).To(BeNil()) 87 | hostname := u.Hostname() 88 | 89 | config := DefaultConfig() 90 | Expect(config).ToNot(BeNil()) 91 | config.SSL = false 92 | config.Hostname = hostname 93 | config.Port = port 94 | 95 | client := lucirpc{ 96 | config: config, 97 | httpClient: ts.Client(), 98 | } 99 | Expect(client).ToNot(BeNil()) 100 | 101 | mux.HandleFunc(authPath, func(w http.ResponseWriter, r *http.Request) { 102 | w.WriteHeader(http.StatusUnauthorized) 103 | }) 104 | 105 | err = client.auth(ctx) 106 | Expect(err).To(Equal(ErrHttpUnauthorized)) 107 | Expect(client.token).To(Equal("")) 108 | }) 109 | 110 | It("should be forbidden", func() { 111 | mux := http.NewServeMux() 112 | ts := httptest.NewServer(mux) 113 | defer ts.Close() 114 | u, err := url.Parse(ts.URL) 115 | Expect(err).To(BeNil()) 116 | port, err := strconv.Atoi(u.Port()) 117 | Expect(err).To(BeNil()) 118 | hostname := u.Hostname() 119 | 120 | config := DefaultConfig() 121 | Expect(config).ToNot(BeNil()) 122 | config.SSL = false 123 | config.Hostname = hostname 124 | config.Port = port 125 | 126 | client := lucirpc{ 127 | config: config, 128 | httpClient: ts.Client(), 129 | } 130 | Expect(client).ToNot(BeNil()) 131 | 132 | mux.HandleFunc(authPath, func(w http.ResponseWriter, r *http.Request) { 133 | w.WriteHeader(http.StatusForbidden) 134 | }) 135 | 136 | err = client.auth(ctx) 137 | Expect(err).To(Equal(ErrHttpForbidden)) 138 | Expect(client.token).To(Equal("")) 139 | }) 140 | 141 | It("should fail", func() { 142 | mux := http.NewServeMux() 143 | ts := httptest.NewServer(mux) 144 | defer ts.Close() 145 | u, err := url.Parse(ts.URL) 146 | Expect(err).To(BeNil()) 147 | port, err := strconv.Atoi(u.Port()) 148 | Expect(err).To(BeNil()) 149 | hostname := u.Hostname() 150 | 151 | config := DefaultConfig() 152 | Expect(config).ToNot(BeNil()) 153 | config.SSL = false 154 | config.Hostname = hostname 155 | config.Port = port 156 | 157 | client := lucirpc{ 158 | config: config, 159 | httpClient: ts.Client(), 160 | } 161 | Expect(client).ToNot(BeNil()) 162 | 163 | mux.HandleFunc(authPath, func(w http.ResponseWriter, r *http.Request) { 164 | w.WriteHeader(http.StatusInternalServerError) 165 | }) 166 | 167 | err = client.auth(ctx) 168 | Expect(err).To(Equal(fmt.Errorf("http status code: 500"))) 169 | }) 170 | 171 | }) 172 | 173 | Context("uci", func() { 174 | It("should get", func() { 175 | mux := http.NewServeMux() 176 | ts := httptest.NewServer(mux) 177 | defer ts.Close() 178 | u, err := url.Parse(ts.URL) 179 | Expect(err).To(BeNil()) 180 | port, err := strconv.Atoi(u.Port()) 181 | Expect(err).To(BeNil()) 182 | hostname := u.Hostname() 183 | 184 | config := DefaultConfig() 185 | Expect(config).ToNot(BeNil()) 186 | config.Hostname = hostname 187 | config.Port = port 188 | config.SSL = false 189 | 190 | client := lucirpc{ 191 | config: config, 192 | httpClient: ts.Client(), 193 | } 194 | Expect(client).ToNot(BeNil()) 195 | 196 | expectedToken := "foobar" 197 | authCalled := false 198 | mux.HandleFunc(authPath, func(w http.ResponseWriter, r *http.Request) { 199 | w.WriteHeader(http.StatusOK) 200 | _, err = w.Write([]byte(`{"result":"` + expectedToken + `"}`)) 201 | Expect(err).To(BeNil()) 202 | }) 203 | 204 | expectedResp := "helloworld" 205 | mux.HandleFunc(uciPath, func(w http.ResponseWriter, r *http.Request) { 206 | // auth should be called 207 | if !authCalled { 208 | authCalled = true 209 | w.WriteHeader(http.StatusUnauthorized) 210 | return 211 | } 212 | 213 | Expect(r.URL.Path).To(Equal(uciPath)) 214 | Expect(r.RequestURI).To(Equal(uciPath + "?auth=" + expectedToken)) 215 | 216 | w.WriteHeader(http.StatusOK) 217 | _, err = w.Write([]byte(`{"result":"` + expectedResp + `"}`)) 218 | Expect(err).To(BeNil()) 219 | }) 220 | 221 | resp, err := client.Uci(ctx, "get", []string{"network.lan.ipaddr"}) 222 | Expect(err).To(BeNil()) 223 | Expect(resp).To(Equal(expectedResp)) 224 | Expect(authCalled).To(BeTrue()) 225 | Expect(client.token).To(Equal(expectedToken)) 226 | }) 227 | }) 228 | }) 229 | -------------------------------------------------------------------------------- /pkg/webhook/webhook.go: -------------------------------------------------------------------------------- 1 | package webhook 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "net/http" 7 | 8 | "github.com/gin-gonic/gin" 9 | "github.com/renanqts/external-dns-openwrt-webhook/pkg/logger" 10 | "go.uber.org/zap" 11 | "sigs.k8s.io/external-dns/endpoint" 12 | "sigs.k8s.io/external-dns/plan" 13 | "sigs.k8s.io/external-dns/provider" 14 | ) 15 | 16 | const ( 17 | contentTypeHeader = "Content-Type" 18 | contentTypePlaintext = "text/plain" 19 | acceptHeader = "Accept" 20 | varyHeader = "Vary" 21 | 22 | errorAcceptHeader = "client must provide an accept header" 23 | errorContentType = "client must provide a content type" 24 | ) 25 | 26 | type Webhook struct { 27 | provider provider.Provider 28 | } 29 | 30 | func New(provider provider.Provider) *Webhook { 31 | return &Webhook{provider: provider} 32 | } 33 | 34 | func (w *Webhook) contentTypeHeaderCheck(c *gin.Context) error { 35 | header := c.GetHeader(contentTypeHeader) 36 | if len(header) == 0 { 37 | c.Header(contentTypeHeader, contentTypePlaintext) 38 | c.AbortWithStatusJSON(http.StatusNotAcceptable, gin.H{"error": errorContentType}) 39 | 40 | logger.Log.Error(errorContentType, zap.String("header", header)) 41 | return errors.New(errorContentType) 42 | } 43 | 44 | return w.headerCheck(header, c) 45 | } 46 | 47 | func (w *Webhook) acceptHeaderCheck(c *gin.Context) error { 48 | header := c.GetHeader(acceptHeader) 49 | if len(header) == 0 { 50 | c.Header(contentTypeHeader, contentTypePlaintext) 51 | c.AbortWithStatusJSON(http.StatusNotAcceptable, gin.H{"error": errorAcceptHeader}) 52 | 53 | logger.Log.Error(errorAcceptHeader, zap.String("header", header)) 54 | return errors.New(errorAcceptHeader) 55 | } 56 | 57 | return w.headerCheck(header, c) 58 | } 59 | 60 | func (w *Webhook) headerCheck(header string, c *gin.Context) error { 61 | // as we support only one media type version, we can ignore the returned value 62 | if _, err := checkAndGetMediaTypeHeaderValue(header); err != nil { 63 | c.Header(contentTypeHeader, contentTypePlaintext) 64 | c.AbortWithStatusJSON(http.StatusUnsupportedMediaType, gin.H{"error": "client must provide a valid versioned media type"}) 65 | 66 | logger.Log.Error("client must provide a valid versioned media type", zap.String("header", header), zap.Error(err)) 67 | return err 68 | } 69 | 70 | return nil 71 | } 72 | 73 | func (w *Webhook) Records(c *gin.Context) { 74 | if err := w.acceptHeaderCheck(c); err != nil { 75 | logger.Log.Error("accept header check failed", zap.Error(err)) 76 | return 77 | } 78 | 79 | records, err := w.provider.Records(c.Request.Context()) 80 | if err != nil { 81 | logger.Log.Error("error getting records", zap.Error(err)) 82 | c.AbortWithStatus(http.StatusInternalServerError) 83 | return 84 | } 85 | 86 | c.Header(contentTypeHeader, string(mediaTypeVersion1)) 87 | c.Header(varyHeader, contentTypeHeader) 88 | if err = json.NewEncoder(c.Writer).Encode(records); err != nil { 89 | logger.Log.Error("error encoding records", zap.Error(err)) 90 | c.AbortWithStatus(http.StatusInternalServerError) 91 | return 92 | } 93 | } 94 | 95 | func (w *Webhook) ApplyChanges(c *gin.Context) { 96 | if err := w.contentTypeHeaderCheck(c); err != nil { 97 | logger.Log.Error("content type header check failed", zap.Error(err)) 98 | return 99 | } 100 | 101 | var changes plan.Changes 102 | if err := json.NewDecoder(c.Request.Body).Decode(&changes); err != nil { 103 | logger.Log.Error("error decoding changes", zap.Error(err)) 104 | c.Header(contentTypeHeader, contentTypePlaintext) 105 | c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "error decoding changes"}) 106 | return 107 | } 108 | 109 | logger.Log.Debug("requesting apply changes", zap.Int("create", len(changes.Create)), 110 | zap.Int("update_old", len(changes.UpdateOld)), zap.Int("update_new", len(changes.UpdateNew)), 111 | zap.Int("delete", len(changes.Delete))) 112 | 113 | if err := w.provider.ApplyChanges(c.Request.Context(), &changes); err != nil { 114 | logger.Log.Error("error when applying changes", zap.Error(err)) 115 | c.Header(contentTypeHeader, contentTypePlaintext) 116 | c.AbortWithStatus(http.StatusInternalServerError) 117 | return 118 | } 119 | 120 | // TODO: check if it is required 121 | c.Status(http.StatusNoContent) 122 | } 123 | 124 | func (w *Webhook) AdjustEndpoints(c *gin.Context) { 125 | if err := w.contentTypeHeaderCheck(c); err != nil { 126 | logger.Log.Error("content type header check failed", zap.Error(err)) 127 | return 128 | } 129 | 130 | if err := w.acceptHeaderCheck(c); err != nil { 131 | logger.Log.Error("accept header check failed", zap.Error(err)) 132 | return 133 | } 134 | 135 | var pve []*endpoint.Endpoint 136 | if err := json.NewDecoder(c.Request.Body).Decode(&pve); err != nil { 137 | c.Header(contentTypeHeader, contentTypePlaintext) 138 | c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "error decoding request body"}) 139 | return 140 | } 141 | 142 | logger.Log.Debug("webhook adjust endpoints", zap.Int("endpoints", len(pve))) 143 | c.Header(contentTypeHeader, contentTypePlaintext) 144 | pve, err := w.provider.AdjustEndpoints(pve) 145 | if err != nil { 146 | c.Header(varyHeader, contentTypeHeader) 147 | logger.Log.Error("error adjusting endpoints", zap.Error(err)) 148 | c.AbortWithStatus(http.StatusInternalServerError) 149 | return 150 | } 151 | 152 | c.Header(contentTypeHeader, string(mediaTypeVersion1)) 153 | c.Header(varyHeader, contentTypeHeader) 154 | 155 | out, err := json.Marshal(&pve) 156 | if err != nil { 157 | logger.Log.Error("error encoding adjusted endpoints", zap.Error(err)) 158 | } 159 | 160 | if _, err := c.Writer.Write(out); err != nil { 161 | logger.Log.Error("error writing response", zap.Error(err)) 162 | } 163 | 164 | logger.Log.Debug("adjusted endpoints", zap.Int("endpoints", len(pve))) 165 | } 166 | 167 | func (w *Webhook) Negotiate(c *gin.Context) { 168 | if err := w.acceptHeaderCheck(c); err != nil { 169 | logger.Log.Error("accept header check failed", zap.Error(err)) 170 | return 171 | } 172 | 173 | b, err := json.Marshal(w.provider.GetDomainFilter()) 174 | if err != nil { 175 | logger.Log.Error("error marshaling domain filter", zap.Error(err)) 176 | c.AbortWithStatus(http.StatusInternalServerError) 177 | return 178 | } 179 | 180 | c.Header(contentTypeHeader, string(mediaTypeVersion1)) 181 | 182 | _, err = c.Writer.Write(b) 183 | if err != nil { 184 | logger.Log.Error("error writing response", zap.Error(err)) 185 | c.AbortWithStatus(http.StatusInternalServerError) 186 | return 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /pkg/openwrt/openwrt.go: -------------------------------------------------------------------------------- 1 | package openwrt 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "fmt" 7 | 8 | "github.com/renanqts/external-dns-openwrt-webhook/pkg/logger" 9 | "github.com/renanqts/external-dns-openwrt-webhook/pkg/lucirpc" 10 | "go.uber.org/zap" 11 | ) 12 | 13 | //go:generate mockgen -destination=../../internal/mocks/openwrt/openwrt.go -package=mocks . OpenWRT 14 | 15 | type OpenWRT interface { 16 | GetDNSRecords(context.Context) (map[string]DNSRecord, error) 17 | SetDNSRecords(context.Context, []DNSRecord) error 18 | UpdateDNSRecords(context.Context, []DNSRecord) error 19 | DeleteDNSRecords(context.Context, []DNSRecord) error 20 | } 21 | 22 | type openWRT struct { 23 | lucirpc lucirpc.LuciRPC 24 | } 25 | 26 | func New(cfg *Config) (OpenWRT, error) { 27 | lrcp, err := lucirpc.New(cfg.LuciRPC) 28 | if err != nil { 29 | return nil, err 30 | } 31 | 32 | return &openWRT{ 33 | lucirpc: lrcp, 34 | }, nil 35 | } 36 | 37 | func (o *openWRT) GetDNSRecords(ctx context.Context) (map[string]DNSRecord, error) { 38 | result, err := o.lucirpc.Uci(ctx, "get_all", []string{"dhcp"}) 39 | if err != nil { 40 | return nil, err 41 | } 42 | 43 | var records map[string]DNSRecord 44 | err = json.Unmarshal([]byte(result), &records) 45 | if err != nil { 46 | return nil, err 47 | } 48 | 49 | for key, record := range records { 50 | switch record.Type { 51 | case "domain": 52 | records[key] = DNSRecord{ 53 | Type: "A", 54 | IP: record.IP, 55 | Name: record.Name, 56 | } 57 | case "cname": 58 | records[key] = DNSRecord{ 59 | Type: "CNAME", 60 | CName: record.CName, 61 | Target: record.Target, 62 | } 63 | default: 64 | // it does not care about other types 65 | logger.Log.Debug("ignoring record", zap.String("type", record.Type)) 66 | delete(records, key) 67 | } 68 | } 69 | 70 | logger.Log.Debug("current records", zap.Any("records", records)) 71 | return records, nil 72 | } 73 | 74 | func (o *openWRT) SetDNSRecords(ctx context.Context, records []DNSRecord) error { 75 | for _, record := range records { 76 | switch { 77 | case record.Type == "A": 78 | if err := o.addA(ctx, record); err != nil { 79 | return err 80 | } 81 | case record.Type == "CNAME": 82 | if err := o.addCName(ctx, record); err != nil { 83 | return err 84 | } 85 | default: 86 | return fmt.Errorf("invalid record type: %s", record.Type) 87 | } 88 | } 89 | 90 | if _, err := o.lucirpc.Uci(ctx, "commit", []string{"dhcp"}); err != nil { 91 | return err 92 | } 93 | logger.Log.Debug("set records", zap.Any("records", records)) 94 | 95 | return nil 96 | } 97 | 98 | func (o *openWRT) UpdateDNSRecords(ctx context.Context, updateRecords []DNSRecord) error { 99 | currentRecords, err := o.GetDNSRecords(ctx) 100 | if err != nil { 101 | return err 102 | } 103 | 104 | for cfg, currentRecord := range currentRecords { 105 | for index, updateRecord := range updateRecords { 106 | if updateRecord.Type == "A" && updateRecord.Name == currentRecord.Name { 107 | _, err := o.lucirpc.Uci(ctx, "delete", []string{"dhcp", cfg}) 108 | if err != nil { 109 | return err 110 | } 111 | 112 | if err := o.addA(ctx, updateRecord); err != nil { 113 | return err 114 | } 115 | 116 | logger.Log.Debug("updated record", zap.Any("record", updateRecord)) 117 | updateRecords = append(updateRecords[:index], updateRecords[index+1:]...) 118 | } 119 | 120 | if updateRecord.Type == "CNAME" && updateRecord.CName == currentRecord.CName { 121 | _, err := o.lucirpc.Uci(ctx, "delete", []string{"dhcp", cfg}) 122 | if err != nil { 123 | return err 124 | } 125 | 126 | if err := o.addCName(ctx, updateRecord); err != nil { 127 | return err 128 | } 129 | 130 | logger.Log.Debug("updated record", zap.Any("record", updateRecord)) 131 | updateRecords = append(updateRecords[:index], updateRecords[index+1:]...) 132 | } 133 | } 134 | } 135 | 136 | if len(updateRecords) > 0 { 137 | return fmt.Errorf("records not found: %v", updateRecords) 138 | } 139 | 140 | if _, err := o.lucirpc.Uci(ctx, "commit", []string{"dhcp"}); err != nil { 141 | return err 142 | } 143 | 144 | return nil 145 | } 146 | 147 | func (o *openWRT) DeleteDNSRecords(ctx context.Context, deleteRecords []DNSRecord) error { 148 | currentRecords, err := o.GetDNSRecords(ctx) 149 | if err != nil { 150 | return err 151 | } 152 | 153 | for cfg, currentRecord := range currentRecords { 154 | for index, deleteRecord := range deleteRecords { 155 | if (deleteRecord.Type == "A" && deleteRecord.Name == currentRecord.Name) || 156 | (deleteRecord.Type == "CNAME" && deleteRecord.CName == currentRecord.CName) { 157 | _, err := o.lucirpc.Uci(ctx, "delete", []string{"dhcp", cfg}) 158 | if err != nil { 159 | return err 160 | } 161 | logger.Log.Debug("deleted record", zap.Any("record", currentRecord)) 162 | deleteRecords = append(deleteRecords[:index], deleteRecords[index+1:]...) 163 | } 164 | } 165 | } 166 | 167 | if len(deleteRecords) > 0 { 168 | return fmt.Errorf("records not found: %v", deleteRecords) 169 | } 170 | 171 | // should we remove even when records not found? 172 | if _, err := o.lucirpc.Uci(ctx, "commit", []string{"dhcp"}); err != nil { 173 | return err 174 | } 175 | 176 | return nil 177 | } 178 | 179 | func (o *openWRT) addA(ctx context.Context, record DNSRecord) error { 180 | if record.Type != "a" && record.Type != "A" { 181 | return fmt.Errorf("invalid record type: %s", record.Type) 182 | } 183 | 184 | if record.Name == "" { 185 | return fmt.Errorf("name is required") 186 | } 187 | 188 | if record.IP == "" { 189 | return fmt.Errorf("ip is required") 190 | } 191 | 192 | cfg, err := o.lucirpc.Uci(ctx, "add", []string{"dhcp", "domain"}) 193 | if err != nil { 194 | return err 195 | } 196 | 197 | if _, err := o.lucirpc.Uci(ctx, "set", []string{"dhcp", cfg, "name", record.Name}); err != nil { 198 | return err 199 | } 200 | 201 | if _, err := o.lucirpc.Uci(ctx, "set", []string{"dhcp", cfg, "ip", record.IP}); err != nil { 202 | return err 203 | } 204 | 205 | return nil 206 | } 207 | 208 | func (o *openWRT) addCName(ctx context.Context, record DNSRecord) error { 209 | if record.Type != "cname" && record.Type != "CNAME" { 210 | return fmt.Errorf("invalid record type: %s", record.Type) 211 | } 212 | 213 | if record.CName == "" { 214 | return fmt.Errorf("cname is required") 215 | } 216 | 217 | if record.Target == "" { 218 | return fmt.Errorf("target is required") 219 | } 220 | 221 | cfg, err := o.lucirpc.Uci(ctx, "add", []string{"dhcp", "cname"}) 222 | if err != nil { 223 | return err 224 | } 225 | 226 | if _, err := o.lucirpc.Uci(ctx, "set", []string{"dhcp", cfg, "cname", record.CName}); err != nil { 227 | return err 228 | } 229 | 230 | if _, err := o.lucirpc.Uci(ctx, "set", []string{"dhcp", cfg, "target", record.Target}); err != nil { 231 | return err 232 | } 233 | 234 | return nil 235 | } 236 | -------------------------------------------------------------------------------- /pkg/openwrt/openwrt_test.go: -------------------------------------------------------------------------------- 1 | package openwrt 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "testing" 7 | 8 | . "github.com/onsi/ginkgo/v2" 9 | . "github.com/onsi/gomega" 10 | mocks "github.com/renanqts/external-dns-openwrt-webhook/internal/mocks/lucirpc" 11 | "github.com/renanqts/external-dns-openwrt-webhook/pkg/logger" 12 | "go.uber.org/mock/gomock" 13 | ) 14 | 15 | func TestOpenWRT(t *testing.T) { 16 | RegisterFailHandler(Fail) 17 | RunSpecs(t, "OpenWRT Suite") 18 | defer GinkgoRecover() 19 | } 20 | 21 | var _ = BeforeSuite(func() { 22 | if err := logger.Init(&logger.Config{ 23 | Level: "debug", 24 | Encoding: "console", 25 | }); err != nil { 26 | panic(err) 27 | } 28 | }) 29 | 30 | var _ = AfterSuite(func() { 31 | _ = logger.Log.Sync() 32 | }) 33 | 34 | var _ = Describe("OpenWRT", func() { 35 | var ( 36 | ctx context.Context 37 | mockCtrl *gomock.Controller 38 | mockLuciRPC *mocks.MockLuciRPC 39 | ) 40 | 41 | BeforeEach(func() { 42 | ctx = context.Background() 43 | mockCtrl = gomock.NewController(GinkgoT()) 44 | mockLuciRPC = mocks.NewMockLuciRPC(mockCtrl) 45 | }) 46 | 47 | AfterEach(func() { 48 | mockCtrl.Finish() 49 | }) 50 | 51 | Context("Get DNS", func() { 52 | It("get all records", func() { 53 | expectedJson, err := json.Marshal(map[string]DNSRecord{ 54 | "x": { 55 | Type: "domain", 56 | Name: "foobar", 57 | IP: "1.1.1.1", 58 | }, 59 | "y": { 60 | Type: "cname", 61 | CName: "foobar", 62 | Target: "bar.foo.com", 63 | }, 64 | "z": { 65 | Type: "whatever", 66 | }, 67 | }) 68 | Expect(err).To(BeNil()) 69 | mockLuciRPC.EXPECT().Uci(ctx, "get_all", []string{"dhcp"}).Return(string(expectedJson), nil) 70 | o := openWRT{ 71 | lucirpc: mockLuciRPC, 72 | } 73 | resultDNS, err := o.GetDNSRecords(ctx) 74 | Expect(err).To(BeNil()) 75 | Expect(resultDNS).ToNot(BeNil()) 76 | Expect(resultDNS).To(Equal(map[string]DNSRecord{ 77 | "x": { 78 | Type: "A", 79 | Name: "foobar", 80 | IP: "1.1.1.1", 81 | }, 82 | "y": { 83 | Type: "CNAME", 84 | CName: "foobar", 85 | Target: "bar.foo.com", 86 | }, 87 | })) 88 | }) 89 | }) 90 | 91 | Context("Set DNS", func() { 92 | It("set A record with success", func() { 93 | cfg := "foobar" 94 | ip := "1.1.1.1" 95 | name := "foo.bar.com" 96 | 97 | mockLuciRPC.EXPECT().Uci(ctx, "add", []string{"dhcp", "domain"}).Return(cfg, nil) 98 | mockLuciRPC.EXPECT().Uci(ctx, "set", []string{"dhcp", cfg, "name", name}).Return("", nil) 99 | mockLuciRPC.EXPECT().Uci(ctx, "set", []string{"dhcp", cfg, "ip", ip}).Return("", nil) 100 | mockLuciRPC.EXPECT().Uci(ctx, "commit", []string{"dhcp"}).Return("", nil) 101 | 102 | o := openWRT{ 103 | lucirpc: mockLuciRPC, 104 | } 105 | err := o.SetDNSRecords(ctx, []DNSRecord{ 106 | { 107 | Type: "A", 108 | IP: ip, 109 | Name: name, 110 | }, 111 | }) 112 | Expect(err).To(BeNil()) 113 | }) 114 | 115 | It("A without name", func() { 116 | o := openWRT{} 117 | err := o.SetDNSRecords(ctx, []DNSRecord{ 118 | { 119 | Type: "A", 120 | IP: "1.1.1.1", 121 | }, 122 | }) 123 | Expect(err).ToNot(BeNil()) 124 | Expect(err.Error()).To(Equal("name is required")) 125 | }) 126 | 127 | It("A without ip", func() { 128 | o := openWRT{} 129 | err := o.SetDNSRecords(ctx, []DNSRecord{ 130 | { 131 | Type: "A", 132 | Name: "foobar", 133 | }, 134 | }) 135 | Expect(err).ToNot(BeNil()) 136 | Expect(err.Error()).To(Equal("ip is required")) 137 | }) 138 | 139 | It("set CNAME record", func() { 140 | cfg := "foobar" 141 | cname := "foo.bar.com" 142 | target := "bar.foo.com" 143 | 144 | mockLuciRPC.EXPECT().Uci(ctx, "add", []string{"dhcp", "cname"}).Return(cfg, nil) 145 | mockLuciRPC.EXPECT().Uci(ctx, "set", []string{"dhcp", cfg, "cname", cname}).Return("", nil) 146 | mockLuciRPC.EXPECT().Uci(ctx, "set", []string{"dhcp", cfg, "target", target}).Return("", nil) 147 | mockLuciRPC.EXPECT().Uci(ctx, "commit", []string{"dhcp"}).Return("", nil) 148 | 149 | o := openWRT{ 150 | lucirpc: mockLuciRPC, 151 | } 152 | err := o.SetDNSRecords(ctx, []DNSRecord{ 153 | { 154 | Type: "CNAME", 155 | CName: cname, 156 | Target: target, 157 | }, 158 | }) 159 | Expect(err).To(BeNil()) 160 | }) 161 | 162 | It("CNAME without cname", func() { 163 | o := openWRT{} 164 | err := o.SetDNSRecords(ctx, []DNSRecord{ 165 | { 166 | Type: "CNAME", 167 | Target: "foo.bar.com", 168 | }, 169 | }) 170 | Expect(err).ToNot(BeNil()) 171 | Expect(err.Error()).To(Equal("cname is required")) 172 | }) 173 | 174 | It("CNAME without target", func() { 175 | o := openWRT{} 176 | err := o.SetDNSRecords(ctx, []DNSRecord{ 177 | { 178 | Type: "CNAME", 179 | CName: "foobar", 180 | }, 181 | }) 182 | Expect(err).ToNot(BeNil()) 183 | Expect(err.Error()).To(Equal("target is required")) 184 | }) 185 | }) 186 | 187 | Context("Update DNS", func() { 188 | It("update A record", func() { 189 | cfg := "x" 190 | dnsName := "happy.com" 191 | updatedIP := "2.2.2.2" 192 | 193 | expectedCurrentDNSRecords := map[string]DNSRecord{ 194 | cfg: { 195 | Type: "domain", 196 | Name: dnsName, 197 | IP: "1.1.1.1", 198 | }, 199 | "y": { 200 | Type: "cname", 201 | CName: "foo.bar.com", 202 | Target: "bar.foo.com", 203 | }, 204 | } 205 | 206 | expectedCurrentJson, err := json.Marshal(expectedCurrentDNSRecords) 207 | Expect(err).To(BeNil()) 208 | mockLuciRPC.EXPECT().Uci(ctx, "get_all", []string{"dhcp"}).Return(string(expectedCurrentJson), nil) 209 | mockLuciRPC.EXPECT().Uci(ctx, "delete", []string{"dhcp", cfg}).Return("", nil) 210 | mockLuciRPC.EXPECT().Uci(ctx, "add", []string{"dhcp", "domain"}).Return(cfg, nil) 211 | mockLuciRPC.EXPECT().Uci(ctx, "set", []string{"dhcp", cfg, "name", dnsName}).Return("", nil) 212 | mockLuciRPC.EXPECT().Uci(ctx, "set", []string{"dhcp", cfg, "ip", updatedIP}).Return("", nil) 213 | mockLuciRPC.EXPECT().Uci(ctx, "commit", []string{"dhcp"}).Return("", nil) 214 | 215 | o := openWRT{ 216 | lucirpc: mockLuciRPC, 217 | } 218 | err = o.UpdateDNSRecords(ctx, []DNSRecord{ 219 | { 220 | Type: "A", 221 | Name: dnsName, 222 | IP: updatedIP, 223 | }, 224 | }) 225 | Expect(err).To(BeNil()) 226 | }) 227 | 228 | It("update CNAME record", func() { 229 | cfg := "y" 230 | cname := "happy.com" 231 | updatedTarget := "foo.bar.com" 232 | 233 | expectedCurrentDNSRecords := map[string]DNSRecord{ 234 | "x": { 235 | Type: "domain", 236 | Name: "happy.com", 237 | IP: "1.1.1.1", 238 | }, 239 | cfg: { 240 | Type: "cname", 241 | CName: cname, 242 | Target: "bar.foo.com", 243 | }, 244 | } 245 | 246 | expectedCurrentJson, err := json.Marshal(expectedCurrentDNSRecords) 247 | Expect(err).To(BeNil()) 248 | mockLuciRPC.EXPECT().Uci(ctx, "get_all", []string{"dhcp"}).Return(string(expectedCurrentJson), nil) 249 | mockLuciRPC.EXPECT().Uci(ctx, "delete", []string{"dhcp", cfg}).Return("", nil) 250 | mockLuciRPC.EXPECT().Uci(ctx, "add", []string{"dhcp", "cname"}).Return(cfg, nil) 251 | mockLuciRPC.EXPECT().Uci(ctx, "set", []string{"dhcp", cfg, "cname", cname}).Return("", nil) 252 | mockLuciRPC.EXPECT().Uci(ctx, "set", []string{"dhcp", cfg, "target", updatedTarget}).Return("", nil) 253 | mockLuciRPC.EXPECT().Uci(ctx, "commit", []string{"dhcp"}).Return("", nil) 254 | 255 | o := openWRT{ 256 | lucirpc: mockLuciRPC, 257 | } 258 | err = o.UpdateDNSRecords(ctx, []DNSRecord{ 259 | { 260 | Type: "CNAME", 261 | CName: cname, 262 | Target: updatedTarget, 263 | }, 264 | }) 265 | Expect(err).To(BeNil()) 266 | }) 267 | 268 | It("not found", func() { 269 | expectedCurrentDNSRecords := map[string]DNSRecord{ 270 | "x": { 271 | Type: "A", 272 | Name: "happy.com", 273 | IP: "1.1.1.1", 274 | }, 275 | "y": { 276 | Type: "CNAME", 277 | CName: "foo.bar.com", 278 | Target: "bar.foo.com", 279 | }, 280 | } 281 | 282 | expectedCurrentJson, err := json.Marshal(expectedCurrentDNSRecords) 283 | Expect(err).To(BeNil()) 284 | mockLuciRPC.EXPECT().Uci(ctx, "get_all", []string{"dhcp"}).Return(string(expectedCurrentJson), nil) 285 | 286 | o := openWRT{ 287 | lucirpc: mockLuciRPC, 288 | } 289 | err = o.UpdateDNSRecords(ctx, []DNSRecord{ 290 | { 291 | Type: "CNAME", 292 | CName: "whatever", 293 | Target: "3.3.3.3", 294 | }, 295 | }) 296 | Expect(err).ToNot(BeNil()) 297 | Expect(err.Error()).To(Equal("records not found: [{CNAME whatever 3.3.3.3}]")) 298 | }) 299 | }) 300 | 301 | Context("Delete DNS", func() { 302 | It("delete A record", func() { 303 | cfg := "x" 304 | name := "happy.com" 305 | ip := "2.2.2.2" 306 | 307 | expectedCurrentDNSRecords := map[string]DNSRecord{ 308 | cfg: { 309 | Type: "domain", 310 | Name: name, 311 | IP: ip, 312 | }, 313 | "y": { 314 | Type: "cname", 315 | CName: "foo.bar.com", 316 | Target: "bar.foo.com", 317 | }, 318 | } 319 | 320 | expectedCurrentJson, err := json.Marshal(expectedCurrentDNSRecords) 321 | Expect(err).To(BeNil()) 322 | mockLuciRPC.EXPECT().Uci(ctx, "get_all", []string{"dhcp"}).Return(string(expectedCurrentJson), nil) 323 | mockLuciRPC.EXPECT().Uci(ctx, "delete", []string{"dhcp", cfg}).Return("", nil) 324 | mockLuciRPC.EXPECT().Uci(ctx, "commit", []string{"dhcp"}).Return("", nil) 325 | 326 | o := openWRT{ 327 | lucirpc: mockLuciRPC, 328 | } 329 | err = o.DeleteDNSRecords(ctx, []DNSRecord{ 330 | { 331 | Type: "A", 332 | Name: name, 333 | IP: ip, 334 | }, 335 | }) 336 | Expect(err).To(BeNil()) 337 | }) 338 | 339 | It("delete CNAME record", func() { 340 | cfg := "y" 341 | cname := "happy.com" 342 | target := "foo.bar.com" 343 | 344 | expectedCurrentDNSRecords := map[string]DNSRecord{ 345 | "x": { 346 | Type: "domain", 347 | Name: "happy.com", 348 | IP: "1.1.1.1", 349 | }, 350 | cfg: { 351 | Type: "cname", 352 | CName: cname, 353 | Target: target, 354 | }, 355 | } 356 | 357 | expectedCurrentJson, err := json.Marshal(expectedCurrentDNSRecords) 358 | Expect(err).To(BeNil()) 359 | mockLuciRPC.EXPECT().Uci(ctx, "get_all", []string{"dhcp"}).Return(string(expectedCurrentJson), nil) 360 | mockLuciRPC.EXPECT().Uci(ctx, "delete", []string{"dhcp", cfg}).Return("", nil) 361 | mockLuciRPC.EXPECT().Uci(ctx, "commit", []string{"dhcp"}).Return("", nil) 362 | 363 | o := openWRT{ 364 | lucirpc: mockLuciRPC, 365 | } 366 | err = o.DeleteDNSRecords(ctx, []DNSRecord{ 367 | { 368 | Type: "CNAME", 369 | CName: cname, 370 | Target: target, 371 | }, 372 | }) 373 | Expect(err).To(BeNil()) 374 | }) 375 | 376 | It("not found", func() { 377 | expectedCurrentDNSRecords := map[string]DNSRecord{ 378 | "x": { 379 | Type: "domain", 380 | Name: "happy.com", 381 | IP: "1.1.1.1", 382 | }, 383 | "y": { 384 | Type: "cname", 385 | CName: "foo.bar.com", 386 | Target: "bar.foo.com", 387 | }, 388 | } 389 | 390 | expectedCurrentJson, err := json.Marshal(expectedCurrentDNSRecords) 391 | Expect(err).To(BeNil()) 392 | mockLuciRPC.EXPECT().Uci(ctx, "get_all", []string{"dhcp"}).Return(string(expectedCurrentJson), nil) 393 | 394 | o := openWRT{ 395 | lucirpc: mockLuciRPC, 396 | } 397 | err = o.DeleteDNSRecords(ctx, []DNSRecord{ 398 | { 399 | Type: "CNAME", 400 | CName: "whatever", 401 | Target: "3.3.3.3", 402 | }, 403 | }) 404 | Expect(err).ToNot(BeNil()) 405 | Expect(err.Error()).To(Equal("records not found: [{CNAME whatever 3.3.3.3}]")) 406 | }) 407 | }) 408 | }) 409 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/Depado/ginprom v1.8.1 h1:lrQTddbRqlHq1j6SpJDySDumJlR7FEybzdX0PS3HXPc= 2 | github.com/Depado/ginprom v1.8.1/go.mod h1:9Z+ahPJLSeMndDfnDTfiuBn2SKVAuL2yvihApWzof9A= 3 | github.com/appleboy/gofight/v2 v2.1.2 h1:VOy3jow4vIK8BRQJoC/I9muxyYlJ2yb9ht2hZoS3rf4= 4 | github.com/appleboy/gofight/v2 v2.1.2/go.mod h1:frW+U1QZEdDgixycTj4CygQ48yLTUhplt43+Wczp3rw= 5 | github.com/aws/aws-sdk-go-v2/service/route53 v1.46.3 h1:pDBrvz7CMK381q5U+nPqtSQZZid5z1XH8lsI6kHNcSY= 6 | github.com/aws/aws-sdk-go-v2/service/route53 v1.46.3/go.mod h1:rDMeB13C/RS0/zw68RQD4LLiWChf5tZBKjEQmjtHa/c= 7 | github.com/aws/smithy-go v1.22.1 h1:/HPHZQ0g7f4eUeK6HKglFz8uwVfZKgoI25rb/J+dnro= 8 | github.com/aws/smithy-go v1.22.1/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= 9 | github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= 10 | github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= 11 | github.com/bytedance/sonic v1.12.1 h1:jWl5Qz1fy7X1ioY74WqO0KjAMtAGQs4sYnjiEBiyX24= 12 | github.com/bytedance/sonic v1.12.1/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk= 13 | github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= 14 | github.com/bytedance/sonic/loader v0.2.0 h1:zNprn+lsIP06C/IqCHs3gPQIvnvpKbbxyXQP1iU4kWM= 15 | github.com/bytedance/sonic/loader v0.2.0/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= 16 | github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= 17 | github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= 18 | github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= 19 | github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= 20 | github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= 21 | github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= 22 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 23 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 24 | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= 25 | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 26 | github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= 27 | github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= 28 | github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= 29 | github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= 30 | github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E= 31 | github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ= 32 | github.com/gabriel-vasile/mimetype v1.4.5 h1:J7wGKdGu33ocBOhGy0z653k/lFKLFDPJMG8Gql0kxn4= 33 | github.com/gabriel-vasile/mimetype v1.4.5/go.mod h1:ibHel+/kbxn9x2407k1izTA1S81ku1z/DlgOW2QE0M4= 34 | github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= 35 | github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= 36 | github.com/gin-contrib/zap v1.1.4 h1:xvxTybg6XBdNtcQLH3Tf0lFr4vhDkwzgLLrIGlNTqIo= 37 | github.com/gin-contrib/zap v1.1.4/go.mod h1:7lgEpe91kLbeJkwBTPgtVBy4zMa6oSBEcvj662diqKQ= 38 | github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= 39 | github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= 40 | github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= 41 | github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= 42 | github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= 43 | github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= 44 | github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= 45 | github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= 46 | github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= 47 | github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= 48 | github.com/go-playground/validator/v10 v10.22.0 h1:k6HsTZ0sTnROkhS//R0O+55JgM8C4Bx7ia+JlgcnOao= 49 | github.com/go-playground/validator/v10 v10.22.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= 50 | github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= 51 | github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= 52 | github.com/goccy/go-json v0.10.4 h1:JSwxQzIqKfmFX1swYPpUThQZp/Ka4wzJdK0LWVytLPM= 53 | github.com/goccy/go-json v0.10.4/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= 54 | github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= 55 | github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= 56 | github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 57 | github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= 58 | github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 59 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 60 | github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= 61 | github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 62 | github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad h1:a6HEuzUHeKH6hwfN/ZoQgRgVIWFJljSWa/zetS2WTvg= 63 | github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= 64 | github.com/google/pprof v0.0.0-20250208200701-d0013a598941 h1:43XjGa6toxLpeksjcxs1jIoIyr+vUfOqY2c6HB4bpoc= 65 | github.com/google/pprof v0.0.0-20250208200701-d0013a598941/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= 66 | github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= 67 | github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= 68 | github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= 69 | github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= 70 | github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= 71 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 72 | github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= 73 | github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= 74 | github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= 75 | github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM= 76 | github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= 77 | github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= 78 | github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= 79 | github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= 80 | github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 81 | github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 82 | github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= 83 | github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= 84 | github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= 85 | github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= 86 | github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= 87 | github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= 88 | github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= 89 | github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= 90 | github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= 91 | github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= 92 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 93 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= 94 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 95 | github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= 96 | github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= 97 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= 98 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= 99 | github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= 100 | github.com/onsi/ginkgo/v2 v2.22.2 h1:/3X8Panh8/WwhU/3Ssa6rCKqPLuAkVY2I0RoyDLySlU= 101 | github.com/onsi/ginkgo/v2 v2.22.2/go.mod h1:oeMosUL+8LtarXBHu/c0bx2D/K9zyQ6uX3cTyztHwsk= 102 | github.com/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8= 103 | github.com/onsi/gomega v1.36.2/go.mod h1:DdwyADRjrc825LhMEkD76cHR5+pUnjhUN8GlHlRPHzY= 104 | github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= 105 | github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= 106 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 107 | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= 108 | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 109 | github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y= 110 | github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= 111 | github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= 112 | github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= 113 | github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc= 114 | github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8= 115 | github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= 116 | github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= 117 | github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= 118 | github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= 119 | github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= 120 | github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= 121 | github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= 122 | github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= 123 | github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= 124 | github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= 125 | github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= 126 | github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= 127 | github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= 128 | github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= 129 | github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= 130 | github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= 131 | github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= 132 | github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 133 | github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI= 134 | github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg= 135 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 136 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 137 | github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 138 | github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= 139 | github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= 140 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 141 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 142 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 143 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 144 | github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= 145 | github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= 146 | github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= 147 | github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= 148 | github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= 149 | github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= 150 | github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= 151 | github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= 152 | github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= 153 | github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= 154 | github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= 155 | github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= 156 | github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= 157 | github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 158 | github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 159 | go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= 160 | go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= 161 | go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU= 162 | go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM= 163 | go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= 164 | go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= 165 | go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= 166 | go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= 167 | golang.org/x/arch v0.9.0 h1:ub9TgUInamJ8mrZIGlBG6/4TqWeMszd4N8lNorbrr6k= 168 | golang.org/x/arch v0.9.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= 169 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 170 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 171 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 172 | golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= 173 | golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= 174 | golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus= 175 | golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M= 176 | golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= 177 | golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= 178 | golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 179 | golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 180 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 181 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 182 | golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 183 | golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= 184 | golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= 185 | golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= 186 | golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8= 187 | golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk= 188 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 189 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 190 | golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 191 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 192 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 193 | golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 194 | golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 195 | golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 196 | golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 197 | golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= 198 | golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 199 | golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= 200 | golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 201 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 202 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 203 | golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= 204 | golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= 205 | golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= 206 | golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= 207 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 208 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 209 | golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= 210 | golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= 211 | golang.org/x/tools v0.28.0 h1:WuB6qZ4RPCQo5aP3WdKZS7i595EdWqWR8vqJTlwTVK8= 212 | golang.org/x/tools v0.28.0/go.mod h1:dcIOrVd3mfQKTgrDVQHqCPMWy6lnhfhtX3hLXYVLfRw= 213 | golang.org/x/tools v0.30.0 h1:BgcpHewrV5AUp2G9MebG4XPFI1E2W41zU1SaqVA9vJY= 214 | golang.org/x/tools v0.30.0/go.mod h1:c347cR/OJfw5TI+GfX7RUPNMdDRRbjvYTS0jPyvsVtY= 215 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 216 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 217 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 218 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 219 | google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk= 220 | google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= 221 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 222 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= 223 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= 224 | gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= 225 | gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= 226 | gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= 227 | gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= 228 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 229 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 230 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 231 | k8s.io/apimachinery v0.32.0 h1:cFSE7N3rmEEtv4ei5X6DaJPHHX0C+upp+v5lVPiEwpg= 232 | k8s.io/apimachinery v0.32.0/go.mod h1:GpHVgxoKlTxClKcteaeuF1Ul/lDVb74KpZcxcmLDElE= 233 | k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= 234 | k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= 235 | k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 h1:M3sRQVHv7vB20Xc2ybTt7ODCeFj6JSWYFzOFnYeS6Ro= 236 | k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= 237 | nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= 238 | sigs.k8s.io/external-dns v0.15.1 h1:7UXUtMrEuS4DZM/1A7gtuooJh2cIYSn3RiUX3buqPHs= 239 | sigs.k8s.io/external-dns v0.15.1/go.mod h1:wuDYInL5buZ56sqSXFc3Wj72diZ4Mw/i2UTL0nJBHYw= 240 | sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 h1:/Rv+M11QRah1itp8VhT6HoVx1Ray9eB4DBr+K+/sCJ8= 241 | sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3/go.mod h1:18nIHnGi6636UCz6m8i4DhaJ65T6EruyzmoQqI2BVDo= 242 | sigs.k8s.io/structured-merge-diff/v4 v4.4.2 h1:MdmvkGuXi/8io6ixD5wud3vOLwc1rj0aNqRlpuvjmwA= 243 | sigs.k8s.io/structured-merge-diff/v4 v4.4.2/go.mod h1:N8f93tFZh9U6vpxwRArLiikrE5/2tiu1w1AGfACIGE4= 244 | sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= 245 | sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= 246 | --------------------------------------------------------------------------------