Skip to content

Commit

Permalink
Merge pull request #4 from ElioLopez/feature-bearer-token-option-add
Browse files Browse the repository at this point in the history
bearer token option add
  • Loading branch information
mirioeggmann authored Sep 7, 2022
2 parents 3f8f0e0 + f215100 commit f15c7c9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,41 @@ kubectl apply -f k8s-cronjob.yaml

## Values for k8s-cronjob.yaml

- Get the ZONE_ID under dash.cloudflare.com -> Your domain -> Overview -> API -> Zone ID
- Get the RECORD_ID: https://api.cloudflare.com/#dns-records-for-a-zone-list-dns-records
```
#example
ZONE_ID = 023e105f4ecef8ad9ca31a8372d0c353
RECORD_ID = 372e67954025e0ba6aaa6d586b9e0b59
```

- Get the RECORD_ID: https://api.cloudflare.com/#dns-records-for-a-zone-list-dns-records
- Specify your domain
```
#example
RECORD_ID = 372e67954025e0ba6aaa6d586b9e0b59
NAME = example.com
```
- Get the ZONE_ID under dash.cloudflare.com -> Your domain -> Overview -> API -> Zone ID
```
#example
ZONE_ID = 023e105f4ecef8ad9ca31a8372d0c353
```

- Get your AUTH_KEY (Create a key with "DNS Edit" permissions): https://support.cloudflare.com/hc/en-us/articles/200167836-Where-do-I-find-my-Cloudflare-API-key-
- There are two options for authentication, AUTH_KEY and AUTH_EMAIL or just API_TOKEN
if AUTH_EMAIL is defined the first option will execute.
Values for the first option:

- Get your AUTH_KEY (Create a key with "DNS Edit" permissions): https://support.cloudflare.com/hc/en2-us/articles/200167836-Where-do-I-find-my-Cloudflare-API-key-
```
#example
AUTH_KEY = c2547eb745049flc9320b638f5e225cf483cc5cfdda41
```

- Specify your cloudflare email
```
#example
AUTH_EMAIL = example@example.com
```
Values for the second option:
- Get your API Token My profile -> API Tokens -> Create Tokens -> Edit Zone DNS for the desired zone (https://developers.cloudflare.com/api/tokens/create/):


- Specify your domain
```
#example
NAME = example.com
```
API_TOKEN = 4525cf483cc5cfd049flc9320b638f5e2c2547eb7da41

For more Cloudflare API informations read the [Cloudflare API documentation v4](https://api.cloudflare.com/)
10 changes: 10 additions & 0 deletions cloudflare-ddns.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
#!/bin/bash

if [[ -z "${AUTH_EMAIL+x}" ]]; then
echo "AUTH_EMAIL are not defined, will use API Bearer Token method"
curl -X PUT "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$RECORD_ID" \
-H "Authorization: Bearer $API_TOKEN" \
-H "Content-Type: application/json" \
--data "{\"type\":\"A\",\"name\":\"$NAME\",\"content\":\"`curl ifconfig.co`\"}"

else
echo "AUTH_EMAIL is defined, will use AUTH_KEY Method"
curl -X PUT "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$RECORD_ID" \
-H "X-Auth-Email: $AUTH_EMAIL" \
-H "X-Auth-Key: $AUTH_KEY" \
-H "Content-Type: application/json" \
--data "{\"type\":\"A\",\"name\":\"$NAME\",\"content\":\"`curl ifconfig.co`\"}"
fi
2 changes: 2 additions & 0 deletions k8s-cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ spec:
value: ""
- name: AUTH_EMAIL
value: ""
- name: API_TOKEN
value: ""
- name: NAME
value: ""
restartPolicy: OnFailure

0 comments on commit f15c7c9

Please sign in to comment.