-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3006faa
Showing
19 changed files
with
835 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: gomod | ||
directory: "/" | ||
schedule: | ||
interval: daily | ||
time: '04:00' | ||
open-pull-requests-limit: 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Release | ||
on: | ||
push: | ||
tags: | ||
- '*' | ||
|
||
jobs: | ||
goreleaser: | ||
name: GoReleaser | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.14 | ||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v2 | ||
with: | ||
version: latest | ||
args: release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Test | ||
on: | ||
pull_request: | ||
push: | ||
|
||
jobs: | ||
test: | ||
name: Test | ||
strategy: | ||
matrix: | ||
go-version: [1.13, 1.14] | ||
platform: [ubuntu-latest, macos-latest, windows-latest] | ||
runs-on: ${{ matrix.platform }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
- name: Test | ||
run: go test ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Deploy | ||
bin/ | ||
dist/ | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Local binary | ||
/scaleway-ddns | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
before: | ||
hooks: | ||
- go mod tidy | ||
builds: | ||
- main: ./cmd/scaleway-ddns | ||
env: | ||
- CGO_ENABLED=0 | ||
goarch: | ||
- amd64 | ||
goos: | ||
- darwin | ||
- linux | ||
- windows | ||
ldflags: | ||
- -s -w | ||
- -X main.version={{.Version}} | ||
- -X main.commit={{.ShortCommit}} | ||
- -X main.date={{.Date}} | ||
checksum: | ||
name_template: checksums.txt | ||
snapshot: | ||
name_template: "{{.Tag}}-{{.ShortCommit}}" | ||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- ^(feat|fix)\(doc\) | ||
- ^(feat|fix)\(test\) | ||
- ^Merge pull request | ||
archives: | ||
- wrap_in_directory: true | ||
files: | ||
- LICENSE | ||
- scaleway-ddns.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* @aerialls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Julien Brochet | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# scaleway-ddns | ||
|
||
[](https://github.com/aerialls/scaleway-ddns/actions?query=workflow%3ATest) | ||
[](https://goreportcard.com/report/github.com/aerialls/scaleway-ddns) | ||
 | ||
|
||
Dynamic DNS service based on [Scaleway DNS](https://console.scaleway.com/domains/external). | ||
|
||
## Usage | ||
|
||
``` | ||
scaleway-ddns --config /etc/scaleway-ddns/scaleway-ddns.yml | ||
``` | ||
|
||
## Parameters | ||
|
||
* `--config` - Specify the location of the configuration file (**required**) | ||
* `--dry-run` - Do not perform update actions (default `false`) | ||
* `--verbose` - Display debug messages (default `false`) | ||
* `--help` - Display the help message block | ||
|
||
## Configuration | ||
|
||
```yaml | ||
scaleway: | ||
organization_id: __ORGANIZATION_ID__ | ||
access_key: __ACCESS_KEY__ | ||
secret_key: __SECRET_KEY__ | ||
|
||
domain: | ||
name: contoso.com | ||
record: public | ||
ttl: 60 | ||
|
||
interval: 300 | ||
|
||
ipv4: | ||
enabled: true | ||
url: https://api-ipv4.ip.sb/ip | ||
|
||
ipv6: | ||
enabled: true | ||
url: https://api-ipv6.ip.sb/ip | ||
``` | ||
**Note**: IPv6 is disabled by default. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Security Policy | ||
|
||
## Supported Versions | ||
|
||
The following versions are currently being supported with security updates. | ||
|
||
| Version | Supported | | ||
| ------- | ------------------ | | ||
| 0.0.x | :white_check_mark: | | ||
|
||
## Reporting a Vulnerability | ||
|
||
To report a suspected vulnerability, please contact [email protected] and include the steps to produce the vulnerability. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/aerialls/scaleway-ddns/config" | ||
"github.com/aerialls/scaleway-ddns/ip" | ||
"github.com/aerialls/scaleway-ddns/scaleway" | ||
) | ||
|
||
// UpdateDNSRecordFromCurrentIP updates the DNS record on Scaleway DNS based | ||
// on the current IP for IPv4 or IPv6 | ||
func UpdateDNSRecordFromCurrentIP( | ||
dns *scaleway.DNS, | ||
domain config.DomainConfig, | ||
cfg config.IPConfig, | ||
recordType string, | ||
dryRun bool, | ||
) error { | ||
if !cfg.Enabled { | ||
logger.Debugf("skipping %s update, disabled in the configuration", recordType) | ||
return nil | ||
} | ||
|
||
scalewayIP, err := dns.GetRecord(domain.Name, domain.Record, recordType) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
currentIP, err := ip.GetPublicIP(cfg.URL) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
logger.Debugf("current IP registered in Scaleway is %s", scalewayIP) | ||
logger.Debugf("current public IP is %s", currentIP) | ||
|
||
if scalewayIP == currentIP { | ||
logger.Debug("both IPs are identical, nothing to do") | ||
return nil | ||
} | ||
|
||
logger.Infof( | ||
"updating %s record from %s to %s", recordType, scalewayIP, currentIP, | ||
) | ||
|
||
if dryRun { | ||
logger.Info("running in dry-run mode, doing nothing") | ||
return nil | ||
} | ||
|
||
err = dns.UpdateRecord( | ||
domain.Name, | ||
domain.Record, | ||
domain.TTL, | ||
currentIP, | ||
recordType, | ||
) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/aerialls/scaleway-ddns/config" | ||
"github.com/aerialls/scaleway-ddns/scaleway" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
cfgFile string | ||
verbose bool | ||
logger *logrus.Logger | ||
dryRun bool | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "scaleway-ddns", | ||
Short: "Dynamic DNS service based on Scaleway DNS", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
logger.Info("starting dynamic records for Scaleway DNS") | ||
|
||
cfg, err := config.NewConfig(cfgFile) | ||
if err != nil { | ||
logger.Fatal(err) | ||
} | ||
|
||
dns, err := scaleway.NewDNS( | ||
logger, | ||
cfg.ScalewayConfig.OrganizationID, | ||
cfg.ScalewayConfig.AccessKey, | ||
cfg.ScalewayConfig.SecretKey, | ||
) | ||
|
||
if err != nil { | ||
logger.Fatal(err) | ||
} | ||
|
||
ticker := time.NewTicker(time.Duration(cfg.Interval) * time.Second) | ||
|
||
for { | ||
select { | ||
case <-ticker.C: | ||
logger.Debugf( | ||
"updating A/AAAA records for %s.%s", | ||
cfg.DomainConfig.Record, | ||
cfg.DomainConfig.Name, | ||
) | ||
|
||
recordTypes := map[string]config.IPConfig{ | ||
"A": cfg.IPv4Config, | ||
"AAAA": cfg.IPv6Config, | ||
} | ||
|
||
for recordType, recordCfg := range recordTypes { | ||
err := UpdateDNSRecordFromCurrentIP( | ||
dns, | ||
cfg.DomainConfig, | ||
recordCfg, | ||
recordType, | ||
dryRun, | ||
) | ||
|
||
if err != nil { | ||
logger.WithError(err).Errorf( | ||
"unable to update %s record", recordType, | ||
) | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
logger = logrus.New() | ||
|
||
cobra.OnInitialize(initConfig) | ||
|
||
rootCmd.Flags().StringVar(&cfgFile, "config", "", "config file") | ||
rootCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "enable verbose logging") | ||
rootCmd.Flags().BoolVarP(&dryRun, "dry-run", "d", false, "don't update DNS records") | ||
|
||
rootCmd.MarkFlagRequired("config") | ||
} | ||
|
||
func initConfig() { | ||
level := logrus.InfoLevel | ||
if verbose { | ||
level = logrus.DebugLevel | ||
} | ||
|
||
logger.SetLevel(level) | ||
logger.SetFormatter(&logrus.TextFormatter{}) | ||
} | ||
|
||
func main() { | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
version = "undefined" | ||
commit = "dev" | ||
date = "undefined" | ||
) | ||
|
||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Prints the version", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println(fmt.Sprintf("scaleway-ddns %s (commit %s, built at %s)", version, commit, date)) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(versionCmd) | ||
} |
Oops, something went wrong.