Compare commits
2 Commits
0.0.4
...
feat-ionos
| Author | SHA1 | Date | |
|---|---|---|---|
| 3b10d88e6f | |||
| f1458b005b |
@@ -4,32 +4,45 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
paths:
|
|
||||||
- "go.mod"
|
|
||||||
- "go.sum"
|
|
||||||
- "**/*.go"
|
|
||||||
- "config.example.yaml"
|
|
||||||
- "Dockerfile"
|
|
||||||
- "Makefile"
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
DOCKER_REGISTRY: gitea.t000-n.de
|
DOCKER_REGISTRY: gitea.t000-n.de
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
check-changes:
|
||||||
|
name: Check changes
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
code: ${{ steps.filter.outputs.code }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Get changes
|
||||||
|
id: filter
|
||||||
|
uses: dorny/paths-filter@v3
|
||||||
|
with:
|
||||||
|
filters: |
|
||||||
|
code:
|
||||||
|
- 'go.mod'
|
||||||
|
- 'go.sum'
|
||||||
|
- '**/*.go'
|
||||||
|
- 'config.example.yaml'
|
||||||
|
- 'Dockerfile'
|
||||||
|
- 'Makefile'
|
||||||
|
|
||||||
test:
|
test:
|
||||||
name: test
|
name: test
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
|
uses: actions/checkout@v4
|
||||||
- name: Setup go
|
- name: Setup go
|
||||||
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version-file: go.mod
|
go-version-file: go.mod
|
||||||
check-latest: true
|
check-latest: true
|
||||||
- name: Create cache key
|
- name: Create cache key
|
||||||
uses: https://gitea.com/actions/go-hashfiles@264ae76b7e50173ce71ed7da4b48e5e517f3f9ec # v0.0.1
|
uses: https://gitea.com/actions/go-hashfiles@v0.0.1
|
||||||
id: hash-go
|
id: hash-go
|
||||||
with:
|
with:
|
||||||
patterns: |
|
patterns: |
|
||||||
@@ -37,7 +50,7 @@ jobs:
|
|||||||
go.sum
|
go.sum
|
||||||
- name: cache go
|
- name: cache go
|
||||||
id: cache-go
|
id: cache-go
|
||||||
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
/go_path
|
/go_path
|
||||||
@@ -57,16 +70,18 @@ jobs:
|
|||||||
arch: [amd64, arm64]
|
arch: [amd64, arm64]
|
||||||
needs:
|
needs:
|
||||||
- test
|
- test
|
||||||
|
- check-changes
|
||||||
|
if: ${{ needs.check-changes.outputs.code == 'true' }}
|
||||||
runs-on:
|
runs-on:
|
||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
- linux_${{ matrix.arch }}
|
- linux_${{ matrix.arch }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
|
uses: actions/checkout@v4
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
|
uses: docker/setup-buildx-action@v3
|
||||||
- name: Login to Registry
|
- name: Login to Registry
|
||||||
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ${{ env.DOCKER_REGISTRY }}
|
registry: ${{ env.DOCKER_REGISTRY }}
|
||||||
username: ${{ secrets.REGISTRY_USER }}
|
username: ${{ secrets.REGISTRY_USER }}
|
||||||
@@ -77,7 +92,7 @@ jobs:
|
|||||||
echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}' | tr '[:upper:]' '[:lower:]') >> $GITHUB_OUTPUT
|
echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}' | tr '[:upper:]' '[:lower:]') >> $GITHUB_OUTPUT
|
||||||
echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT
|
echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
@@ -88,36 +103,14 @@ jobs:
|
|||||||
tags: |
|
tags: |
|
||||||
${{ env.DOCKER_REGISTRY }}/t.behrendt/${{ steps.meta.outputs.REPO_NAME }}:${{ steps.meta.outputs.REPO_VERSION }}-${{ matrix.arch }}
|
${{ env.DOCKER_REGISTRY }}/t.behrendt/${{ steps.meta.outputs.REPO_NAME }}:${{ steps.meta.outputs.REPO_VERSION }}-${{ matrix.arch }}
|
||||||
|
|
||||||
create_tag:
|
|
||||||
name: Create tag
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
outputs:
|
|
||||||
tag: ${{ steps.tag.outputs.new-tag }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
- uses: https://gitea.t000-n.de/t.behrendt/conventional-semantic-git-tag-increment@9841c96e72d4fc1ecec620e91e213895341cce86 # 0.1.22
|
|
||||||
id: tag
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.GITEA_TOKEN }}
|
|
||||||
prerelease: ${{ github.event_name == 'workflow_dispatch' }}
|
|
||||||
- run: |
|
|
||||||
git tag ${{ steps.tag.outputs.new-tag }}
|
|
||||||
git push origin ${{ steps.tag.outputs.new-tag }}
|
|
||||||
- name: Set output
|
|
||||||
run: |
|
|
||||||
echo "tag=${{ steps.tag.outputs.new-tag }}" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
create_manifest:
|
create_manifest:
|
||||||
name: Create manifest
|
name: Create manifest
|
||||||
needs:
|
needs:
|
||||||
- build_and_push
|
- build_and_push
|
||||||
- create_tag
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Get Metadata
|
- name: Get Metadata
|
||||||
id: meta
|
id: meta
|
||||||
@@ -126,7 +119,7 @@ jobs:
|
|||||||
echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT
|
echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Login to Registry
|
- name: Login to Registry
|
||||||
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ${{ env.DOCKER_REGISTRY }}
|
registry: ${{ env.DOCKER_REGISTRY }}
|
||||||
username: ${{ secrets.REGISTRY_USER }}
|
username: ${{ secrets.REGISTRY_USER }}
|
||||||
@@ -134,8 +127,8 @@ jobs:
|
|||||||
|
|
||||||
- name: Create manifest
|
- name: Create manifest
|
||||||
run: |
|
run: |
|
||||||
docker manifest create ${{ env.DOCKER_REGISTRY }}/t.behrendt/${{ steps.meta.outputs.REPO_NAME }}:${{ needs.create_tag.outputs.tag }} \
|
docker manifest create ${{ env.DOCKER_REGISTRY }}/t.behrendt/${{ steps.meta.outputs.REPO_NAME }}:latest \
|
||||||
${{ env.DOCKER_REGISTRY }}/t.behrendt/${{ steps.meta.outputs.REPO_NAME }}:${{ steps.meta.outputs.REPO_VERSION }}-amd64 \
|
${{ env.DOCKER_REGISTRY }}/t.behrendt/${{ steps.meta.outputs.REPO_NAME }}:${{ steps.meta.outputs.REPO_VERSION }}-amd64 \
|
||||||
${{ env.DOCKER_REGISTRY }}/t.behrendt/${{ steps.meta.outputs.REPO_NAME }}:${{ steps.meta.outputs.REPO_VERSION }}-arm64
|
${{ env.DOCKER_REGISTRY }}/t.behrendt/${{ steps.meta.outputs.REPO_NAME }}:${{ steps.meta.outputs.REPO_VERSION }}-arm64
|
||||||
|
|
||||||
docker manifest push ${{ env.DOCKER_REGISTRY }}/t.behrendt/${{ steps.meta.outputs.REPO_NAME }}:${{ needs.create_tag.outputs.tag }}
|
docker manifest push ${{ env.DOCKER_REGISTRY }}/t.behrendt/${{ steps.meta.outputs.REPO_NAME }}:latest
|
||||||
|
|||||||
@@ -13,14 +13,14 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
|
uses: actions/checkout@v4
|
||||||
- name: Setup go
|
- name: Setup go
|
||||||
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version-file: go.mod
|
go-version-file: go.mod
|
||||||
check-latest: true
|
check-latest: true
|
||||||
- name: Create cache key
|
- name: Create cache key
|
||||||
uses: https://gitea.com/actions/go-hashfiles@264ae76b7e50173ce71ed7da4b48e5e517f3f9ec # v0.0.1
|
uses: https://gitea.com/actions/go-hashfiles@v0.0.1
|
||||||
id: hash-go
|
id: hash-go
|
||||||
with:
|
with:
|
||||||
patterns: |
|
patterns: |
|
||||||
@@ -28,7 +28,7 @@ jobs:
|
|||||||
go.sum
|
go.sum
|
||||||
- name: cache go
|
- name: cache go
|
||||||
id: cache-go
|
id: cache-go
|
||||||
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
/go_path
|
/go_path
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.25-alpine@sha256:26111811bc967321e7b6f852e914d14bede324cd1accb7f81811929a6a57fea9 as build
|
FROM golang:1.24-alpine as build
|
||||||
|
|
||||||
ARG GOARCH=amd64
|
ARG GOARCH=amd64
|
||||||
|
|
||||||
@@ -9,6 +9,6 @@ COPY . .
|
|||||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${GOARCH} \
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${GOARCH} \
|
||||||
go build -trimpath -ldflags="-s -w" -o main .
|
go build -trimpath -ldflags="-s -w" -o main .
|
||||||
|
|
||||||
FROM gcr.io/distroless/static-debian12@sha256:4b2a093ef4649bccd586625090a3c668b254cfe180dee54f4c94f3e9bd7e381e
|
FROM gcr.io/distroless/static-debian12
|
||||||
COPY --from=build /app/main /
|
COPY --from=build /app/main /
|
||||||
CMD ["/main"]
|
CMD ["/main"]
|
||||||
|
|||||||
@@ -8,10 +8,6 @@ dns_provider:
|
|||||||
config:
|
config:
|
||||||
api_key: <your-api-key>
|
api_key: <your-api-key>
|
||||||
base_url: https://api.hosting.ionos.com/dns
|
base_url: https://api.hosting.ionos.com/dns
|
||||||
# Optional: default TTL to use when patching records with missing TTL (default: 300)
|
|
||||||
# default_ttl: 300
|
|
||||||
# Optional: default priority to use when patching records with missing priority (default: 0)
|
|
||||||
# default_prio: 0
|
|
||||||
notification_provider:
|
notification_provider:
|
||||||
type: gotify
|
type: gotify
|
||||||
config:
|
config:
|
||||||
|
|||||||
10
go.mod
10
go.mod
@@ -1,18 +1,18 @@
|
|||||||
module realdnydns
|
module realdnydns
|
||||||
|
|
||||||
go 1.25.0
|
go 1.24.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gitea.t000-n.de/t.behrendt/ionosDnsClient v1.0.2
|
|
||||||
github.com/go-co-op/gocron v1.37.0
|
github.com/go-co-op/gocron v1.37.0
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
|
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/oapi-codegen/runtime v1.1.1 // indirect
|
github.com/redis/go-redis/v9 v9.7.0 // indirect
|
||||||
github.com/robfig/cron/v3 v3.0.1 // indirect
|
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||||
github.com/stretchr/testify v1.11.1 // indirect
|
github.com/stretchr/testify v1.10.0 // indirect
|
||||||
go.uber.org/atomic v1.11.0 // indirect
|
go.uber.org/atomic v1.11.0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
20
go.sum
20
go.sum
@@ -1,19 +1,16 @@
|
|||||||
gitea.t000-n.de/t.behrendt/ionosDnsClient v1.0.2 h1:EWz4kLLv7lSZx/F8K0/WxN5xeVNh7z4qbeDurZYBcNk=
|
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
|
||||||
gitea.t000-n.de/t.behrendt/ionosDnsClient v1.0.2/go.mod h1:HZfdMF7X9LK/3FP1jJVzMWbM5BcgcZg/Qwx2WClFipg=
|
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
|
|
||||||
github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ=
|
|
||||||
github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk=
|
|
||||||
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
|
|
||||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||||
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||||
github.com/go-co-op/gocron v1.37.0 h1:ZYDJGtQ4OMhTLKOKMIch+/CY70Brbb1dGdooLEhh7b0=
|
github.com/go-co-op/gocron v1.37.0 h1:ZYDJGtQ4OMhTLKOKMIch+/CY70Brbb1dGdooLEhh7b0=
|
||||||
github.com/go-co-op/gocron v1.37.0/go.mod h1:3L/n6BkO7ABj+TrfSVXLRzsP26zmikL4ISkLQ0O8iNY=
|
github.com/go-co-op/gocron v1.37.0/go.mod h1:3L/n6BkO7ABj+TrfSVXLRzsP26zmikL4ISkLQ0O8iNY=
|
||||||
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE=
|
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||||
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
|
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
|
||||||
@@ -22,17 +19,16 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
|||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmtpMYro=
|
|
||||||
github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
|
|
||||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa9E=
|
||||||
|
github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=
|
||||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||||
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
||||||
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
|
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
|
||||||
github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
|
github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
|
||||||
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
|
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
@@ -40,8 +36,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
|
|||||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||||
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
|
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
|
||||||
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
|
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
|
||||||
|
|||||||
224
pkg/dnsProvider/ionos/api/ionosAPI.go
Normal file
224
pkg/dnsProvider/ionos/api/ionosAPI.go
Normal file
@@ -0,0 +1,224 @@
|
|||||||
|
package ionosAPI
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"realdnydns/model/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Docs: https://developer.hosting.ionos.com/docs/dns
|
||||||
|
*/
|
||||||
|
type IonosAPI interface {
|
||||||
|
GetARecord(tld string, subdomain string) (*common.ARecord, error)
|
||||||
|
SetARecord(tld string, subdomain string, ip net.IP, ttl int, prio int, disabled bool) (*common.ARecord, error)
|
||||||
|
GetZoneId(tld string) (string, error)
|
||||||
|
GetRecordId(zoneId string, tld string, subdomain string, recordType string) (string, error)
|
||||||
|
HttpCall(method string, url string, body io.Reader, queryParams map[string]string) (*http.Response, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type IonosAPIImpl struct {
|
||||||
|
APIKey string
|
||||||
|
BaseURL string
|
||||||
|
HTTPClient *http.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
type ZonesResponse []struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Id string `json:"id"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ZoneResponse struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Records []RecordResponse `json:"records"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RecordResponse struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
RootName string `json:"rootName"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Content string `json:"content"`
|
||||||
|
ChangeDate string `json:"changeDate"`
|
||||||
|
TTL int `json:"ttl"`
|
||||||
|
Prio int `json:"prio"`
|
||||||
|
Disabled bool `json:"disabled"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ChangeRecord struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Content string `json:"content"`
|
||||||
|
TTL int `json:"ttl"`
|
||||||
|
Prio int `json:"prio"`
|
||||||
|
Disabled bool `json:"disabled"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ChangeRecordRequest struct {
|
||||||
|
Content string `json:"content"`
|
||||||
|
TTL int `json:"ttl"`
|
||||||
|
Prio int `json:"prio"`
|
||||||
|
Disabled bool `json:"disabled"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(APIKey string, BaseURL string) IonosAPI {
|
||||||
|
return &IonosAPIImpl{
|
||||||
|
APIKey: APIKey,
|
||||||
|
BaseURL: BaseURL,
|
||||||
|
HTTPClient: &http.Client{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IonosAPIImpl) HttpCall(method string, path string, body io.Reader, queryParams map[string]string) (*http.Response, error) {
|
||||||
|
requestUrl, _ := url.Parse(i.BaseURL + path)
|
||||||
|
|
||||||
|
query := requestUrl.Query()
|
||||||
|
for key, value := range queryParams {
|
||||||
|
query.Add(key, value)
|
||||||
|
}
|
||||||
|
requestUrl.RawQuery = query.Encode()
|
||||||
|
|
||||||
|
req, err := http.NewRequest(method, requestUrl.String(), body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Add("X-API-Key", i.APIKey)
|
||||||
|
req.Header.Add("Content-Type", "application/json")
|
||||||
|
req.Header.Add("Accept", "application/json")
|
||||||
|
|
||||||
|
return i.HTTPClient.Do(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IonosAPIImpl) GetZoneId(tld string) (string, error) {
|
||||||
|
res, err := i.HttpCall("GET", "/v1/zones", nil, nil)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
responseBody := make([]byte, res.ContentLength)
|
||||||
|
res.Body.Read(responseBody)
|
||||||
|
|
||||||
|
zones := []ZoneResponse{}
|
||||||
|
json.Unmarshal(responseBody, &zones)
|
||||||
|
|
||||||
|
for _, z := range zones {
|
||||||
|
if z.Name == tld {
|
||||||
|
return z.Id, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "", errors.New("zone not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IonosAPIImpl) GetRecordId(zoneId string, tld string, subdomain string, recordType string) (string, error) {
|
||||||
|
var domain string
|
||||||
|
if subdomain == "@" || subdomain == "" {
|
||||||
|
domain = tld
|
||||||
|
} else {
|
||||||
|
domain = subdomain + "." + tld
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := i.HttpCall("GET", "/v1/zones/"+zoneId, nil, map[string]string{"recordName": domain, "recordType": recordType})
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
responseBody := make([]byte, res.ContentLength)
|
||||||
|
res.Body.Read(responseBody)
|
||||||
|
|
||||||
|
zone := ZoneResponse{}
|
||||||
|
json.Unmarshal(responseBody, &zone)
|
||||||
|
|
||||||
|
for _, record := range zone.Records {
|
||||||
|
if record.Type == recordType && record.Name == domain {
|
||||||
|
return record.Id, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "", errors.New("record not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *IonosAPIImpl) SetARecord(tld string, subdomain string, ip net.IP, ttl int, prio int, disabled bool) (*common.ARecord, error) {
|
||||||
|
zoneId, err := i.GetZoneId(tld)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
recordId, err := i.GetRecordId(zoneId, tld, subdomain, "A")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
changeRecordRequest, err := json.Marshal(ChangeRecordRequest{
|
||||||
|
Content: ip.String(),
|
||||||
|
TTL: ttl,
|
||||||
|
Prio: prio,
|
||||||
|
Disabled: false,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := i.HttpCall("PUT", "/v1/zones/"+zoneId+"/records/"+recordId, bytes.NewReader(changeRecordRequest), nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
responseBody := make([]byte, res.ContentLength)
|
||||||
|
res.Body.Read(responseBody)
|
||||||
|
|
||||||
|
if res.StatusCode != 200 {
|
||||||
|
return nil, errors.New("error updating record")
|
||||||
|
}
|
||||||
|
|
||||||
|
changeRecord := ChangeRecord{}
|
||||||
|
json.Unmarshal(responseBody, &changeRecord)
|
||||||
|
|
||||||
|
return &common.ARecord{
|
||||||
|
Domain: changeRecord.Name,
|
||||||
|
IP: changeRecord.Content,
|
||||||
|
TTL: changeRecord.TTL,
|
||||||
|
Prio: changeRecord.Prio,
|
||||||
|
Disabled: changeRecord.Disabled,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ionos *IonosAPIImpl) GetARecord(tld string, subdomain string) (*common.ARecord, error) {
|
||||||
|
zoneId, err := ionos.GetZoneId(tld)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
recordId, err := ionos.GetRecordId(zoneId, tld, subdomain, "A")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := ionos.HttpCall("GET", "/v1/zones/"+zoneId+"/records/"+recordId, nil, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
responseBody := make([]byte, res.ContentLength)
|
||||||
|
res.Body.Read(responseBody)
|
||||||
|
|
||||||
|
record := RecordResponse{}
|
||||||
|
json.Unmarshal(responseBody, &record)
|
||||||
|
|
||||||
|
return &common.ARecord{
|
||||||
|
Domain: record.Name,
|
||||||
|
IP: record.Content,
|
||||||
|
TTL: record.TTL,
|
||||||
|
Prio: record.Prio,
|
||||||
|
Disabled: record.Disabled,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
285
pkg/dnsProvider/ionos/api/ionosAPI_test.go
Normal file
285
pkg/dnsProvider/ionos/api/ionosAPI_test.go
Normal file
@@ -0,0 +1,285 @@
|
|||||||
|
package ionosAPI
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func utilMockServerImpl() func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
zonesResponse := []ZoneResponse{
|
||||||
|
{
|
||||||
|
Name: "example.com",
|
||||||
|
Id: "1234567890",
|
||||||
|
Type: "NATIVE",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "notTheExample.org",
|
||||||
|
Id: "0987654321",
|
||||||
|
Type: "SLAVE",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
zonesResponseJson, _ := json.Marshal(zonesResponse)
|
||||||
|
|
||||||
|
recordResponseSub := RecordResponse{
|
||||||
|
Id: "abcdefghij",
|
||||||
|
Name: "example.com",
|
||||||
|
RootName: "example.com",
|
||||||
|
Type: "A",
|
||||||
|
Content: "127.0.0.1",
|
||||||
|
ChangeDate: "2019-12-09T13:04:25.772Z",
|
||||||
|
TTL: 300,
|
||||||
|
Prio: 0,
|
||||||
|
Disabled: false,
|
||||||
|
}
|
||||||
|
recordResponseSubJson, _ := json.Marshal(recordResponseSub)
|
||||||
|
|
||||||
|
recordResponseTLD := RecordResponse{
|
||||||
|
Id: "jihgfedcba",
|
||||||
|
Name: "sub.example.com",
|
||||||
|
RootName: "example.com",
|
||||||
|
Type: "A",
|
||||||
|
Content: "127.0.0.2",
|
||||||
|
ChangeDate: "2019-12-09T13:04:25.772Z",
|
||||||
|
TTL: 300,
|
||||||
|
Prio: 0,
|
||||||
|
Disabled: false,
|
||||||
|
}
|
||||||
|
recordResponseTLDJson, _ := json.Marshal(recordResponseTLD)
|
||||||
|
|
||||||
|
zoneResponse := ZoneResponse{
|
||||||
|
Id: "1234567890",
|
||||||
|
Name: "example.com",
|
||||||
|
Type: "NATIVE",
|
||||||
|
Records: []RecordResponse{
|
||||||
|
recordResponseSub,
|
||||||
|
recordResponseTLD,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
zoneResponseJson, _ := json.Marshal(zoneResponse)
|
||||||
|
|
||||||
|
changeRecord := ChangeRecord{
|
||||||
|
Name: "sub.example.com",
|
||||||
|
Type: "A",
|
||||||
|
Content: "127.0.0.1",
|
||||||
|
TTL: 300,
|
||||||
|
Prio: 0,
|
||||||
|
Disabled: false,
|
||||||
|
}
|
||||||
|
changeRecordJson, _ := json.Marshal(changeRecord)
|
||||||
|
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var response []byte
|
||||||
|
|
||||||
|
if r.Method == "GET" {
|
||||||
|
if r.RequestURI == "/v1/zones" {
|
||||||
|
response = zonesResponseJson
|
||||||
|
} else if r.RequestURI == "/v1/zones/1234567890?recordName=example.com&recordType=A" ||
|
||||||
|
r.RequestURI == "/v1/zones/1234567890?recordName=sub.example.com&recordType=A" {
|
||||||
|
response = zoneResponseJson
|
||||||
|
} else if r.RequestURI == "/v1/zones/1234567890/records/abcdefghij" {
|
||||||
|
response = recordResponseSubJson
|
||||||
|
} else if r.RequestURI == "/v1/zones/1234567890/records/jihgfedcba" {
|
||||||
|
response = recordResponseTLDJson
|
||||||
|
}
|
||||||
|
} else if r.Method == "PUT" {
|
||||||
|
response = changeRecordJson
|
||||||
|
} else {
|
||||||
|
response = []byte("404")
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Write(response)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHttpCall(t *testing.T) {
|
||||||
|
mockServer := httptest.NewServer(http.HandlerFunc(utilMockServerImpl()))
|
||||||
|
defer mockServer.Close()
|
||||||
|
|
||||||
|
ionosAPI := New("dummyKey", mockServer.URL)
|
||||||
|
|
||||||
|
t.Run("returns response for GET request", testHttpCallGet(ionosAPI))
|
||||||
|
t.Run("returns response for PUT request", testHttpCallPut(ionosAPI))
|
||||||
|
t.Run("returns error for non existing endpoint", testHttpCallNonExistingEndpoint())
|
||||||
|
}
|
||||||
|
|
||||||
|
func testHttpCallGet(api IonosAPI) func(t *testing.T) {
|
||||||
|
return func(t *testing.T) {
|
||||||
|
res, err := api.HttpCall("GET", "/v1/zones", nil, nil)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("HttpCall() returned unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if res.StatusCode != 200 {
|
||||||
|
t.Fatalf("HttpCall() returned unexpected status code: %v instead of 200", res.StatusCode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testHttpCallPut(api IonosAPI) func(t *testing.T) {
|
||||||
|
return func(t *testing.T) {
|
||||||
|
res, err := api.HttpCall("PUT", "/v1/zones/1234567890/records/abcdefghij", nil, nil)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("HttpCall() returned unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if res.StatusCode != 200 {
|
||||||
|
t.Fatalf("HttpCall() returned unexpected status code: %v instead of 200", res.StatusCode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testHttpCallNonExistingEndpoint() func(t *testing.T) {
|
||||||
|
return func(t *testing.T) {
|
||||||
|
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(404)
|
||||||
|
}))
|
||||||
|
defer mockServer.Close()
|
||||||
|
|
||||||
|
api := New("dummyKey", mockServer.URL)
|
||||||
|
|
||||||
|
res, err := api.HttpCall("GET", "/v1/nonExistingEndpoint", nil, nil)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("HttpCall() returned unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if res.StatusCode != 404 {
|
||||||
|
t.Fatalf("HttpCall() returned unexpected status code: %v instead of 404", res.StatusCode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetZoneId(t *testing.T) {
|
||||||
|
mockServer := httptest.NewServer(http.HandlerFunc(utilMockServerImpl()))
|
||||||
|
|
||||||
|
ionosAPI := New("dummyKey", mockServer.URL)
|
||||||
|
|
||||||
|
t.Run("returns zoneId for tracked domain", testGetZoneIdSuccess(ionosAPI))
|
||||||
|
t.Run("returns error for non tracked domain", testGetZoneIdNoMatch(ionosAPI))
|
||||||
|
}
|
||||||
|
|
||||||
|
func testGetZoneIdSuccess(api IonosAPI) func(t *testing.T) {
|
||||||
|
return func(t *testing.T) {
|
||||||
|
zoneId, err := api.GetZoneId("example.com")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GetZoneId() returned unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if zoneId != "1234567890" {
|
||||||
|
t.Fatalf("GetZoneId() returned unexpected zoneId: %v instead of 1234567890", zoneId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testGetZoneIdNoMatch(api IonosAPI) func(t *testing.T) {
|
||||||
|
return func(t *testing.T) {
|
||||||
|
zoneId, err := api.GetZoneId("nonTrackedDomain.com")
|
||||||
|
|
||||||
|
if err == nil || zoneId != "" {
|
||||||
|
t.Fatalf("GetZoneId() did not return an error for a non tracked domain")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetRecordId(t *testing.T) {
|
||||||
|
mockServer := httptest.NewServer(http.HandlerFunc(utilMockServerImpl()))
|
||||||
|
defer mockServer.Close()
|
||||||
|
|
||||||
|
ionosAPI := New("dummyKey", mockServer.URL)
|
||||||
|
|
||||||
|
t.Run("returns zoneId for top level domain", testGetRecordIdForTopLevelDomain(ionosAPI))
|
||||||
|
t.Run("returns zoneId for subdomain", testGetRecordIdForSubdomain(ionosAPI))
|
||||||
|
t.Run("returns error for untracked subdomain", testGetRecordIdWithUntrackedSubdomain(ionosAPI))
|
||||||
|
}
|
||||||
|
|
||||||
|
func testGetRecordIdForTopLevelDomain(api IonosAPI) func(t *testing.T) {
|
||||||
|
return func(t *testing.T) {
|
||||||
|
recordId, err := api.GetRecordId("1234567890", "example.com", "", "A")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GetZoneId() returned unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if recordId != "abcdefghij" {
|
||||||
|
t.Fatalf("GetZoneId() returned unexpected zoneId: %v instead of abcdefghij", recordId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testGetRecordIdForSubdomain(api IonosAPI) func(t *testing.T) {
|
||||||
|
return func(t *testing.T) {
|
||||||
|
recordId, err := api.GetRecordId("1234567890", "example.com", "sub", "A")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GetZoneId() returned unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if recordId != "jihgfedcba" {
|
||||||
|
t.Fatalf("GetZoneId() returned unexpected zoneId: %v instead of jihgfedcba", recordId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testGetRecordIdWithUntrackedSubdomain(api IonosAPI) func(t *testing.T) {
|
||||||
|
return func(t *testing.T) {
|
||||||
|
recordId, err := api.GetRecordId("1234567890", "example.com", "untrackedSub", "A")
|
||||||
|
|
||||||
|
if err == nil && recordId == "" {
|
||||||
|
t.Fatalf("GetZoneId() did not return an error for a non tracked domain")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetARecord(t *testing.T) {
|
||||||
|
mockServer := httptest.NewServer(http.HandlerFunc(utilMockServerImpl()))
|
||||||
|
defer mockServer.Close()
|
||||||
|
|
||||||
|
ionosAPI := New("dummyKey", mockServer.URL)
|
||||||
|
|
||||||
|
t.Run("returns A record for top level domain", testGetARecordFor(ionosAPI, "example.com", ""))
|
||||||
|
t.Run("returns A record for subdomain", testGetARecordFor(ionosAPI, "example.com", "sub"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func testGetARecordFor(api IonosAPI, tld string, subdomain string) func(t *testing.T) {
|
||||||
|
return func(t *testing.T) {
|
||||||
|
var domain string
|
||||||
|
if subdomain == "" {
|
||||||
|
domain = tld
|
||||||
|
} else {
|
||||||
|
domain = subdomain + "." + tld
|
||||||
|
}
|
||||||
|
|
||||||
|
record, err := api.GetARecord(tld, subdomain)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GetARecord() returned unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if record.Domain != domain {
|
||||||
|
t.Fatalf("GetARecord() returned unexpected record for: %v instead of %v", record.Domain, domain)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSetARecord(t *testing.T) {
|
||||||
|
mockServer := httptest.NewServer(http.HandlerFunc(utilMockServerImpl()))
|
||||||
|
defer mockServer.Close()
|
||||||
|
|
||||||
|
ionosAPI := New("dummyKey", mockServer.URL)
|
||||||
|
|
||||||
|
changedARecord, err := ionosAPI.SetARecord("example.com", "sub", net.ParseIP("127.0.0.1"), 300, 0, false)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("SetARecord() returned unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if changedARecord.Domain != "sub.example.com" {
|
||||||
|
t.Fatalf("SetARecord() returned unexpected record for: %v instead of sub.example.com", changedARecord.Domain)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,30 +1,31 @@
|
|||||||
package ionosDnsProvider
|
package ionosDnsProvider
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"errors"
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
|
||||||
"realdnydns/model/common"
|
"realdnydns/model/common"
|
||||||
"realdnydns/pkg/dnsProvider"
|
"realdnydns/pkg/dnsProvider"
|
||||||
"sync"
|
ionosAPI "realdnydns/pkg/dnsProvider/ionos/api"
|
||||||
|
|
||||||
ionosDnsClient "gitea.t000-n.de/t.behrendt/ionosDnsClient"
|
redis "github.com/redis/go-redis/v9"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IONOS struct {
|
type IONOS struct {
|
||||||
client *ionosDnsClient.ClientWithResponses
|
API ionosAPI.IonosAPI
|
||||||
zoneIdMap map[string]string
|
Redis *redis.Client
|
||||||
defaultTtl int
|
|
||||||
defaultPrio int
|
|
||||||
zoneIdMapMutex sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type IONOSConfig struct {
|
type IONOSConfig struct {
|
||||||
APIKey string `yaml:"api_key"`
|
APIKey string `yaml:"api_key"`
|
||||||
BaseURL string `yaml:"base_url"`
|
BaseURL string `yaml:"base_url"`
|
||||||
DefaultTTL *int `yaml:"default_ttl,omitempty"`
|
Redis *IONOSRedisConfig
|
||||||
DefaultPrio *int `yaml:"default_prio,omitempty"`
|
}
|
||||||
|
|
||||||
|
type IONOSRedisConfig struct {
|
||||||
|
Address string `yaml:"host"`
|
||||||
|
Password string `yaml:"password"`
|
||||||
|
DB int `yaml:"db"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewIonos(config *IONOSConfig) (dnsProvider.DNSProvider, error) {
|
func NewIonos(config *IONOSConfig) (dnsProvider.DNSProvider, error) {
|
||||||
@@ -36,231 +37,25 @@ func NewIonos(config *IONOSConfig) (dnsProvider.DNSProvider, error) {
|
|||||||
return nil, errors.New("base_url is required")
|
return nil, errors.New("base_url is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
options := []ionosDnsClient.ClientOption{
|
var redisClient *redis.Client = nil
|
||||||
ionosDnsClient.WithRequestEditorFn(func(ctx context.Context, req *http.Request) error {
|
if config.Redis != nil {
|
||||||
req.Header.Set("X-API-Key", config.APIKey)
|
redisClient = redis.NewClient(&redis.Options{
|
||||||
return nil
|
Addr: config.Redis.Address,
|
||||||
}),
|
Password: config.Redis.Password,
|
||||||
}
|
DB: config.Redis.DB,
|
||||||
|
})
|
||||||
client, err := ionosDnsClient.NewClientWithResponses(config.BaseURL, options...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set default values for TTL and Prio if not provided
|
|
||||||
defaultTtl := 300
|
|
||||||
if config.DefaultTTL != nil {
|
|
||||||
defaultTtl = *config.DefaultTTL
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultPrio := 0
|
|
||||||
if config.DefaultPrio != nil {
|
|
||||||
defaultPrio = *config.DefaultPrio
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &IONOS{
|
return &IONOS{
|
||||||
client: client,
|
ionosAPI.New(config.APIKey, config.BaseURL),
|
||||||
zoneIdMap: make(map[string]string),
|
redisClient,
|
||||||
defaultTtl: defaultTtl,
|
|
||||||
defaultPrio: defaultPrio,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *IONOS) UpdateRecord(tld string, subdomain string, ip net.IP, ttl int, prio int, disabled bool) (*common.ARecord, error) {
|
func (ionos *IONOS) UpdateRecord(tld string, subdomain string, ip net.IP, ttl int, prio int, disabled bool) (*common.ARecord, error) {
|
||||||
|
return ionos.API.SetARecord(tld, subdomain, ip, ttl, prio, disabled)
|
||||||
zoneId, err := i.getZoneIdForTld(tld)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
domain := assembleTldSubdomainToDomain(tld, subdomain)
|
|
||||||
recordId, err := i.getRecordIdForDomain(zoneId, domain)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
ipString := ip.String()
|
|
||||||
res, err := i.client.UpdateRecordWithResponse(context.Background(), zoneId, recordId, ionosDnsClient.RecordUpdate{
|
|
||||||
Content: &ipString,
|
|
||||||
Ttl: &ttl,
|
|
||||||
Prio: &prio,
|
|
||||||
Disabled: &disabled,
|
|
||||||
})
|
|
||||||
if err != nil || res.StatusCode() != 200 {
|
|
||||||
return nil, errors.New("failed to update record")
|
|
||||||
}
|
|
||||||
|
|
||||||
if res.JSON200 == nil {
|
|
||||||
return nil, errors.New("record response is empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
record := *res.JSON200
|
|
||||||
if record.Name == nil || record.Content == nil {
|
|
||||||
return nil, errors.New("record is empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle optional fields with defaults
|
|
||||||
recordTtl := 0
|
|
||||||
if record.Ttl != nil {
|
|
||||||
recordTtl = *record.Ttl
|
|
||||||
}
|
|
||||||
|
|
||||||
recordPrio := 0
|
|
||||||
if record.Prio != nil {
|
|
||||||
recordPrio = *record.Prio
|
|
||||||
}
|
|
||||||
|
|
||||||
recordDisabled := false
|
|
||||||
if record.Disabled != nil {
|
|
||||||
recordDisabled = *record.Disabled
|
|
||||||
}
|
|
||||||
|
|
||||||
return &common.ARecord{
|
|
||||||
Domain: *record.Name,
|
|
||||||
IP: *record.Content,
|
|
||||||
TTL: recordTtl,
|
|
||||||
Prio: recordPrio,
|
|
||||||
Disabled: recordDisabled,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *IONOS) getZoneIdForTld(tld string) (string, error) {
|
func (ionos *IONOS) GetRecord(tld string, subdomain string) (*common.ARecord, error) {
|
||||||
i.zoneIdMapMutex.Lock()
|
return ionos.API.GetARecord(tld, subdomain)
|
||||||
defer i.zoneIdMapMutex.Unlock()
|
|
||||||
if zoneId, ok := i.zoneIdMap[tld]; ok {
|
|
||||||
return zoneId, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
res, err := i.client.GetZonesWithResponse(context.Background())
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
} else if res.StatusCode() != 200 {
|
|
||||||
return "", errors.New("failed to get zones")
|
|
||||||
}
|
|
||||||
|
|
||||||
if res.JSON200 == nil {
|
|
||||||
return "", errors.New("zones response is empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
zones := *res.JSON200
|
|
||||||
|
|
||||||
for _, zone := range zones {
|
|
||||||
if *zone.Name == tld {
|
|
||||||
if zone.Id == nil || *zone.Id == "" {
|
|
||||||
return "", errors.New("zone id is empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
i.zoneIdMap[tld] = *zone.Id
|
|
||||||
return *zone.Id, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return "", errors.New("no zone found")
|
|
||||||
}
|
|
||||||
|
|
||||||
var recordTypeA = "A"
|
|
||||||
|
|
||||||
func assembleTldSubdomainToDomain(tld string, subdomain string) string {
|
|
||||||
if subdomain == "@" || subdomain == "" {
|
|
||||||
return tld
|
|
||||||
}
|
|
||||||
return subdomain + "." + tld
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *IONOS) getRecordIdForDomain(zoneId string, domain string) (string, error) {
|
|
||||||
res, err := i.client.GetZoneWithResponse(context.Background(), zoneId, &ionosDnsClient.GetZoneParams{
|
|
||||||
RecordName: &domain,
|
|
||||||
RecordType: &recordTypeA,
|
|
||||||
})
|
|
||||||
if err != nil || res.StatusCode() != 200 {
|
|
||||||
return "", errors.New("failed to get zone")
|
|
||||||
}
|
|
||||||
|
|
||||||
if res.JSON200 == nil {
|
|
||||||
return "", errors.New("zone response is empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
zone := *res.JSON200
|
|
||||||
|
|
||||||
for _, record := range *zone.Records {
|
|
||||||
if *record.Name == domain && *record.Type == ionosDnsClient.RecordTypes("A") {
|
|
||||||
return *record.Id, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return "", errors.New("no record found")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *IONOS) GetRecord(tld string, subdomain string) (*common.ARecord, error) {
|
|
||||||
zoneId, err := i.getZoneIdForTld(tld)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
domain := assembleTldSubdomainToDomain(tld, subdomain)
|
|
||||||
recordId, err := i.getRecordIdForDomain(zoneId, domain)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
res, err := i.client.GetRecordWithResponse(context.Background(), zoneId, recordId)
|
|
||||||
if err != nil || res.StatusCode() != 200 || res.JSON200 == nil {
|
|
||||||
return nil, errors.New("failed to get record")
|
|
||||||
}
|
|
||||||
|
|
||||||
record := *res.JSON200
|
|
||||||
|
|
||||||
if record.Name == nil || *record.Name == "" || *record.Name != domain {
|
|
||||||
return nil, errors.New("record name does not match or is empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
if record.Content == nil || *record.Content == "" {
|
|
||||||
return nil, errors.New("record content is empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
needsUpdate := false
|
|
||||||
|
|
||||||
ttl := i.defaultTtl
|
|
||||||
if record.Ttl != nil {
|
|
||||||
ttl = *record.Ttl
|
|
||||||
} else {
|
|
||||||
needsUpdate = true
|
|
||||||
}
|
|
||||||
|
|
||||||
prio := i.defaultPrio
|
|
||||||
if record.Prio != nil {
|
|
||||||
prio = *record.Prio
|
|
||||||
} else {
|
|
||||||
needsUpdate = true
|
|
||||||
}
|
|
||||||
|
|
||||||
disabled := false
|
|
||||||
if record.Disabled != nil {
|
|
||||||
disabled = *record.Disabled
|
|
||||||
} else {
|
|
||||||
needsUpdate = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// realDynDns requires every field to be set, so we need to update the record if any of the fields are missing
|
|
||||||
if needsUpdate {
|
|
||||||
ip := net.ParseIP(*record.Content)
|
|
||||||
if ip == nil {
|
|
||||||
return nil, errors.New("invalid IP address in record content")
|
|
||||||
}
|
|
||||||
|
|
||||||
updatedRecord, err := i.UpdateRecord(tld, subdomain, ip, ttl, prio, disabled)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return updatedRecord, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return &common.ARecord{
|
|
||||||
Domain: *record.Name,
|
|
||||||
IP: *record.Content,
|
|
||||||
TTL: ttl,
|
|
||||||
Prio: prio,
|
|
||||||
Disabled: disabled,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,6 @@ package externalIpProvider
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -41,15 +40,12 @@ func (p *ExternalIpProviderImplPlain) GetExternalIp() (net.IP, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if res.StatusCode != 200 {
|
if res.StatusCode != 200 {
|
||||||
res.Body.Close()
|
|
||||||
return nil, errors.New("unexpected status code")
|
return nil, errors.New("unexpected status code")
|
||||||
}
|
}
|
||||||
|
|
||||||
responseBody, err := io.ReadAll(res.Body)
|
responseBody := make([]byte, res.ContentLength)
|
||||||
res.Body.Close()
|
res.Body.Read(responseBody)
|
||||||
if err != nil {
|
defer res.Body.Close()
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
parsedIp := net.ParseIP(string(responseBody))
|
parsedIp := net.ParseIP(string(responseBody))
|
||||||
if parsedIp == nil {
|
if parsedIp == nil {
|
||||||
|
|||||||
@@ -1,22 +1,12 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
"extends": [
|
|
||||||
"local>t.behrendt/renovate-configs:common",
|
|
||||||
"local>t.behrendt/renovate-configs:action"
|
|
||||||
],
|
|
||||||
"packageRules": [
|
"packageRules": [
|
||||||
{
|
{
|
||||||
"matchPackageNames": [
|
"matchPackageNames": [
|
||||||
"golang",
|
"golang",
|
||||||
"gomod",
|
|
||||||
"go"
|
"go"
|
||||||
],
|
],
|
||||||
"groupName": "go version",
|
"groupName": "go version"
|
||||||
"matchUpdateTypes": [
|
|
||||||
"major",
|
|
||||||
"minor",
|
|
||||||
"patch"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user