-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zone id get from os environment variable
- Loading branch information
Showing
1 changed file
with
8 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
import os | ||
from cloudflare import Cloudflare | ||
|
||
|
||
zone_id = os.getenv("CLOUDFLARE_ZONE_ID") | ||
if zone_id is None: | ||
sys.exit("CLOUDFLARE_ZONE_ID is not defined") | ||
|
||
cloudflare_token = "your-cloudflare-token" | ||
cloudflare_zone_id = "zone" | ||
alias_name = "www.mydns.com" | ||
cannonical_name = "cname.example.com" | ||
|
||
client = Cloudflare() | ||
|
||
client = Cloudflare() | ||
|
||
|
||
# create dns using defined driver | ||
record = client.dns.records.create( | ||
zone_id=cloudflare_zone_id, | ||
zone_id=zone_id, | ||
type='CNAME', | ||
name=alias_name, | ||
content=cannonical_name, | ||
proxied=False | ||
) | ||
|
||
|
||
# print output | ||
print(record) | ||
print(record) |
4002758
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could query Cloudflare for the zone id from the name using zones.list, such as in this snippet from one of my scripts where I used cf as the client