-
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dondominio): create record if it does not exist
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package dondominio | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"net/netip" | ||
|
||
"github.com/qdm12/ddns-updater/internal/provider/constants" | ||
) | ||
|
||
// See https://dondominio.dev/en/api/docs/api/#dns-zone-create-service-dnscreate | ||
func (p *Provider) create(ctx context.Context, client *http.Client, ip netip.Addr) (err error) { | ||
recordType := constants.A | ||
if ip.Is6() { | ||
recordType = constants.AAAA | ||
} | ||
requestData := struct { | ||
APIUser string `json:"apiuser"` | ||
APIPasswd string `json:"apipasswd"` | ||
ServiceName string `json:"serviceName"` | ||
Name string `json:"name"` // Name for the DNS zone | ||
Type string `json:"type"` | ||
Value string `json:"value"` | ||
}{ | ||
APIUser: p.username, | ||
APIPasswd: p.password, | ||
ServiceName: p.name, | ||
Name: p.BuildDomainName(), | ||
Type: recordType, | ||
Value: ip.String(), | ||
} | ||
|
||
_, err = apiCall(ctx, client, "/service/dnscreate", requestData) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
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