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'
|
||||
18
main.go
18
main.go
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
@@ -24,9 +23,7 @@ func getResolver(resolverName string) PublicIpResolver {
|
||||
case public_resolvers.IfConfigMeTag:
|
||||
fallthrough
|
||||
default:
|
||||
return public_resolvers.NewIfConfigMe(&http.Client{
|
||||
Timeout: 10 * time.Second,
|
||||
})
|
||||
return public_resolvers.NewDefaultIfConfigMe()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +54,14 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Println("waiting for update tick ...")
|
||||
ticker := time.NewTicker(config.CheckInterval)
|
||||
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)
|
||||
@@ -86,6 +91,11 @@ func main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
case <-ctx.Done():
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func allDNSRecords(ctx context.Context, api *cloudflare.API, rc *cloudflare.ResourceContainer) ([]cloudflare.DNSRecord, error) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -24,6 +25,12 @@ type IfConfigMe struct {
|
||||
client Doer
|
||||
}
|
||||
|
||||
func NewDefaultIfConfigMe() *IfConfigMe {
|
||||
return NewIfConfigMe(&http.Client{
|
||||
Timeout: 10 * time.Second,
|
||||
})
|
||||
}
|
||||
|
||||
func NewIfConfigMe(c Doer) *IfConfigMe {
|
||||
return &IfConfigMe{client: c}
|
||||
}
|
||||
@@ -38,7 +45,9 @@ func (i IfConfigMe) ResolvePublicIp(ctx context.Context) (net.IP, error) {
|
||||
if err != nil {
|
||||
return net.IP{}, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func() {
|
||||
_ = resp.Body.Close()
|
||||
}()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return net.IP{}, fmt.Errorf("unexpected response code %d", resp.StatusCode)
|
||||
|
||||
Reference in New Issue
Block a user