This commit is contained in:
parent
85c288970a
commit
7113939121
@ -16,8 +16,10 @@ steps:
|
|||||||
cpu: 50
|
cpu: 50
|
||||||
memory: 50M
|
memory: 50M
|
||||||
|
|
||||||
- name: golang-ci lint
|
- name: golangci lint
|
||||||
image: docker.io/golangci/golangci-lint:1.44.2-alpine
|
commands:
|
||||||
|
- golangci-lint run
|
||||||
|
image: docker.io/golangci/golangci-lint:v1.44.2-alpine
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
cpu: 100
|
cpu: 100
|
||||||
|
1
main.go
1
main.go
@ -16,7 +16,6 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
switch os.Getenv("DYNDNS_CLIENT_LOGGER_LEVEL") {
|
switch os.Getenv("DYNDNS_CLIENT_LOGGER_LEVEL") {
|
||||||
case "DEBUG", "debug":
|
case "DEBUG", "debug":
|
||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
|
@ -37,7 +37,6 @@ func GetDefaultConfiguration() (*types.Config, error) {
|
|||||||
|
|
||||||
// Read config from a file
|
// Read config from a file
|
||||||
func Read(cnfFile string) (*types.Config, error) {
|
func Read(cnfFile string) (*types.Config, error) {
|
||||||
|
|
||||||
// Load burned in configuration if config not available
|
// Load burned in configuration if config not available
|
||||||
if _, err := os.Stat(cnfFile); os.IsNotExist(err) {
|
if _, err := os.Stat(cnfFile); os.IsNotExist(err) {
|
||||||
if err := os.MkdirAll(filepath.Dir(cnfFile), 0755); err != nil {
|
if err := os.MkdirAll(filepath.Dir(cnfFile), 0755); err != nil {
|
||||||
|
@ -48,7 +48,7 @@ func Start(cnf *types.Config) {
|
|||||||
for {
|
for {
|
||||||
interfaces, err := netlink.LinkList()
|
interfaces, err := netlink.LinkList()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("%v", err.Error())
|
log.Fatalf("%v", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@ -99,7 +99,7 @@ func Start(cnf *types.Config) {
|
|||||||
interfaceLogger.Error(err.Error())
|
interfaceLogger.Error(err.Error())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = removeIPRecords(daemonCtx, interfaceLogger, updaters, cnf.Zones, recordType, update.LinkAddress.IP)
|
err = removeIPRecords(daemonCtx, interfaceLogger, updaters, cnf.Zones, recordType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
interfaceLogger.Error(err.Error())
|
interfaceLogger.Error(err.Error())
|
||||||
}
|
}
|
||||||
@ -146,7 +146,6 @@ func searchInterfaceByIndex(index int, interfaces []netlink.Link) (netlink.Link,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func addIPRecords(ctx context.Context, logEntry *log.Entry, updaters map[string]updater.Updater, zones map[string]*types.Zone, recordType string, ip net.IP) error {
|
func addIPRecords(ctx context.Context, logEntry *log.Entry, updaters map[string]updater.Updater, zones map[string]*types.Zone, recordType string, ip net.IP) error {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errorChannel = make(chan error, len(zones))
|
errorChannel = make(chan error, len(zones))
|
||||||
wg = new(sync.WaitGroup)
|
wg = new(sync.WaitGroup)
|
||||||
@ -166,7 +165,6 @@ func addIPRecords(ctx context.Context, logEntry *log.Entry, updaters map[string]
|
|||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
|
||||||
go func(ctx context.Context, zoneName string, hostname string, recordType string, ip net.IP, wg *sync.WaitGroup) {
|
go func(ctx context.Context, zoneName string, hostname string, recordType string, ip net.IP, wg *sync.WaitGroup) {
|
||||||
|
|
||||||
zoneLogger := logEntry.WithFields(log.Fields{
|
zoneLogger := logEntry.WithFields(log.Fields{
|
||||||
"zone": zoneName,
|
"zone": zoneName,
|
||||||
"hostname": hostname,
|
"hostname": hostname,
|
||||||
@ -186,7 +184,6 @@ func addIPRecords(ctx context.Context, logEntry *log.Entry, updaters map[string]
|
|||||||
}
|
}
|
||||||
|
|
||||||
zoneLogger.Info("dns-record successfully updated")
|
zoneLogger.Info("dns-record successfully updated")
|
||||||
|
|
||||||
}(ctx, zoneName, hostname, recordType, ip, wg)
|
}(ctx, zoneName, hostname, recordType, ip, wg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,7 +200,6 @@ func addIPRecords(ctx context.Context, logEntry *log.Entry, updaters map[string]
|
|||||||
}
|
}
|
||||||
|
|
||||||
func pruneRecords(ctx context.Context, updaters map[string]updater.Updater, zones map[string]*types.Zone) error {
|
func pruneRecords(ctx context.Context, updaters map[string]updater.Updater, zones map[string]*types.Zone) error {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errorChannel = make(chan error, len(zones))
|
errorChannel = make(chan error, len(zones))
|
||||||
wg = new(sync.WaitGroup)
|
wg = new(sync.WaitGroup)
|
||||||
@ -250,8 +246,7 @@ func pruneRecords(ctx context.Context, updaters map[string]updater.Updater, zone
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeIPRecords(ctx context.Context, logEntry *log.Entry, updaters map[string]updater.Updater, zones map[string]*types.Zone, recordType string, ip net.IP) error {
|
func removeIPRecords(ctx context.Context, logEntry *log.Entry, updaters map[string]updater.Updater, zones map[string]*types.Zone, recordType string) error {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errorChannel = make(chan error, len(zones))
|
errorChannel = make(chan error, len(zones))
|
||||||
wg = new(sync.WaitGroup)
|
wg = new(sync.WaitGroup)
|
||||||
@ -290,7 +285,6 @@ func removeIPRecords(ctx context.Context, logEntry *log.Entry, updaters map[stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
zoneLogger.Info("dns-record successfully removed")
|
zoneLogger.Info("dns-record successfully removed")
|
||||||
|
|
||||||
}(ctx, zoneName, hostname, recordType, wg)
|
}(ctx, zoneName, hostname, recordType, wg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,7 +303,6 @@ func removeIPRecords(ctx context.Context, logEntry *log.Entry, updaters map[stri
|
|||||||
// verifyHostname returns a boolean if the hostname id valid. The hostname does
|
// verifyHostname returns a boolean if the hostname id valid. The hostname does
|
||||||
// not contains any dot or local, localhost, localdomain.
|
// not contains any dot or local, localhost, localdomain.
|
||||||
func verifyHostname(hostname string) bool {
|
func verifyHostname(hostname string) bool {
|
||||||
|
|
||||||
if !validHostname.MatchString(hostname) {
|
if !validHostname.MatchString(hostname) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user