Compare commits

...

187 Commits

Author SHA1 Message Date
Marc Brugger
3c58a8f091 Replace deprecated API endpoints (#326)
* extend query log config
* replace deprecated services
* replace more deprecated services
* implement equals for stats config
2024-04-02 20:31:47 +02:00
dependabot[bot]
4a62b80e75 Bump github.com/golangci/golangci-lint from 1.57.1 to 1.57.2 (#325)
Bumps [github.com/golangci/golangci-lint](https://github.com/golangci/golangci-lint) from 1.57.1 to 1.57.2.
- [Release notes](https://github.com/golangci/golangci-lint/releases)
- [Changelog](https://github.com/golangci/golangci-lint/blob/master/CHANGELOG.md)
- [Commits](https://github.com/golangci/golangci-lint/compare/v1.57.1...v1.57.2)

---
updated-dependencies:
- dependency-name: github.com/golangci/golangci-lint
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-01 06:46:21 +02:00
dependabot[bot]
52c1687d83 Bump the onsi group with 2 updates (#322)
Bumps the onsi group with 2 updates: [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) and [github.com/onsi/gomega](https://github.com/onsi/gomega).


Updates `github.com/onsi/ginkgo/v2` from 2.16.0 to 2.17.1
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.16.0...v2.17.1)

Updates `github.com/onsi/gomega` from 1.31.1 to 1.32.0
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.31.1...v1.32.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: onsi
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: onsi
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-25 07:03:08 +01:00
dependabot[bot]
238a0f46e0 Bump github.com/golangci/golangci-lint from 1.56.2 to 1.57.1 (#323)
Bumps [github.com/golangci/golangci-lint](https://github.com/golangci/golangci-lint) from 1.56.2 to 1.57.1.
- [Release notes](https://github.com/golangci/golangci-lint/releases)
- [Changelog](https://github.com/golangci/golangci-lint/blob/master/CHANGELOG.md)
- [Commits](https://github.com/golangci/golangci-lint/compare/v1.56.2...v1.57.1)

---
updated-dependencies:
- dependency-name: github.com/golangci/golangci-lint
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-25 07:02:59 +01:00
bakito
bbf5d2d178 skip upx for darwin 2024-03-24 18:58:19 +01:00
Marc Brugger
1c4ea24da1 Sanitize dns config (#321)
Sanitize dns config for misconfigurations
2024-03-24 18:51:07 +01:00
dependabot[bot]
f277460b9d Bump github.com/docker/docker (#318)
Bumps [github.com/docker/docker](https://github.com/docker/docker) from 24.0.7+incompatible to 24.0.9+incompatible.
- [Release notes](https://github.com/docker/docker/releases)
- [Commits](https://github.com/docker/docker/compare/v24.0.7...v24.0.9)

---
updated-dependencies:
- dependency-name: github.com/docker/docker
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-20 21:57:44 +01:00
dependabot[bot]
15c1643d34 Bump the k8s group with 2 updates (#316)
Bumps the k8s group with 2 updates: [k8s.io/apimachinery](https://github.com/kubernetes/apimachinery) and [k8s.io/code-generator](https://github.com/kubernetes/code-generator).


Updates `k8s.io/apimachinery` from 0.29.2 to 0.29.3
- [Commits](https://github.com/kubernetes/apimachinery/compare/v0.29.2...v0.29.3)

Updates `k8s.io/code-generator` from 0.29.2 to 0.29.3
- [Commits](https://github.com/kubernetes/code-generator/compare/v0.29.2...v0.29.3)

---
updated-dependencies:
- dependency-name: k8s.io/apimachinery
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: k8s
- dependency-name: k8s.io/code-generator
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: k8s
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-18 07:10:10 +01:00
dependabot[bot]
e7f0a05e1a Bump github.com/go-resty/resty/v2 from 2.9.1 to 2.12.0 (#317)
Bumps [github.com/go-resty/resty/v2](https://github.com/go-resty/resty) from 2.9.1 to 2.12.0.
- [Release notes](https://github.com/go-resty/resty/releases)
- [Commits](https://github.com/go-resty/resty/compare/v2.9.1...v2.12.0)

---
updated-dependencies:
- dependency-name: github.com/go-resty/resty/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-18 07:09:59 +01:00
dependabot[bot]
8506b5d5a5 Bump google.golang.org/protobuf from 1.32.0 to 1.33.0 (#315)
Bumps google.golang.org/protobuf from 1.32.0 to 1.33.0.

---
updated-dependencies:
- dependency-name: google.golang.org/protobuf
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-14 06:59:50 +01:00
dependabot[bot]
0d629127a9 Bump github.com/prometheus/client_golang from 1.17.0 to 1.19.0 (#314)
* Bump github.com/prometheus/client_golang from 1.17.0 to 1.19.0

Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.17.0 to 1.19.0.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.17.0...v1.19.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* go-jose.v2 v2.6.3

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: bakito <github@bakito.ch>
2024-03-12 20:03:12 +01:00
Marc Brugger
d6d8d2148d Implement metrics from adguard-exporter (#303)
* implement metrics
2024-03-12 19:48:29 +01:00
Areg Vrtanesyan
5a3f2004bc Update file.go to load from default .adguardhome-sync.yaml file (#313)
* Updateing file.go to load from default .adguardhome-sync.yaml file

* Update file_test.go to load from default .adguardhome-sync.yaml file
2024-03-12 18:41:12 +01:00
dependabot[bot]
0e86fc8094 Bump golang.org/x/mod from 0.15.0 to 0.16.0 (#311)
Bumps [golang.org/x/mod](https://github.com/golang/mod) from 0.15.0 to 0.16.0.
- [Commits](https://github.com/golang/mod/compare/v0.15.0...v0.16.0)

---
updated-dependencies:
- dependency-name: golang.org/x/mod
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-11 07:05:22 +01:00
dependabot[bot]
3c6c4b88ef Bump the onsi group with 1 update (#310)
Bumps the onsi group with 1 update: [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo).


Updates `github.com/onsi/ginkgo/v2` from 2.15.0 to 2.16.0
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.15.0...v2.16.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: onsi
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-11 07:04:42 +01:00
dependabot[bot]
4b4a10be7e Bump gopkg.in/go-jose/go-jose.v2 from 2.6.1 to 2.6.3 (#309)
Bumps gopkg.in/go-jose/go-jose.v2 from 2.6.1 to 2.6.3.

---
updated-dependencies:
- dependency-name: gopkg.in/go-jose/go-jose.v2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-08 01:13:35 +01:00
Marc Brugger
4f1491858b update model to v0.107.44 (#308) 2024-03-05 23:03:37 +01:00
dependabot[bot]
33433b1aaf Bump go.uber.org/zap from 1.26.0 to 1.27.0 (#307)
Bumps [go.uber.org/zap](https://github.com/uber-go/zap) from 1.26.0 to 1.27.0.
- [Release notes](https://github.com/uber-go/zap/releases)
- [Changelog](https://github.com/uber-go/zap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/uber-go/zap/compare/v1.26.0...v1.27.0)

---
updated-dependencies:
- dependency-name: go.uber.org/zap
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-02-26 07:39:20 +01:00
dependabot[bot]
d85ebe0d34 Bump github.com/golangci/golangci-lint from 1.56.1 to 1.56.2 (#306)
* Bump github.com/golangci/golangci-lint from 1.56.1 to 1.56.2

Bumps [github.com/golangci/golangci-lint](https://github.com/golangci/golangci-lint) from 1.56.1 to 1.56.2.
- [Release notes](https://github.com/golangci/golangci-lint/releases)
- [Changelog](https://github.com/golangci/golangci-lint/blob/master/CHANGELOG.md)
- [Commits](https://github.com/golangci/golangci-lint/compare/v1.56.1...v1.56.2)

---
updated-dependencies:
- dependency-name: github.com/golangci/golangci-lint
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* ignore goseg G402

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: bakito <github@bakito.ch>
2024-02-19 07:56:35 +01:00
dependabot[bot]
235bd85510 Bump the k8s group with 2 updates (#305)
Bumps the k8s group with 2 updates: [k8s.io/apimachinery](https://github.com/kubernetes/apimachinery) and [k8s.io/code-generator](https://github.com/kubernetes/code-generator).


Updates `k8s.io/apimachinery` from 0.29.1 to 0.29.2
- [Commits](https://github.com/kubernetes/apimachinery/compare/v0.29.1...v0.29.2)

Updates `k8s.io/code-generator` from 0.29.1 to 0.29.2
- [Commits](https://github.com/kubernetes/code-generator/compare/v0.29.1...v0.29.2)

---
updated-dependencies:
- dependency-name: k8s.io/apimachinery
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: k8s
- dependency-name: k8s.io/code-generator
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: k8s
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-02-19 07:21:10 +01:00
Adam Shand
5c29345f48 Adding examples for API_USERNAME & API_PASSWORD (#302)
I couldn't find any documentation on how to configure these.  So adding to help out others.
2024-02-14 09:58:05 +01:00
dependabot[bot]
ebcb2b84ae Bump github.com/goreleaser/goreleaser from 1.23.0 to 1.24.0 (#299)
Bumps [github.com/goreleaser/goreleaser](https://github.com/goreleaser/goreleaser) from 1.23.0 to 1.24.0.
- [Release notes](https://github.com/goreleaser/goreleaser/releases)
- [Changelog](https://github.com/goreleaser/goreleaser/blob/main/.goreleaser.yaml)
- [Commits](https://github.com/goreleaser/goreleaser/compare/v1.23.0...v1.24.0)

---
updated-dependencies:
- dependency-name: github.com/goreleaser/goreleaser
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-02-12 07:52:37 +01:00
dependabot[bot]
080021e73d Bump golang.org/x/mod from 0.14.0 to 0.15.0 (#300)
Bumps [golang.org/x/mod](https://github.com/golang/mod) from 0.14.0 to 0.15.0.
- [Commits](https://github.com/golang/mod/compare/v0.14.0...v0.15.0)

---
updated-dependencies:
- dependency-name: golang.org/x/mod
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-02-12 07:37:33 +01:00
dependabot[bot]
f447e28c86 Bump github.com/golangci/golangci-lint from 1.55.2 to 1.56.1 (#301)
Bumps [github.com/golangci/golangci-lint](https://github.com/golangci/golangci-lint) from 1.55.2 to 1.56.1.
- [Release notes](https://github.com/golangci/golangci-lint/releases)
- [Changelog](https://github.com/golangci/golangci-lint/blob/master/CHANGELOG.md)
- [Commits](https://github.com/golangci/golangci-lint/compare/v1.55.2...v1.56.1)

---
updated-dependencies:
- dependency-name: github.com/golangci/golangci-lint
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-02-12 07:37:22 +01:00
dependabot[bot]
f3b2ca644c Bump golangci/golangci-lint-action from 3 to 4 (#298)
Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 3 to 4.
- [Release notes](https://github.com/golangci/golangci-lint-action/releases)
- [Commits](https://github.com/golangci/golangci-lint-action/compare/v3...v4)

---
updated-dependencies:
- dependency-name: golangci/golangci-lint-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-02-12 07:34:43 +01:00
Marc Brugger
4fdead0add Update go in codeql-analysis.yml (#297) 2024-02-04 16:19:59 +01:00
Marc Brugger
059c6e9df7 Handle nil user rules correctly #295 (#296)
* Handle nil user rules correctly #295
2024-02-04 08:55:53 +01:00
bakito
a3f0efa8bc #275 update examples to show only numbered replica env variables 2024-01-31 18:46:33 +01:00
dependabot[bot]
a79ad5abeb Bump github.com/google/uuid from 1.5.0 to 1.6.0 (#293)
Bumps [github.com/google/uuid](https://github.com/google/uuid) from 1.5.0 to 1.6.0.
- [Release notes](https://github.com/google/uuid/releases)
- [Changelog](https://github.com/google/uuid/blob/master/CHANGELOG.md)
- [Commits](https://github.com/google/uuid/compare/v1.5.0...v1.6.0)

---
updated-dependencies:
- dependency-name: github.com/google/uuid
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-01-29 08:30:51 +01:00
dependabot[bot]
c6f8a14643 Bump github.com/deepmap/oapi-codegen/v2 from 2.0.0 to 2.1.0 (#292)
Bumps [github.com/deepmap/oapi-codegen/v2](https://github.com/deepmap/oapi-codegen) from 2.0.0 to 2.1.0.
- [Release notes](https://github.com/deepmap/oapi-codegen/releases)
- [Commits](https://github.com/deepmap/oapi-codegen/compare/v2.0.0...v2.1.0)

---
updated-dependencies:
- dependency-name: github.com/deepmap/oapi-codegen/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-01-29 08:30:39 +01:00
Marc Brugger
d262357c87 support for json logs #290 (#291)
* support for json logs #290
2024-01-26 09:14:41 +01:00
dependabot[bot]
5da3730015 Bump the onsi group with 1 update (#288)
Bumps the onsi group with 1 update: [github.com/onsi/gomega](https://github.com/onsi/gomega).


Updates `github.com/onsi/gomega` from 1.31.0 to 1.31.1
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.31.0...v1.31.1)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: onsi
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-01-22 07:01:30 +01:00
dependabot[bot]
b444a4887b Bump the k8s group with 2 updates (#286)
Bumps the k8s group with 2 updates: [k8s.io/apimachinery](https://github.com/kubernetes/apimachinery) and [k8s.io/code-generator](https://github.com/kubernetes/code-generator).


Updates `k8s.io/apimachinery` from 0.29.0 to 0.29.1
- [Commits](https://github.com/kubernetes/apimachinery/compare/v0.29.0...v0.29.1)

Updates `k8s.io/code-generator` from 0.29.0 to 0.29.1
- [Commits](https://github.com/kubernetes/code-generator/compare/v0.29.0...v0.29.1)

---
updated-dependencies:
- dependency-name: k8s.io/apimachinery
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: k8s
- dependency-name: k8s.io/code-generator
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: k8s
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-01-19 00:32:20 +01:00
dependabot[bot]
cc7133927f Bump the onsi group with 2 updates (#283)
Bumps the onsi group with 2 updates: [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) and [github.com/onsi/gomega](https://github.com/onsi/gomega).


Updates `github.com/onsi/ginkgo/v2` from 2.14.0 to 2.15.0
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.14.0...v2.15.0)

Updates `github.com/onsi/gomega` from 1.30.0 to 1.31.0
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.30.0...v1.31.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: onsi
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: onsi
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-01-19 00:22:49 +01:00
Marc Brugger
4b01042a4f Update dependabot.yml 2024-01-19 00:22:12 +01:00
Marc Brugger
4b94ef998d Update dependabot.yml to use groups 2024-01-19 00:19:46 +01:00
bakito
db5764b3d7 simplify test 2024-01-18 21:23:05 +01:00
Marc Brugger
3c0115b71c Dhcp server enabled handling (#282)
* switch to go.uber.org/mock

* #281 special handling for dhcpServerEnabled
2024-01-17 19:29:25 +01:00
Marc Brugger
c401c790bc switch to go.uber.org/mock (#280) 2024-01-16 16:46:13 +01:00
dependabot[bot]
271dcacf19 Bump github.com/go-git/go-git/v5 from 5.7.0 to 5.11.0 (#279)
Bumps [github.com/go-git/go-git/v5](https://github.com/go-git/go-git) from 5.7.0 to 5.11.0.
- [Release notes](https://github.com/go-git/go-git/releases)
- [Commits](https://github.com/go-git/go-git/compare/v5.7.0...v5.11.0)

---
updated-dependencies:
- dependency-name: github.com/go-git/go-git/v5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-01-15 22:06:42 +01:00
dependabot[bot]
983d29d033 Bump github.com/cloudflare/circl from 1.3.5 to 1.3.7 (#278)
Bumps [github.com/cloudflare/circl](https://github.com/cloudflare/circl) from 1.3.5 to 1.3.7.
- [Release notes](https://github.com/cloudflare/circl/releases)
- [Commits](https://github.com/cloudflare/circl/compare/v1.3.5...v1.3.7)

---
updated-dependencies:
- dependency-name: github.com/cloudflare/circl
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-01-15 22:06:31 +01:00
Marc Brugger
078f6e1cc4 add dependencies to tools.go (#277) 2024-01-15 21:07:56 +01:00
Marc Brugger
9f8f6bc814 run tests with ginkgo cli (#276) 2024-01-15 18:24:10 +01:00
bakito
ef35178396 move deprecations to wiki 2024-01-15 08:13:52 +01:00
dependabot[bot]
b3781c6d8f Bump github.com/onsi/ginkgo/v2 from 2.13.2 to 2.14.0 (#274)
Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.13.2 to 2.14.0.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.13.2...v2.14.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-01-15 07:07:45 +01:00
bakito
2319739f6d ignore wiki from 2024-01-14 21:21:19 +01:00
Marc Brugger
f9ac1ca698 Add e2e status to Readme 2024-01-14 21:02:19 +01:00
bakito
9802bf2f37 add tests #272 2024-01-14 16:38:58 +01:00
bakito
843433e35d extend dhcp checks #272 2024-01-14 16:13:45 +01:00
bakito
15c651ca96 #272 do not sync dhcp if empty IP 2024-01-14 14:03:04 +01:00
Marc Brugger
4c1e56ccce Fix config issues with new env library (#273)
* correct config issues #271 #272

* rename type tags

* replace env lib

* move to config module

* read flags

* show e2e logs on error

* extract env

* replace deprecated env var

* increment index

* check replica numbers do not start with 0

* remove test suite

* error handling

* refactor flags

* flags test

* file test

* file test

* config tests

* extend tests

* test mixed mode

* simplify

* simplify

* test mask

* correct uniqe replicas

* Update types_test.go

* e2e test with file mode
2024-01-14 13:29:36 +01:00
bakito
906dfc680a extend bug issue template wiht 'applied-config' 2024-01-14 09:07:54 +01:00
Marc Brugger
583197f1c8 add deprecated env var table 2024-01-10 20:12:08 +01:00
Marc Brugger
5fca3b1002 better readable env vars (#270)
* better readable env vars
2024-01-08 19:39:47 +01:00
bakito
1edf5ae52a add filter test cases 2024-01-08 19:20:31 +01:00
bakito
39f7f41e6d update readme 2024-01-07 22:44:32 +01:00
Marc Brugger
3139ad605f Refactor sync into separate action functions (#268)
* sync-actions

* dns rewrites and filters

* continue on filter error

* servides

* client settings

* dns

* dhcp

* remove deprecated env var

* fix client tests

* tests

* copy replica config

* map continue on error

* map env var with underscore
2024-01-07 22:03:21 +01:00
bakito
a9de069f6b update dependencies 2024-01-07 10:05:13 +01:00
Marc Brugger
4a8e2aab51 allow definig web URL (#267) 2024-01-07 09:55:21 +01:00
Marc Brugger
749c5f178c add option to print full config for debugging (#266)
* add option to print full config for debugging

* print link to FAQ in auth errors
2024-01-07 03:05:44 +01:00
Marc Brugger
680989bc2e add tzdata to image (#265) 2024-01-05 09:27:36 +01:00
dependabot[bot]
418989989b Bump github.com/go-resty/resty/v2 from 2.9.1 to 2.11.0 (#263)
Bumps [github.com/go-resty/resty/v2](https://github.com/go-resty/resty) from 2.9.1 to 2.11.0.
- [Release notes](https://github.com/go-resty/resty/releases)
- [Commits](https://github.com/go-resty/resty/compare/v2.9.1...v2.11.0)

---
updated-dependencies:
- dependency-name: github.com/go-resty/resty/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-28 08:07:19 +01:00
dependabot[bot]
9a06a6ac10 Bump github.com/spf13/viper from 1.18.1 to 1.18.2 (#261)
Bumps [github.com/spf13/viper](https://github.com/spf13/viper) from 1.18.1 to 1.18.2.
- [Release notes](https://github.com/spf13/viper/releases)
- [Commits](https://github.com/spf13/viper/compare/v1.18.1...v1.18.2)

---
updated-dependencies:
- dependency-name: github.com/spf13/viper
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-25 07:36:08 +01:00
bakito
ff7bae0bba build main image only once a day if needed 2023-12-22 22:45:50 +01:00
Marc Brugger
215ee946dd add protection flag to api status (#260) 2023-12-22 21:03:46 +01:00
bakito
cc13b9318d correct api status host property from 'origin' to 'host' 2023-12-22 17:26:29 +01:00
bakito
9d26eec6b0 asure cacerts are installed in build image 2023-12-20 20:41:34 +01:00
Marc Brugger
bb969a0005 upgrade agh schema to v0.107.43 (#257) 2023-12-20 07:57:41 +01:00
bakito
37b8fda889 extend issue template description 2023-12-19 21:34:02 +01:00
bakito
0c9487a53d logs are required in template 2023-12-19 19:38:37 +01:00
Marc Brugger
a039704f1b update issue templates (#256) 2023-12-19 19:36:53 +01:00
Marc Brugger
ec9be5aed6 Update general_issue.md (#255) 2023-12-19 17:52:48 +01:00
Marc Brugger
542aacb002 Create general_issue.md (#254)
* Create general_issue.md

* Add bug label
2023-12-19 17:27:03 +01:00
Marc Brugger
e7e391f85c Create config.yml (#253) 2023-12-19 17:11:34 +01:00
dependabot[bot]
8ccd773b4b Bump golang.org/x/crypto from 0.16.0 to 0.17.0 (#251)
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.16.0 to 0.17.0.
- [Commits](https://github.com/golang/crypto/compare/v0.16.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-19 06:44:47 +01:00
dependabot[bot]
cb52a43940 Bump github/codeql-action from 2 to 3 (#249)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2 to 3.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/v2...v3)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-18 06:40:39 +01:00
dependabot[bot]
2463809356 Bump k8s.io/apimachinery from 0.28.4 to 0.29.0 (#250)
Bumps [k8s.io/apimachinery](https://github.com/kubernetes/apimachinery) from 0.28.4 to 0.29.0.
- [Commits](https://github.com/kubernetes/apimachinery/compare/v0.28.4...v0.29.0)

---
updated-dependencies:
- dependency-name: k8s.io/apimachinery
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-18 06:40:22 +01:00
dependabot[bot]
b71df4d8ed Bump github.com/google/uuid from 1.4.0 to 1.5.0 (#248)
Bumps [github.com/google/uuid](https://github.com/google/uuid) from 1.4.0 to 1.5.0.
- [Release notes](https://github.com/google/uuid/releases)
- [Changelog](https://github.com/google/uuid/blob/master/CHANGELOG.md)
- [Commits](https://github.com/google/uuid/compare/v1.4.0...v1.5.0)

---
updated-dependencies:
- dependency-name: github.com/google/uuid
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-12 23:10:10 +01:00
bakito
4cd60e818a downgrade resty 2023-12-12 22:57:12 +01:00
dependabot[bot]
31aad9471b Bump github.com/spf13/viper from 1.17.0 to 1.18.1 (#245)
Bumps [github.com/spf13/viper](https://github.com/spf13/viper) from 1.17.0 to 1.18.1.
- [Release notes](https://github.com/spf13/viper/releases)
- [Commits](https://github.com/spf13/viper/compare/v1.17.0...v1.18.1)

---
updated-dependencies:
- dependency-name: github.com/spf13/viper
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-11 06:43:00 +01:00
dependabot[bot]
34dac9e091 Bump actions/setup-go from 4 to 5 (#246)
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 4 to 5.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/setup-go
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-11 06:42:51 +01:00
dependabot[bot]
c1c81bb8f6 Bump github.com/onsi/ginkgo/v2 from 2.13.1 to 2.13.2 (#243)
Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.13.1 to 2.13.2.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.13.1...v2.13.2)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-04 08:02:14 +01:00
Marc Brugger
012350a8fd #239 do not sync incomplete profile (#240) 2023-11-23 08:11:32 +01:00
dependabot[bot]
fefdda0015 Bump github.com/oapi-codegen/runtime from 1.0.0 to 1.1.0 (#237)
Bumps [github.com/oapi-codegen/runtime](https://github.com/oapi-codegen/runtime) from 1.0.0 to 1.1.0.
- [Release notes](https://github.com/oapi-codegen/runtime/releases)
- [Commits](https://github.com/oapi-codegen/runtime/compare/v1.0.0...v1.1.0)

---
updated-dependencies:
- dependency-name: github.com/oapi-codegen/runtime
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-20 07:10:53 +01:00
dependabot[bot]
55d63df17b Bump k8s.io/apimachinery from 0.28.3 to 0.28.4 (#238)
Bumps [k8s.io/apimachinery](https://github.com/kubernetes/apimachinery) from 0.28.3 to 0.28.4.
- [Commits](https://github.com/kubernetes/apimachinery/compare/v0.28.3...v0.28.4)

---
updated-dependencies:
- dependency-name: k8s.io/apimachinery
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-20 07:10:45 +01:00
bakito
37ee52aa8f add links to dashboard 2023-11-13 23:45:42 +01:00
Marc Brugger
da289017a5 Generate types from openapi (#201)
* generate model from openAPI schema
* implement replica status #231
* Sync "Pause service blocking schedule" #234
* Sync "Safe Search Provider" #200
2023-11-13 21:09:08 +01:00
dependabot[bot]
0fb6f38bab Bump github.com/onsi/ginkgo/v2 from 2.13.0 to 2.13.1 (#235)
Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.13.0 to 2.13.1.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.13.0...v2.13.1)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-13 07:03:51 +01:00
dependabot[bot]
014e9c8a26 Bump github.com/onsi/gomega from 1.29.0 to 1.30.0 (#236)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.29.0 to 1.30.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.29.0...v1.30.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-13 06:56:23 +01:00
dependabot[bot]
d07c005191 Bump github.com/spf13/cobra from 1.7.0 to 1.8.0 (#233)
Bumps [github.com/spf13/cobra](https://github.com/spf13/cobra) from 1.7.0 to 1.8.0.
- [Release notes](https://github.com/spf13/cobra/releases)
- [Commits](https://github.com/spf13/cobra/compare/v1.7.0...v1.8.0)

---
updated-dependencies:
- dependency-name: github.com/spf13/cobra
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-06 06:49:57 +01:00
dependabot[bot]
a2b9930f92 Bump golang.org/x/mod from 0.13.0 to 0.14.0 (#232)
Bumps [golang.org/x/mod](https://github.com/golang/mod) from 0.13.0 to 0.14.0.
- [Commits](https://github.com/golang/mod/compare/v0.13.0...v0.14.0)

---
updated-dependencies:
- dependency-name: golang.org/x/mod
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-06 06:43:53 +01:00
dependabot[bot]
8ac7b9addd Bump github.com/onsi/gomega from 1.28.1 to 1.29.0 (#229)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.28.1 to 1.29.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.28.1...v1.29.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-30 07:26:33 +01:00
dependabot[bot]
8115f52d8a Bump github.com/google/uuid from 1.3.1 to 1.4.0 (#230)
Bumps [github.com/google/uuid](https://github.com/google/uuid) from 1.3.1 to 1.4.0.
- [Release notes](https://github.com/google/uuid/releases)
- [Changelog](https://github.com/google/uuid/blob/master/CHANGELOG.md)
- [Commits](https://github.com/google/uuid/compare/v1.3.1...v1.4.0)

---
updated-dependencies:
- dependency-name: github.com/google/uuid
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-30 07:26:11 +01:00
dependabot[bot]
1581b82ae5 Bump github.com/onsi/gomega from 1.28.0 to 1.28.1 (#228)
* Bump github.com/onsi/gomega from 1.28.0 to 1.28.1

Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.28.0 to 1.28.1.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.28.0...v1.28.1)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update .golangci.yml

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Marc Brugger <github@bakito.ch>
2023-10-24 19:43:05 +02:00
dependabot[bot]
9a466cb86b Bump github.com/go-resty/resty/v2 from 2.9.1 to 2.10.0 (#226)
Bumps [github.com/go-resty/resty/v2](https://github.com/go-resty/resty) from 2.9.1 to 2.10.0.
- [Release notes](https://github.com/go-resty/resty/releases)
- [Commits](https://github.com/go-resty/resty/compare/v2.9.1...v2.10.0)

---
updated-dependencies:
- dependency-name: github.com/go-resty/resty/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-16 08:01:00 +02:00
dependabot[bot]
fda2ac0a5a Bump github.com/onsi/ginkgo/v2 from 2.12.1 to 2.13.0 (#225)
Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.12.1 to 2.13.0.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.12.1...v2.13.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-16 08:00:36 +02:00
dependabot[bot]
c1975eebdb Bump golang.org/x/net from 0.15.0 to 0.17.0 (#224)
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.15.0 to 0.17.0.
- [Commits](https://github.com/golang/net/compare/v0.15.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-12 06:53:00 +02:00
dependabot[bot]
ab891449cf Bump github.com/spf13/viper from 1.16.0 to 1.17.0 (#222)
Bumps [github.com/spf13/viper](https://github.com/spf13/viper) from 1.16.0 to 1.17.0.
- [Release notes](https://github.com/spf13/viper/releases)
- [Commits](https://github.com/spf13/viper/compare/v1.16.0...v1.17.0)

---
updated-dependencies:
- dependency-name: github.com/spf13/viper
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-09 12:30:42 +02:00
dependabot[bot]
e4f235586e Bump golang.org/x/mod from 0.12.0 to 0.13.0 (#223)
Bumps [golang.org/x/mod](https://github.com/golang/mod) from 0.12.0 to 0.13.0.
- [Commits](https://github.com/golang/mod/compare/v0.12.0...v0.13.0)

---
updated-dependencies:
- dependency-name: golang.org/x/mod
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-09 08:22:58 +02:00
dependabot[bot]
49e79274bb Bump github.com/go-resty/resty/v2 from 2.8.0 to 2.9.1 (#220)
Bumps [github.com/go-resty/resty/v2](https://github.com/go-resty/resty) from 2.8.0 to 2.9.1.
- [Release notes](https://github.com/go-resty/resty/releases)
- [Commits](https://github.com/go-resty/resty/compare/v2.8.0...v2.9.1)

---
updated-dependencies:
- dependency-name: github.com/go-resty/resty/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-02 08:02:55 +02:00
dependabot[bot]
4d077eba3c Bump github.com/onsi/gomega from 1.27.10 to 1.28.0 (#221)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.27.10 to 1.28.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.27.10...v1.28.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-02 08:02:47 +02:00
dependabot[bot]
ad24071c9c Bump github.com/onsi/ginkgo/v2 from 2.12.0 to 2.12.1 (#219)
Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.12.0 to 2.12.1.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.12.0...v2.12.1)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-25 07:12:23 +02:00
dependabot[bot]
d99af0c43d Bump go.uber.org/zap from 1.25.0 to 1.26.0 (#212)
Bumps [go.uber.org/zap](https://github.com/uber-go/zap) from 1.25.0 to 1.26.0.
- [Release notes](https://github.com/uber-go/zap/releases)
- [Changelog](https://github.com/uber-go/zap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/uber-go/zap/compare/v1.25.0...v1.26.0)

---
updated-dependencies:
- dependency-name: go.uber.org/zap
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-18 07:05:56 +02:00
dependabot[bot]
0f86e61cdd Bump docker/login-action from 2 to 3 (#214)
Bumps [docker/login-action](https://github.com/docker/login-action) from 2 to 3.
- [Release notes](https://github.com/docker/login-action/releases)
- [Commits](https://github.com/docker/login-action/compare/v2...v3)

---
updated-dependencies:
- dependency-name: docker/login-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-18 07:05:46 +02:00
dependabot[bot]
dea2d04a63 Bump github.com/go-resty/resty/v2 from 2.7.0 to 2.8.0 (#213)
Bumps [github.com/go-resty/resty/v2](https://github.com/go-resty/resty) from 2.7.0 to 2.8.0.
- [Release notes](https://github.com/go-resty/resty/releases)
- [Commits](https://github.com/go-resty/resty/compare/v2.7.0...v2.8.0)

---
updated-dependencies:
- dependency-name: github.com/go-resty/resty/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-18 07:05:17 +02:00
dependabot[bot]
a34eb1ae57 Bump docker/build-push-action from 4 to 5 (#216)
Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 4 to 5.
- [Release notes](https://github.com/docker/build-push-action/releases)
- [Commits](https://github.com/docker/build-push-action/compare/v4...v5)

---
updated-dependencies:
- dependency-name: docker/build-push-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-18 07:04:38 +02:00
dependabot[bot]
6f426a870f Bump goreleaser/goreleaser-action from 4 to 5 (#215)
Bumps [goreleaser/goreleaser-action](https://github.com/goreleaser/goreleaser-action) from 4 to 5.
- [Release notes](https://github.com/goreleaser/goreleaser-action/releases)
- [Commits](https://github.com/goreleaser/goreleaser-action/compare/v4...v5)

---
updated-dependencies:
- dependency-name: goreleaser/goreleaser-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-18 07:04:28 +02:00
dependabot[bot]
0e129d4b10 Bump docker/setup-buildx-action from 2 to 3 (#218)
Bumps [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) from 2 to 3.
- [Release notes](https://github.com/docker/setup-buildx-action/releases)
- [Commits](https://github.com/docker/setup-buildx-action/compare/v2...v3)

---
updated-dependencies:
- dependency-name: docker/setup-buildx-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-18 07:04:14 +02:00
dependabot[bot]
2d65e7dc9e Bump docker/setup-qemu-action from 2 to 3 (#217)
Bumps [docker/setup-qemu-action](https://github.com/docker/setup-qemu-action) from 2 to 3.
- [Release notes](https://github.com/docker/setup-qemu-action/releases)
- [Commits](https://github.com/docker/setup-qemu-action/compare/v2...v3)

---
updated-dependencies:
- dependency-name: docker/setup-qemu-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-18 07:04:03 +02:00
dependabot[bot]
6e47c07aa3 Bump actions/checkout from 3 to 4 (#211)
Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-11 06:40:45 +02:00
dependabot[bot]
dea159d766 Bump github.com/google/uuid from 1.3.0 to 1.3.1 (#207)
Bumps [github.com/google/uuid](https://github.com/google/uuid) from 1.3.0 to 1.3.1.
- [Release notes](https://github.com/google/uuid/releases)
- [Changelog](https://github.com/google/uuid/blob/master/CHANGELOG.md)
- [Commits](https://github.com/google/uuid/compare/v1.3.0...v1.3.1)

---
updated-dependencies:
- dependency-name: github.com/google/uuid
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-08-28 06:49:32 +02:00
dependabot[bot]
e4221a9ca7 Bump github.com/onsi/ginkgo/v2 from 2.11.0 to 2.12.0 (#208)
Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.11.0 to 2.12.0.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.11.0...v2.12.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-08-28 06:43:14 +02:00
dependabot[bot]
240a0285c2 Bump github.com/jinzhu/copier from 0.3.5 to 0.4.0 (#209)
Bumps [github.com/jinzhu/copier](https://github.com/jinzhu/copier) from 0.3.5 to 0.4.0.
- [Commits](https://github.com/jinzhu/copier/compare/v0.3.5...v0.4.0)

---
updated-dependencies:
- dependency-name: github.com/jinzhu/copier
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-08-28 06:42:56 +02:00
dependabot[bot]
bc69d0388c Bump go.uber.org/zap from 1.24.0 to 1.25.0 (#206)
Bumps [go.uber.org/zap](https://github.com/uber-go/zap) from 1.24.0 to 1.25.0.
- [Release notes](https://github.com/uber-go/zap/releases)
- [Changelog](https://github.com/uber-go/zap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/uber-go/zap/compare/v1.24.0...v1.25.0)

---
updated-dependencies:
- dependency-name: go.uber.org/zap
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-08-07 08:06:40 +03:00
David Johnson
5043f157fa Add support for using cookie for auth (#205) 2023-08-05 08:38:21 +03:00
dependabot[bot]
2b4877f122 Bump github.com/onsi/gomega from 1.27.9 to 1.27.10 (#204)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.27.9 to 1.27.10.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.27.9...v1.27.10)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-31 05:35:08 +02:00
dependabot[bot]
53b9cf704c Bump github.com/onsi/gomega from 1.27.8 to 1.27.9 (#203)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.27.8 to 1.27.9.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.27.8...v1.27.9)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-24 07:33:25 +02:00
dependabot[bot]
69dd7650e1 Bump golang.org/x/mod from 0.11.0 to 0.12.0 (#202)
Bumps [golang.org/x/mod](https://github.com/golang/mod) from 0.11.0 to 0.12.0.
- [Commits](https://github.com/golang/mod/compare/v0.11.0...v0.12.0)

---
updated-dependencies:
- dependency-name: golang.org/x/mod
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-10 07:27:44 +02:00
dependabot[bot]
06b93cbdac Bump golang.org/x/mod from 0.10.0 to 0.11.0 (#197)
Bumps [golang.org/x/mod](https://github.com/golang/mod) from 0.10.0 to 0.11.0.
- [Commits](https://github.com/golang/mod/compare/v0.10.0...v0.11.0)

---
updated-dependencies:
- dependency-name: golang.org/x/mod
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-19 20:47:30 +02:00
dependabot[bot]
dd21859cd1 Bump github.com/onsi/ginkgo/v2 from 2.10.0 to 2.11.0 (#198)
* Bump github.com/onsi/ginkgo/v2 from 2.10.0 to 2.11.0

Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.10.0 to 2.11.0.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.10.0...v2.11.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update Dockerfile

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Marc Brugger <github@bakito.ch>
2023-06-19 20:26:42 +02:00
dependabot[bot]
9a19b33116 Bump github.com/onsi/gomega from 1.27.7 to 1.27.8 (#196)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.27.7 to 1.27.8.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.27.7...v1.27.8)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-12 07:23:20 +02:00
dependabot[bot]
5385d0aaed Bump github.com/onsi/ginkgo/v2 from 2.9.7 to 2.10.0 (#195)
Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.9.7 to 2.10.0.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.9.7...v2.10.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-12 07:17:13 +02:00
bakito
02547975e9 update tools 2023-06-10 08:03:40 +02:00
dependabot[bot]
598324b7aa Bump github.com/onsi/ginkgo/v2 from 2.9.5 to 2.9.7 (#192)
* Bump github.com/onsi/ginkgo/v2 from 2.9.5 to 2.9.7

Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.9.5 to 2.9.7.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.9.5...v2.9.7)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* skip-pkg-cache: true

* Update .golangci.yml

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Marc Brugger <github@bakito.ch>
2023-06-02 07:37:01 +02:00
dependabot[bot]
49cd71daf7 Bump github.com/spf13/viper from 1.15.0 to 1.16.0 (#193)
Bumps [github.com/spf13/viper](https://github.com/spf13/viper) from 1.15.0 to 1.16.0.
- [Release notes](https://github.com/spf13/viper/releases)
- [Commits](https://github.com/spf13/viper/compare/v1.15.0...v1.16.0)

---
updated-dependencies:
- dependency-name: github.com/spf13/viper
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-02 07:36:28 +02:00
Marc Brugger
2f2cd0af58 set provenance: false for image builds (#191) 2023-06-01 22:50:56 +02:00
dependabot[bot]
607238230d Bump github.com/gin-gonic/gin from 1.9.0 to 1.9.1 (#190)
Bumps [github.com/gin-gonic/gin](https://github.com/gin-gonic/gin) from 1.9.0 to 1.9.1.
- [Release notes](https://github.com/gin-gonic/gin/releases)
- [Changelog](https://github.com/gin-gonic/gin/blob/master/CHANGELOG.md)
- [Commits](https://github.com/gin-gonic/gin/compare/v1.9.0...v1.9.1)

---
updated-dependencies:
- dependency-name: github.com/gin-gonic/gin
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-01 22:36:03 +02:00
dependabot[bot]
ed952dd891 Bump github.com/onsi/gomega from 1.27.6 to 1.27.7 (#189)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.27.6 to 1.27.7.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.27.6...v1.27.7)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-22 11:53:21 +02:00
dependabot[bot]
50de6b1d71 Bump github.com/onsi/ginkgo/v2 from 2.9.2 to 2.9.4 (#187)
Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.9.2 to 2.9.4.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.9.2...v2.9.4)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-08 07:09:28 +02:00
bakito
4db293ccf2 update all builder images packages to get latestav ailable cacerts #185 2023-05-01 07:37:08 +02:00
bakito
3211406ef2 update tools 2023-04-12 20:29:37 +02:00
Marc Brugger
c93084e623 Only sync dhcp config if it is valid (#184)
* handle new install page redirect location

* only sync dhcp config if valid
2023-04-12 20:02:55 +02:00
Marc Brugger
009715ccea handle new install page redirect location (#183) 2023-04-12 19:33:15 +02:00
bakito
c22f38fff2 correct go.mod version to 1.20 2023-04-10 22:22:50 +02:00
dependabot[bot]
e2c6ef40ec Bump golang.org/x/mod from 0.9.0 to 0.10.0 (#181)
Bumps [golang.org/x/mod](https://github.com/golang/mod) from 0.9.0 to 0.10.0.
- [Release notes](https://github.com/golang/mod/releases)
- [Commits](https://github.com/golang/mod/compare/v0.9.0...v0.10.0)

---
updated-dependencies:
- dependency-name: golang.org/x/mod
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-10 08:53:09 +02:00
dependabot[bot]
b44e2f8d8d Bump github.com/spf13/cobra from 1.6.1 to 1.7.0 (#180)
Bumps [github.com/spf13/cobra](https://github.com/spf13/cobra) from 1.6.1 to 1.7.0.
- [Release notes](https://github.com/spf13/cobra/releases)
- [Commits](https://github.com/spf13/cobra/compare/v1.6.1...v1.7.0)

---
updated-dependencies:
- dependency-name: github.com/spf13/cobra
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-10 08:53:01 +02:00
dependabot[bot]
c20bec7a13 Bump github.com/onsi/gomega from 1.27.5 to 1.27.6 (#178)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.27.5 to 1.27.6.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.27.5...v1.27.6)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-03 06:48:08 +02:00
Marc Brugger
f21874c546 log os and arch (#177) 2023-03-28 20:38:48 +02:00
dependabot[bot]
fce8aea40b Bump github.com/onsi/gomega from 1.27.4 to 1.27.5 (#175)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.27.4 to 1.27.5.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.27.4...v1.27.5)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-27 06:50:27 +02:00
Marc Brugger
1dab955843 print config in debug mode (#171) 2023-03-21 14:28:16 +01:00
bakito
92c4d1f41a #170 add log level to readme 2023-03-21 11:14:44 +01:00
dependabot[bot]
89e4f2f0aa Bump github.com/onsi/gomega from 1.27.3 to 1.27.4 (#168)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.27.3 to 1.27.4.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.27.3...v1.27.4)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-20 07:19:52 +01:00
dependabot[bot]
cf0458b4a9 Bump actions/setup-go from 3 to 4 (#169)
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 3 to 4.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/setup-go
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-20 06:48:39 +01:00
Marc Brugger
c524a8ce2b Update sync.go (#167) 2023-03-17 20:43:06 +01:00
bakito
5df430e694 update readme with api port 2023-03-15 20:57:29 +01:00
Minchao
faaefd726a fix type of replica-interface-name flag to string (#166) 2023-03-15 20:57:18 +01:00
dependabot[bot]
19451db485 Bump github.com/onsi/ginkgo/v2 from 2.9.0 to 2.9.1 (#164)
Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.9.0 to 2.9.1.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.9.0...v2.9.1)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-13 10:47:34 +01:00
Dustin Essington
abe38e7a2c Adjust origin-insecure-skip-verify to a bool (#161) 2023-03-12 08:49:37 +01:00
Marc Brugger
495e0d261d Allow enabling/disabling target dhcp server (#160)
* Allow enabling/disabling target dhcp server

* add test

* extend tests
2023-03-06 22:07:34 +01:00
Marc Brugger
cfcffab9d1 correct interface name env var from REPLICA%s_INTERFACWENAME to REPLICA%s_INTERFACENAME (#159) 2023-03-06 21:13:50 +01:00
dependabot[bot]
94ed2c6245 Bump github.com/onsi/ginkgo/v2 from 2.8.3 to 2.9.0 (#157)
Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.8.3 to 2.9.0.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.8.3...v2.9.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-06 08:42:52 +01:00
dependabot[bot]
e3f01f75a2 Bump github.com/onsi/gomega from 1.27.1 to 1.27.2 (#156)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.27.1 to 1.27.2.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.27.1...v1.27.2)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-06 07:56:18 +01:00
dependabot[bot]
5865a8160e Bump golang.org/x/mod from 0.8.0 to 0.9.0 (#158)
Bumps [golang.org/x/mod](https://github.com/golang/mod) from 0.8.0 to 0.9.0.
- [Release notes](https://github.com/golang/mod/releases)
- [Commits](https://github.com/golang/mod/compare/v0.8.0...v0.9.0)

---
updated-dependencies:
- dependency-name: golang.org/x/mod
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-06 07:56:02 +01:00
dependabot[bot]
619dd5fcd9 Bump github.com/onsi/ginkgo/v2 from 2.8.1 to 2.8.3 (#154)
Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.8.1 to 2.8.3.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.8.1...v2.8.3)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-27 06:39:08 +01:00
dependabot[bot]
9310ddddaf Bump golang.org/x/mod (#153)
Bumps [golang.org/x/mod](https://github.com/golang/mod) from 0.6.0-dev.0.20220419223038-86c51ed26bb4 to 0.8.0.
- [Release notes](https://github.com/golang/mod/releases)
- [Commits](https://github.com/golang/mod/commits/v0.8.0)

---
updated-dependencies:
- dependency-name: golang.org/x/mod
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-27 05:22:22 +01:00
dependabot[bot]
25265a5f51 Bump github.com/gin-gonic/gin from 1.8.2 to 1.9.0 (#152)
Bumps [github.com/gin-gonic/gin](https://github.com/gin-gonic/gin) from 1.8.2 to 1.9.0.
- [Release notes](https://github.com/gin-gonic/gin/releases)
- [Changelog](https://github.com/gin-gonic/gin/blob/master/CHANGELOG.md)
- [Commits](https://github.com/gin-gonic/gin/compare/v1.8.2...v1.9.0)

---
updated-dependencies:
- dependency-name: github.com/gin-gonic/gin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-27 05:22:10 +01:00
dependabot[bot]
bdc8024ba9 Bump github.com/onsi/gomega from 1.26.0 to 1.27.1 (#151)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.26.0 to 1.27.1.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.26.0...v1.27.1)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-20 08:32:03 +01:00
bakito
116fdf5c11 update makefile 2023-02-07 22:56:29 +01:00
bakito
49f301589d fix dhcp clone function #149 2023-02-07 21:44:31 +01:00
bakito
6d08d42626 log post body #149 2023-02-07 21:27:17 +01:00
bakito
3c7243fcba go 1.20 docker base image 2023-02-07 19:49:27 +01:00
dependabot[bot]
f6bb8757a4 Bump github.com/onsi/ginkgo/v2 from 2.7.1 to 2.8.0 (#147)
Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.7.1 to 2.8.0.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.7.1...v2.8.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-06 07:51:13 +01:00
dependabot[bot]
2cd21c8331 Bump docker/build-push-action from 3 to 4 (#148)
Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 3 to 4.
- [Release notes](https://github.com/docker/build-push-action/releases)
- [Commits](https://github.com/docker/build-push-action/compare/v3...v4)

---
updated-dependencies:
- dependency-name: docker/build-push-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-06 07:51:01 +01:00
dependabot[bot]
edac7a3b4d Bump github.com/onsi/ginkgo/v2 from 2.7.0 to 2.7.1 (#145)
Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.7.0 to 2.7.1.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.7.0...v2.7.1)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-30 07:18:09 +01:00
dependabot[bot]
64b73ba7cf Bump github.com/onsi/gomega from 1.25.0 to 1.26.0 (#146)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.25.0 to 1.26.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.25.0...v1.26.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-30 07:11:55 +01:00
dependabot[bot]
e41e5dbaa9 Bump github.com/spf13/viper from 1.14.0 to 1.15.0 (#143)
Bumps [github.com/spf13/viper](https://github.com/spf13/viper) from 1.14.0 to 1.15.0.
- [Release notes](https://github.com/spf13/viper/releases)
- [Commits](https://github.com/spf13/viper/compare/v1.14.0...v1.15.0)

---
updated-dependencies:
- dependency-name: github.com/spf13/viper
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-22 21:31:24 +01:00
dependabot[bot]
00c77a77c9 Bump github.com/onsi/gomega from 1.24.2 to 1.25.0 (#142)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.24.2 to 1.25.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.24.2...v1.25.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-22 21:28:06 +01:00
dependabot[bot]
378aa54500 Bump github.com/onsi/ginkgo/v2 from 2.6.1 to 2.7.0 (#141)
Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.6.1 to 2.7.0.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.6.1...v2.7.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-16 07:26:22 +01:00
bakito
3bc7874412 add debug log hint to bug template 2023-01-13 18:22:27 +01:00
bakito
a4864b2b7a use toolbox to update Makefile 2022-12-28 17:45:08 +01:00
bakito
2b27ce88fe go 1.19 2022-12-28 17:36:15 +01:00
Marc Brugger
c32694ff5c Create FUNDING.yml - fixes #135 2022-12-27 22:40:47 +01:00
bakito
97ae38c3fa do not sync DHCP if disabled #137 2022-12-27 19:32:24 +01:00
bakito
9edec9cf04 allow different version patterns - fixes #139 2022-12-27 18:50:50 +01:00
bakito
dcaad44315 use composite kind with registry action 2022-12-26 11:15:39 +01:00
dependabot[bot]
ddc8e9f31d Bump github.com/gin-gonic/gin from 1.8.1 to 1.8.2 (#138)
Bumps [github.com/gin-gonic/gin](https://github.com/gin-gonic/gin) from 1.8.1 to 1.8.2.
- [Release notes](https://github.com/gin-gonic/gin/releases)
- [Changelog](https://github.com/gin-gonic/gin/blob/master/CHANGELOG.md)
- [Commits](https://github.com/gin-gonic/gin/compare/v1.8.1...v1.8.2)

---
updated-dependencies:
- dependency-name: github.com/gin-gonic/gin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-26 10:23:14 +01:00
Marc Brugger
6b07040ad7 move e2e test in regular build (#136)
* move e2e test in regular build

* write to summary
2022-12-25 11:49:37 +01:00
Marc Brugger
ec3209bdb3 Update kind action 2022-12-23 23:13:26 +01:00
dependabot[bot]
883a270f56 Bump github.com/onsi/gomega from 1.24.1 to 1.24.2 (#131)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.24.1 to 1.24.2.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.24.1...v1.24.2)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-19 07:04:15 +01:00
dependabot[bot]
cbcc85dc93 Bump helm/kind-action from 1.4.0 to 1.5.0 (#133)
Bumps [helm/kind-action](https://github.com/helm/kind-action) from 1.4.0 to 1.5.0.
- [Release notes](https://github.com/helm/kind-action/releases)
- [Commits](https://github.com/helm/kind-action/compare/v1.4.0...v1.5.0)

---
updated-dependencies:
- dependency-name: helm/kind-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-19 07:02:45 +01:00
dependabot[bot]
aecd921c82 Bump goreleaser/goreleaser-action from 3 to 4 (#134)
Bumps [goreleaser/goreleaser-action](https://github.com/goreleaser/goreleaser-action) from 3 to 4.
- [Release notes](https://github.com/goreleaser/goreleaser-action/releases)
- [Commits](https://github.com/goreleaser/goreleaser-action/compare/v3...v4)

---
updated-dependencies:
- dependency-name: goreleaser/goreleaser-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-19 07:02:35 +01:00
dependabot[bot]
549fcde1e7 Bump github.com/onsi/ginkgo/v2 from 2.5.1 to 2.6.0 (#129)
Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.5.1 to 2.6.0.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.5.1...v2.6.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-12 08:09:22 +01:00
dependabot[bot]
25430ebb10 Bump go.uber.org/zap from 1.23.0 to 1.24.0 (#128)
Bumps [go.uber.org/zap](https://github.com/uber-go/zap) from 1.23.0 to 1.24.0.
- [Release notes](https://github.com/uber-go/zap/releases)
- [Changelog](https://github.com/uber-go/zap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/uber-go/zap/compare/v1.23.0...v1.24.0)

---
updated-dependencies:
- dependency-name: go.uber.org/zap
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-05 08:25:27 +01:00
dependabot[bot]
e216c051d4 Bump github.com/onsi/ginkgo/v2 from 2.5.0 to 2.5.1 (#125)
Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.5.0 to 2.5.1.
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/ginkgo/compare/v2.5.0...v2.5.1)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-11-21 07:12:14 +01:00
Marc Brugger
debeff618d Update README.md 2022-11-20 18:49:36 +01:00
bakito
30706e5a30 #124 don't upx windows binaries as they make trouble with virus scanners 2022-11-18 18:50:42 +01:00
dependabot[bot]
5957bd0fde Bump github.com/onsi/gomega from 1.24.0 to 1.24.1 (#123)
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.24.0 to 1.24.1.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](https://github.com/onsi/gomega/compare/v1.24.0...v1.24.1)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-11-14 07:18:11 +01:00
102 changed files with 18367 additions and 2795 deletions

3
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1,3 @@
# These are supported funding model platforms
github: [bakito]

View File

@@ -1,27 +0,0 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. What version of AdGuardHome sync used?
2. What version of AdGuardHome us used?
3. How does the configuration look?
4. What is the error message?
**Expected behavior**
A clear and concise description of what you expected to happen.
**Log Files**
If applicable, add log files or json responses from AdGuardHome to help explain your problem.
**Additional context**
Add any other context about the problem here.

67
.github/ISSUE_TEMPLATE/bug_report.yaml vendored Normal file
View File

@@ -0,0 +1,67 @@
name: Bug report
description: Create a report to help us improve
labels: ['bug']
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this issue report! If you have usage questions, please try the [FAQ](https://github.com/bakito/adguardhome-sync/wiki/FAQ) first.
- type: textarea
id: what-happened
attributes:
label: What happened?
description: Also tell us, what did you expect to happen?
validations:
required: true
- type: textarea
id: adguardhome-sync-version
attributes:
label: AdguardHome-Sync Version
description: What version of adguardhome-sync was running when you discovered this issue?
validations:
required: true
- type: textarea
id: adguardhome-version
attributes:
label: AdguardHome Version
description: What version of adguardhome was running when you discovered this issue?
validations:
required: true
- type: textarea
id: config
attributes:
label: Configuration
description: |
- How did you configure adguardhome-sync?
- Please provide your configuration
render: shell
validations:
required: true
- type: textarea
id: applied-config
attributes:
label: Current Applied Configuration
description: |
- Run adguardhome-sync with environment variable `PRINT_CONFIG_ONLY=true` and provide the output here
render: shell
- type: textarea
id: logs
attributes:
label: Relevant log output
description: |
Please copy and paste any relevant **debug** log output. This will be automatically formatted into code, so no need for backticks.
Enable debug logs by defining the following environment variable `LOG_LEVEL=debug`.
Please also check adguardhome logs and paste any relevant logs/errors to this issue.
render: shell
validations:
required: true
- type: textarea
attributes:
label: Anything else?
description: |
Links? References? Anything that will provide more context about the issue you are encountering!
Tip: You can attach images or log files by clicking this area to highlight it and then dragging files in.
validations:
required: false

1
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@@ -0,0 +1 @@
blank_issues_enabled: false

View File

@@ -1,20 +0,0 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

View File

@@ -0,0 +1,36 @@
name: Feature request
description: Suggest an idea for this project
labels: ['enhancement']
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this issue report!
- type: textarea
id: relation
attributes:
label: Is your feature request related to a problem? Please describe.
description: A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
validations:
required: true
- type: textarea
id: solution
attributes:
label: Describe the solution you'd like*
description: |
A clear and concise description of what you want to happen.
validations:
required: true
- type: textarea
id: alternatives
attributes:
label: Describe alternatives you've considered
description: |
A clear and concise description of any alternative solutions or features you've considered.
- type: textarea
attributes:
label: Anything else?
description: |
Add any other context or screenshots about the feature request here.
validations:
required: false

View File

@@ -0,0 +1,60 @@
name: General Issue
description: Report an issue with your setup
labels: []
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this issue report! If you have usage questions, please try the [FAQ](https://github.com/bakito/adguardhome-sync/wiki/FAQ) first.
- type: textarea
id: what-happened
attributes:
label: What happened?
description: Also tell us, what did you expect to happen?
validations:
required: true
- type: textarea
id: adguardhome-sync-version
attributes:
label: AdguardHome-Sync Version
description: What version of adguardhome-sync was running when you discovered this issue?
validations:
required: true
- type: textarea
id: adguardhome-version
attributes:
label: AdguardHome Version
description: What version of adguardhome was running when you discovered this issue?
validations:
required: true
- type: textarea
id: config
attributes:
label: Configuration
description: |
- How did you configure adguardhome-sync?
- Please provide your configuration
render: shell
validations:
required: true
- type: textarea
id: logs
attributes:
label: Relevant log output
description: |
Please copy and paste any relevant **debug** log output. This will be automatically formatted into code, so no need for backticks.
Enable debug logs by defining the following environment variable `LOG_LEVEL=debug`.
Please also check adguardhome logs and paste any relevant logs/errors to this issue.
render: shell
validations:
required: true
- type: textarea
attributes:
label: Anything else?
description: |
Links? References? Anything that will provide more context about the issue you are encountering!
Tip: You can attach images or log files by clicking this area to highlight it and then dragging files in.
validations:
required: false

View File

@@ -9,6 +9,19 @@ updates:
directory: "/" # Location of package manifests directory: "/" # Location of package manifests
schedule: schedule:
interval: "weekly" interval: "weekly"
groups:
k8s:
patterns:
- "k8s.io/*"
update-types:
- "minor"
- "patch"
onsi:
patterns:
- "github.com/onsi/*"
update-types:
- "minor"
- "patch"
- package-ecosystem: "github-actions" - package-ecosystem: "github-actions"
directory: "/" directory: "/"
schedule: schedule:

View File

@@ -38,11 +38,17 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v3 uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
# Initializes the CodeQL tools for scanning. # Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@v2 uses: github/codeql-action/init@v3
with: with:
languages: ${{ matrix.language }} languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file. # If you wish to specify custom queries, you can do so here or in a config file.
@@ -53,7 +59,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below) # If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild - name: Autobuild
uses: github/codeql-action/autobuild@v2 uses: github/codeql-action/autobuild@v3
# Command-line programs to run using the OS shell. # Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl # 📚 https://git.io/JvXDl
@@ -67,4 +73,4 @@ jobs:
# make release # make release
- name: Perform CodeQL Analysis - name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2 uses: github/codeql-action/analyze@v3

45
.github/workflows/e2e.yaml vendored Normal file
View File

@@ -0,0 +1,45 @@
name: e2e tests
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
e2e:
runs-on: ubuntu-latest
strategy:
matrix:
build:
- mode: env
- mode: file
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup jq
uses: dcarbone/install-jq-action@v2
- name: Install kind with registry
uses: bakito/kind-with-registry-action@main
- name: Build image
run: ./testdata/e2e/bin/build-image.sh
- name: Install Helm Chart
run: ./testdata/e2e/bin/install-chart.sh ${{ matrix.build.mode }}
- name: Wait for sync to finish
run: ./testdata/e2e/bin/wait-for-sync.sh
- name: Show origin Logs
run: ./testdata/e2e/bin/show-origin-logs.sh
- name: Show Replica Logs
run: ./testdata/e2e/bin/show-replica-logs.sh
- name: Show Sync Logs
run: ./testdata/e2e/bin/show-sync-logs.sh
- name: Show Sync Metrics
run: ./testdata/e2e/bin/show-sync-metrics.sh
- name: Read latest replica config
run: ./testdata/e2e/bin/read-latest-replica-config.sh

View File

@@ -11,15 +11,17 @@ jobs:
name: lint name: lint
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v3 uses: actions/setup-go@v5
with: with:
go-version-file: "go.mod" go-version-file: "go.mod"
- name: golangci-lint - name: golangci-lint
uses: golangci/golangci-lint-action@v3 uses: golangci/golangci-lint-action@v4
with:
skip-pkg-cache: true
test: test:
name: test name: test
@@ -27,10 +29,10 @@ jobs:
steps: steps:
- name: Check out code into the Go module directory - name: Check out code into the Go module directory
uses: actions/checkout@v3 uses: actions/checkout@v4
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v3 uses: actions/setup-go@v5
with: with:
go-version-file: "go.mod" go-version-file: "go.mod"
@@ -48,15 +50,15 @@ jobs:
steps: steps:
- name: Check out code into the Go module directory - name: Check out code into the Go module directory
uses: actions/checkout@v3 uses: actions/checkout@v4
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v3 uses: actions/setup-go@v5
with: with:
go-version-file: "go.mod" go-version-file: "go.mod"
- name: Run GoReleaser - name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3 uses: goreleaser/goreleaser-action@v5
with: with:
version: latest version: latest
args: --skip-publish --snapshot --rm-dist args: --skip-publish --snapshot --rm-dist

View File

@@ -1,9 +1,9 @@
name: docker-image name: docker-image
on: on:
push: workflow_dispatch: # allows manual triggering
branches: schedule:
- main - cron: '0 0 * * *'
release: release:
types: types:
- published - published
@@ -22,30 +22,31 @@ jobs:
- name: Get current date - name: Get current date
run: echo "curr_date=$(date --utc +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_ENV run: echo "curr_date=$(date --utc +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_ENV
- name: Set up QEMU - name: Set up QEMU
uses: docker/setup-qemu-action@v2 uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2 uses: docker/setup-buildx-action@v3
- name: Login to Quay - name: Login to Quay
uses: docker/login-action@v2 uses: docker/login-action@v3
with: with:
registry: quay.io registry: quay.io
username: ${{ secrets.REGISTRY_USERNAME }} username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }} password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Login to ghcr.io - name: Login to ghcr.io
uses: docker/login-action@v2 uses: docker/login-action@v3
with: with:
registry: ghcr.io registry: ghcr.io
username: ${{ github.repository_owner }} username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v4
- name: Modify Dockerfile - name: Modify Dockerfile
run: | run: |
sed -i -e "s|FROM scratch|FROM ${{ matrix.build.fromImage }}|g" Dockerfile sed -i -e "s|FROM scratch|FROM ${{ matrix.build.fromImage }}|g" Dockerfile
- name: Build and push ${{github.event.release.tag_name }} - name: Build and push ${{github.event.release.tag_name }}
id: docker_build_release id: docker_build_release
uses: docker/build-push-action@v3 uses: docker/build-push-action@v5
if: ${{ github.event.release.tag_name != '' }} if: ${{ github.event.release.tag_name != '' }}
with: with:
context: . context: .
@@ -53,44 +54,30 @@ jobs:
push: true push: true
tags: quay.io/bakito/adguardhome-sync:${{ matrix.build.tagPrefix }}latest,quay.io/bakito/adguardhome-sync:${{ matrix.build.tagPrefix }}${{ github.event.release.tag_name }},ghcr.io/bakito/adguardhome-sync:${{ matrix.build.tagPrefix }}latest,ghcr.io/bakito/adguardhome-sync:${{ matrix.build.tagPrefix }}${{ github.event.release.tag_name }} tags: quay.io/bakito/adguardhome-sync:${{ matrix.build.tagPrefix }}latest,quay.io/bakito/adguardhome-sync:${{ matrix.build.tagPrefix }}${{ github.event.release.tag_name }},ghcr.io/bakito/adguardhome-sync:${{ matrix.build.tagPrefix }}latest,ghcr.io/bakito/adguardhome-sync:${{ matrix.build.tagPrefix }}${{ github.event.release.tag_name }}
platforms: linux/amd64,linux/arm64,linux/arm/v7 platforms: linux/amd64,linux/arm64,linux/arm/v7
provenance: false
build-args: | build-args: |
VERSION=${{ github.event.release.tag_name }} VERSION=${{ github.event.release.tag_name }}
BUILD=${{ env.curr_date }} BUILD=${{ env.curr_date }}
- name: Check for commits in the last 24 hours
run: echo "NEW_COMMIT_COUNT=$(git log --oneline --since '24 hours ago' | wc -l)" >> $GITHUB_ENV
if: ${{ github.event.release.tag_name == '' }}
- name: Build and push main - name: Build and push main
id: docker_build_main id: docker_build_main
uses: docker/build-push-action@v3 uses: docker/build-push-action@v5
if: ${{ github.event.release.tag_name == '' }} if: ${{ github.event.release.tag_name == '' && env.NEW_COMMIT_COUNT > 0 }}
with: with:
context: . context: .
pull: true pull: true
push: true push: true
tags: quay.io/bakito/adguardhome-sync:${{ matrix.build.tagPrefix }}main,ghcr.io/bakito/adguardhome-sync:${{ matrix.build.tagPrefix }}main tags: quay.io/bakito/adguardhome-sync:${{ matrix.build.tagPrefix }}main,ghcr.io/bakito/adguardhome-sync:${{ matrix.build.tagPrefix }}main
platforms: linux/amd64,linux/arm64,linux/arm/v7 platforms: linux/amd64,linux/arm64,linux/arm/v7
provenance: false
build-args: | build-args: |
VERSION=main VERSION=main
BUILD=${{ env.curr_date }} BUILD=${{ env.curr_date }}
- name: Image digest - name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }} run: echo ${{ steps.docker_build.outputs.digest }}
test:
needs: images
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Create kind cluster
uses: helm/kind-action@v1.4.0
with:
version: v0.14.0
kubectl_version: v1.24.0
- name: Install Helm Chart
run: ./testdata/e2e/bin/install-chart.sh
- name: Wait for sync to finish
run: ./testdata/e2e/bin/wait-for-sync.sh
- name: Show origin Logs
run: ./testdata/e2e/bin/show-origin-logs.sh
- name: Show Replica Logs
run: ./testdata/e2e/bin/show-replica-logs.sh
- name: Show Sync Logs
run: ./testdata/e2e/bin/show-sync-logs.sh

17
.github/workflows/stale.yml vendored Normal file
View File

@@ -0,0 +1,17 @@
name: Mark stale issues and pull requests
on:
schedule:
- cron: "0 0 * * *"
jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v9
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'This issue has been inactive for 60 days. If the issue is still relevant please comment to re-activate the issue. If no action is taken within 7 days, the issue will be marked closed.'
stale-pr-message: 'This pull request has been inactive for 60 days. If the pull request is still relevant please comment to re-activate the pull request. If no action is taken within 7 days, the pull request will be marked closed.'

10
.gitignore vendored
View File

@@ -1,7 +1,15 @@
.vscode
.idea .idea
coverage.out .fleet
.run
coverage.out*
dist dist
adguardhome-sync adguardhome-sync
main main
.adguardhome-sync.yaml .adguardhome-sync.yaml
tmp tmp
bin
config*.yaml
*.log
wiki
Taskfile.yml

View File

@@ -3,37 +3,35 @@ run:
linters: linters:
enable: enable:
- asciicheck - asciicheck
- bodyclose - bodyclose
- depguard - dogsled
- dogsled - durationcheck
- durationcheck - errcheck
- errcheck - errorlint
- errorlint - gci
- exportloopref - gofmt
- gci - gofumpt
- gofmt - goimports
- gofumpt - gosec
- goimports - gosimple
- gosec - govet
- gosimple - importas
- govet - ineffassign
- importas - megacheck
- ineffassign - misspell
- megacheck - nakedret
- misspell - nolintlint
- nakedret - staticcheck
- nolintlint - unconvert
- revive - unparam
- staticcheck - unused
- unconvert
- unparam
- unused
- wastedassign
linters-settings: linters-settings:
gosec: gosec:
# Exclude generated files # Exclude generated files
exclude-generated: true exclude-generated: true
excludes:
- G601 # not applicable in go 1.22 anymore
gofmt: gofmt:
# simplify code: gofmt with `-s` option, true by default # simplify code: gofmt with `-s` option, true by default
simplify: true simplify: true

View File

@@ -28,11 +28,9 @@ builds:
- goos: windows - goos: windows
goarch: arm64 goarch: arm64
hooks: hooks:
post: upx {{ .Path }} post:
archives: # don't upx windows binaries as they make trouble with virus scanners
- replacements: - bash -c 'if [[ "{{ .Path }}" != *.exe ]] && [[ "{{ .Path }}" != *darwin* ]]; then upx {{ .Path }}; fi'
386: i386
amd64: x86_64
checksum: checksum:
name_template: 'checksums.txt' name_template: 'checksums.txt'
snapshot: snapshot:
@@ -44,4 +42,4 @@ changelog:
- '^docs:' - '^docs:'
- '^test:' - '^test:'
release: release:
prerelease: auto prerelease: auto

3
.oapi-codegen.yaml Normal file
View File

@@ -0,0 +1,3 @@
output-options:
client-type-name: AdguardHomeClient
response-type-suffix: Resp

View File

@@ -1,8 +1,10 @@
FROM golang:1.18 as builder FROM golang:1.22-bullseye as builder
WORKDIR /go/src/app WORKDIR /go/src/app
RUN apt-get update && apt-get install -y upx RUN apt-get update && \
apt-get install -y upx ca-certificates tzdata && \
apt-get upgrade -y # upgrade to get latest ca-certs
ARG VERSION=main ARG VERSION=main
ARG BUILD="N/A" ARG BUILD="N/A"
@@ -24,6 +26,7 @@ LABEL maintainer="bakito <github@bakito.ch>"
EXPOSE 8080 EXPOSE 8080
ENTRYPOINT ["/opt/go/adguardhome-sync"] ENTRYPOINT ["/opt/go/adguardhome-sync"]
CMD ["run", "--config", "/config/adguardhome-sync.yaml"] CMD ["run", "--config", "/config/adguardhome-sync.yaml"]
COPY --from=builder /go/src/app/adguardhome-sync /opt/go/adguardhome-sync
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /usr/share/zoneinfo/ /usr/share/zoneinfo/
COPY --from=builder /go/src/app/adguardhome-sync /opt/go/adguardhome-sync
USER 1001 USER 1001

116
Makefile
View File

@@ -1,51 +1,107 @@
# Run go lint against code # Run go lint against code
lint: lint: golangci-lint
golangci-lint run --fix $(GOLANGCI_LINT) run --fix
# Run go mod tidy # Run go mod tidy
tidy: tidy:
go mod tidy go mod tidy
generate: deepcopy-gen generate: deepcopy-gen
touch ./tmp/deepcopy-gen-boilerplate.go.txt @mkdir -p ./tmp
deepcopy-gen -h ./tmp/deepcopy-gen-boilerplate.go.txt -i ./pkg/types @touch ./tmp/deepcopy-gen-boilerplate.go.txt
$(DEEPCOPY_GEN) -h ./tmp/deepcopy-gen-boilerplate.go.txt -i ./pkg/types
# Run tests # Run tests
test: generate lint test-ci test: generate lint test-ci
# Run ci tests # Run ci tests
test-ci: mocks tidy test-ci: mocks tidy ginkgo
go test ./... -coverprofile=coverage.out $(GINKGO) --cover --coverprofile coverage.out.tmp ./...
cat coverage.out.tmp | grep -v "_generated.go" > coverage.out
go tool cover -func=coverage.out go tool cover -func=coverage.out
mocks: mockgen mocks: mockgen
mockgen -package client -destination pkg/mocks/client/mock.go github.com/bakito/adguardhome-sync/pkg/client Client $(MOCKGEN) -package client -destination pkg/mocks/client/mock.go github.com/bakito/adguardhome-sync/pkg/client Client
$(MOCKGEN) -package client -destination pkg/mocks/flags/mock.go github.com/bakito/adguardhome-sync/pkg/config Flags
release: semver release: semver goreleaser
@version=$$(semver); \ @version=$$($(LOCALBIN)/semver); \
git tag -s $$version -m"Release $$version" git tag -s $$version -m"Release $$version"
goreleaser --rm-dist $(GORELEASER) --clean
test-release: test-release: goreleaser
goreleaser --skip-publish --snapshot --rm-dist $(GORELEASER) --skip=publish --snapshot --clean
semver: ## toolbox - start
ifeq (, $(shell which semver)) ## Current working directory
$(shell go install github.com/bakito/semver@latest) LOCALDIR ?= $(shell which cygpath > /dev/null 2>&1 && cygpath -m $$(pwd) || pwd)
endif ## Location to install dependencies to
LOCALBIN ?= $(LOCALDIR)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
mockgen: ## Tool Binaries
ifeq (, $(shell which mockgen)) DEEPCOPY_GEN ?= $(LOCALBIN)/deepcopy-gen
$(shell go install github.com/golang/mock/mockgen@v1.6.0) GINKGO ?= $(LOCALBIN)/ginkgo
endif GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
GORELEASER ?= $(LOCALBIN)/goreleaser
MOCKGEN ?= $(LOCALBIN)/mockgen
OAPI_CODEGEN ?= $(LOCALBIN)/oapi-codegen
SEMVER ?= $(LOCALBIN)/semver
deepcopy-gen: ## Tool Installer
ifeq (, $(shell which deepcopy-gen)) .PHONY: deepcopy-gen
$(shell go install k8s.io/code-generator/cmd/deepcopy-gen@latest) deepcopy-gen: $(DEEPCOPY_GEN) ## Download deepcopy-gen locally if necessary.
endif $(DEEPCOPY_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/deepcopy-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/deepcopy-gen
.PHONY: ginkgo
ginkgo: $(GINKGO) ## Download ginkgo locally if necessary.
$(GINKGO): $(LOCALBIN)
test -s $(LOCALBIN)/ginkgo || GOBIN=$(LOCALBIN) go install github.com/onsi/ginkgo/v2/ginkgo
.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
test -s $(LOCALBIN)/golangci-lint || GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint
.PHONY: goreleaser
goreleaser: $(GORELEASER) ## Download goreleaser locally if necessary.
$(GORELEASER): $(LOCALBIN)
test -s $(LOCALBIN)/goreleaser || GOBIN=$(LOCALBIN) go install github.com/goreleaser/goreleaser
.PHONY: mockgen
mockgen: $(MOCKGEN) ## Download mockgen locally if necessary.
$(MOCKGEN): $(LOCALBIN)
test -s $(LOCALBIN)/mockgen || GOBIN=$(LOCALBIN) go install go.uber.org/mock/mockgen
.PHONY: oapi-codegen
oapi-codegen: $(OAPI_CODEGEN) ## Download oapi-codegen locally if necessary.
$(OAPI_CODEGEN): $(LOCALBIN)
test -s $(LOCALBIN)/oapi-codegen || GOBIN=$(LOCALBIN) go install github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen
.PHONY: semver
semver: $(SEMVER) ## Download semver locally if necessary.
$(SEMVER): $(LOCALBIN)
test -s $(LOCALBIN)/semver || GOBIN=$(LOCALBIN) go install github.com/bakito/semver
## Update Tools
.PHONY: update-toolbox-tools
update-toolbox-tools:
@rm -f \
$(LOCALBIN)/deepcopy-gen \
$(LOCALBIN)/ginkgo \
$(LOCALBIN)/golangci-lint \
$(LOCALBIN)/goreleaser \
$(LOCALBIN)/mockgen \
$(LOCALBIN)/oapi-codegen \
$(LOCALBIN)/semver
toolbox makefile -f $(LOCALDIR)/Makefile
## toolbox - end
start-replica: start-replica:
docker run --pull always --name adguardhome-replica -p 9090:80 -p 9091:3000 --rm adguard/adguardhome docker run --pull always --name adguardhome-replica -p 9091:3000 --rm adguard/adguardhome:latest
# docker run --pull always --name adguardhome-replica -p 9090:80 -p 9091:3000 --rm adguard/adguardhome:v0.107.13
copy-replica-config:
docker cp adguardhome-replica:/opt/adguardhome/conf/AdGuardHome.yaml tmp/AdGuardHome.yaml
start-replica2:
docker run --pull always --name adguardhome-replica2 -p 9093:3000 --rm adguard/adguardhome:latest
# docker run --pull always --name adguardhome-replica -p 9090:80 -p 9091:3000 --rm adguard/adguardhome:v0.107.13 # docker run --pull always --name adguardhome-replica -p 9090:80 -p 9091:3000 --rm adguard/adguardhome:v0.107.13
check_defined = \ check_defined = \
@@ -65,3 +121,13 @@ kind-create:
kind-test: kind-test:
@./testdata/e2e/bin/install-chart.sh @./testdata/e2e/bin/install-chart.sh
model: oapi-codegen
@mkdir -p tmp
go run openapi/main.go v0.107.46
$(OAPI_CODEGEN) -package model -generate types,client -config .oapi-codegen.yaml tmp/schema.yaml > pkg/client/model/model_generated.go
model-diff:
go run openapi/main.go v0.107.46
go run openapi/main.go
diff tmp/schema.yaml tmp/schema-master.yaml

125
README.md
View File

@@ -1,11 +1,18 @@
[![Go](https://github.com/bakito/adguardhome-sync/actions/workflows/go.yml/badge.svg)](https://github.com/bakito/adguardhome-sync/actions/workflows/go.yml) [![Go](https://github.com/bakito/adguardhome-sync/actions/workflows/go.yml/badge.svg)](https://github.com/bakito/adguardhome-sync/actions/workflows/go.yml)
[![e2e tests](https://github.com/bakito/adguardhome-sync/actions/workflows/e2e.yaml/badge.svg)](https://github.com/bakito/adguardhome-sync/actions/workflows/e2e.yaml)
[![Go Report Card](https://goreportcard.com/badge/github.com/bakito/adguardhome-sync)](https://goreportcard.com/report/github.com/bakito/adguardhome-sync) [![Go Report Card](https://goreportcard.com/badge/github.com/bakito/adguardhome-sync)](https://goreportcard.com/report/github.com/bakito/adguardhome-sync)
[![Coverage Status](https://coveralls.io/repos/github/bakito/adguardhome-sync/badge.svg?branch=main)](https://coveralls.io/github/bakito/adguardhome-sync?branch=main) [![Coverage Status](https://coveralls.io/repos/github/bakito/adguardhome-sync/badge.svg?branch=main&service=github)](https://coveralls.io/github/bakito/adguardhome-sync?branch=main)
# AdGuardHome sync # AdGuardHome sync
Synchronize [AdGuardHome](https://github.com/AdguardTeam/AdGuardHome) config to replica instances. Synchronize [AdGuardHome](https://github.com/AdguardTeam/AdGuardHome) config to replica instances.
## FAQ & Deprecations
Please check the wiki
for [FAQ](https://github.com/bakito/adguardhome-sync/wiki/FAQ)
and [Deprecations](https://github.com/bakito/adguardhome-sync/wiki/Deprecations).
## Current sync features ## Current sync features
- General Settings - General Settings
@@ -37,16 +44,28 @@ go install github.com/bakito/adguardhome-sync@latest
Both the origin instance must be initially setup via the AdguardHome installation wizard. Both the origin instance must be initially setup via the AdguardHome installation wizard.
## Username / Password vs. Cookie
Some instances of AdGuard Home do not support basic authentication. For instance, many routers with built-in Adguard
Home support do not. If this is the case, a valid cookie may be provided instead. If the router protects the AdGuard
instance behind its own authentication, the cookie from an authenticated request may allow the sync to succeed.
- This has been tested successfully against GL.Inet routers with AdGuard Home.
- Note: due to the short validity of cookies, this approach is likely only suitable for one-time syncs
## Run Linux/Mac ## Run Linux/Mac
```bash ```bash
export LOG_LEVEL=info
export ORIGIN_URL=https://192.168.1.2:3000 export ORIGIN_URL=https://192.168.1.2:3000
export ORIGIN_USERNAME=username export ORIGIN_USERNAME=username
export ORIGIN_PASSWORD=password export ORIGIN_PASSWORD=password
export REPLICA_URL=http://192.168.1.3 # export ORIGIN_COOKIE=Origin-Cookie-Name=CCCOOOKKKIIIEEE
export REPLICA_USERNAME=username export REPLICA1_URL=http://192.168.1.3
export REPLICA_PASSWORD=password export REPLICA1_USERNAME=username
export REPLICA1_PASSWORD=password
# export REPLICA_COOKIE=Replica-Cookie-Name=CCCOOOKKKIIIEEE
# run once # run once
adguardhome-sync run adguardhome-sync run
@@ -69,10 +88,12 @@ REM set LOG_LEVEL=error
set ORIGIN_URL=http://192.168.1.2:3000 set ORIGIN_URL=http://192.168.1.2:3000
set ORIGIN_USERNAME=username set ORIGIN_USERNAME=username
set ORIGIN_PASSWORD=password set ORIGIN_PASSWORD=password
# set ORIGIN_COOKIE=Origin-Cookie-Name=CCCOOOKKKIIIEEE
set REPLICA_URL=http://192.168.2.2:3000 set REPLICA1_URL=http://192.168.2.2:3000
set REPLICA_USERNAME=username set REPLICA1_USERNAME=username
set REPLICA_PASSWORD=password set REPLICA1_PASSWORD=password
# set REPLICA1_COOKIE=Replica-Cookie-Name=CCCOOOKKKIIIEEE
set FEATURES_DHCP=false set FEATURES_DHCP=false
set FEATURES_DHCP_SERVERCONFIG=false set FEATURES_DHCP_SERVERCONFIG=false
@@ -126,31 +147,44 @@ services:
container_name: adguardhome-sync container_name: adguardhome-sync
command: run command: run
environment: environment:
ORIGIN_URL: 'https://192.168.1.2:3000' LOG_LEVEL: "info"
ORIGIN_USERNAME: 'username' ORIGIN_URL: "https://192.168.1.2:3000"
ORIGIN_PASSWORD: 'password' # ORIGIN_WEB_URL: "https://some-other.url" # used in the web interface (default: <origin-url>
REPLICA_URL: 'http://192.168.1.3'
REPLICA_USERNAME: 'username' ORIGIN_USERNAME: "username"
REPLICA_PASSWORD: 'password' ORIGIN_PASSWORD: "password"
REPLICA1_URL: 'http://192.168.1.4' REPLICA1_URL: "http://192.168.1.3"
REPLICA1_USERNAME: 'username' REPLICA1_USERNAME: "username"
REPLICA1_PASSWORD: 'password' REPLICA1_PASSWORD: "password"
REPLICA1_APIPATH: '/some/path/control' REPLICA2_URL: "http://192.168.1.4"
# REPLICA1_AUTOSETUP: true # if true, AdGuardHome is automatically initialized. REPLICA2_USERNAME: "username"
# REPLICA1_INTERFACENAME: 'ens18' # use custom dhcp interface name REPLICA2_PASSWORD: "password"
CRON: '*/10 * * * *' # run every 10 minutes REPLICA2_API_PATH: "/some/path/control"
# REPLICA2_WEB_URL: "https://some-other.url" # used in the web interface (default: <replica-url>
# REPLICA2_AUTO_SETUP: true # if true, AdGuardHome is automatically initialized.
# REPLICA2_INTERFACE_NAME: 'ens18' # use custom dhcp interface name
# REPLICA2_DHCP_SERVER_ENABLED: true/false (optional) enables/disables the dhcp server on the replica
CRON: "*/10 * * * *" # run every 10 minutes
RUNONSTART: true RUNONSTART: true
# CONTINUE_ON_ERROR: false # If enabled, the synchronisation task will not fail on single errors, but will log the errors and continue
# Configure the sync API server, disabled if api port is 0
API_PORT: 8080
# API_DARK_MODE: true
# API_USERNAME: admin
# API_PASSWORD: secret
# Configure sync features; by default all features are enabled. # Configure sync features; by default all features are enabled.
# FEATURES_GENERALSETTINGS: true # FEATURES_GENERAL_SETTINGS: true
# FEATURES_QUERYLOGCONFIG: true # FEATURES_QUERY_LOG_CONFIG: true
# FEATURES_STATSCONFIG: true # FEATURES_STATS_CONFIG: true
# FEATURES_CLIENTSETTINGS: true # FEATURES_CLIENT_SETTINGS: true
# FEATURES_SERVICES: true # FEATURES_SERVICES: true
# FEATURES_FILTERS: true # FEATURES_FILTERS: true
# FEATURES_DHCP_SERVERCONFIG: true # FEATURES_DHCP_SERVER_CONFIG: true
# FEATURES_DHCP_STATICLEASES: true # FEATURES_DHCP_STATIC_LEASES: true
# FEATURES_DNS_SERVERCONFIG: true # FEATURES_DNS_SERVER_CONFIG: true
# FEATURES_DNS_ACCESSLISTS: true # FEATURES_DNS_ACCESS_LISTS: true
# FEATURES_DNS_REWRITES: true # FEATURES_DNS_REWRITES: true
ports: ports:
- 8080:8080 - 8080:8080
@@ -168,6 +202,9 @@ cron: "*/10 * * * *"
# runs the synchronisation on startup # runs the synchronisation on startup
runOnStart: true runOnStart: true
# If enabled, the synchronisation task will not fail on single errors, but will log the errors and continue
continueOnError: false
origin: origin:
# url of the origin instance # url of the origin instance
url: https://192.168.1.2:3000 url: https://192.168.1.2:3000
@@ -175,32 +212,37 @@ origin:
# insecureSkipVerify: true # disable tls check # insecureSkipVerify: true # disable tls check
username: username username: username
password: password password: password
# cookie: Origin-Cookie-Name=CCCOOOKKKIIIEEE
# replica instance (optional, if only one) # replicas instances
replica:
# url of the replica instance
url: http://192.168.1.3
username: username
password: password
# replicas instances (optional, if more than one)
replicas: replicas:
# url of the replica instance # url of the replica instance
- url: http://192.168.1.3 - url: http://192.168.1.3
username: username username: username
password: password password: password
# cookie: Replica1-Cookie-Name=CCCOOOKKKIIIEEE
- url: http://192.168.1.4 - url: http://192.168.1.4
username: username username: username
password: password password: password
# autoSetup: true # if true, AdGuardHome is automatically initialized. # cookie: Replica2-Cookie-Name=CCCOOOKKKIIIEEE
# autoSetup: true # if true, AdGuardHome is automatically initialized.
# webURL: "https://some-other.url" # used in the web interface (default: <replica-url>
# Configure the sync API server, disabled if api port is 0 # Configure the sync API server, disabled if api port is 0
api: api:
# Port, default 8080 # Port, default 8080
port: 8080 port: 8080
# if username and password are defined, basic auth is applied to the sync API # if username and password are defined, basic auth is applied to the sync API
username: username username: username
password: password password: password
# enable api dark mode
darkMode: true
# enable metrics on path '/metrics' (api port must be != 0)
# metrics:
# enabled: true
# scrapeInterval: 30s
# queryLogLimit: 10000
# Configure sync features; by default all features are enabled. # Configure sync features; by default all features are enabled.
features: features:
@@ -221,7 +263,7 @@ features:
## Log Level ## Log Level
The log level can be set with the environment variable: LOG_LEVEL The log level can be set with the environment variable: `LOG_LEVEL`
The following log levels are supported (default: info) The following log levels are supported (default: info)
@@ -229,3 +271,8 @@ The following log levels are supported (default: info)
- info - info
- warn - warn
- error - error
## Log Format
Default log format is `console`.
It can be changed to `json`by setting the environment variable: `LOG_FORMAT=json`

135
Taskfile.yml Normal file
View File

@@ -0,0 +1,135 @@
version: '3'
env:
AGH_MODEL_VERSION: v0.107.43
GOBIN: '{{.USER_WORKING_DIR}}/bin'
tasks:
install-go-tool:
label: "Install {{ .TOOL_NAME }}"
cmds:
- go install {{ .TOOL_MODULE }}
status:
- test -f {{.GOBIN}}/{{.TOOL_NAME}}
deepcopy-gen:
desc: Install deepcopy-gen
cmd:
task: install-go-tool
vars:
TOOL_NAME: deepcopy-gen
TOOL_MODULE: k8s.io/code-generator/cmd/deepcopy-gen
ginkgo:
cmd:
task: install-go-tool
vars:
TOOL_NAME: ginkgo
TOOL_MODULE: github.com/onsi/ginkgo/v2/ginkgo
goreleaser:
cmd:
task: install-go-tool
vars:
TOOL_NAME: goreleaser
TOOL_MODULE: github.com/goreleaser/goreleaser
golangci-lint:
cmd:
task: install-go-tool
vars:
TOOL_NAME: golangci-lint
TOOL_MODULE: github.com/golangci/golangci-lint/cmd/golangci-lint
mockgen:
cmd:
task: install-go-tool
vars:
TOOL_NAME: mockgen
TOOL_MODULE: go.uber.org/mock/mockgen
oapi-codegen:
cmd:
task: install-go-tool
vars:
TOOL_NAME: oapi-codegen
TOOL_MODULE: github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen
semver:
cmd:
task: install-go-tool
vars:
TOOL_NAME: semver
TOOL_MODULE: github.com/bakito/semver
lint:
deps:
- golangci-lint
cmds:
- '{{.GOBIN}}/golangci-lint run --fix'
tidy:
desc: Run go mod tidy
cmd: go mod tidy
generate:
deps:
- deepcopy-gen
cmds:
- mkdir -p ./tmp
- touch ./tmp/deepcopy-gen-boilerplate.go.txt
- '{{.GOBIN}}/deepcopy-gen -h ./tmp/deepcopy-gen-boilerplate.go.txt -i ./pkg/types'
mocks:
deps:
- mockgen
cmds:
- '{{.GOBIN}}/mockgen -package client -destination pkg/mocks/client/mock.go github.com/bakito/adguardhome-sync/pkg/client Client'
- '{{.GOBIN}}/mockgen -package client -destination pkg/mocks/flags/mock.go github.com/bakito/adguardhome-sync/pkg/config Flags'
test:
cmds:
- task: generate
- task: lint
- task: test-ci
test-ci:
deps:
- ginkgo
- tidy
- mocks
cmds:
- '{{.GOBIN}}/ginkgo --cover --coverprofile coverage.out.tmp ./...'
- cat coverage.out.tmp | grep -v "_generated.go" > coverage.out
- go tool cover -func=coverage.out
release:
deps:
- semver
- goreleaser
cmds:
- git tag -s $$version -m"Release $({{.GOBIN}}/semver)
- '{{.GOBIN}}/goreleaser --clean'
test-release:
deps:
- goreleaser
- semver
cmds:
- '{{.GOBIN}}/goreleaser --skip=publish --snapshot --clean'
model:
deps:
- oapi-codegen
cmds:
- mkdir -p tmp
- go run openapi/main.go {{.AGH_MODEL_VERSION}}
- '{{.GOBIN}}/oapi-codegen -package model -generate types,client -config .oapi-codegen.yaml tmp/schema.yaml > pkg/client/model/model_generated.go'
model-diff:
deps:
- oapi-codegen
cmds:
- go run openapi/main.go {{.AGH_MODEL_VERSION}}
- go run openapi/main.go
- diff tmp/schema.yaml tmp/schema-master.yaml

View File

@@ -3,64 +3,15 @@ package cmd
import ( import (
"fmt" "fmt"
"os" "os"
"regexp"
"strings"
"github.com/bakito/adguardhome-sync/pkg/log" "github.com/bakito/adguardhome-sync/pkg/log"
"github.com/bakito/adguardhome-sync/pkg/types"
"github.com/bakito/adguardhome-sync/version" "github.com/bakito/adguardhome-sync/version"
"github.com/mitchellh/go-homedir"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper"
)
const (
configCron = "cron"
configRunOnStart = "runOnStart"
configAPIPort = "api.port"
configAPIUsername = "api.username"
configAPIPassword = "api.password"
configAPIDarkMode = "api.darkMode"
configFeatureDHCPServerConfig = "features.dhcp.serverConfig"
configFeatureDHCPStaticLeases = "features.dhcp.staticLeases"
configFeatureDNServerConfig = "features.dns.serverConfig"
configFeatureDNSPAccessLists = "features.dns.accessLists"
configFeatureDNSRewrites = "features.dns.rewrites"
configFeatureGeneralSettings = "features.generalSettings"
configFeatureQueryLogConfig = "features.queryLogConfig"
configFeatureStatsConfig = "features.statsConfig"
configFeatureClientSettings = "features.clientSettings"
configFeatureServices = "features.services"
configFeatureFilters = "features.filters"
configOriginURL = "origin.url"
configOriginAPIPath = "origin.apiPath"
configOriginUsername = "origin.username"
configOriginPassword = "origin.password"
configOriginInsecureSkipVerify = "origin.insecureSkipVerify"
configReplicaURL = "replica.url"
configReplicaAPIPath = "replica.apiPath"
configReplicaUsername = "replica.username"
configReplicaPassword = "replica.password"
configReplicaInsecureSkipVerify = "replica.insecureSkipVerify"
configReplicaAutoSetup = "replica.autoSetup"
configReplicaInterfaceName = "replica.interfaceName"
envReplicasUsernameFormat = "REPLICA%s_USERNAME" // #nosec G101
envReplicasPasswordFormat = "REPLICA%s_PASSWORD" // #nosec G101
envReplicasAPIPathFormat = "REPLICA%s_APIPATH"
envReplicasInsecureSkipVerifyFormat = "REPLICA%s_INSECURESKIPVERIFY"
envReplicasAutoSetup = "REPLICA%s_AUTOSETUP"
envReplicasInterfaceName = "REPLICA%s_INTERFACWENAME"
) )
var ( var (
cfgFile string cfgFile string
logger = log.GetLogger("root") logger = log.GetLogger("root")
envReplicasURLPattern = regexp.MustCompile(`^REPLICA(\d+)_URL=(.*)`)
) )
// rootCmd represents the base command when called without any subcommands // rootCmd represents the base command when called without any subcommands
@@ -80,8 +31,6 @@ func Execute() {
} }
func init() { func init() {
cobra.OnInitialize(initConfig)
// Here you will define your flags and configuration settings. // Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here, // Cobra supports persistent flags, which, if defined here,
// will be global for your application. // will be global for your application.
@@ -92,66 +41,3 @@ func init() {
// when this action is called directly. // when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
} }
// initConfig reads in config file and ENV variables if set.
func initConfig() {
if cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
} else {
// Find home directory.
home, err := homedir.Dir()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// Search config in home directory with name ".adguardhome-sync" (without extension).
viper.AddConfigPath(home)
viper.SetConfigName(".adguardhome-sync")
}
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_", ".", "_"))
viper.AutomaticEnv() // read in environment variables that match
// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
logger.Info("Using config file:", viper.ConfigFileUsed())
} else if cfgFile != "" {
fmt.Println(err)
os.Exit(1)
}
}
func getConfig() (*types.Config, error) {
cfg := &types.Config{}
if err := viper.Unmarshal(cfg); err != nil {
return nil, err
}
if len(cfg.Replicas) == 0 {
cfg.Replicas = append(cfg.Replicas, collectEnvReplicas()...)
}
return cfg, nil
}
// Manually collect replicas from env.
func collectEnvReplicas() []types.AdGuardInstance {
var replicas []types.AdGuardInstance
for _, v := range os.Environ() {
if envReplicasURLPattern.MatchString(v) {
sm := envReplicasURLPattern.FindStringSubmatch(v)
re := types.AdGuardInstance{
URL: sm[2],
Username: os.Getenv(fmt.Sprintf(envReplicasUsernameFormat, sm[1])),
Password: os.Getenv(fmt.Sprintf(envReplicasPasswordFormat, sm[1])),
APIPath: os.Getenv(fmt.Sprintf(envReplicasAPIPathFormat, sm[1])),
InsecureSkipVerify: strings.EqualFold(os.Getenv(fmt.Sprintf(envReplicasInsecureSkipVerifyFormat, sm[1])), "true"),
AutoSetup: strings.EqualFold(os.Getenv(fmt.Sprintf(envReplicasAutoSetup, sm[1])), "true"),
InterfaceName: os.Getenv(fmt.Sprintf(envReplicasInterfaceName, sm[1])),
}
replicas = append(replicas, re)
}
}
return replicas
}

View File

@@ -1,61 +0,0 @@
package cmd
import (
"os"
"github.com/bakito/adguardhome-sync/pkg/types"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var envVars = []string{
"FEATURES_GENERALSETTINGS",
"FEATURES_QUERYLOGCONFIG",
"FEATURES_STATSCONFIG",
"FEATURES_CLIENTSETTINGS",
"FEATURES_SERVICES",
"FEATURES_FILTERS",
"FEATURES_DHCP_SERVERCONFIG",
"FEATURES_DHCP_STATICLEASES",
"FEATURES_DNS_SERVERCONFIG",
"FEATURES_DNS_ACCESSLISTS",
"FEATURES_DNS_REWRITES",
}
var _ = Describe("Run", func() {
BeforeEach(func() {
for _, envVar := range envVars {
Ω(os.Unsetenv(envVar)).ShouldNot(HaveOccurred())
}
initConfig()
})
Context("getConfig", func() {
It("features should be true by default", func() {
cfg, err := getConfig()
Ω(err).ShouldNot(HaveOccurred())
verifyFeatures(cfg, true)
})
It("features should be false", func() {
for _, envVar := range envVars {
Ω(os.Setenv(envVar, "false")).ShouldNot(HaveOccurred())
}
cfg, err := getConfig()
Ω(err).ShouldNot(HaveOccurred())
verifyFeatures(cfg, false)
})
})
})
func verifyFeatures(cfg *types.Config, value bool) {
Ω(cfg.Features.GeneralSettings).Should(Equal(value))
Ω(cfg.Features.QueryLogConfig).Should(Equal(value))
Ω(cfg.Features.StatsConfig).Should(Equal(value))
Ω(cfg.Features.ClientSettings).Should(Equal(value))
Ω(cfg.Features.Services).Should(Equal(value))
Ω(cfg.Features.Filters).Should(Equal(value))
Ω(cfg.Features.DHCP.ServerConfig).Should(Equal(value))
Ω(cfg.Features.DHCP.StaticLeases).Should(Equal(value))
Ω(cfg.Features.DNS.ServerConfig).Should(Equal(value))
Ω(cfg.Features.DNS.AccessLists).Should(Equal(value))
Ω(cfg.Features.DNS.Rewrites).Should(Equal(value))
}

View File

@@ -1,10 +1,11 @@
package cmd package cmd
import ( import (
"github.com/bakito/adguardhome-sync/pkg/config"
"github.com/bakito/adguardhome-sync/pkg/log" "github.com/bakito/adguardhome-sync/pkg/log"
"github.com/bakito/adguardhome-sync/pkg/sync" "github.com/bakito/adguardhome-sync/pkg/sync"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "gopkg.in/yaml.v3"
) )
// runCmd represents the run command // runCmd represents the run command
@@ -14,79 +15,75 @@ var doCmd = &cobra.Command{
Long: `Synchronizes the configuration form an origin instance to a replica`, Long: `Synchronizes the configuration form an origin instance to a replica`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
logger = log.GetLogger("run") logger = log.GetLogger("run")
cfg, err := getConfig() cfg, err := config.Get(cfgFile, cmd.Flags())
if err != nil { if err != nil {
logger.Error(err) logger.Error(err)
return err return err
} }
if err := cfg.Init(); err != nil {
logger.Error(err)
return err
}
if cfg.PrintConfigOnly {
config, err := yaml.Marshal(cfg)
if err != nil {
logger.Error(err)
return err
}
logger.Infof("Printing adguardhome-sync config (THE APPLICATION WILL NOT START IN THIS MODE): \n%s",
string(config))
return nil
}
return sync.Sync(cfg) return sync.Sync(cfg)
}, },
} }
func init() { func init() {
rootCmd.AddCommand(doCmd) rootCmd.AddCommand(doCmd)
doCmd.PersistentFlags().String("cron", "", "The cron expression to run in daemon mode") doCmd.PersistentFlags().String(config.FlagCron, "", "The cron expression to run in daemon mode")
_ = viper.BindPFlag(configCron, doCmd.PersistentFlags().Lookup("cron")) doCmd.PersistentFlags().Bool(config.FlagRunOnStart, true, "Run the sync job on start.")
doCmd.PersistentFlags().Bool("runOnStart", true, "Run the sync job on start.") doCmd.PersistentFlags().Bool(config.FlagPrintConfigOnly, false, "Prints the configuration only and exists. "+
_ = viper.BindPFlag(configRunOnStart, doCmd.PersistentFlags().Lookup("runOnStart")) "Can be used to debug the config E.g: when having authentication issues.")
doCmd.PersistentFlags().Int("api-port", 8080, "Sync API Port, the API endpoint will be started to enable remote triggering; if 0 port API is disabled.") doCmd.PersistentFlags().Bool(config.FlagContinueOnError, false, "If enabled, the synchronisation task "+
_ = viper.BindPFlag(configAPIPort, doCmd.PersistentFlags().Lookup("api-port")) "will not fail on single errors, but will log the errors and continue.")
doCmd.PersistentFlags().String("api-username", "", "Sync API username")
_ = viper.BindPFlag(configAPIUsername, doCmd.PersistentFlags().Lookup("api-username"))
doCmd.PersistentFlags().String("api-password", "", "Sync API password")
_ = viper.BindPFlag(configAPIPassword, doCmd.PersistentFlags().Lookup("api-password"))
doCmd.PersistentFlags().String("api-darkMode", "", "API UI in dark mode")
_ = viper.BindPFlag(configAPIDarkMode, doCmd.PersistentFlags().Lookup("api-darkMode"))
doCmd.PersistentFlags().Bool("feature-dhcp-server-config", true, "Enable DHCP server config feature") doCmd.PersistentFlags().Int(config.FlagApiPort, 8080, "Sync API Port, the API endpoint will be started to enable remote triggering; if 0 port API is disabled.")
_ = viper.BindPFlag(configFeatureDHCPServerConfig, doCmd.PersistentFlags().Lookup("feature-dhcp-server-config")) doCmd.PersistentFlags().String(config.FlagApiUsername, "", "Sync API username")
doCmd.PersistentFlags().Bool("feature-dhcp-static-leases", true, "Enable DHCP server static leases feature") doCmd.PersistentFlags().String(config.FlagApiPassword, "", "Sync API password")
_ = viper.BindPFlag(configFeatureDHCPStaticLeases, doCmd.PersistentFlags().Lookup("feature-dhcp-static-leases")) doCmd.PersistentFlags().String(config.FlagApiDarkMode, "", "API UI in dark mode")
doCmd.PersistentFlags().Bool("feature-dns-server-config", true, "Enable DNS server config feature") doCmd.PersistentFlags().Bool(config.FlagFeatureDhcpServerConfig, true, "Enable DHCP server config feature")
_ = viper.BindPFlag(configFeatureDNServerConfig, doCmd.PersistentFlags().Lookup("feature-dns-server-config")) doCmd.PersistentFlags().Bool(config.FlagFeatureDhcpStaticLeases, true, "Enable DHCP server static leases feature")
doCmd.PersistentFlags().Bool("feature-dns-access-lists", true, "Enable DNS server access lists feature")
_ = viper.BindPFlag(configFeatureDNSPAccessLists, doCmd.PersistentFlags().Lookup("feature-dns-access-lists"))
doCmd.PersistentFlags().Bool("feature-dns-rewrites", true, "Enable DNS rewrites feature")
_ = viper.BindPFlag(configFeatureDNSRewrites, doCmd.PersistentFlags().Lookup("feature-dns-rewrites"))
doCmd.PersistentFlags().Bool("feature-general-settings", true, "Enable general settings feature")
_ = viper.BindPFlag(configFeatureGeneralSettings, doCmd.PersistentFlags().Lookup("feature-general-settings"))
_ = viper.BindPFlag("features.generalSettings", doCmd.PersistentFlags().Lookup("feature-general-settings"))
doCmd.PersistentFlags().Bool("feature-query-log-config", true, "Enable query log config feature")
_ = viper.BindPFlag(configFeatureQueryLogConfig, doCmd.PersistentFlags().Lookup("feature-query-log-config"))
doCmd.PersistentFlags().Bool("feature-stats-config", true, "Enable stats config feature")
_ = viper.BindPFlag(configFeatureStatsConfig, doCmd.PersistentFlags().Lookup("feature-stats-config"))
doCmd.PersistentFlags().Bool("feature-client-settings", true, "Enable client settings feature")
_ = viper.BindPFlag(configFeatureClientSettings, doCmd.PersistentFlags().Lookup("feature-client-settings"))
doCmd.PersistentFlags().Bool("feature-services", true, "Enable services sync feature")
_ = viper.BindPFlag(configFeatureServices, doCmd.PersistentFlags().Lookup("feature-services"))
doCmd.PersistentFlags().Bool("feature-filters", true, "Enable filters sync feature")
_ = viper.BindPFlag(configFeatureFilters, doCmd.PersistentFlags().Lookup("feature-filters"))
doCmd.PersistentFlags().String("origin-url", "", "Origin instance url") doCmd.PersistentFlags().Bool(config.FlagFeatureDnsServerConfig, true, "Enable DNS server config feature")
_ = viper.BindPFlag(configOriginURL, doCmd.PersistentFlags().Lookup("origin-url")) doCmd.PersistentFlags().Bool(config.FlagFeatureDnsAccessLists, true, "Enable DNS server access lists feature")
doCmd.PersistentFlags().String("origin-api-path", "/control", "Origin instance API path") doCmd.PersistentFlags().Bool(config.FlagFeatureDnsRewrites, true, "Enable DNS rewrites feature")
_ = viper.BindPFlag(configOriginAPIPath, doCmd.PersistentFlags().Lookup("origin-api-path"))
doCmd.PersistentFlags().String("origin-username", "", "Origin instance username")
_ = viper.BindPFlag(configOriginUsername, doCmd.PersistentFlags().Lookup("origin-username"))
doCmd.PersistentFlags().String("origin-password", "", "Origin instance password")
_ = viper.BindPFlag(configOriginPassword, doCmd.PersistentFlags().Lookup("origin-password"))
doCmd.PersistentFlags().String("origin-insecure-skip-verify", "", "Enable Origin instance InsecureSkipVerify")
_ = viper.BindPFlag(configOriginInsecureSkipVerify, doCmd.PersistentFlags().Lookup("origin-insecure-skip-verify"))
doCmd.PersistentFlags().String("replica-url", "", "Replica instance url") doCmd.PersistentFlags().Bool(config.FlagFeatureGeneral, true, "Enable general settings feature")
_ = viper.BindPFlag(configReplicaURL, doCmd.PersistentFlags().Lookup("replica-url")) doCmd.PersistentFlags().Bool(config.FlagFeatureQueryLog, true, "Enable query log config feature")
doCmd.PersistentFlags().String("replica-api-path", "/control", "Replica instance API path") doCmd.PersistentFlags().Bool(config.FlagFeatureStats, true, "Enable stats config feature")
_ = viper.BindPFlag(configReplicaAPIPath, doCmd.PersistentFlags().Lookup("replica-api-path")) doCmd.PersistentFlags().Bool(config.FlagFeatureClient, true, "Enable client settings feature")
doCmd.PersistentFlags().String("replica-username", "", "Replica instance username") doCmd.PersistentFlags().Bool(config.FlagFeatureServices, true, "Enable services sync feature")
_ = viper.BindPFlag(configReplicaUsername, doCmd.PersistentFlags().Lookup("replica-username")) doCmd.PersistentFlags().Bool(config.FlagFeatureFilters, true, "Enable filters sync feature")
doCmd.PersistentFlags().String("replica-password", "", "Replica instance password")
_ = viper.BindPFlag(configReplicaPassword, doCmd.PersistentFlags().Lookup("replica-password")) doCmd.PersistentFlags().String(config.FlagOriginURL, "", "Origin instance url")
doCmd.PersistentFlags().Bool("replica-insecure-skip-verify", false, "Enable Replica instance InsecureSkipVerify") doCmd.PersistentFlags().String(config.FlagOriginWebURL, "", "Origin instance web url used in the web interface (default: <origin-url>)")
_ = viper.BindPFlag(configReplicaInsecureSkipVerify, doCmd.PersistentFlags().Lookup("replica-insecure-skip-verify")) doCmd.PersistentFlags().String(config.FlagOriginApiPath, "/control", "Origin instance API path")
doCmd.PersistentFlags().Bool("replica-auto-setup", false, "Enable automatic setup of new AdguardHome instances. This replaces the setup wizard.") doCmd.PersistentFlags().String(config.FlagOriginUsername, "", "Origin instance username")
_ = viper.BindPFlag(configReplicaAutoSetup, doCmd.PersistentFlags().Lookup("replica-auto-setup")) doCmd.PersistentFlags().String(config.FlagOriginPassword, "", "Origin instance password")
doCmd.PersistentFlags().Bool("replica-interface-name", false, "Optional change the interface name of the replica if it differs from the master") doCmd.PersistentFlags().String(config.FlagOriginCookie, "", "If Set, uses a cookie for authentication")
_ = viper.BindPFlag(configReplicaInterfaceName, doCmd.PersistentFlags().Lookup("replica-interface-name")) doCmd.PersistentFlags().Bool(config.FlagOriginISV, false, "Enable Origin instance InsecureSkipVerify")
doCmd.PersistentFlags().String(config.FlagReplicaURL, "", "Replica instance url")
doCmd.PersistentFlags().String(config.FlagReplicaWebURL, "", "Replica instance web url used in the web interface (default: <replica-url>)")
doCmd.PersistentFlags().String(config.FlagReplicaApiPath, "/control", "Replica instance API path")
doCmd.PersistentFlags().String(config.FlagReplicaUsername, "", "Replica instance username")
doCmd.PersistentFlags().String(config.FlagReplicaPassword, "", "Replica instance password")
doCmd.PersistentFlags().String(config.FlagReplicaCookie, "", "If Set, uses a cookie for authentication")
doCmd.PersistentFlags().Bool(config.FlagReplicaISV, false, "Enable Replica instance InsecureSkipVerify")
doCmd.PersistentFlags().Bool(config.FlagReplicaAutoSetup, false, "Enable automatic setup of new AdguardHome instances. This replaces the setup wizard.")
doCmd.PersistentFlags().String(config.FlagReplicaInterfaceName, "", "Optional change the interface name of the replica if it differs from the master")
} }

453
go.mod
View File

@@ -1,57 +1,432 @@
module github.com/bakito/adguardhome-sync module github.com/bakito/adguardhome-sync
go 1.18 go 1.22
require ( require (
github.com/gin-gonic/gin v1.8.1 github.com/bakito/semver v1.1.3
github.com/go-resty/resty/v2 v2.7.0 github.com/caarlos0/env/v10 v10.0.0
github.com/golang/mock v1.6.0 github.com/deepmap/oapi-codegen/v2 v2.1.0
github.com/google/uuid v1.3.0 github.com/gin-gonic/gin v1.9.1
github.com/jinzhu/copier v0.3.5 github.com/go-resty/resty/v2 v2.12.0
github.com/mitchellh/go-homedir v1.1.0 github.com/golangci/golangci-lint v1.57.2
github.com/onsi/ginkgo/v2 v2.4.0 github.com/google/uuid v1.6.0
github.com/onsi/gomega v1.24.0 github.com/goreleaser/goreleaser v1.24.0
github.com/jinzhu/copier v0.4.0
github.com/oapi-codegen/runtime v1.1.1
github.com/onsi/ginkgo/v2 v2.17.1
github.com/onsi/gomega v1.32.0
github.com/prometheus/client_golang v1.19.0
github.com/robfig/cron/v3 v3.0.1 github.com/robfig/cron/v3 v3.0.1
github.com/spf13/cobra v1.6.1 github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.14.0 go.uber.org/mock v0.4.0
go.uber.org/zap v1.23.0 go.uber.org/zap v1.27.0
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc
golang.org/x/mod v0.16.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/apimachinery v0.29.3
k8s.io/code-generator v0.29.3
) )
require ( require (
github.com/fsnotify/fsnotify v1.6.0 // indirect 4d63.com/gocheckcompilerdirectives v1.2.1 // indirect
4d63.com/gochecknoglobals v0.2.1 // indirect
cloud.google.com/go v0.110.10 // indirect
cloud.google.com/go/compute v1.23.3 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.5 // indirect
cloud.google.com/go/kms v1.15.5 // indirect
cloud.google.com/go/storage v1.35.1 // indirect
code.gitea.io/sdk/gitea v0.17.1 // indirect
dario.cat/mergo v1.0.0 // indirect
github.com/4meepo/tagalign v1.3.3 // indirect
github.com/Abirdcfly/dupword v0.0.14 // indirect
github.com/AlekSi/pointer v1.2.0 // indirect
github.com/Antonboom/errname v0.1.12 // indirect
github.com/Antonboom/nilnil v0.1.7 // indirect
github.com/Antonboom/testifylint v1.2.0 // indirect
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/keyvault/azkeys v0.10.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/keyvault/internal v0.7.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.2.0 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.29 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.23 // indirect
github.com/Azure/go-autorest/autorest/azure/auth v0.5.12 // indirect
github.com/Azure/go-autorest/autorest/azure/cli v0.4.6 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.0 // indirect
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 // indirect
github.com/GaijinEntertainment/go-exhaustruct/v3 v3.2.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/OpenPeeDeeP/depguard/v2 v2.2.0 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/alecthomas/go-check-sumtype v0.1.4 // indirect
github.com/alessio/shellescape v1.4.1 // indirect
github.com/alexkohler/nakedret/v2 v2.0.4 // indirect
github.com/alexkohler/prealloc v1.0.0 // indirect
github.com/alingse/asasalint v0.0.11 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/ashanbrown/forbidigo v1.6.0 // indirect
github.com/ashanbrown/makezero v1.1.1 // indirect
github.com/atc0005/go-teams-notify/v2 v2.9.0 // indirect
github.com/aws/aws-sdk-go v1.50.10 // indirect
github.com/aws/aws-sdk-go-v2 v1.24.0 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.4 // indirect
github.com/aws/aws-sdk-go-v2/config v1.26.1 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.16.12 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.10 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.15.7 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.9 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.9 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.9 // indirect
github.com/aws/aws-sdk-go-v2/service/ecr v1.20.2 // indirect
github.com/aws/aws-sdk-go-v2/service/ecrpublic v1.18.2 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.4 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.2.9 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.9 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.16.9 // indirect
github.com/aws/aws-sdk-go-v2/service/kms v1.27.5 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.47.5 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.18.5 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.5 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.26.5 // indirect
github.com/aws/smithy-go v1.19.0 // indirect
github.com/awslabs/amazon-ecr-credential-helper/ecr-login v0.0.0-20231024185945-8841054dbdb8 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bkielbasa/cyclop v1.2.1 // indirect
github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb // indirect
github.com/blizzy78/varnamelen v0.8.0 // indirect
github.com/bombsimon/wsl/v4 v4.2.1 // indirect
github.com/breml/bidichk v0.2.7 // indirect
github.com/breml/errchkjson v0.3.6 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/butuzov/ireturn v0.3.0 // indirect
github.com/butuzov/mirror v1.1.0 // indirect
github.com/bytedance/sonic v1.10.2 // indirect
github.com/caarlos0/ctrlc v1.2.0 // indirect
github.com/caarlos0/env/v9 v9.0.0 // indirect
github.com/caarlos0/go-reddit/v3 v3.0.1 // indirect
github.com/caarlos0/go-shellwords v1.0.12 // indirect
github.com/caarlos0/go-version v0.1.1 // indirect
github.com/caarlos0/log v0.4.4 // indirect
github.com/catenacyber/perfsprint v0.7.1 // indirect
github.com/cavaliergopher/cpio v1.0.1 // indirect
github.com/ccojocar/zxcvbn-go v1.0.2 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/charithe/durationcheck v0.0.10 // indirect
github.com/charmbracelet/lipgloss v0.9.1 // indirect
github.com/charmbracelet/x/exp/ordered v0.0.0-20231010190216-1cb11efc897d // indirect
github.com/chavacava/garif v0.1.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/chrismellard/docker-credential-acr-env v0.0.0-20230304212654-82a0ddb27589 // indirect
github.com/ckaznocha/intrange v0.1.1 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.14.3 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/curioswitch/go-reassign v0.2.0 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/daixiang0/gci v0.12.3 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/davidmz/go-pageant v1.0.2 // indirect
github.com/denis-tingaikin/go-header v0.5.0 // indirect
github.com/dghubble/go-twitter v0.0.0-20211115160449-93a8679adecb // indirect
github.com/dghubble/oauth1 v0.7.2 // indirect
github.com/dghubble/sling v1.4.0 // indirect
github.com/dimchansky/utfbom v1.1.1 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/cli v24.0.7+incompatible // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker v24.0.9+incompatible // indirect
github.com/docker/docker-credential-helpers v0.8.0 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/elliotchance/orderedmap/v2 v2.2.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/ettle/strcase v0.2.0 // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/firefart/nonamedreturns v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fzipp/gocyclo v0.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/getkin/kin-openapi v0.122.0 // indirect
github.com/ghostiam/protogetter v0.3.5 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect github.com/go-critic/go-critic v0.11.2 // indirect
github.com/go-playground/locales v0.14.0 // indirect github.com/go-fed/httpsig v1.1.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-playground/validator/v10 v10.10.0 // indirect github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/goccy/go-json v0.9.7 // indirect github.com/go-git/go-git/v5 v5.11.0 // indirect
github.com/google/go-cmp v0.5.9 // indirect github.com/go-logr/logr v1.4.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect github.com/go-openapi/analysis v0.21.4 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect github.com/go-openapi/errors v0.20.4 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/loads v0.21.2 // indirect
github.com/go-openapi/runtime v0.26.0 // indirect
github.com/go-openapi/spec v0.20.9 // indirect
github.com/go-openapi/strfmt v0.21.7 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-openapi/validate v0.22.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.16.0 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible // indirect
github.com/go-toolsmith/astcast v1.1.0 // indirect
github.com/go-toolsmith/astcopy v1.1.0 // indirect
github.com/go-toolsmith/astequal v1.2.0 // indirect
github.com/go-toolsmith/astfmt v1.1.0 // indirect
github.com/go-toolsmith/astp v1.1.0 // indirect
github.com/go-toolsmith/strparse v1.1.0 // indirect
github.com/go-toolsmith/typep v1.1.0 // indirect
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
github.com/go-xmlfmt/xmlfmt v1.1.2 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang-jwt/jwt/v5 v5.1.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a // indirect
github.com/golangci/gofmt v0.0.0-20231018234816-f50ced29576e // indirect
github.com/golangci/misspell v0.4.1 // indirect
github.com/golangci/plugin-module-register v0.1.1 // indirect
github.com/golangci/revgrep v0.5.2 // indirect
github.com/golangci/unconvert v0.0.0-20240309020433-c5143eacb3ed // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-containerregistry v0.19.0 // indirect
github.com/google/go-github/v57 v57.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/ko v0.15.1 // indirect
github.com/google/pprof v0.0.0-20231023181126-ff6d637d2a7b // indirect
github.com/google/rpmpack v0.5.0 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 // indirect
github.com/google/wire v0.5.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/gordonklaus/ineffassign v0.1.0 // indirect
github.com/goreleaser/chglog v0.5.0 // indirect
github.com/goreleaser/fileglob v1.3.0 // indirect
github.com/goreleaser/nfpm/v2 v2.35.3 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/gostaticanalysis/analysisutil v0.7.1 // indirect
github.com/gostaticanalysis/comment v1.4.2 // indirect
github.com/gostaticanalysis/forcetypeassert v0.1.0 // indirect
github.com/gostaticanalysis/nilerr v0.1.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.4 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.1-vault-5 // indirect
github.com/hexops/gotextdiff v1.0.3 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/invopop/jsonschema v0.12.0 // indirect
github.com/invopop/yaml v0.2.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jgautheron/goconst v1.7.1 // indirect
github.com/jingyugao/rowserrcheck v1.1.1 // indirect
github.com/jirfag/go-printf-func-name v0.0.0-20200119135958-7558a9eaa5af // indirect
github.com/jjti/go-spancheck v0.5.3 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect github.com/json-iterator/go v1.1.12 // indirect
github.com/leodido/go-urn v1.2.1 // indirect github.com/julz/importas v0.1.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect github.com/karamaru-alpha/copyloopvar v1.0.10 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/kisielk/errcheck v1.7.0 // indirect
github.com/kkHAIKE/contextcheck v1.1.5 // indirect
github.com/klauspost/compress v1.17.5 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/klauspost/pgzip v1.2.6 // indirect
github.com/kulti/thelper v0.6.3 // indirect
github.com/kunwardeep/paralleltest v1.0.10 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/kyoh86/exportloopref v0.1.11 // indirect
github.com/ldez/gomoddirectives v0.2.4 // indirect
github.com/ldez/tagliatelle v0.5.0 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/leonklingele/grouper v1.1.1 // indirect
github.com/letsencrypt/boulder v0.0.0-20231026200631-000cd05d5491 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/lufeee/execinquery v1.2.1 // indirect
github.com/macabu/inamedparam v0.1.3 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/maratori/testableexamples v1.0.0 // indirect
github.com/maratori/testpackage v1.1.1 // indirect
github.com/matoous/godox v0.0.0-20230222163458-006bad1f9d26 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-mastodon v0.0.6 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mgechev/revive v1.3.7 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/moricho/tparallel v0.3.1 // indirect
github.com/muesli/mango v0.1.0 // indirect
github.com/muesli/mango-cobra v1.2.0 // indirect
github.com/muesli/mango-pflag v0.1.0 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/roff v0.1.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/nakabonne/nestif v0.3.1 // indirect
github.com/nishanths/exhaustive v0.12.0 // indirect
github.com/nishanths/predeclared v0.2.2 // indirect
github.com/nunnatsa/ginkgolinter v0.16.2 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect github.com/pelletier/go-toml/v2 v2.2.0 // indirect
github.com/spf13/afero v1.9.2 // indirect github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/spf13/cast v1.5.0 // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/polyfloyd/go-errorlint v1.4.8 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/quasilyte/go-ruleguard v0.4.2 // indirect
github.com/quasilyte/gogrep v0.5.0 // indirect
github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727 // indirect
github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 // indirect
github.com/rivo/uniseg v0.4.2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/ryancurrah/gomodguard v1.3.1 // indirect
github.com/ryanrolds/sqlclosecheck v0.5.1 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sanposhiho/wastedassign/v2 v2.0.7 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect
github.com/sashamelentyev/interfacebloat v1.1.0 // indirect
github.com/sashamelentyev/usestdlibvars v1.25.0 // indirect
github.com/secure-systems-lab/go-securesystemslib v0.7.0 // indirect
github.com/securego/gosec/v2 v2.19.0 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/sigstore/cosign/v2 v2.2.1 // indirect
github.com/sigstore/rekor v1.3.3 // indirect
github.com/sigstore/sigstore v1.7.5 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sivchari/containedctx v1.0.3 // indirect
github.com/sivchari/tenv v1.7.1 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/slack-go/slack v0.12.3 // indirect
github.com/sonatard/noctx v0.0.2 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/sourcegraph/go-diff v0.7.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.1 // indirect github.com/spf13/viper v1.17.0 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect github.com/ssgreg/nlreturn/v2 v2.2.1 // indirect
go.uber.org/atomic v1.9.0 // indirect github.com/stbenjam/no-sprintf-host-port v0.1.1 // indirect
go.uber.org/multierr v1.8.0 // indirect github.com/stretchr/objx v0.5.2 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect github.com/stretchr/testify v1.9.0 // indirect
golang.org/x/net v0.1.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect
golang.org/x/sys v0.1.0 // indirect github.com/t-yuki/gocover-cobertura v0.0.0-20180217150009-aaee18c8195c // indirect
golang.org/x/text v0.4.0 // indirect github.com/tdakkota/asciicheck v0.2.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect github.com/technoweenie/multipartstreamer v1.0.1 // indirect
github.com/tetafro/godot v1.4.16 // indirect
github.com/timakin/bodyclose v0.0.0-20230421092635-574207250966 // indirect
github.com/timonwong/loggercheck v0.9.4 // indirect
github.com/titanous/rocacheck v0.0.0-20171023193734-afe73141d399 // indirect
github.com/tomarrell/wrapcheck/v2 v2.8.3 // indirect
github.com/tommy-muehle/go-mnd/v2 v2.5.1 // indirect
github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/ultraware/funlen v0.1.0 // indirect
github.com/ultraware/whitespace v0.1.0 // indirect
github.com/uudashr/gocognit v1.1.2 // indirect
github.com/vbatts/tar-split v0.11.5 // indirect
github.com/withfig/autocomplete-tools/integrations/cobra v1.2.1 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/xanzy/go-gitlab v0.97.0 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xen0n/gosmopolitan v1.2.2 // indirect
github.com/yagipy/maintidx v1.0.0 // indirect
github.com/yeya24/promlinter v0.2.0 // indirect
github.com/ykadowak/zerologlint v0.1.5 // indirect
gitlab.com/bosi/decorder v0.4.1 // indirect
gitlab.com/digitalxero/go-conventional-commit v1.0.7 // indirect
go-simpler.org/musttag v0.9.0 // indirect
go-simpler.org/sloglint v0.5.0 // indirect
go.mongodb.org/mongo-driver v1.12.1 // indirect
go.opencensus.io v0.24.0 // indirect
go.uber.org/automaxprocs v1.5.3 // indirect
go.uber.org/multierr v1.11.0 // indirect
gocloud.dev v0.36.0 // indirect
golang.org/x/arch v0.7.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp/typeparams v0.0.0-20240314144324-c7f7c6466f7f // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.19.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/api v0.152.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/go-jose/go-jose.v2 v2.6.3 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/mail.v2 v2.3.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect honnef.co/go/tools v0.4.7 // indirect
k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
mvdan.cc/gofumpt v0.6.0 // indirect
mvdan.cc/unparam v0.0.0-20240104100049-c549a3470d14 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kind v0.20.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
) )

1422
go.sum

File diff suppressed because it is too large Load Diff

63
openapi/main.go Normal file
View File

@@ -0,0 +1,63 @@
package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
"gopkg.in/yaml.v3"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
func main() {
version := "master"
fileName := "schema-master.yaml"
if len(os.Args) > 1 {
version = os.Args[1]
fileName = "schema.yaml"
}
log.Printf("Patching schema version %s\n", version)
resp, err := http.Get(fmt.Sprintf("https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/%s/openapi/openapi.yaml", version))
if err != nil {
log.Fatalln(err)
}
defer func() { _ = resp.Body.Close() }()
data, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
}
schema := make(map[string]interface{})
err = yaml.Unmarshal(data, &schema)
if err != nil {
log.Fatalln(err)
}
if requestBodies, ok, _ := unstructured.NestedMap(schema, "components", "requestBodies"); ok {
for k := range requestBodies {
_ = unstructured.SetNestedField(schema, k+"Body", "components", "requestBodies", k, "x-go-name")
}
}
if dnsInfo, ok, _ := unstructured.NestedMap(schema,
"paths", "/dns_info", "get", "responses", "200", "content", "application/json", "schema"); ok {
if allOf, ok, _ := unstructured.NestedSlice(dnsInfo, "allOf"); ok && len(allOf) == 2 {
delete(dnsInfo, "allOf")
if err := unstructured.SetNestedMap(schema, allOf[0].(map[string]interface{}),
"paths", "/dns_info", "get", "responses", "200", "content", "application/json", "schema"); err != nil {
log.Fatalln(err)
}
}
}
b, err := yaml.Marshal(&schema)
if err != nil {
log.Fatalln(err)
}
log.Printf("Writing schema file tmp/%s", fileName)
err = os.WriteFile("tmp/"+fileName, b, 0o600)
if err != nil {
log.Fatalln(err)
}
}

View File

@@ -0,0 +1,101 @@
package client
import (
"encoding/json"
"net/http"
"github.com/go-resty/resty/v2"
"go.uber.org/zap"
)
func (cl *client) doGet(req *resty.Request, url string) error {
rl := cl.log.With("method", "GET", "path", url)
if cl.client.UserInfo != nil {
rl = rl.With("username", cl.client.UserInfo.Username)
}
req.ForceContentType("application/json")
rl.Debug("do get")
resp, err := req.Get(url)
if err != nil {
if resp != nil && resp.StatusCode() == http.StatusFound {
loc := resp.Header().Get("Location")
if loc == "/install.html" || loc == "/control/install.html" {
return ErrSetupNeeded
}
}
rl.With("status", resp.StatusCode(), "body", string(resp.Body()), "error", err).Debug("error in do get")
return detailedError(resp, err)
}
checkAuthenticationIssue(resp, rl)
rl.With(
"status", resp.StatusCode(),
"body", string(resp.Body()),
"content-type", resp.Header()["Content-Type"],
).Debug("got response")
if resp.StatusCode() != http.StatusOK {
return detailedError(resp, nil)
}
return nil
}
func (cl *client) doPost(req *resty.Request, url string) error {
rl := cl.log.With("method", "POST", "path", url)
if cl.client.UserInfo != nil {
rl = rl.With("username", cl.client.UserInfo.Username)
}
b, _ := json.Marshal(req.Body)
rl.With("body", string(b)).Debug("do post")
resp, err := req.Post(url)
if err != nil {
rl.With("status", resp.StatusCode(), "body", string(resp.Body()), "error", err).Debug("error in do post")
return detailedError(resp, err)
}
checkAuthenticationIssue(resp, rl)
rl.With(
"status", resp.StatusCode(),
"body", string(resp.Body()),
"content-type", contentType(resp),
).Debug("got response")
if resp.StatusCode() != http.StatusOK {
return detailedError(resp, nil)
}
return nil
}
func (cl *client) doPut(req *resty.Request, url string) error {
rl := cl.log.With("method", "PUT", "path", url)
if cl.client.UserInfo != nil {
rl = rl.With("username", cl.client.UserInfo.Username)
}
b, _ := json.Marshal(req.Body)
rl.With("body", string(b)).Debug("do put")
resp, err := req.Put(url)
if err != nil {
rl.With("status", resp.StatusCode(), "body", string(resp.Body()), "error", err).Debug("error in do put")
return detailedError(resp, err)
}
checkAuthenticationIssue(resp, rl)
rl.With(
"status", resp.StatusCode(),
"body", string(resp.Body()),
"content-type", contentType(resp),
).Debug("got response")
if resp.StatusCode() != http.StatusOK {
return detailedError(resp, nil)
}
return nil
}
func checkAuthenticationIssue(resp *resty.Response, rl *zap.SugaredLogger) {
if resp != nil && (resp.StatusCode() == http.StatusUnauthorized || resp.StatusCode() == http.StatusForbidden) {
rl.With("status", resp.StatusCode()).Error("there seems to be an authentication issue - " +
"please check https://github.com/bakito/adguardhome-sync/wiki/FAQ")
}
}

View File

@@ -9,9 +9,12 @@ import (
"os" "os"
"path" "path"
"strconv" "strconv"
"strings"
"github.com/bakito/adguardhome-sync/pkg/client/model"
"github.com/bakito/adguardhome-sync/pkg/log" "github.com/bakito/adguardhome-sync/pkg/log"
"github.com/bakito/adguardhome-sync/pkg/types" "github.com/bakito/adguardhome-sync/pkg/types"
"github.com/bakito/adguardhome-sync/pkg/utils"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
"go.uber.org/zap" "go.uber.org/zap"
) )
@@ -50,12 +53,16 @@ func New(config types.AdGuardInstance) (Client, error) {
u.Path = path.Clean(u.Path) u.Path = path.Clean(u.Path)
cl := resty.New().SetBaseURL(u.String()).SetDisableWarn(true) cl := resty.New().SetBaseURL(u.String()).SetDisableWarn(true)
if config.InsecureSkipVerify { // #nosec G402 has to be explicitly enabled
// #nosec G402 has to be explicitly enabled cl.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: config.InsecureSkipVerify})
cl.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
}
if config.Username != "" && config.Password != "" { cookieParts := strings.Split(config.Cookie, "=")
if len(cookieParts) == 2 {
cl.SetCookie(&http.Cookie{
Name: cookieParts[0],
Value: cookieParts[1],
})
} else if config.Username != "" && config.Password != "" {
cl = cl.SetBasicAuth(config.Username, config.Password) cl = cl.SetBasicAuth(config.Username, config.Password)
} }
@@ -71,52 +78,56 @@ func New(config types.AdGuardInstance) (Client, error) {
} }
return &client{ return &client{
host: u.Host, host: config.Host,
client: cl, client: cl,
log: l.With("host", u.Host), log: l.With("host", config.Host),
}, nil }, nil
} }
// Client AdguardHome API client interface // Client AdguardHome API client interface
type Client interface { type Client interface {
Host() string Host() string
Status() (*types.Status, error) Status() (*model.ServerStatus, error)
Stats() (*model.Stats, error)
QueryLog(limit int) (*model.QueryLog, error)
ToggleProtection(enable bool) error ToggleProtection(enable bool) error
RewriteList() (*types.RewriteEntries, error) RewriteList() (*model.RewriteEntries, error)
AddRewriteEntries(e ...types.RewriteEntry) error AddRewriteEntries(e ...model.RewriteEntry) error
DeleteRewriteEntries(e ...types.RewriteEntry) error DeleteRewriteEntries(e ...model.RewriteEntry) error
Filtering() (*types.FilteringStatus, error) Filtering() (*model.FilterStatus, error)
ToggleFiltering(enabled bool, interval float64) error ToggleFiltering(enabled bool, interval int) error
AddFilters(whitelist bool, e ...types.Filter) error AddFilter(whitelist bool, f model.Filter) error
DeleteFilters(whitelist bool, e ...types.Filter) error DeleteFilter(whitelist bool, f model.Filter) error
UpdateFilters(whitelist bool, e ...types.Filter) error UpdateFilter(whitelist bool, f model.Filter) error
RefreshFilters(whitelist bool) error RefreshFilters(whitelist bool) error
SetCustomRules(rules types.UserRules) error SetCustomRules(rules *[]string) error
SafeBrowsing() (bool, error) SafeBrowsing() (bool, error)
ToggleSafeBrowsing(enable bool) error ToggleSafeBrowsing(enable bool) error
Parental() (bool, error) Parental() (bool, error)
ToggleParental(enable bool) error ToggleParental(enable bool) error
SafeSearch() (bool, error) SafeSearchConfig() (*model.SafeSearchConfig, error)
ToggleSafeSearch(enable bool) error SetSafeSearchConfig(settings *model.SafeSearchConfig) error
Services() (types.Services, error) ProfileInfo() (*model.ProfileInfo, error)
SetServices(services types.Services) error SetProfileInfo(settings *model.ProfileInfo) error
Clients() (*types.Clients, error) BlockedServicesSchedule() (*model.BlockedServicesSchedule, error)
AddClients(client ...types.Client) error SetBlockedServicesSchedule(schedule *model.BlockedServicesSchedule) error
UpdateClients(client ...types.Client) error Clients() (*model.Clients, error)
DeleteClients(client ...types.Client) error AddClient(client *model.Client) error
QueryLogConfig() (*types.QueryLogConfig, error) UpdateClient(client *model.Client) error
SetQueryLogConfig(enabled bool, interval float64, anonymizeClientIP bool) error DeleteClient(client *model.Client) error
StatsConfig() (*types.IntervalConfig, error) QueryLogConfig() (*model.QueryLogConfigWithIgnored, error)
SetStatsConfig(interval float64) error SetQueryLogConfig(*model.QueryLogConfigWithIgnored) error
StatsConfig() (*model.GetStatsConfigResponse, error)
SetStatsConfig(sc *model.PutStatsConfigUpdateRequest) error
Setup() error Setup() error
AccessList() (*types.AccessList, error) AccessList() (*model.AccessList, error)
SetAccessList(*types.AccessList) error SetAccessList(*model.AccessList) error
DNSConfig() (*types.DNSConfig, error) DNSConfig() (*model.DNSConfig, error)
SetDNSConfig(*types.DNSConfig) error SetDNSConfig(*model.DNSConfig) error
DHCPServerConfig() (*types.DHCPServerConfig, error) DhcpConfig() (*model.DhcpStatus, error)
SetDHCPServerConfig(*types.DHCPServerConfig) error SetDhcpConfig(*model.DhcpStatus) error
AddDHCPStaticLeases(leases ...types.Lease) error AddDHCPStaticLease(lease model.DhcpStaticLease) error
DeleteDHCPStaticLeases(leases ...types.Lease) error DeleteDHCPStaticLease(lease model.DhcpStaticLease) error
} }
type client struct { type client struct {
@@ -130,57 +141,6 @@ func (cl *client) Host() string {
return cl.host return cl.host
} }
func (cl *client) doGet(req *resty.Request, url string) error {
rl := cl.log.With("method", "GET", "path", url)
if cl.client.UserInfo != nil {
rl = rl.With("username", cl.client.UserInfo.Username)
}
req.ForceContentType("application/json")
rl.Debug("do get")
resp, err := req.Get(url)
if err != nil {
if resp != nil && resp.StatusCode() == http.StatusFound {
loc := resp.Header().Get("Location")
if loc == "/install.html" {
return ErrSetupNeeded
}
}
rl.With("status", resp.StatusCode(), "body", string(resp.Body()), "error", err).Debug("error in do get")
return detailedError(resp, err)
}
rl.With(
"status", resp.StatusCode(),
"body", string(resp.Body()),
"content-type", resp.Header()["Content-Type"],
).Debug("got response")
if resp.StatusCode() != http.StatusOK {
return detailedError(resp, nil)
}
return nil
}
func (cl *client) doPost(req *resty.Request, url string) error {
rl := cl.log.With("method", "POST", "path", url)
if cl.client.UserInfo != nil {
rl = rl.With("username", cl.client.UserInfo.Username)
}
rl.Debug("do post")
resp, err := req.Post(url)
if err != nil {
rl.With("status", resp.StatusCode(), "body", string(resp.Body()), "error", err).Debug("error in do post")
return detailedError(resp, err)
}
rl.With(
"status", resp.StatusCode(),
"body", string(resp.Body()),
"content-type", contentType(resp),
).Debug("got response")
if resp.StatusCode() != http.StatusOK {
return detailedError(resp, nil)
}
return nil
}
func contentType(resp *resty.Response) string { func contentType(resp *resty.Response) string {
if ct, ok := resp.Header()["Content-Type"]; ok { if ct, ok := resp.Header()["Content-Type"]; ok {
if len(ct) != 1 { if len(ct) != 1 {
@@ -191,23 +151,34 @@ func contentType(resp *resty.Response) string {
return "" return ""
} }
func (cl *client) Status() (*types.Status, error) { func (cl *client) Status() (*model.ServerStatus, error) {
status := &types.Status{} status := &model.ServerStatus{}
err := cl.doGet(cl.client.R().EnableTrace().SetResult(status), "status") err := cl.doGet(cl.client.R().EnableTrace().SetResult(status), "status")
cl.version = status.Version cl.version = status.Version
return status, err return status, err
} }
func (cl *client) RewriteList() (*types.RewriteEntries, error) { func (cl *client) Stats() (*model.Stats, error) {
rewrites := &types.RewriteEntries{} stats := &model.Stats{}
err := cl.doGet(cl.client.R().EnableTrace().SetResult(stats), "stats")
return stats, err
}
func (cl *client) QueryLog(limit int) (*model.QueryLog, error) {
ql := &model.QueryLog{}
err := cl.doGet(cl.client.R().EnableTrace().SetResult(ql), fmt.Sprintf(`querylog?limit=%d&response_status="all"`, limit))
return ql, err
}
func (cl *client) RewriteList() (*model.RewriteEntries, error) {
rewrites := &model.RewriteEntries{}
err := cl.doGet(cl.client.R().EnableTrace().SetResult(&rewrites), "/rewrite/list") err := cl.doGet(cl.client.R().EnableTrace().SetResult(&rewrites), "/rewrite/list")
return rewrites, err return rewrites, err
} }
func (cl *client) AddRewriteEntries(entries ...types.RewriteEntry) error { func (cl *client) AddRewriteEntries(entries ...model.RewriteEntry) error {
for i := range entries { for _, e := range entries {
e := entries[i] cl.log.With("domain", e.Domain, "answer", e.Answer).Info("Add DNS rewrite entry")
cl.log.With("domain", e.Domain, "answer", e.Answer).Info("Add rewrite entry")
err := cl.doPost(cl.client.R().EnableTrace().SetBody(&e), "/rewrite/add") err := cl.doPost(cl.client.R().EnableTrace().SetBody(&e), "/rewrite/add")
if err != nil { if err != nil {
return err return err
@@ -216,10 +187,9 @@ func (cl *client) AddRewriteEntries(entries ...types.RewriteEntry) error {
return nil return nil
} }
func (cl *client) DeleteRewriteEntries(entries ...types.RewriteEntry) error { func (cl *client) DeleteRewriteEntries(entries ...model.RewriteEntry) error {
for i := range entries { for _, e := range entries {
e := entries[i] cl.log.With("domain", e.Domain, "answer", e.Answer).Info("Delete DNS rewrite entry")
cl.log.With("domain", e.Domain, "answer", e.Answer).Info("Delete rewrite entry")
err := cl.doPost(cl.client.R().EnableTrace().SetBody(&e), "/rewrite/delete") err := cl.doPost(cl.client.R().EnableTrace().SetBody(&e), "/rewrite/delete")
if err != nil { if err != nil {
return err return err
@@ -244,16 +214,8 @@ func (cl *client) ToggleParental(enable bool) error {
return cl.toggleBool("parental", enable) return cl.toggleBool("parental", enable)
} }
func (cl *client) SafeSearch() (bool, error) {
return cl.toggleStatus("safesearch")
}
func (cl *client) ToggleSafeSearch(enable bool) error {
return cl.toggleBool("safesearch", enable)
}
func (cl *client) toggleStatus(mode string) (bool, error) { func (cl *client) toggleStatus(mode string) (bool, error) {
fs := &types.EnableConfig{} fs := &model.EnableConfig{}
err := cl.doGet(cl.client.R().EnableTrace().SetResult(fs), fmt.Sprintf("/%s/status", mode)) err := cl.doGet(cl.client.R().EnableTrace().SetResult(fs), fmt.Sprintf("/%s/status", mode))
return fs.Enabled, err return fs.Enabled, err
} }
@@ -269,51 +231,36 @@ func (cl *client) toggleBool(mode string, enable bool) error {
return cl.doPost(cl.client.R().EnableTrace(), fmt.Sprintf("/%s/%s", mode, target)) return cl.doPost(cl.client.R().EnableTrace(), fmt.Sprintf("/%s/%s", mode, target))
} }
func (cl *client) Filtering() (*types.FilteringStatus, error) { func (cl *client) Filtering() (*model.FilterStatus, error) {
f := &types.FilteringStatus{} f := &model.FilterStatus{}
err := cl.doGet(cl.client.R().EnableTrace().SetResult(f), "/filtering/status") err := cl.doGet(cl.client.R().EnableTrace().SetResult(f), "/filtering/status")
return f, err return f, err
} }
func (cl *client) AddFilters(whitelist bool, filters ...types.Filter) error { func (cl *client) AddFilter(whitelist bool, f model.Filter) error {
for _, f := range filters { cl.log.With("url", f.Url, "whitelist", whitelist, "enabled", f.Enabled).Info("Add filter")
cl.log.With("url", f.URL, "whitelist", whitelist, "enabled", f.Enabled).Info("Add filter") ff := &model.AddUrlRequest{Name: utils.Ptr(f.Name), Url: utils.Ptr(f.Url), Whitelist: utils.Ptr(whitelist)}
ff := &types.Filter{Name: f.Name, URL: f.URL, Whitelist: whitelist} return cl.doPost(cl.client.R().EnableTrace().SetBody(ff), "/filtering/add_url")
err := cl.doPost(cl.client.R().EnableTrace().SetBody(ff), "/filtering/add_url")
if err != nil {
return err
}
}
return nil
} }
func (cl *client) DeleteFilters(whitelist bool, filters ...types.Filter) error { func (cl *client) DeleteFilter(whitelist bool, f model.Filter) error {
for _, f := range filters { cl.log.With("url", f.Url, "whitelist", whitelist, "enabled", f.Enabled).Info("Delete filter")
cl.log.With("url", f.URL, "whitelist", whitelist, "enabled", f.Enabled).Info("Delete filter") ff := &model.RemoveUrlRequest{Url: utils.Ptr(f.Url), Whitelist: utils.Ptr(whitelist)}
ff := &types.Filter{URL: f.URL, Whitelist: whitelist} return cl.doPost(cl.client.R().EnableTrace().SetBody(ff), "/filtering/remove_url")
err := cl.doPost(cl.client.R().EnableTrace().SetBody(ff), "/filtering/remove_url")
if err != nil {
return err
}
}
return nil
} }
func (cl *client) UpdateFilters(whitelist bool, filters ...types.Filter) error { func (cl *client) UpdateFilter(whitelist bool, f model.Filter) error {
for _, f := range filters { cl.log.With("url", f.Url, "whitelist", whitelist, "enabled", f.Enabled).Info("Update filter")
cl.log.With("url", f.URL, "whitelist", whitelist, "enabled", f.Enabled).Info("Update filter") fu := &model.FilterSetUrl{
fu := &types.FilterUpdate{Whitelist: whitelist, URL: f.URL, Data: types.Filter{ID: f.ID, Name: f.Name, URL: f.URL, Whitelist: whitelist, Enabled: f.Enabled}} Whitelist: utils.Ptr(whitelist), Url: utils.Ptr(f.Url),
err := cl.doPost(cl.client.R().EnableTrace().SetBody(fu), "/filtering/set_url") Data: &model.FilterSetUrlData{Name: f.Name, Url: f.Url, Enabled: f.Enabled},
if err != nil {
return err
}
} }
return nil return cl.doPost(cl.client.R().EnableTrace().SetBody(fu), "/filtering/set_url")
} }
func (cl *client) RefreshFilters(whitelist bool) error { func (cl *client) RefreshFilters(whitelist bool) error {
cl.log.With("whitelist", whitelist).Info("Refresh filter") cl.log.With("whitelist", whitelist).Info("Refresh filter")
return cl.doPost(cl.client.R().EnableTrace().SetBody(&types.RefreshFilter{Whitelist: whitelist}), "/filtering/refresh") return cl.doPost(cl.client.R().EnableTrace().SetBody(&model.FilterRefreshRequest{Whitelist: utils.Ptr(whitelist)}), "/filtering/refresh")
} }
func (cl *client) ToggleProtection(enable bool) error { func (cl *client) ToggleProtection(enable bool) error {
@@ -321,95 +268,75 @@ func (cl *client) ToggleProtection(enable bool) error {
return cl.doPost(cl.client.R().EnableTrace().SetBody(&types.Protection{ProtectionEnabled: enable}), "/dns_config") return cl.doPost(cl.client.R().EnableTrace().SetBody(&types.Protection{ProtectionEnabled: enable}), "/dns_config")
} }
func (cl *client) SetCustomRules(rules types.UserRules) error { func (cl *client) SetCustomRules(rules *[]string) error {
cl.log.With("rules", len(rules)).Info("Set user rules") var l int
return cl.doPost(cl.client.R().EnableTrace().SetBody(rules.ToPayload(cl.version)), "/filtering/set_rules") if rules != nil {
l = len(*rules)
}
cl.log.With("rules", l).Info("Set user rules")
return cl.doPost(cl.client.R().EnableTrace().SetBody(&model.SetRulesRequest{Rules: rules}), "/filtering/set_rules")
} }
func (cl *client) ToggleFiltering(enabled bool, interval float64) error { func (cl *client) ToggleFiltering(enabled bool, interval int) error {
cl.log.With("enabled", enabled, "interval", interval).Info("Toggle filtering") cl.log.With("enabled", enabled, "interval", interval).Info("Toggle filtering")
return cl.doPost(cl.client.R().EnableTrace().SetBody(&types.FilteringConfig{ return cl.doPost(cl.client.R().EnableTrace().SetBody(&model.FilterConfig{
EnableConfig: types.EnableConfig{Enabled: enabled}, Enabled: utils.Ptr(enabled),
IntervalConfig: types.IntervalConfig{Interval: interval}, Interval: utils.Ptr(interval),
}), "/filtering/config") }), "/filtering/config")
} }
func (cl *client) Services() (types.Services, error) { func (cl *client) BlockedServicesSchedule() (*model.BlockedServicesSchedule, error) {
svcs := types.Services{} sched := &model.BlockedServicesSchedule{}
err := cl.doGet(cl.client.R().EnableTrace().SetResult(&svcs), "/blocked_services/list") err := cl.doGet(cl.client.R().EnableTrace().SetResult(sched), "/blocked_services/get")
return svcs, err return sched, err
} }
func (cl *client) SetServices(services types.Services) error { func (cl *client) SetBlockedServicesSchedule(schedule *model.BlockedServicesSchedule) error {
cl.log.With("services", len(services)).Info("Set services") cl.log.With("services", schedule.ServicesString()).Info("Set blocked services schedule")
return cl.doPost(cl.client.R().EnableTrace().SetBody(&services), "/blocked_services/set") return cl.doPut(cl.client.R().EnableTrace().SetBody(schedule), "/blocked_services/update")
} }
func (cl *client) Clients() (*types.Clients, error) { func (cl *client) Clients() (*model.Clients, error) {
clients := &types.Clients{} clients := &model.Clients{}
err := cl.doGet(cl.client.R().EnableTrace().SetResult(clients), "/clients") err := cl.doGet(cl.client.R().EnableTrace().SetResult(clients), "/clients")
return clients, err return clients, err
} }
func (cl *client) AddClients(clients ...types.Client) error { func (cl *client) AddClient(client *model.Client) error {
for i := range clients { cl.log.With("name", *client.Name).Info("Add client settings")
client := clients[i] return cl.doPost(cl.client.R().EnableTrace().SetBody(client), "/clients/add")
cl.log.With("name", client.Name).Info("Add client")
err := cl.doPost(cl.client.R().EnableTrace().SetBody(&client), "/clients/add")
if err != nil {
return err
}
}
return nil
} }
func (cl *client) UpdateClients(clients ...types.Client) error { func (cl *client) UpdateClient(client *model.Client) error {
for _, client := range clients { cl.log.With("name", *client.Name).Info("Update client settings")
cl.log.With("name", client.Name).Info("Update client") return cl.doPost(cl.client.R().EnableTrace().SetBody(&model.ClientUpdate{Name: client.Name, Data: client}), "/clients/update")
err := cl.doPost(cl.client.R().EnableTrace().SetBody(&types.ClientUpdate{Name: client.Name, Data: client}), "/clients/update")
if err != nil {
return err
}
}
return nil
} }
func (cl *client) DeleteClients(clients ...types.Client) error { func (cl *client) DeleteClient(client *model.Client) error {
for i := range clients { cl.log.With("name", *client.Name).Info("Delete client settings")
client := clients[i] return cl.doPost(cl.client.R().EnableTrace().SetBody(client), "/clients/delete")
cl.log.With("name", client.Name).Info("Delete client")
err := cl.doPost(cl.client.R().EnableTrace().SetBody(&client), "/clients/delete")
if err != nil {
return err
}
}
return nil
} }
func (cl *client) QueryLogConfig() (*types.QueryLogConfig, error) { func (cl *client) QueryLogConfig() (*model.QueryLogConfigWithIgnored, error) {
qlc := &types.QueryLogConfig{} qlc := &model.QueryLogConfigWithIgnored{}
err := cl.doGet(cl.client.R().EnableTrace().SetResult(qlc), "/querylog_info") err := cl.doGet(cl.client.R().EnableTrace().SetResult(qlc), "/querylog/config")
return qlc, err return qlc, err
} }
func (cl *client) SetQueryLogConfig(enabled bool, interval float64, anonymizeClientIP bool) error { func (cl *client) SetQueryLogConfig(qlc *model.QueryLogConfigWithIgnored) error {
cl.log.With("enabled", enabled, "interval", interval, "anonymizeClientIP", anonymizeClientIP).Info("Set query log config") cl.log.With("enabled", *qlc.Enabled, "interval", *qlc.Interval, "anonymizeClientIP", *qlc.AnonymizeClientIp).Info("Set query log config")
return cl.doPost(cl.client.R().EnableTrace().SetBody(&types.QueryLogConfig{ return cl.doPut(cl.client.R().EnableTrace().SetBody(qlc), "/querylog/config/update")
EnableConfig: types.EnableConfig{Enabled: enabled},
IntervalConfig: types.IntervalConfig{Interval: interval},
AnonymizeClientIP: anonymizeClientIP,
}), "/querylog_config")
} }
func (cl *client) StatsConfig() (*types.IntervalConfig, error) { func (cl *client) StatsConfig() (*model.GetStatsConfigResponse, error) {
stats := &types.IntervalConfig{} stats := &model.GetStatsConfigResponse{}
err := cl.doGet(cl.client.R().EnableTrace().SetResult(stats), "/stats_info") err := cl.doGet(cl.client.R().EnableTrace().SetResult(stats), "/stats/config")
return stats, err return stats, err
} }
func (cl *client) SetStatsConfig(interval float64) error { func (cl *client) SetStatsConfig(sc *model.PutStatsConfigUpdateRequest) error {
cl.log.With("interval", interval).Info("Set stats config") cl.log.With("interval", sc.Interval).Info("Set stats config")
return cl.doPost(cl.client.R().EnableTrace().SetBody(&types.IntervalConfig{Interval: interval}), "/stats_config") return cl.doPut(cl.client.R().EnableTrace().SetBody(sc), "/stats/config/update")
} }
func (cl *client) Setup() error { func (cl *client) Setup() error {
@@ -438,57 +365,75 @@ func (cl *client) Setup() error {
return cl.doPost(req, "/install/configure") return cl.doPost(req, "/install/configure")
} }
func (cl *client) AccessList() (*types.AccessList, error) { func (cl *client) AccessList() (*model.AccessList, error) {
al := &types.AccessList{} al := &model.AccessList{}
err := cl.doGet(cl.client.R().EnableTrace().SetResult(al), "/access/list") err := cl.doGet(cl.client.R().EnableTrace().SetResult(al), "/access/list")
return al, err return al, err
} }
func (cl *client) SetAccessList(list *types.AccessList) error { func (cl *client) SetAccessList(list *model.AccessList) error {
cl.log.Info("Set access list") cl.log.Info("Set access list")
return cl.doPost(cl.client.R().EnableTrace().SetBody(list), "/access/set") return cl.doPost(cl.client.R().EnableTrace().SetBody(list), "/access/set")
} }
func (cl *client) DNSConfig() (*types.DNSConfig, error) { func (cl *client) DNSConfig() (*model.DNSConfig, error) {
cfg := &types.DNSConfig{} cfg := &model.DNSConfig{}
err := cl.doGet(cl.client.R().EnableTrace().SetResult(cfg), "/dns_info") err := cl.doGet(cl.client.R().EnableTrace().SetResult(cfg), "/dns_info")
return cfg, err return cfg, err
} }
func (cl *client) SetDNSConfig(config *types.DNSConfig) error { func (cl *client) SetDNSConfig(config *model.DNSConfig) error {
cl.log.Info("Set dns config list") cl.log.Info("Set dns config list")
return cl.doPost(cl.client.R().EnableTrace().SetBody(config), "/dns_config") return cl.doPost(cl.client.R().EnableTrace().SetBody(config), "/dns_config")
} }
func (cl *client) DHCPServerConfig() (*types.DHCPServerConfig, error) { func (cl *client) DhcpConfig() (*model.DhcpStatus, error) {
cfg := &types.DHCPServerConfig{} cfg := &model.DhcpStatus{}
err := cl.doGet(cl.client.R().EnableTrace().SetResult(cfg), "/dhcp/status") err := cl.doGet(cl.client.R().EnableTrace().SetResult(cfg), "/dhcp/status")
return cfg, err return cfg, err
} }
func (cl *client) SetDHCPServerConfig(config *types.DHCPServerConfig) error { func (cl *client) SetDhcpConfig(config *model.DhcpStatus) error {
cl.log.Info("Set dhcp server config") cl.log.Info("Set dhcp server config")
return cl.doPost(cl.client.R().EnableTrace().SetBody(config), "/dhcp/set_config") return cl.doPost(cl.client.R().EnableTrace().SetBody(config), "/dhcp/set_config")
} }
func (cl *client) AddDHCPStaticLeases(leases ...types.Lease) error { func (cl *client) AddDHCPStaticLease(l model.DhcpStaticLease) error {
for _, l := range leases { cl.log.With("mac", l.Mac, "ip", l.Ip, "hostname", l.Hostname).Info("Add static dhcp lease")
cl.log.With("mac", l.HWAddr, "ip", l.IP, "hostname", l.Hostname).Info("Add static dhcp lease") err := cl.doPost(cl.client.R().EnableTrace().SetBody(l), "/dhcp/add_static_lease")
err := cl.doPost(cl.client.R().EnableTrace().SetBody(l), "/dhcp/add_static_lease") if err != nil {
if err != nil { return err
return err
}
} }
return nil return nil
} }
func (cl *client) DeleteDHCPStaticLeases(leases ...types.Lease) error { func (cl *client) DeleteDHCPStaticLease(l model.DhcpStaticLease) error {
for _, l := range leases { cl.log.With("mac", l.Mac, "ip", l.Ip, "hostname", l.Hostname).Info("Delete static dhcp lease")
cl.log.With("mac", l.HWAddr, "ip", l.IP, "hostname", l.Hostname).Info("Delete static dhcp lease") err := cl.doPost(cl.client.R().EnableTrace().SetBody(l), "/dhcp/remove_static_lease")
err := cl.doPost(cl.client.R().EnableTrace().SetBody(l), "/dhcp/remove_static_lease") if err != nil {
if err != nil { return err
return err
}
} }
return nil return nil
} }
func (cl *client) SafeSearchConfig() (*model.SafeSearchConfig, error) {
sss := &model.SafeSearchConfig{}
err := cl.doGet(cl.client.R().EnableTrace().SetResult(sss), "/safesearch/status")
return sss, err
}
func (cl *client) SetSafeSearchConfig(settings *model.SafeSearchConfig) error {
cl.log.With("enabled", *settings.Enabled).Info("Set safesearch settings")
return cl.doPut(cl.client.R().EnableTrace().SetBody(settings), "/safesearch/settings")
}
func (cl *client) ProfileInfo() (*model.ProfileInfo, error) {
p := &model.ProfileInfo{}
err := cl.doGet(cl.client.R().EnableTrace().SetResult(p), "/profile")
return p, err
}
func (cl *client) SetProfileInfo(profile *model.ProfileInfo) error {
cl.log.With("language", profile.Language, "theme", profile.Theme).Info("Set profile")
return cl.doPut(cl.client.R().EnableTrace().SetBody(profile), "/profile/update")
}

View File

@@ -9,7 +9,9 @@ import (
"path/filepath" "path/filepath"
"github.com/bakito/adguardhome-sync/pkg/client" "github.com/bakito/adguardhome-sync/pkg/client"
"github.com/bakito/adguardhome-sync/pkg/client/model"
"github.com/bakito/adguardhome-sync/pkg/types" "github.com/bakito/adguardhome-sync/pkg/types"
"github.com/bakito/adguardhome-sync/pkg/utils"
"github.com/google/uuid" "github.com/google/uuid"
. "github.com/onsi/ginkgo/v2" . "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
@@ -33,19 +35,22 @@ var _ = Describe("Client", func() {
Context("Host", func() { Context("Host", func() {
It("should read the current host", func() { It("should read the current host", func() {
cl, _ := client.New(types.AdGuardInstance{URL: "https://foo.bar:3000"}) inst := types.AdGuardInstance{URL: "https://foo.bar:3000"}
err := inst.Init()
Ω(err).ShouldNot(HaveOccurred())
cl, _ := client.New(inst)
host := cl.Host() host := cl.Host()
Ω(host).Should(Equal("foo.bar:3000")) Ω(host).Should(Equal("foo.bar:3000"))
}) })
}) })
Context("Filtering", func() { Context("Filter", func() {
It("should read filtering status", func() { It("should read filter status", func() {
ts, cl = ClientGet("filtering-status.json", "/filtering/status") ts, cl = ClientGet("filtering-status.json", "/filtering/status")
fs, err := cl.Filtering() fs, err := cl.Filtering()
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
Ω(fs.Enabled).Should(BeTrue()) Ω(*fs.Enabled).Should(BeTrue())
Ω(fs.Filters).Should(HaveLen(2)) Ω(*fs.Filters).Should(HaveLen(2))
}) })
It("should enable protection", func() { It("should enable protection", func() {
ts, cl = ClientPost("/filtering/config", `{"enabled":true,"interval":123}`) ts, cl = ClientPost("/filtering/config", `{"enabled":true,"interval":123}`)
@@ -64,35 +69,46 @@ var _ = Describe("Client", func() {
}) })
It("should add Filters", func() { It("should add Filters", func() {
ts, cl = ClientPost("/filtering/add_url", ts, cl = ClientPost("/filtering/add_url",
`{"id":0,"enabled":false,"url":"foo","name":"","rules_count":0,"whitelist":true}`, `{"name":"","url":"foo","whitelist":true}`,
`{"id":0,"enabled":false,"url":"bar","name":"","rules_count":0,"whitelist":true}`, `{"name":"","url":"bar","whitelist":true}`,
) )
err := cl.AddFilters(true, types.Filter{URL: "foo"}, types.Filter{URL: "bar"}) err := cl.AddFilter(true, model.Filter{Url: "foo"})
Ω(err).ShouldNot(HaveOccurred())
err = cl.AddFilter(true, model.Filter{Url: "bar"})
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should update Filters", func() { It("should update Filters", func() {
ts, cl = ClientPost("/filtering/set_url", ts, cl = ClientPost("/filtering/set_url",
`{"url":"foo","data":{"id":0,"enabled":false,"url":"foo","name":"","rules_count":0,"whitelist":true},"whitelist":true}`, `{"data":{"enabled":false,"name":"","url":"foo"},"url":"foo","whitelist":true}`,
`{"url":"bar","data":{"id":0,"enabled":false,"url":"bar","name":"","rules_count":0,"whitelist":true},"whitelist":true}`, `{"data":{"enabled":false,"name":"","url":"bar"},"url":"bar","whitelist":true}`,
) )
err := cl.UpdateFilters(true, types.Filter{URL: "foo"}, types.Filter{URL: "bar"}) err := cl.UpdateFilter(true, model.Filter{Url: "foo"})
Ω(err).ShouldNot(HaveOccurred())
err = cl.UpdateFilter(true, model.Filter{Url: "bar"})
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should delete Filters", func() { It("should delete Filters", func() {
ts, cl = ClientPost("/filtering/remove_url", ts, cl = ClientPost("/filtering/remove_url",
`{"id":0,"enabled":false,"url":"foo","name":"","rules_count":0,"whitelist":true}`, `{"url":"foo","whitelist":true}`,
`{"id":0,"enabled":false,"url":"bar","name":"","rules_count":0,"whitelist":true}`, `{"url":"bar","whitelist":true}`,
) )
err := cl.DeleteFilters(true, types.Filter{URL: "foo"}, types.Filter{URL: "bar"}) err := cl.DeleteFilter(true, model.Filter{Url: "foo"})
Ω(err).ShouldNot(HaveOccurred())
err = cl.DeleteFilter(true, model.Filter{Url: "bar"})
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
}) It("should set empty filter rules", func() {
ts, cl = ClientPost("/filtering/set_rules",
Context("CustomRules", func() { `{"rules":[]}`,
It("should set SetCustomRules", func() { )
ts, cl = ClientPost("/filtering/set_rules", `foo err := cl.SetCustomRules(utils.Ptr([]string{}))
bar`) Ω(err).ShouldNot(HaveOccurred())
err := cl.SetCustomRules([]string{"foo", "bar"}) })
It("should set nil filter rules", func() {
ts, cl = ClientPost("/filtering/set_rules",
`{}`,
)
err := cl.SetCustomRules(nil)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
}) })
@@ -102,8 +118,8 @@ bar`)
ts, cl = ClientGet("status.json", "/status") ts, cl = ClientGet("status.json", "/status")
fs, err := cl.Status() fs, err := cl.Status()
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
Ω(fs.DNSAddresses).Should(HaveLen(1)) Ω(fs.DnsAddresses).Should(HaveLen(1))
Ω(fs.DNSAddresses[0]).Should(Equal("192.168.1.2")) Ω(fs.DnsAddresses[0]).Should(Equal("192.168.1.2"))
Ω(fs.Version).Should(Equal("v0.105.2")) Ω(fs.Version).Should(Equal("v0.105.2"))
}) })
It("should return ErrSetupNeeded", func() { It("should return ErrSetupNeeded", func() {
@@ -135,13 +151,19 @@ bar`)
Ω(*rwl).Should(HaveLen(2)) Ω(*rwl).Should(HaveLen(2))
}) })
It("should add RewriteList", func() { It("should add RewriteList", func() {
ts, cl = ClientPost("/rewrite/add", `{"domain":"foo","answer":"foo"}`, `{"domain":"bar","answer":"bar"}`) ts, cl = ClientPost("/rewrite/add", `{"answer":"foo","domain":"foo"}`, `{"answer":"bar","domain":"bar"}`)
err := cl.AddRewriteEntries(types.RewriteEntry{Answer: "foo", Domain: "foo"}, types.RewriteEntry{Answer: "bar", Domain: "bar"}) err := cl.AddRewriteEntries(
model.RewriteEntry{Answer: utils.Ptr("foo"), Domain: utils.Ptr("foo")},
model.RewriteEntry{Answer: utils.Ptr("bar"), Domain: utils.Ptr("bar")},
)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should delete RewriteList", func() { It("should delete RewriteList", func() {
ts, cl = ClientPost("/rewrite/delete", `{"domain":"foo","answer":"foo"}`, `{"domain":"bar","answer":"bar"}`) ts, cl = ClientPost("/rewrite/delete", `{"answer":"foo","domain":"foo"}`, `{"answer":"bar","domain":"bar"}`)
err := cl.DeleteRewriteEntries(types.RewriteEntry{Answer: "foo", Domain: "foo"}, types.RewriteEntry{Answer: "bar", Domain: "bar"}) err := cl.DeleteRewriteEntries(
model.RewriteEntry{Answer: utils.Ptr("foo"), Domain: utils.Ptr("foo")},
model.RewriteEntry{Answer: utils.Ptr("bar"), Domain: utils.Ptr("bar")},
)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
}) })
@@ -165,21 +187,22 @@ bar`)
}) })
}) })
Context("SafeSearch", func() { Context("SafeSearchConfig", func() {
It("should read safesearch status", func() { It("should read safesearch status", func() {
ts, cl = ClientGet("safesearch-status.json", "/safesearch/status") ts, cl = ClientGet("safesearch-status.json", "/safesearch/status")
ss, err := cl.SafeSearch() ss, err := cl.SafeSearchConfig()
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
Ω(ss).Should(BeTrue()) Ω(ss.Enabled).ShouldNot(BeNil())
Ω(*ss.Enabled).Should(BeTrue())
}) })
It("should enable safesearch", func() { It("should enable safesearch", func() {
ts, cl = ClientPost("/safesearch/enable", "") ts, cl = ClientPut("/safesearch/settings", `{"enabled":true}`)
err := cl.ToggleSafeSearch(true) err := cl.SetSafeSearchConfig(&model.SafeSearchConfig{Enabled: utils.Ptr(true)})
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should disable safesearch", func() { It("should disable safesearch", func() {
ts, cl = ClientPost("/safesearch/disable", "") ts, cl = ClientPut("/safesearch/settings", `{"enabled":false}`)
err := cl.ToggleSafeSearch(false) err := cl.SetSafeSearchConfig(&model.SafeSearchConfig{Enabled: utils.Ptr(false)})
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
}) })
@@ -216,16 +239,25 @@ bar`)
}) })
}) })
Context("Services", func() { Context("BlockedServicesSchedule", func() {
It("should read Services", func() { It("should read BlockedServicesSchedule", func() {
ts, cl = ClientGet("blockedservices-list.json", "/blocked_services/list") ts, cl = ClientGet("blockedservicesschedule-get.json", "/blocked_services/get")
s, err := cl.Services() s, err := cl.BlockedServicesSchedule()
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
Ω(s).Should(HaveLen(2)) Ω(*s.Ids).Should(HaveLen(3))
}) })
It("should set Services", func() { It("should set BlockedServicesSchedule", func() {
ts, cl = ClientPost("/blocked_services/set", `["foo","bar"]`) ts, cl = ClientPost("/blocked_services/update",
err := cl.SetServices([]string{"foo", "bar"}) `{"ids":["bar","foo"],"schedule":{"mon":{"end":99,"start":1}}}`)
err := cl.SetBlockedServicesSchedule(&model.BlockedServicesSchedule{
Ids: utils.Ptr([]string{"foo", "bar"}),
Schedule: &model.Schedule{
Mon: &model.DayRange{
Start: utils.Ptr(float32(1.0)),
End: utils.Ptr(float32(99.0)),
},
},
})
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
}) })
@@ -235,55 +267,69 @@ bar`)
ts, cl = ClientGet("clients.json", "/clients") ts, cl = ClientGet("clients.json", "/clients")
c, err := cl.Clients() c, err := cl.Clients()
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
Ω(c.Clients).Should(HaveLen(2)) Ω(*c.Clients).Should(HaveLen(2))
}) })
It("should add Clients", func() { It("should add Clients", func() {
ts, cl = ClientPost("/clients/add", ts, cl = ClientPost("/clients/add",
`{"ids":["id"],"use_global_settings":false,"use_global_blocked_services":false,"name":"foo","filtering_enabled":false,"parental_enabled":false,"safesearch_enabled":false,"safebrowsing_enabled":false,"disallowed":false,"disallowed_rule":""}`, `{"ids":["id"],"name":"foo"}`,
) )
err := cl.AddClients(types.Client{Name: "foo", Ids: []string{"id"}}) err := cl.AddClient(&model.Client{Name: utils.Ptr("foo"), Ids: utils.Ptr([]string{"id"})})
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should update Clients", func() { It("should update Clients", func() {
ts, cl = ClientPost("/clients/update", ts, cl = ClientPost("/clients/update",
`{"name":"foo","data":{"ids":["id"],"use_global_settings":false,"use_global_blocked_services":false,"name":"foo","filtering_enabled":false,"parental_enabled":false,"safesearch_enabled":false,"safebrowsing_enabled":false,"disallowed":false,"disallowed_rule":""}}`, `{"data":{"ids":["id"],"name":"foo"},"name":"foo"}`,
) )
err := cl.UpdateClients(types.Client{Name: "foo", Ids: []string{"id"}}) err := cl.UpdateClient(&model.Client{Name: utils.Ptr("foo"), Ids: utils.Ptr([]string{"id"})})
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should delete Clients", func() { It("should delete Clients", func() {
ts, cl = ClientPost("/clients/delete", ts, cl = ClientPost("/clients/delete",
`{"ids":["id"],"use_global_settings":false,"use_global_blocked_services":false,"name":"foo","filtering_enabled":false,"parental_enabled":false,"safesearch_enabled":false,"safebrowsing_enabled":false,"disallowed":false,"disallowed_rule":""}`, `{"ids":["id"],"name":"foo"}`,
) )
err := cl.DeleteClients(types.Client{Name: "foo", Ids: []string{"id"}}) err := cl.DeleteClient(&model.Client{Name: utils.Ptr("foo"), Ids: utils.Ptr([]string{"id"})})
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
}) })
Context("QueryLogConfig", func() { Context("QueryLogConfig", func() {
It("should read QueryLogConfig", func() { It("should read QueryLogConfig", func() {
ts, cl = ClientGet("querylog_info.json", "/querylog_info") ts, cl = ClientGet("querylog_config.json", "/querylog/config")
qlc, err := cl.QueryLogConfig() qlc, err := cl.QueryLogConfig()
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
Ω(qlc.Enabled).Should(BeTrue()) Ω(qlc.Enabled).ShouldNot(BeNil())
Ω(qlc.Interval).Should(Equal(90.0)) Ω(*qlc.Enabled).Should(BeTrue())
Ω(qlc.Interval).ShouldNot(BeNil())
Ω(*qlc.Interval).Should(Equal(model.QueryLogConfigInterval(90)))
}) })
It("should set QueryLogConfig", func() { It("should set QueryLogConfig", func() {
ts, cl = ClientPost("/querylog_config", `{"enabled":true,"interval":123,"anonymize_client_ip":true}`) ts, cl = ClientPut("/querylog/config/update", `{"anonymize_client_ip":true,"enabled":true,"interval":123,"ignored":["foo.bar"]}`)
err := cl.SetQueryLogConfig(true, 123, true)
var interval model.QueryLogConfigInterval = 123
err := cl.SetQueryLogConfig(&model.QueryLogConfigWithIgnored{
QueryLogConfig: model.QueryLogConfig{
AnonymizeClientIp: utils.Ptr(true),
Interval: &interval,
Enabled: utils.Ptr(true),
},
Ignored: []string{"foo.bar"},
})
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
}) })
Context("StatsConfig", func() { Context("StatsConfig", func() {
It("should read StatsConfig", func() { It("should read StatsConfig", func() {
ts, cl = ClientGet("stats_info.json", "/stats_info") ts, cl = ClientGet("stats_info.json", "/stats/config")
sc, err := cl.StatsConfig() sc, err := cl.StatsConfig()
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
Ω(sc.Interval).Should(Equal(1.0)) Ω(sc.Interval).ShouldNot(BeNil())
Ω(sc.Interval).Should(Equal(float32(1)))
}) })
It("should set StatsConfig", func() { It("should set StatsConfig", func() {
ts, cl = ClientPost("/stats_config", `{"interval":123}`) ts, cl = ClientPost("/stats/config/update", `{"enabled":false,"ignored":null,"interval":123}`)
err := cl.SetStatsConfig(123.0)
var interval float32 = 123
err := cl.SetStatsConfig(&model.PutStatsConfigUpdateRequest{Interval: interval})
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
}) })
@@ -308,7 +354,8 @@ bar`)
Context("doPost", func() { Context("doPost", func() {
It("should return an error on status code != 200", func() { It("should return an error on status code != 200", func() {
err := cl.SetStatsConfig(123) var interval float32 = 123
err := cl.SetStatsConfig(&model.PutStatsConfigUpdateRequest{Interval: interval})
Ω(err).Should(HaveOccurred()) Ω(err).Should(HaveOccurred())
Ω(err.Error()).Should(Equal("401 Unauthorized")) Ω(err.Error()).Should(Equal("401 Unauthorized"))
}) })
@@ -344,3 +391,18 @@ func ClientPost(path string, content ...string) (*httptest.Server, client.Client
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
return ts, cl return ts, cl
} }
func ClientPut(path string, content ...string) (*httptest.Server, client.Client) {
index := 0
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Ω(r.URL.Path).Should(Equal(types.DefaultAPIPath + path))
body, err := io.ReadAll(r.Body)
Ω(err).ShouldNot(HaveOccurred())
Ω(body).Should(Equal([]byte(content[index])))
index++
}))
cl, err := client.New(types.AdGuardInstance{URL: ts.URL, Username: username, Password: password})
Ω(err).ShouldNot(HaveOccurred())
return ts, cl
}

View File

@@ -0,0 +1,143 @@
package client
import (
"context"
"crypto/tls"
"encoding/base64"
"errors"
"fmt"
"io"
"net/http"
"net/url"
"path"
"github.com/bakito/adguardhome-sync/pkg/client/model"
"github.com/bakito/adguardhome-sync/pkg/log"
"github.com/bakito/adguardhome-sync/pkg/types"
"go.uber.org/zap"
)
var l = log.GetLogger("client")
// New create a new api client
func New(config types.AdGuardInstance) (Client, error) {
var apiURL string
if config.APIPath == "" {
apiURL = fmt.Sprintf("%s/control", config.URL)
} else {
apiURL = fmt.Sprintf("%s/%s", config.URL, config.APIPath)
}
u, err := url.Parse(apiURL)
if err != nil {
return nil, err
}
u.Path = path.Clean(u.Path)
httpClient := &http.Client{
Transport: &http.Transport{
// #nosec G402 has to be explicitly enabled
TLSClientConfig: &tls.Config{InsecureSkipVerify: config.InsecureSkipVerify},
},
}
aghClient, err := model.NewClient(u.String(), func(client *model.AdguardHomeClient) error {
client.Client = httpClient
client.RequestEditors = append(client.RequestEditors, func(ctx context.Context, req *http.Request) error {
if config.Username != "" && config.Password != "" {
req.Header.Add("Authorization", "Basic "+basicAuth(config.Username, config.Password))
}
return nil
})
return nil
})
if err != nil {
return nil, err
}
return &apiClient{
host: u.Host,
client: aghClient,
log: l.With("host", u.Host),
}, nil
}
func basicAuth(username, password string) string {
auth := username + ":" + password
return base64.StdEncoding.EncodeToString([]byte(auth))
}
type apiClient struct {
host string
client *model.AdguardHomeClient
log *zap.SugaredLogger
}
func (a apiClient) Host(context.Context) string {
return a.host
}
func (a apiClient) GetServerStatus(ctx context.Context) (*model.ServerStatus, error) {
sr, err := read(ctx, a.client.Status, model.ParseStatusResp)
if err != nil {
return nil, err
}
return sr.JSON200, nil
}
func (a apiClient) GetFilteringStatus(ctx context.Context) (*model.FilterStatus, error) {
sr, err := read(ctx, a.client.FilteringStatus, model.ParseFilteringStatusResp)
if err != nil {
return nil, err
}
return sr.JSON200, nil
}
func (a apiClient) SetFilteringConfig(ctx context.Context, config model.FilterConfig) error {
return write(ctx, config, a.client.FilteringConfig)
}
func write[B interface{}](
ctx context.Context,
body B,
req func(ctx context.Context, body B, reqEditors ...model.RequestEditorFn) (*http.Response, error),
) error {
resp, err := req(ctx, body)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return detailedError(resp)
}
return nil
}
func read[I interface{}](
ctx context.Context,
req func(ctx context.Context, reqEditors ...model.RequestEditorFn) (*http.Response, error),
parse func(rsp *http.Response) (*I, error),
) (*I, error) {
resp, err := req(ctx)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, detailedError(resp)
}
return parse(resp)
}
func detailedError(resp *http.Response) error {
e := resp.Status
body, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
if len(body) > 0 {
e += fmt.Sprintf("(%s)", string(body))
}
return errors.New(e)
}

View File

@@ -0,0 +1,15 @@
package client
import (
"context"
"github.com/bakito/adguardhome-sync/pkg/client/model"
)
type Client interface {
Host(ctx context.Context) string
GetServerStatus(ctx context.Context) (*model.ServerStatus, error)
GetFilteringStatus(ctx context.Context) (*model.FilterStatus, error)
SetFilteringConfig(ctx context.Context, config model.FilterConfig) error
}

View File

@@ -0,0 +1,27 @@
package client
import (
"net/http"
"github.com/bakito/adguardhome-sync/pkg/client/model"
"github.com/go-resty/resty/v2"
)
var _ model.HttpRequestDoer = &adapter{}
func RestyAdapter(r *resty.Client) model.HttpRequestDoer {
return &adapter{
client: r,
}
}
type adapter struct {
client *resty.Client
}
func (a adapter) Do(req *http.Request) (*http.Response, error) {
r, err := a.client.R().
SetHeaderMultiValues(req.Header).
Execute(req.Method, req.URL.String())
return r.RawResponse, err
}

View File

@@ -0,0 +1,423 @@
package model
import (
"fmt"
"sort"
"strings"
"github.com/bakito/adguardhome-sync/pkg/utils"
"github.com/jinzhu/copier"
"go.uber.org/zap"
)
// Clone the config
func (c *DhcpStatus) Clone() *DhcpStatus {
clone := &DhcpStatus{}
_ = copier.Copy(clone, c)
return clone
}
func (c *DhcpStatus) cleanV4V6() {
if c.V4 != nil && !c.V4.isValid() {
c.V4 = nil
}
if c.V6 != nil && !c.V6.isValid() {
c.V6 = nil
}
}
// CleanAndEquals dhcp server config equal check where V4 and V6 are cleaned in advance
func (c *DhcpStatus) CleanAndEquals(o *DhcpStatus) bool {
c.cleanV4V6()
o.cleanV4V6()
return c.Equals(o)
}
// Equals dhcp server config equal check
func (c *DhcpStatus) Equals(o *DhcpStatus) bool {
return utils.JsonEquals(c, o)
}
func (c *DhcpStatus) HasConfig() bool {
return (c.V4 != nil && c.V4.isValid()) || (c.V6 != nil && c.V6.isValid())
}
func (j DhcpConfigV4) isValid() bool {
return j.GatewayIp != nil && *j.GatewayIp != "" &&
j.SubnetMask != nil && *j.SubnetMask != "" &&
j.RangeStart != nil && *j.RangeStart != "" &&
j.RangeEnd != nil && *j.RangeEnd != ""
}
func (j DhcpConfigV6) isValid() bool {
return j.RangeStart != nil && *j.RangeStart != ""
}
type DhcpStaticLeases []DhcpStaticLease
// MergeDhcpStaticLeases the leases
func MergeDhcpStaticLeases(l *[]DhcpStaticLease, other *[]DhcpStaticLease) (DhcpStaticLeases, DhcpStaticLeases) {
var thisLeases []DhcpStaticLease
var otherLeases []DhcpStaticLease
if l != nil {
thisLeases = *l
}
if other != nil {
otherLeases = *other
}
current := make(map[string]DhcpStaticLease)
var adds DhcpStaticLeases
var removes DhcpStaticLeases
for _, le := range thisLeases {
current[le.Mac] = le
}
for _, le := range otherLeases {
if _, ok := current[le.Mac]; ok {
delete(current, le.Mac)
} else {
adds = append(adds, le)
}
}
for _, rr := range current {
removes = append(removes, rr)
}
return adds, removes
}
// Equals dns config equal check
func (c *DNSConfig) Equals(o *DNSConfig) bool {
cc := c.Clone()
oo := o.Clone()
cc.Sort()
oo.Sort()
return utils.JsonEquals(cc, oo)
}
func (c *DNSConfig) Clone() *DNSConfig {
return utils.Clone(c, &DNSConfig{})
}
// Sort sort dns config
func (c *DNSConfig) Sort() {
if c.UpstreamDns != nil {
sort.Strings(*c.UpstreamDns)
}
if c.UpstreamDns != nil {
sort.Strings(*c.BootstrapDns)
}
if c.UpstreamDns != nil {
sort.Strings(*c.LocalPtrUpstreams)
}
}
// Equals access list equal check
func (al *AccessList) Equals(o *AccessList) bool {
return EqualsStringSlice(al.AllowedClients, o.AllowedClients, true) &&
EqualsStringSlice(al.DisallowedClients, o.DisallowedClients, true) &&
EqualsStringSlice(al.BlockedHosts, o.BlockedHosts, true)
}
func EqualsStringSlice(a *[]string, b *[]string, sortIt bool) bool {
if a == nil && b == nil {
return true
}
if a == nil || b == nil {
return false
}
aa := *a
bb := *b
if sortIt {
sort.Strings(aa)
sort.Strings(bb)
}
if len(aa) != len(bb) {
return false
}
for i, v := range aa {
if v != bb[i] {
return false
}
}
return true
}
// Sort clients
func (cl *Client) Sort() {
if cl.Ids != nil {
sort.Strings(*cl.Ids)
}
if cl.Tags != nil {
sort.Strings(*cl.Tags)
}
if cl.BlockedServices != nil {
sort.Strings(*cl.BlockedServices)
}
if cl.Upstreams != nil {
sort.Strings(*cl.Upstreams)
}
}
// Equals Clients equal check
func (cl *Client) Equals(o *Client) bool {
cl.Sort()
o.Sort()
return utils.JsonEquals(cl, o)
}
// Add ac client
func (clients *Clients) Add(cl Client) {
if clients.Clients == nil {
clients.Clients = &ClientsArray{cl}
} else {
a := append(*clients.Clients, cl)
clients.Clients = &a
}
}
// Merge merge Clients
func (clients *Clients) Merge(other *Clients) ([]*Client, []*Client, []*Client) {
current := make(map[string]*Client)
if clients.Clients != nil {
cc := *clients.Clients
for _, client := range cc {
current[*client.Name] = &client
}
}
expected := make(map[string]*Client)
if other.Clients != nil {
oc := *other.Clients
for _, client := range oc {
expected[*client.Name] = &client
}
}
var adds []*Client
var removes []*Client
var updates []*Client
for _, cl := range expected {
if oc, ok := current[*cl.Name]; ok {
if !cl.Equals(oc) {
updates = append(updates, cl)
}
delete(current, *cl.Name)
} else {
adds = append(adds, cl)
}
}
for _, rr := range current {
removes = append(removes, rr)
}
return adds, updates, removes
}
// Key RewriteEntry key
func (re *RewriteEntry) Key() string {
var d string
var a string
if re.Domain != nil {
d = *re.Domain
}
if re.Answer != nil {
a = *re.Answer
}
return fmt.Sprintf("%s#%s", d, a)
}
// RewriteEntries list of RewriteEntry
type RewriteEntries []RewriteEntry
// Merge RewriteEntries
func (rwe *RewriteEntries) Merge(other *RewriteEntries) (RewriteEntries, RewriteEntries, RewriteEntries) {
current := make(map[string]RewriteEntry)
var adds RewriteEntries
var removes RewriteEntries
var duplicates RewriteEntries
processed := make(map[string]bool)
for _, rr := range *rwe {
if _, ok := processed[rr.Key()]; !ok {
current[rr.Key()] = rr
processed[rr.Key()] = true
} else {
// remove duplicate
removes = append(removes, rr)
}
}
for _, rr := range *other {
if _, ok := current[rr.Key()]; ok {
delete(current, rr.Key())
} else {
if _, ok := processed[rr.Key()]; !ok {
adds = append(adds, rr)
processed[rr.Key()] = true
} else {
// skip duplicate
duplicates = append(duplicates, rr)
}
}
}
for _, rr := range current {
removes = append(removes, rr)
}
return adds, removes, duplicates
}
func MergeFilters(this *[]Filter, other *[]Filter) ([]Filter, []Filter, []Filter) {
if this == nil && other == nil {
return nil, nil, nil
}
current := make(map[string]*Filter)
var adds []Filter
var updates []Filter
var removes []Filter
if this != nil {
for _, fi := range *this {
current[fi.Url] = &fi
}
}
if other != nil {
for _, rr := range *other {
if c, ok := current[rr.Url]; ok {
if !c.Equals(&rr) {
updates = append(updates, rr)
}
delete(current, rr.Url)
} else {
adds = append(adds, rr)
}
}
}
for _, rr := range current {
removes = append(removes, *rr)
}
return adds, updates, removes
}
// Equals Filter equal check
func (f *Filter) Equals(o *Filter) bool {
return f.Enabled == o.Enabled && f.Url == o.Url && f.Name == o.Name
}
type QueryLogConfigWithIgnored struct {
QueryLogConfig
// Ignored List of host names, which should not be written to log
Ignored []string `json:"ignored,omitempty"`
}
// Equals QueryLogConfig equal check
func (qlc *QueryLogConfigWithIgnored) Equals(o *QueryLogConfigWithIgnored) bool {
return utils.JsonEquals(qlc, o)
}
// Equals QueryLogConfigInterval equal check
func (qlc *QueryLogConfigInterval) Equals(o *QueryLogConfigInterval) bool {
return ptrEquals(qlc, o)
}
func ptrEquals[T comparable](a *T, b *T) bool {
if a == nil && b == nil {
return true
}
var aa T
if a != nil {
aa = *a
}
var bb T
if b != nil {
bb = *b
}
return aa == bb
}
// EnableConfig API struct
type EnableConfig struct {
Enabled bool `json:"enabled"`
}
func (ssc *SafeSearchConfig) Equals(o *SafeSearchConfig) bool {
return ptrEquals(ssc.Enabled, o.Enabled) &&
ptrEquals(ssc.Bing, o.Bing) &&
ptrEquals(ssc.Duckduckgo, o.Duckduckgo) &&
ptrEquals(ssc.Google, o.Google) &&
ptrEquals(ssc.Pixabay, o.Pixabay) &&
ptrEquals(ssc.Yandex, o.Yandex) &&
ptrEquals(ssc.Youtube, o.Youtube)
}
func (pi *ProfileInfo) Equals(o *ProfileInfo) bool {
return pi.Language == o.Language &&
pi.Theme == o.Theme
}
func (pi *ProfileInfo) ShouldSyncFor(o *ProfileInfo) *ProfileInfo {
if pi.Equals(o) {
return nil
}
merged := &ProfileInfo{Name: pi.Name, Language: pi.Language, Theme: pi.Theme}
if o.Language != "" {
merged.Language = o.Language
}
if o.Theme != "" {
merged.Theme = o.Theme
}
if merged.Name == "" || merged.Language == "" || merged.Theme == "" || merged.Equals(pi) {
return nil
}
return merged
}
func (bss *BlockedServicesSchedule) Equals(o *BlockedServicesSchedule) bool {
return utils.JsonEquals(bss, o)
}
func (bss *BlockedServicesSchedule) ServicesString() string {
return ArrayString(bss.Ids)
}
func ArrayString(a *[]string) string {
if a == nil {
return "[]"
}
sorted := *a
sort.Strings(sorted)
return fmt.Sprintf("[%s]", strings.Join(sorted, ","))
}
func (c *DNSConfig) Sanitize(l *zap.SugaredLogger) {
// disable UsePrivatePtrResolvers if not configured
if c.UsePrivatePtrResolvers != nil && *c.UsePrivatePtrResolvers &&
(c.LocalPtrUpstreams == nil || len(*c.LocalPtrUpstreams) == 0) {
l.Warn("disabling replica 'Use private reverse DNS resolvers' as no 'Private reverse DNS servers' are configured on origin")
c.UsePrivatePtrResolvers = utils.Ptr(false)
}
}
// Equals GetStatsConfigResponse equal check
func (sc *GetStatsConfigResponse) Equals(o *GetStatsConfigResponse) bool {
return utils.JsonEquals(sc, o)
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,103 @@
package model
import (
"github.com/bakito/adguardhome-sync/pkg/log"
"github.com/bakito/adguardhome-sync/pkg/utils"
. "github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"go.uber.org/zap"
)
var _ = Describe("Types", func() {
Context("DhcpConfigV4", func() {
DescribeTable("DhcpConfigV4 should not be valid",
func(v4 DhcpConfigV4) {
gomega.Ω(v4.isValid()).Should(gomega.BeFalse())
},
Entry(`When GatewayIp is nil`, DhcpConfigV4{
GatewayIp: nil,
SubnetMask: utils.Ptr("2.2.2.2"),
RangeStart: utils.Ptr("3.3.3.3"),
RangeEnd: utils.Ptr("4.4.4.4"),
}),
Entry(`When GatewayIp is ""`, DhcpConfigV4{
GatewayIp: utils.Ptr(""),
SubnetMask: utils.Ptr("2.2.2.2"),
RangeStart: utils.Ptr("3.3.3.3"),
RangeEnd: utils.Ptr("4.4.4.4"),
}),
Entry(`When SubnetMask is nil`, DhcpConfigV4{
GatewayIp: utils.Ptr("1.1.1.1"),
SubnetMask: nil,
RangeStart: utils.Ptr("3.3.3.3"),
RangeEnd: utils.Ptr("4.4.4.4"),
}),
Entry(`When SubnetMask is ""`, DhcpConfigV4{
GatewayIp: utils.Ptr("1.1.1.1"),
SubnetMask: utils.Ptr(""),
RangeStart: utils.Ptr("3.3.3.3"),
RangeEnd: utils.Ptr("4.4.4.4"),
}),
Entry(`When SubnetMask is nil`, DhcpConfigV4{
GatewayIp: utils.Ptr("1.1.1.1"),
SubnetMask: utils.Ptr("2.2.2.2"),
RangeStart: nil,
RangeEnd: utils.Ptr("4.4.4.4"),
}),
Entry(`When SubnetMask is ""`, DhcpConfigV4{
GatewayIp: utils.Ptr("1.1.1.1"),
SubnetMask: utils.Ptr("2.2.2.2"),
RangeStart: utils.Ptr(""),
RangeEnd: utils.Ptr("4.4.4.4"),
}),
Entry(`When RangeEnd is nil`, DhcpConfigV4{
GatewayIp: utils.Ptr("1.1.1.1"),
SubnetMask: utils.Ptr("2.2.2.2"),
RangeStart: utils.Ptr("3.3.3.3"),
RangeEnd: nil,
}),
Entry(`When RangeEnd is ""`, DhcpConfigV4{
GatewayIp: utils.Ptr("1.1.1.1"),
SubnetMask: utils.Ptr("2.2.2.2"),
RangeStart: utils.Ptr("3.3.3.3"),
RangeEnd: utils.Ptr(""),
}),
)
})
Context("DhcpConfigV6", func() {
DescribeTable("DhcpConfigV6 should not be valid",
func(v6 DhcpConfigV6) {
gomega.Ω(v6.isValid()).Should(gomega.BeFalse())
},
Entry(`When SubnetMask is nil`, DhcpConfigV6{RangeStart: nil}),
Entry(`When SubnetMask is ""`, DhcpConfigV6{RangeStart: utils.Ptr("")}),
)
})
Context("DNSConfig", func() {
var (
cfg *DNSConfig
l *zap.SugaredLogger
)
BeforeEach(func() {
cfg = &DNSConfig{
UsePrivatePtrResolvers: utils.Ptr(true),
}
l = log.GetLogger("test")
})
Context("Sanitize", func() {
It("should disable UsePrivatePtrResolvers resolvers is nil ", func() {
cfg.LocalPtrUpstreams = nil
cfg.Sanitize(l)
gomega.Ω(cfg.UsePrivatePtrResolvers).ShouldNot(gomega.BeNil())
gomega.Ω(*cfg.UsePrivatePtrResolvers).Should(gomega.Equal(false))
})
It("should disable UsePrivatePtrResolvers resolvers is empty ", func() {
cfg.LocalPtrUpstreams = utils.Ptr([]string{})
cfg.Sanitize(l)
gomega.Ω(cfg.UsePrivatePtrResolvers).ShouldNot(gomega.BeNil())
gomega.Ω(*cfg.UsePrivatePtrResolvers).Should(gomega.Equal(false))
})
})
})
})

View File

@@ -0,0 +1,13 @@
package model_test
import (
"testing"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
func TestTypes(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Model Suite")
}

View File

@@ -0,0 +1,443 @@
package model_test
import (
"encoding/json"
"os"
"github.com/bakito/adguardhome-sync/pkg/client/model"
"github.com/bakito/adguardhome-sync/pkg/types"
"github.com/bakito/adguardhome-sync/pkg/utils"
"github.com/google/uuid"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Types", func() {
var (
url string
apiPath string
)
BeforeEach(func() {
url = "https://" + uuid.NewString()
apiPath = "/" + uuid.NewString()
})
Context("FilteringStatus", func() {
It("should correctly parse json", func() {
b, err := os.ReadFile("../../../testdata/filtering-status.json")
fs := &model.FilterStatus{}
Ω(err).ShouldNot(HaveOccurred())
err = json.Unmarshal(b, fs)
Ω(err).ShouldNot(HaveOccurred())
})
})
Context("Filters", func() {
Context("Merge", func() {
var (
originFilters []model.Filter
replicaFilters []model.Filter
)
BeforeEach(func() {
originFilters = []model.Filter{}
replicaFilters = []model.Filter{}
})
It("should add a missing filter", func() {
originFilters = append(originFilters, model.Filter{Url: url})
a, u, d := model.MergeFilters(&replicaFilters, &originFilters)
Ω(a).Should(HaveLen(1))
Ω(u).Should(BeEmpty())
Ω(d).Should(BeEmpty())
Ω(a[0].Url).Should(Equal(url))
})
It("should remove additional filter", func() {
replicaFilters = append(replicaFilters, model.Filter{Url: url})
a, u, d := model.MergeFilters(&replicaFilters, &originFilters)
Ω(a).Should(BeEmpty())
Ω(u).Should(BeEmpty())
Ω(d).Should(HaveLen(1))
Ω(d[0].Url).Should(Equal(url))
})
It("should update existing filter when enabled differs", func() {
enabled := true
originFilters = append(originFilters, model.Filter{Url: url, Enabled: enabled})
replicaFilters = append(replicaFilters, model.Filter{Url: url, Enabled: !enabled})
a, u, d := model.MergeFilters(&replicaFilters, &originFilters)
Ω(a).Should(BeEmpty())
Ω(u).Should(HaveLen(1))
Ω(d).Should(BeEmpty())
Ω(u[0].Enabled).Should(Equal(enabled))
})
It("should update existing filter when name differs", func() {
name1 := uuid.NewString()
name2 := uuid.NewString()
originFilters = append(originFilters, model.Filter{Url: url, Name: name1})
replicaFilters = append(replicaFilters, model.Filter{Url: url, Name: name2})
a, u, d := model.MergeFilters(&replicaFilters, &originFilters)
Ω(a).Should(BeEmpty())
Ω(u).Should(HaveLen(1))
Ω(d).Should(BeEmpty())
Ω(u[0].Name).Should(Equal(name1))
})
It("should have no changes", func() {
originFilters = append(originFilters, model.Filter{Url: url})
replicaFilters = append(replicaFilters, model.Filter{Url: url})
a, u, d := model.MergeFilters(&replicaFilters, &originFilters)
Ω(a).Should(BeEmpty())
Ω(u).Should(BeEmpty())
Ω(d).Should(BeEmpty())
})
})
})
Context("AdGuardInstance", func() {
It("should build a key with url and api apiPath", func() {
i := &types.AdGuardInstance{URL: url, APIPath: apiPath}
Ω(i.Key()).Should(Equal(url + "#" + apiPath))
})
})
Context("RewriteEntry", func() {
It("should build a key with url and api apiPath", func() {
domain := uuid.NewString()
answer := uuid.NewString()
re := &model.RewriteEntry{Domain: utils.Ptr(domain), Answer: utils.Ptr(answer)}
Ω(re.Key()).Should(Equal(domain + "#" + answer))
})
})
Context("QueryLogConfig", func() {
Context("Equal", func() {
var (
a *model.QueryLogConfigWithIgnored
b *model.QueryLogConfigWithIgnored
)
BeforeEach(func() {
a = &model.QueryLogConfigWithIgnored{}
b = &model.QueryLogConfigWithIgnored{}
})
It("should be equal", func() {
a.Enabled = utils.Ptr(true)
var interval model.QueryLogConfigInterval = 1
a.Interval = &interval
a.AnonymizeClientIp = utils.Ptr(true)
b.Enabled = utils.Ptr(true)
b.Interval = &interval
b.AnonymizeClientIp = utils.Ptr(true)
Ω(a.Equals(b)).Should(BeTrue())
})
It("should not be equal when enabled differs", func() {
a.Enabled = utils.Ptr(true)
b.Enabled = utils.Ptr(false)
Ω(a.Equals(b)).ShouldNot(BeTrue())
})
It("should not be equal when interval differs", func() {
var interval1 model.QueryLogConfigInterval = 1
var interval2 model.QueryLogConfigInterval = 2
a.Interval = &interval1
b.Interval = &interval2
Ω(a.Equals(b)).ShouldNot(BeTrue())
})
It("should not be equal when anonymizeClientIP differs", func() {
a.AnonymizeClientIp = utils.Ptr(true)
b.AnonymizeClientIp = utils.Ptr(false)
Ω(a.Equals(b)).ShouldNot(BeTrue())
})
})
})
Context("RewriteEntries", func() {
Context("Merge", func() {
var (
originRE model.RewriteEntries
replicaRE model.RewriteEntries
domain string
)
BeforeEach(func() {
originRE = model.RewriteEntries{}
replicaRE = model.RewriteEntries{}
domain = uuid.NewString()
})
It("should add a missing rewrite entry", func() {
originRE = append(originRE, model.RewriteEntry{Domain: utils.Ptr(domain)})
a, r, d := replicaRE.Merge(&originRE)
Ω(a).Should(HaveLen(1))
Ω(r).Should(BeEmpty())
Ω(d).Should(BeEmpty())
Ω(*a[0].Domain).Should(Equal(domain))
})
It("should remove additional rewrite entry", func() {
replicaRE = append(replicaRE, model.RewriteEntry{Domain: utils.Ptr(domain)})
a, r, d := replicaRE.Merge(&originRE)
Ω(a).Should(BeEmpty())
Ω(r).Should(HaveLen(1))
Ω(d).Should(BeEmpty())
Ω(*r[0].Domain).Should(Equal(domain))
})
It("should have no changes", func() {
originRE = append(originRE, model.RewriteEntry{Domain: utils.Ptr(domain)})
replicaRE = append(replicaRE, model.RewriteEntry{Domain: utils.Ptr(domain)})
a, r, d := replicaRE.Merge(&originRE)
Ω(a).Should(BeEmpty())
Ω(r).Should(BeEmpty())
Ω(d).Should(BeEmpty())
})
It("should remove target duplicate", func() {
originRE = append(originRE, model.RewriteEntry{Domain: utils.Ptr(domain)})
replicaRE = append(replicaRE, model.RewriteEntry{Domain: utils.Ptr(domain)})
replicaRE = append(replicaRE, model.RewriteEntry{Domain: utils.Ptr(domain)})
a, r, d := replicaRE.Merge(&originRE)
Ω(a).Should(BeEmpty())
Ω(r).Should(HaveLen(1))
Ω(d).Should(BeEmpty())
})
It("should remove target duplicate", func() {
originRE = append(originRE, model.RewriteEntry{Domain: utils.Ptr(domain)})
originRE = append(originRE, model.RewriteEntry{Domain: utils.Ptr(domain)})
replicaRE = append(replicaRE, model.RewriteEntry{Domain: utils.Ptr(domain)})
a, r, d := replicaRE.Merge(&originRE)
Ω(a).Should(BeEmpty())
Ω(r).Should(BeEmpty())
Ω(d).Should(HaveLen(1))
})
})
})
Context("Config", func() {
var cfg *types.Config
BeforeEach(func() {
cfg = &types.Config{}
})
Context("UniqueReplicas", func() {
It("should be empty if noting defined", func() {
r := cfg.UniqueReplicas()
Ω(r).Should(BeEmpty())
})
It("should be empty if replica url is not set", func() {
cfg.Replica = &types.AdGuardInstance{URL: ""}
r := cfg.UniqueReplicas()
Ω(r).Should(BeEmpty())
})
It("should be empty if replicas url is not set", func() {
cfg.Replicas = []types.AdGuardInstance{{URL: ""}}
r := cfg.UniqueReplicas()
Ω(r).Should(BeEmpty())
})
It("should return only one replica if same url and apiPath", func() {
cfg.Replica = &types.AdGuardInstance{URL: url, APIPath: apiPath}
cfg.Replicas = []types.AdGuardInstance{{URL: url, APIPath: apiPath}, {URL: url, APIPath: apiPath}}
r := cfg.UniqueReplicas()
Ω(r).Should(HaveLen(1))
})
It("should return 3 one replicas if urls are different", func() {
cfg.Replica = &types.AdGuardInstance{URL: url, APIPath: apiPath}
cfg.Replicas = []types.AdGuardInstance{{URL: url + "1", APIPath: apiPath}, {URL: url, APIPath: apiPath + "1"}}
r := cfg.UniqueReplicas()
Ω(r).Should(HaveLen(3))
})
It("should set default api apiPath if not set", func() {
cfg.Replica = &types.AdGuardInstance{URL: url}
cfg.Replicas = []types.AdGuardInstance{{URL: url + "1"}}
r := cfg.UniqueReplicas()
Ω(r).Should(HaveLen(2))
Ω(r[0].APIPath).Should(Equal(types.DefaultAPIPath))
Ω(r[1].APIPath).Should(Equal(types.DefaultAPIPath))
})
})
})
Context("Clients", func() {
Context("Merge", func() {
var (
originClients *model.Clients
replicaClients model.Clients
name string
)
BeforeEach(func() {
originClients = &model.Clients{}
replicaClients = model.Clients{}
name = uuid.NewString()
})
It("should add a missing client", func() {
originClients.Add(model.Client{Name: utils.Ptr(name)})
a, u, d := replicaClients.Merge(originClients)
Ω(a).Should(HaveLen(1))
Ω(u).Should(BeEmpty())
Ω(d).Should(BeEmpty())
Ω(*a[0].Name).Should(Equal(name))
})
It("should remove additional client", func() {
replicaClients.Add(model.Client{Name: utils.Ptr(name)})
a, u, d := replicaClients.Merge(originClients)
Ω(a).Should(BeEmpty())
Ω(u).Should(BeEmpty())
Ω(d).Should(HaveLen(1))
Ω(*d[0].Name).Should(Equal(name))
})
It("should update existing client when name differs", func() {
disallowed := true
originClients.Add(model.Client{Name: utils.Ptr(name), FilteringEnabled: utils.Ptr(disallowed)})
replicaClients.Add(model.Client{Name: utils.Ptr(name), FilteringEnabled: utils.Ptr(!disallowed)})
a, u, d := replicaClients.Merge(originClients)
Ω(a).Should(BeEmpty())
Ω(u).Should(HaveLen(1))
Ω(d).Should(BeEmpty())
Ω(*u[0].FilteringEnabled).Should(Equal(disallowed))
})
})
})
Context("BlockedServices", func() {
Context("Equals", func() {
It("should be equal", func() {
s1 := &model.BlockedServicesArray{"a", "b"}
s2 := &model.BlockedServicesArray{"b", "a"}
Ω(model.EqualsStringSlice(s1, s2, true)).Should(BeTrue())
})
It("should not be equal different values", func() {
s1 := &model.BlockedServicesArray{"a", "b"}
s2 := &model.BlockedServicesArray{"B", "a"}
Ω(model.EqualsStringSlice(s1, s2, true)).ShouldNot(BeTrue())
})
It("should not be equal different length", func() {
s1 := &model.BlockedServicesArray{"a", "b"}
s2 := &model.BlockedServicesArray{"b", "a", "c"}
Ω(model.EqualsStringSlice(s1, s2, true)).ShouldNot(BeTrue())
})
})
})
Context("DNSConfig", func() {
Context("Equals", func() {
It("should be equal", func() {
dc1 := &model.DNSConfig{LocalPtrUpstreams: utils.Ptr([]string{"a"})}
dc2 := &model.DNSConfig{LocalPtrUpstreams: utils.Ptr([]string{"a"})}
Ω(dc1.Equals(dc2)).Should(BeTrue())
})
It("should not be equal", func() {
dc1 := &model.DNSConfig{LocalPtrUpstreams: utils.Ptr([]string{"a"})}
dc2 := &model.DNSConfig{LocalPtrUpstreams: utils.Ptr([]string{"b"})}
Ω(dc1.Equals(dc2)).ShouldNot(BeTrue())
})
})
})
Context("DHCPServerConfig", func() {
Context("Equals", func() {
It("should be equal", func() {
dc1 := &model.DhcpStatus{
V4: &model.DhcpConfigV4{
GatewayIp: utils.Ptr("1.2.3.4"),
LeaseDuration: utils.Ptr(123),
RangeStart: utils.Ptr("1.2.3.5"),
RangeEnd: utils.Ptr("1.2.3.6"),
SubnetMask: utils.Ptr("255.255.255.0"),
},
}
dc2 := &model.DhcpStatus{
V4: &model.DhcpConfigV4{
GatewayIp: utils.Ptr("1.2.3.4"),
LeaseDuration: utils.Ptr(123),
RangeStart: utils.Ptr("1.2.3.5"),
RangeEnd: utils.Ptr("1.2.3.6"),
SubnetMask: utils.Ptr("255.255.255.0"),
},
}
Ω(dc1.Equals(dc2)).Should(BeTrue())
})
It("should not be equal", func() {
dc1 := &model.DhcpStatus{
V4: &model.DhcpConfigV4{
GatewayIp: utils.Ptr("1.2.3.3"),
LeaseDuration: utils.Ptr(123),
RangeStart: utils.Ptr("1.2.3.5"),
RangeEnd: utils.Ptr("1.2.3.6"),
SubnetMask: utils.Ptr("255.255.255.0"),
},
}
dc2 := &model.DhcpStatus{
V4: &model.DhcpConfigV4{
GatewayIp: utils.Ptr("1.2.3.4"),
LeaseDuration: utils.Ptr(123),
RangeStart: utils.Ptr("1.2.3.5"),
RangeEnd: utils.Ptr("1.2.3.6"),
SubnetMask: utils.Ptr("255.255.255.0"),
},
}
Ω(dc1.Equals(dc2)).ShouldNot(BeTrue())
})
})
Context("Clone", func() {
It("clone should be equal", func() {
dc1 := &model.DhcpStatus{
V4: &model.DhcpConfigV4{
GatewayIp: utils.Ptr("1.2.3.4"),
LeaseDuration: utils.Ptr(123),
RangeStart: utils.Ptr("1.2.3.5"),
RangeEnd: utils.Ptr("1.2.3.6"),
SubnetMask: utils.Ptr("255.255.255.0"),
},
}
Ω(dc1.Clone().Equals(dc1)).Should(BeTrue())
})
})
Context("HasConfig", func() {
It("should not have a config", func() {
dc1 := &model.DhcpStatus{
V4: &model.DhcpConfigV4{},
V6: &model.DhcpConfigV6{},
}
Ω(dc1.HasConfig()).Should(BeFalse())
})
It("should not have a v4 config with nil IP", func() {
dc1 := &model.DhcpStatus{
V4: &model.DhcpConfigV4{
GatewayIp: nil,
},
V6: &model.DhcpConfigV6{
RangeStart: utils.Ptr("1.2.3.5"),
},
}
Ω(dc1.HasConfig()).Should(BeTrue())
})
It("should not have a v4 config with empty IP", func() {
dc1 := &model.DhcpStatus{
V4: &model.DhcpConfigV4{
GatewayIp: utils.Ptr(""),
},
V6: &model.DhcpConfigV6{
RangeStart: utils.Ptr("1.2.3.5"),
},
}
Ω(dc1.HasConfig()).Should(BeTrue())
})
It("should not have a v6 config", func() {
dc1 := &model.DhcpStatus{
V4: &model.DhcpConfigV4{
GatewayIp: utils.Ptr("1.2.3.4"),
LeaseDuration: utils.Ptr(123),
RangeStart: utils.Ptr("1.2.3.5"),
RangeEnd: utils.Ptr("1.2.3.6"),
SubnetMask: utils.Ptr("255.255.255.0"),
},
V6: &model.DhcpConfigV6{},
}
Ω(dc1.HasConfig()).Should(BeTrue())
})
})
})
})

95
pkg/config/config.go Normal file
View File

@@ -0,0 +1,95 @@
package config
import (
"errors"
"regexp"
"github.com/bakito/adguardhome-sync/pkg/log"
"github.com/bakito/adguardhome-sync/pkg/types"
"github.com/caarlos0/env/v10"
)
var (
envReplicasURLPattern = regexp.MustCompile(`^REPLICA(\d+)_URL=(.*)`)
logger = log.GetLogger("config")
)
func Get(configFile string, flags Flags) (*types.Config, error) {
path, err := configFilePath(configFile)
if err != nil {
return nil, err
}
cfg := initialConfig()
// read yaml config
if err := readFile(cfg, path); err != nil {
return nil, err
}
// overwrite from command flags
if err := readFlags(cfg, flags); err != nil {
return nil, err
}
// *bool field creates issues when already not nil
cfg.Origin.DHCPServerEnabled = nil // origin filed makes no sense to be set.
// keep previously set value
replicaDhcpServer := cfg.Replica.DHCPServerEnabled
cfg.Replica.DHCPServerEnabled = nil
// overwrite from env vars
if err := env.Parse(cfg); err != nil {
return nil, err
}
if err := env.ParseWithOptions(cfg.Replica, env.Options{Prefix: "REPLICA_"}); err != nil {
return nil, err
}
// if not set from env, use previous value
if cfg.Replica.DHCPServerEnabled == nil {
cfg.Replica.DHCPServerEnabled = replicaDhcpServer
}
if err := env.ParseWithOptions(&cfg.Origin, env.Options{Prefix: "ORIGIN_"}); err != nil {
return nil, err
}
if cfg.Replica != nil &&
cfg.Replica.URL == "" &&
cfg.Replica.Username == "" {
cfg.Replica = nil
}
if len(cfg.Replicas) > 0 && cfg.Replica != nil {
return nil, errors.New("mixed replica config in use. " +
"Do not use single replica and numbered (list) replica config combined")
}
handleDeprecatedEnvVars(cfg)
if cfg.Replica != nil {
cfg.Replicas = []types.AdGuardInstance{*cfg.Replica}
cfg.Replica = nil
}
cfg.Replicas, err = enrichReplicasFromEnv(cfg.Replicas)
return cfg, err
}
func initialConfig() *types.Config {
return &types.Config{
RunOnStart: true,
Origin: types.AdGuardInstance{
APIPath: "/control",
},
Replica: &types.AdGuardInstance{
APIPath: "/control",
},
API: types.API{
Port: 8080,
},
Features: types.NewFeatures(true),
}
}

View File

@@ -1,4 +1,4 @@
package cmd_test package config_test
import ( import (
"testing" "testing"
@@ -9,5 +9,5 @@ import (
func TestCmd(t *testing.T) { func TestCmd(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Cmd Suite") RunSpecs(t, "Config Suite")
} }

238
pkg/config/config_test.go Normal file
View File

@@ -0,0 +1,238 @@
package config_test
import (
"os"
"github.com/bakito/adguardhome-sync/pkg/config"
flagsmock "github.com/bakito/adguardhome-sync/pkg/mocks/flags"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
gm "go.uber.org/mock/gomock"
)
var _ = Describe("Config", func() {
Context("Get", func() {
var (
flags *flagsmock.MockFlags
mockCtrl *gm.Controller
changedEnvVars []string
setEnv = func(name string, value string) {
_ = os.Setenv(name, value)
changedEnvVars = append(changedEnvVars, name)
}
)
BeforeEach(func() {
mockCtrl = gm.NewController(GinkgoT())
flags = flagsmock.NewMockFlags(mockCtrl)
changedEnvVars = nil
})
AfterEach(func() {
for _, envVar := range changedEnvVars {
_ = os.Unsetenv(envVar)
println(envVar)
}
defer mockCtrl.Finish()
})
Context("Get", func() {
Context("Mixed Config", func() {
It("should have the origin URL from the config file", func() {
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
_, err := config.Get("../../testdata/config_test_replicas_and_replica.yaml", flags)
Ω(err).Should(HaveOccurred())
Ω(err.Error()).Should(ContainSubstring("mixed replica config in use"))
})
})
Context("Origin Url", func() {
It("should have the origin URL from the config file", func() {
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
cfg, err := config.Get("../../testdata/config_test_replicas.yaml", flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.Origin.URL).Should(Equal("https://origin-file:443"))
})
It("should have the origin URL from the config flags", func() {
flags.EXPECT().Changed(config.FlagOriginURL).Return(true).AnyTimes()
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
flags.EXPECT().GetString(config.FlagOriginURL).Return("https://origin-flag:443", nil).AnyTimes()
cfg, err := config.Get("../../testdata/config_test_replicas.yaml", flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.Origin.URL).Should(Equal("https://origin-flag:443"))
})
It("should have the origin URL from the config env var", func() {
setEnv("ORIGIN_URL", "https://origin-env:443")
flags.EXPECT().Changed(config.FlagOriginURL).Return(true).AnyTimes()
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
flags.EXPECT().GetString(config.FlagOriginURL).Return("https://origin-flag:443", nil).AnyTimes()
cfg, err := config.Get("../../testdata/config_test_replicas.yaml", flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.Origin.URL).Should(Equal("https://origin-env:443"))
})
})
Context("Replica insecure skip verify", func() {
It("should have the insecure skip verify from the config file", func() {
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
cfg, err := config.Get("../../testdata/config_test_replica.yaml", flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.Replicas[0].InsecureSkipVerify).Should(BeFalse())
})
It("should have the insecure skip verify from the config flags", func() {
flags.EXPECT().Changed(config.FlagReplicaISV).Return(true).AnyTimes()
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
flags.EXPECT().GetBool(config.FlagReplicaISV).Return(true, nil).AnyTimes()
cfg, err := config.Get("../../testdata/config_test_replica.yaml", flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.Replicas[0].InsecureSkipVerify).Should(BeTrue())
})
It("should have the insecure skip verify from the config env var", func() {
setEnv("REPLICA_INSECURE_SKIP_VERIFY", "false")
flags.EXPECT().Changed(config.FlagReplicaISV).Return(true).AnyTimes()
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
flags.EXPECT().GetBool(config.FlagReplicaISV).Return(true, nil).AnyTimes()
cfg, err := config.Get("../../testdata/config_test_replica.yaml", flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.Replicas[0].InsecureSkipVerify).Should(BeFalse())
})
})
Context("Replica 1 insecure skip verify", func() {
It("should have the insecure skip verify from the config file", func() {
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
cfg, err := config.Get("../../testdata/config_test_replicas.yaml", flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.Replicas[0].InsecureSkipVerify).Should(BeFalse())
})
It("should have the insecure skip verify from the config env var", func() {
setEnv("REPLICA1_INSECURE_SKIP_VERIFY", "true")
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
cfg, err := config.Get("../../testdata/config_test_replicas.yaml", flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.Replicas[0].InsecureSkipVerify).Should(BeTrue())
})
})
Context("API Port", func() {
It("should have the api port from the config file", func() {
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
cfg, err := config.Get("../../testdata/config_test_replicas.yaml", flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.API.Port).Should(Equal(9090))
})
It("should have the api port from the config flags", func() {
flags.EXPECT().Changed(config.FlagApiPort).Return(true).AnyTimes()
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
flags.EXPECT().GetInt(config.FlagApiPort).Return(9990, nil).AnyTimes()
cfg, err := config.Get("../../testdata/config_test_replicas.yaml", flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.API.Port).Should(Equal(9990))
})
It("should have the api port from the config env var", func() {
setEnv("API_PORT", "9999")
flags.EXPECT().Changed(config.FlagApiPort).Return(true).AnyTimes()
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
flags.EXPECT().GetInt(config.FlagApiPort).Return(9990, nil).AnyTimes()
cfg, err := config.Get("../../testdata/config_test_replicas.yaml", flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.API.Port).Should(Equal(9999))
})
})
Context("Replica DHCPServerEnabled", func() {
It("should have the dhcp server enabled from the config file", func() {
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
cfg, err := config.Get("../../testdata/config_test_replica.yaml", flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.Replicas[0].DHCPServerEnabled).ShouldNot(BeNil())
Ω(*cfg.Replicas[0].DHCPServerEnabled).Should(BeFalse())
})
})
Context("Replica 1 DHCPServerEnabled", func() {
It("should have the dhcp server enabled from the config file", func() {
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
cfg, err := config.Get("../../testdata/config_test_replicas.yaml", flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.Replicas[0].DHCPServerEnabled).ShouldNot(BeNil())
Ω(*cfg.Replicas[0].DHCPServerEnabled).Should(BeFalse())
})
})
Context("API Port", func() {
It("should have the api port from the config file", func() {
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
cfg, err := config.Get("../../testdata/config_test_replicas.yaml", flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.API.Port).Should(Equal(9090))
})
It("should have the api port from the config flags", func() {
flags.EXPECT().Changed(config.FlagApiPort).Return(true).AnyTimes()
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
flags.EXPECT().GetInt(config.FlagApiPort).Return(9990, nil).AnyTimes()
cfg, err := config.Get("../../testdata/config_test_replicas.yaml", flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.API.Port).Should(Equal(9990))
})
It("should have the api port from the config env var", func() {
setEnv("API_PORT", "9999")
flags.EXPECT().Changed(config.FlagApiPort).Return(true).AnyTimes()
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
flags.EXPECT().GetInt(config.FlagApiPort).Return(9990, nil).AnyTimes()
cfg, err := config.Get("../../testdata/config_test_replicas.yaml", flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.API.Port).Should(Equal(9999))
})
})
//////
Context("Feature DNS Server Config", func() {
It("should have the feature dns server config from the config file", func() {
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
cfg, err := config.Get("../../testdata/config_test_replicas.yaml", flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.Features.DNS.ServerConfig).Should(BeFalse())
})
It("should have the feature dns server config from the config flags", func() {
flags.EXPECT().Changed(config.FlagFeatureDnsServerConfig).Return(true).AnyTimes()
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
flags.EXPECT().GetBool(config.FlagFeatureDnsServerConfig).Return(true, nil).AnyTimes()
cfg, err := config.Get("../../testdata/config_test_replicas.yaml", flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.Features.DNS.ServerConfig).Should(BeTrue())
})
It("should have the feature dns server config from the config env var", func() {
setEnv("FEATURES_DNS_SERVER_CONFIG", "false")
flags.EXPECT().Changed(config.FlagFeatureDnsServerConfig).Return(true).AnyTimes()
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
flags.EXPECT().GetBool(config.FlagFeatureDnsServerConfig).Return(true, nil).AnyTimes()
cfg, err := config.Get("../../testdata/config_test_replicas.yaml", flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.Features.DNS.ServerConfig).Should(BeFalse())
})
It("should have the feature dns server config from the config DEPRECATED env var", func() {
setEnv("FEATURES_DNS_SERVERCONFIG", "false")
flags.EXPECT().Changed(config.FlagFeatureDnsServerConfig).Return(true).AnyTimes()
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
flags.EXPECT().GetBool(config.FlagFeatureDnsServerConfig).Return(true, nil).AnyTimes()
cfg, err := config.Get("../../testdata/config_test_replicas.yaml", flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.Features.DNS.ServerConfig).Should(BeFalse())
})
})
})
})
})

View File

@@ -0,0 +1,138 @@
package config_test
import (
"fmt"
"os"
"github.com/bakito/adguardhome-sync/pkg/config"
"github.com/bakito/adguardhome-sync/pkg/types"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var envVars = []string{
"FEATURES_GENERAL_SETTINGS",
"FEATURES_QUERY_LOG_CONFIG",
"FEATURES_STATS_CONFIG",
"FEATURES_CLIENT_SETTINGS",
"FEATURES_SERVICES",
"FEATURES_FILTERS",
"FEATURES_DHCP_SERVER_CONFIG",
"FEATURES_DHCP_STATIC_LEASES",
"FEATURES_DNS_SERVER_CONFIG",
"FEATURES_DNS_ACCESS_LISTS",
"FEATURES_DNS_REWRITES",
"REPLICA1_INTERFACE_NAME",
"REPLICA1_DHCP_SERVER_ENABLED",
}
var deprecatedEnvVars = []string{
"FEATURES_GENERALSETTINGS",
"FEATURES_QUERYLOGCONFIG",
"FEATURES_STATSCONFIG",
"FEATURES_CLIENTSETTINGS",
"FEATURES_SERVICES",
"FEATURES_FILTERS",
"FEATURES_DHCP_SERVERCONFIG",
"FEATURES_DHCP_STATICLEASES",
"FEATURES_DNS_SERVERCONFIG",
"FEATURES_DNS_ACCESSLISTS",
"FEATURES_DNS_REWRITES",
"REPLICA1_INTERFACENAME",
"REPLICA1_DHCPSERVERENABLED",
}
var _ = Describe("Config", func() {
Context("deprecated", func() {
BeforeEach(func() {
for _, envVar := range deprecatedEnvVars {
Ω(os.Setenv(envVar, "false")).ShouldNot(HaveOccurred())
}
})
AfterEach(func() {
for _, envVar := range deprecatedEnvVars {
Ω(os.Unsetenv(envVar)).ShouldNot(HaveOccurred())
}
})
Context("Get", func() {
It("features should be false", func() {
cfg, err := config.Get("", nil)
Ω(err).ShouldNot(HaveOccurred())
verifyFeatures(cfg, false)
})
})
})
Context("current", func() {
BeforeEach(func() {
for _, envVar := range envVars {
Ω(os.Unsetenv(envVar)).ShouldNot(HaveOccurred())
}
})
AfterEach(func() {
for _, envVar := range envVars {
Ω(os.Unsetenv(envVar)).ShouldNot(HaveOccurred())
}
})
Context("Get", func() {
It("features should be true by default", func() {
cfg, err := config.Get("", nil)
Ω(err).ShouldNot(HaveOccurred())
verifyFeatures(cfg, true)
})
It("features should be true by default", func() {
cfg, err := config.Get("", nil)
Ω(err).ShouldNot(HaveOccurred())
verifyFeatures(cfg, true)
})
It("features should be false", func() {
for _, envVar := range envVars {
Ω(os.Setenv(envVar, "false")).ShouldNot(HaveOccurred())
}
cfg, err := config.Get("", nil)
Ω(err).ShouldNot(HaveOccurred())
verifyFeatures(cfg, false)
})
Context("interface name", func() {
It("should set interface name of replica 1", func() {
Ω(os.Setenv("REPLICA1_URL", "https://foo.bar")).ShouldNot(HaveOccurred())
Ω(os.Setenv(fmt.Sprintf("REPLICA%s_INTERFACE_NAME", "1"), "eth0")).ShouldNot(HaveOccurred())
cfg, err := config.Get("", nil)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.Replicas[0].InterfaceName).Should(Equal("eth0"))
})
})
Context("dhcp server", func() {
It("should enable the dhcp server of replica 1", func() {
Ω(os.Setenv("REPLICA1_URL", "https://foo.bar")).ShouldNot(HaveOccurred())
Ω(os.Setenv(fmt.Sprintf("REPLICA%s_DHCPSERVERENABLED", "1"), "true")).ShouldNot(HaveOccurred())
cfg, err := config.Get("", nil)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.Replicas[0].DHCPServerEnabled).ShouldNot(BeNil())
Ω(*cfg.Replicas[0].DHCPServerEnabled).Should(BeTrue())
})
It("should disable the dhcp server of replica 1", func() {
Ω(os.Setenv("REPLICA1_URL", "https://foo.bar")).ShouldNot(HaveOccurred())
Ω(os.Setenv(fmt.Sprintf("REPLICA%s_DHCPSERVERENABLED", "1"), "false")).ShouldNot(HaveOccurred())
cfg, err := config.Get("", nil)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.Replicas[0].DHCPServerEnabled).ShouldNot(BeNil())
Ω(*cfg.Replicas[0].DHCPServerEnabled).Should(BeFalse())
})
})
})
})
})
func verifyFeatures(cfg *types.Config, value bool) {
Ω(cfg.Features.GeneralSettings).Should(Equal(value))
Ω(cfg.Features.QueryLogConfig).Should(Equal(value))
Ω(cfg.Features.StatsConfig).Should(Equal(value))
Ω(cfg.Features.ClientSettings).Should(Equal(value))
Ω(cfg.Features.Services).Should(Equal(value))
Ω(cfg.Features.Filters).Should(Equal(value))
Ω(cfg.Features.DHCP.ServerConfig).Should(Equal(value))
Ω(cfg.Features.DHCP.StaticLeases).Should(Equal(value))
Ω(cfg.Features.DNS.ServerConfig).Should(Equal(value))
Ω(cfg.Features.DNS.AccessLists).Should(Equal(value))
Ω(cfg.Features.DNS.Rewrites).Should(Equal(value))
}

145
pkg/config/env.go Normal file
View File

@@ -0,0 +1,145 @@
package config
import (
"fmt"
"os"
"strconv"
"strings"
"github.com/bakito/adguardhome-sync/pkg/types"
"github.com/bakito/adguardhome-sync/pkg/utils"
"github.com/caarlos0/env/v10"
)
func handleDeprecatedEnvVars(cfg *types.Config) {
if val, ok := checkDeprecatedEnvVar("RUNONSTART", "RUN_ON_START"); ok {
cfg.RunOnStart, _ = strconv.ParseBool(val)
}
if val, ok := checkDeprecatedEnvVar("API_DARKMODE", "API_DARK_MODE"); ok {
cfg.API.DarkMode, _ = strconv.ParseBool(val)
}
if val, ok := checkDeprecatedEnvVar("FEATURES_GENERALSETTINGS", "FEATURES_GENERAL_SETTINGS"); ok {
cfg.Features.GeneralSettings, _ = strconv.ParseBool(val)
}
if val, ok := checkDeprecatedEnvVar("FEATURES_QUERYLOGCONFIG", "FEATURES_QUERY_LOG_CONFIG"); ok {
cfg.Features.QueryLogConfig, _ = strconv.ParseBool(val)
}
if val, ok := checkDeprecatedEnvVar("FEATURES_STATSCONFIG", "FEATURES_STATS_CONFIG"); ok {
cfg.Features.StatsConfig, _ = strconv.ParseBool(val)
}
if val, ok := checkDeprecatedEnvVar("FEATURES_CLIENTSETTINGS", "FEATURES_CLIENT_SETTINGS"); ok {
cfg.Features.ClientSettings, _ = strconv.ParseBool(val)
}
if val, ok := checkDeprecatedEnvVar("FEATURES_DHCP_SERVERCONFIG", "FEATURES_DHCP_SERVER_CONFIG"); ok {
cfg.Features.DHCP.ServerConfig, _ = strconv.ParseBool(val)
}
if val, ok := checkDeprecatedEnvVar("FEATURES_DHCP_STATICLEASES", "FEATURES_DHCP_STATIC_LEASES"); ok {
cfg.Features.DHCP.StaticLeases, _ = strconv.ParseBool(val)
}
if val, ok := checkDeprecatedEnvVar("FEATURES_DNS_ACCESSLISTS", "FEATURES_DNS_ACCESS_LISTS"); ok {
cfg.Features.DNS.AccessLists, _ = strconv.ParseBool(val)
}
if val, ok := checkDeprecatedEnvVar("FEATURES_DNS_SERVERCONFIG", "FEATURES_DNS_SERVER_CONFIG"); ok {
cfg.Features.DNS.ServerConfig, _ = strconv.ParseBool(val)
}
if cfg.Replica != nil {
if val, ok := checkDeprecatedEnvVar("REPLICA_WEBURL", "REPLICA_WEB_URL"); ok {
cfg.Replica.WebURL = val
}
if val, ok := checkDeprecatedEnvVar("REPLICA_AUTOSETUP", "REPLICA_AUTO_SETUP"); ok {
cfg.Replica.AutoSetup, _ = strconv.ParseBool(val)
}
if val, ok := checkDeprecatedEnvVar("REPLICA_INTERFACENAME", "REPLICA_INTERFACE_NAME"); ok {
cfg.Replica.InterfaceName = val
}
if val, ok := checkDeprecatedEnvVar("REPLICA_DHCPSERVERENABLED", "REPLICA_DHCP_SERVER_ENABLED"); ok {
if b, err := strconv.ParseBool(val); err != nil {
cfg.Replica.DHCPServerEnabled = utils.Ptr(b)
}
}
}
}
func checkDeprecatedEnvVar(oldName string, newName string) (string, bool) {
old, oldOK := os.LookupEnv(oldName)
if oldOK {
logger.With("deprecated", oldName, "replacement", newName).
Warn("Deprecated env variable is used, please use the correct one")
}
new, newOK := os.LookupEnv(newName)
if newOK {
return new, true
}
return old, oldOK
}
func checkDeprecatedReplicaEnvVar(oldPattern string, newPattern string, replicaID int) (string, bool) {
return checkDeprecatedEnvVar(fmt.Sprintf(oldPattern, replicaID), fmt.Sprintf(newPattern, replicaID))
}
// Manually collect replicas from env.
func enrichReplicasFromEnv(initialReplicas []types.AdGuardInstance) ([]types.AdGuardInstance, error) {
var replicas []types.AdGuardInstance
for _, v := range os.Environ() {
if envReplicasURLPattern.MatchString(v) {
sm := envReplicasURLPattern.FindStringSubmatch(v)
id, _ := strconv.Atoi(sm[1])
if id <= 0 {
return nil, fmt.Errorf("numbered replica env variables must have a number id >= 1, got %q", v)
}
if id > len(initialReplicas) {
replicas = append(replicas, types.AdGuardInstance{URL: sm[2]})
} else {
re := initialReplicas[id-1]
re.URL = sm[2]
replicas = append(replicas, re)
}
}
}
if len(replicas) == 0 {
replicas = initialReplicas
}
for i := range replicas {
reID := i + 1
// keep previously set value
replicaDhcpServer := replicas[i].DHCPServerEnabled
replicas[i].DHCPServerEnabled = nil
if err := env.ParseWithOptions(&replicas[i], env.Options{Prefix: fmt.Sprintf("REPLICA%d_", reID)}); err != nil {
return nil, err
}
if replicas[i].DHCPServerEnabled == nil {
replicas[i].DHCPServerEnabled = replicaDhcpServer
}
if val, ok := checkDeprecatedReplicaEnvVar("REPLICA%d_APIPATH", "REPLICA%d_API_PATH", reID); ok {
replicas[i].APIPath = val
}
if val, ok := checkDeprecatedReplicaEnvVar("REPLICA%d_INSECURESKIPVERIFY", "REPLICA%d_INSECURE_SKIP_VERIFY", reID); ok {
replicas[i].InsecureSkipVerify = strings.EqualFold(val, "true")
}
if val, ok := checkDeprecatedReplicaEnvVar("REPLICA%d_AUTOSETUP", "REPLICA%d_AUTO_SETUP", reID); ok {
replicas[i].AutoSetup = strings.EqualFold(val, "true")
}
if val, ok := checkDeprecatedReplicaEnvVar("REPLICA%d_INTERFACENAME", "REPLICA%d_INTERFACE_NAME", reID); ok {
replicas[i].InterfaceName = val
}
if dhcpEnabled, ok := checkDeprecatedReplicaEnvVar("REPLICA%d_DHCPSERVERENABLED", "REPLICA%d_DHCP_SERVER_ENABLED", reID); ok {
if strings.EqualFold(dhcpEnabled, "true") {
replicas[i].DHCPServerEnabled = utils.Ptr(true)
} else if strings.EqualFold(dhcpEnabled, "false") {
replicas[i].DHCPServerEnabled = utils.Ptr(false)
}
}
if replicas[i].APIPath == "" {
replicas[i].APIPath = "/control"
}
}
return replicas, nil
}

25
pkg/config/env_test.go Normal file
View File

@@ -0,0 +1,25 @@
package config
import (
"os"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Config", func() {
Context("env", func() {
Context("enrichReplicasFromEnv", func() {
It("should have the origin URL from the config env var", func() {
_ = os.Setenv("REPLICA0_URL", "https://origin-env:443")
defer func() {
_ = os.Unsetenv("REPLICA0_URL")
}()
_, err := enrichReplicasFromEnv(nil)
Ω(err).Should(HaveOccurred())
Ω(err.Error()).Should(ContainSubstring("numbered replica env variables must have a number id >= 1"))
})
})
})
})

34
pkg/config/file.go Normal file
View File

@@ -0,0 +1,34 @@
package config
import (
"os"
"path/filepath"
"github.com/bakito/adguardhome-sync/pkg/types"
"gopkg.in/yaml.v3"
)
func readFile(cfg *types.Config, path string) error {
if _, err := os.Stat(path); err == nil {
b, err := os.ReadFile(path)
if err != nil {
return err
}
if err := yaml.Unmarshal(b, cfg); err != nil {
return err
}
}
return nil
}
func configFilePath(configFile string) (string, error) {
if configFile == "" {
// Find home directory.
home, err := os.UserHomeDir()
if err != nil {
return "", err
}
return filepath.Join(home, ".adguardhome-sync.yaml"), nil
}
return configFile, nil
}

32
pkg/config/file_test.go Normal file
View File

@@ -0,0 +1,32 @@
package config
import (
"os"
"path/filepath"
"github.com/google/uuid"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Config", func() {
var ()
BeforeEach(func() {
})
Context("configFilePath", func() {
It("should return the same value", func() {
path := uuid.NewString()
result, err := configFilePath(path)
Ω(err).ShouldNot(HaveOccurred())
Ω(result).Should(Equal(path))
})
It("should the file in HOME dir", func() {
home := os.Getenv("HOME")
result, err := configFilePath("")
Ω(err).ShouldNot(HaveOccurred())
Ω(result).Should(Equal(filepath.Join(home, "/.adguardhome-sync.yaml")))
})
})
})

44
pkg/config/flag-names.go Normal file
View File

@@ -0,0 +1,44 @@
package config
const (
FlagCron = "cron"
FlagRunOnStart = "runOnStart"
FlagPrintConfigOnly = "printConfigOnly"
FlagContinueOnError = "continueOnError"
FlagApiPort = "api-port"
FlagApiUsername = "api-username"
FlagApiPassword = "api-password"
FlagApiDarkMode = "api-dark-mode"
FlagFeatureDhcpServerConfig = "feature-dhcp-server-config"
FlagFeatureDhcpStaticLeases = "feature-dhcp-static-leases"
FlagFeatureDnsServerConfig = "feature-dns-server-config"
FlagFeatureDnsAccessLists = "feature-dns-access-lists"
FlagFeatureDnsRewrites = "feature-dns-rewrites"
FlagFeatureGeneral = "feature-general-settings"
FlagFeatureQueryLog = "feature-query-log-config"
FlagFeatureStats = "feature-stats-config"
FlagFeatureClient = "feature-client-settings"
FlagFeatureServices = "feature-services"
FlagFeatureFilters = "feature-filters"
FlagOriginURL = "origin-url"
FlagOriginWebURL = "origin-web-url"
FlagOriginApiPath = "origin-api-path"
FlagOriginUsername = "origin-username"
FlagOriginPassword = "origin-password"
FlagOriginCookie = "origin-cookie"
FlagOriginISV = "origin-insecure-skip-verify"
FlagReplicaURL = "replica-url"
FlagReplicaWebURL = "replica-web-url"
FlagReplicaApiPath = "replica-api-path"
FlagReplicaUsername = "replica-username"
FlagReplicaPassword = "replica-password"
FlagReplicaCookie = "replica-cookie"
FlagReplicaISV = "replica-insecure-skip-verify"
FlagReplicaAutoSetup = "replica-auto-setup"
FlagReplicaInterfaceName = "replica-interface-name"
)

283
pkg/config/flags.go Normal file
View File

@@ -0,0 +1,283 @@
package config
import (
"github.com/bakito/adguardhome-sync/pkg/types"
)
func readFlags(cfg *types.Config, flags Flags) error {
if flags == nil {
return nil
}
fr := &flagReader{
cfg: cfg,
flags: flags,
}
if err := fr.readRootFlags(); err != nil {
return err
}
if err := fr.readApiFlags(); err != nil {
return err
}
if err := fr.readFeatureFlags(); err != nil {
return err
}
if err := fr.readOriginFlags(); err != nil {
return err
}
if err := fr.readReplicaFlags(); err != nil {
return err
}
return nil
}
type flagReader struct {
cfg *types.Config
flags Flags
}
func (fr *flagReader) readReplicaFlags() error {
if err := fr.setStringFlag(FlagReplicaURL, func(cgf *types.Config, value string) {
fr.cfg.Replica.URL = value
}); err != nil {
return err
}
if err := fr.setStringFlag(FlagReplicaWebURL, func(cgf *types.Config, value string) {
fr.cfg.Replica.WebURL = value
}); err != nil {
return err
}
if err := fr.setStringFlag(FlagReplicaApiPath, func(cgf *types.Config, value string) {
fr.cfg.Replica.APIPath = value
}); err != nil {
return err
}
if err := fr.setStringFlag(FlagReplicaUsername, func(cgf *types.Config, value string) {
fr.cfg.Replica.Username = value
}); err != nil {
return err
}
if err := fr.setStringFlag(FlagReplicaPassword, func(cgf *types.Config, value string) {
fr.cfg.Replica.Password = value
}); err != nil {
return err
}
if err := fr.setStringFlag(FlagReplicaCookie, func(cgf *types.Config, value string) {
fr.cfg.Replica.Cookie = value
}); err != nil {
return err
}
if err := fr.setBoolFlag(FlagReplicaISV, func(cgf *types.Config, value bool) {
fr.cfg.Replica.InsecureSkipVerify = value
}); err != nil {
return err
}
if err := fr.setBoolFlag(FlagReplicaAutoSetup, func(cgf *types.Config, value bool) {
fr.cfg.Replica.AutoSetup = value
}); err != nil {
return err
}
if err := fr.setStringFlag(FlagReplicaInterfaceName, func(cgf *types.Config, value string) {
fr.cfg.Replica.InterfaceName = value
}); err != nil {
return err
}
return nil
}
func (fr *flagReader) readOriginFlags() error {
if err := fr.setStringFlag(FlagOriginURL, func(cgf *types.Config, value string) {
fr.cfg.Origin.URL = value
}); err != nil {
return err
}
if err := fr.setStringFlag(FlagOriginWebURL, func(cgf *types.Config, value string) {
fr.cfg.Origin.WebURL = value
}); err != nil {
return err
}
if err := fr.setStringFlag(FlagOriginApiPath, func(cgf *types.Config, value string) {
fr.cfg.Origin.APIPath = value
}); err != nil {
return err
}
if err := fr.setStringFlag(FlagOriginUsername, func(cgf *types.Config, value string) {
fr.cfg.Origin.Username = value
}); err != nil {
return err
}
if err := fr.setStringFlag(FlagOriginPassword, func(cgf *types.Config, value string) {
fr.cfg.Origin.Password = value
}); err != nil {
return err
}
if err := fr.setStringFlag(FlagOriginCookie, func(cgf *types.Config, value string) {
fr.cfg.Origin.Cookie = value
}); err != nil {
return err
}
if err := fr.setBoolFlag(FlagOriginISV, func(cgf *types.Config, value bool) {
fr.cfg.Origin.InsecureSkipVerify = value
}); err != nil {
return err
}
return nil
}
func (fr *flagReader) readFeatureFlags() error {
if err := fr.setBoolFlag(FlagFeatureDhcpServerConfig, func(cgf *types.Config, value bool) {
fr.cfg.Features.DHCP.ServerConfig = value
}); err != nil {
return err
}
if err := fr.setBoolFlag(FlagFeatureDhcpStaticLeases, func(cgf *types.Config, value bool) {
fr.cfg.Features.DHCP.StaticLeases = value
}); err != nil {
return err
}
if err := fr.setBoolFlag(FlagFeatureDnsServerConfig, func(cgf *types.Config, value bool) {
fr.cfg.Features.DNS.ServerConfig = value
}); err != nil {
return err
}
if err := fr.setBoolFlag(FlagFeatureDnsAccessLists, func(cgf *types.Config, value bool) {
fr.cfg.Features.DNS.AccessLists = value
}); err != nil {
return err
}
if err := fr.setBoolFlag(FlagFeatureDnsRewrites, func(cgf *types.Config, value bool) {
fr.cfg.Features.DNS.Rewrites = value
}); err != nil {
return err
}
if err := fr.setBoolFlag(FlagFeatureGeneral, func(cgf *types.Config, value bool) {
fr.cfg.Features.GeneralSettings = value
}); err != nil {
return err
}
if err := fr.setBoolFlag(FlagFeatureQueryLog, func(cgf *types.Config, value bool) {
fr.cfg.Features.QueryLogConfig = value
}); err != nil {
return err
}
if err := fr.setBoolFlag(FlagFeatureStats, func(cgf *types.Config, value bool) {
fr.cfg.Features.StatsConfig = value
}); err != nil {
return err
}
if err := fr.setBoolFlag(FlagFeatureClient, func(cgf *types.Config, value bool) {
fr.cfg.Features.ClientSettings = value
}); err != nil {
return err
}
if err := fr.setBoolFlag(FlagFeatureServices, func(cgf *types.Config, value bool) {
fr.cfg.Features.Services = value
}); err != nil {
return err
}
if err := fr.setBoolFlag(FlagFeatureFilters, func(cgf *types.Config, value bool) {
fr.cfg.Features.Filters = value
}); err != nil {
return err
}
return nil
}
func (fr *flagReader) readApiFlags() (err error) {
if err = fr.setIntFlag(FlagApiPort, func(cgf *types.Config, value int) {
fr.cfg.API.Port = value
}); err != nil {
return
}
if err = fr.setStringFlag(FlagApiUsername, func(cgf *types.Config, value string) {
fr.cfg.API.Username = value
}); err != nil {
return
}
if err = fr.setStringFlag(FlagApiPassword, func(cgf *types.Config, value string) {
fr.cfg.API.Password = value
}); err != nil {
return
}
if err = fr.setBoolFlag(FlagApiDarkMode, func(cgf *types.Config, value bool) {
fr.cfg.API.DarkMode = value
}); err != nil {
return
}
return
}
func (fr *flagReader) readRootFlags() (err error) {
if err = fr.setStringFlag(FlagCron, func(cgf *types.Config, value string) {
fr.cfg.Cron = value
}); err != nil {
return
}
if err = fr.setBoolFlag(FlagRunOnStart, func(cgf *types.Config, value bool) {
fr.cfg.RunOnStart = value
}); err != nil {
return
}
if err = fr.setBoolFlag(FlagPrintConfigOnly, func(cgf *types.Config, value bool) {
fr.cfg.PrintConfigOnly = value
}); err != nil {
return
}
if err = fr.setBoolFlag(FlagContinueOnError, func(cgf *types.Config, value bool) {
fr.cfg.ContinueOnError = value
}); err != nil {
return
}
return
}
type Flags interface {
Changed(name string) bool
GetString(name string) (string, error)
GetInt(name string) (int, error)
GetBool(name string) (bool, error)
}
func (fr *flagReader) setStringFlag(name string, cb callback[string]) (err error) {
if fr.flags.Changed(name) {
if value, err := fr.flags.GetString(name); err != nil {
return err
} else {
cb(fr.cfg, value)
}
}
return nil
}
func (fr *flagReader) setBoolFlag(name string, cb callback[bool]) (err error) {
if fr.flags.Changed(name) {
if value, err := fr.flags.GetBool(name); err != nil {
return err
} else {
cb(fr.cfg, value)
}
}
return nil
}
func (fr *flagReader) setIntFlag(name string, cb callback[int]) (err error) {
if fr.flags.Changed(name) {
if value, err := fr.flags.GetInt(name); err != nil {
return err
} else {
cb(fr.cfg, value)
}
}
return nil
}
type callback[T any] func(cgf *types.Config, value T)

235
pkg/config/flags_test.go Normal file
View File

@@ -0,0 +1,235 @@
package config
import (
"strings"
flagsmock "github.com/bakito/adguardhome-sync/pkg/mocks/flags"
"github.com/bakito/adguardhome-sync/pkg/types"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
gm "go.uber.org/mock/gomock"
)
var _ = Describe("Config", func() {
var (
cfg *types.Config
flags *flagsmock.MockFlags
mockCtrl *gm.Controller
)
BeforeEach(func() {
cfg = &types.Config{
Replica: &types.AdGuardInstance{},
Features: types.Features{
DNS: types.DNS{
AccessLists: true,
ServerConfig: true,
Rewrites: true,
},
DHCP: types.DHCP{
ServerConfig: true,
StaticLeases: true,
},
GeneralSettings: true,
QueryLogConfig: true,
StatsConfig: true,
ClientSettings: true,
Services: true,
Filters: true,
},
}
mockCtrl = gm.NewController(GinkgoT())
flags = flagsmock.NewMockFlags(mockCtrl)
})
AfterEach(func() {
defer mockCtrl.Finish()
})
Context("readFlags", func() {
It("should not change the config with nil flags", func() {
clone := cfg.DeepCopy()
err := readFlags(cfg, nil)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg).Should(Equal(clone))
})
It("should not change the config with no changed flags", func() {
clone := cfg.DeepCopy()
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
err := readFlags(cfg, flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg).Should(Equal(clone))
})
})
Context("readFeatureFlags", func() {
It("should disable all flags", func() {
flags.EXPECT().Changed(gm.Any()).DoAndReturn(func(name string) bool {
return strings.HasPrefix(name, "feature")
}).AnyTimes()
flags.EXPECT().GetBool(gm.Any()).Return(false, nil).AnyTimes()
err := readFlags(cfg, flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.Features).Should(Equal(types.Features{
DNS: types.DNS{
AccessLists: false,
ServerConfig: false,
Rewrites: false,
},
DHCP: types.DHCP{
ServerConfig: false,
StaticLeases: false,
},
GeneralSettings: false,
QueryLogConfig: false,
StatsConfig: false,
ClientSettings: false,
Services: false,
Filters: false,
}))
})
})
Context("readApiFlags", func() {
It("should change all values", func() {
cfg.API = types.API{
Port: 1111,
Username: "2222",
Password: "3333",
DarkMode: false,
}
flags.EXPECT().Changed(gm.Any()).DoAndReturn(func(name string) bool {
return strings.HasPrefix(name, "api")
}).AnyTimes()
flags.EXPECT().GetInt(FlagApiPort).Return(9999, nil)
flags.EXPECT().GetString(FlagApiUsername).Return("aaaa", nil)
flags.EXPECT().GetString(FlagApiPassword).Return("bbbb", nil)
flags.EXPECT().GetBool(FlagApiDarkMode).Return(true, nil)
err := readFlags(cfg, flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.API).Should(Equal(types.API{
Port: 9999,
Username: "aaaa",
Password: "bbbb",
DarkMode: true,
}))
})
})
Context("readRootFlags", func() {
It("should change all values", func() {
cfg.Cron = "*/10 * * * *"
cfg.PrintConfigOnly = false
cfg.ContinueOnError = false
cfg.RunOnStart = false
flags.EXPECT().Changed(FlagCron).Return(true)
flags.EXPECT().Changed(FlagRunOnStart).Return(true)
flags.EXPECT().Changed(FlagPrintConfigOnly).Return(true)
flags.EXPECT().Changed(FlagContinueOnError).Return(true)
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
flags.EXPECT().GetString(FlagCron).Return("*/30 * * * *", nil)
flags.EXPECT().GetBool(FlagRunOnStart).Return(true, nil)
flags.EXPECT().GetBool(FlagPrintConfigOnly).Return(true, nil)
flags.EXPECT().GetBool(FlagContinueOnError).Return(true, nil)
err := readFlags(cfg, flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.Cron).Should(Equal("*/30 * * * *"))
Ω(cfg.RunOnStart).Should(BeTrue())
Ω(cfg.PrintConfigOnly).Should(BeTrue())
Ω(cfg.ContinueOnError).Should(BeTrue())
})
})
Context("readOriginFlags", func() {
It("should change all values", func() {
cfg.Origin = types.AdGuardInstance{
URL: "1",
WebURL: "2",
APIPath: "3",
Username: "4",
Password: "5",
Cookie: "6",
InsecureSkipVerify: false,
}
flags.EXPECT().Changed(FlagOriginURL).Return(true)
flags.EXPECT().Changed(FlagOriginWebURL).Return(true)
flags.EXPECT().Changed(FlagOriginApiPath).Return(true)
flags.EXPECT().Changed(FlagOriginUsername).Return(true)
flags.EXPECT().Changed(FlagOriginPassword).Return(true)
flags.EXPECT().Changed(FlagOriginCookie).Return(true)
flags.EXPECT().Changed(FlagOriginISV).Return(true)
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
flags.EXPECT().GetString(FlagOriginURL).Return("a", nil)
flags.EXPECT().GetString(FlagOriginWebURL).Return("b", nil)
flags.EXPECT().GetString(FlagOriginApiPath).Return("c", nil)
flags.EXPECT().GetString(FlagOriginUsername).Return("d", nil)
flags.EXPECT().GetString(FlagOriginPassword).Return("e", nil)
flags.EXPECT().GetString(FlagOriginCookie).Return("f", nil)
flags.EXPECT().GetBool(FlagOriginISV).Return(true, nil)
err := readFlags(cfg, flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.Origin).Should(Equal(types.AdGuardInstance{
URL: "a",
WebURL: "b",
APIPath: "c",
Username: "d",
Password: "e",
Cookie: "f",
InsecureSkipVerify: true,
}))
})
})
Context("readReplicaFlags", func() {
It("should change all values", func() {
cfg.Replica = &types.AdGuardInstance{
URL: "1",
WebURL: "2",
APIPath: "3",
Username: "4",
Password: "5",
Cookie: "6",
InsecureSkipVerify: false,
AutoSetup: false,
InterfaceName: "7",
}
flags.EXPECT().Changed(FlagReplicaURL).Return(true)
flags.EXPECT().Changed(FlagReplicaWebURL).Return(true)
flags.EXPECT().Changed(FlagReplicaApiPath).Return(true)
flags.EXPECT().Changed(FlagReplicaUsername).Return(true)
flags.EXPECT().Changed(FlagReplicaPassword).Return(true)
flags.EXPECT().Changed(FlagReplicaCookie).Return(true)
flags.EXPECT().Changed(FlagReplicaISV).Return(true)
flags.EXPECT().Changed(FlagReplicaAutoSetup).Return(true)
flags.EXPECT().Changed(FlagReplicaInterfaceName).Return(true)
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
flags.EXPECT().GetString(FlagReplicaURL).Return("a", nil)
flags.EXPECT().GetString(FlagReplicaWebURL).Return("b", nil)
flags.EXPECT().GetString(FlagReplicaApiPath).Return("c", nil)
flags.EXPECT().GetString(FlagReplicaUsername).Return("d", nil)
flags.EXPECT().GetString(FlagReplicaPassword).Return("e", nil)
flags.EXPECT().GetString(FlagReplicaCookie).Return("f", nil)
flags.EXPECT().GetBool(FlagReplicaISV).Return(true, nil)
flags.EXPECT().GetBool(FlagReplicaAutoSetup).Return(true, nil)
flags.EXPECT().GetString(FlagReplicaInterfaceName).Return("g", nil)
err := readFlags(cfg, flags)
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.Replica).Should(Equal(&types.AdGuardInstance{
URL: "a",
WebURL: "b",
APIPath: "c",
Username: "d",
Password: "e",
Cookie: "f",
InsecureSkipVerify: true,
AutoSetup: true,
InterfaceName: "g",
}))
})
})
})

View File

@@ -10,6 +10,7 @@ import (
const ( const (
logHistorySize = 50 logHistorySize = 50
envLogLevel = "LOG_LEVEL" envLogLevel = "LOG_LEVEL"
envLogFormat = "LOG_FORMAT"
) )
var ( var (
@@ -31,14 +32,23 @@ func init() {
} }
} }
format := "console"
if fmt, ok := os.LookupEnv(envLogFormat); ok {
format = fmt
}
cfg := zap.Config{ cfg := zap.Config{
Level: zap.NewAtomicLevelAt(level), Level: zap.NewAtomicLevelAt(level),
Development: false, Development: false,
Encoding: "console", Encoding: format,
EncoderConfig: zap.NewDevelopmentEncoderConfig(), EncoderConfig: zap.NewProductionEncoderConfig(),
OutputPaths: []string{"stdout"}, OutputPaths: []string{"stdout"},
ErrorOutputPaths: []string{"stderr"}, ErrorOutputPaths: []string{"stderr"},
} }
cfg.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
cfg.EncoderConfig.EncodeDuration = zapcore.StringDurationEncoder
cfg.EncoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder
opt := zap.WrapCore(func(c zapcore.Core) zapcore.Core { opt := zap.WrapCore(func(c zapcore.Core) zapcore.Core {
return zapcore.NewTee(c, &logList{ return zapcore.NewTee(c, &logList{
enc: zapcore.NewConsoleEncoder(cfg.EncoderConfig), enc: zapcore.NewConsoleEncoder(cfg.EncoderConfig),

14
pkg/metrics/handler.go Normal file
View File

@@ -0,0 +1,14 @@
package metrics
import (
"github.com/gin-gonic/gin"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func Handler() gin.HandlerFunc {
h := promhttp.Handler()
return func(c *gin.Context) {
h.ServeHTTP(c.Writer, c.Request)
}
}

245
pkg/metrics/metrics.go Normal file
View File

@@ -0,0 +1,245 @@
package metrics
import (
"github.com/bakito/adguardhome-sync/pkg/client/model"
"github.com/bakito/adguardhome-sync/pkg/log"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/exp/constraints"
)
var (
l = log.GetLogger("metrics")
// avgProcessingTime - Average processing time for a DNS query
avgProcessingTime = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "avg_processing_time",
Namespace: "adguard",
Help: "This represent the average processing time for a DNS query in s",
},
[]string{"hostname"},
)
// dnsQueries - Number of DNS queries
dnsQueries = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "num_dns_queries",
Namespace: "adguard",
Help: "Number of DNS queries",
},
[]string{"hostname"},
)
// blockedFiltering - Number of DNS queries blocked
blockedFiltering = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "num_blocked_filtering",
Namespace: "adguard",
Help: "This represent the number of domains blocked",
},
[]string{"hostname"},
)
// parentalFiltering - Number of DNS queries replaced by parental control
parentalFiltering = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "num_replaced_parental",
Namespace: "adguard",
Help: "This represent the number of domains blocked (parental)",
},
[]string{"hostname"},
)
// safeBrowsingFiltering - Number of DNS queries replaced by safe browsing
safeBrowsingFiltering = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "num_replaced_safebrowsing",
Namespace: "adguard",
Help: "This represent the number of domains blocked (safe browsing)",
},
[]string{"hostname"},
)
// safeSearchFiltering - Number of DNS queries replaced by safe search
safeSearchFiltering = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "num_replaced_safesearch",
Namespace: "adguard",
Help: "This represent the number of domains blocked (safe search)",
},
[]string{"hostname"},
)
// topQueries - The number of top queries
topQueries = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "top_queried_domains",
Namespace: "adguard",
Help: "This represent the top queried domains",
},
[]string{"hostname", "domain"},
)
// topBlocked - The number of top domains blocked
topBlocked = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "top_blocked_domains",
Namespace: "adguard",
Help: "This represent the top bloacked domains",
},
[]string{"hostname", "domain"},
)
// topClients - The number of top clients
topClients = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "top_clients",
Namespace: "adguard",
Help: "This represent the top clients",
},
[]string{"hostname", "client"},
)
// queryTypes - The type of DNS Queries (A, AAAA...)
queryTypes = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "query_types",
Namespace: "adguard",
Help: "This represent the DNS query types",
},
[]string{"hostname", "type"},
)
// running - If Adguard is running
running = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "running",
Namespace: "adguard",
Help: "This represent if Adguard is running",
},
[]string{"hostname"},
)
// protectionEnabled - If Adguard protection is enabled
protectionEnabled = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "protection_enabled",
Namespace: "adguard",
Help: "This represent if Adguard Protection is enabled",
},
[]string{"hostname"},
)
)
// Init initializes all Prometheus metrics made available by AdGuard exporter.
func Init() {
initMetric("avg_processing_time", avgProcessingTime)
initMetric("num_dns_queries", dnsQueries)
initMetric("num_blocked_filtering", blockedFiltering)
initMetric("num_replaced_parental", parentalFiltering)
initMetric("num_replaced_safebrowsing", safeBrowsingFiltering)
initMetric("num_replaced_safesearch", safeSearchFiltering)
initMetric("top_queried_domains", topQueries)
initMetric("top_blocked_domains", topBlocked)
initMetric("top_clients", topClients)
initMetric("query_types", queryTypes)
initMetric("running", running)
initMetric("protection_enabled", protectionEnabled)
}
func initMetric(name string, metric *prometheus.GaugeVec) {
prometheus.MustRegister(metric)
l.With("name", name).Info("New Prometheus metric registered")
}
func Update(ims ...InstanceMetrics) {
for _, im := range ims {
update(im)
}
l.Debug("updated")
}
func update(im InstanceMetrics) {
// Status
var isRunning int = 0
if im.Status.Running {
isRunning = 1
}
running.WithLabelValues(im.HostName).Set(float64(isRunning))
var isProtected int = 0
if im.Status.ProtectionEnabled {
isProtected = 1
}
protectionEnabled.WithLabelValues(im.HostName).Set(float64(isProtected))
// Stats
avgProcessingTime.WithLabelValues(im.HostName).Set(safeMetric(im.Stats.AvgProcessingTime))
dnsQueries.WithLabelValues(im.HostName).Set(safeMetric(im.Stats.NumDnsQueries))
blockedFiltering.WithLabelValues(im.HostName).Set(safeMetric(im.Stats.NumBlockedFiltering))
parentalFiltering.WithLabelValues(im.HostName).Set(safeMetric(im.Stats.NumReplacedParental))
safeBrowsingFiltering.WithLabelValues(im.HostName).Set(safeMetric(im.Stats.NumReplacedSafebrowsing))
safeSearchFiltering.WithLabelValues(im.HostName).Set(safeMetric(im.Stats.NumReplacedSafesearch))
if im.Stats.TopQueriedDomains != nil {
for _, tq := range *im.Stats.TopQueriedDomains {
for domain, value := range tq.AdditionalProperties {
topQueries.WithLabelValues(im.HostName, domain).Set(float64(value))
}
}
}
if im.Stats.TopBlockedDomains != nil {
for _, tb := range *im.Stats.TopBlockedDomains {
for domain, value := range tb.AdditionalProperties {
topBlocked.WithLabelValues(im.HostName, domain).Set(float64(value))
}
}
}
if im.Stats.TopClients != nil {
for _, tc := range *im.Stats.TopClients {
for source, value := range tc.AdditionalProperties {
topClients.WithLabelValues(im.HostName, source).Set(float64(value))
}
}
}
// LogQuery
m := make(map[string]int)
if im.QueryLog != nil && im.QueryLog.Data != nil {
logdata := *im.QueryLog.Data
for _, ld := range logdata {
if ld.Answer != nil {
dnsanswer := *ld.Answer
if len(dnsanswer) > 0 {
for _, dnsa := range dnsanswer {
dnsType := *dnsa.Type
m[dnsType] += 1
}
}
}
}
}
for key, value := range m {
queryTypes.WithLabelValues(im.HostName, key).Set(float64(value))
}
}
type InstanceMetrics struct {
HostName string
Status *model.ServerStatus
Stats *model.Stats
QueryLog *model.QueryLog
}
func safeMetric[T Number](v *T) float64 {
if v == nil {
return 0
}
return float64(*v)
}
type Number interface {
constraints.Float | constraints.Integer
}

View File

@@ -1,5 +1,10 @@
// Code generated by MockGen. DO NOT EDIT. // Code generated by MockGen. DO NOT EDIT.
// Source: github.com/bakito/adguardhome-sync/pkg/client (interfaces: Client) // Source: github.com/bakito/adguardhome-sync/pkg/client (interfaces: Client)
//
// Generated by this command:
//
// mockgen -package client -destination pkg/mocks/client/mock.go github.com/bakito/adguardhome-sync/pkg/client Client
//
// Package client is a generated GoMock package. // Package client is a generated GoMock package.
package client package client
@@ -7,8 +12,8 @@ package client
import ( import (
reflect "reflect" reflect "reflect"
types "github.com/bakito/adguardhome-sync/pkg/types" model "github.com/bakito/adguardhome-sync/pkg/client/model"
gomock "github.com/golang/mock/gomock" gomock "go.uber.org/mock/gomock"
) )
// MockClient is a mock of Client interface. // MockClient is a mock of Client interface.
@@ -35,10 +40,10 @@ func (m *MockClient) EXPECT() *MockClientMockRecorder {
} }
// AccessList mocks base method. // AccessList mocks base method.
func (m *MockClient) AccessList() (*types.AccessList, error) { func (m *MockClient) AccessList() (*model.AccessList, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "AccessList") ret := m.ctrl.Call(m, "AccessList")
ret0, _ := ret[0].(*types.AccessList) ret0, _ := ret[0].(*model.AccessList)
ret1, _ := ret[1].(error) ret1, _ := ret[1].(error)
return ret0, ret1 return ret0, ret1
} }
@@ -49,65 +54,52 @@ func (mr *MockClientMockRecorder) AccessList() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AccessList", reflect.TypeOf((*MockClient)(nil).AccessList)) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AccessList", reflect.TypeOf((*MockClient)(nil).AccessList))
} }
// AddClients mocks base method. // AddClient mocks base method.
func (m *MockClient) AddClients(arg0 ...types.Client) error { func (m *MockClient) AddClient(arg0 *model.Client) error {
m.ctrl.T.Helper() m.ctrl.T.Helper()
varargs := []interface{}{} ret := m.ctrl.Call(m, "AddClient", arg0)
for _, a := range arg0 {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "AddClients", varargs...)
ret0, _ := ret[0].(error) ret0, _ := ret[0].(error)
return ret0 return ret0
} }
// AddClients indicates an expected call of AddClients. // AddClient indicates an expected call of AddClient.
func (mr *MockClientMockRecorder) AddClients(arg0 ...interface{}) *gomock.Call { func (mr *MockClientMockRecorder) AddClient(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddClients", reflect.TypeOf((*MockClient)(nil).AddClients), arg0...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddClient", reflect.TypeOf((*MockClient)(nil).AddClient), arg0)
} }
// AddDHCPStaticLeases mocks base method. // AddDHCPStaticLease mocks base method.
func (m *MockClient) AddDHCPStaticLeases(arg0 ...types.Lease) error { func (m *MockClient) AddDHCPStaticLease(arg0 model.DhcpStaticLease) error {
m.ctrl.T.Helper() m.ctrl.T.Helper()
varargs := []interface{}{} ret := m.ctrl.Call(m, "AddDHCPStaticLease", arg0)
for _, a := range arg0 {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "AddDHCPStaticLeases", varargs...)
ret0, _ := ret[0].(error) ret0, _ := ret[0].(error)
return ret0 return ret0
} }
// AddDHCPStaticLeases indicates an expected call of AddDHCPStaticLeases. // AddDHCPStaticLease indicates an expected call of AddDHCPStaticLease.
func (mr *MockClientMockRecorder) AddDHCPStaticLeases(arg0 ...interface{}) *gomock.Call { func (mr *MockClientMockRecorder) AddDHCPStaticLease(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddDHCPStaticLeases", reflect.TypeOf((*MockClient)(nil).AddDHCPStaticLeases), arg0...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddDHCPStaticLease", reflect.TypeOf((*MockClient)(nil).AddDHCPStaticLease), arg0)
} }
// AddFilters mocks base method. // AddFilter mocks base method.
func (m *MockClient) AddFilters(arg0 bool, arg1 ...types.Filter) error { func (m *MockClient) AddFilter(arg0 bool, arg1 model.Filter) error {
m.ctrl.T.Helper() m.ctrl.T.Helper()
varargs := []interface{}{arg0} ret := m.ctrl.Call(m, "AddFilter", arg0, arg1)
for _, a := range arg1 {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "AddFilters", varargs...)
ret0, _ := ret[0].(error) ret0, _ := ret[0].(error)
return ret0 return ret0
} }
// AddFilters indicates an expected call of AddFilters. // AddFilter indicates an expected call of AddFilter.
func (mr *MockClientMockRecorder) AddFilters(arg0 interface{}, arg1 ...interface{}) *gomock.Call { func (mr *MockClientMockRecorder) AddFilter(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
varargs := append([]interface{}{arg0}, arg1...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddFilter", reflect.TypeOf((*MockClient)(nil).AddFilter), arg0, arg1)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddFilters", reflect.TypeOf((*MockClient)(nil).AddFilters), varargs...)
} }
// AddRewriteEntries mocks base method. // AddRewriteEntries mocks base method.
func (m *MockClient) AddRewriteEntries(arg0 ...types.RewriteEntry) error { func (m *MockClient) AddRewriteEntries(arg0 ...model.RewriteEntry) error {
m.ctrl.T.Helper() m.ctrl.T.Helper()
varargs := []interface{}{} varargs := []any{}
for _, a := range arg0 { for _, a := range arg0 {
varargs = append(varargs, a) varargs = append(varargs, a)
} }
@@ -117,16 +109,31 @@ func (m *MockClient) AddRewriteEntries(arg0 ...types.RewriteEntry) error {
} }
// AddRewriteEntries indicates an expected call of AddRewriteEntries. // AddRewriteEntries indicates an expected call of AddRewriteEntries.
func (mr *MockClientMockRecorder) AddRewriteEntries(arg0 ...interface{}) *gomock.Call { func (mr *MockClientMockRecorder) AddRewriteEntries(arg0 ...any) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddRewriteEntries", reflect.TypeOf((*MockClient)(nil).AddRewriteEntries), arg0...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddRewriteEntries", reflect.TypeOf((*MockClient)(nil).AddRewriteEntries), arg0...)
} }
// BlockedServicesSchedule mocks base method.
func (m *MockClient) BlockedServicesSchedule() (*model.BlockedServicesSchedule, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "BlockedServicesSchedule")
ret0, _ := ret[0].(*model.BlockedServicesSchedule)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// BlockedServicesSchedule indicates an expected call of BlockedServicesSchedule.
func (mr *MockClientMockRecorder) BlockedServicesSchedule() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockedServicesSchedule", reflect.TypeOf((*MockClient)(nil).BlockedServicesSchedule))
}
// Clients mocks base method. // Clients mocks base method.
func (m *MockClient) Clients() (*types.Clients, error) { func (m *MockClient) Clients() (*model.Clients, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Clients") ret := m.ctrl.Call(m, "Clients")
ret0, _ := ret[0].(*types.Clients) ret0, _ := ret[0].(*model.Clients)
ret1, _ := ret[1].(error) ret1, _ := ret[1].(error)
return ret0, ret1 return ret0, ret1
} }
@@ -137,26 +144,11 @@ func (mr *MockClientMockRecorder) Clients() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Clients", reflect.TypeOf((*MockClient)(nil).Clients)) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Clients", reflect.TypeOf((*MockClient)(nil).Clients))
} }
// DHCPServerConfig mocks base method.
func (m *MockClient) DHCPServerConfig() (*types.DHCPServerConfig, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "DHCPServerConfig")
ret0, _ := ret[0].(*types.DHCPServerConfig)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// DHCPServerConfig indicates an expected call of DHCPServerConfig.
func (mr *MockClientMockRecorder) DHCPServerConfig() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DHCPServerConfig", reflect.TypeOf((*MockClient)(nil).DHCPServerConfig))
}
// DNSConfig mocks base method. // DNSConfig mocks base method.
func (m *MockClient) DNSConfig() (*types.DNSConfig, error) { func (m *MockClient) DNSConfig() (*model.DNSConfig, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "DNSConfig") ret := m.ctrl.Call(m, "DNSConfig")
ret0, _ := ret[0].(*types.DNSConfig) ret0, _ := ret[0].(*model.DNSConfig)
ret1, _ := ret[1].(error) ret1, _ := ret[1].(error)
return ret0, ret1 return ret0, ret1
} }
@@ -167,65 +159,52 @@ func (mr *MockClientMockRecorder) DNSConfig() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DNSConfig", reflect.TypeOf((*MockClient)(nil).DNSConfig)) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DNSConfig", reflect.TypeOf((*MockClient)(nil).DNSConfig))
} }
// DeleteClients mocks base method. // DeleteClient mocks base method.
func (m *MockClient) DeleteClients(arg0 ...types.Client) error { func (m *MockClient) DeleteClient(arg0 *model.Client) error {
m.ctrl.T.Helper() m.ctrl.T.Helper()
varargs := []interface{}{} ret := m.ctrl.Call(m, "DeleteClient", arg0)
for _, a := range arg0 {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "DeleteClients", varargs...)
ret0, _ := ret[0].(error) ret0, _ := ret[0].(error)
return ret0 return ret0
} }
// DeleteClients indicates an expected call of DeleteClients. // DeleteClient indicates an expected call of DeleteClient.
func (mr *MockClientMockRecorder) DeleteClients(arg0 ...interface{}) *gomock.Call { func (mr *MockClientMockRecorder) DeleteClient(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteClients", reflect.TypeOf((*MockClient)(nil).DeleteClients), arg0...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteClient", reflect.TypeOf((*MockClient)(nil).DeleteClient), arg0)
} }
// DeleteDHCPStaticLeases mocks base method. // DeleteDHCPStaticLease mocks base method.
func (m *MockClient) DeleteDHCPStaticLeases(arg0 ...types.Lease) error { func (m *MockClient) DeleteDHCPStaticLease(arg0 model.DhcpStaticLease) error {
m.ctrl.T.Helper() m.ctrl.T.Helper()
varargs := []interface{}{} ret := m.ctrl.Call(m, "DeleteDHCPStaticLease", arg0)
for _, a := range arg0 {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "DeleteDHCPStaticLeases", varargs...)
ret0, _ := ret[0].(error) ret0, _ := ret[0].(error)
return ret0 return ret0
} }
// DeleteDHCPStaticLeases indicates an expected call of DeleteDHCPStaticLeases. // DeleteDHCPStaticLease indicates an expected call of DeleteDHCPStaticLease.
func (mr *MockClientMockRecorder) DeleteDHCPStaticLeases(arg0 ...interface{}) *gomock.Call { func (mr *MockClientMockRecorder) DeleteDHCPStaticLease(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteDHCPStaticLeases", reflect.TypeOf((*MockClient)(nil).DeleteDHCPStaticLeases), arg0...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteDHCPStaticLease", reflect.TypeOf((*MockClient)(nil).DeleteDHCPStaticLease), arg0)
} }
// DeleteFilters mocks base method. // DeleteFilter mocks base method.
func (m *MockClient) DeleteFilters(arg0 bool, arg1 ...types.Filter) error { func (m *MockClient) DeleteFilter(arg0 bool, arg1 model.Filter) error {
m.ctrl.T.Helper() m.ctrl.T.Helper()
varargs := []interface{}{arg0} ret := m.ctrl.Call(m, "DeleteFilter", arg0, arg1)
for _, a := range arg1 {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "DeleteFilters", varargs...)
ret0, _ := ret[0].(error) ret0, _ := ret[0].(error)
return ret0 return ret0
} }
// DeleteFilters indicates an expected call of DeleteFilters. // DeleteFilter indicates an expected call of DeleteFilter.
func (mr *MockClientMockRecorder) DeleteFilters(arg0 interface{}, arg1 ...interface{}) *gomock.Call { func (mr *MockClientMockRecorder) DeleteFilter(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
varargs := append([]interface{}{arg0}, arg1...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteFilter", reflect.TypeOf((*MockClient)(nil).DeleteFilter), arg0, arg1)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteFilters", reflect.TypeOf((*MockClient)(nil).DeleteFilters), varargs...)
} }
// DeleteRewriteEntries mocks base method. // DeleteRewriteEntries mocks base method.
func (m *MockClient) DeleteRewriteEntries(arg0 ...types.RewriteEntry) error { func (m *MockClient) DeleteRewriteEntries(arg0 ...model.RewriteEntry) error {
m.ctrl.T.Helper() m.ctrl.T.Helper()
varargs := []interface{}{} varargs := []any{}
for _, a := range arg0 { for _, a := range arg0 {
varargs = append(varargs, a) varargs = append(varargs, a)
} }
@@ -235,16 +214,31 @@ func (m *MockClient) DeleteRewriteEntries(arg0 ...types.RewriteEntry) error {
} }
// DeleteRewriteEntries indicates an expected call of DeleteRewriteEntries. // DeleteRewriteEntries indicates an expected call of DeleteRewriteEntries.
func (mr *MockClientMockRecorder) DeleteRewriteEntries(arg0 ...interface{}) *gomock.Call { func (mr *MockClientMockRecorder) DeleteRewriteEntries(arg0 ...any) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteRewriteEntries", reflect.TypeOf((*MockClient)(nil).DeleteRewriteEntries), arg0...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteRewriteEntries", reflect.TypeOf((*MockClient)(nil).DeleteRewriteEntries), arg0...)
} }
// DhcpConfig mocks base method.
func (m *MockClient) DhcpConfig() (*model.DhcpStatus, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "DhcpConfig")
ret0, _ := ret[0].(*model.DhcpStatus)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// DhcpConfig indicates an expected call of DhcpConfig.
func (mr *MockClientMockRecorder) DhcpConfig() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DhcpConfig", reflect.TypeOf((*MockClient)(nil).DhcpConfig))
}
// Filtering mocks base method. // Filtering mocks base method.
func (m *MockClient) Filtering() (*types.FilteringStatus, error) { func (m *MockClient) Filtering() (*model.FilterStatus, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Filtering") ret := m.ctrl.Call(m, "Filtering")
ret0, _ := ret[0].(*types.FilteringStatus) ret0, _ := ret[0].(*model.FilterStatus)
ret1, _ := ret[1].(error) ret1, _ := ret[1].(error)
return ret0, ret1 return ret0, ret1
} }
@@ -284,11 +278,41 @@ func (mr *MockClientMockRecorder) Parental() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Parental", reflect.TypeOf((*MockClient)(nil).Parental)) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Parental", reflect.TypeOf((*MockClient)(nil).Parental))
} }
// ProfileInfo mocks base method.
func (m *MockClient) ProfileInfo() (*model.ProfileInfo, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ProfileInfo")
ret0, _ := ret[0].(*model.ProfileInfo)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// ProfileInfo indicates an expected call of ProfileInfo.
func (mr *MockClientMockRecorder) ProfileInfo() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProfileInfo", reflect.TypeOf((*MockClient)(nil).ProfileInfo))
}
// QueryLog mocks base method.
func (m *MockClient) QueryLog(arg0 int) (*model.QueryLog, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "QueryLog", arg0)
ret0, _ := ret[0].(*model.QueryLog)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// QueryLog indicates an expected call of QueryLog.
func (mr *MockClientMockRecorder) QueryLog(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryLog", reflect.TypeOf((*MockClient)(nil).QueryLog), arg0)
}
// QueryLogConfig mocks base method. // QueryLogConfig mocks base method.
func (m *MockClient) QueryLogConfig() (*types.QueryLogConfig, error) { func (m *MockClient) QueryLogConfig() (*model.QueryLogConfigWithIgnored, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "QueryLogConfig") ret := m.ctrl.Call(m, "QueryLogConfig")
ret0, _ := ret[0].(*types.QueryLogConfig) ret0, _ := ret[0].(*model.QueryLogConfigWithIgnored)
ret1, _ := ret[1].(error) ret1, _ := ret[1].(error)
return ret0, ret1 return ret0, ret1
} }
@@ -308,16 +332,16 @@ func (m *MockClient) RefreshFilters(arg0 bool) error {
} }
// RefreshFilters indicates an expected call of RefreshFilters. // RefreshFilters indicates an expected call of RefreshFilters.
func (mr *MockClientMockRecorder) RefreshFilters(arg0 interface{}) *gomock.Call { func (mr *MockClientMockRecorder) RefreshFilters(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RefreshFilters", reflect.TypeOf((*MockClient)(nil).RefreshFilters), arg0) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RefreshFilters", reflect.TypeOf((*MockClient)(nil).RefreshFilters), arg0)
} }
// RewriteList mocks base method. // RewriteList mocks base method.
func (m *MockClient) RewriteList() (*types.RewriteEntries, error) { func (m *MockClient) RewriteList() (*model.RewriteEntries, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "RewriteList") ret := m.ctrl.Call(m, "RewriteList")
ret0, _ := ret[0].(*types.RewriteEntries) ret0, _ := ret[0].(*model.RewriteEntries)
ret1, _ := ret[1].(error) ret1, _ := ret[1].(error)
return ret0, ret1 return ret0, ret1
} }
@@ -343,38 +367,23 @@ func (mr *MockClientMockRecorder) SafeBrowsing() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SafeBrowsing", reflect.TypeOf((*MockClient)(nil).SafeBrowsing)) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SafeBrowsing", reflect.TypeOf((*MockClient)(nil).SafeBrowsing))
} }
// SafeSearch mocks base method. // SafeSearchConfig mocks base method.
func (m *MockClient) SafeSearch() (bool, error) { func (m *MockClient) SafeSearchConfig() (*model.SafeSearchConfig, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SafeSearch") ret := m.ctrl.Call(m, "SafeSearchConfig")
ret0, _ := ret[0].(bool) ret0, _ := ret[0].(*model.SafeSearchConfig)
ret1, _ := ret[1].(error) ret1, _ := ret[1].(error)
return ret0, ret1 return ret0, ret1
} }
// SafeSearch indicates an expected call of SafeSearch. // SafeSearchConfig indicates an expected call of SafeSearchConfig.
func (mr *MockClientMockRecorder) SafeSearch() *gomock.Call { func (mr *MockClientMockRecorder) SafeSearchConfig() *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SafeSearch", reflect.TypeOf((*MockClient)(nil).SafeSearch)) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SafeSearchConfig", reflect.TypeOf((*MockClient)(nil).SafeSearchConfig))
}
// Services mocks base method.
func (m *MockClient) Services() (types.Services, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Services")
ret0, _ := ret[0].(types.Services)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Services indicates an expected call of Services.
func (mr *MockClientMockRecorder) Services() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Services", reflect.TypeOf((*MockClient)(nil).Services))
} }
// SetAccessList mocks base method. // SetAccessList mocks base method.
func (m *MockClient) SetAccessList(arg0 *types.AccessList) error { func (m *MockClient) SetAccessList(arg0 *model.AccessList) error {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetAccessList", arg0) ret := m.ctrl.Call(m, "SetAccessList", arg0)
ret0, _ := ret[0].(error) ret0, _ := ret[0].(error)
@@ -382,13 +391,27 @@ func (m *MockClient) SetAccessList(arg0 *types.AccessList) error {
} }
// SetAccessList indicates an expected call of SetAccessList. // SetAccessList indicates an expected call of SetAccessList.
func (mr *MockClientMockRecorder) SetAccessList(arg0 interface{}) *gomock.Call { func (mr *MockClientMockRecorder) SetAccessList(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetAccessList", reflect.TypeOf((*MockClient)(nil).SetAccessList), arg0) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetAccessList", reflect.TypeOf((*MockClient)(nil).SetAccessList), arg0)
} }
// SetBlockedServicesSchedule mocks base method.
func (m *MockClient) SetBlockedServicesSchedule(arg0 *model.BlockedServicesSchedule) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetBlockedServicesSchedule", arg0)
ret0, _ := ret[0].(error)
return ret0
}
// SetBlockedServicesSchedule indicates an expected call of SetBlockedServicesSchedule.
func (mr *MockClientMockRecorder) SetBlockedServicesSchedule(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetBlockedServicesSchedule", reflect.TypeOf((*MockClient)(nil).SetBlockedServicesSchedule), arg0)
}
// SetCustomRules mocks base method. // SetCustomRules mocks base method.
func (m *MockClient) SetCustomRules(arg0 types.UserRules) error { func (m *MockClient) SetCustomRules(arg0 *[]string) error {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetCustomRules", arg0) ret := m.ctrl.Call(m, "SetCustomRules", arg0)
ret0, _ := ret[0].(error) ret0, _ := ret[0].(error)
@@ -396,27 +419,13 @@ func (m *MockClient) SetCustomRules(arg0 types.UserRules) error {
} }
// SetCustomRules indicates an expected call of SetCustomRules. // SetCustomRules indicates an expected call of SetCustomRules.
func (mr *MockClientMockRecorder) SetCustomRules(arg0 interface{}) *gomock.Call { func (mr *MockClientMockRecorder) SetCustomRules(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetCustomRules", reflect.TypeOf((*MockClient)(nil).SetCustomRules), arg0) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetCustomRules", reflect.TypeOf((*MockClient)(nil).SetCustomRules), arg0)
} }
// SetDHCPServerConfig mocks base method.
func (m *MockClient) SetDHCPServerConfig(arg0 *types.DHCPServerConfig) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetDHCPServerConfig", arg0)
ret0, _ := ret[0].(error)
return ret0
}
// SetDHCPServerConfig indicates an expected call of SetDHCPServerConfig.
func (mr *MockClientMockRecorder) SetDHCPServerConfig(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetDHCPServerConfig", reflect.TypeOf((*MockClient)(nil).SetDHCPServerConfig), arg0)
}
// SetDNSConfig mocks base method. // SetDNSConfig mocks base method.
func (m *MockClient) SetDNSConfig(arg0 *types.DNSConfig) error { func (m *MockClient) SetDNSConfig(arg0 *model.DNSConfig) error {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetDNSConfig", arg0) ret := m.ctrl.Call(m, "SetDNSConfig", arg0)
ret0, _ := ret[0].(error) ret0, _ := ret[0].(error)
@@ -424,41 +433,69 @@ func (m *MockClient) SetDNSConfig(arg0 *types.DNSConfig) error {
} }
// SetDNSConfig indicates an expected call of SetDNSConfig. // SetDNSConfig indicates an expected call of SetDNSConfig.
func (mr *MockClientMockRecorder) SetDNSConfig(arg0 interface{}) *gomock.Call { func (mr *MockClientMockRecorder) SetDNSConfig(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetDNSConfig", reflect.TypeOf((*MockClient)(nil).SetDNSConfig), arg0) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetDNSConfig", reflect.TypeOf((*MockClient)(nil).SetDNSConfig), arg0)
} }
// SetQueryLogConfig mocks base method. // SetDhcpConfig mocks base method.
func (m *MockClient) SetQueryLogConfig(arg0 bool, arg1 float64, arg2 bool) error { func (m *MockClient) SetDhcpConfig(arg0 *model.DhcpStatus) error {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetQueryLogConfig", arg0, arg1, arg2) ret := m.ctrl.Call(m, "SetDhcpConfig", arg0)
ret0, _ := ret[0].(error)
return ret0
}
// SetDhcpConfig indicates an expected call of SetDhcpConfig.
func (mr *MockClientMockRecorder) SetDhcpConfig(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetDhcpConfig", reflect.TypeOf((*MockClient)(nil).SetDhcpConfig), arg0)
}
// SetProfileInfo mocks base method.
func (m *MockClient) SetProfileInfo(arg0 *model.ProfileInfo) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetProfileInfo", arg0)
ret0, _ := ret[0].(error)
return ret0
}
// SetProfileInfo indicates an expected call of SetProfileInfo.
func (mr *MockClientMockRecorder) SetProfileInfo(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetProfileInfo", reflect.TypeOf((*MockClient)(nil).SetProfileInfo), arg0)
}
// SetQueryLogConfig mocks base method.
func (m *MockClient) SetQueryLogConfig(arg0 *model.QueryLogConfigWithIgnored) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetQueryLogConfig", arg0)
ret0, _ := ret[0].(error) ret0, _ := ret[0].(error)
return ret0 return ret0
} }
// SetQueryLogConfig indicates an expected call of SetQueryLogConfig. // SetQueryLogConfig indicates an expected call of SetQueryLogConfig.
func (mr *MockClientMockRecorder) SetQueryLogConfig(arg0, arg1, arg2 interface{}) *gomock.Call { func (mr *MockClientMockRecorder) SetQueryLogConfig(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetQueryLogConfig", reflect.TypeOf((*MockClient)(nil).SetQueryLogConfig), arg0, arg1, arg2) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetQueryLogConfig", reflect.TypeOf((*MockClient)(nil).SetQueryLogConfig), arg0)
} }
// SetServices mocks base method. // SetSafeSearchConfig mocks base method.
func (m *MockClient) SetServices(arg0 types.Services) error { func (m *MockClient) SetSafeSearchConfig(arg0 *model.SafeSearchConfig) error {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetServices", arg0) ret := m.ctrl.Call(m, "SetSafeSearchConfig", arg0)
ret0, _ := ret[0].(error) ret0, _ := ret[0].(error)
return ret0 return ret0
} }
// SetServices indicates an expected call of SetServices. // SetSafeSearchConfig indicates an expected call of SetSafeSearchConfig.
func (mr *MockClientMockRecorder) SetServices(arg0 interface{}) *gomock.Call { func (mr *MockClientMockRecorder) SetSafeSearchConfig(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetServices", reflect.TypeOf((*MockClient)(nil).SetServices), arg0) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetSafeSearchConfig", reflect.TypeOf((*MockClient)(nil).SetSafeSearchConfig), arg0)
} }
// SetStatsConfig mocks base method. // SetStatsConfig mocks base method.
func (m *MockClient) SetStatsConfig(arg0 float64) error { func (m *MockClient) SetStatsConfig(arg0 *model.GetStatsConfigResponse) error {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetStatsConfig", arg0) ret := m.ctrl.Call(m, "SetStatsConfig", arg0)
ret0, _ := ret[0].(error) ret0, _ := ret[0].(error)
@@ -466,7 +503,7 @@ func (m *MockClient) SetStatsConfig(arg0 float64) error {
} }
// SetStatsConfig indicates an expected call of SetStatsConfig. // SetStatsConfig indicates an expected call of SetStatsConfig.
func (mr *MockClientMockRecorder) SetStatsConfig(arg0 interface{}) *gomock.Call { func (mr *MockClientMockRecorder) SetStatsConfig(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetStatsConfig", reflect.TypeOf((*MockClient)(nil).SetStatsConfig), arg0) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetStatsConfig", reflect.TypeOf((*MockClient)(nil).SetStatsConfig), arg0)
} }
@@ -485,11 +522,26 @@ func (mr *MockClientMockRecorder) Setup() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Setup", reflect.TypeOf((*MockClient)(nil).Setup)) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Setup", reflect.TypeOf((*MockClient)(nil).Setup))
} }
// Stats mocks base method.
func (m *MockClient) Stats() (*model.Stats, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Stats")
ret0, _ := ret[0].(*model.Stats)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Stats indicates an expected call of Stats.
func (mr *MockClientMockRecorder) Stats() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stats", reflect.TypeOf((*MockClient)(nil).Stats))
}
// StatsConfig mocks base method. // StatsConfig mocks base method.
func (m *MockClient) StatsConfig() (*types.IntervalConfig, error) { func (m *MockClient) StatsConfig() (*model.GetStatsConfigResponse, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "StatsConfig") ret := m.ctrl.Call(m, "StatsConfig")
ret0, _ := ret[0].(*types.IntervalConfig) ret0, _ := ret[0].(*model.GetStatsConfigResponse)
ret1, _ := ret[1].(error) ret1, _ := ret[1].(error)
return ret0, ret1 return ret0, ret1
} }
@@ -501,10 +553,10 @@ func (mr *MockClientMockRecorder) StatsConfig() *gomock.Call {
} }
// Status mocks base method. // Status mocks base method.
func (m *MockClient) Status() (*types.Status, error) { func (m *MockClient) Status() (*model.ServerStatus, error) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Status") ret := m.ctrl.Call(m, "Status")
ret0, _ := ret[0].(*types.Status) ret0, _ := ret[0].(*model.ServerStatus)
ret1, _ := ret[1].(error) ret1, _ := ret[1].(error)
return ret0, ret1 return ret0, ret1
} }
@@ -516,7 +568,7 @@ func (mr *MockClientMockRecorder) Status() *gomock.Call {
} }
// ToggleFiltering mocks base method. // ToggleFiltering mocks base method.
func (m *MockClient) ToggleFiltering(arg0 bool, arg1 float64) error { func (m *MockClient) ToggleFiltering(arg0 bool, arg1 int) error {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ToggleFiltering", arg0, arg1) ret := m.ctrl.Call(m, "ToggleFiltering", arg0, arg1)
ret0, _ := ret[0].(error) ret0, _ := ret[0].(error)
@@ -524,7 +576,7 @@ func (m *MockClient) ToggleFiltering(arg0 bool, arg1 float64) error {
} }
// ToggleFiltering indicates an expected call of ToggleFiltering. // ToggleFiltering indicates an expected call of ToggleFiltering.
func (mr *MockClientMockRecorder) ToggleFiltering(arg0, arg1 interface{}) *gomock.Call { func (mr *MockClientMockRecorder) ToggleFiltering(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ToggleFiltering", reflect.TypeOf((*MockClient)(nil).ToggleFiltering), arg0, arg1) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ToggleFiltering", reflect.TypeOf((*MockClient)(nil).ToggleFiltering), arg0, arg1)
} }
@@ -538,7 +590,7 @@ func (m *MockClient) ToggleParental(arg0 bool) error {
} }
// ToggleParental indicates an expected call of ToggleParental. // ToggleParental indicates an expected call of ToggleParental.
func (mr *MockClientMockRecorder) ToggleParental(arg0 interface{}) *gomock.Call { func (mr *MockClientMockRecorder) ToggleParental(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ToggleParental", reflect.TypeOf((*MockClient)(nil).ToggleParental), arg0) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ToggleParental", reflect.TypeOf((*MockClient)(nil).ToggleParental), arg0)
} }
@@ -552,7 +604,7 @@ func (m *MockClient) ToggleProtection(arg0 bool) error {
} }
// ToggleProtection indicates an expected call of ToggleProtection. // ToggleProtection indicates an expected call of ToggleProtection.
func (mr *MockClientMockRecorder) ToggleProtection(arg0 interface{}) *gomock.Call { func (mr *MockClientMockRecorder) ToggleProtection(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ToggleProtection", reflect.TypeOf((*MockClient)(nil).ToggleProtection), arg0) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ToggleProtection", reflect.TypeOf((*MockClient)(nil).ToggleProtection), arg0)
} }
@@ -566,58 +618,35 @@ func (m *MockClient) ToggleSafeBrowsing(arg0 bool) error {
} }
// ToggleSafeBrowsing indicates an expected call of ToggleSafeBrowsing. // ToggleSafeBrowsing indicates an expected call of ToggleSafeBrowsing.
func (mr *MockClientMockRecorder) ToggleSafeBrowsing(arg0 interface{}) *gomock.Call { func (mr *MockClientMockRecorder) ToggleSafeBrowsing(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ToggleSafeBrowsing", reflect.TypeOf((*MockClient)(nil).ToggleSafeBrowsing), arg0) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ToggleSafeBrowsing", reflect.TypeOf((*MockClient)(nil).ToggleSafeBrowsing), arg0)
} }
// ToggleSafeSearch mocks base method. // UpdateClient mocks base method.
func (m *MockClient) ToggleSafeSearch(arg0 bool) error { func (m *MockClient) UpdateClient(arg0 *model.Client) error {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ToggleSafeSearch", arg0) ret := m.ctrl.Call(m, "UpdateClient", arg0)
ret0, _ := ret[0].(error) ret0, _ := ret[0].(error)
return ret0 return ret0
} }
// ToggleSafeSearch indicates an expected call of ToggleSafeSearch. // UpdateClient indicates an expected call of UpdateClient.
func (mr *MockClientMockRecorder) ToggleSafeSearch(arg0 interface{}) *gomock.Call { func (mr *MockClientMockRecorder) UpdateClient(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ToggleSafeSearch", reflect.TypeOf((*MockClient)(nil).ToggleSafeSearch), arg0) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateClient", reflect.TypeOf((*MockClient)(nil).UpdateClient), arg0)
} }
// UpdateClients mocks base method. // UpdateFilter mocks base method.
func (m *MockClient) UpdateClients(arg0 ...types.Client) error { func (m *MockClient) UpdateFilter(arg0 bool, arg1 model.Filter) error {
m.ctrl.T.Helper() m.ctrl.T.Helper()
varargs := []interface{}{} ret := m.ctrl.Call(m, "UpdateFilter", arg0, arg1)
for _, a := range arg0 {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "UpdateClients", varargs...)
ret0, _ := ret[0].(error) ret0, _ := ret[0].(error)
return ret0 return ret0
} }
// UpdateClients indicates an expected call of UpdateClients. // UpdateFilter indicates an expected call of UpdateFilter.
func (mr *MockClientMockRecorder) UpdateClients(arg0 ...interface{}) *gomock.Call { func (mr *MockClientMockRecorder) UpdateFilter(arg0, arg1 any) *gomock.Call {
mr.mock.ctrl.T.Helper() mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateClients", reflect.TypeOf((*MockClient)(nil).UpdateClients), arg0...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateFilter", reflect.TypeOf((*MockClient)(nil).UpdateFilter), arg0, arg1)
}
// UpdateFilters mocks base method.
func (m *MockClient) UpdateFilters(arg0 bool, arg1 ...types.Filter) error {
m.ctrl.T.Helper()
varargs := []interface{}{arg0}
for _, a := range arg1 {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "UpdateFilters", varargs...)
ret0, _ := ret[0].(error)
return ret0
}
// UpdateFilters indicates an expected call of UpdateFilters.
func (mr *MockClientMockRecorder) UpdateFilters(arg0 interface{}, arg1 ...interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
varargs := append([]interface{}{arg0}, arg1...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateFilters", reflect.TypeOf((*MockClient)(nil).UpdateFilters), varargs...)
} }

98
pkg/mocks/flags/mock.go Normal file
View File

@@ -0,0 +1,98 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: github.com/bakito/adguardhome-sync/pkg/config (interfaces: Flags)
//
// Generated by this command:
//
// mockgen -package client -destination pkg/mocks/flags/mock.go github.com/bakito/adguardhome-sync/pkg/config Flags
//
// Package client is a generated GoMock package.
package client
import (
reflect "reflect"
gomock "go.uber.org/mock/gomock"
)
// MockFlags is a mock of Flags interface.
type MockFlags struct {
ctrl *gomock.Controller
recorder *MockFlagsMockRecorder
}
// MockFlagsMockRecorder is the mock recorder for MockFlags.
type MockFlagsMockRecorder struct {
mock *MockFlags
}
// NewMockFlags creates a new mock instance.
func NewMockFlags(ctrl *gomock.Controller) *MockFlags {
mock := &MockFlags{ctrl: ctrl}
mock.recorder = &MockFlagsMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockFlags) EXPECT() *MockFlagsMockRecorder {
return m.recorder
}
// Changed mocks base method.
func (m *MockFlags) Changed(arg0 string) bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Changed", arg0)
ret0, _ := ret[0].(bool)
return ret0
}
// Changed indicates an expected call of Changed.
func (mr *MockFlagsMockRecorder) Changed(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Changed", reflect.TypeOf((*MockFlags)(nil).Changed), arg0)
}
// GetBool mocks base method.
func (m *MockFlags) GetBool(arg0 string) (bool, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetBool", arg0)
ret0, _ := ret[0].(bool)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetBool indicates an expected call of GetBool.
func (mr *MockFlagsMockRecorder) GetBool(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBool", reflect.TypeOf((*MockFlags)(nil).GetBool), arg0)
}
// GetInt mocks base method.
func (m *MockFlags) GetInt(arg0 string) (int, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetInt", arg0)
ret0, _ := ret[0].(int)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetInt indicates an expected call of GetInt.
func (mr *MockFlagsMockRecorder) GetInt(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetInt", reflect.TypeOf((*MockFlags)(nil).GetInt), arg0)
}
// GetString mocks base method.
func (m *MockFlags) GetString(arg0 string) (string, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetString", arg0)
ret0, _ := ret[0].(string)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// GetString indicates an expected call of GetString.
func (mr *MockFlagsMockRecorder) GetString(arg0 any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetString", reflect.TypeOf((*MockFlags)(nil).GetString), arg0)
}

275
pkg/sync/action-general.go Normal file
View File

@@ -0,0 +1,275 @@
package sync
import (
"github.com/bakito/adguardhome-sync/pkg/client"
"github.com/bakito/adguardhome-sync/pkg/client/model"
"github.com/bakito/adguardhome-sync/pkg/utils"
"go.uber.org/zap"
)
var (
actionProfileInfo = func(ac *actionContext) error {
if pro, err := ac.client.ProfileInfo(); err != nil {
return err
} else if merged := pro.ShouldSyncFor(ac.origin.profileInfo); merged != nil {
return ac.client.SetProfileInfo(merged)
}
return nil
}
actionProtection = func(ac *actionContext) error {
if ac.origin.status.ProtectionEnabled != ac.replicaStatus.ProtectionEnabled {
return ac.client.ToggleProtection(ac.origin.status.ProtectionEnabled)
}
return nil
}
actionParental = func(ac *actionContext) error {
if rp, err := ac.client.Parental(); err != nil {
return err
} else if ac.origin.parental != rp {
return ac.client.ToggleParental(ac.origin.parental)
}
return nil
}
actionSafeSearchConfig = func(ac *actionContext) error {
if ssc, err := ac.client.SafeSearchConfig(); err != nil {
return err
} else if !ac.origin.safeSearch.Equals(ssc) {
return ac.client.SetSafeSearchConfig(ac.origin.safeSearch)
}
return nil
}
actionSafeBrowsing = func(ac *actionContext) error {
if rs, err := ac.client.SafeBrowsing(); err != nil {
return err
} else if ac.origin.safeBrowsing != rs {
if err = ac.client.ToggleSafeBrowsing(ac.origin.safeBrowsing); err != nil {
return err
}
}
return nil
}
actionQueryLogConfig = func(ac *actionContext) error {
qlc, err := ac.client.QueryLogConfig()
if err != nil {
return err
}
if !ac.origin.queryLogConfig.Equals(qlc) {
return ac.client.SetQueryLogConfig(ac.origin.queryLogConfig)
}
return nil
}
actionStatsConfig = func(ac *actionContext) error {
sc, err := ac.client.StatsConfig()
if err != nil {
return err
}
if !sc.Equals(ac.origin.statsConfig) {
return ac.client.SetStatsConfig(ac.origin.statsConfig)
}
return nil
}
actionDNSRewrites = func(ac *actionContext) error {
replicaRewrites, err := ac.client.RewriteList()
if err != nil {
return err
}
a, r, d := replicaRewrites.Merge(ac.origin.rewrites)
if err = ac.client.DeleteRewriteEntries(r...); err != nil {
return err
}
if err = ac.client.AddRewriteEntries(a...); err != nil {
return err
}
for _, dupl := range d {
ac.rl.With("domain", dupl.Domain, "answer", dupl.Answer).Warn("Skipping duplicated rewrite from source")
}
return nil
}
actionFilters = func(ac *actionContext) error {
rf, err := ac.client.Filtering()
if err != nil {
return err
}
if err = syncFilterType(ac.rl, ac.origin.filters.Filters, rf.Filters, false, ac.client, ac.continueOnError); err != nil {
return err
}
if err = syncFilterType(ac.rl, ac.origin.filters.WhitelistFilters, rf.WhitelistFilters, true, ac.client, ac.continueOnError); err != nil {
return err
}
if utils.PtrToString(ac.origin.filters.UserRules) != utils.PtrToString(rf.UserRules) {
return ac.client.SetCustomRules(ac.origin.filters.UserRules)
}
if ac.origin.filters.Enabled != rf.Enabled || ac.origin.filters.Interval != rf.Interval {
return ac.client.ToggleFiltering(*ac.origin.filters.Enabled, *ac.origin.filters.Interval)
}
return nil
}
actionBlockedServicesSchedule = func(ac *actionContext) error {
rbss, err := ac.client.BlockedServicesSchedule()
if err != nil {
return err
}
if !ac.origin.blockedServicesSchedule.Equals(rbss) {
return ac.client.SetBlockedServicesSchedule(ac.origin.blockedServicesSchedule)
}
return nil
}
actionClientSettings = func(ac *actionContext) error {
rc, err := ac.client.Clients()
if err != nil {
return err
}
a, u, r := rc.Merge(ac.origin.clients)
for _, client := range r {
if err := ac.client.DeleteClient(client); err != nil {
ac.rl.With("client-name", client.Name, "error", err).Error("error deleting client setting")
if !ac.continueOnError {
return err
}
}
}
for _, client := range a {
if err := ac.client.AddClient(client); err != nil {
ac.rl.With("client-name", client.Name, "error", err).Error("error adding client setting")
if !ac.continueOnError {
return err
}
}
}
for _, client := range u {
if err := ac.client.UpdateClient(client); err != nil {
ac.rl.With("client-name", client.Name, "error", err).Error("error updating client setting")
if !ac.continueOnError {
return err
}
}
}
return nil
}
actionDNSAccessLists = func(ac *actionContext) error {
al, err := ac.client.AccessList()
if err != nil {
return err
}
if !al.Equals(ac.origin.accessList) {
return ac.client.SetAccessList(ac.origin.accessList)
}
return nil
}
actionDNSServerConfig = func(ac *actionContext) error {
dc, err := ac.client.DNSConfig()
if err != nil {
return err
}
dc.Sanitize(ac.rl)
if !dc.Equals(ac.origin.dnsConfig) {
if err = ac.client.SetDNSConfig(ac.origin.dnsConfig); err != nil {
return err
}
}
return nil
}
actionDHCPServerConfig = func(ac *actionContext) error {
if ac.origin.dhcpServerConfig.HasConfig() {
sc, err := ac.client.DhcpConfig()
if err != nil {
return err
}
origClone := ac.origin.dhcpServerConfig.Clone()
if ac.replica.InterfaceName != "" {
// overwrite interface name
origClone.InterfaceName = utils.Ptr(ac.replica.InterfaceName)
}
if ac.replica.DHCPServerEnabled != nil {
// overwrite dhcp enabled
origClone.Enabled = ac.replica.DHCPServerEnabled
}
if !sc.CleanAndEquals(origClone) {
return ac.client.SetDhcpConfig(origClone)
}
}
return nil
}
actionDHCPStaticLeases = func(ac *actionContext) error {
sc, err := ac.client.DhcpConfig()
if err != nil {
return err
}
a, r := model.MergeDhcpStaticLeases(sc.StaticLeases, ac.origin.dhcpServerConfig.StaticLeases)
for _, lease := range r {
if err := ac.client.DeleteDHCPStaticLease(lease); err != nil {
ac.rl.With("hostname", lease.Hostname, "error", err).Error("error deleting dhcp static lease")
if !ac.continueOnError {
return err
}
}
}
for _, lease := range a {
if err := ac.client.AddDHCPStaticLease(lease); err != nil {
ac.rl.With("hostname", lease.Hostname, "error", err).Error("error adding dhcp static lease")
if !ac.continueOnError {
return err
}
}
}
return nil
}
)
func syncFilterType(rl *zap.SugaredLogger, of *[]model.Filter, rFilters *[]model.Filter, whitelist bool, replica client.Client, continueOnError bool) error {
fa, fu, fd := model.MergeFilters(rFilters, of)
for _, f := range fd {
if err := replica.DeleteFilter(whitelist, f); err != nil {
rl.With("filter", f.Name, "url", f.Url, "whitelist", whitelist, "error", err).Error("error deleting filter")
if !continueOnError {
return err
}
}
}
for _, f := range fa {
if err := replica.AddFilter(whitelist, f); err != nil {
rl.With("filter", f.Name, "url", f.Url, "whitelist", whitelist, "error", err).Error("error adding filter")
if !continueOnError {
return err
}
}
}
for _, f := range fu {
if err := replica.UpdateFilter(whitelist, f); err != nil {
rl.With("filter", f.Name, "url", f.Url, "whitelist", whitelist, "error", err).Error("error updating filter")
if !continueOnError {
return err
}
}
}
if len(fa) > 0 || len(fu) > 0 {
if err := replica.RefreshFilters(whitelist); err != nil {
return err
}
}
return nil
}

103
pkg/sync/action.go Normal file
View File

@@ -0,0 +1,103 @@
package sync
import (
"github.com/bakito/adguardhome-sync/pkg/client"
"github.com/bakito/adguardhome-sync/pkg/client/model"
"github.com/bakito/adguardhome-sync/pkg/types"
"go.uber.org/zap"
)
func setupActions(cfg *types.Config) (actions []syncAction) {
if cfg.Features.GeneralSettings {
actions = append(actions,
action("profile info", actionProfileInfo),
action("protection", actionProtection),
action("parental", actionParental),
action("safe search config", actionSafeSearchConfig),
action("safe browsing", actionSafeBrowsing),
)
}
if cfg.Features.QueryLogConfig {
actions = append(actions,
action("query log config", actionQueryLogConfig),
)
}
if cfg.Features.StatsConfig {
actions = append(actions,
action("stats config", actionStatsConfig),
)
}
if cfg.Features.DNS.Rewrites {
actions = append(actions,
action("DNS rewrites", actionDNSRewrites),
)
}
if cfg.Features.Filters {
actions = append(actions,
action("actionFilters", actionFilters),
)
}
if cfg.Features.Services {
actions = append(actions,
action("blocked services schedule", actionBlockedServicesSchedule),
)
}
if cfg.Features.ClientSettings {
actions = append(actions,
action("client settings", actionClientSettings),
)
}
if cfg.Features.DNS.AccessLists {
actions = append(actions,
action("DNS access lists", actionDNSAccessLists),
)
}
if cfg.Features.DNS.ServerConfig {
actions = append(actions,
action("DNS server config", actionDNSServerConfig),
)
}
if cfg.Features.DHCP.ServerConfig {
actions = append(actions,
action("DHCP server config", actionDHCPServerConfig),
)
}
if cfg.Features.DHCP.StaticLeases {
actions = append(actions,
action("DHCP static leases", actionDHCPStaticLeases),
)
}
return actions
}
type syncAction interface {
sync(ac *actionContext) error
name() string
}
type actionContext struct {
rl *zap.SugaredLogger
origin *origin
client client.Client
replicaStatus *model.ServerStatus
continueOnError bool
replica types.AdGuardInstance
}
type defaultAction struct {
myName string
doSync func(ac *actionContext) error
}
func action(name string, f func(ac *actionContext) error) syncAction {
return &defaultAction{myName: name, doSync: f}
}
func (d *defaultAction) sync(ac *actionContext) error {
return d.doSync(ac)
}
func (d *defaultAction) name() string {
return d.myName
}

View File

@@ -15,6 +15,7 @@ import (
"time" "time"
"github.com/bakito/adguardhome-sync/pkg/log" "github.com/bakito/adguardhome-sync/pkg/log"
"github.com/bakito/adguardhome-sync/pkg/metrics"
"github.com/bakito/adguardhome-sync/version" "github.com/bakito/adguardhome-sync/version"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -33,9 +34,10 @@ func (w *worker) handleSync(c *gin.Context) {
func (w *worker) handleRoot(c *gin.Context) { func (w *worker) handleRoot(c *gin.Context) {
c.HTML(http.StatusOK, "index.html", map[string]interface{}{ c.HTML(http.StatusOK, "index.html", map[string]interface{}{
"DarkMode": w.cfg.API.DarkMode, "DarkMode": w.cfg.API.DarkMode,
"Version": version.Version, "Version": version.Version,
"Build": version.Build, "Build": version.Build,
"SyncStatus": w.status(),
}, },
) )
} }
@@ -48,6 +50,10 @@ func (w *worker) handleLogs(c *gin.Context) {
c.Data(http.StatusOK, "text/plain", []byte(strings.Join(log.Logs(), ""))) c.Data(http.StatusOK, "text/plain", []byte(strings.Join(log.Logs(), "")))
} }
func (w *worker) handleStatus(c *gin.Context) {
c.JSON(http.StatusOK, w.status())
}
func (w *worker) listenAndServe() { func (w *worker) listenAndServe() {
l.With("port", w.cfg.API.Port).Info("Starting API server") l.With("port", w.cfg.API.Port).Info("Starting API server")
@@ -69,8 +75,14 @@ func (w *worker) listenAndServe() {
r.SetHTMLTemplate(template.Must(template.New("index.html").Parse(string(index)))) r.SetHTMLTemplate(template.Must(template.New("index.html").Parse(string(index))))
r.POST("/api/v1/sync", w.handleSync) r.POST("/api/v1/sync", w.handleSync)
r.GET("/api/v1/logs", w.handleLogs) r.GET("/api/v1/logs", w.handleLogs)
r.GET("/api/v1/status", w.handleStatus)
r.GET("/favicon.ico", w.handleFavicon) r.GET("/favicon.ico", w.handleFavicon)
r.GET("/", w.handleRoot) r.GET("/", w.handleRoot)
if w.cfg.API.Metrics.Enabled {
r.GET("/metrics", metrics.Handler())
go w.startScraping()
}
go func() { go func() {
if err := httpServer.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) { if err := httpServer.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) {
@@ -95,7 +107,7 @@ func (w *worker) listenAndServe() {
l.Fatal("os.Kill - terminating...") l.Fatal("os.Kill - terminating...")
}() }()
gracefullCtx, cancelShutdown := context.WithTimeout(context.Background(), 5*time.Second) gracefulCtx, cancelShutdown := context.WithTimeout(context.Background(), 5*time.Second)
defer cancelShutdown() defer cancelShutdown()
if w.cron != nil { if w.cron != nil {
@@ -103,7 +115,7 @@ func (w *worker) listenAndServe() {
w.cron.Stop() w.cron.Stop()
} }
if err := httpServer.Shutdown(gracefullCtx); err != nil { if err := httpServer.Shutdown(gracefulCtx); err != nil {
l.With("error", err).Error("Shutdown error") l.With("error", err).Error("Shutdown error")
defer os.Exit(1) defer os.Exit(1)
} else { } else {
@@ -115,3 +127,17 @@ func (w *worker) listenAndServe() {
defer os.Exit(0) defer os.Exit(0)
} }
type syncStatus struct {
SyncRunning bool `json:"syncRunning"`
Origin replicaStatus `json:"origin"`
Replicas []replicaStatus `json:"replicas"`
}
type replicaStatus struct {
Host string `json:"host"`
URL string `json:"url"`
Status string `json:"status"`
Error string `json:"error,omitempty"`
ProtectionEnabled *bool `json:"protection_enabled"`
}

View File

@@ -1,4 +1,4 @@
<html> <html lang="en">
<head> <head>
<title>AdGuardHome sync</title> <title>AdGuardHome sync</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.6.0.min.js"> <script type="text/javascript" src="https://code.jquery.com/jquery-3.6.0.min.js">
@@ -18,21 +18,35 @@
$('#logs').html(data); $('#logs').html(data);
} }
); );
$.get("api/v1/status", {}, function (status) {
$('#origin').removeClass(function (index, className) {
return (className.match(/(^|\s)btn-\S+/g) || []).join(' ');
}).addClass("btn-" + status.origin.status).attr('title', status.origin.error);
status.replicas.forEach(function (replica, i) {
$('#replica_' + i).removeClass(function (index, className) {
return (className.match(/(^|\s)btn-\S+/g) || []).join(' ');
}).addClass("btn-" + replica.status).attr('title', replica.error);
});
}
);
}); });
$("#sync").click(function () { $("#sync").click(function () {
$.post("api/v1/sync", {}, function (data) { $.post("api/v1/sync", {}, function (data) {
}); });
$("#showLogs").click();
}); });
$("#showLogs").click() $("#showLogs").click();
}); });
</script> </script>
<link rel="shortcut icon" href="favicon.ico"> <link rel="shortcut icon" href="favicon.ico">
</head> </head>
<body> <body>
<div class="container-fluid px-4"> <div class="container-fluid px-4">
<div class="row"> <div class="row">
<p class="h1">AdGuardHome sync <p class="h1">
<p class="h6">{{ .Version }} ({{ .Build }})</p></p> AdGuardHome sync
<p class="h6">{{ .Version }} ({{ .Build }})</p>
</p>
</div> </div>
<div class="row"> <div class="row">
<div class="col"> <div class="col">
@@ -41,6 +55,18 @@
<input class="btn btn-secondary" type="button" id="showLogs" value="Update Logs"/> <input class="btn btn-secondary" type="button" id="showLogs" value="Update Logs"/>
</div> </div>
</div> </div>
<div class="col col-md-auto">
<div class="float-right">
<a href="{{ .SyncStatus.Origin.URL }}" target="_blank" class="btn btn-{{ .SyncStatus.Origin.Status }}"
type="button" id="origin"
{{ if .SyncStatus.Origin.Error }} title="{{ .SyncStatus.Origin.Error }}" {{ end }}>Origin {{ .SyncStatus.Origin.Host }}</a>
{{ range $i, $r := .SyncStatus.Replicas }}
<a href="{{ $r.URL }}" target="_blank" class="btn btn-{{ $r.Status }}"
type="button" id="replica_{{ $i }}"
{{ if $r.Error }} title="{{ $r.Error }}" {{ end }} >Replica {{ $r.Host }}</a>
{{ end }}
</div>
</div>
</div> </div>
<div class="row mt-3"> <div class="row mt-3">
<div class="col-12"> <div class="col-12">
@@ -49,4 +75,4 @@
</div> </div>
</div> </div>
</body> </body>
</html> </html>

50
pkg/sync/scrape.go Normal file
View File

@@ -0,0 +1,50 @@
package sync
import (
"time"
"github.com/bakito/adguardhome-sync/pkg/metrics"
"github.com/bakito/adguardhome-sync/pkg/types"
)
func (w *worker) startScraping() {
metrics.Init()
if w.cfg.API.Metrics.ScrapeInterval == 0 {
w.cfg.API.Metrics.ScrapeInterval = 30 * time.Second
}
if w.cfg.API.Metrics.QueryLogLimit == 0 {
w.cfg.API.Metrics.QueryLogLimit = 10_000
}
l.With(
"scrape-interval", w.cfg.API.Metrics.ScrapeInterval,
"query-log-limit", w.cfg.API.Metrics.QueryLogLimit,
).Info("setup metrics")
w.scrape()
for range time.Tick(w.cfg.API.Metrics.ScrapeInterval) {
w.scrape()
}
}
func (w *worker) scrape() {
var ims []metrics.InstanceMetrics
ims = append(ims, w.getMetrics(w.cfg.Origin))
for _, replica := range w.cfg.Replicas {
ims = append(ims, w.getMetrics(replica))
}
metrics.Update(ims...)
}
func (w *worker) getMetrics(inst types.AdGuardInstance) (im metrics.InstanceMetrics) {
client, err := w.createClient(inst)
if err != nil {
l.With("error", err, "url", w.cfg.Origin.URL).Error("Error creating origin client")
return
}
im.HostName = inst.Host
im.Status, _ = client.Status()
im.Stats, _ = client.Stats()
im.QueryLog, _ = client.QueryLog(w.cfg.API.Metrics.QueryLogLimit)
return
}

View File

@@ -3,11 +3,15 @@ package sync
import ( import (
"errors" "errors"
"fmt" "fmt"
"runtime"
"sort"
"time" "time"
"github.com/bakito/adguardhome-sync/pkg/client" "github.com/bakito/adguardhome-sync/pkg/client"
"github.com/bakito/adguardhome-sync/pkg/client/model"
"github.com/bakito/adguardhome-sync/pkg/log" "github.com/bakito/adguardhome-sync/pkg/log"
"github.com/bakito/adguardhome-sync/pkg/types" "github.com/bakito/adguardhome-sync/pkg/types"
"github.com/bakito/adguardhome-sync/pkg/utils"
"github.com/bakito/adguardhome-sync/pkg/versions" "github.com/bakito/adguardhome-sync/pkg/versions"
"github.com/bakito/adguardhome-sync/version" "github.com/bakito/adguardhome-sync/version"
"github.com/robfig/cron/v3" "github.com/robfig/cron/v3"
@@ -26,7 +30,13 @@ func Sync(cfg *types.Config) error {
return fmt.Errorf("no replicas configured") return fmt.Errorf("no replicas configured")
} }
l.With("version", version.Version, "build", version.Build).Info("AdGuardHome sync") l.With(
"version", version.Version,
"build", version.Build,
"os", runtime.GOOS,
"arch", runtime.GOARCH,
).Info("AdGuardHome sync")
cfg.Log(l)
cfg.Features.LogDisabled(l) cfg.Features.LogDisabled(l)
cfg.Origin.AutoSetup = false cfg.Origin.AutoSetup = false
@@ -80,6 +90,57 @@ type worker struct {
running bool running bool
cron *cron.Cron cron *cron.Cron
createClient func(instance types.AdGuardInstance) (client.Client, error) createClient func(instance types.AdGuardInstance) (client.Client, error)
actions []syncAction
}
func (w *worker) status() *syncStatus {
syncStatus := &syncStatus{
Origin: w.getStatus(w.cfg.Origin),
}
for _, replica := range w.cfg.Replicas {
st := w.getStatus(replica)
if w.running {
st.Status = "info"
}
syncStatus.Replicas = append(syncStatus.Replicas, st)
}
sort.Slice(syncStatus.Replicas, func(i, j int) bool {
return syncStatus.Replicas[i].Host < syncStatus.Replicas[j].Host
})
syncStatus.SyncRunning = w.running
return syncStatus
}
func (w *worker) getStatus(inst types.AdGuardInstance) (st replicaStatus) {
st = replicaStatus{Host: inst.WebHost, URL: inst.WebURL}
oc, err := w.createClient(inst)
if err != nil {
l.With("error", err, "url", w.cfg.Origin.URL).Error("Error creating origin client")
st.Status = "danger"
st.Error = err.Error()
return
}
sl := l.With("from", inst.WebHost)
status, err := oc.Status()
if err != nil {
if errors.Is(err, client.ErrSetupNeeded) {
st.Status = "warning"
st.Error = err.Error()
return
}
sl.With("error", err).Error("Error getting origin status")
st.Status = "danger"
st.Error = err.Error()
return
}
st.Status = "success"
st.ProtectionEnabled = utils.Ptr(status.ProtectionEnabled)
return
} }
func (w *worker) sync() { func (w *worker) sync() {
@@ -112,12 +173,18 @@ func (w *worker) sync() {
sl.With("version", o.status.Version).Info("Connected to origin") sl.With("version", o.status.Version).Info("Connected to origin")
o.profileInfo, err = oc.ProfileInfo()
if err != nil {
sl.With("error", err).Error("Error getting profileInfo info")
return
}
o.parental, err = oc.Parental() o.parental, err = oc.Parental()
if err != nil { if err != nil {
sl.With("error", err).Error("Error getting parental status") sl.With("error", err).Error("Error getting parental status")
return return
} }
o.safeSearch, err = oc.SafeSearch() o.safeSearch, err = oc.SafeSearchConfig()
if err != nil { if err != nil {
sl.With("error", err).Error("Error getting safe search status") sl.With("error", err).Error("Error getting safe search status")
return return
@@ -134,15 +201,15 @@ func (w *worker) sync() {
return return
} }
o.services, err = oc.Services() o.blockedServicesSchedule, err = oc.BlockedServicesSchedule()
if err != nil { if err != nil {
sl.With("error", err).Error("Error getting origin services") sl.With("error", err).Error("Error getting origin blocked services schedule")
return return
} }
o.filters, err = oc.Filtering() o.filters, err = oc.Filtering()
if err != nil { if err != nil {
sl.With("error", err).Error("Error getting origin filters") sl.With("error", err).Error("Error getting origin actionFilters")
return return
} }
o.clients, err = oc.Clients() o.clients, err = oc.Clients()
@@ -173,12 +240,16 @@ func (w *worker) sync() {
return return
} }
o.dhcpServerConfig, err = oc.DHCPServerConfig() if w.cfg.Features.DHCP.ServerConfig || w.cfg.Features.DHCP.StaticLeases {
if err != nil { o.dhcpServerConfig, err = oc.DhcpConfig()
sl.With("error", err).Error("Error getting dhcp server config") if err != nil {
return sl.With("error", err).Error("Error getting dhcp server config")
return
}
} }
w.actions = setupActions(w.cfg)
replicas := w.cfg.UniqueReplicas() replicas := w.cfg.UniqueReplicas()
for _, replica := range replicas { for _, replica := range replicas {
w.syncTo(sl, o, replica) w.syncTo(sl, o, replica)
@@ -195,76 +266,44 @@ func (w *worker) syncTo(l *zap.SugaredLogger, o *origin, replica types.AdGuardIn
rl := l.With("to", rc.Host()) rl := l.With("to", rc.Host())
rl.Info("Start sync") rl.Info("Start sync")
rs, err := w.statusWithSetup(rl, replica, rc) replicaStatus, err := w.statusWithSetup(rl, replica, rc)
if err != nil { if err != nil {
rl.With("error", err).Error("Error getting replica status") rl.With("error", err).Error("Error getting replica status")
return return
} }
rl.With("version", rs.Version).Info("Connected to replica") rl.With("version", replicaStatus.Version).Info("Connected to replica")
if versions.IsNewerThan(versions.MinAgh, rs.Version) { if versions.IsNewerThan(versions.MinAgh, replicaStatus.Version) {
rl.With("error", err, "version", rs.Version).Errorf("Replica AdGuard Home version must be >= %s", versions.MinAgh) rl.With("error", err, "version", replicaStatus.Version).Errorf("Replica AdGuard Home version must be >= %s", versions.MinAgh)
return return
} }
if versions.IsSame(rs.Version, versions.IncompatibleAPI) { if o.status.Version != replicaStatus.Version {
rl.With("error", err, "version", rs.Version).Errorf("Replica AdGuard Home runs with an incompatible API - Please ugrade to version %s or newer", versions.FixedIncompatibleAPI) rl.With("originVersion", o.status.Version, "replicaVersion", replicaStatus.Version).Warn("Versions do not match")
return
} }
if o.status.Version != rs.Version { ac := &actionContext{
rl.With("originVersion", o.status.Version, "replicaVersion", rs.Version).Warn("Versions do not match") continueOnError: w.cfg.ContinueOnError,
rl: rl,
origin: o,
replicaStatus: replicaStatus,
client: rc,
replica: replica,
} }
for _, action := range w.actions {
err = w.syncGeneralSettings(o, rs, rc) if err := action.sync(ac); err != nil {
if err != nil { rl.With("error", err).Errorf("Error syncing %s", action.name())
rl.With("error", err).Error("Error syncing general settings") if !w.cfg.ContinueOnError {
return return
} }
}
err = w.syncConfigs(o, rc)
if err != nil {
rl.With("error", err).Error("Error syncing configs")
return
}
err = w.syncRewrites(rl, o.rewrites, rc)
if err != nil {
rl.With("error", err).Error("Error syncing rewrites")
return
}
err = w.syncFilters(o.filters, rc)
if err != nil {
rl.With("error", err).Error("Error syncing filters")
return
}
err = w.syncServices(o.services, rc)
if err != nil {
rl.With("error", err).Error("Error syncing services")
return
}
if err = w.syncClients(o.clients, rc); err != nil {
rl.With("error", err).Error("Error syncing clients")
return
}
if err = w.syncDNS(o.accessList, o.dnsConfig, rc); err != nil {
rl.With("error", err).Error("Error syncing dns")
return
}
if err = w.syncDHCPServer(o.dhcpServerConfig, rc, replica); err != nil {
rl.With("error", err).Error("Error syncing dns")
return
} }
rl.Info("Sync done") rl.Info("Sync done")
} }
func (w *worker) statusWithSetup(rl *zap.SugaredLogger, replica types.AdGuardInstance, rc client.Client) (*types.Status, error) { func (w *worker) statusWithSetup(rl *zap.SugaredLogger, replica types.AdGuardInstance, rc client.Client) (*model.ServerStatus, error) {
rs, err := rc.Status() rs, err := rc.Status()
if err != nil { if err != nil {
if replica.AutoSetup && errors.Is(err, client.ErrSetupNeeded) { if replica.AutoSetup && errors.Is(err, client.ErrSetupNeeded) {
@@ -279,244 +318,19 @@ func (w *worker) statusWithSetup(rl *zap.SugaredLogger, replica types.AdGuardIns
return rs, err return rs, err
} }
func (w *worker) syncServices(os types.Services, replica client.Client) error {
if w.cfg.Features.Services {
rs, err := replica.Services()
if err != nil {
return err
}
if !os.Equals(rs) {
if err := replica.SetServices(os); err != nil {
return err
}
}
}
return nil
}
func (w *worker) syncFilters(of *types.FilteringStatus, replica client.Client) error {
if w.cfg.Features.Filters {
rf, err := replica.Filtering()
if err != nil {
return err
}
if err = w.syncFilterType(of.Filters, rf.Filters, false, replica); err != nil {
return err
}
if err = w.syncFilterType(of.WhitelistFilters, rf.WhitelistFilters, true, replica); err != nil {
return err
}
if of.UserRules.String() != rf.UserRules.String() {
return replica.SetCustomRules(of.UserRules)
}
if of.Enabled != rf.Enabled || of.Interval != rf.Interval {
if err = replica.ToggleFiltering(of.Enabled, of.Interval); err != nil {
return err
}
}
}
return nil
}
func (w *worker) syncFilterType(of types.Filters, rFilters types.Filters, whitelist bool, replica client.Client) error {
fa, fu, fd := rFilters.Merge(of)
if err := replica.DeleteFilters(whitelist, fd...); err != nil {
return err
}
if err := replica.AddFilters(whitelist, fa...); err != nil {
return err
}
if err := replica.UpdateFilters(whitelist, fu...); err != nil {
return err
}
if len(fa) > 0 || len(fu) > 0 {
if err := replica.RefreshFilters(whitelist); err != nil {
return err
}
}
return nil
}
func (w *worker) syncRewrites(rl *zap.SugaredLogger, or *types.RewriteEntries, replica client.Client) error {
if w.cfg.Features.DNS.Rewrites {
replicaRewrites, err := replica.RewriteList()
if err != nil {
return err
}
a, r, d := replicaRewrites.Merge(or)
if err = replica.DeleteRewriteEntries(r...); err != nil {
return err
}
if err = replica.AddRewriteEntries(a...); err != nil {
return err
}
for _, dupl := range d {
rl.With("domain", dupl.Domain, "answer", dupl.Answer).Warn("Skipping duplicated rewrite from source")
}
}
return nil
}
func (w *worker) syncClients(oc *types.Clients, replica client.Client) error {
if w.cfg.Features.ClientSettings {
rc, err := replica.Clients()
if err != nil {
return err
}
a, u, r := rc.Merge(oc)
if err = replica.DeleteClients(r...); err != nil {
return err
}
if err = replica.AddClients(a...); err != nil {
return err
}
if err = replica.UpdateClients(u...); err != nil {
return err
}
}
return nil
}
func (w *worker) syncGeneralSettings(o *origin, rs *types.Status, replica client.Client) error {
if w.cfg.Features.GeneralSettings {
if o.status.ProtectionEnabled != rs.ProtectionEnabled {
if err := replica.ToggleProtection(o.status.ProtectionEnabled); err != nil {
return err
}
}
if rp, err := replica.Parental(); err != nil {
return err
} else if o.parental != rp {
if err = replica.ToggleParental(o.parental); err != nil {
return err
}
}
if rs, err := replica.SafeSearch(); err != nil {
return err
} else if o.safeSearch != rs {
if err = replica.ToggleSafeSearch(o.safeSearch); err != nil {
return err
}
}
if rs, err := replica.SafeBrowsing(); err != nil {
return err
} else if o.safeBrowsing != rs {
if err = replica.ToggleSafeBrowsing(o.safeBrowsing); err != nil {
return err
}
}
}
return nil
}
func (w *worker) syncConfigs(o *origin, rc client.Client) error {
if w.cfg.Features.QueryLogConfig {
qlc, err := rc.QueryLogConfig()
if err != nil {
return err
}
if !o.queryLogConfig.Equals(qlc) {
if err = rc.SetQueryLogConfig(o.queryLogConfig.Enabled, o.queryLogConfig.Interval, o.queryLogConfig.AnonymizeClientIP); err != nil {
return err
}
}
}
if w.cfg.Features.StatsConfig {
sc, err := rc.StatsConfig()
if err != nil {
return err
}
if o.statsConfig.Interval != sc.Interval {
if err = rc.SetStatsConfig(o.statsConfig.Interval); err != nil {
return err
}
}
}
return nil
}
func (w *worker) syncDNS(oal *types.AccessList, odc *types.DNSConfig, rc client.Client) error {
if w.cfg.Features.DNS.AccessLists {
al, err := rc.AccessList()
if err != nil {
return err
}
if !al.Equals(oal) {
if err = rc.SetAccessList(oal); err != nil {
return err
}
}
}
if w.cfg.Features.DNS.ServerConfig {
dc, err := rc.DNSConfig()
if err != nil {
return err
}
if !dc.Equals(odc) {
if err = rc.SetDNSConfig(odc); err != nil {
return err
}
}
}
return nil
}
func (w *worker) syncDHCPServer(osc *types.DHCPServerConfig, rc client.Client, replica types.AdGuardInstance) error {
sc, err := rc.DHCPServerConfig()
if w.cfg.Features.DHCP.ServerConfig {
if err != nil {
return err
}
origClone := osc.Clone()
if replica.InterfaceName != "" {
// overwrite interface name
origClone.InterfaceName = replica.InterfaceName
}
if !sc.Equals(origClone) {
if err = rc.SetDHCPServerConfig(origClone); err != nil {
return err
}
}
}
if w.cfg.Features.DHCP.StaticLeases {
a, r := sc.StaticLeases.Merge(osc.StaticLeases)
if err = rc.DeleteDHCPStaticLeases(r...); err != nil {
return err
}
if err = rc.AddDHCPStaticLeases(a...); err != nil {
return err
}
}
return nil
}
type origin struct { type origin struct {
status *types.Status status *model.ServerStatus
rewrites *types.RewriteEntries rewrites *model.RewriteEntries
services types.Services blockedServicesSchedule *model.BlockedServicesSchedule
filters *types.FilteringStatus filters *model.FilterStatus
clients *types.Clients clients *model.Clients
queryLogConfig *types.QueryLogConfig queryLogConfig *model.QueryLogConfigWithIgnored
statsConfig *types.IntervalConfig statsConfig *model.GetStatsConfigResponse
accessList *types.AccessList accessList *model.AccessList
dnsConfig *types.DNSConfig dnsConfig *model.DNSConfig
dhcpServerConfig *types.DHCPServerConfig dhcpServerConfig *model.DhcpStatus
parental bool parental bool
safeSearch bool safeSearch *model.SafeSearchConfig
safeBrowsing bool profileInfo *model.ProfileInfo
safeBrowsing bool
} }

View File

@@ -4,13 +4,15 @@ import (
"errors" "errors"
"github.com/bakito/adguardhome-sync/pkg/client" "github.com/bakito/adguardhome-sync/pkg/client"
"github.com/bakito/adguardhome-sync/pkg/client/model"
clientmock "github.com/bakito/adguardhome-sync/pkg/mocks/client" clientmock "github.com/bakito/adguardhome-sync/pkg/mocks/client"
"github.com/bakito/adguardhome-sync/pkg/types" "github.com/bakito/adguardhome-sync/pkg/types"
"github.com/bakito/adguardhome-sync/pkg/utils"
"github.com/bakito/adguardhome-sync/pkg/versions" "github.com/bakito/adguardhome-sync/pkg/versions"
gm "github.com/golang/mock/gomock"
"github.com/google/uuid" "github.com/google/uuid"
. "github.com/onsi/ginkgo/v2" . "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
gm "go.uber.org/mock/gomock"
) )
var _ = Describe("Sync", func() { var _ = Describe("Sync", func() {
@@ -19,6 +21,7 @@ var _ = Describe("Sync", func() {
cl *clientmock.MockClient cl *clientmock.MockClient
w *worker w *worker
te error te error
ac *actionContext
) )
BeforeEach(func() { BeforeEach(func() {
@@ -46,251 +49,290 @@ var _ = Describe("Sync", func() {
StatsConfig: true, StatsConfig: true,
QueryLogConfig: true, QueryLogConfig: true,
}, },
Replicas: []types.AdGuardInstance{
{},
},
}, },
} }
te = errors.New(uuid.NewString()) te = errors.New(uuid.NewString())
ac = &actionContext{
continueOnError: false,
rl: l,
origin: &origin{
profileInfo: &model.ProfileInfo{
Name: "origin",
Language: "en",
Theme: "auto",
},
status: &model.ServerStatus{},
safeSearch: &model.SafeSearchConfig{},
queryLogConfig: &model.QueryLogConfigWithIgnored{},
statsConfig: &model.PutStatsConfigUpdateRequest{},
},
replicaStatus: &model.ServerStatus{},
client: cl,
replica: w.cfg.Replicas[0],
}
}) })
AfterEach(func() { AfterEach(func() {
defer mockCtrl.Finish() defer mockCtrl.Finish()
}) })
Context("worker", func() { Context("worker", func() {
Context("syncRewrites", func() { Context("actionDNSRewrites", func() {
var ( var (
domain string domain string
answer string answer string
reO types.RewriteEntries reO model.RewriteEntries
reR types.RewriteEntries reR model.RewriteEntries
) )
BeforeEach(func() { BeforeEach(func() {
domain = uuid.NewString() domain = uuid.NewString()
answer = uuid.NewString() answer = uuid.NewString()
reO = []types.RewriteEntry{{Domain: domain, Answer: answer}} reO = model.RewriteEntries{{Domain: utils.Ptr(domain), Answer: utils.Ptr(answer)}}
reR = []types.RewriteEntry{{Domain: domain, Answer: answer}} reR = model.RewriteEntries{{Domain: utils.Ptr(domain), Answer: utils.Ptr(answer)}}
}) })
It("should have no changes (empty slices)", func() { It("should have no changes (empty slices)", func() {
ac.origin.rewrites = &reO
cl.EXPECT().RewriteList().Return(&reR, nil) cl.EXPECT().RewriteList().Return(&reR, nil)
cl.EXPECT().AddRewriteEntries() cl.EXPECT().AddRewriteEntries()
cl.EXPECT().DeleteRewriteEntries() cl.EXPECT().DeleteRewriteEntries()
err := w.syncRewrites(l, &reO, cl) err := actionDNSRewrites(ac)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should add one rewrite entry", func() { It("should add one rewrite entry", func() {
reR = []types.RewriteEntry{} reR = []model.RewriteEntry{}
ac.origin.rewrites = &reO
cl.EXPECT().RewriteList().Return(&reR, nil) cl.EXPECT().RewriteList().Return(&reR, nil)
cl.EXPECT().AddRewriteEntries(reO[0]) cl.EXPECT().AddRewriteEntries(reO[0])
cl.EXPECT().DeleteRewriteEntries() cl.EXPECT().DeleteRewriteEntries()
err := w.syncRewrites(l, &reO, cl) err := actionDNSRewrites(ac)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should remove one rewrite entry", func() { It("should remove one rewrite entry", func() {
reO = []types.RewriteEntry{} reO = []model.RewriteEntry{}
ac.origin.rewrites = &reO
cl.EXPECT().RewriteList().Return(&reR, nil) cl.EXPECT().RewriteList().Return(&reR, nil)
cl.EXPECT().AddRewriteEntries() cl.EXPECT().AddRewriteEntries()
cl.EXPECT().DeleteRewriteEntries(reR[0]) cl.EXPECT().DeleteRewriteEntries(reR[0])
err := w.syncRewrites(l, &reO, cl) err := actionDNSRewrites(ac)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should remove one rewrite entry", func() { It("should remove one rewrite entry", func() {
reO = []types.RewriteEntry{} reO = []model.RewriteEntry{}
ac.origin.rewrites = &reO
cl.EXPECT().RewriteList().Return(&reR, nil) cl.EXPECT().RewriteList().Return(&reR, nil)
cl.EXPECT().AddRewriteEntries() cl.EXPECT().AddRewriteEntries()
cl.EXPECT().DeleteRewriteEntries(reR[0]) cl.EXPECT().DeleteRewriteEntries(reR[0])
err := w.syncRewrites(l, &reO, cl) err := actionDNSRewrites(ac)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should return error when error on RewriteList()", func() { It("should return error when error on RewriteList()", func() {
ac.origin.rewrites = &reO
cl.EXPECT().RewriteList().Return(nil, te) cl.EXPECT().RewriteList().Return(nil, te)
err := w.syncRewrites(l, &reO, cl) err := actionDNSRewrites(ac)
Ω(err).Should(HaveOccurred()) Ω(err).Should(HaveOccurred())
}) })
It("should return error when error on AddRewriteEntries()", func() { It("should return error when error on AddRewriteEntries()", func() {
ac.origin.rewrites = &reO
cl.EXPECT().RewriteList().Return(&reR, nil) cl.EXPECT().RewriteList().Return(&reR, nil)
cl.EXPECT().DeleteRewriteEntries() cl.EXPECT().DeleteRewriteEntries()
cl.EXPECT().AddRewriteEntries().Return(te) cl.EXPECT().AddRewriteEntries().Return(te)
err := w.syncRewrites(l, &reO, cl) err := actionDNSRewrites(ac)
Ω(err).Should(HaveOccurred()) Ω(err).Should(HaveOccurred())
}) })
It("should return error when error on DeleteRewriteEntries()", func() { It("should return error when error on DeleteRewriteEntries()", func() {
ac.origin.rewrites = &reO
cl.EXPECT().RewriteList().Return(&reR, nil) cl.EXPECT().RewriteList().Return(&reR, nil)
cl.EXPECT().DeleteRewriteEntries().Return(te) cl.EXPECT().DeleteRewriteEntries().Return(te)
err := w.syncRewrites(l, &reO, cl) err := actionDNSRewrites(ac)
Ω(err).Should(HaveOccurred()) Ω(err).Should(HaveOccurred())
}) })
}) })
Context("syncClients", func() { Context("actionClientSettings", func() {
var ( var (
clO *types.Clients clR *model.Clients
clR *types.Clients
name string name string
) )
BeforeEach(func() { BeforeEach(func() {
name = uuid.NewString() name = uuid.NewString()
clO = &types.Clients{Clients: []types.Client{{Name: name}}} ac.origin.clients = &model.Clients{Clients: &model.ClientsArray{{Name: utils.Ptr(name)}}}
clR = &types.Clients{Clients: []types.Client{{Name: name}}} clR = &model.Clients{Clients: &model.ClientsArray{{Name: utils.Ptr(name)}}}
}) })
It("should have no changes (empty slices)", func() { It("should have no changes (empty slices)", func() {
cl.EXPECT().Clients().Return(clR, nil) cl.EXPECT().Clients().Return(clR, nil)
cl.EXPECT().AddClients() err := actionClientSettings(ac)
cl.EXPECT().UpdateClients()
cl.EXPECT().DeleteClients()
err := w.syncClients(clO, cl)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should add one client", func() { It("should add one client", func() {
clR.Clients = []types.Client{} clR.Clients = &model.ClientsArray{}
cl.EXPECT().Clients().Return(clR, nil) cl.EXPECT().Clients().Return(clR, nil)
cl.EXPECT().AddClients(clO.Clients[0]) cl.EXPECT().AddClient(&(*ac.origin.clients.Clients)[0])
cl.EXPECT().UpdateClients() err := actionClientSettings(ac)
cl.EXPECT().DeleteClients()
err := w.syncClients(clO, cl)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should update one client", func() { It("should update one client", func() {
clR.Clients[0].Disallowed = true (*clR.Clients)[0].FilteringEnabled = utils.Ptr(true)
cl.EXPECT().Clients().Return(clR, nil) cl.EXPECT().Clients().Return(clR, nil)
cl.EXPECT().AddClients() cl.EXPECT().UpdateClient(&(*ac.origin.clients.Clients)[0])
cl.EXPECT().UpdateClients(clO.Clients[0]) err := actionClientSettings(ac)
cl.EXPECT().DeleteClients()
err := w.syncClients(clO, cl)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should delete one client", func() { It("should delete one client", func() {
clO.Clients = []types.Client{} ac.origin.clients.Clients = &model.ClientsArray{}
cl.EXPECT().Clients().Return(clR, nil) cl.EXPECT().Clients().Return(clR, nil)
cl.EXPECT().AddClients() cl.EXPECT().DeleteClient(&(*clR.Clients)[0])
cl.EXPECT().UpdateClients() err := actionClientSettings(ac)
cl.EXPECT().DeleteClients(clR.Clients[0])
err := w.syncClients(clO, cl)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should return error when error on Clients()", func() { It("should return error when error on Clients()", func() {
cl.EXPECT().Clients().Return(nil, te) cl.EXPECT().Clients().Return(nil, te)
err := w.syncClients(clO, cl) err := actionClientSettings(ac)
Ω(err).Should(HaveOccurred())
})
It("should return error when error on AddClients()", func() {
cl.EXPECT().Clients().Return(clR, nil)
cl.EXPECT().DeleteClients()
cl.EXPECT().AddClients().Return(te)
err := w.syncClients(clO, cl)
Ω(err).Should(HaveOccurred())
})
It("should return error when error on UpdateClients()", func() {
cl.EXPECT().Clients().Return(clR, nil)
cl.EXPECT().DeleteClients()
cl.EXPECT().AddClients()
cl.EXPECT().UpdateClients().Return(te)
err := w.syncClients(clO, cl)
Ω(err).Should(HaveOccurred())
})
It("should return error when error on DeleteClients()", func() {
cl.EXPECT().Clients().Return(clR, nil)
cl.EXPECT().DeleteClients().Return(te)
err := w.syncClients(clO, cl)
Ω(err).Should(HaveOccurred()) Ω(err).Should(HaveOccurred())
}) })
}) })
Context("syncGeneralSettings", func() { Context("actionParental", func() {
var (
o *origin
rs *types.Status
)
BeforeEach(func() {
o = &origin{
status: &types.Status{},
}
rs = &types.Status{}
})
It("should have no changes", func() { It("should have no changes", func() {
cl.EXPECT().Parental() cl.EXPECT().Parental()
cl.EXPECT().SafeSearch() err := actionParental(ac)
cl.EXPECT().SafeBrowsing()
err := w.syncGeneralSettings(o, rs, cl)
Ω(err).ShouldNot(HaveOccurred())
})
It("should have protection enabled changes", func() {
o.status.ProtectionEnabled = true
cl.EXPECT().ToggleProtection(true)
cl.EXPECT().Parental()
cl.EXPECT().SafeSearch()
cl.EXPECT().SafeBrowsing()
err := w.syncGeneralSettings(o, rs, cl)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should have parental enabled changes", func() { It("should have parental enabled changes", func() {
o.parental = true ac.origin.parental = true
cl.EXPECT().Parental() cl.EXPECT().Parental()
cl.EXPECT().ToggleParental(true) cl.EXPECT().ToggleParental(true)
cl.EXPECT().SafeSearch() err := actionParental(ac)
cl.EXPECT().SafeBrowsing() Ω(err).ShouldNot(HaveOccurred())
err := w.syncGeneralSettings(o, rs, cl) })
})
Context("actionProtection", func() {
It("should have no changes", func() {
err := actionProtection(ac)
Ω(err).ShouldNot(HaveOccurred())
})
It("should have protection enabled changes", func() {
ac.origin.status.ProtectionEnabled = true
cl.EXPECT().ToggleProtection(true)
err := actionProtection(ac)
Ω(err).ShouldNot(HaveOccurred())
})
})
Context("actionSafeSearchConfig", func() {
It("should have no changes", func() {
cl.EXPECT().SafeSearchConfig().Return(ac.origin.safeSearch, nil)
err := actionSafeSearchConfig(ac)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should have safeSearch enabled changes", func() { It("should have safeSearch enabled changes", func() {
o.safeSearch = true ac.origin.safeSearch = &model.SafeSearchConfig{Enabled: utils.Ptr(true)}
cl.EXPECT().Parental() cl.EXPECT().SafeSearchConfig().Return(&model.SafeSearchConfig{}, nil)
cl.EXPECT().SafeSearch() cl.EXPECT().SetSafeSearchConfig(ac.origin.safeSearch)
cl.EXPECT().ToggleSafeSearch(true) err := actionSafeSearchConfig(ac)
cl.EXPECT().SafeBrowsing()
err := w.syncGeneralSettings(o, rs, cl)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should have Duckduckgo safeSearch enabled changed", func() {
ac.origin.safeSearch = &model.SafeSearchConfig{Duckduckgo: utils.Ptr(true)}
cl.EXPECT().SafeSearchConfig().Return(&model.SafeSearchConfig{Google: utils.Ptr(true)}, nil)
cl.EXPECT().SetSafeSearchConfig(ac.origin.safeSearch)
err := actionSafeSearchConfig(ac)
Ω(err).ShouldNot(HaveOccurred())
})
})
Context("actionProfileInfo", func() {
It("should have no changes", func() {
cl.EXPECT().ProfileInfo().Return(ac.origin.profileInfo, nil)
err := actionProfileInfo(ac)
Ω(err).ShouldNot(HaveOccurred())
})
It("should have profileInfo language changed", func() {
ac.origin.profileInfo.Language = "de"
cl.EXPECT().ProfileInfo().Return(&model.ProfileInfo{Name: "replica", Language: "en"}, nil)
cl.EXPECT().SetProfileInfo(&model.ProfileInfo{
Language: "de",
Name: "replica",
Theme: "auto",
})
err := actionProfileInfo(ac)
Ω(err).ShouldNot(HaveOccurred())
})
It("should not sync profileInfo if language is not set", func() {
ac.origin.profileInfo.Language = ""
cl.EXPECT().ProfileInfo().Return(&model.ProfileInfo{Name: "replica", Language: "en", Theme: "auto"}, nil)
cl.EXPECT().SetProfileInfo(ac.origin.profileInfo).Times(0)
err := actionProfileInfo(ac)
Ω(err).ShouldNot(HaveOccurred())
})
It("should not sync profileInfo if theme is not set", func() {
ac.origin.profileInfo.Theme = ""
cl.EXPECT().ProfileInfo().Return(&model.ProfileInfo{Name: "replica", Language: "en", Theme: "auto"}, nil)
cl.EXPECT().SetProfileInfo(ac.origin.profileInfo).Times(0)
err := actionProfileInfo(ac)
Ω(err).ShouldNot(HaveOccurred())
})
})
Context("actionSafeBrowsing", func() {
It("should have no changes", func() {
cl.EXPECT().SafeBrowsing()
err := actionSafeBrowsing(ac)
Ω(err).ShouldNot(HaveOccurred())
})
It("should have safeBrowsing enabled changes", func() { It("should have safeBrowsing enabled changes", func() {
o.safeBrowsing = true ac.origin.safeBrowsing = true
cl.EXPECT().Parental()
cl.EXPECT().SafeSearch()
cl.EXPECT().SafeBrowsing() cl.EXPECT().SafeBrowsing()
cl.EXPECT().ToggleSafeBrowsing(true) cl.EXPECT().ToggleSafeBrowsing(true)
err := w.syncGeneralSettings(o, rs, cl) err := actionSafeBrowsing(ac)
Ω(err).ShouldNot(HaveOccurred())
})
})
Context("actionQueryLogConfig", func() {
var qlc *model.QueryLogConfigWithIgnored
BeforeEach(func() {
qlc = &model.QueryLogConfigWithIgnored{}
})
It("should have no changes", func() {
cl.EXPECT().QueryLogConfig().Return(qlc, nil)
err := actionQueryLogConfig(ac)
Ω(err).ShouldNot(HaveOccurred())
})
It("should have QueryLogConfig changes", func() {
var interval model.QueryLogConfigInterval = 123
ac.origin.queryLogConfig.Interval = &interval
cl.EXPECT().QueryLogConfig().Return(qlc, nil)
cl.EXPECT().SetQueryLogConfig(&model.QueryLogConfigWithIgnored{QueryLogConfig: model.QueryLogConfig{AnonymizeClientIp: nil, Interval: &interval, Enabled: nil}})
err := actionQueryLogConfig(ac)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
}) })
Context("syncConfigs", func() { Context("syncConfigs", func() {
var ( var sc *model.PutStatsConfigUpdateRequest
o *origin
qlc *types.QueryLogConfig
sc *types.IntervalConfig
)
BeforeEach(func() { BeforeEach(func() {
o = &origin{ sc = &model.PutStatsConfigUpdateRequest{}
queryLogConfig: &types.QueryLogConfig{},
statsConfig: &types.IntervalConfig{},
}
qlc = &types.QueryLogConfig{}
sc = &types.IntervalConfig{}
}) })
It("should have no changes", func() { It("should have no changes", func() {
cl.EXPECT().QueryLogConfig().Return(qlc, nil)
cl.EXPECT().StatsConfig().Return(sc, nil) cl.EXPECT().StatsConfig().Return(sc, nil)
err := w.syncConfigs(o, cl) err := actionStatsConfig(ac)
Ω(err).ShouldNot(HaveOccurred())
})
It("should have QueryLogConfig changes", func() {
o.queryLogConfig.Interval = 123
cl.EXPECT().QueryLogConfig().Return(qlc, nil)
cl.EXPECT().SetQueryLogConfig(false, 123.0, false)
cl.EXPECT().StatsConfig().Return(sc, nil)
err := w.syncConfigs(o, cl)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should have StatsConfig changes", func() { It("should have StatsConfig changes", func() {
o.statsConfig.Interval = 123 var interval float32 = 123
cl.EXPECT().QueryLogConfig().Return(qlc, nil) ac.origin.statsConfig.Interval = interval
cl.EXPECT().StatsConfig().Return(sc, nil) cl.EXPECT().StatsConfig().Return(sc, nil)
cl.EXPECT().SetStatsConfig(123.0) cl.EXPECT().SetStatsConfig(&model.PutStatsConfigUpdateRequest{Interval: interval})
err := w.syncConfigs(o, cl) err := actionStatsConfig(ac)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
}) })
Context("statusWithSetup", func() { Context("statusWithSetup", func() {
var ( var (
status *types.Status status *model.ServerStatus
inst types.AdGuardInstance inst types.AdGuardInstance
) )
BeforeEach(func() { BeforeEach(func() {
status = &types.Status{} status = &model.ServerStatus{}
inst = types.AdGuardInstance{ inst = types.AdGuardInstance{
AutoSetup: true, AutoSetup: true,
} }
@@ -317,142 +359,189 @@ var _ = Describe("Sync", func() {
Ω(st).Should(BeNil()) Ω(st).Should(BeNil())
}) })
}) })
Context("syncServices", func() { Context("actionBlockedServicesSchedule", func() {
var ( var rbss *model.BlockedServicesSchedule
os types.Services
rs types.Services
)
BeforeEach(func() { BeforeEach(func() {
os = []string{"foo"} ac.origin.blockedServicesSchedule = &model.BlockedServicesSchedule{}
rs = []string{"foo"} rbss = &model.BlockedServicesSchedule{}
}) })
It("should have no changes", func() { It("should have no changes", func() {
cl.EXPECT().Services().Return(rs, nil) cl.EXPECT().BlockedServicesSchedule().Return(ac.origin.blockedServicesSchedule, nil)
err := w.syncServices(os, cl) err := actionBlockedServicesSchedule(ac)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should have services changes", func() { It("should have blockedServices schedule changes", func() {
os = []string{"bar"} ac.origin.blockedServicesSchedule = &model.BlockedServicesSchedule{Ids: utils.Ptr([]string{"bar"})}
cl.EXPECT().Services().Return(rs, nil)
cl.EXPECT().SetServices(os) cl.EXPECT().BlockedServicesSchedule().Return(rbss, nil)
err := w.syncServices(os, cl) cl.EXPECT().SetBlockedServicesSchedule(ac.origin.blockedServicesSchedule)
err := actionBlockedServicesSchedule(ac)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
}) })
Context("syncFilters", func() { Context("syncFilters", func() {
var ( var rf *model.FilterStatus
of *types.FilteringStatus
rf *types.FilteringStatus
)
BeforeEach(func() { BeforeEach(func() {
of = &types.FilteringStatus{} ac.origin.filters = &model.FilterStatus{}
rf = &types.FilteringStatus{} rf = &model.FilterStatus{}
}) })
It("should have no changes", func() { It("should have no changes", func() {
cl.EXPECT().Filtering().Return(rf, nil) cl.EXPECT().Filtering().Return(rf, nil)
cl.EXPECT().AddFilters(false) err := actionFilters(ac)
cl.EXPECT().UpdateFilters(false)
cl.EXPECT().DeleteFilters(false)
cl.EXPECT().AddFilters(true)
cl.EXPECT().UpdateFilters(true)
cl.EXPECT().DeleteFilters(true)
err := w.syncFilters(of, cl)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should have changes user roles", func() { It("should have changes user roles", func() {
of.UserRules = []string{"foo"} ac.origin.filters.UserRules = utils.Ptr([]string{"foo"})
cl.EXPECT().Filtering().Return(rf, nil) cl.EXPECT().Filtering().Return(rf, nil)
cl.EXPECT().AddFilters(false) cl.EXPECT().SetCustomRules(ac.origin.filters.UserRules)
cl.EXPECT().UpdateFilters(false) err := actionFilters(ac)
cl.EXPECT().DeleteFilters(false)
cl.EXPECT().AddFilters(true)
cl.EXPECT().UpdateFilters(true)
cl.EXPECT().DeleteFilters(true)
cl.EXPECT().SetCustomRules(of.UserRules)
err := w.syncFilters(of, cl)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should have changed filtering config", func() { It("should have changed filtering config", func() {
of.Enabled = true ac.origin.filters.Enabled = utils.Ptr(true)
of.Interval = 123 ac.origin.filters.Interval = utils.Ptr(123)
cl.EXPECT().Filtering().Return(rf, nil) cl.EXPECT().Filtering().Return(rf, nil)
cl.EXPECT().AddFilters(false) cl.EXPECT().ToggleFiltering(*ac.origin.filters.Enabled, *ac.origin.filters.Interval)
cl.EXPECT().UpdateFilters(false) err := actionFilters(ac)
cl.EXPECT().DeleteFilters(false) Ω(err).ShouldNot(HaveOccurred())
cl.EXPECT().AddFilters(true) })
cl.EXPECT().UpdateFilters(true) It("should add a filter", func() {
cl.EXPECT().DeleteFilters(true) ac.origin.filters.Filters = utils.Ptr([]model.Filter{{Name: "foo", Url: "https://foo.bar"}})
cl.EXPECT().ToggleFiltering(of.Enabled, of.Interval) cl.EXPECT().Filtering().Return(rf, nil)
err := w.syncFilters(of, cl) cl.EXPECT().AddFilter(false, model.Filter{Name: "foo", Url: "https://foo.bar"})
cl.EXPECT().RefreshFilters(gm.Any())
err := actionFilters(ac)
Ω(err).ShouldNot(HaveOccurred())
})
It("should delete a filter", func() {
rf.Filters = utils.Ptr([]model.Filter{{Name: "foo", Url: "https://foo.bar"}})
cl.EXPECT().Filtering().Return(rf, nil)
cl.EXPECT().DeleteFilter(false, model.Filter{Name: "foo", Url: "https://foo.bar"})
err := actionFilters(ac)
Ω(err).ShouldNot(HaveOccurred())
})
It("should update a filter", func() {
ac.origin.filters.Filters = utils.Ptr([]model.Filter{{Name: "foo", Url: "https://foo.bar", Enabled: true}})
rf.Filters = utils.Ptr([]model.Filter{{Name: "foo", Url: "https://foo.bar"}})
cl.EXPECT().Filtering().Return(rf, nil)
cl.EXPECT().UpdateFilter(false, model.Filter{Name: "foo", Url: "https://foo.bar", Enabled: true})
cl.EXPECT().RefreshFilters(gm.Any())
err := actionFilters(ac)
Ω(err).ShouldNot(HaveOccurred())
})
It("should abort after failed added filter", func() {
ac.continueOnError = false
ac.origin.filters.Filters = utils.Ptr([]model.Filter{{Name: "foo", Url: "https://foo.bar"}})
cl.EXPECT().Filtering().Return(rf, nil)
cl.EXPECT().AddFilter(false, model.Filter{Name: "foo", Url: "https://foo.bar"}).Return(errors.New("test failure"))
err := actionFilters(ac)
Ω(err).Should(HaveOccurred())
})
It("should continue after failed added filter", func() {
ac.continueOnError = true
ac.origin.filters.Filters = utils.Ptr([]model.Filter{{Name: "foo", Url: "https://foo.bar"}, {Name: "bar", Url: "https://bar.foo"}})
cl.EXPECT().Filtering().Return(rf, nil)
cl.EXPECT().AddFilter(false, model.Filter{Name: "foo", Url: "https://foo.bar"}).Return(errors.New("test failure"))
cl.EXPECT().AddFilter(false, model.Filter{Name: "bar", Url: "https://bar.foo"})
cl.EXPECT().RefreshFilters(gm.Any())
err := actionFilters(ac)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
}) })
Context("syncDNS", func() { Context("actionDNSAccessLists", func() {
var ( var ral *model.AccessList
oal *types.AccessList
ral *types.AccessList
odc *types.DNSConfig
rdc *types.DNSConfig
)
BeforeEach(func() { BeforeEach(func() {
oal = &types.AccessList{} ac.origin.accessList = &model.AccessList{}
ral = &types.AccessList{} ral = &model.AccessList{}
odc = &types.DNSConfig{}
rdc = &types.DNSConfig{}
}) })
It("should have no changes", func() { It("should have no changes", func() {
cl.EXPECT().AccessList().Return(ral, nil) cl.EXPECT().AccessList().Return(ral, nil)
cl.EXPECT().DNSConfig().Return(rdc, nil) err := actionDNSAccessLists(ac)
err := w.syncDNS(oal, odc, cl)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should have access list changes", func() { It("should have access list changes", func() {
ral.BlockedHosts = []string{"foo"} ral.BlockedHosts = utils.Ptr([]string{"foo"})
cl.EXPECT().AccessList().Return(ral, nil) cl.EXPECT().AccessList().Return(ral, nil)
cl.EXPECT().DNSConfig().Return(rdc, nil) cl.EXPECT().SetAccessList(ac.origin.accessList)
cl.EXPECT().SetAccessList(oal) err := actionDNSAccessLists(ac)
err := w.syncDNS(oal, odc, cl)
Ω(err).ShouldNot(HaveOccurred())
})
It("should have dns config changes", func() {
rdc.Bootstraps = []string{"foo"}
cl.EXPECT().AccessList().Return(ral, nil)
cl.EXPECT().DNSConfig().Return(rdc, nil)
cl.EXPECT().SetDNSConfig(odc)
err := w.syncDNS(oal, odc, cl)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
}) })
Context("syncDHCPServer", func() { Context("actionDNSServerConfig", func() {
var ( var rdc *model.DNSConfig
osc *types.DHCPServerConfig
rsc *types.DHCPServerConfig
)
BeforeEach(func() { BeforeEach(func() {
osc = &types.DHCPServerConfig{} ac.origin.dnsConfig = &model.DNSConfig{}
rsc = &types.DHCPServerConfig{} rdc = &model.DNSConfig{}
})
It("should have no changes", func() {
cl.EXPECT().DNSConfig().Return(rdc, nil)
err := actionDNSServerConfig(ac)
Ω(err).ShouldNot(HaveOccurred())
})
It("should have dns config changes", func() {
rdc.BootstrapDns = utils.Ptr([]string{"foo"})
cl.EXPECT().DNSConfig().Return(rdc, nil)
cl.EXPECT().SetDNSConfig(ac.origin.dnsConfig)
err := actionDNSServerConfig(ac)
Ω(err).ShouldNot(HaveOccurred())
})
})
Context("actionDHCPServerConfig", func() {
var rsc *model.DhcpStatus
BeforeEach(func() {
ac.origin.dhcpServerConfig = &model.DhcpStatus{
V4: &model.DhcpConfigV4{
GatewayIp: utils.Ptr("1.2.3.4"),
RangeStart: utils.Ptr("1.2.3.5"),
RangeEnd: utils.Ptr("1.2.3.6"),
SubnetMask: utils.Ptr("255.255.255.0"),
},
}
rsc = &model.DhcpStatus{}
w.cfg.Features.DHCP.StaticLeases = false w.cfg.Features.DHCP.StaticLeases = false
}) })
It("should have no changes", func() { It("should have no changes", func() {
cl.EXPECT().DHCPServerConfig().Return(rsc, nil) rsc.V4 = ac.origin.dhcpServerConfig.V4
err := w.syncDHCPServer(osc, cl, types.AdGuardInstance{}) cl.EXPECT().DhcpConfig().Return(rsc, nil)
err := actionDHCPServerConfig(ac)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should have changes", func() { It("should have changes", func() {
rsc.Enabled = true rsc.Enabled = utils.Ptr(true)
cl.EXPECT().DHCPServerConfig().Return(rsc, nil) cl.EXPECT().DhcpConfig().Return(rsc, nil)
cl.EXPECT().SetDHCPServerConfig(osc) cl.EXPECT().SetDhcpConfig(ac.origin.dhcpServerConfig)
err := w.syncDHCPServer(osc, cl, types.AdGuardInstance{}) err := actionDHCPServerConfig(ac)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
It("should use replica interface name", func() { It("should use replica interface name", func() {
cl.EXPECT().DHCPServerConfig().Return(rsc, nil) ac.replica.InterfaceName = "foo"
oscClone := osc.Clone() cl.EXPECT().DhcpConfig().Return(rsc, nil)
oscClone.InterfaceName = "foo" oscClone := ac.origin.dhcpServerConfig.Clone()
cl.EXPECT().SetDHCPServerConfig(oscClone) oscClone.InterfaceName = utils.Ptr("foo")
err := w.syncDHCPServer(osc, cl, types.AdGuardInstance{InterfaceName: "foo"}) cl.EXPECT().SetDhcpConfig(oscClone)
err := actionDHCPServerConfig(ac)
Ω(err).ShouldNot(HaveOccurred())
})
It("should enable the target dhcp server", func() {
ac.replica.DHCPServerEnabled = utils.Ptr(true)
cl.EXPECT().DhcpConfig().Return(rsc, nil)
oscClone := ac.origin.dhcpServerConfig.Clone()
oscClone.Enabled = utils.Ptr(true)
cl.EXPECT().SetDhcpConfig(oscClone)
err := actionDHCPServerConfig(ac)
Ω(err).ShouldNot(HaveOccurred())
})
It("should not sync empty IPv4", func() {
ac.replica.DHCPServerEnabled = utils.Ptr(false)
ac.origin.dhcpServerConfig.V4 = &model.DhcpConfigV4{
GatewayIp: utils.Ptr(""),
}
err := actionDHCPServerConfig(ac)
Ω(err).ShouldNot(HaveOccurred()) Ω(err).ShouldNot(HaveOccurred())
}) })
}) })
@@ -461,7 +550,7 @@ var _ = Describe("Sync", func() {
BeforeEach(func() { BeforeEach(func() {
w.cfg = &types.Config{ w.cfg = &types.Config{
Origin: types.AdGuardInstance{}, Origin: types.AdGuardInstance{},
Replica: types.AdGuardInstance{URL: "foo"}, Replica: &types.AdGuardInstance{URL: "foo"},
Features: types.Features{ Features: types.Features{
DHCP: types.DHCP{ DHCP: types.DHCP{
ServerConfig: true, ServerConfig: true,
@@ -484,98 +573,106 @@ var _ = Describe("Sync", func() {
It("should have no changes", func() { It("should have no changes", func() {
// origin // origin
cl.EXPECT().Host() cl.EXPECT().Host()
cl.EXPECT().Status().Return(&types.Status{Version: versions.MinAgh}, nil) cl.EXPECT().Status().Return(&model.ServerStatus{Version: versions.MinAgh}, nil)
cl.EXPECT().ProfileInfo().Return(&model.ProfileInfo{}, nil)
cl.EXPECT().Parental() cl.EXPECT().Parental()
cl.EXPECT().SafeSearch() cl.EXPECT().SafeSearchConfig().Return(&model.SafeSearchConfig{}, nil)
cl.EXPECT().SafeBrowsing() cl.EXPECT().SafeBrowsing()
cl.EXPECT().RewriteList().Return(&types.RewriteEntries{}, nil) cl.EXPECT().RewriteList().Return(&model.RewriteEntries{}, nil)
cl.EXPECT().Services() cl.EXPECT().BlockedServicesSchedule()
cl.EXPECT().Filtering().Return(&types.FilteringStatus{}, nil) cl.EXPECT().Filtering().Return(&model.FilterStatus{}, nil)
cl.EXPECT().Clients().Return(&types.Clients{}, nil) cl.EXPECT().Clients().Return(&model.Clients{}, nil)
cl.EXPECT().QueryLogConfig().Return(&types.QueryLogConfig{}, nil) cl.EXPECT().QueryLogConfig().Return(&model.QueryLogConfigWithIgnored{}, nil)
cl.EXPECT().StatsConfig().Return(&types.IntervalConfig{}, nil) cl.EXPECT().StatsConfig().Return(&model.PutStatsConfigUpdateRequest{}, nil)
cl.EXPECT().AccessList().Return(&types.AccessList{}, nil) cl.EXPECT().AccessList().Return(&model.AccessList{}, nil)
cl.EXPECT().DNSConfig().Return(&types.DNSConfig{}, nil) cl.EXPECT().DNSConfig().Return(&model.DNSConfig{}, nil)
cl.EXPECT().DHCPServerConfig().Return(&types.DHCPServerConfig{}, nil) cl.EXPECT().DhcpConfig().Return(&model.DhcpStatus{}, nil)
// replica // replica
cl.EXPECT().Host() cl.EXPECT().Host()
cl.EXPECT().Status().Return(&types.Status{Version: versions.MinAgh}, nil) cl.EXPECT().Status().Return(&model.ServerStatus{Version: versions.MinAgh}, nil)
cl.EXPECT().ProfileInfo().Return(&model.ProfileInfo{}, nil)
cl.EXPECT().Parental() cl.EXPECT().Parental()
cl.EXPECT().SafeSearch() cl.EXPECT().SafeSearchConfig().Return(&model.SafeSearchConfig{}, nil)
cl.EXPECT().SafeBrowsing() cl.EXPECT().SafeBrowsing()
cl.EXPECT().QueryLogConfig().Return(&types.QueryLogConfig{}, nil) cl.EXPECT().QueryLogConfig().Return(&model.QueryLogConfigWithIgnored{}, nil)
cl.EXPECT().StatsConfig().Return(&types.IntervalConfig{}, nil) cl.EXPECT().StatsConfig().Return(&model.PutStatsConfigUpdateRequest{}, nil)
cl.EXPECT().RewriteList().Return(&types.RewriteEntries{}, nil) cl.EXPECT().RewriteList().Return(&model.RewriteEntries{}, nil)
cl.EXPECT().AddRewriteEntries() cl.EXPECT().AddRewriteEntries()
cl.EXPECT().DeleteRewriteEntries() cl.EXPECT().DeleteRewriteEntries()
cl.EXPECT().Filtering().Return(&types.FilteringStatus{}, nil) cl.EXPECT().Filtering().Return(&model.FilterStatus{}, nil)
cl.EXPECT().AddFilters(false) cl.EXPECT().BlockedServicesSchedule()
cl.EXPECT().UpdateFilters(false) cl.EXPECT().Clients().Return(&model.Clients{}, nil)
cl.EXPECT().DeleteFilters(false) cl.EXPECT().AccessList().Return(&model.AccessList{}, nil)
cl.EXPECT().AddFilters(true) cl.EXPECT().DNSConfig().Return(&model.DNSConfig{}, nil)
cl.EXPECT().UpdateFilters(true) cl.EXPECT().DhcpConfig().Return(&model.DhcpStatus{}, nil)
cl.EXPECT().DeleteFilters(true) w.sync()
cl.EXPECT().Services() })
cl.EXPECT().Clients().Return(&types.Clients{}, nil) It("should not sync DHCP", func() {
cl.EXPECT().AddClients() w.cfg.Features.DHCP.ServerConfig = false
cl.EXPECT().UpdateClients() w.cfg.Features.DHCP.StaticLeases = false
cl.EXPECT().DeleteClients() // origin
cl.EXPECT().AccessList().Return(&types.AccessList{}, nil) cl.EXPECT().Host()
cl.EXPECT().DNSConfig().Return(&types.DNSConfig{}, nil) cl.EXPECT().Status().Return(&model.ServerStatus{Version: versions.MinAgh}, nil)
cl.EXPECT().DHCPServerConfig().Return(&types.DHCPServerConfig{}, nil) cl.EXPECT().ProfileInfo().Return(&model.ProfileInfo{}, nil)
cl.EXPECT().AddDHCPStaticLeases().Return(nil) cl.EXPECT().Parental()
cl.EXPECT().DeleteDHCPStaticLeases().Return(nil) cl.EXPECT().SafeSearchConfig().Return(&model.SafeSearchConfig{}, nil)
cl.EXPECT().SafeBrowsing()
cl.EXPECT().RewriteList().Return(&model.RewriteEntries{}, nil)
cl.EXPECT().BlockedServicesSchedule()
cl.EXPECT().Filtering().Return(&model.FilterStatus{}, nil)
cl.EXPECT().Clients().Return(&model.Clients{}, nil)
cl.EXPECT().QueryLogConfig().Return(&model.QueryLogConfigWithIgnored{}, nil)
cl.EXPECT().StatsConfig().Return(&model.PutStatsConfigUpdateRequest{}, nil)
cl.EXPECT().AccessList().Return(&model.AccessList{}, nil)
cl.EXPECT().DNSConfig().Return(&model.DNSConfig{}, nil)
// replica
cl.EXPECT().Host()
cl.EXPECT().Status().Return(&model.ServerStatus{Version: versions.MinAgh}, nil)
cl.EXPECT().ProfileInfo().Return(&model.ProfileInfo{}, nil)
cl.EXPECT().Parental()
cl.EXPECT().SafeSearchConfig().Return(&model.SafeSearchConfig{}, nil)
cl.EXPECT().SafeBrowsing()
cl.EXPECT().QueryLogConfig().Return(&model.QueryLogConfigWithIgnored{}, nil)
cl.EXPECT().StatsConfig().Return(&model.PutStatsConfigUpdateRequest{}, nil)
cl.EXPECT().RewriteList().Return(&model.RewriteEntries{}, nil)
cl.EXPECT().AddRewriteEntries()
cl.EXPECT().DeleteRewriteEntries()
cl.EXPECT().Filtering().Return(&model.FilterStatus{}, nil)
cl.EXPECT().BlockedServicesSchedule()
cl.EXPECT().Clients().Return(&model.Clients{}, nil)
cl.EXPECT().AccessList().Return(&model.AccessList{}, nil)
cl.EXPECT().DNSConfig().Return(&model.DNSConfig{}, nil)
w.sync() w.sync()
}) })
It("origin version is too small", func() { It("origin version is too small", func() {
// origin // origin
cl.EXPECT().Host() cl.EXPECT().Host()
cl.EXPECT().Status().Return(&types.Status{Version: "v0.106.9"}, nil) cl.EXPECT().Status().Return(&model.ServerStatus{Version: "v0.106.9"}, nil)
w.sync() w.sync()
}) })
It("replica version is too small", func() { It("replica version is too small", func() {
// origin // origin
cl.EXPECT().Host() cl.EXPECT().Host()
cl.EXPECT().Status().Return(&types.Status{Version: versions.MinAgh}, nil) cl.EXPECT().Status().Return(&model.ServerStatus{Version: versions.MinAgh}, nil)
cl.EXPECT().ProfileInfo().Return(&model.ProfileInfo{}, nil)
cl.EXPECT().Parental() cl.EXPECT().Parental()
cl.EXPECT().SafeSearch() cl.EXPECT().SafeSearchConfig().Return(&model.SafeSearchConfig{}, nil)
cl.EXPECT().SafeBrowsing() cl.EXPECT().SafeBrowsing()
cl.EXPECT().RewriteList().Return(&types.RewriteEntries{}, nil) cl.EXPECT().RewriteList().Return(&model.RewriteEntries{}, nil)
cl.EXPECT().Services() cl.EXPECT().BlockedServicesSchedule()
cl.EXPECT().Filtering().Return(&types.FilteringStatus{}, nil) cl.EXPECT().Filtering().Return(&model.FilterStatus{}, nil)
cl.EXPECT().Clients().Return(&types.Clients{}, nil) cl.EXPECT().Clients().Return(&model.Clients{}, nil)
cl.EXPECT().QueryLogConfig().Return(&types.QueryLogConfig{}, nil) cl.EXPECT().QueryLogConfig().Return(&model.QueryLogConfigWithIgnored{}, nil)
cl.EXPECT().StatsConfig().Return(&types.IntervalConfig{}, nil) cl.EXPECT().StatsConfig().Return(&model.PutStatsConfigUpdateRequest{}, nil)
cl.EXPECT().AccessList().Return(&types.AccessList{}, nil) cl.EXPECT().AccessList().Return(&model.AccessList{}, nil)
cl.EXPECT().DNSConfig().Return(&types.DNSConfig{}, nil) cl.EXPECT().DNSConfig().Return(&model.DNSConfig{}, nil)
cl.EXPECT().DHCPServerConfig().Return(&types.DHCPServerConfig{}, nil) cl.EXPECT().DhcpConfig().Return(&model.DhcpStatus{}, nil)
// replica // replica
cl.EXPECT().Host() cl.EXPECT().Host()
cl.EXPECT().Status().Return(&types.Status{Version: "v0.106.9"}, nil) cl.EXPECT().Status().Return(&model.ServerStatus{Version: "v0.106.9"}, nil)
w.sync()
})
It("replica version is with incompatible API", func() {
// origin
cl.EXPECT().Host()
cl.EXPECT().Status().Return(&types.Status{Version: versions.MinAgh}, nil)
cl.EXPECT().Parental()
cl.EXPECT().SafeSearch()
cl.EXPECT().SafeBrowsing()
cl.EXPECT().RewriteList().Return(&types.RewriteEntries{}, nil)
cl.EXPECT().Services()
cl.EXPECT().Filtering().Return(&types.FilteringStatus{}, nil)
cl.EXPECT().Clients().Return(&types.Clients{}, nil)
cl.EXPECT().QueryLogConfig().Return(&types.QueryLogConfig{}, nil)
cl.EXPECT().StatsConfig().Return(&types.IntervalConfig{}, nil)
cl.EXPECT().AccessList().Return(&types.AccessList{}, nil)
cl.EXPECT().DNSConfig().Return(&types.DNSConfig{}, nil)
cl.EXPECT().DHCPServerConfig().Return(&types.DHCPServerConfig{}, nil)
// replica
cl.EXPECT().Host()
cl.EXPECT().Status().Return(&types.Status{Version: versions.IncompatibleAPI}, nil)
w.sync() w.sync()
}) })
}) })

View File

@@ -5,47 +5,54 @@
package types package types
import (
net "net"
)
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DNSConfig) DeepCopyInto(out *DNSConfig) { func (in *AdGuardInstance) DeepCopyInto(out *AdGuardInstance) {
*out = *in *out = *in
if in.Upstreams != nil { if in.DHCPServerEnabled != nil {
in, out := &in.Upstreams, &out.Upstreams in, out := &in.DHCPServerEnabled, &out.DHCPServerEnabled
*out = make([]string, len(*in)) *out = new(bool)
copy(*out, *in) **out = **in
}
if in.Bootstraps != nil {
in, out := &in.Bootstraps, &out.Bootstraps
*out = make([]string, len(*in))
copy(*out, *in)
}
if in.BlockingIPv4 != nil {
in, out := &in.BlockingIPv4, &out.BlockingIPv4
*out = make(net.IP, len(*in))
copy(*out, *in)
}
if in.BlockingIPv6 != nil {
in, out := &in.BlockingIPv6, &out.BlockingIPv6
*out = make(net.IP, len(*in))
copy(*out, *in)
}
if in.LocalPTRUpstreams != nil {
in, out := &in.LocalPTRUpstreams, &out.LocalPTRUpstreams
*out = make([]string, len(*in))
copy(*out, *in)
} }
return return
} }
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DNSConfig. // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AdGuardInstance.
func (in *DNSConfig) DeepCopy() *DNSConfig { func (in *AdGuardInstance) DeepCopy() *AdGuardInstance {
if in == nil { if in == nil {
return nil return nil
} }
out := new(DNSConfig) out := new(AdGuardInstance)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Config) DeepCopyInto(out *Config) {
*out = *in
in.Origin.DeepCopyInto(&out.Origin)
if in.Replica != nil {
in, out := &in.Replica, &out.Replica
*out = new(AdGuardInstance)
(*in).DeepCopyInto(*out)
}
if in.Replicas != nil {
in, out := &in.Replicas, &out.Replicas
*out = make([]AdGuardInstance, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
out.API = in.API
out.Features = in.Features
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Config.
func (in *Config) DeepCopy() *Config {
if in == nil {
return nil
}
out := new(Config)
in.DeepCopyInto(out) in.DeepCopyInto(out)
return out return out
} }

View File

@@ -1,89 +0,0 @@
package types
import (
"encoding/json"
"net"
"time"
"github.com/jinzhu/copier"
)
// DHCPServerConfig dhcp server config
type DHCPServerConfig struct {
V4 *V4ServerConfJSON `json:"v4"`
V6 *V6ServerConfJSON `json:"v6"`
InterfaceName string `json:"interface_name"`
Enabled bool `json:"enabled"`
Leases Leases `json:"leases,omitempty"`
StaticLeases Leases `json:"static_leases,omitempty"`
}
// Clone the config
func (c *DHCPServerConfig) Clone() *DHCPServerConfig {
clone := &DHCPServerConfig{}
_ = copier.Copy(c, clone)
return clone
}
// Equals dhcp server config equal check
func (c *DHCPServerConfig) Equals(o *DHCPServerConfig) bool {
a, _ := json.Marshal(c)
b, _ := json.Marshal(o)
return string(a) == string(b)
}
// V4ServerConfJSON v4 server conf
type V4ServerConfJSON struct {
GatewayIP net.IP `json:"gateway_ip"`
SubnetMask net.IP `json:"subnet_mask"`
RangeStart net.IP `json:"range_start"`
RangeEnd net.IP `json:"range_end"`
LeaseDuration uint32 `json:"lease_duration"`
}
// V6ServerConfJSON v6 server conf
type V6ServerConfJSON struct {
RangeStart net.IP `json:"range_start"`
RangeEnd net.IP `json:"range_end"`
LeaseDuration uint32 `json:"lease_duration"`
}
// Leases slice of leases type
type Leases []Lease
// Merge the leases
func (l Leases) Merge(other Leases) ([]Lease, []Lease) {
current := make(map[string]Lease)
var adds Leases
var removes Leases
for _, le := range l {
current[le.HWAddr] = le
}
for _, le := range other {
if _, ok := current[le.HWAddr]; ok {
delete(current, le.HWAddr)
} else {
adds = append(adds, le)
}
}
for _, rr := range current {
removes = append(removes, rr)
}
return adds, removes
}
// Lease contains the necessary information about a DHCP lease
type Lease struct {
HWAddr string `json:"mac"`
IP net.IP `json:"ip"`
Hostname string `json:"hostname"`
// Lease expiration time
// 1: static lease
Expiry time.Time `json:"expires"`
}

View File

@@ -1,71 +0,0 @@
package types
import (
"encoding/json"
"net"
"sort"
)
// DNSConfig dns config
// +k8s:deepcopy-gen=true
type DNSConfig struct {
Upstreams []string `json:"upstream_dns,omitempty"`
UpstreamsFile string `json:"upstream_dns_file"`
Bootstraps []string `json:"bootstrap_dns,omitempty"`
ProtectionEnabled bool `json:"protection_enabled"`
RateLimit uint32 `json:"ratelimit"`
BlockingMode string `json:"blocking_mode,omitempty"`
BlockingIPv4 net.IP `json:"blocking_ipv4,omitempty"`
BlockingIPv6 net.IP `json:"blocking_ipv6"`
EDNSCSEnabled bool `json:"edns_cs_enabled"`
DNSSECEnabled bool `json:"dnssec_enabled"`
DisableIPv6 bool `json:"disable_ipv6"`
UpstreamMode string `json:"upstream_mode,omitempty"`
CacheSize uint32 `json:"cache_size"`
CacheMinTTL uint32 `json:"cache_ttl_min"`
CacheMaxTTL uint32 `json:"cache_ttl_max"`
CacheOptimistic bool `json:"cache_optimistic"`
ResolveClients bool `json:"resolve_clients"`
LocalPTRUpstreams []string `json:"local_ptr_upstreams,omitempty"`
}
// Equals dns config equal check
func (c *DNSConfig) Equals(o *DNSConfig) bool {
cc := c.DeepCopy()
oo := o.DeepCopy()
cc.Sort()
oo.Sort()
a, _ := json.Marshal(cc)
b, _ := json.Marshal(oo)
return string(a) == string(b)
}
// Sort sort dns config
func (c *DNSConfig) Sort() {
sort.Strings(c.Upstreams)
sort.Strings(c.Bootstraps)
sort.Strings(c.LocalPTRUpstreams)
}
// AccessList access list
type AccessList struct {
AllowedClients []string `json:"allowed_clients"`
DisallowedClients []string `json:"disallowed_clients"`
BlockedHosts []string `json:"blocked_hosts"`
}
// Equals access list equal check
func (al *AccessList) Equals(o *AccessList) bool {
return equals(al.AllowedClients, o.AllowedClients) &&
equals(al.DisallowedClients, o.DisallowedClients) &&
equals(al.BlockedHosts, o.BlockedHosts)
}
// Sort sort access list
func (al *AccessList) Sort() {
sort.Strings(al.AllowedClients)
sort.Strings(al.DisallowedClients)
sort.Strings(al.BlockedHosts)
}

View File

@@ -4,33 +4,61 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
) )
func NewFeatures(enabled bool) Features {
return Features{
DNS: DNS{
AccessLists: enabled,
ServerConfig: enabled,
Rewrites: enabled,
},
DHCP: DHCP{
ServerConfig: enabled,
StaticLeases: enabled,
},
GeneralSettings: enabled,
QueryLogConfig: enabled,
StatsConfig: enabled,
ClientSettings: enabled,
Services: enabled,
Filters: enabled,
}
}
// Features feature flags // Features feature flags
type Features struct { type Features struct {
DNS DNS `json:"dns" yaml:"dns"` DNS DNS `json:"dns" yaml:"dns"`
DHCP DHCP `json:"dhcp" yaml:"dhcp"` DHCP DHCP `json:"dhcp" yaml:"dhcp"`
GeneralSettings bool `json:"generalSettings" yaml:"generalSettings"` GeneralSettings bool `json:"generalSettings" yaml:"generalSettings" env:"FEATURES_GENERAL_SETTINGS"`
QueryLogConfig bool `json:"queryLogConfig" yaml:"queryLogConfig"` QueryLogConfig bool `json:"queryLogConfig" yaml:"queryLogConfig" env:"FEATURES_QUERY_LOG_CONFIG"`
StatsConfig bool `json:"statsConfig" yaml:"statsConfig"` StatsConfig bool `json:"statsConfig" yaml:"statsConfig" env:"FEATURES_STATS_CONFIG"`
ClientSettings bool `json:"clientSettings" yaml:"clientSettings"` ClientSettings bool `json:"clientSettings" yaml:"clientSettings" env:"FEATURES_CLIENT_SETTINGS"`
Services bool `json:"services" yaml:"services"` Services bool `json:"services" yaml:"services" env:"FEATURES_SERVICES"`
Filters bool `json:"filters" yaml:"filters"` Filters bool `json:"filters" yaml:"filters" env:"FEATURES_FILTERS"`
} }
// DHCP features // DHCP features
type DHCP struct { type DHCP struct {
ServerConfig bool `json:"serverConfig" yaml:"serverConfig"` ServerConfig bool `json:"serverConfig" yaml:"serverConfig" env:"FEATURES_DHCP_SERVER_CONFIG"`
StaticLeases bool `json:"staticLeases" yaml:"staticLeases"` StaticLeases bool `json:"staticLeases" yaml:"staticLeases" env:"FEATURES_DHCP_STATIC_LEASES"`
} }
// DNS features // DNS features
type DNS struct { type DNS struct {
AccessLists bool `json:"accessLists" yaml:"accessLists"` AccessLists bool `json:"accessLists" yaml:"accessLists" env:"FEATURES_DNS_ACCESS_LISTS"`
ServerConfig bool `json:"serverConfig" yaml:"serverConfig"` ServerConfig bool `json:"serverConfig" yaml:"serverConfig" env:"FEATURES_DNS_SERVER_CONFIG"`
Rewrites bool `json:"rewrites" yaml:"rewrites"` Rewrites bool `json:"rewrites" yaml:"rewrites" env:"FEATURES_DNS_REWRITES"`
} }
// LogDisabled log all disabled features // LogDisabled log all disabled features
func (f *Features) LogDisabled(l *zap.SugaredLogger) { func (f *Features) LogDisabled(l *zap.SugaredLogger) {
features := f.collectDisabled()
if len(features) > 0 {
l.With("features", features).Info("Disabled features")
}
}
func (f *Features) collectDisabled() []string {
var features []string var features []string
if !f.DHCP.ServerConfig { if !f.DHCP.ServerConfig {
features = append(features, "DHCP.ServerConfig") features = append(features, "DHCP.ServerConfig")
@@ -60,13 +88,10 @@ func (f *Features) LogDisabled(l *zap.SugaredLogger) {
features = append(features, "ClientSettings") features = append(features, "ClientSettings")
} }
if !f.Services { if !f.Services {
features = append(features, "Services") features = append(features, "BlockedServices")
} }
if !f.Filters { if !f.Filters {
features = append(features, "Filters") features = append(features, "Filters")
} }
return features
if len(features) > 0 {
l.With("features", features).Info("Disabled features")
}
} }

View File

@@ -1,12 +1,12 @@
package types package types
import ( import (
"encoding/json"
"fmt" "fmt"
"sort" "net/url"
"strings" "strings"
"time"
"github.com/bakito/adguardhome-sync/pkg/versions" "go.uber.org/zap"
) )
const ( const (
@@ -15,31 +15,54 @@ const (
) )
// Config application configuration struct // Config application configuration struct
// +k8s:deepcopy-gen=true
type Config struct { type Config struct {
Origin AdGuardInstance `json:"origin" yaml:"origin"` Origin AdGuardInstance `json:"origin" yaml:"origin" env:"ORIGIN"`
Replica AdGuardInstance `json:"replica,omitempty" yaml:"replica,omitempty"` Replica *AdGuardInstance `json:"replica,omitempty" yaml:"replica,omitempty" env:"REPLICA"`
Replicas []AdGuardInstance `json:"replicas,omitempty" yaml:"replicas,omitempty"` Replicas []AdGuardInstance `json:"replicas,omitempty" yaml:"replicas,omitempty"`
Cron string `json:"cron,omitempty" yaml:"cron,omitempty"` Cron string `json:"cron,omitempty" yaml:"cron,omitempty" env:"CRON"`
RunOnStart bool `json:"runOnStart,omitempty" yaml:"runOnStart,omitempty"` RunOnStart bool `json:"runOnStart,omitempty" yaml:"runOnStart,omitempty" env:"RUN_ON_START"`
API API `json:"api,omitempty" yaml:"api,omitempty"` PrintConfigOnly bool `json:"printConfigOnly,omitempty" yaml:"printConfigOnly,omitempty" env:"PRINT_CONFIG_ONLY"`
Features Features `json:"features,omitempty" yaml:"features,omitempty"` ContinueOnError bool `json:"continueOnError,omitempty" yaml:"continueOnError,omitempty" env:"CONTINUE_ON_ERROR"`
API API `json:"api,omitempty" yaml:"api,omitempty" env:"API"`
Features Features `json:"features,omitempty" yaml:"features,omitempty" env:"FEATURES_"`
} }
// API configuration // API configuration
type API struct { type API struct {
Port int `json:"port,omitempty" yaml:"port,omitempty"` Port int `json:"port,omitempty" yaml:"port,omitempty" env:"API_PORT"`
Username string `json:"username,omitempty" yaml:"username,omitempty"` Username string `json:"username,omitempty" yaml:"username,omitempty" env:"API_USERNAME"`
Password string `json:"password,omitempty" yaml:"password,omitempty"` Password string `json:"password,omitempty" yaml:"password,omitempty" env:"API_PASSWORD"`
DarkMode bool `json:"darkMode,omitempty" yaml:"darkMode,omitempty"` DarkMode bool `json:"darkMode,omitempty" yaml:"darkMode,omitempty" env:"API_DARK_MODE"`
Metrics Metrics `json:"metrics,omitempty" yaml:"metrics,omitempty" env:"API_METRICS"`
}
// Metrics configuration
type Metrics struct {
Enabled bool `json:"enabled,omitempty" yaml:"enabled,omitempty" env:"API_METRICS_ENABLED"`
ScrapeInterval time.Duration `json:"scrapeInterval,omitempty" yaml:"scrapeInterval,omitempty" env:"API_METRICS_SCRAPE_INTERVAL"`
QueryLogLimit int `json:"queryLogLimit,omitempty" yaml:"queryLogLimit,omitempty" env:"API_METRICS_QUERY_LOG_LIMIT"`
}
// Mask maks username and password
func (a *API) Mask() {
a.Username = mask(a.Username)
a.Password = mask(a.Password)
} }
// UniqueReplicas get unique replication instances // UniqueReplicas get unique replication instances
func (cfg *Config) UniqueReplicas() []AdGuardInstance { func (cfg *Config) UniqueReplicas() []AdGuardInstance {
dedup := make(map[string]AdGuardInstance) dedup := make(map[string]AdGuardInstance)
if cfg.Replica.URL != "" { if cfg.Replica != nil && cfg.Replica.URL != "" {
dedup[cfg.Replica.Key()] = cfg.Replica if cfg.Replica.APIPath == "" {
cfg.Replica.APIPath = DefaultAPIPath
}
dedup[cfg.Replica.Key()] = *cfg.Replica
} }
for _, replica := range cfg.Replicas { for _, replica := range cfg.Replicas {
if replica.APIPath == "" {
replica.APIPath = DefaultAPIPath
}
if replica.URL != "" { if replica.URL != "" {
dedup[replica.Key()] = replica dedup[replica.Key()] = replica
} }
@@ -47,23 +70,63 @@ func (cfg *Config) UniqueReplicas() []AdGuardInstance {
var r []AdGuardInstance var r []AdGuardInstance
for _, replica := range dedup { for _, replica := range dedup {
if replica.APIPath == "" {
replica.APIPath = DefaultAPIPath
}
r = append(r, replica) r = append(r, replica)
} }
return r return r
} }
// Log the current config
func (cfg *Config) Log(l *zap.SugaredLogger) {
c := cfg.mask()
l.With("config", c).Debug("Using config")
}
func (cfg *Config) mask() *Config {
c := cfg.DeepCopy()
c.Origin.Mask()
if c.Replica != nil {
if c.Replica.URL == "" {
c.Replica = nil
} else {
c.Replica.Mask()
}
}
for i := range c.Replicas {
c.Replicas[i].Mask()
}
c.API.Mask()
return c
}
func (cfg *Config) Init() error {
if err := cfg.Origin.Init(); err != nil {
return err
}
for i := range cfg.Replicas {
replica := &cfg.Replicas[i]
if err := replica.Init(); err != nil {
return err
}
}
return nil
}
// AdGuardInstance AdguardHome config instance // AdGuardInstance AdguardHome config instance
// +k8s:deepcopy-gen=true
type AdGuardInstance struct { type AdGuardInstance struct {
URL string `json:"url" yaml:"url"` URL string `json:"url" yaml:"url" env:"URL"`
APIPath string `json:"apiPath,omitempty" yaml:"apiPath,omitempty"` WebURL string `json:"webURL" yaml:"webURL" env:"WEB_URL"`
Username string `json:"username,omitempty" yaml:"username,omitempty"` APIPath string `json:"apiPath,omitempty" yaml:"apiPath,omitempty" env:"API_PATH"`
Password string `json:"password,omitempty" yaml:"password,omitempty"` Username string `json:"username,omitempty" yaml:"username,omitempty" env:"USERNAME"`
InsecureSkipVerify bool `json:"insecureSkipVerify" yaml:"insecureSkipVerify"` Password string `json:"password,omitempty" yaml:"password,omitempty" env:"PASSWORD"`
AutoSetup bool `json:"autoSetup" yaml:"autoSetup"` Cookie string `json:"cookie,omitempty" yaml:"cookie,omitempty" env:"COOKIE"`
InterfaceName string `json:"interfaceName" yaml:"interfaceName"` InsecureSkipVerify bool `json:"insecureSkipVerify" yaml:"insecureSkipVerify" env:"INSECURE_SKIP_VERIFY"`
AutoSetup bool `json:"autoSetup" yaml:"autoSetup" env:"AUTO_SETUP"`
InterfaceName string `json:"interfaceName,omitempty" yaml:"interfaceName,omitempty" env:"INTERFACE_NAME"`
DHCPServerEnabled *bool `json:"dhcpServerEnabled,omitempty" yaml:"dhcpServerEnabled,omitempty" env:"DHCP_SERVER_ENABLED"`
Host string `json:"-" yaml:"-"`
WebHost string `json:"-" yaml:"-"`
} }
// Key AdGuardInstance key // Key AdGuardInstance key
@@ -71,313 +134,45 @@ func (i *AdGuardInstance) Key() string {
return fmt.Sprintf("%s#%s", i.URL, i.APIPath) return fmt.Sprintf("%s#%s", i.URL, i.APIPath)
} }
// Mask maks username and password
func (i *AdGuardInstance) Mask() {
i.Username = mask(i.Username)
i.Password = mask(i.Password)
}
func (i *AdGuardInstance) Init() error {
u, err := url.Parse(i.URL)
if err != nil {
return err
}
i.Host = u.Host
if i.WebURL == "" {
i.WebHost = i.Host
i.WebURL = i.URL
} else {
u, err := url.Parse(i.WebURL)
if err != nil {
return err
}
i.WebHost = u.Host
}
return nil
}
func mask(s string) string {
if s == "" {
return "***"
}
mask := strings.Repeat("*", len(s)-2)
return fmt.Sprintf("%v%s%v", string(s[0]), mask, string(s[len(s)-1]))
}
// Protection API struct // Protection API struct
type Protection struct { type Protection struct {
ProtectionEnabled bool `json:"protection_enabled"` ProtectionEnabled bool `json:"protection_enabled"`
} }
// Status API struct
type Status struct {
Protection
DNSAddresses []string `json:"dns_addresses"`
DNSPort int `json:"dns_port"`
HTTPPort int `json:"http_port"`
DhcpAvailable bool `json:"dhcp_available"`
Running bool `json:"running"`
Version string `json:"version"`
Language string `json:"language"`
}
// RewriteEntries list of RewriteEntry
type RewriteEntries []RewriteEntry
// Merge RewriteEntries
func (rwe *RewriteEntries) Merge(other *RewriteEntries) (RewriteEntries, RewriteEntries, RewriteEntries) {
current := make(map[string]RewriteEntry)
var adds RewriteEntries
var removes RewriteEntries
var duplicates RewriteEntries
processed := make(map[string]bool)
for _, rr := range *rwe {
if _, ok := processed[rr.Key()]; !ok {
current[rr.Key()] = rr
processed[rr.Key()] = true
} else {
// remove duplicate
removes = append(removes, rr)
}
}
for _, rr := range *other {
if _, ok := current[rr.Key()]; ok {
delete(current, rr.Key())
} else {
if _, ok := processed[rr.Key()]; !ok {
adds = append(adds, rr)
processed[rr.Key()] = true
} else {
// skip duplicate
duplicates = append(duplicates, rr)
}
}
}
for _, rr := range current {
removes = append(removes, rr)
}
return adds, removes, duplicates
}
// RewriteEntry API struct
type RewriteEntry struct {
Domain string `json:"domain"`
Answer string `json:"answer"`
}
// Key RewriteEntry key
func (re *RewriteEntry) Key() string {
return fmt.Sprintf("%s#%s", re.Domain, re.Answer)
}
// Filters list of Filter
type Filters []Filter
// Merge merge Filters
func (f Filters) Merge(other Filters) (Filters, Filters, Filters) {
current := make(map[string]Filter)
var adds Filters
var updates Filters
var removes Filters
for _, f := range f {
current[f.URL] = f
}
for i := range other {
rr := other[i]
if c, ok := current[rr.URL]; ok {
if !c.Equals(&rr) {
updates = append(updates, rr)
}
delete(current, rr.URL)
} else {
adds = append(adds, rr)
}
}
for _, rr := range current {
removes = append(removes, rr)
}
return adds, updates, removes
}
// Filter API struct
type Filter struct {
ID int `json:"id"`
Enabled bool `json:"enabled"`
URL string `json:"url"` // needed for add
Name string `json:"name"` // needed for add
RulesCount int `json:"rules_count"`
Whitelist bool `json:"whitelist"` // needed for add
}
// Equals Filter equal check
func (f *Filter) Equals(o *Filter) bool {
return f.Enabled == o.Enabled && f.URL == o.URL && f.Name == o.Name
}
// FilterUpdate API struct
type FilterUpdate struct {
URL string `json:"url"`
Data Filter `json:"data"`
Whitelist bool `json:"whitelist"`
}
// FilteringStatus API struct
type FilteringStatus struct {
FilteringConfig
Filters Filters `json:"filters"`
WhitelistFilters Filters `json:"whitelist_filters"`
UserRules UserRules `json:"user_rules"`
}
// UserRules API struct
type UserRules []string
// String toString of Users
func (ur UserRules) String() string {
return strings.Join(ur, "\n")
}
// ToPayload return the version specific payload for user rules
func (ur UserRules) ToPayload(version string) interface{} {
if versions.IsNewerThan(version, versions.LastStringCustomRules) {
return &UserRulesRequest{Rules: ur}
}
return ur.String()
}
// UserRulesRequest API struct
type UserRulesRequest struct {
Rules UserRules
}
// String toString of Users
func (ur UserRulesRequest) String() string {
return ur.Rules.String()
}
// EnableConfig API struct
type EnableConfig struct {
Enabled bool `json:"enabled"`
}
// IntervalConfig API struct
type IntervalConfig struct {
Interval float64 `json:"interval"`
}
// FilteringConfig API struct
type FilteringConfig struct {
EnableConfig
IntervalConfig
}
// QueryLogConfig API struct
type QueryLogConfig struct {
EnableConfig
IntervalConfig
AnonymizeClientIP bool `json:"anonymize_client_ip"`
}
// Equals QueryLogConfig equal check
func (qlc *QueryLogConfig) Equals(o *QueryLogConfig) bool {
return qlc.Enabled == o.Enabled && qlc.AnonymizeClientIP == o.AnonymizeClientIP && qlc.Interval == o.Interval
}
// RefreshFilter API struct
type RefreshFilter struct {
Whitelist bool `json:"whitelist"`
}
// Services API struct
type Services []string
// Sort sort Services
func (s Services) Sort() {
sort.Strings(s)
}
// Equals Services equal check
func (s Services) Equals(o Services) bool {
s.Sort()
o.Sort()
return equals(s, o)
}
// Clients API struct
type Clients struct {
Clients []Client `json:"clients"`
AutoClients []struct {
IP string `json:"ip"`
Name string `json:"name"`
Source string `json:"source"`
WhoisInfo struct{} `json:"whois_info"`
} `json:"auto_clients"`
SupportedTags []string `json:"supported_tags"`
}
// Client API struct
type Client struct {
Ids []string `json:"ids,omitempty"`
Tags []string `json:"tags,omitempty"`
BlockedServices []string `json:"blocked_services,omitempty"`
Upstreams []string `json:"upstreams,omitempty"`
UseGlobalSettings bool `json:"use_global_settings"`
UseGlobalBlockedServices bool `json:"use_global_blocked_services"`
Name string `json:"name"`
FilteringEnabled bool `json:"filtering_enabled"`
ParentalEnabled bool `json:"parental_enabled"`
SafesearchEnabled bool `json:"safesearch_enabled"`
SafebrowsingEnabled bool `json:"safebrowsing_enabled"`
Disallowed bool `json:"disallowed"`
DisallowedRule string `json:"disallowed_rule"`
}
// Sort sort clients
func (cl *Client) Sort() {
sort.Strings(cl.Ids)
sort.Strings(cl.Tags)
sort.Strings(cl.BlockedServices)
sort.Strings(cl.Upstreams)
}
// Equals Clients equal check
func (cl *Client) Equals(o *Client) bool {
cl.Sort()
o.Sort()
a, _ := json.Marshal(cl)
b, _ := json.Marshal(o)
return string(a) == string(b)
}
// Merge merge Clients
func (clients *Clients) Merge(other *Clients) ([]Client, []Client, []Client) {
current := make(map[string]Client)
for _, client := range clients.Clients {
current[client.Name] = client
}
expected := make(map[string]Client)
for _, client := range other.Clients {
expected[client.Name] = client
}
var adds []Client
var removes []Client
var updates []Client
for _, cl := range expected {
if oc, ok := current[cl.Name]; ok {
if !cl.Equals(&oc) {
updates = append(updates, cl)
}
delete(current, cl.Name)
} else {
adds = append(adds, cl)
}
}
for _, rr := range current {
removes = append(removes, rr)
}
return adds, updates, removes
}
// ClientUpdate API struct
type ClientUpdate struct {
Name string `json:"name"`
Data Client `json:"data"`
}
func equals(a []string, b []string) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}
// InstallConfig AdguardHome install config // InstallConfig AdguardHome install config
type InstallConfig struct { type InstallConfig struct {
Web InstallPort `json:"web"` Web InstallPort `json:"web"`

View File

@@ -7,7 +7,7 @@ import (
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
) )
func TestTypes(t *testing.T) { func TestSync(t *testing.T) {
RegisterFailHandler(Fail) RegisterFailHandler(Fail)
RunSpecs(t, "Types Suite") RunSpecs(t, "Types Suite")
} }

View File

@@ -1,362 +1,98 @@
package types_test package types
import ( import (
"encoding/json"
"os"
"github.com/bakito/adguardhome-sync/pkg/types"
"github.com/bakito/adguardhome-sync/pkg/versions"
"github.com/google/uuid"
. "github.com/onsi/ginkgo/v2" . "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
) )
var _ = Describe("Types", func() { var _ = Describe("Types", func() {
var (
url string
apiPath string
)
BeforeEach(func() {
url = "https://" + uuid.NewString()
apiPath = "/" + uuid.NewString()
})
Context("FilteringStatus", func() {
It("should correctly parse json", func() {
b, err := os.ReadFile("../..//testdata/filtering-status.json")
fs := &types.FilteringStatus{}
Ω(err).ShouldNot(HaveOccurred())
err = json.Unmarshal(b, fs)
Ω(err).ShouldNot(HaveOccurred())
})
})
Context("Filters", func() {
Context("Merge", func() {
var (
originFilters types.Filters
replicaFilters types.Filters
)
BeforeEach(func() {
originFilters = types.Filters{}
replicaFilters = types.Filters{}
})
It("should add a missing filter", func() {
originFilters = append(originFilters, types.Filter{URL: url})
a, u, d := replicaFilters.Merge(originFilters)
Ω(a).Should(HaveLen(1))
Ω(u).Should(BeEmpty())
Ω(d).Should(BeEmpty())
Ω(a[0].URL).Should(Equal(url))
})
It("should remove additional filter", func() {
replicaFilters = append(replicaFilters, types.Filter{URL: url})
a, u, d := replicaFilters.Merge(originFilters)
Ω(a).Should(BeEmpty())
Ω(u).Should(BeEmpty())
Ω(d).Should(HaveLen(1))
Ω(d[0].URL).Should(Equal(url))
})
It("should update existing filter when enabled differs", func() {
enabled := true
originFilters = append(originFilters, types.Filter{URL: url, Enabled: enabled})
replicaFilters = append(replicaFilters, types.Filter{URL: url, Enabled: !enabled})
a, u, d := replicaFilters.Merge(originFilters)
Ω(a).Should(BeEmpty())
Ω(u).Should(HaveLen(1))
Ω(d).Should(BeEmpty())
Ω(u[0].Enabled).Should(Equal(enabled))
})
It("should update existing filter when name differs", func() {
name1 := uuid.NewString()
name2 := uuid.NewString()
originFilters = append(originFilters, types.Filter{URL: url, Name: name1})
replicaFilters = append(replicaFilters, types.Filter{URL: url, Name: name2})
a, u, d := replicaFilters.Merge(originFilters)
Ω(a).Should(BeEmpty())
Ω(u).Should(HaveLen(1))
Ω(d).Should(BeEmpty())
Ω(u[0].Name).Should(Equal(name1))
})
It("should have no changes", func() {
originFilters = append(originFilters, types.Filter{URL: url})
replicaFilters = append(replicaFilters, types.Filter{URL: url})
a, u, d := replicaFilters.Merge(originFilters)
Ω(a).Should(BeEmpty())
Ω(u).Should(BeEmpty())
Ω(d).Should(BeEmpty())
})
})
})
Context("AdGuardInstance", func() { Context("AdGuardInstance", func() {
It("should build a key with url and api apiPath", func() { var inst AdGuardInstance
i := &types.AdGuardInstance{URL: url, APIPath: apiPath}
Ω(i.Key()).Should(Equal(url + "#" + apiPath)) BeforeEach(func() {
inst = AdGuardInstance{}
}) })
}) Context("Instance Init", func() {
Context("RewriteEntry", func() {
It("should build a key with url and api apiPath", func() {
domain := uuid.NewString()
answer := uuid.NewString()
re := &types.RewriteEntry{Domain: domain, Answer: answer}
Ω(re.Key()).Should(Equal(domain + "#" + answer))
})
})
Context("QueryLogConfig", func() {
Context("Equal", func() {
var (
a *types.QueryLogConfig
b *types.QueryLogConfig
)
BeforeEach(func() { BeforeEach(func() {
a = &types.QueryLogConfig{} inst.URL = "https://localhost:3000"
b = &types.QueryLogConfig{}
}) })
It("should be equal", func() { It("should correctly set Host and WebHost if only URL is set", func() {
a.Enabled = true err := inst.Init()
a.Interval = 1 Ω(err).ShouldNot(HaveOccurred())
a.AnonymizeClientIP = true Ω(inst.Host).Should(Equal("localhost:3000"))
b.Enabled = true Ω(inst.WebHost).Should(Equal("localhost:3000"))
b.Interval = 1 Ω(inst.URL).Should(Equal("https://localhost:3000"))
b.AnonymizeClientIP = true Ω(inst.WebURL).Should(Equal("https://localhost:3000"))
Ω(a.Equals(b)).Should(BeTrue())
}) })
It("should not be equal when enabled differs", func() { It("should correctly set Host and WebHost if URL and WebURL are set", func() {
a.Enabled = true inst.WebURL = "https://127.0.0.1:4000"
b.Enabled = false err := inst.Init()
Ω(a.Equals(b)).ShouldNot(BeTrue()) Ω(err).ShouldNot(HaveOccurred())
Ω(inst.Host).Should(Equal("localhost:3000"))
Ω(inst.WebHost).Should(Equal("127.0.0.1:4000"))
Ω(inst.WebURL).Should(Equal(inst.WebURL))
Ω(inst.URL).Should(Equal("https://localhost:3000"))
Ω(inst.WebURL).Should(Equal("https://127.0.0.1:4000"))
}) })
It("should not be equal when interval differs", func() {
a.Interval = 1
b.Interval = 2
Ω(a.Equals(b)).ShouldNot(BeTrue())
})
It("should not be equal when anonymizeClientIP differs", func() {
a.AnonymizeClientIP = true
b.AnonymizeClientIP = false
Ω(a.Equals(b)).ShouldNot(BeTrue())
})
})
})
Context("RewriteEntries", func() {
Context("Merge", func() {
var (
originRE types.RewriteEntries
replicaRE types.RewriteEntries
domain string
)
BeforeEach(func() {
originRE = types.RewriteEntries{}
replicaRE = types.RewriteEntries{}
domain = uuid.NewString()
})
It("should add a missing rewrite entry", func() {
originRE = append(originRE, types.RewriteEntry{Domain: domain})
a, r, d := replicaRE.Merge(&originRE)
Ω(a).Should(HaveLen(1))
Ω(r).Should(BeEmpty())
Ω(d).Should(BeEmpty())
Ω(a[0].Domain).Should(Equal(domain))
})
It("should remove additional ewrite entry", func() {
replicaRE = append(replicaRE, types.RewriteEntry{Domain: domain})
a, r, d := replicaRE.Merge(&originRE)
Ω(a).Should(BeEmpty())
Ω(r).Should(HaveLen(1))
Ω(d).Should(BeEmpty())
Ω(r[0].Domain).Should(Equal(domain))
})
It("should have no changes", func() {
originRE = append(originRE, types.RewriteEntry{Domain: domain})
replicaRE = append(replicaRE, types.RewriteEntry{Domain: domain})
a, r, d := replicaRE.Merge(&originRE)
Ω(a).Should(BeEmpty())
Ω(r).Should(BeEmpty())
Ω(d).Should(BeEmpty())
})
It("should remove target duplicate", func() {
originRE = append(originRE, types.RewriteEntry{Domain: domain})
replicaRE = append(replicaRE, types.RewriteEntry{Domain: domain})
replicaRE = append(replicaRE, types.RewriteEntry{Domain: domain})
a, r, d := replicaRE.Merge(&originRE)
Ω(a).Should(BeEmpty())
Ω(r).Should(HaveLen(1))
Ω(d).Should(BeEmpty())
})
It("should remove target duplicate", func() {
originRE = append(originRE, types.RewriteEntry{Domain: domain})
originRE = append(originRE, types.RewriteEntry{Domain: domain})
replicaRE = append(replicaRE, types.RewriteEntry{Domain: domain})
a, r, d := replicaRE.Merge(&originRE)
Ω(a).Should(BeEmpty())
Ω(r).Should(BeEmpty())
Ω(d).Should(HaveLen(1))
})
})
})
Context("UserRules", func() {
It("should join the rules correctly", func() {
r1 := uuid.NewString()
r2 := uuid.NewString()
ur := types.UserRules([]string{r1, r2})
Ω(ur.String()).Should(Equal(r1 + "\n" + r2))
})
It("should return a string for versions <= "+versions.LastStringCustomRules, func() {
r1 := uuid.NewString()
r2 := uuid.NewString()
pl := types.UserRules([]string{r1, r2}).ToPayload(versions.LastStringCustomRules)
Ω(pl).Should(BeAssignableToTypeOf(""))
})
It("should return a struct for versions > "+versions.IncompatibleAPI, func() {
r1 := uuid.NewString()
r2 := uuid.NewString()
pl := types.UserRules([]string{r1, r2}).ToPayload(versions.FixedIncompatibleAPI)
Ω(pl).Should(BeAssignableToTypeOf(&types.UserRulesRequest{}))
})
})
Context("UserRulesRequest", func() {
It("should join the rules correctly", func() {
r1 := uuid.NewString()
r2 := uuid.NewString()
urr := types.UserRulesRequest{Rules: []string{r1, r2}}
Ω(urr.String()).Should(Equal(r1 + "\n" + r2))
}) })
}) })
Context("Config", func() { Context("Config", func() {
var cfg *types.Config Context("init", func() {
BeforeEach(func() { cfg := Config{
cfg = &types.Config{} Replicas: []AdGuardInstance{
{URL: "https://localhost:3000"},
},
}
err := cfg.Init()
Ω(err).ShouldNot(HaveOccurred())
Ω(cfg.Replicas[0].Host).Should(Equal("localhost:3000"))
Ω(cfg.Replicas[0].WebHost).Should(Equal("localhost:3000"))
Ω(cfg.Replicas[0].URL).Should(Equal("https://localhost:3000"))
Ω(cfg.Replicas[0].WebURL).Should(Equal("https://localhost:3000"))
}) })
Context("UniqueReplicas", func() { Context("UniqueReplicas", func() {
It("should be empty if noting defined", func() { It("should return unique replicas in the array", func() {
r := cfg.UniqueReplicas() cfg := Config{
Ω(r).Should(BeEmpty()) Replicas: []AdGuardInstance{
{URL: "a"},
{URL: "a", APIPath: DefaultAPIPath},
{URL: "a", APIPath: "foo"},
{URL: "b", APIPath: DefaultAPIPath},
},
Replica: &AdGuardInstance{URL: "b"},
}
replicas := cfg.UniqueReplicas()
Ω(replicas).Should(HaveLen(3))
}) })
It("should be empty if replica url is not set", func() { })
cfg.Replica = types.AdGuardInstance{URL: ""} Context("mask", func() {
r := cfg.UniqueReplicas() It("should mask all names and passwords", func() {
Ω(r).Should(BeEmpty()) cfg := Config{
}) Replicas: []AdGuardInstance{
It("should be empty if replicas url is not set", func() { {URL: "a", Username: "user", Password: "pass"},
cfg.Replicas = []types.AdGuardInstance{{URL: ""}} },
r := cfg.UniqueReplicas() Replica: &AdGuardInstance{URL: "a", Username: "user", Password: "pass"},
Ω(r).Should(BeEmpty()) API: API{Username: "user", Password: "pass"},
}) }
It("should return only one replica if same url and apiPath", func() { masked := cfg.mask()
cfg.Replica = types.AdGuardInstance{URL: url, APIPath: apiPath} Ω(masked.Replicas[0].Username).Should(Equal("u**r"))
cfg.Replicas = []types.AdGuardInstance{{URL: url, APIPath: apiPath}, {URL: url, APIPath: apiPath}} Ω(masked.Replicas[0].Password).Should(Equal("p**s"))
r := cfg.UniqueReplicas() Ω(masked.Replica.Username).Should(Equal("u**r"))
Ω(r).Should(HaveLen(1)) Ω(masked.Replica.Password).Should(Equal("p**s"))
}) Ω(masked.API.Username).Should(Equal("u**r"))
It("should return 3 one replicas if urls are different", func() { Ω(masked.API.Password).Should(Equal("p**s"))
cfg.Replica = types.AdGuardInstance{URL: url, APIPath: apiPath}
cfg.Replicas = []types.AdGuardInstance{{URL: url + "1", APIPath: apiPath}, {URL: url, APIPath: apiPath + "1"}}
r := cfg.UniqueReplicas()
Ω(r).Should(HaveLen(3))
})
It("should set default api apiPath if not set", func() {
cfg.Replica = types.AdGuardInstance{URL: url}
cfg.Replicas = []types.AdGuardInstance{{URL: url + "1"}}
r := cfg.UniqueReplicas()
Ω(r).Should(HaveLen(2))
Ω(r[0].APIPath).Should(Equal(types.DefaultAPIPath))
Ω(r[1].APIPath).Should(Equal(types.DefaultAPIPath))
}) })
}) })
}) })
Context("Feature", func() {
Context("Clients", func() { Context("LogDisabled", func() {
Context("Merge", func() { It("should log all features", func() {
var ( f := NewFeatures(false)
originClients *types.Clients Ω(f.collectDisabled()).Should(HaveLen(11))
replicaClients types.Clients
name string
)
BeforeEach(func() {
originClients = &types.Clients{}
replicaClients = types.Clients{}
name = uuid.NewString()
}) })
It("should log no features", func() {
It("should add a missing client", func() { f := NewFeatures(true)
originClients.Clients = append(originClients.Clients, types.Client{Name: name}) Ω(f.collectDisabled()).Should(BeEmpty())
a, u, d := replicaClients.Merge(originClients)
Ω(a).Should(HaveLen(1))
Ω(u).Should(BeEmpty())
Ω(d).Should(BeEmpty())
Ω(a[0].Name).Should(Equal(name))
})
It("should remove additional client", func() {
replicaClients.Clients = append(replicaClients.Clients, types.Client{Name: name})
a, u, d := replicaClients.Merge(originClients)
Ω(a).Should(BeEmpty())
Ω(u).Should(BeEmpty())
Ω(d).Should(HaveLen(1))
Ω(d[0].Name).Should(Equal(name))
})
It("should update existing client when name differs", func() {
disallowed := true
originClients.Clients = append(originClients.Clients, types.Client{Name: name, Disallowed: disallowed})
replicaClients.Clients = append(replicaClients.Clients, types.Client{Name: name, Disallowed: !disallowed})
a, u, d := replicaClients.Merge(originClients)
Ω(a).Should(BeEmpty())
Ω(u).Should(HaveLen(1))
Ω(d).Should(BeEmpty())
Ω(u[0].Disallowed).Should(Equal(disallowed))
})
})
})
Context("Services", func() {
Context("Equals", func() {
It("should be equal", func() {
s1 := types.Services([]string{"a", "b"})
s2 := types.Services([]string{"b", "a"})
Ω(s1.Equals(s2)).Should(BeTrue())
})
It("should not be equal different values", func() {
s1 := types.Services([]string{"a", "b"})
s2 := types.Services([]string{"B", "a"})
Ω(s1.Equals(s2)).ShouldNot(BeTrue())
})
It("should not be equal different length", func() {
s1 := types.Services([]string{"a", "b"})
s2 := types.Services([]string{"b", "a", "c"})
Ω(s1.Equals(s2)).ShouldNot(BeTrue())
})
})
})
Context("DNSConfig", func() {
Context("Equals", func() {
It("should be equal", func() {
dc1 := &types.DNSConfig{Upstreams: []string{"a"}}
dc2 := &types.DNSConfig{Upstreams: []string{"a"}}
Ω(dc1.Equals(dc2)).Should(BeTrue())
})
It("should not be equal", func() {
dc1 := &types.DNSConfig{Upstreams: []string{"a"}}
dc2 := &types.DNSConfig{Upstreams: []string{"b"}}
Ω(dc1.Equals(dc2)).ShouldNot(BeTrue())
}) })
}) })
}) })

15
pkg/utils/clone.go Normal file
View File

@@ -0,0 +1,15 @@
package utils
import "encoding/json"
func Clone[I interface{}](in I, out I) I {
b, _ := json.Marshal(in)
_ = json.Unmarshal(b, out)
return out
}
func JsonEquals(a interface{}, b interface{}) bool {
ja, _ := json.Marshal(a)
jb, _ := json.Marshal(b)
return string(ja) == string(jb)
}

14
pkg/utils/ptr.go Normal file
View File

@@ -0,0 +1,14 @@
package utils
import "fmt"
func Ptr[I interface{}](i I) *I {
return &i
}
func PtrToString[I interface{}](i *I) string {
if i == nil {
return ""
}
return fmt.Sprintf("%v", i)
}

View File

@@ -4,22 +4,20 @@ import "golang.org/x/mod/semver"
const ( const (
// MinAgh minimal adguardhome version // MinAgh minimal adguardhome version
MinAgh = "v0.107.0" MinAgh = "v0.107.40"
// LastStringCustomRules last adguardhome version with string payload custom rules
// https://github.com/bakito/adguardhome-sync/issues/99
LastStringCustomRules = "v0.107.13"
// IncompatibleAPI adguardhome version with incompatible API
// https://github.com/bakito/adguardhome-sync/issues/99
IncompatibleAPI = "v0.107.14"
// FixedIncompatibleAPI adguardhome version with fixed API
// https://github.com/bakito/adguardhome-sync/issues/99
FixedIncompatibleAPI = "v0.107.15"
) )
func IsNewerThan(v1 string, v2 string) bool { func IsNewerThan(v1 string, v2 string) bool {
return semver.Compare(v1, v2) == 1 return semver.Compare(sanitize(v1), sanitize(v2)) == 1
} }
func IsSame(v1 string, v2 string) bool { func IsSame(v1 string, v2 string) bool {
return semver.Compare(v1, v2) == 0 return semver.Compare(sanitize(v1), sanitize(v2)) == 0
}
func sanitize(v string) string {
if v == "" || v[0] == 'v' {
return v
}
return "v" + v
} }

View File

@@ -0,0 +1,13 @@
package versions_test
import (
"testing"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
func TestTypes(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Types Suite")
}

View File

@@ -0,0 +1,24 @@
package versions_test
import (
"github.com/bakito/adguardhome-sync/pkg/versions"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Versions", func() {
Context("IsNewerThan", func() {
It("should correctly parse json", func() {
Ω(versions.IsNewerThan("v0.106.10", "v0.106.9")).Should(BeTrue())
Ω(versions.IsNewerThan("v0.106.9", "v0.106.10")).Should(BeFalse())
Ω(versions.IsNewerThan("v0.106.10", "0.106.9")).Should(BeTrue())
Ω(versions.IsNewerThan("v0.106.9", "0.106.10")).Should(BeFalse())
})
})
Context("IsSame", func() {
It("should be the same version", func() {
Ω(versions.IsSame("v0.106.9", "v0.106.9")).Should(BeTrue())
Ω(versions.IsSame("0.106.9", "v0.106.9")).Should(BeTrue())
})
})
})

2
testdata/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
docker-compose.yaml
!config_test_*.yaml

View File

@@ -0,0 +1,22 @@
{
"schedule": {
"time_zone": "Europe/Zurich",
"tue": {
"start": 0,
"end": 86340000
},
"thu": {
"start": 0,
"end": 86340000
},
"sat": {
"start": 0,
"end": 35940000
}
},
"ids": [
"9gag",
"dailymotion",
"disneyplus"
]
}

37
testdata/config_test_replica.yaml vendored Normal file
View File

@@ -0,0 +1,37 @@
origin:
url: https://origin-file:443
webURL: https://origin-file:443
apiPath: /control
username: foo
password: '*********'
insecureSkipVerify: true
autoSetup: false
replica:
url: https://replica-file:443
webURL: https://replica-file:443
apiPath: /control
username: bar
password: '*********'
insecureSkipVerify: false
autoSetup: false
interfaceName: eth3
dhcpServerEnabled: false
cron: '*/15 * * * *'
runOnStart: true
printConfigOnly: true
api:
port: 9090
features:
dns:
accessLists: true
serverConfig: false
rewrites: true
dhcp:
serverConfig: true
staticLeases: true
generalSettings: true
queryLogConfig: true
statsConfig: true
clientSettings: true
services: true
filters: true

37
testdata/config_test_replicas.yaml vendored Normal file
View File

@@ -0,0 +1,37 @@
origin:
url: https://origin-file:443
webURL: https://origin-file:443
apiPath: /control
username: foo
password: '*********'
insecureSkipVerify: true
autoSetup: false
replicas:
- url: https://replica-file:443
webURL: https://replica-file:443
apiPath: /control
username: bar
password: '*********'
insecureSkipVerify: false
autoSetup: false
interfaceName: eth3
dhcpServerEnabled: false
cron: '*/15 * * * *'
runOnStart: true
printConfigOnly: true
api:
port: 9090
features:
dns:
accessLists: true
serverConfig: false
rewrites: true
dhcp:
serverConfig: true
staticLeases: true
generalSettings: true
queryLogConfig: true
statsConfig: true
clientSettings: true
services: true
filters: true

View File

@@ -0,0 +1,47 @@
origin:
url: https://origin-file:443
webURL: https://origin-file:443
apiPath: /control
username: foo
password: '*********'
insecureSkipVerify: true
autoSetup: false
replica:
url: https://replica-file:443
webURL: https://replica-file:443
apiPath: /control
username: bar
password: '*********'
insecureSkipVerify: false
autoSetup: false
interfaceName: eth3
dhcpServerEnabled: false
replicas:
- url: https://replicas-file:443
webURL: https://replicas-file:443
apiPath: /control
username: bar
password: '*********'
insecureSkipVerify: false
autoSetup: false
interfaceName: eth3
dhcpServerEnabled: false
cron: '*/15 * * * *'
runOnStart: true
printConfigOnly: true
api:
port: 9090
features:
dns:
accessLists: true
serverConfig: false
rewrites: true
dhcp:
serverConfig: true
staticLeases: true
generalSettings: true
queryLogConfig: true
statsConfig: true
clientSettings: true
services: true
filters: true

4
testdata/e2e/bin/build-image.sh vendored Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/bash
set -e
docker build -f Dockerfile --build-arg VERSION=e2e-tests -t localhost:5001/adguardhome-sync:e2e .
docker push localhost:5001/adguardhome-sync:e2e

View File

@@ -6,4 +6,4 @@ kubectl config set-context --current --namespace=agh-e2e
if [[ $(helm list --no-headers -n agh-e2e | grep agh-e2e | wc -l) == "1" ]]; then if [[ $(helm list --no-headers -n agh-e2e | grep agh-e2e | wc -l) == "1" ]]; then
helm delete agh-e2e -n agh-e2e --wait helm delete agh-e2e -n agh-e2e --wait
fi fi
helm install agh-e2e testdata/e2e -n agh-e2e --create-namespace helm install agh-e2e testdata/e2e -n agh-e2e --create-namespace --set mode=${1}

View File

@@ -0,0 +1,6 @@
#!/bin/bash
set -e
echo "## AdGuardHome.yaml of latest replica" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
kubectl exec adguardhome-replica-latest -- cat /opt/adguardhome/conf/AdGuardHome.yaml >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY

View File

@@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
set -e set -e
echo Pod adguardhome-origin logs echo "## Pod adguardhome-origin logs" >> $GITHUB_STEP_SUMMARY
kubectl logs adguardhome-origin echo '```' >> $GITHUB_STEP_SUMMARY
kubectl logs adguardhome-origin >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY

View File

@@ -2,9 +2,17 @@
set -e set -e
for pod in $(kubectl get pods -l bakito.net/adguardhome-sync=replica -o name); do for pod in $(kubectl get pods -l bakito.net/adguardhome-sync=replica -o name); do
echo Pod "${pod} logs" echo "## Pod ${pod} logs" >> $GITHUB_STEP_SUMMARY
kubectl logs ${pod} echo '```' >> $GITHUB_STEP_SUMMARY
ERRORS=$(kubectl logs ${pod} | grep '\[error\]' | wc -l) LOGS=$(kubectl logs ${pod})
echo "Found ${ERRORS} error(s) in log" # ignore certain errors
echo "----------------------------------------------" LOGS=$(echo -e "${LOGS}" | grep -v -e "error.* deleting filter .* no such file or directory" )
# https://github.com/AdguardTeam/AdGuardHome/issues/4944
LOGS=$(echo -e "${LOGS}" | grep -v -e "error.* creating dhcpv4 srv")
echo -e "${LOGS}" >> $GITHUB_STEP_SUMMARY
ERRORS=$(echo -e "${LOGS}"} | grep '\[error\]' | wc -l)
echo '```' >> $GITHUB_STEP_SUMMARY
echo "Found ${ERRORS} error(s) in ${pod} log" >> $GITHUB_STEP_SUMMARY
echo "----------------------------------------------" >> $GITHUB_STEP_SUMMARY
done done

View File

@@ -1,8 +1,10 @@
#!/bin/bash #!/bin/bash
set -e set -e
echo Pod adguardhome-sync logs echo "## Pod adguardhome-sync logs" >> $GITHUB_STEP_SUMMARY
kubectl logs adguardhome-sync echo '```' >> $GITHUB_STEP_SUMMARY
kubectl logs adguardhome-sync >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
ERRORS=$(kubectl logs adguardhome-sync | grep Error | wc -l) ERRORS=$(kubectl logs adguardhome-sync | grep Error | wc -l)
echo "Found ${ERRORS} error(s) in log"; echo "Found ${ERRORS} error(s) in adguardhome-sync log"; >> $GITHUB_STEP_SUMMARY
if [[ "${ERRORS}" != "0" ]]; then exit 1; fi if [[ "${ERRORS}" != "0" ]]; then exit 1; fi

11
testdata/e2e/bin/show-sync-metrics.sh vendored Executable file
View File

@@ -0,0 +1,11 @@
#!/bin/bash
set -e
echo "wait another scrape interval (30s)"
sleep 30
echo "## Pod adguardhome-sync metrics" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
curl http://localhost:9090/metrics -s >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY

View File

@@ -1,4 +1,14 @@
#!/bin/bash #!/bin/bash
set -e
kubectl wait --for=jsonpath='{.status.phase}'=Succeeded pod/adguardhome-sync --timeout=1m kubectl wait --for=jsonpath='{.status.phase}'=Running pod/adguardhome-sync --timeout=1m
kubectl port-forward pod/adguardhome-sync 9090:9090 &
for i in {1..6}; do
sleep 10
RUNNING=$(curl http://localhost:9090/api/v1/status -s | jq -r .syncRunning)
echo "SyncRunning = ${RUNNING}"
if [[ "${RUNNING}" == "false" ]]; then
exit 0
fi
done

206
testdata/e2e/resources/AdGuardHome.yaml vendored Normal file
View File

@@ -0,0 +1,206 @@
http:
pprof:
port: 6060
enabled: false
address: 0.0.0.0:3000
session_ttl: 720h
users:
- name: username
password: $2a$10$yrrX.EvDpUUnZxr74u6euOMeF6dPFd/mEyohDq1LkpH76JyeObPBm
auth_attempts: 5
block_auth_min: 15
http_proxy: ""
language: en
theme: auto
dns:
bind_hosts:
- 0.0.0.0
port: 53
anonymize_client_ip: false
ratelimit: 20
ratelimit_whitelist: [ ]
refuse_any: true
upstream_dns:
- https://dns10.quad9.net/dns-query
upstream_dns_file: ""
bootstrap_dns:
- 1.1.1.1:53
fallback_dns: [ ]
all_servers: false
fastest_addr: false
fastest_timeout: 1s
allowed_clients: [ ]
disallowed_clients: [ ]
blocked_hosts:
- version.bind
- id.server
- hostname.bind
trusted_proxies:
- 127.0.0.0/8
- ::1/128
cache_size: 4194304
cache_ttl_min: 0
cache_ttl_max: 0
cache_optimistic: true
bogus_nxdomain: [ ]
aaaa_disabled: false
enable_dnssec: false
edns_client_subnet:
custom_ip: ""
enabled: false
use_custom: false
max_goroutines: 300
handle_ddr: true
ipset: [ ]
ipset_file: ""
bootstrap_prefer_ipv6: false
upstream_timeout: 10s
private_networks: [ ]
use_private_ptr_resolvers: true
local_ptr_upstreams: [ ]
use_dns64: false
dns64_prefixes: [ ]
serve_http3: false
use_http3_upstreams: false
tls:
enabled: false
server_name: ""
force_https: false
port_https: 443
port_dns_over_tls: 853
port_dns_over_quic: 853
port_dnscrypt: 0
dnscrypt_config_file: ""
allow_unencrypted_doh: false
certificate_chain: ""
private_key: ""
certificate_path: ""
private_key_path: ""
strict_sni_check: false
querylog:
ignored: [ ]
interval: 6h
size_memory: 1000
enabled: true
file_enabled: true
statistics:
ignored: [ ]
interval: 24h
enabled: true
filters:
- enabled: true
url: https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt
name: AdGuard DNS filter
id: 1
- enabled: true
url: https://adaway.org/hosts.txt
name: AdAway Default Blocklist
id: 2
whitelist_filters: [ ]
user_rules:
- '||metrics2.data.hicloud.com^$important'
- '||www.curiouscorrespondence.com^$important'
- '||bluewizard.com^$important'
- '||facebook.com^$important'
dhcp:
enabled: false
interface_name: eth0
local_domain_name: lan
dhcpv4:
gateway_ip: 1.2.3.4
subnet_mask: 255.255.0.0
range_start: 1.2.3.5
range_end: 1.2.3.56
lease_duration: 86400
icmp_timeout_msec: 1000
options: [ ]
dhcpv6:
range_start: ""
lease_duration: 86400
ra_slaac_only: false
ra_allow_slaac: false
filtering:
blocking_ipv4: ""
blocking_ipv6: ""
blocked_services:
schedule:
time_zone: Europe/Zurich
tue:
start: 0s
end: 23h59m
thu:
start: 0s
end: 23h59m
sat:
start: 0s
end: 9h59m
ids:
- 9gag
- dailymotion
- disneyplus
protection_disabled_until: null
safe_search:
enabled: true
bing: true
duckduckgo: true
google: true
pixabay: true
yandex: true
youtube: true
blocking_mode: default
parental_block_host: family-block.dns.adguard.com
safebrowsing_block_host: standard-block.dns.adguard.com
rewrites: [ ]
safebrowsing_cache_size: 1048576
safesearch_cache_size: 1048576
parental_cache_size: 1048576
cache_time: 30
filters_update_interval: 24
blocked_response_ttl: 10
filtering_enabled: true
parental_enabled: true
safebrowsing_enabled: true
protection_enabled: true
clients:
runtime_sources:
whois: true
arp: true
rdns: true
dhcp: true
hosts: true
persistent:
- name: Device 1
tags:
- device_1
ids:
- 2.2.2.2
blocked_services:
schedule:
time_zone: Europe/Zurich
ids:
- facebook
- mail_ru
- qq
- vk
- ok
upstreams: [ ]
use_global_settings: true
filtering_enabled: false
parental_enabled: false
safebrowsing_enabled: false
use_global_blocked_services: false
ignore_querylog: false
ignore_statistics: false
log:
file: ""
max_backups: 0
max_size: 100
max_age: 3
compress: false
local_time: false
verbose: false
os:
group: ""
user: ""
rlimit_nofile: 0
schema_version: 27

4
testdata/e2e/templates/NOTES.txt vendored Normal file
View File

@@ -0,0 +1,4 @@
Installed adguardhome-sync end-2-end test with {{ len .Values.replica.versions }} replica instances.
{{- range $_, $version := .Values.replica.versions }}
- {{ $version }}
{{- end }}

View File

@@ -5,170 +5,4 @@ metadata:
namespace: {{ .Release.Namespace }} namespace: {{ .Release.Namespace }}
data: data:
AdGuardHome.yaml: | AdGuardHome.yaml: |
bind_host: 0.0.0.0 {{- .Files.Get "resources/AdGuardHome.yaml" | nindent 4 }}
bind_port: 3000
beta_bind_port: 0
users:
- name: username
password: $2a$10$yrrX.EvDpUUnZxr74u6euOMeF6dPFd/mEyohDq1LkpH76JyeObPBm
auth_attempts: 5
block_auth_min: 15
http_proxy: ""
language: en
debug_pprof: false
web_session_ttl: 720
dns:
bind_hosts:
- 0.0.0.0
port: 53
statistics_interval: 1
querylog_enabled: true
querylog_file_enabled: true
querylog_interval: 6h
querylog_size_memory: 1000
anonymize_client_ip: false
protection_enabled: true
blocking_mode: default
blocking_ipv4: ""
blocking_ipv6: ""
blocked_response_ttl: 10
parental_block_host: family-block.dns.adguard.com
safebrowsing_block_host: standard-block.dns.adguard.com
ratelimit: 20
ratelimit_whitelist: []
refuse_any: true
upstream_dns:
- https://dns10.quad9.net/dns-query
upstream_dns_file: ""
bootstrap_dns:
- 1.1.1.1:53
all_servers: false
fastest_addr: false
fastest_timeout: 1s
allowed_clients: []
disallowed_clients: []
blocked_hosts:
- version.bind
- id.server
- hostname.bind
trusted_proxies:
- 127.0.0.0/8
- ::1/128
cache_size: 4194304
cache_ttl_min: 0
cache_ttl_max: 0
cache_optimistic: true
bogus_nxdomain: []
aaaa_disabled: false
enable_dnssec: false
edns_client_subnet: false
max_goroutines: 300
handle_ddr: true
ipset: []
ipset_file: ""
filtering_enabled: true
filters_update_interval: 12
parental_enabled: true
safesearch_enabled: true
safebrowsing_enabled: true
safebrowsing_cache_size: 1048576
safesearch_cache_size: 1048576
parental_cache_size: 1048576
cache_time: 30
rewrites:
- domain: foo.bar.com
answer: 1.2.3.4
blocked_services:
- 9gag
- dailymotion
upstream_timeout: 10s
private_networks: []
use_private_ptr_resolvers: true
local_ptr_upstreams: []
serve_http3: false
use_http3_upstreams: false
tls:
enabled: false
server_name: ""
force_https: false
port_https: 443
port_dns_over_tls: 853
port_dns_over_quic: 853
port_dnscrypt: 0
dnscrypt_config_file: ""
allow_unencrypted_doh: false
strict_sni_check: false
certificate_chain: ""
private_key: ""
certificate_path: ""
private_key_path: ""
filters:
- enabled: true
url: https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt
name: AdGuard DNS filter
id: 1
- enabled: true
url: https://adaway.org/hosts.txt
name: AdAway Default Blocklist
id: 2
whitelist_filters: []
user_rules:
- '||metrics2.data.hicloud.com^$important'
- '||www.curiouscorrespondence.com^$important'
- '||bluewizard.com^$important'
- '||facebook.com^$important'
dhcp:
enabled: false
interface_name: eth0
local_domain_name: lan
dhcpv4:
gateway_ip: 1.2.3.4
subnet_mask: 255.255.0.0
range_start: 1.2.3.5
range_end: 1.2.3.56
lease_duration: 86400
icmp_timeout_msec: 1000
options: []
dhcpv6:
range_start: ""
lease_duration: 86400
ra_slaac_only: false
ra_allow_slaac: false
clients:
runtime_sources:
whois: true
arp: true
rdns: true
dhcp: true
hosts: true
persistent:
- name: Device 1
tags:
- device_1
ids:
- 2.2.2.2
blocked_services:
- facebook
- ok
- vk
- mail_ru
- qq
upstreams: []
use_global_settings: true
filtering_enabled: false
parental_enabled: false
safesearch_enabled: false
safebrowsing_enabled: false
use_global_blocked_services: false
log_file: ""
log_max_backups: 0
log_max_size: 100
log_max_age: 3
log_compress: false
log_localtime: false
verbose: false
os:
group: ""
user: ""
rlimit_nofile: 0
schema_version: 14

View File

@@ -0,0 +1,21 @@
{{- if eq .Values.mode "env" }}
apiVersion: v1
kind: ConfigMap
metadata:
name: sync-conf
namespace: {{ .Release.Namespace }}
data:
API_PORT: '9090'
API_METRICS_ENABLED: 'true'
API_METRICS_SCRAPE_INTERVAL: '30s'
LOG_FORMAT: 'json'
ORIGIN_URL: 'http://service-origin.{{ $.Release.Namespace }}.svc.cluster.local:3000'
ORIGIN_PASSWORD: 'password'
ORIGIN_USERNAME: 'username'
{{- range $i,$version := .Values.replica.versions }}
REPLICA{{ add 1 $i }}_AUTO_SETUP: 'true'
REPLICA{{ add 1 $i }}_URL: 'http://service-replica-{{ $version | toString | replace "." "-" }}.{{ $.Release.Namespace }}.svc.cluster.local:3000'
REPLICA{{ add 1 $i }}_PASSWORD: 'password'
REPLICA{{ add 1 $i }}_USERNAME: 'username'
{{- end }}
{{- end }}

View File

@@ -0,0 +1,25 @@
{{- if eq .Values.mode "file" }}
apiVersion: v1
kind: ConfigMap
metadata:
name: sync-conf
namespace: {{ .Release.Namespace }}
data:
config.yaml: |
origin:
url: 'http://service-origin.{{ $.Release.Namespace }}.svc.cluster.local:3000'
username: username
password: password
api:
port: 9090
metrics:
enabled: true
scrapeInterval: 30s
replicas:
{{- range $i,$version := .Values.replica.versions }}
- url: 'http://service-replica-{{ $version | toString | replace "." "-" }}.{{ $.Release.Namespace }}.svc.cluster.local:3000'
username: username
password: password
autoSetup: true
{{- end }}
{{- end }}

View File

@@ -1,17 +0,0 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: sync-conf
namespace: {{ .Release.Namespace }}
data:
API_PORT: "0"
LOG_LEVEL: info
ORIGIN_URL: http://service-origin.{{ $.Release.Namespace }}.svc.cluster.local:3000
ORIGIN_PASSWORD: password
ORIGIN_USERNAME: username
{{ range $i,$_ := .Values.replica.versions }}
REPLICA{{ $i }}_AUTOSETUP: "true"
REPLICA{{ $i }}_URL: http://service-replica-{{ $i }}.{{ $.Release.Namespace }}.svc.cluster.local:3000
REPLICA{{ $i }}_PASSWORD: password
REPLICA{{ $i }}_USERNAME: username
{{- end }}

View File

@@ -1,11 +1,11 @@
{{ range $i, $version := .Values.replica.versions }} {{ range $_, $version := .Values.replica.versions }}
apiVersion: v1 apiVersion: v1
kind: Pod kind: Pod
metadata: metadata:
name: adguardhome-replica-{{ $i }} name: adguardhome-replica-{{ $version | toString | replace "." "-" }}
namespace: {{ $.Release.Namespace }} namespace: {{ $.Release.Namespace }}
labels: labels:
app.kubernetes.io/name: adguardhome-replica-{{ $i }} app.kubernetes.io/name: adguardhome-replica-{{ $version | toString | replace "." "-" }}
bakito.net/adguardhome-sync: replica bakito.net/adguardhome-sync: replica
spec: spec:
containers: containers:

View File

@@ -1,3 +1,4 @@
{{- if eq .Values.mode "env" }}
apiVersion: v1 apiVersion: v1
kind: Pod kind: Pod
metadata: metadata:
@@ -7,7 +8,7 @@ spec:
serviceAccountName: agh-e2e serviceAccountName: agh-e2e
initContainers: initContainers:
- name: wait-for-others - name: wait-for-others
image: bitnami/kubectl:1.24 image: {{ .Values.kubectl.repository }}:{{ .Values.kubectl.tag }}
command: command:
- /bin/bash - /bin/bash
- -c - -c
@@ -15,11 +16,15 @@ spec:
{{- .Files.Get "bin/wait-for-agh-pods.sh" | nindent 10}} {{- .Files.Get "bin/wait-for-agh-pods.sh" | nindent 10}}
containers: containers:
- name: adguardhome-sync - name: adguardhome-sync
image: ghcr.io/bakito/adguardhome-sync:main image: localhost:5001/adguardhome-sync:e2e
command: command:
- /opt/go/adguardhome-sync - /opt/go/adguardhome-sync
- run - run
env:
- name: LOG_LEVEL
value: 'debug'
envFrom: envFrom:
- configMapRef: - configMapRef:
name: sync-conf name: sync-conf
restartPolicy: Never restartPolicy: Never
{{- end }}

View File

@@ -0,0 +1,36 @@
{{- if eq .Values.mode "file" }}
apiVersion: v1
kind: Pod
metadata:
name: adguardhome-sync
namespace: {{ $.Release.Namespace }}
spec:
serviceAccountName: agh-e2e
initContainers:
- name: wait-for-others
image: {{ .Values.kubectl.repository }}:{{ .Values.kubectl.tag }}
command:
- /bin/bash
- -c
- |
{{- .Files.Get "bin/wait-for-agh-pods.sh" | nindent 10}}
containers:
- name: adguardhome-sync
image: localhost:5001/adguardhome-sync:e2e
command:
- /opt/go/adguardhome-sync
- run
- '--config'
- /etc/go/adguardhome-sync/config.yaml
env:
- name: LOG_LEVEL
value: 'debug'
volumeMounts:
- name: config
mountPath: /etc/go/adguardhome-sync/
volumes:
- name: config
configMap:
name: sync-conf
restartPolicy: Never
{{- end }}

View File

@@ -3,7 +3,6 @@ kind: ServiceAccount
metadata: metadata:
name: agh-e2e name: agh-e2e
namespace: {{ .Release.Namespace }} namespace: {{ .Release.Namespace }}
--- ---
apiVersion: rbac.authorization.k8s.io/v1 apiVersion: rbac.authorization.k8s.io/v1
@@ -15,7 +14,6 @@ rules:
- apiGroups: [ "" ] - apiGroups: [ "" ]
resources: [ "pods" ] resources: [ "pods" ]
verbs: [ "get", "watch", "list" ] verbs: [ "get", "watch", "list" ]
--- ---
apiVersion: rbac.authorization.k8s.io/v1 apiVersion: rbac.authorization.k8s.io/v1

View File

@@ -1,11 +1,11 @@
{{ range $i ,$_ := .Values.replica.versions }} {{ range $i ,$version := .Values.replica.versions }}
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
name: service-replica-{{ $i }} name: service-replica-{{ $version | toString | replace "." "-" }}
spec: spec:
selector: selector:
app.kubernetes.io/name: adguardhome-replica-{{ $i }} app.kubernetes.io/name: adguardhome-replica-{{ $version | toString | replace "." "-" }}
ports: ports:
- protocol: TCP - protocol: TCP
port: 3000 port: 3000

View File

@@ -1,5 +1,11 @@
replica: replica:
versions: versions:
- v0.107.40
- v0.107.43
- latest - latest
- v0.107.13
- v0.107.15 mode: env
kubectl:
repository: bitnami/kubectl
tag: 1.27

View File

@@ -7,8 +7,7 @@
"enabled": true, "enabled": true,
"url": "https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt", "url": "https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt",
"name": "AdGuard DNS filter", "name": "AdGuard DNS filter",
"rules_count": 37330, "rules_count": 37330
"last_updated": ""
}, },
{ {
"id": 1616956421, "id": 1616956421,
@@ -24,4 +23,4 @@
"||metrics2.data.hicloud.com^$important", "||metrics2.data.hicloud.com^$important",
"" ""
] ]
} }

8
testdata/querylog_config.json vendored Normal file
View File

@@ -0,0 +1,8 @@
{
"enabled": true,
"interval": 90,
"anonymize_client_ip": false,
"ignored": [
"foo.bar"
]
}

Some files were not shown because too many files have changed in this diff Show More