Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Cloudflare API tokens. #21

Merged
merged 1 commit into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,17 @@ sudo cu-ddns configure
sudo cu-ddns start
```

### Cloudflare

When creating the Cloudflare API token, the following permissions are needed: `All zones - Zone:Edit, DNS:Edit`.


## Features

*Multiple Providers* - This is currently a lie.
Linode DNS is supported with DigitalOcean DNS next on the list.
*Multiple Providers* - Linode and Cloudflare are supported.
DigitalOcean DNS next on the list.

*IPv4/6 Support* - both IPv4 and IPv6 are supporting.
Currently, you can't specifically choose though. Whichever is the default route/protocol of your local machine, that's what will be used.
*IPv4/6 Support* - IPv4 is supported with IPv6 coming in the near future.


## License
Expand Down
18 changes: 4 additions & 14 deletions src/cmd/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,18 @@ This will configure:
survey.AskOne(q2, &apiToken, survey.WithValidator(survey.Required))
viper.Set("providerToken", apiToken)

if provider == "cloudflare" {

providerEmail := ""
q3 := &survey.Input{
Message: "Enter your Cloudflare email address:",
}
survey.AskOne(q3, &providerEmail, survey.WithValidator(survey.Required))
viper.Set("providerEmail", providerEmail)
}

domainName := ""
q4 := &survey.Input{
q3 := &survey.Input{
Message: "Enter the domain name portion of the hostname to configure. For example, if the hostname is home.example.com, enter example.com:",
}
survey.AskOne(q4, &domainName, survey.WithValidator(survey.Required))
survey.AskOne(q3, &domainName, survey.WithValidator(survey.Required))
viper.Set("domainname", domainName)

arecord := ""
q5 := &survey.Input{
q4 := &survey.Input{
Message: "Enter the A/AAAA portion of the hostname. For example, if the hostname is home.example.com, enter home:",
}
survey.AskOne(q5, &arecord, survey.WithValidator(survey.Required))
survey.AskOne(q4, &arecord, survey.WithValidator(survey.Required))
viper.Set("arecord", arecord)

// Below is neccessary due to an unmerged PR in Viper
Expand Down
19 changes: 16 additions & 3 deletions src/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,22 @@ var runCmd = &cobra.Command{
_, err = linodeClient.UpdateDomainRecord(context.Background(), domainID, recordID, linodego.DomainRecordUpdateOptions{Target: dIP})
} else if viper.GetString("provider") == "cloudflare" {

api, err := cloudflare.New(apiToken, viper.GetString("providerEmail"))
if err != nil {
log.Fatal(err)
var api *cloudflare.API

// backwards compatibility support for the old Cloudflare key/email combo
// will remove somewhere down the line, likely before v1.0 release
if viper.IsSet("providerEmail") {

api, err = cloudflare.New(apiToken, viper.GetString("providerEmail"))
if err != nil {
log.Fatal(err)
}
} else {

api, err = cloudflare.NewWithAPIToken(apiToken)
if err != nil {
log.Fatal(err)
}
}

zoneID, err := api.ZoneIDByName(theDomain)
Expand Down
28 changes: 22 additions & 6 deletions src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,27 @@ module github.com/cloud-unpacked/cu-ddns
go 1.12

require (
github.com/AlecAivazis/survey/v2 v2.0.1
github.com/cloudflare/cloudflare-go v0.9.2
github.com/linode/linodego v0.9.0
github.com/sirupsen/logrus v1.2.0
github.com/spf13/cobra v0.0.4
github.com/AlecAivazis/survey/v2 v2.0.2
github.com/Netflix/go-expect v0.0.0-20190729225929-0e00d9168667 // indirect
github.com/cloudflare/cloudflare-go v0.10.0
github.com/dnaeon/go-vcr v1.0.1 // indirect
github.com/golang/protobuf v1.3.2 // indirect
github.com/hinshun/vt10x v0.0.0-20180809195222-d55458df857c // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/kr/pty v1.1.8 // indirect
github.com/linode/linodego v0.10.0
github.com/magiconair/properties v1.8.1 // indirect
github.com/mattn/go-isatty v0.0.9 // indirect
github.com/pelletier/go-toml v1.4.0 // indirect
github.com/sirupsen/logrus v1.4.2
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cobra v0.0.5
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.4.0
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be
github.com/stretchr/testify v1.4.0 // indirect
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 // indirect
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 // indirect
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
golang.org/x/time v0.0.0-20190513212739-9d24e82272b4 // indirect
google.golang.org/appengine v1.6.1 // indirect
)
Loading