Skip to content

Commit 488050a

Browse files
author
Jonathan Pulsifer
committed
hi ddnsb0t 🤖
Signed-off-by: Jonathan Pulsifer <jonathan@pulsifer.ca>
0 parents  commit 488050a

19 files changed

+1497
-0
lines changed

.github/dependabot.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: gomod
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
time: "10:00"
8+
open-pull-requests-limit: 10

.github/workflows/ddnsb0t.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: ddnsb0t
2+
on:
3+
push:
4+
paths-ignore:
5+
- "function/**"
6+
jobs:
7+
build:
8+
name: Build
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Set up Go 1.15
12+
uses: actions/setup-go@v1
13+
with:
14+
go-version: 1.15
15+
id: go
16+
17+
- name: Check out code into the Go module directory
18+
uses: actions/checkout@v1
19+
20+
- name: Download go modules
21+
run: go mod download
22+
23+
- name: Verify go modules
24+
run: go mod verify
25+
26+
- name: Build
27+
run: go build -v .

.github/workflows/docker.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: docker
2+
on:
3+
push:
4+
paths-ignore:
5+
- "function/**"
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- name: Build docker image
12+
run: |
13+
docker build -t jonpulsifer/ddnsb0t:${{ github.sha }} .
14+
- name: Container security scan
15+
uses: Azure/container-scan@v0
16+
with:
17+
image-name: jonpulsifer/ddnsb0t:${{ github.sha }}
18+
- name: Lint Dockerfile
19+
uses: Shopify/gh-action-hadolint@master

.github/workflows/function.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: function
2+
on:
3+
push:
4+
paths:
5+
- 'function/**'
6+
env:
7+
GO111MODULE: on
8+
jobs:
9+
build:
10+
name: Build
11+
runs-on: ubuntu-latest
12+
steps:
13+
14+
- name: Set up Go 1.13
15+
uses: actions/setup-go@v1
16+
with:
17+
go-version: 1.13
18+
id: go
19+
20+
- name: Check out code into the Go module directory
21+
uses: actions/checkout@v1
22+
23+
- name: Download modules
24+
run: go mod download
25+
working-directory: function
26+
27+
- name: Verify modules
28+
run: go mod verify
29+
working-directory: function
30+
31+
- name: Test
32+
run: go test -v .
33+
working-directory: function
34+
35+
- name: Build
36+
run: go build -v .
37+
working-directory: function

.gitignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Binaries for programs and plugins
2+
ddnsb0t
3+
*.exe
4+
*.exe~
5+
*.dll
6+
*.so
7+
*.dylib
8+
9+
# Test binary, build with `go test -c`
10+
*.test
11+
12+
# Output of the go coverage tool, specifically when used with LiteIDE
13+
*.out

CODE_OF_CONDUCT.md

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at jonathan@pulsifer.ca. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq

Dockerfile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM golang:alpine AS build
2+
# hadolint ignore=DL3018
3+
RUN apk update && apk add --no-cache git
4+
WORKDIR /go/src/github.com/jonpulsifer/ddnsb0t
5+
COPY . .
6+
RUN go mod tidy
7+
RUN CGO_ENABLED=0 GOOS=linux go build -installsuffix cgo -ldflags '-w -s' -o /go/bin/ddnsb0t
8+
9+
FROM scratch
10+
COPY --from=build /go/bin/ddnsb0t /ddnsb0t
11+
ENTRYPOINT ["/ddnsb0t"]
12+
CMD ["--help"]

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 jonathan@pulsifer.ca
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# ddnsb0t
2+
3+
![ddnsb0t](https://github.com/jonpulsifer/ddnsb0t/workflows/ddnsb0t/badge.svg)
4+
![function](https://github.com/jonpulsifer/ddnsb0t/workflows/function/badge.svg)
5+
![docker](https://github.com/jonpulsifer/ddnsb0t/workflows/docker/badge.svg)
6+
[![Go Report Card](https://goreportcard.com/badge/github.com/jonpulsifer/ddnsb0t)](https://goreportcard.com/report/github.com/jonpulsifer/ddnsb0t)
7+
8+
**ddnsb0t** is a program that uses [CloudEvents](https://cloudevents.io/) to communicate to a [Google Cloud Function](https://cloud.google.com/functions) and update my DNS entries using [Google Cloud DNS](https://cloud.google.com/dns).
9+
10+
```raw
11+
ddnsb0t - A bot that fires a CloudEvent down range to a cloud function to update my DNS records in Google Cloud.
12+
13+
Usage: ddnsb0t <command>
14+
15+
Flags:
16+
17+
--domain the default domain (default: <none>)
18+
--endpoint the remote URL for the cloud function (default: <none>)
19+
--external use the network's external IP address (default: false)
20+
--hostname the hostname to update (default: <none>)
21+
--interval how long between each update (eg. 30s, 5m, 1h) (default: 5m0s)
22+
--once run the thing once (default: false)
23+
--token an api token for the cloud function to prevent abuse (default: <none>)
24+
--verbose set the log level to debug (default: false)
25+
26+
Commands:
27+
28+
version Show the version information.
29+
```
30+
31+
## Installation
32+
33+
1. Install ddnsb0t using `go get https://github.com/jonpulsifer/ddnsb0t`
34+
2. Run ddnsb0t `$GOPATH/bin/ddnsb0t -endpoint=https://fn.example.com/ddns -token=sometoken -once`
35+
3. Optionally configure a cron job (below)
36+
37+
```sh
38+
#!/bin/sh
39+
# */5 * * * * /path/to/this/script.sh
40+
export DDNS_ENDPOINT="https://your.url.example.com/ddns"
41+
export DDNS_DOMAIN="example.com"
42+
export DDNS_API_TOKEN="sometoken"
43+
ddnsb0t --once "$@"
44+
```
45+
46+
Running `ddnsb0t` should produce the response from the cloud function
47+
48+
```sh
49+
INFO[0000] dns update requested fqdn=somename.example.com. ip=10.13.37.1 status=pending
50+
```
51+
52+
## Development
53+
54+
1. Run a local cloud events receiver by running `go run ./cmd/main.go` from the `function` directory. This will start an HTTP receiver at `http://localhost:8080`
55+
2. Build ddnsb0t: `go build -o ddnsb0t`
56+
3. Use ddnsb0t: `./ddnsb0t -endpoint=http://localhost:8080 -token=sometoken -once`
57+
58+
### Cloud Events
59+
60+
#### Request
61+
62+
```raw
63+
Validation: valid
64+
Context Attributes,
65+
specversion: 1.0
66+
type: dev.pulsifer.ddns.request
67+
source: https://github.com/jonpulsifer/ddnsb0t
68+
id: 521ccda3-b297-43a0-887c-a76b25557806
69+
dataschema: https://github.com/jonpulsifer/ddnsb0t/pkg/ddns/ddns.go
70+
datacontenttype: application/json
71+
Data,
72+
{
73+
"ip": "10.13.37.1",
74+
"fqdn": "somename.example.com.",
75+
"token": "sometoken"
76+
}
77+
```
78+
79+
#### Response
80+
81+
```raw
82+
Validation: valid
83+
Context Attributes,
84+
specversion: 1.0
85+
type: dev.pulsifer.ddns.response
86+
source: https://github.com/jonpulsifer/ddnsb0t
87+
id: 5c50e41c-2074-446e-8d4b-0c038e04eb07
88+
dataschema: https://github.com/jonpulsifer/ddnsb0t/pkg/ddns/ddns.go
89+
datacontenttype: application/json
90+
Data,
91+
{
92+
"fqdn": "somename.example.com.",
93+
"status": "pending",
94+
"additions": 1,
95+
"deletions": 1
96+
}
97+
```

dev.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: ddnsb0t
2+
3+
type: go
4+
5+
up:
6+
- go:
7+
version: 1.15.5
8+
modules: true
9+
10+
# `dev run` runs `dev build` and then `dev run-built` if these are both defined.
11+
commands:
12+
build:
13+
run: go build -o ddnsb0t
14+
run-built:
15+
desc: |
16+
Run the target after `dev build`.
17+
`dev run` is a special command that will run `dev build` and then `dev run-built` if they are both defined.
18+
run: ./ddnsb0t
19+
test:
20+
run: go test ./...
21+
style:
22+
run: 'golint ./... && errcheck ./...'

function/cmd/main.go

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"log"
6+
"os"
7+
8+
"github.com/GoogleCloudPlatform/functions-framework-go/funcframework"
9+
"github.com/jonpulsifer/ddnsb0t/function"
10+
)
11+
12+
func main() {
13+
ctx := context.Background()
14+
if err := funcframework.RegisterHTTPFunctionContext(ctx, "/ddns", function.DDNSCloudEventReceiver); err != nil {
15+
log.Fatalf("funcframework.RegisterHTTPFunctionContext: %v\n", err)
16+
}
17+
// Use PORT environment variable, or default to 8080.
18+
port := "8080"
19+
if envPort := os.Getenv("PORT"); envPort != "" {
20+
port = envPort
21+
}
22+
if err := funcframework.Start(port); err != nil {
23+
log.Fatalf("funcframework.Start: %v\n", err)
24+
}
25+
}

0 commit comments

Comments
 (0)