-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (48 loc) · 1.27 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"fmt"
"github.com/ovh/go-ovh/ovh"
"github.com/spf13/viper"
)
func main() {
// Setup configuration with viper
viper.SetDefault("API_ENDPOINT", "ovh-eu")
viper.BindEnv("API_ENDPOINT")
viper.BindEnv("APPLICATION_KEY")
viper.BindEnv("APPLICATION_SECRET")
viper.BindEnv("CONSUMER_KEY")
viper.BindEnv("DNS_ZONE")
viper.BindEnv("RECORD_ID")
viper.BindEnv("SUBDOMAIN")
viper.BindEnv("TARGET")
viper.BindEnv("TTL")
apiEndpoint := viper.GetString("API_ENDPOINT")
appKey := viper.GetString("APPLICATION_KEY")
appSecret := viper.GetString("APPLICATION_SECRET")
consumerKey := viper.GetString("CONSUMER_KEY")
client, err := ovh.NewClient(
apiEndpoint,
appKey,
appSecret,
consumerKey,
)
if err != nil {
panic(err)
}
type Params struct {
SubDomain string `json:"subDomain,omitempty"`
Target string `json:"target,omitempty"`
TTL int64 `json:"ttl,omitempty"`
}
var reqBody = &Params{
SubDomain: viper.GetString("SUBDOMAIN"),
Target: viper.GetString("TARGET"),
TTL: viper.GetInt64("TTL"),
}
dnsZone := viper.GetString("DNS_ZONE")
recordId := viper.GetString("RECORD_ID")
query := fmt.Sprintf("/domain/zone/%v/record/%v", dnsZone, recordId)
if err = client.Put(query, reqBody, nil); err != nil {
panic(err)
}
}