Skip to content

Commit

Permalink
Merge pull request #21 from davidramiro/refactor/v3
Browse files Browse the repository at this point in the history
refactor (v3): simplify API, improve config, create interfaces
  • Loading branch information
davidramiro authored Feb 11, 2024
2 parents accb5d3 + b3d1395 commit bdf45fa
Show file tree
Hide file tree
Showing 32 changed files with 1,887 additions and 1,057 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '>=1.20.0'
- name: Create config.yml from secrets
run: echo -n "${{ secrets.CONFIG_YML }}" | base64 --decode > config.yml
go-version: '>=1.22.0'
- name: Install mockery
run: go install github.com/vektra/mockery/v2@v2.40.3
- name: Generate mocks
run: mockery
- name: Build
run: go build -v ./...
- name: Test with the Go CLI
run: go test -v ./...
run: go test ./... -coverprofile="cover.out" -covermode=atomic -coverpkg=./...
- name: check test coverage
uses: vladopajic/go-test-coverage@v2
with:
config: ./.testcoverage.yml
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ dist/
# Go workspace file
go.work

config.yml
config.toml

.idea/
.idea/

mocks/
12 changes: 12 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
with-expecter: True
outpkg: "mock_{{.PackageName}}"
packages:
github.com/davidramiro/frigabun/services:
interfaces:
DnsUpdateService:
HTTPClient:
github.com/davidramiro/frigabun/services/factory:
interfaces:
ServiceFactory:
config:
all: True
11 changes: 11 additions & 0 deletions .testcoverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
profile: cover.out

threshold:
file: 70
package: 80
total: 90

exclude:
paths:
- main.go
- mocks
42 changes: 18 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,27 @@
# frigabun

Web service to allow FritzBox routers to update Gandi and Porkbun DNS entries when obtaining a new IP address.
Uses the new LiveDNS API. Written in Go 1.20
Web service to allow FritzBox routers to update Gandi, Cloudflare and Porkbun DNS entries when obtaining a new IP address.

## Requirements
- A domain name on Gandi or Porkbun
- Gandi or Porkbun API credentials
- A domain name on Gandi, Porkbun or Cloudflare
- Gandi, Porkbun or Cloudflare API credentials
- FritzBox router with up-to-date firmware
- Optional: To build or run manually: Go 1.20

## Set up service

- Download the [latest](https://github.com/davidramiro/frigabun/releases/latest) release archive for your OS/arch
- Unzip, rename `config.sample.yml` to `config.yml` (config is fine as default, if you want to run tests, fill in your API info)
- Unzip, rename `config.sample.toml` to `config.toml`
- Add credentials to the registrars you want to use and set `enabled` to `true`

## Obtaining credentials

### Gandi

- Obtain Gandi API credentials:
- Go to [Account settings](https://account.gandi.net/en)
- Choose Authentication options
- Generate an API key on the bottom of the page
- Log into your FritzBox
- Navigate to `Internet` -> `Permit Access` -> `DynDNS`
- Enable DynDNS and use `User-defined` as Provider
- Enter the following URL: `http://{HOST}:{PORT}/api/update?apikey=<passwd>&domain={DOMAIN}&subdomain={SUBDOMAIN}&ip=<ipaddr>&registrar=gandi`
- Replace the `{HOST}` and `{PORT}` with your deployment of the application
- By default, the application uses port `9595`
- Replace `{DOMAIN}` with your base domain
- e.g. `yourdomain.com`
- Replace `{SUBDOMAIN}` with your subdomain or comma separated subdomains
- e.g. `subdomain` or `sudomain1,subdomain2`
- Enter the full domain in the `Domain Name` field
- e.g. `subdomain.domain.com` (if you use multiple subdomains, just choose any of those)
- Enter any value in the `Username` field
- Unused, but required by the FritzBox interface
- Enter your Gandi API-Key in the `Password` field

### Porkbun

Expand All @@ -43,10 +30,18 @@ Uses the new LiveDNS API. Written in Go 1.20
- Create an API key, note down API key and API secret key
- Go to [domain management](https://porkbun.com/account/domains)
- Expand the details of your domain and enable the API access toggle on every domain you want to manage via frigabun

### Cloudflare

- Get your `zoneId` as per [this article](https://developers.cloudflare.com/fundamentals/setup/find-account-and-zone-ids/)
- Create an API token on [this page](https://dash.cloudflare.com/profile/api-tokens)
- Make sure to set `Zone.DNS` permissions and set it to the zone your domain is in

## FritzBox Setup
- Log into your FritzBox
- Navigate to `Internet` -> `Permit Access` -> `DynDNS`
- Enable DynDNS and use `User-defined` as Provider
- Enter the following URL: `http://{HOST}:{PORT}/api/update?apikey=<username>&secretapikey=<passwd>&domain={DOMAIN}&subdomain={SUBDOMAIN}&ip=<ipaddr>&registrar=porkbun`
- Enter the following URL: `http://{HOST}:{PORT}/api/update?domain={DOMAIN}&subdomain={SUBDOMAIN}&ip=<ipaddr>&registrar=gandi`
- Replace the `{HOST}` and `{PORT}` with your deployment of the application
- By default, the application uses port `9595`
- Replace `{DOMAIN}` with your base domain
Expand All @@ -55,9 +50,8 @@ Uses the new LiveDNS API. Written in Go 1.20
- e.g. `subdomain` or `sudomain1,subdomain2`
- Enter the full domain in the `Domain Name` field
- e.g. `subdomain.domain.com` (if you use multiple subdomains, just choose any of those)
- Enter your Porkbun API key in the `Username` field
- Enter your Porkbun API Secret Key in the `Password` field

- Enter any value in the `Username` and `Password` fields
- Unused, but required by the FritzBox interface

Your settings should look something like this:

Expand Down
24 changes: 24 additions & 0 deletions config.sample.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[api]
port = 9595
enableStatusLog = false

[gandi]
enabled = true
baseUrl = "https://dns.api.gandi.net/api/v5"
ttl = 1800
apiKey = ""

[porkbun]
enabled = false
baseUrl = "https://porkbun.com/api/json/v3"
apiKey = ""
secretApiKey = ""
ttl = 1800

[cloudflare]
enabled = false
baseUrl = "https://api.cloudflare.com/client/v4"
apiKey = ""
zoneId = ""
ttl = 1800

25 changes: 0 additions & 25 deletions config.sample.yml

This file was deleted.

45 changes: 31 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,46 @@ module github.com/davidramiro/frigabun
go 1.20

require (
github.com/go-faker/faker/v4 v4.1.0
github.com/rs/zerolog v1.29.1
gopkg.in/yaml.v3 v3.0.1
github.com/rs/zerolog v1.32.0
github.com/spf13/viper v1.18.2
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.1 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/time v0.3.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
github.com/labstack/echo/v4 v4.10.2
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2
github.com/labstack/echo/v4 v4.11.4
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/stretchr/testify v1.8.4
golang.org/x/sys v0.5.0 // indirect
golang.org/x/sys v0.17.0 // indirect
)
Loading

0 comments on commit bdf45fa

Please sign in to comment.