You've already forked ddns-updater
github action + minor refactor
This commit is contained in:
31
.github/workflows/image-scanner.yml
vendored
Normal file
31
.github/workflows/image-scanner.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
name: build
|
||||||
|
on:
|
||||||
|
workflow_run:
|
||||||
|
workflows: [ "Code check" ]
|
||||||
|
types:
|
||||||
|
- completed
|
||||||
|
jobs:
|
||||||
|
on-failure:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
|
||||||
|
steps:
|
||||||
|
- run: echo 'The triggering workflow failed'
|
||||||
|
build:
|
||||||
|
name: Image vulnerability scanner
|
||||||
|
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Build an image from Dockerfile
|
||||||
|
run: |
|
||||||
|
docker build -t docker.io/my-organization/my-app:${{ github.sha }} .
|
||||||
|
- name: Run Trivy vulnerability scanner
|
||||||
|
uses: aquasecurity/trivy-action@master
|
||||||
|
with:
|
||||||
|
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
|
||||||
|
format: 'table'
|
||||||
|
exit-code: '1'
|
||||||
|
ignore-unfixed: true
|
||||||
|
vuln-type: 'os,library'
|
||||||
|
severity: 'CRITICAL,HIGH'
|
||||||
64
main.go
64
main.go
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
@@ -24,9 +23,7 @@ func getResolver(resolverName string) PublicIpResolver {
|
|||||||
case public_resolvers.IfConfigMeTag:
|
case public_resolvers.IfConfigMeTag:
|
||||||
fallthrough
|
fallthrough
|
||||||
default:
|
default:
|
||||||
return public_resolvers.NewIfConfigMe(&http.Client{
|
return public_resolvers.NewDefaultIfConfigMe()
|
||||||
Timeout: 10 * time.Second,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,33 +54,46 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dns, err := allDNSRecords(ctx, api, cloudflare.ZoneIdentifier(zoneID))
|
log.Println("waiting for update tick ...")
|
||||||
if err != nil {
|
ticker := time.NewTicker(config.CheckInterval)
|
||||||
log.Fatal(err)
|
defer ticker.Stop()
|
||||||
}
|
for {
|
||||||
|
select {
|
||||||
|
case <-ticker.C:
|
||||||
|
log.Println("tick received checking ...")
|
||||||
|
func() {
|
||||||
|
dns, err := allDNSRecords(ctx, api, cloudflare.ZoneIdentifier(zoneID))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
for _, dnsRecord := range dns {
|
for _, dnsRecord := range dns {
|
||||||
if internal.Contains(config.DnsRecordsToCheck, dnsRecord.Name) {
|
if internal.Contains(config.DnsRecordsToCheck, dnsRecord.Name) {
|
||||||
log.Printf("Checking record `%s` with current value `%s` ...", dnsRecord.Name, dnsRecord.Content)
|
log.Printf("Checking record `%s` with current value `%s` ...", dnsRecord.Name, dnsRecord.Content)
|
||||||
if currentPublicIP.String() == dnsRecord.Content {
|
if currentPublicIP.String() == dnsRecord.Content {
|
||||||
log.Println("OK")
|
log.Println("OK")
|
||||||
continue // no update needed
|
continue // no update needed
|
||||||
}
|
}
|
||||||
|
|
||||||
update := cloudflare.UpdateDNSRecordParams{
|
update := cloudflare.UpdateDNSRecordParams{
|
||||||
ID: dnsRecord.ID,
|
ID: dnsRecord.ID,
|
||||||
Content: currentPublicIP.String(),
|
Content: currentPublicIP.String(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.OnChangeComment != "" {
|
if config.OnChangeComment != "" {
|
||||||
update.Comment = config.OnChangeComment
|
update.Comment = config.OnChangeComment
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := api.UpdateDNSRecord(ctx, cloudflare.ZoneIdentifier(zoneID), update); err != nil {
|
if _, err := api.UpdateDNSRecord(ctx, cloudflare.ZoneIdentifier(zoneID), update); err != nil {
|
||||||
log.Printf("error updating dns record: %s", err)
|
log.Printf("error updating dns record: %s", err)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Updated to `%s`", currentPublicIP)
|
log.Printf("Updated to `%s`", currentPublicIP)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
case <-ctx.Done():
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -24,6 +25,12 @@ type IfConfigMe struct {
|
|||||||
client Doer
|
client Doer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewDefaultIfConfigMe() *IfConfigMe {
|
||||||
|
return NewIfConfigMe(&http.Client{
|
||||||
|
Timeout: 10 * time.Second,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func NewIfConfigMe(c Doer) *IfConfigMe {
|
func NewIfConfigMe(c Doer) *IfConfigMe {
|
||||||
return &IfConfigMe{client: c}
|
return &IfConfigMe{client: c}
|
||||||
}
|
}
|
||||||
@@ -38,7 +45,9 @@ func (i IfConfigMe) ResolvePublicIp(ctx context.Context) (net.IP, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return net.IP{}, err
|
return net.IP{}, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() {
|
||||||
|
_ = resp.Body.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
return net.IP{}, fmt.Errorf("unexpected response code %d", resp.StatusCode)
|
return net.IP{}, fmt.Errorf("unexpected response code %d", resp.StatusCode)
|
||||||
|
|||||||
Reference in New Issue
Block a user