Compare commits
48 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c58a8f091 | ||
|
|
4a62b80e75 | ||
|
|
52c1687d83 | ||
|
|
238a0f46e0 | ||
|
|
bbf5d2d178 | ||
|
|
1c4ea24da1 | ||
|
|
f277460b9d | ||
|
|
15c1643d34 | ||
|
|
e7f0a05e1a | ||
|
|
8506b5d5a5 | ||
|
|
0d629127a9 | ||
|
|
d6d8d2148d | ||
|
|
5a3f2004bc | ||
|
|
0e86fc8094 | ||
|
|
3c6c4b88ef | ||
|
|
4b4a10be7e | ||
|
|
4f1491858b | ||
|
|
33433b1aaf | ||
|
|
d85ebe0d34 | ||
|
|
235bd85510 | ||
|
|
5c29345f48 | ||
|
|
ebcb2b84ae | ||
|
|
080021e73d | ||
|
|
f447e28c86 | ||
|
|
f3b2ca644c | ||
|
|
4fdead0add | ||
|
|
059c6e9df7 | ||
|
|
a3f0efa8bc | ||
|
|
a79ad5abeb | ||
|
|
c6f8a14643 | ||
|
|
d262357c87 | ||
|
|
5da3730015 | ||
|
|
b444a4887b | ||
|
|
cc7133927f | ||
|
|
4b01042a4f | ||
|
|
4b94ef998d | ||
|
|
db5764b3d7 | ||
|
|
3c0115b71c | ||
|
|
c401c790bc | ||
|
|
271dcacf19 | ||
|
|
983d29d033 | ||
|
|
078f6e1cc4 | ||
|
|
9f8f6bc814 | ||
|
|
ef35178396 | ||
|
|
b3781c6d8f | ||
|
|
2319739f6d | ||
|
|
f9ac1ca698 | ||
|
|
9802bf2f37 |
13
.github/dependabot.yml
vendored
13
.github/dependabot.yml
vendored
@@ -9,6 +9,19 @@ updates:
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
groups:
|
||||
k8s:
|
||||
patterns:
|
||||
- "k8s.io/*"
|
||||
update-types:
|
||||
- "minor"
|
||||
- "patch"
|
||||
onsi:
|
||||
patterns:
|
||||
- "github.com/onsi/*"
|
||||
update-types:
|
||||
- "minor"
|
||||
- "patch"
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
|
||||
6
.github/workflows/codeql-analysis.yml
vendored
6
.github/workflows/codeql-analysis.yml
vendored
@@ -40,6 +40,12 @@ jobs:
|
||||
- name: Checkout repository
|
||||
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.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v3
|
||||
|
||||
5
.github/workflows/e2e.yaml
vendored
5
.github/workflows/e2e.yaml
vendored
@@ -20,6 +20,9 @@ jobs:
|
||||
- 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
|
||||
|
||||
@@ -36,5 +39,7 @@ jobs:
|
||||
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
|
||||
|
||||
2
.github/workflows/go.yml
vendored
2
.github/workflows/go.yml
vendored
@@ -19,7 +19,7 @@ jobs:
|
||||
go-version-file: "go.mod"
|
||||
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
uses: golangci/golangci-lint-action@v4
|
||||
with:
|
||||
skip-pkg-cache: true
|
||||
|
||||
|
||||
17
.github/workflows/stale.yml
vendored
Normal file
17
.github/workflows/stale.yml
vendored
Normal 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.'
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,5 +1,6 @@
|
||||
.vscode
|
||||
.idea
|
||||
.fleet
|
||||
.run
|
||||
coverage.out*
|
||||
dist
|
||||
@@ -10,3 +11,5 @@ tmp
|
||||
bin
|
||||
config*.yaml
|
||||
*.log
|
||||
wiki
|
||||
Taskfile.yml
|
||||
|
||||
@@ -3,34 +3,35 @@ run:
|
||||
|
||||
linters:
|
||||
enable:
|
||||
- asciicheck
|
||||
- bodyclose
|
||||
- dogsled
|
||||
- durationcheck
|
||||
- errcheck
|
||||
- errorlint
|
||||
- exportloopref
|
||||
- gci
|
||||
- gofmt
|
||||
- gofumpt
|
||||
- goimports
|
||||
- gosec
|
||||
- gosimple
|
||||
- govet
|
||||
- importas
|
||||
- ineffassign
|
||||
- megacheck
|
||||
- misspell
|
||||
- nakedret
|
||||
- nolintlint
|
||||
- staticcheck
|
||||
- unconvert
|
||||
- unparam
|
||||
- unused
|
||||
- asciicheck
|
||||
- bodyclose
|
||||
- dogsled
|
||||
- durationcheck
|
||||
- errcheck
|
||||
- errorlint
|
||||
- gci
|
||||
- gofmt
|
||||
- gofumpt
|
||||
- goimports
|
||||
- gosec
|
||||
- gosimple
|
||||
- govet
|
||||
- importas
|
||||
- ineffassign
|
||||
- megacheck
|
||||
- misspell
|
||||
- nakedret
|
||||
- nolintlint
|
||||
- staticcheck
|
||||
- unconvert
|
||||
- unparam
|
||||
- unused
|
||||
linters-settings:
|
||||
gosec:
|
||||
# Exclude generated files
|
||||
exclude-generated: true
|
||||
excludes:
|
||||
- G601 # not applicable in go 1.22 anymore
|
||||
gofmt:
|
||||
# simplify code: gofmt with `-s` option, true by default
|
||||
simplify: true
|
||||
|
||||
@@ -30,7 +30,7 @@ builds:
|
||||
hooks:
|
||||
post:
|
||||
# don't upx windows binaries as they make trouble with virus scanners
|
||||
- bash -c 'if [[ "{{ .Path }}" != *.exe ]]; then upx {{ .Path }}; fi'
|
||||
- bash -c 'if [[ "{{ .Path }}" != *.exe ]] && [[ "{{ .Path }}" != *darwin* ]]; then upx {{ .Path }}; fi'
|
||||
checksum:
|
||||
name_template: 'checksums.txt'
|
||||
snapshot:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM golang:1.21-bullseye as builder
|
||||
FROM golang:1.22-bullseye as builder
|
||||
|
||||
WORKDIR /go/src/app
|
||||
|
||||
|
||||
90
Makefile
90
Makefile
@@ -15,8 +15,8 @@ generate: deepcopy-gen
|
||||
test: generate lint test-ci
|
||||
|
||||
# Run ci tests
|
||||
test-ci: mocks tidy
|
||||
go test ./... -coverprofile=coverage.out.tmp
|
||||
test-ci: mocks tidy ginkgo
|
||||
$(GINKGO) --cover --coverprofile coverage.out.tmp ./...
|
||||
cat coverage.out.tmp | grep -v "_generated.go" > coverage.out
|
||||
go tool cover -func=coverage.out
|
||||
|
||||
@@ -30,7 +30,7 @@ release: semver goreleaser
|
||||
$(GORELEASER) --clean
|
||||
|
||||
test-release: goreleaser
|
||||
$(GORELEASER) --skip-publish --snapshot --clean
|
||||
$(GORELEASER) --skip=publish --snapshot --clean
|
||||
|
||||
## toolbox - start
|
||||
## Current working directory
|
||||
@@ -41,64 +41,56 @@ $(LOCALBIN):
|
||||
mkdir -p $(LOCALBIN)
|
||||
|
||||
## Tool Binaries
|
||||
SEMVER ?= $(LOCALBIN)/semver
|
||||
OAPI_CODEGEN ?= $(LOCALBIN)/oapi-codegen
|
||||
MOCKGEN ?= $(LOCALBIN)/mockgen
|
||||
DEEPCOPY_GEN ?= $(LOCALBIN)/deepcopy-gen
|
||||
GINKGO ?= $(LOCALBIN)/ginkgo
|
||||
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
|
||||
GORELEASER ?= $(LOCALBIN)/goreleaser
|
||||
DEEPCOPY_GEN ?= $(LOCALBIN)/deepcopy-gen
|
||||
|
||||
## Tool Versions
|
||||
SEMVER_VERSION ?= v1.1.3
|
||||
OAPI_CODEGEN_VERSION ?= v2.0.0
|
||||
MOCKGEN_VERSION ?= v1.6.0
|
||||
GOLANGCI_LINT_VERSION ?= v1.55.2
|
||||
GORELEASER_VERSION ?= v1.23.0
|
||||
DEEPCOPY_GEN_VERSION ?= v0.29.0
|
||||
MOCKGEN ?= $(LOCALBIN)/mockgen
|
||||
OAPI_CODEGEN ?= $(LOCALBIN)/oapi-codegen
|
||||
SEMVER ?= $(LOCALBIN)/semver
|
||||
|
||||
## Tool Installer
|
||||
.PHONY: semver
|
||||
semver: $(SEMVER) ## Download semver locally if necessary.
|
||||
$(SEMVER): $(LOCALBIN)
|
||||
test -s $(LOCALBIN)/semver || GOBIN=$(LOCALBIN) go install github.com/bakito/semver@$(SEMVER_VERSION)
|
||||
.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@$(OAPI_CODEGEN_VERSION)
|
||||
.PHONY: mockgen
|
||||
mockgen: $(MOCKGEN) ## Download mockgen locally if necessary.
|
||||
$(MOCKGEN): $(LOCALBIN)
|
||||
test -s $(LOCALBIN)/mockgen || GOBIN=$(LOCALBIN) go install github.com/golang/mock/mockgen@$(MOCKGEN_VERSION)
|
||||
.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@$(GOLANGCI_LINT_VERSION)
|
||||
.PHONY: goreleaser
|
||||
goreleaser: $(GORELEASER) ## Download goreleaser locally if necessary.
|
||||
$(GORELEASER): $(LOCALBIN)
|
||||
test -s $(LOCALBIN)/goreleaser || GOBIN=$(LOCALBIN) go install github.com/goreleaser/goreleaser@$(GORELEASER_VERSION)
|
||||
.PHONY: deepcopy-gen
|
||||
deepcopy-gen: $(DEEPCOPY_GEN) ## Download deepcopy-gen locally if necessary.
|
||||
$(DEEPCOPY_GEN): $(LOCALBIN)
|
||||
test -s $(LOCALBIN)/deepcopy-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/deepcopy-gen@$(DEEPCOPY_GEN_VERSION)
|
||||
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)/semver \
|
||||
$(LOCALBIN)/oapi-codegen \
|
||||
$(LOCALBIN)/mockgen \
|
||||
$(LOCALBIN)/deepcopy-gen \
|
||||
$(LOCALBIN)/ginkgo \
|
||||
$(LOCALBIN)/golangci-lint \
|
||||
$(LOCALBIN)/goreleaser \
|
||||
$(LOCALBIN)/deepcopy-gen
|
||||
toolbox makefile -f $(LOCALDIR)/Makefile \
|
||||
github.com/bakito/semver \
|
||||
github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen \
|
||||
github.com/golang/mock/mockgen \
|
||||
github.com/golangci/golangci-lint/cmd/golangci-lint \
|
||||
github.com/goreleaser/goreleaser \
|
||||
k8s.io/code-generator/cmd/deepcopy-gen@github.com/kubernetes/code-generator
|
||||
$(LOCALBIN)/mockgen \
|
||||
$(LOCALBIN)/oapi-codegen \
|
||||
$(LOCALBIN)/semver
|
||||
toolbox makefile -f $(LOCALDIR)/Makefile
|
||||
## toolbox - end
|
||||
|
||||
start-replica:
|
||||
@@ -132,10 +124,10 @@ kind-test:
|
||||
|
||||
model: oapi-codegen
|
||||
@mkdir -p tmp
|
||||
go run openapi/main.go v0.107.43
|
||||
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.43
|
||||
go run openapi/main.go v0.107.46
|
||||
go run openapi/main.go
|
||||
diff tmp/schema.yaml tmp/schema-master.yaml
|
||||
|
||||
84
README.md
84
README.md
@@ -1,4 +1,5 @@
|
||||
[](https://github.com/bakito/adguardhome-sync/actions/workflows/go.yml)
|
||||
[](https://github.com/bakito/adguardhome-sync/actions/workflows/e2e.yaml)
|
||||
[](https://goreportcard.com/report/github.com/bakito/adguardhome-sync)
|
||||
[](https://coveralls.io/github/bakito/adguardhome-sync?branch=main)
|
||||
|
||||
@@ -6,38 +7,11 @@
|
||||
|
||||
Synchronize [AdGuardHome](https://github.com/AdguardTeam/AdGuardHome) config to replica instances.
|
||||
|
||||
## FAQ
|
||||
## FAQ & Deprecations
|
||||
|
||||
Please check the wiki for [FAQ](https://github.com/bakito/adguardhome-sync/wiki/FAQ).
|
||||
|
||||
## Deprecation of Environment Variables as of v0.6.0
|
||||
|
||||
The following environment variables have been deprecated and replaced with better readable ones:
|
||||
Deprecated variables are still supported but will be logged as warning.
|
||||
| Deprecated | Replacement |
|
||||
| :----------- |:----------- |
|
||||
| RUNONSTART | RUN_ON_START |
|
||||
| PRINTCONFIGONLY | PRINT_CONFIG_ONLY |
|
||||
| CONTINUE_ON_ERROR | CONTINUE_ON_ERROR |
|
||||
| API_DARKMODE | API_DARK_MODE |
|
||||
| FEATURES_DHCP_SERVERCONFIG | FEATURES_DHCP_SERVER_CONFIG |
|
||||
| FEATURES_DHCP_STATICLEASES | FEATURES_DHCP_STATIC_LEASES |
|
||||
| FEATURES_DNS_ACCESSLISTS | FEATURES_DNS_ACCESS_LISTS |
|
||||
| FEATURES_DNS_SERVERCONFIG | FEATURES_DNS_SERVER_CONFIG |
|
||||
| FEATURES_GENERALSETTINGS | FEATURES_GENERAL_SETTINGS |
|
||||
| FEATURES_QUERYLOGCONFIG | FEATURES_QUERY_LOG_CONFIG |
|
||||
| FEATURES_STATSCONFIG | FEATURES_STATS_CONFIG |
|
||||
| FEATURES_CLIENTSETTINGS | FEATURES_CLIENT_SETTINGS |
|
||||
| ORIGIN_WEBURL | ORIGIN_WEB_URL |
|
||||
| ORIGIN_APIPATH | ORIGIN_API_PATH |
|
||||
| ORIGIN_INSECURE_SKIP_VERIFY | ORIGIN_INSECURE_SKIP_VERIFY |
|
||||
| *REPLICA_WEBURL | REPLICA_WEB_URL |
|
||||
| *REPLICA_APIPATH | REPLICA_API_PATH |
|
||||
| *REPLICA_INSECURE_SKIP_VERIFY | REPLICA_INSECURE_SKIP_VERIFY |
|
||||
| *REPLICA_AUTOSETUP | REPLICA_AUTO_SETUP |
|
||||
| *REPLICA_INTERFACENAME | REPLICA_INTERFACE_NAME |
|
||||
|
||||
\* is also valid for numbered `REPLICA#_` variables
|
||||
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
|
||||
|
||||
@@ -88,9 +62,9 @@ export ORIGIN_URL=https://192.168.1.2:3000
|
||||
export ORIGIN_USERNAME=username
|
||||
export ORIGIN_PASSWORD=password
|
||||
# export ORIGIN_COOKIE=Origin-Cookie-Name=CCCOOOKKKIIIEEE
|
||||
export REPLICA_URL=http://192.168.1.3
|
||||
export REPLICA_USERNAME=username
|
||||
export REPLICA_PASSWORD=password
|
||||
export REPLICA1_URL=http://192.168.1.3
|
||||
export REPLICA1_USERNAME=username
|
||||
export REPLICA1_PASSWORD=password
|
||||
# export REPLICA_COOKIE=Replica-Cookie-Name=CCCOOOKKKIIIEEE
|
||||
|
||||
# run once
|
||||
@@ -116,10 +90,10 @@ set ORIGIN_USERNAME=username
|
||||
set ORIGIN_PASSWORD=password
|
||||
# set ORIGIN_COOKIE=Origin-Cookie-Name=CCCOOOKKKIIIEEE
|
||||
|
||||
set REPLICA_URL=http://192.168.2.2:3000
|
||||
set REPLICA_USERNAME=username
|
||||
set REPLICA_PASSWORD=password
|
||||
# set REPLICA_COOKIE=Replica-Cookie-Name=CCCOOOKKKIIIEEE
|
||||
set REPLICA1_URL=http://192.168.2.2:3000
|
||||
set REPLICA1_USERNAME=username
|
||||
set REPLICA1_PASSWORD=password
|
||||
# set REPLICA1_COOKIE=Replica-Cookie-Name=CCCOOOKKKIIIEEE
|
||||
|
||||
set FEATURES_DHCP=false
|
||||
set FEATURES_DHCP_SERVERCONFIG=false
|
||||
@@ -179,23 +153,26 @@ services:
|
||||
|
||||
ORIGIN_USERNAME: "username"
|
||||
ORIGIN_PASSWORD: "password"
|
||||
REPLICA_URL: "http://192.168.1.3"
|
||||
REPLICA_USERNAME: "username"
|
||||
REPLICA_PASSWORD: "password"
|
||||
REPLICA1_URL: "http://192.168.1.4"
|
||||
REPLICA1_URL: "http://192.168.1.3"
|
||||
REPLICA1_USERNAME: "username"
|
||||
REPLICA1_PASSWORD: "password"
|
||||
REPLICA1_API_PATH: "/some/path/control"
|
||||
# REPLICA1_WEB_URL: "https://some-other.url" # used in the web interface (default: <replica-url>
|
||||
# REPLICA1_AUTO_SETUP: true # if true, AdGuardHome is automatically initialized.
|
||||
# REPLICA1_INTERFACE_NAME: 'ens18' # use custom dhcp interface name
|
||||
# REPLICA1_DHCP_SERVER_ENABLED: true/false (optional) enables/disables the dhcp server on the replica
|
||||
REPLICA2_URL: "http://192.168.1.4"
|
||||
REPLICA2_USERNAME: "username"
|
||||
REPLICA2_PASSWORD: "password"
|
||||
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
|
||||
# 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.
|
||||
# FEATURES_GENERAL_SETTINGS: true
|
||||
@@ -261,6 +238,12 @@ api:
|
||||
# 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.
|
||||
features:
|
||||
generalSettings: true
|
||||
@@ -280,7 +263,7 @@ features:
|
||||
|
||||
## 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)
|
||||
|
||||
@@ -288,3 +271,8 @@ The following log levels are supported (default: info)
|
||||
- info
|
||||
- warn
|
||||
- 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
135
Taskfile.yml
Normal 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
|
||||
401
go.mod
401
go.mod
@@ -1,69 +1,432 @@
|
||||
module github.com/bakito/adguardhome-sync
|
||||
|
||||
go 1.21
|
||||
go 1.22
|
||||
|
||||
require (
|
||||
github.com/bakito/semver v1.1.3
|
||||
github.com/caarlos0/env/v10 v10.0.0
|
||||
github.com/deepmap/oapi-codegen/v2 v2.1.0
|
||||
github.com/gin-gonic/gin v1.9.1
|
||||
github.com/go-resty/resty/v2 v2.9.1
|
||||
github.com/golang/mock v1.6.0
|
||||
github.com/google/uuid v1.5.0
|
||||
github.com/go-resty/resty/v2 v2.12.0
|
||||
github.com/golangci/golangci-lint v1.57.2
|
||||
github.com/google/uuid v1.6.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.13.2
|
||||
github.com/onsi/gomega v1.30.0
|
||||
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/spf13/cobra v1.8.0
|
||||
go.uber.org/zap v1.26.0
|
||||
golang.org/x/mod v0.14.0
|
||||
go.uber.org/mock v0.4.0
|
||||
go.uber.org/zap v1.27.0
|
||||
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.0
|
||||
k8s.io/apimachinery v0.29.3
|
||||
k8s.io/code-generator v0.29.3
|
||||
)
|
||||
|
||||
require (
|
||||
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/go-logr/logr v1.3.0 // indirect
|
||||
github.com/go-critic/go-critic v0.11.2 // indirect
|
||||
github.com/go-fed/httpsig v1.1.0 // indirect
|
||||
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
|
||||
github.com/go-git/go-billy/v5 v5.5.0 // indirect
|
||||
github.com/go-git/go-git/v5 v5.11.0 // indirect
|
||||
github.com/go-logr/logr v1.4.1 // indirect
|
||||
github.com/go-openapi/analysis v0.21.4 // 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/pprof v0.0.0-20210720184732-4bb14d4b1be1 // 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/julz/importas v0.1.0 // indirect
|
||||
github.com/karamaru-alpha/copyloopvar v1.0.10 // 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/reflectwalk v1.0.2 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.1.1 // 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/v2 v2.2.0 // indirect
|
||||
github.com/perimeterx/marshmallow v1.1.5 // indirect
|
||||
github.com/pjbgf/sha1cd v0.3.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/viper v1.17.0 // indirect
|
||||
github.com/ssgreg/nlreturn/v2 v2.2.1 // indirect
|
||||
github.com/stbenjam/no-sprintf-host-port v0.1.1 // indirect
|
||||
github.com/stretchr/objx v0.5.2 // indirect
|
||||
github.com/stretchr/testify v1.9.0 // indirect
|
||||
github.com/subosito/gotenv v1.6.0 // indirect
|
||||
github.com/t-yuki/gocover-cobertura v0.0.0-20180217150009-aaee18c8195c // indirect
|
||||
github.com/tdakkota/asciicheck v0.2.0 // 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.18.0 // indirect
|
||||
golang.org/x/net v0.19.0 // indirect
|
||||
golang.org/x/sys v0.16.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/tools v0.16.0 // indirect
|
||||
google.golang.org/protobuf v1.32.0 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // 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/mail.v2 v2.3.1 // indirect
|
||||
gopkg.in/warnings.v0 v0.1.2 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // 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
|
||||
)
|
||||
|
||||
@@ -53,10 +53,8 @@ func New(config types.AdGuardInstance) (Client, error) {
|
||||
u.Path = path.Clean(u.Path)
|
||||
cl := resty.New().SetBaseURL(u.String()).SetDisableWarn(true)
|
||||
|
||||
if config.InsecureSkipVerify {
|
||||
// #nosec G402 has to be explicitly enabled
|
||||
cl.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
|
||||
}
|
||||
// #nosec G402 has to be explicitly enabled
|
||||
cl.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: config.InsecureSkipVerify})
|
||||
|
||||
cookieParts := strings.Split(config.Cookie, "=")
|
||||
if len(cookieParts) == 2 {
|
||||
@@ -90,6 +88,8 @@ func New(config types.AdGuardInstance) (Client, error) {
|
||||
type Client interface {
|
||||
Host() string
|
||||
Status() (*model.ServerStatus, error)
|
||||
Stats() (*model.Stats, error)
|
||||
QueryLog(limit int) (*model.QueryLog, error)
|
||||
ToggleProtection(enable bool) error
|
||||
RewriteList() (*model.RewriteEntries, error)
|
||||
AddRewriteEntries(e ...model.RewriteEntry) error
|
||||
@@ -109,18 +109,16 @@ type Client interface {
|
||||
SetSafeSearchConfig(settings *model.SafeSearchConfig) error
|
||||
ProfileInfo() (*model.ProfileInfo, error)
|
||||
SetProfileInfo(settings *model.ProfileInfo) error
|
||||
BlockedServices() (*model.BlockedServicesArray, error)
|
||||
BlockedServicesSchedule() (*model.BlockedServicesSchedule, error)
|
||||
SetBlockedServices(services *model.BlockedServicesArray) error
|
||||
SetBlockedServicesSchedule(schedule *model.BlockedServicesSchedule) error
|
||||
Clients() (*model.Clients, error)
|
||||
AddClient(client *model.Client) error
|
||||
UpdateClient(client *model.Client) error
|
||||
DeleteClient(client *model.Client) error
|
||||
QueryLogConfig() (*model.QueryLogConfig, error)
|
||||
SetQueryLogConfig(*model.QueryLogConfig) error
|
||||
StatsConfig() (*model.StatsConfig, error)
|
||||
SetStatsConfig(sc *model.StatsConfig) error
|
||||
QueryLogConfig() (*model.QueryLogConfigWithIgnored, error)
|
||||
SetQueryLogConfig(*model.QueryLogConfigWithIgnored) error
|
||||
StatsConfig() (*model.GetStatsConfigResponse, error)
|
||||
SetStatsConfig(sc *model.PutStatsConfigUpdateRequest) error
|
||||
Setup() error
|
||||
AccessList() (*model.AccessList, error)
|
||||
SetAccessList(*model.AccessList) error
|
||||
@@ -160,6 +158,18 @@ func (cl *client) Status() (*model.ServerStatus, error) {
|
||||
return status, err
|
||||
}
|
||||
|
||||
func (cl *client) Stats() (*model.Stats, error) {
|
||||
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")
|
||||
@@ -167,8 +177,7 @@ func (cl *client) RewriteList() (*model.RewriteEntries, error) {
|
||||
}
|
||||
|
||||
func (cl *client) AddRewriteEntries(entries ...model.RewriteEntry) error {
|
||||
for i := range entries {
|
||||
e := entries[i]
|
||||
for _, e := range entries {
|
||||
cl.log.With("domain", e.Domain, "answer", e.Answer).Info("Add DNS rewrite entry")
|
||||
err := cl.doPost(cl.client.R().EnableTrace().SetBody(&e), "/rewrite/add")
|
||||
if err != nil {
|
||||
@@ -179,8 +188,7 @@ func (cl *client) AddRewriteEntries(entries ...model.RewriteEntry) error {
|
||||
}
|
||||
|
||||
func (cl *client) DeleteRewriteEntries(entries ...model.RewriteEntry) error {
|
||||
for i := range entries {
|
||||
e := entries[i]
|
||||
for _, e := range entries {
|
||||
cl.log.With("domain", e.Domain, "answer", e.Answer).Info("Delete DNS rewrite entry")
|
||||
err := cl.doPost(cl.client.R().EnableTrace().SetBody(&e), "/rewrite/delete")
|
||||
if err != nil {
|
||||
@@ -261,7 +269,11 @@ func (cl *client) ToggleProtection(enable bool) error {
|
||||
}
|
||||
|
||||
func (cl *client) SetCustomRules(rules *[]string) error {
|
||||
cl.log.With("rules", len(*rules)).Info("Set user rules")
|
||||
var l int
|
||||
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")
|
||||
}
|
||||
|
||||
@@ -273,17 +285,6 @@ func (cl *client) ToggleFiltering(enabled bool, interval int) error {
|
||||
}), "/filtering/config")
|
||||
}
|
||||
|
||||
func (cl *client) BlockedServices() (*model.BlockedServicesArray, error) {
|
||||
svcs := &model.BlockedServicesArray{}
|
||||
err := cl.doGet(cl.client.R().EnableTrace().SetResult(svcs), "/blocked_services/list")
|
||||
return svcs, err
|
||||
}
|
||||
|
||||
func (cl *client) SetBlockedServices(services *model.BlockedServicesArray) error {
|
||||
cl.log.With("services", model.ArrayString(services)).Info("Set blocked services")
|
||||
return cl.doPost(cl.client.R().EnableTrace().SetBody(services), "/blocked_services/set")
|
||||
}
|
||||
|
||||
func (cl *client) BlockedServicesSchedule() (*model.BlockedServicesSchedule, error) {
|
||||
sched := &model.BlockedServicesSchedule{}
|
||||
err := cl.doGet(cl.client.R().EnableTrace().SetResult(sched), "/blocked_services/get")
|
||||
@@ -316,26 +317,26 @@ func (cl *client) DeleteClient(client *model.Client) error {
|
||||
return cl.doPost(cl.client.R().EnableTrace().SetBody(client), "/clients/delete")
|
||||
}
|
||||
|
||||
func (cl *client) QueryLogConfig() (*model.QueryLogConfig, error) {
|
||||
qlc := &model.QueryLogConfig{}
|
||||
err := cl.doGet(cl.client.R().EnableTrace().SetResult(qlc), "/querylog_info")
|
||||
func (cl *client) QueryLogConfig() (*model.QueryLogConfigWithIgnored, error) {
|
||||
qlc := &model.QueryLogConfigWithIgnored{}
|
||||
err := cl.doGet(cl.client.R().EnableTrace().SetResult(qlc), "/querylog/config")
|
||||
return qlc, err
|
||||
}
|
||||
|
||||
func (cl *client) SetQueryLogConfig(qlc *model.QueryLogConfig) error {
|
||||
func (cl *client) SetQueryLogConfig(qlc *model.QueryLogConfigWithIgnored) error {
|
||||
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(qlc), "/querylog_config")
|
||||
return cl.doPut(cl.client.R().EnableTrace().SetBody(qlc), "/querylog/config/update")
|
||||
}
|
||||
|
||||
func (cl *client) StatsConfig() (*model.StatsConfig, error) {
|
||||
stats := &model.StatsConfig{}
|
||||
err := cl.doGet(cl.client.R().EnableTrace().SetResult(stats), "/stats_info")
|
||||
func (cl *client) StatsConfig() (*model.GetStatsConfigResponse, error) {
|
||||
stats := &model.GetStatsConfigResponse{}
|
||||
err := cl.doGet(cl.client.R().EnableTrace().SetResult(stats), "/stats/config")
|
||||
return stats, err
|
||||
}
|
||||
|
||||
func (cl *client) SetStatsConfig(sc *model.StatsConfig) error {
|
||||
cl.log.With("interval", *sc.Interval).Info("Set stats config")
|
||||
return cl.doPost(cl.client.R().EnableTrace().SetBody(sc), "/stats_config")
|
||||
func (cl *client) SetStatsConfig(sc *model.PutStatsConfigUpdateRequest) error {
|
||||
cl.log.With("interval", sc.Interval).Info("Set stats config")
|
||||
return cl.doPut(cl.client.R().EnableTrace().SetBody(sc), "/stats/config/update")
|
||||
}
|
||||
|
||||
func (cl *client) Setup() error {
|
||||
|
||||
@@ -97,6 +97,20 @@ var _ = Describe("Client", func() {
|
||||
err = cl.DeleteFilter(true, model.Filter{Url: "bar"})
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
})
|
||||
It("should set empty filter rules", func() {
|
||||
ts, cl = ClientPost("/filtering/set_rules",
|
||||
`{"rules":[]}`,
|
||||
)
|
||||
err := cl.SetCustomRules(utils.Ptr([]string{}))
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
})
|
||||
It("should set nil filter rules", func() {
|
||||
ts, cl = ClientPost("/filtering/set_rules",
|
||||
`{}`,
|
||||
)
|
||||
err := cl.SetCustomRules(nil)
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
Context("Status", func() {
|
||||
@@ -225,20 +239,6 @@ var _ = Describe("Client", func() {
|
||||
})
|
||||
})
|
||||
|
||||
Context("BlockedServices", func() {
|
||||
It("should read BlockedServices", func() {
|
||||
ts, cl = ClientGet("blockedservices-list.json", "/blocked_services/list")
|
||||
s, err := cl.BlockedServices()
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
Ω(*s).Should(HaveLen(2))
|
||||
})
|
||||
It("should set BlockedServices", func() {
|
||||
ts, cl = ClientPost("/blocked_services/set", `["bar","foo"]`)
|
||||
err := cl.SetBlockedServices(&model.BlockedServicesArray{"foo", "bar"})
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
Context("BlockedServicesSchedule", func() {
|
||||
It("should read BlockedServicesSchedule", func() {
|
||||
ts, cl = ClientGet("blockedservicesschedule-get.json", "/blocked_services/get")
|
||||
@@ -294,7 +294,7 @@ var _ = Describe("Client", func() {
|
||||
|
||||
Context("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()
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
Ω(qlc.Enabled).ShouldNot(BeNil())
|
||||
@@ -303,26 +303,33 @@ var _ = Describe("Client", func() {
|
||||
Ω(*qlc.Interval).Should(Equal(model.QueryLogConfigInterval(90)))
|
||||
})
|
||||
It("should set QueryLogConfig", func() {
|
||||
ts, cl = ClientPost("/querylog_config", `{"anonymize_client_ip":true,"enabled":true,"interval":123}`)
|
||||
ts, cl = ClientPut("/querylog/config/update", `{"anonymize_client_ip":true,"enabled":true,"interval":123,"ignored":["foo.bar"]}`)
|
||||
|
||||
var interval model.QueryLogConfigInterval = 123
|
||||
err := cl.SetQueryLogConfig(&model.QueryLogConfig{AnonymizeClientIp: utils.Ptr(true), Interval: &interval, Enabled: utils.Ptr(true)})
|
||||
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())
|
||||
})
|
||||
})
|
||||
Context("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()
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
Ω(sc.Interval).ShouldNot(BeNil())
|
||||
Ω(*sc.Interval).Should(Equal(model.StatsConfigInterval(1)))
|
||||
Ω(sc.Interval).Should(Equal(float32(1)))
|
||||
})
|
||||
It("should set StatsConfig", func() {
|
||||
ts, cl = ClientPost("/stats_config", `{"interval":123}`)
|
||||
ts, cl = ClientPost("/stats/config/update", `{"enabled":false,"ignored":null,"interval":123}`)
|
||||
|
||||
var interval model.StatsConfigInterval = 123
|
||||
err := cl.SetStatsConfig(&model.StatsConfig{Interval: &interval})
|
||||
var interval float32 = 123
|
||||
err := cl.SetStatsConfig(&model.PutStatsConfigUpdateRequest{Interval: interval})
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
})
|
||||
})
|
||||
@@ -347,8 +354,8 @@ var _ = Describe("Client", func() {
|
||||
|
||||
Context("doPost", func() {
|
||||
It("should return an error on status code != 200", func() {
|
||||
var interval model.StatsConfigInterval = 123
|
||||
err := cl.SetStatsConfig(&model.StatsConfig{Interval: &interval})
|
||||
var interval float32 = 123
|
||||
err := cl.SetStatsConfig(&model.PutStatsConfigUpdateRequest{Interval: interval})
|
||||
Ω(err).Should(HaveOccurred())
|
||||
Ω(err.Error()).Should(Equal("401 Unauthorized"))
|
||||
})
|
||||
|
||||
@@ -33,12 +33,11 @@ func New(config types.AdGuardInstance) (Client, error) {
|
||||
}
|
||||
u.Path = path.Clean(u.Path)
|
||||
|
||||
httpClient := &http.Client{}
|
||||
if config.InsecureSkipVerify {
|
||||
// #nosec G402 has to be explicitly enabled
|
||||
httpClient.Transport = &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}
|
||||
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 {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/bakito/adguardhome-sync/pkg/utils"
|
||||
"github.com/jinzhu/copier"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// Clone the config
|
||||
@@ -189,8 +190,7 @@ func (clients *Clients) Merge(other *Clients) ([]*Client, []*Client, []*Client)
|
||||
current := make(map[string]*Client)
|
||||
if clients.Clients != nil {
|
||||
cc := *clients.Clients
|
||||
for i := range cc {
|
||||
client := cc[i]
|
||||
for _, client := range cc {
|
||||
current[*client.Name] = &client
|
||||
}
|
||||
}
|
||||
@@ -198,8 +198,7 @@ func (clients *Clients) Merge(other *Clients) ([]*Client, []*Client, []*Client)
|
||||
expected := make(map[string]*Client)
|
||||
if other.Clients != nil {
|
||||
oc := *other.Clients
|
||||
for i := range oc {
|
||||
client := oc[i]
|
||||
for _, client := range oc {
|
||||
expected[*client.Name] = &client
|
||||
}
|
||||
}
|
||||
@@ -292,15 +291,13 @@ func MergeFilters(this *[]Filter, other *[]Filter) ([]Filter, []Filter, []Filter
|
||||
var updates []Filter
|
||||
var removes []Filter
|
||||
if this != nil {
|
||||
for i := range *this {
|
||||
fi := (*this)[i]
|
||||
for _, fi := range *this {
|
||||
current[fi.Url] = &fi
|
||||
}
|
||||
}
|
||||
|
||||
if other != nil {
|
||||
for i := range *other {
|
||||
rr := (*other)[i]
|
||||
for _, rr := range *other {
|
||||
if c, ok := current[rr.Url]; ok {
|
||||
if !c.Equals(&rr) {
|
||||
updates = append(updates, rr)
|
||||
@@ -324,11 +321,16 @@ 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 *QueryLogConfig) Equals(o *QueryLogConfig) bool {
|
||||
return ptrEquals(qlc.Enabled, o.Enabled) &&
|
||||
ptrEquals(qlc.AnonymizeClientIp, o.AnonymizeClientIp) &&
|
||||
qlc.Interval.Equals(o.Interval)
|
||||
func (qlc *QueryLogConfigWithIgnored) Equals(o *QueryLogConfigWithIgnored) bool {
|
||||
return utils.JsonEquals(qlc, o)
|
||||
}
|
||||
|
||||
// Equals QueryLogConfigInterval equal check
|
||||
@@ -405,3 +407,17 @@ func ArrayString(a *[]string) string {
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package model provides primitives to interact with the openapi HTTP API.
|
||||
//
|
||||
// Code generated by github.com/deepmap/oapi-codegen/v2 version v2.0.0 DO NOT EDIT.
|
||||
// Code generated by github.com/deepmap/oapi-codegen/v2 version v2.1.0 DO NOT EDIT.
|
||||
package model
|
||||
|
||||
import (
|
||||
@@ -37,6 +37,14 @@ const (
|
||||
Refused DNSConfigBlockingMode = "refused"
|
||||
)
|
||||
|
||||
// Defines values for DNSConfigUpstreamMode.
|
||||
const (
|
||||
MapConstDeprecatedTrueDescriptionUseloadBalanceInstead DNSConfigUpstreamMode = "map[const: deprecated:true description:Use `load_balance` instead.]"
|
||||
MapConstFastestAddr DNSConfigUpstreamMode = "map[const:fastest_addr]"
|
||||
MapConstLoadBalance DNSConfigUpstreamMode = "map[const:load_balance]"
|
||||
MapConstParallel DNSConfigUpstreamMode = "map[const:parallel]"
|
||||
)
|
||||
|
||||
// Defines values for DhcpSearchResultOtherServerFound.
|
||||
const (
|
||||
DhcpSearchResultOtherServerFoundError DhcpSearchResultOtherServerFound = "error"
|
||||
@@ -306,7 +314,7 @@ type Client struct {
|
||||
// changed.
|
||||
//
|
||||
// This behaviour can be changed in the future versions.
|
||||
UpstreamsCacheSize *int `json:"upstreams_cache_size,omitempty"`
|
||||
UpstreamsCacheSize *int `json:"upstreams_cache_size,omitempty"`
|
||||
UseGlobalBlockedServices *bool `json:"use_global_blocked_services,omitempty"`
|
||||
UseGlobalSettings *bool `json:"use_global_settings,omitempty"`
|
||||
}
|
||||
@@ -431,15 +439,20 @@ type DNSConfig struct {
|
||||
ResolveClients *bool `json:"resolve_clients,omitempty"`
|
||||
|
||||
// UpstreamDns Upstream servers, port is optional after colon. Empty value will reset it to default values.
|
||||
UpstreamDns *[]string `json:"upstream_dns,omitempty"`
|
||||
UpstreamDnsFile *string `json:"upstream_dns_file,omitempty"`
|
||||
UpstreamMode *interface{} `json:"upstream_mode,omitempty"`
|
||||
UsePrivatePtrResolvers *bool `json:"use_private_ptr_resolvers,omitempty"`
|
||||
UpstreamDns *[]string `json:"upstream_dns,omitempty"`
|
||||
UpstreamDnsFile *string `json:"upstream_dns_file,omitempty"`
|
||||
|
||||
// UpstreamMode Upstream modes enumeration.
|
||||
UpstreamMode *DNSConfigUpstreamMode `json:"upstream_mode,omitempty"`
|
||||
UsePrivatePtrResolvers *bool `json:"use_private_ptr_resolvers,omitempty"`
|
||||
}
|
||||
|
||||
// DNSConfigBlockingMode defines model for DNSConfig.BlockingMode.
|
||||
type DNSConfigBlockingMode string
|
||||
|
||||
// DNSConfigUpstreamMode Upstream modes enumeration.
|
||||
type DNSConfigUpstreamMode string
|
||||
|
||||
// DayRange The single interval within a day. It begins at the `start` and ends before the `end`.
|
||||
type DayRange struct {
|
||||
// End The number of milliseconds elapsed from the start of a day. It is expected to be rounded to minutes. The maximum value is `86400000` (24 hours).
|
||||
@@ -1046,6 +1059,9 @@ type TlsConfig struct {
|
||||
// PrivateKeySaved Set to true if the user has previously saved a private key as a string. This is used so that the server and the client don't have to send the private key between each other every time, which might lead to security issues.
|
||||
PrivateKeySaved *bool `json:"private_key_saved,omitempty"`
|
||||
|
||||
// ServePlainDns Set to true if plain DNS is allowed for incoming requests.
|
||||
ServePlainDns *bool `json:"serve_plain_dns,omitempty"`
|
||||
|
||||
// ServerName server_name is the hostname of your HTTPS/TLS server
|
||||
ServerName *string `json:"server_name,omitempty"`
|
||||
|
||||
|
||||
103
pkg/client/model/model_private_test.go
Normal file
103
pkg/client/model/model_private_test.go
Normal 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))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -115,12 +115,12 @@ var _ = Describe("Types", func() {
|
||||
Context("QueryLogConfig", func() {
|
||||
Context("Equal", func() {
|
||||
var (
|
||||
a *model.QueryLogConfig
|
||||
b *model.QueryLogConfig
|
||||
a *model.QueryLogConfigWithIgnored
|
||||
b *model.QueryLogConfigWithIgnored
|
||||
)
|
||||
BeforeEach(func() {
|
||||
a = &model.QueryLogConfig{}
|
||||
b = &model.QueryLogConfig{}
|
||||
a = &model.QueryLogConfigWithIgnored{}
|
||||
b = &model.QueryLogConfigWithIgnored{}
|
||||
})
|
||||
It("should be equal", func() {
|
||||
a.Enabled = utils.Ptr(true)
|
||||
|
||||
@@ -32,15 +32,26 @@ func Get(configFile string, flags Flags) (*types.Config, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// overwrite from env vars
|
||||
// *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.Origin, env.Options{Prefix: "ORIGIN_"}); err != nil {
|
||||
if err := env.ParseWithOptions(cfg.Replica, env.Options{Prefix: "REPLICA_"}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := env.ParseWithOptions(cfg.Replica, env.Options{Prefix: "REPLICA_"}); err != nil {
|
||||
// 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
|
||||
}
|
||||
|
||||
|
||||
@@ -5,22 +5,32 @@ import (
|
||||
|
||||
"github.com/bakito/adguardhome-sync/pkg/config"
|
||||
flagsmock "github.com/bakito/adguardhome-sync/pkg/mocks/flags"
|
||||
gm "github.com/golang/mock/gomock"
|
||||
. "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
|
||||
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() {
|
||||
@@ -51,10 +61,7 @@ var _ = Describe("Config", func() {
|
||||
Ω(cfg.Origin.URL).Should(Equal("https://origin-flag:443"))
|
||||
})
|
||||
It("should have the origin URL from the config env var", func() {
|
||||
os.Setenv("ORIGIN_URL", "https://origin-env:443")
|
||||
defer func() {
|
||||
_ = os.Unsetenv("ORIGIN_URL")
|
||||
}()
|
||||
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()
|
||||
@@ -82,10 +89,7 @@ var _ = Describe("Config", func() {
|
||||
Ω(cfg.Replicas[0].InsecureSkipVerify).Should(BeTrue())
|
||||
})
|
||||
It("should have the insecure skip verify from the config env var", func() {
|
||||
os.Setenv("REPLICA_INSECURE_SKIP_VERIFY", "false")
|
||||
defer func() {
|
||||
_ = os.Unsetenv("REPLICA_INSECURE_SKIP_VERIFY")
|
||||
}()
|
||||
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()
|
||||
@@ -105,10 +109,7 @@ var _ = Describe("Config", func() {
|
||||
Ω(cfg.Replicas[0].InsecureSkipVerify).Should(BeFalse())
|
||||
})
|
||||
It("should have the insecure skip verify from the config env var", func() {
|
||||
os.Setenv("REPLICA1_INSECURE_SKIP_VERIFY", "true")
|
||||
defer func() {
|
||||
_ = os.Unsetenv("REPLICA1_INSECURE_SKIP_VERIFY")
|
||||
}()
|
||||
setEnv("REPLICA1_INSECURE_SKIP_VERIFY", "true")
|
||||
flags.EXPECT().Changed(gm.Any()).Return(false).AnyTimes()
|
||||
|
||||
cfg, err := config.Get("../../testdata/config_test_replicas.yaml", flags)
|
||||
@@ -133,10 +134,7 @@ var _ = Describe("Config", func() {
|
||||
Ω(cfg.API.Port).Should(Equal(9990))
|
||||
})
|
||||
It("should have the api port from the config env var", func() {
|
||||
os.Setenv("API_PORT", "9999")
|
||||
defer func() {
|
||||
_ = os.Unsetenv("API_PORT")
|
||||
}()
|
||||
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()
|
||||
@@ -146,6 +144,58 @@ var _ = Describe("Config", func() {
|
||||
Ω(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()
|
||||
@@ -163,10 +213,7 @@ var _ = Describe("Config", func() {
|
||||
Ω(cfg.Features.DNS.ServerConfig).Should(BeTrue())
|
||||
})
|
||||
It("should have the feature dns server config from the config env var", func() {
|
||||
os.Setenv("FEATURES_DNS_SERVER_CONFIG", "false")
|
||||
defer func() {
|
||||
_ = os.Unsetenv("FEATURES_DNS_SERVER_CONFIG")
|
||||
}()
|
||||
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()
|
||||
@@ -176,10 +223,7 @@ var _ = Describe("Config", func() {
|
||||
Ω(cfg.Features.DNS.ServerConfig).Should(BeFalse())
|
||||
})
|
||||
It("should have the feature dns server config from the config DEPRECATED env var", func() {
|
||||
os.Setenv("FEATURES_DNS_SERVERCONFIG", "false")
|
||||
defer func() {
|
||||
_ = os.Unsetenv("FEATURES_DNS_SERVERCONFIG")
|
||||
}()
|
||||
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()
|
||||
|
||||
@@ -107,9 +107,15 @@ func enrichReplicasFromEnv(initialReplicas []types.AdGuardInstance) ([]types.AdG
|
||||
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
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func configFilePath(configFile string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return filepath.Join(home, ".adguardhome-sync"), nil
|
||||
return filepath.Join(home, ".adguardhome-sync.yaml"), nil
|
||||
}
|
||||
return configFile, nil
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ var _ = Describe("Config", func() {
|
||||
result, err := configFilePath("")
|
||||
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
Ω(result).Should(Equal(filepath.Join(home, "/.adguardhome-sync")))
|
||||
Ω(result).Should(Equal(filepath.Join(home, "/.adguardhome-sync.yaml")))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
|
||||
flagsmock "github.com/bakito/adguardhome-sync/pkg/mocks/flags"
|
||||
"github.com/bakito/adguardhome-sync/pkg/types"
|
||||
gm "github.com/golang/mock/gomock"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
gm "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
var _ = Describe("Config", func() {
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
const (
|
||||
logHistorySize = 50
|
||||
envLogLevel = "LOG_LEVEL"
|
||||
envLogFormat = "LOG_FORMAT"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -31,14 +32,23 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
format := "console"
|
||||
if fmt, ok := os.LookupEnv(envLogFormat); ok {
|
||||
format = fmt
|
||||
}
|
||||
|
||||
cfg := zap.Config{
|
||||
Level: zap.NewAtomicLevelAt(level),
|
||||
Development: false,
|
||||
Encoding: "console",
|
||||
EncoderConfig: zap.NewDevelopmentEncoderConfig(),
|
||||
Encoding: format,
|
||||
EncoderConfig: zap.NewProductionEncoderConfig(),
|
||||
OutputPaths: []string{"stdout"},
|
||||
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 {
|
||||
return zapcore.NewTee(c, &logList{
|
||||
enc: zapcore.NewConsoleEncoder(cfg.EncoderConfig),
|
||||
|
||||
14
pkg/metrics/handler.go
Normal file
14
pkg/metrics/handler.go
Normal 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
245
pkg/metrics/metrics.go
Normal 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
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// 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
|
||||
@@ -8,7 +13,7 @@ import (
|
||||
reflect "reflect"
|
||||
|
||||
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.
|
||||
@@ -58,7 +63,7 @@ func (m *MockClient) AddClient(arg0 *model.Client) error {
|
||||
}
|
||||
|
||||
// AddClient indicates an expected call of AddClient.
|
||||
func (mr *MockClientMockRecorder) AddClient(arg0 interface{}) *gomock.Call {
|
||||
func (mr *MockClientMockRecorder) AddClient(arg0 any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddClient", reflect.TypeOf((*MockClient)(nil).AddClient), arg0)
|
||||
}
|
||||
@@ -72,7 +77,7 @@ func (m *MockClient) AddDHCPStaticLease(arg0 model.DhcpStaticLease) error {
|
||||
}
|
||||
|
||||
// AddDHCPStaticLease indicates an expected call of AddDHCPStaticLease.
|
||||
func (mr *MockClientMockRecorder) AddDHCPStaticLease(arg0 interface{}) *gomock.Call {
|
||||
func (mr *MockClientMockRecorder) AddDHCPStaticLease(arg0 any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddDHCPStaticLease", reflect.TypeOf((*MockClient)(nil).AddDHCPStaticLease), arg0)
|
||||
}
|
||||
@@ -86,7 +91,7 @@ func (m *MockClient) AddFilter(arg0 bool, arg1 model.Filter) error {
|
||||
}
|
||||
|
||||
// AddFilter indicates an expected call of AddFilter.
|
||||
func (mr *MockClientMockRecorder) AddFilter(arg0, arg1 interface{}) *gomock.Call {
|
||||
func (mr *MockClientMockRecorder) AddFilter(arg0, arg1 any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddFilter", reflect.TypeOf((*MockClient)(nil).AddFilter), arg0, arg1)
|
||||
}
|
||||
@@ -94,7 +99,7 @@ func (mr *MockClientMockRecorder) AddFilter(arg0, arg1 interface{}) *gomock.Call
|
||||
// AddRewriteEntries mocks base method.
|
||||
func (m *MockClient) AddRewriteEntries(arg0 ...model.RewriteEntry) error {
|
||||
m.ctrl.T.Helper()
|
||||
varargs := []interface{}{}
|
||||
varargs := []any{}
|
||||
for _, a := range arg0 {
|
||||
varargs = append(varargs, a)
|
||||
}
|
||||
@@ -104,26 +109,11 @@ func (m *MockClient) AddRewriteEntries(arg0 ...model.RewriteEntry) error {
|
||||
}
|
||||
|
||||
// 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()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddRewriteEntries", reflect.TypeOf((*MockClient)(nil).AddRewriteEntries), arg0...)
|
||||
}
|
||||
|
||||
// BlockedServices mocks base method.
|
||||
func (m *MockClient) BlockedServices() (*[]string, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "BlockedServices")
|
||||
ret0, _ := ret[0].(*[]string)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// BlockedServices indicates an expected call of BlockedServices.
|
||||
func (mr *MockClientMockRecorder) BlockedServices() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockedServices", reflect.TypeOf((*MockClient)(nil).BlockedServices))
|
||||
}
|
||||
|
||||
// BlockedServicesSchedule mocks base method.
|
||||
func (m *MockClient) BlockedServicesSchedule() (*model.BlockedServicesSchedule, error) {
|
||||
m.ctrl.T.Helper()
|
||||
@@ -178,7 +168,7 @@ func (m *MockClient) DeleteClient(arg0 *model.Client) error {
|
||||
}
|
||||
|
||||
// DeleteClient indicates an expected call of DeleteClient.
|
||||
func (mr *MockClientMockRecorder) DeleteClient(arg0 interface{}) *gomock.Call {
|
||||
func (mr *MockClientMockRecorder) DeleteClient(arg0 any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteClient", reflect.TypeOf((*MockClient)(nil).DeleteClient), arg0)
|
||||
}
|
||||
@@ -192,7 +182,7 @@ func (m *MockClient) DeleteDHCPStaticLease(arg0 model.DhcpStaticLease) error {
|
||||
}
|
||||
|
||||
// DeleteDHCPStaticLease indicates an expected call of DeleteDHCPStaticLease.
|
||||
func (mr *MockClientMockRecorder) DeleteDHCPStaticLease(arg0 interface{}) *gomock.Call {
|
||||
func (mr *MockClientMockRecorder) DeleteDHCPStaticLease(arg0 any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteDHCPStaticLease", reflect.TypeOf((*MockClient)(nil).DeleteDHCPStaticLease), arg0)
|
||||
}
|
||||
@@ -206,7 +196,7 @@ func (m *MockClient) DeleteFilter(arg0 bool, arg1 model.Filter) error {
|
||||
}
|
||||
|
||||
// DeleteFilter indicates an expected call of DeleteFilter.
|
||||
func (mr *MockClientMockRecorder) DeleteFilter(arg0, arg1 interface{}) *gomock.Call {
|
||||
func (mr *MockClientMockRecorder) DeleteFilter(arg0, arg1 any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteFilter", reflect.TypeOf((*MockClient)(nil).DeleteFilter), arg0, arg1)
|
||||
}
|
||||
@@ -214,7 +204,7 @@ func (mr *MockClientMockRecorder) DeleteFilter(arg0, arg1 interface{}) *gomock.C
|
||||
// DeleteRewriteEntries mocks base method.
|
||||
func (m *MockClient) DeleteRewriteEntries(arg0 ...model.RewriteEntry) error {
|
||||
m.ctrl.T.Helper()
|
||||
varargs := []interface{}{}
|
||||
varargs := []any{}
|
||||
for _, a := range arg0 {
|
||||
varargs = append(varargs, a)
|
||||
}
|
||||
@@ -224,7 +214,7 @@ func (m *MockClient) DeleteRewriteEntries(arg0 ...model.RewriteEntry) error {
|
||||
}
|
||||
|
||||
// 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()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteRewriteEntries", reflect.TypeOf((*MockClient)(nil).DeleteRewriteEntries), arg0...)
|
||||
}
|
||||
@@ -303,11 +293,26 @@ func (mr *MockClientMockRecorder) ProfileInfo() *gomock.Call {
|
||||
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.
|
||||
func (m *MockClient) QueryLogConfig() (*model.QueryLogConfig, error) {
|
||||
func (m *MockClient) QueryLogConfig() (*model.QueryLogConfigWithIgnored, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "QueryLogConfig")
|
||||
ret0, _ := ret[0].(*model.QueryLogConfig)
|
||||
ret0, _ := ret[0].(*model.QueryLogConfigWithIgnored)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
@@ -327,7 +332,7 @@ func (m *MockClient) RefreshFilters(arg0 bool) error {
|
||||
}
|
||||
|
||||
// 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()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RefreshFilters", reflect.TypeOf((*MockClient)(nil).RefreshFilters), arg0)
|
||||
}
|
||||
@@ -386,25 +391,11 @@ func (m *MockClient) SetAccessList(arg0 *model.AccessList) error {
|
||||
}
|
||||
|
||||
// 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()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetAccessList", reflect.TypeOf((*MockClient)(nil).SetAccessList), arg0)
|
||||
}
|
||||
|
||||
// SetBlockedServices mocks base method.
|
||||
func (m *MockClient) SetBlockedServices(arg0 *[]string) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SetBlockedServices", arg0)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SetBlockedServices indicates an expected call of SetBlockedServices.
|
||||
func (mr *MockClientMockRecorder) SetBlockedServices(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetBlockedServices", reflect.TypeOf((*MockClient)(nil).SetBlockedServices), arg0)
|
||||
}
|
||||
|
||||
// SetBlockedServicesSchedule mocks base method.
|
||||
func (m *MockClient) SetBlockedServicesSchedule(arg0 *model.BlockedServicesSchedule) error {
|
||||
m.ctrl.T.Helper()
|
||||
@@ -414,7 +405,7 @@ func (m *MockClient) SetBlockedServicesSchedule(arg0 *model.BlockedServicesSched
|
||||
}
|
||||
|
||||
// SetBlockedServicesSchedule indicates an expected call of SetBlockedServicesSchedule.
|
||||
func (mr *MockClientMockRecorder) SetBlockedServicesSchedule(arg0 interface{}) *gomock.Call {
|
||||
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)
|
||||
}
|
||||
@@ -428,7 +419,7 @@ func (m *MockClient) SetCustomRules(arg0 *[]string) error {
|
||||
}
|
||||
|
||||
// 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()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetCustomRules", reflect.TypeOf((*MockClient)(nil).SetCustomRules), arg0)
|
||||
}
|
||||
@@ -442,7 +433,7 @@ func (m *MockClient) SetDNSConfig(arg0 *model.DNSConfig) error {
|
||||
}
|
||||
|
||||
// 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()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetDNSConfig", reflect.TypeOf((*MockClient)(nil).SetDNSConfig), arg0)
|
||||
}
|
||||
@@ -456,7 +447,7 @@ func (m *MockClient) SetDhcpConfig(arg0 *model.DhcpStatus) error {
|
||||
}
|
||||
|
||||
// SetDhcpConfig indicates an expected call of SetDhcpConfig.
|
||||
func (mr *MockClientMockRecorder) SetDhcpConfig(arg0 interface{}) *gomock.Call {
|
||||
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)
|
||||
}
|
||||
@@ -470,13 +461,13 @@ func (m *MockClient) SetProfileInfo(arg0 *model.ProfileInfo) error {
|
||||
}
|
||||
|
||||
// SetProfileInfo indicates an expected call of SetProfileInfo.
|
||||
func (mr *MockClientMockRecorder) SetProfileInfo(arg0 interface{}) *gomock.Call {
|
||||
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.QueryLogConfig) error {
|
||||
func (m *MockClient) SetQueryLogConfig(arg0 *model.QueryLogConfigWithIgnored) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SetQueryLogConfig", arg0)
|
||||
ret0, _ := ret[0].(error)
|
||||
@@ -484,7 +475,7 @@ func (m *MockClient) SetQueryLogConfig(arg0 *model.QueryLogConfig) error {
|
||||
}
|
||||
|
||||
// SetQueryLogConfig indicates an expected call of SetQueryLogConfig.
|
||||
func (mr *MockClientMockRecorder) SetQueryLogConfig(arg0 interface{}) *gomock.Call {
|
||||
func (mr *MockClientMockRecorder) SetQueryLogConfig(arg0 any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetQueryLogConfig", reflect.TypeOf((*MockClient)(nil).SetQueryLogConfig), arg0)
|
||||
}
|
||||
@@ -498,13 +489,13 @@ func (m *MockClient) SetSafeSearchConfig(arg0 *model.SafeSearchConfig) error {
|
||||
}
|
||||
|
||||
// SetSafeSearchConfig indicates an expected call of SetSafeSearchConfig.
|
||||
func (mr *MockClientMockRecorder) SetSafeSearchConfig(arg0 interface{}) *gomock.Call {
|
||||
func (mr *MockClientMockRecorder) SetSafeSearchConfig(arg0 any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetSafeSearchConfig", reflect.TypeOf((*MockClient)(nil).SetSafeSearchConfig), arg0)
|
||||
}
|
||||
|
||||
// SetStatsConfig mocks base method.
|
||||
func (m *MockClient) SetStatsConfig(arg0 *model.StatsConfig) error {
|
||||
func (m *MockClient) SetStatsConfig(arg0 *model.GetStatsConfigResponse) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SetStatsConfig", arg0)
|
||||
ret0, _ := ret[0].(error)
|
||||
@@ -512,7 +503,7 @@ func (m *MockClient) SetStatsConfig(arg0 *model.StatsConfig) error {
|
||||
}
|
||||
|
||||
// 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()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetStatsConfig", reflect.TypeOf((*MockClient)(nil).SetStatsConfig), arg0)
|
||||
}
|
||||
@@ -531,11 +522,26 @@ func (mr *MockClientMockRecorder) Setup() *gomock.Call {
|
||||
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.
|
||||
func (m *MockClient) StatsConfig() (*model.StatsConfig, error) {
|
||||
func (m *MockClient) StatsConfig() (*model.GetStatsConfigResponse, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "StatsConfig")
|
||||
ret0, _ := ret[0].(*model.StatsConfig)
|
||||
ret0, _ := ret[0].(*model.GetStatsConfigResponse)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
@@ -570,7 +576,7 @@ func (m *MockClient) ToggleFiltering(arg0 bool, arg1 int) error {
|
||||
}
|
||||
|
||||
// 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()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ToggleFiltering", reflect.TypeOf((*MockClient)(nil).ToggleFiltering), arg0, arg1)
|
||||
}
|
||||
@@ -584,7 +590,7 @@ func (m *MockClient) ToggleParental(arg0 bool) error {
|
||||
}
|
||||
|
||||
// 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()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ToggleParental", reflect.TypeOf((*MockClient)(nil).ToggleParental), arg0)
|
||||
}
|
||||
@@ -598,7 +604,7 @@ func (m *MockClient) ToggleProtection(arg0 bool) error {
|
||||
}
|
||||
|
||||
// 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()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ToggleProtection", reflect.TypeOf((*MockClient)(nil).ToggleProtection), arg0)
|
||||
}
|
||||
@@ -612,7 +618,7 @@ func (m *MockClient) ToggleSafeBrowsing(arg0 bool) error {
|
||||
}
|
||||
|
||||
// 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()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ToggleSafeBrowsing", reflect.TypeOf((*MockClient)(nil).ToggleSafeBrowsing), arg0)
|
||||
}
|
||||
@@ -626,7 +632,7 @@ func (m *MockClient) UpdateClient(arg0 *model.Client) error {
|
||||
}
|
||||
|
||||
// UpdateClient indicates an expected call of UpdateClient.
|
||||
func (mr *MockClientMockRecorder) UpdateClient(arg0 interface{}) *gomock.Call {
|
||||
func (mr *MockClientMockRecorder) UpdateClient(arg0 any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateClient", reflect.TypeOf((*MockClient)(nil).UpdateClient), arg0)
|
||||
}
|
||||
@@ -640,7 +646,7 @@ func (m *MockClient) UpdateFilter(arg0 bool, arg1 model.Filter) error {
|
||||
}
|
||||
|
||||
// UpdateFilter indicates an expected call of UpdateFilter.
|
||||
func (mr *MockClientMockRecorder) UpdateFilter(arg0, arg1 interface{}) *gomock.Call {
|
||||
func (mr *MockClientMockRecorder) UpdateFilter(arg0, arg1 any) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateFilter", reflect.TypeOf((*MockClient)(nil).UpdateFilter), arg0, arg1)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
// 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
|
||||
@@ -7,7 +12,7 @@ package client
|
||||
import (
|
||||
reflect "reflect"
|
||||
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
// MockFlags is a mock of Flags interface.
|
||||
@@ -42,7 +47,7 @@ func (m *MockFlags) Changed(arg0 string) bool {
|
||||
}
|
||||
|
||||
// Changed indicates an expected call of Changed.
|
||||
func (mr *MockFlagsMockRecorder) Changed(arg0 interface{}) *gomock.Call {
|
||||
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)
|
||||
}
|
||||
@@ -57,7 +62,7 @@ func (m *MockFlags) GetBool(arg0 string) (bool, error) {
|
||||
}
|
||||
|
||||
// GetBool indicates an expected call of GetBool.
|
||||
func (mr *MockFlagsMockRecorder) GetBool(arg0 interface{}) *gomock.Call {
|
||||
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)
|
||||
}
|
||||
@@ -72,7 +77,7 @@ func (m *MockFlags) GetInt(arg0 string) (int, error) {
|
||||
}
|
||||
|
||||
// GetInt indicates an expected call of GetInt.
|
||||
func (mr *MockFlagsMockRecorder) GetInt(arg0 interface{}) *gomock.Call {
|
||||
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)
|
||||
}
|
||||
@@ -87,7 +92,7 @@ func (m *MockFlags) GetString(arg0 string) (string, error) {
|
||||
}
|
||||
|
||||
// GetString indicates an expected call of GetString.
|
||||
func (mr *MockFlagsMockRecorder) GetString(arg0 interface{}) *gomock.Call {
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ var (
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if ac.origin.statsConfig.Interval != sc.Interval {
|
||||
if !sc.Equals(ac.origin.statsConfig) {
|
||||
return ac.client.SetStatsConfig(ac.origin.statsConfig)
|
||||
}
|
||||
return nil
|
||||
@@ -111,17 +111,6 @@ var (
|
||||
return nil
|
||||
}
|
||||
|
||||
actionBlockedServices = func(ac *actionContext) error {
|
||||
rs, err := ac.client.BlockedServices()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !model.EqualsStringSlice(ac.origin.blockedServices, rs, true) {
|
||||
return ac.client.SetBlockedServices(ac.origin.blockedServices)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
actionBlockedServicesSchedule = func(ac *actionContext) error {
|
||||
rbss, err := ac.client.BlockedServicesSchedule()
|
||||
if err != nil {
|
||||
@@ -186,6 +175,9 @@ var (
|
||||
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
|
||||
|
||||
@@ -39,7 +39,6 @@ func setupActions(cfg *types.Config) (actions []syncAction) {
|
||||
}
|
||||
if cfg.Features.Services {
|
||||
actions = append(actions,
|
||||
action("blocked services", actionBlockedServices),
|
||||
action("blocked services schedule", actionBlockedServicesSchedule),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/bakito/adguardhome-sync/pkg/log"
|
||||
"github.com/bakito/adguardhome-sync/pkg/metrics"
|
||||
"github.com/bakito/adguardhome-sync/version"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -77,6 +78,11 @@ func (w *worker) listenAndServe() {
|
||||
r.GET("/api/v1/status", w.handleStatus)
|
||||
r.GET("/favicon.ico", w.handleFavicon)
|
||||
r.GET("/", w.handleRoot)
|
||||
if w.cfg.API.Metrics.Enabled {
|
||||
r.GET("/metrics", metrics.Handler())
|
||||
|
||||
go w.startScraping()
|
||||
}
|
||||
|
||||
go func() {
|
||||
if err := httpServer.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) {
|
||||
@@ -101,7 +107,7 @@ func (w *worker) listenAndServe() {
|
||||
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()
|
||||
|
||||
if w.cron != nil {
|
||||
@@ -109,7 +115,7 @@ func (w *worker) listenAndServe() {
|
||||
w.cron.Stop()
|
||||
}
|
||||
|
||||
if err := httpServer.Shutdown(gracefullCtx); err != nil {
|
||||
if err := httpServer.Shutdown(gracefulCtx); err != nil {
|
||||
l.With("error", err).Error("Shutdown error")
|
||||
defer os.Exit(1)
|
||||
} else {
|
||||
@@ -123,8 +129,9 @@ func (w *worker) listenAndServe() {
|
||||
}
|
||||
|
||||
type syncStatus struct {
|
||||
Origin replicaStatus `json:"origin"`
|
||||
Replicas []replicaStatus `json:"replicas"`
|
||||
SyncRunning bool `json:"syncRunning"`
|
||||
Origin replicaStatus `json:"origin"`
|
||||
Replicas []replicaStatus `json:"replicas"`
|
||||
}
|
||||
|
||||
type replicaStatus struct {
|
||||
|
||||
50
pkg/sync/scrape.go
Normal file
50
pkg/sync/scrape.go
Normal 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
|
||||
}
|
||||
@@ -110,6 +110,8 @@ func (w *worker) status() *syncStatus {
|
||||
return syncStatus.Replicas[i].Host < syncStatus.Replicas[j].Host
|
||||
})
|
||||
|
||||
syncStatus.SyncRunning = w.running
|
||||
|
||||
return syncStatus
|
||||
}
|
||||
|
||||
@@ -199,12 +201,6 @@ func (w *worker) sync() {
|
||||
return
|
||||
}
|
||||
|
||||
o.blockedServices, err = oc.BlockedServices()
|
||||
if err != nil {
|
||||
sl.With("error", err).Error("Error getting origin blocked services")
|
||||
return
|
||||
}
|
||||
|
||||
o.blockedServicesSchedule, err = oc.BlockedServicesSchedule()
|
||||
if err != nil {
|
||||
sl.With("error", err).Error("Error getting origin blocked services schedule")
|
||||
@@ -325,12 +321,11 @@ func (w *worker) statusWithSetup(rl *zap.SugaredLogger, replica types.AdGuardIns
|
||||
type origin struct {
|
||||
status *model.ServerStatus
|
||||
rewrites *model.RewriteEntries
|
||||
blockedServices *model.BlockedServicesArray
|
||||
blockedServicesSchedule *model.BlockedServicesSchedule
|
||||
filters *model.FilterStatus
|
||||
clients *model.Clients
|
||||
queryLogConfig *model.QueryLogConfig
|
||||
statsConfig *model.StatsConfig
|
||||
queryLogConfig *model.QueryLogConfigWithIgnored
|
||||
statsConfig *model.GetStatsConfigResponse
|
||||
accessList *model.AccessList
|
||||
dnsConfig *model.DNSConfig
|
||||
dhcpServerConfig *model.DhcpStatus
|
||||
|
||||
@@ -9,10 +9,10 @@ import (
|
||||
"github.com/bakito/adguardhome-sync/pkg/types"
|
||||
"github.com/bakito/adguardhome-sync/pkg/utils"
|
||||
"github.com/bakito/adguardhome-sync/pkg/versions"
|
||||
gm "github.com/golang/mock/gomock"
|
||||
"github.com/google/uuid"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
gm "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
var _ = Describe("Sync", func() {
|
||||
@@ -67,8 +67,8 @@ var _ = Describe("Sync", func() {
|
||||
},
|
||||
status: &model.ServerStatus{},
|
||||
safeSearch: &model.SafeSearchConfig{},
|
||||
queryLogConfig: &model.QueryLogConfig{},
|
||||
statsConfig: &model.StatsConfig{},
|
||||
queryLogConfig: &model.QueryLogConfigWithIgnored{},
|
||||
statsConfig: &model.PutStatsConfigUpdateRequest{},
|
||||
},
|
||||
replicaStatus: &model.ServerStatus{},
|
||||
client: cl,
|
||||
@@ -289,9 +289,9 @@ var _ = Describe("Sync", func() {
|
||||
})
|
||||
})
|
||||
Context("actionQueryLogConfig", func() {
|
||||
var qlc *model.QueryLogConfig
|
||||
var qlc *model.QueryLogConfigWithIgnored
|
||||
BeforeEach(func() {
|
||||
qlc = &model.QueryLogConfig{}
|
||||
qlc = &model.QueryLogConfigWithIgnored{}
|
||||
})
|
||||
It("should have no changes", func() {
|
||||
cl.EXPECT().QueryLogConfig().Return(qlc, nil)
|
||||
@@ -302,15 +302,15 @@ var _ = Describe("Sync", func() {
|
||||
var interval model.QueryLogConfigInterval = 123
|
||||
ac.origin.queryLogConfig.Interval = &interval
|
||||
cl.EXPECT().QueryLogConfig().Return(qlc, nil)
|
||||
cl.EXPECT().SetQueryLogConfig(&model.QueryLogConfig{AnonymizeClientIp: nil, Interval: &interval, Enabled: nil})
|
||||
cl.EXPECT().SetQueryLogConfig(&model.QueryLogConfigWithIgnored{QueryLogConfig: model.QueryLogConfig{AnonymizeClientIp: nil, Interval: &interval, Enabled: nil}})
|
||||
err := actionQueryLogConfig(ac)
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
})
|
||||
})
|
||||
Context("syncConfigs", func() {
|
||||
var sc *model.StatsConfig
|
||||
var sc *model.PutStatsConfigUpdateRequest
|
||||
BeforeEach(func() {
|
||||
sc = &model.StatsConfig{}
|
||||
sc = &model.PutStatsConfigUpdateRequest{}
|
||||
})
|
||||
It("should have no changes", func() {
|
||||
cl.EXPECT().StatsConfig().Return(sc, nil)
|
||||
@@ -318,10 +318,10 @@ var _ = Describe("Sync", func() {
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
})
|
||||
It("should have StatsConfig changes", func() {
|
||||
var interval model.StatsConfigInterval = 123
|
||||
ac.origin.statsConfig.Interval = &interval
|
||||
var interval float32 = 123
|
||||
ac.origin.statsConfig.Interval = interval
|
||||
cl.EXPECT().StatsConfig().Return(sc, nil)
|
||||
cl.EXPECT().SetStatsConfig(&model.StatsConfig{Interval: &interval})
|
||||
cl.EXPECT().SetStatsConfig(&model.PutStatsConfigUpdateRequest{Interval: interval})
|
||||
err := actionStatsConfig(ac)
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
})
|
||||
@@ -359,26 +359,6 @@ var _ = Describe("Sync", func() {
|
||||
Ω(st).Should(BeNil())
|
||||
})
|
||||
})
|
||||
Context("actionBlockedServices", func() {
|
||||
var rbs *model.BlockedServicesArray
|
||||
BeforeEach(func() {
|
||||
ac.origin.blockedServices = &model.BlockedServicesArray{"foo"}
|
||||
rbs = &model.BlockedServicesArray{"foo"}
|
||||
})
|
||||
It("should have no changes", func() {
|
||||
cl.EXPECT().BlockedServices().Return(rbs, nil)
|
||||
err := actionBlockedServices(ac)
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
})
|
||||
It("should have blockedServices changes", func() {
|
||||
ac.origin.blockedServices = &model.BlockedServicesArray{"bar"}
|
||||
|
||||
cl.EXPECT().BlockedServices().Return(rbs, nil)
|
||||
cl.EXPECT().SetBlockedServices(ac.origin.blockedServices)
|
||||
err := actionBlockedServices(ac)
|
||||
Ω(err).ShouldNot(HaveOccurred())
|
||||
})
|
||||
})
|
||||
Context("actionBlockedServicesSchedule", func() {
|
||||
var rbss *model.BlockedServicesSchedule
|
||||
BeforeEach(func() {
|
||||
@@ -599,12 +579,11 @@ var _ = Describe("Sync", func() {
|
||||
cl.EXPECT().SafeSearchConfig().Return(&model.SafeSearchConfig{}, nil)
|
||||
cl.EXPECT().SafeBrowsing()
|
||||
cl.EXPECT().RewriteList().Return(&model.RewriteEntries{}, nil)
|
||||
cl.EXPECT().BlockedServices()
|
||||
cl.EXPECT().BlockedServicesSchedule()
|
||||
cl.EXPECT().Filtering().Return(&model.FilterStatus{}, nil)
|
||||
cl.EXPECT().Clients().Return(&model.Clients{}, nil)
|
||||
cl.EXPECT().QueryLogConfig().Return(&model.QueryLogConfig{}, nil)
|
||||
cl.EXPECT().StatsConfig().Return(&model.StatsConfig{}, 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)
|
||||
cl.EXPECT().DhcpConfig().Return(&model.DhcpStatus{}, nil)
|
||||
@@ -616,13 +595,12 @@ var _ = Describe("Sync", func() {
|
||||
cl.EXPECT().Parental()
|
||||
cl.EXPECT().SafeSearchConfig().Return(&model.SafeSearchConfig{}, nil)
|
||||
cl.EXPECT().SafeBrowsing()
|
||||
cl.EXPECT().QueryLogConfig().Return(&model.QueryLogConfig{}, nil)
|
||||
cl.EXPECT().StatsConfig().Return(&model.StatsConfig{}, nil)
|
||||
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().BlockedServices()
|
||||
cl.EXPECT().BlockedServicesSchedule()
|
||||
cl.EXPECT().Clients().Return(&model.Clients{}, nil)
|
||||
cl.EXPECT().AccessList().Return(&model.AccessList{}, nil)
|
||||
@@ -641,12 +619,11 @@ var _ = Describe("Sync", func() {
|
||||
cl.EXPECT().SafeSearchConfig().Return(&model.SafeSearchConfig{}, nil)
|
||||
cl.EXPECT().SafeBrowsing()
|
||||
cl.EXPECT().RewriteList().Return(&model.RewriteEntries{}, nil)
|
||||
cl.EXPECT().BlockedServices()
|
||||
cl.EXPECT().BlockedServicesSchedule()
|
||||
cl.EXPECT().Filtering().Return(&model.FilterStatus{}, nil)
|
||||
cl.EXPECT().Clients().Return(&model.Clients{}, nil)
|
||||
cl.EXPECT().QueryLogConfig().Return(&model.QueryLogConfig{}, nil)
|
||||
cl.EXPECT().StatsConfig().Return(&model.StatsConfig{}, 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)
|
||||
|
||||
@@ -657,13 +634,12 @@ var _ = Describe("Sync", func() {
|
||||
cl.EXPECT().Parental()
|
||||
cl.EXPECT().SafeSearchConfig().Return(&model.SafeSearchConfig{}, nil)
|
||||
cl.EXPECT().SafeBrowsing()
|
||||
cl.EXPECT().QueryLogConfig().Return(&model.QueryLogConfig{}, nil)
|
||||
cl.EXPECT().StatsConfig().Return(&model.StatsConfig{}, nil)
|
||||
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().BlockedServices()
|
||||
cl.EXPECT().BlockedServicesSchedule()
|
||||
cl.EXPECT().Clients().Return(&model.Clients{}, nil)
|
||||
cl.EXPECT().AccessList().Return(&model.AccessList{}, nil)
|
||||
@@ -685,12 +661,11 @@ var _ = Describe("Sync", func() {
|
||||
cl.EXPECT().SafeSearchConfig().Return(&model.SafeSearchConfig{}, nil)
|
||||
cl.EXPECT().SafeBrowsing()
|
||||
cl.EXPECT().RewriteList().Return(&model.RewriteEntries{}, nil)
|
||||
cl.EXPECT().BlockedServices()
|
||||
cl.EXPECT().BlockedServicesSchedule()
|
||||
cl.EXPECT().Filtering().Return(&model.FilterStatus{}, nil)
|
||||
cl.EXPECT().Clients().Return(&model.Clients{}, nil)
|
||||
cl.EXPECT().QueryLogConfig().Return(&model.QueryLogConfig{}, nil)
|
||||
cl.EXPECT().StatsConfig().Return(&model.StatsConfig{}, 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)
|
||||
cl.EXPECT().DhcpConfig().Return(&model.DhcpStatus{}, nil)
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
@@ -29,10 +30,18 @@ type Config struct {
|
||||
|
||||
// API configuration
|
||||
type API struct {
|
||||
Port int `json:"port,omitempty" yaml:"port,omitempty" env:"API_PORT"`
|
||||
Username string `json:"username,omitempty" yaml:"username,omitempty" env:"API_USERNAME"`
|
||||
Password string `json:"password,omitempty" yaml:"password,omitempty" env:"API_PASSWORD"`
|
||||
DarkMode bool `json:"darkMode,omitempty" yaml:"darkMode,omitempty" env:"API_DARK_MODE"`
|
||||
Port int `json:"port,omitempty" yaml:"port,omitempty" env:"API_PORT"`
|
||||
Username string `json:"username,omitempty" yaml:"username,omitempty" env:"API_USERNAME"`
|
||||
Password string `json:"password,omitempty" yaml:"password,omitempty" env:"API_PASSWORD"`
|
||||
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
|
||||
|
||||
1
testdata/config_test_replica.yaml
vendored
1
testdata/config_test_replica.yaml
vendored
@@ -15,6 +15,7 @@ replica:
|
||||
insecureSkipVerify: false
|
||||
autoSetup: false
|
||||
interfaceName: eth3
|
||||
dhcpServerEnabled: false
|
||||
cron: '*/15 * * * *'
|
||||
runOnStart: true
|
||||
printConfigOnly: true
|
||||
|
||||
1
testdata/config_test_replicas.yaml
vendored
1
testdata/config_test_replicas.yaml
vendored
@@ -15,6 +15,7 @@ replicas:
|
||||
insecureSkipVerify: false
|
||||
autoSetup: false
|
||||
interfaceName: eth3
|
||||
dhcpServerEnabled: false
|
||||
cron: '*/15 * * * *'
|
||||
runOnStart: true
|
||||
printConfigOnly: true
|
||||
|
||||
@@ -15,6 +15,7 @@ replica:
|
||||
insecureSkipVerify: false
|
||||
autoSetup: false
|
||||
interfaceName: eth3
|
||||
dhcpServerEnabled: false
|
||||
replicas:
|
||||
- url: https://replicas-file:443
|
||||
webURL: https://replicas-file:443
|
||||
@@ -24,6 +25,7 @@ replicas:
|
||||
insecureSkipVerify: false
|
||||
autoSetup: false
|
||||
interfaceName: eth3
|
||||
dhcpServerEnabled: false
|
||||
cron: '*/15 * * * *'
|
||||
runOnStart: true
|
||||
printConfigOnly: true
|
||||
|
||||
11
testdata/e2e/bin/show-sync-metrics.sh
vendored
Executable file
11
testdata/e2e/bin/show-sync-metrics.sh
vendored
Executable 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
|
||||
18
testdata/e2e/bin/wait-for-sync.sh
vendored
18
testdata/e2e/bin/wait-for-sync.sh
vendored
@@ -1,8 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
kubectl wait --for=jsonpath='{.status.phase}'=Succeeded pod/adguardhome-sync --timeout=1m
|
||||
RESULT=$?
|
||||
if [[ "${RESULT}" != "0" ]]; then
|
||||
kubectl logs adguardhome-sync
|
||||
fi
|
||||
exit ${RESULT}
|
||||
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
|
||||
|
||||
@@ -5,7 +5,10 @@ metadata:
|
||||
name: sync-conf
|
||||
namespace: {{ .Release.Namespace }}
|
||||
data:
|
||||
API_PORT: '0'
|
||||
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'
|
||||
|
||||
@@ -11,7 +11,10 @@ data:
|
||||
username: username
|
||||
password: password
|
||||
api:
|
||||
port: 0
|
||||
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'
|
||||
|
||||
8
testdata/querylog_config.json
vendored
Normal file
8
testdata/querylog_config.json
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"enabled": true,
|
||||
"interval": 90,
|
||||
"anonymize_client_ip": false,
|
||||
"ignored": [
|
||||
"foo.bar"
|
||||
]
|
||||
}
|
||||
5
testdata/querylog_info.json
vendored
5
testdata/querylog_info.json
vendored
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"enabled": true,
|
||||
"interval": 90,
|
||||
"anonymize_client_ip": false
|
||||
}
|
||||
14
tools.go
Normal file
14
tools.go
Normal file
@@ -0,0 +1,14 @@
|
||||
//go:build tools
|
||||
// +build tools
|
||||
|
||||
package tools
|
||||
|
||||
import (
|
||||
_ "github.com/bakito/semver"
|
||||
_ "github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen"
|
||||
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
|
||||
_ "github.com/goreleaser/goreleaser"
|
||||
_ "github.com/onsi/ginkgo/v2/ginkgo"
|
||||
_ "go.uber.org/mock/mockgen"
|
||||
_ "k8s.io/code-generator/cmd/deepcopy-gen"
|
||||
)
|
||||
Reference in New Issue
Block a user