-
Notifications
You must be signed in to change notification settings - Fork 20
/
dns_records_add.go
924 lines (838 loc) · 25.8 KB
/
dns_records_add.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
package cmd
import (
"fmt"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
// dnsACmd represents the A command
var dnsACmd = &cobra.Command{
Use: "A <domain name>",
Short: "Add A record type to a domain",
Long: `Add an "A" record that points your domain or a subdomain to an IP address.`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
cmdExitOnUsageError(cmd, "invalid arguments")
}
return cmdCheckRequiredFlags(cmd, []string{"address"})
},
RunE: func(cmd *cobra.Command, args []string) error {
name, err := cmd.Flags().GetString("name")
if err != nil {
return err
}
addr, err := cmd.Flags().GetString("address")
if err != nil {
return err
}
ttl, err := cmd.Flags().GetInt("ttl")
if err != nil {
return err
}
domain, err := csDNS.GetDomain(gContext, args[0])
if err != nil {
return err
}
_, err = csDNS.CreateRecord(gContext, args[0], egoscale.DNSRecord{
DomainID: domain.ID,
TTL: ttl,
RecordType: "A",
Name: name,
Content: addr,
})
if err != nil {
return err
}
fmt.Printf("Record %q was created successfully to %q\n", cmd.Name(), args[0])
return nil
},
}
func init() {
dnsAddCmd.AddCommand(dnsACmd)
dnsACmd.Flags().StringP("name", "n", "", "Leave this blank to create a record for <domain name>, You may use the '*' wildcard here.")
dnsACmd.Flags().StringP("address", "a", "", "Example: 127.0.0.1")
dnsACmd.Flags().IntP("ttl", "t", 3600, "The time in seconds to live (refresh rate) of the record.")
}
// AAAACmd represents the AAAA command
var dnsAAAACmd = &cobra.Command{
Use: "AAAA <domain name>",
Short: "Add AAAA record type to a domain",
Long: `Add an "AAAA" record that points your domain to an IPv6 address. These records are the same as A records except they use IPv6 addresses.`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
cmdExitOnUsageError(cmd, "invalid arguments")
}
return cmdCheckRequiredFlags(cmd, []string{"address"})
},
RunE: func(cmd *cobra.Command, args []string) error {
name, err := cmd.Flags().GetString("name")
if err != nil {
return err
}
addr, err := cmd.Flags().GetString("address")
if err != nil {
return err
}
ttl, err := cmd.Flags().GetInt("ttl")
if err != nil {
return err
}
domain, err := csDNS.GetDomain(gContext, args[0])
if err != nil {
return err
}
_, err = csDNS.CreateRecord(gContext, args[0], egoscale.DNSRecord{
DomainID: domain.ID,
TTL: ttl,
RecordType: "AAAA",
Name: name,
Content: addr,
})
if err != nil {
return err
}
fmt.Printf("Record %q was created successfully to %q\n", cmd.Name(), args[0])
return nil
},
}
func init() {
dnsAddCmd.AddCommand(dnsAAAACmd)
dnsAAAACmd.Flags().StringP("name", "n", "", "Leave this blank to create a record for <domain name>, You may use the '*' wildcard here.")
dnsAAAACmd.Flags().StringP("address", "a", "", "Example: 2001:0db8:85a3:0000:0000:EA75:1337:BEEF")
dnsAAAACmd.Flags().IntP("ttl", "t", 3600, "The time in seconds to live (refresh rate) of the record.")
}
// dnsCAACmd represents the URL command
var dnsCAACmd = &cobra.Command{
Use: "CAA <domain name>",
Short: "Add CAA record type to a domain",
Long: `A Certification Authority Authorization (CAA) record is used to specify which certificate
authorities (CAs) are allowed to issue certificates for a domain.
What is a flag? <https://tools.ietf.org/html/rfc6844#section-3>
`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
cmdExitOnUsageError(cmd, "invalid arguments")
}
return cmdCheckRequiredFlags(cmd, []string{})
},
RunE: func(cmd *cobra.Command, args []string) error {
name, err := cmd.Flags().GetString("name")
if err != nil {
return err
}
flag, err := cmd.Flags().GetUint8("flag")
if err != nil {
return err
}
tag, err := cmd.Flags().GetStringSlice("tag")
if err != nil {
return err
}
if len(tag) != 2 {
return fmt.Errorf("flag error: tag must contain <key>,<value>")
}
ttl, err := cmd.Flags().GetInt("ttl")
if err != nil {
return err
}
domain, err := csDNS.GetDomain(gContext, args[0])
if err != nil {
return err
}
_, err = csDNS.CreateRecord(gContext, args[0], egoscale.DNSRecord{
DomainID: domain.ID,
TTL: ttl,
RecordType: "CAA",
Name: name,
Content: fmt.Sprintf("%d %s %q", flag, tag[0], tag[1]),
})
if err != nil {
return err
}
fmt.Printf("Record %q was created successfully to %q\n", cmd.Name(), args[0])
return nil
},
}
func init() {
dnsAddCmd.AddCommand(dnsCAACmd)
dnsCAACmd.Flags().StringP("name", "n", "", "Leave this blank to create a record for <domain name>, You may use the '*' wildcard here.")
dnsCAACmd.Flags().Uint8P("flag", "f", 0, "An unsigned integer between 0-255.")
dnsCAACmd.Flags().StringSliceP("tag", "", []string{}, `CAA tag "<key>,<value>", available tags: (issue | issuewild | iodef)`)
dnsCAACmd.Flags().IntP("ttl", "t", 3600, "The time in seconds to live (refresh rate) of the record.")
}
// ALIASCmd represents the ALIAS command
var dnsALIASCmd = &cobra.Command{
Use: "ALIAS <domain name>",
Short: "Add ALIAS record type to a domain",
Long: `Add an "ALIAS" record. An ALIAS record is a special record that will
map a domain to another domain transparently. It can be used like a CNAME but
for a name with other records, like the root. When the record is resolved it will
look up the A records for the aliased domain and return those as the records for
the record name. Note: If you want to redirect to a URL, use a URL record instead.`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
cmdExitOnUsageError(cmd, "invalid arguments")
}
return cmdCheckRequiredFlags(cmd, []string{"alias"})
},
RunE: func(cmd *cobra.Command, args []string) error {
name, err := cmd.Flags().GetString("name")
if err != nil {
return err
}
alias, err := cmd.Flags().GetString("alias")
if err != nil {
return err
}
ttl, err := cmd.Flags().GetInt("ttl")
if err != nil {
return err
}
domain, err := csDNS.GetDomain(gContext, args[0])
if err != nil {
return err
}
_, err = csDNS.CreateRecord(gContext, args[0], egoscale.DNSRecord{
DomainID: domain.ID,
TTL: ttl,
RecordType: "ALIAS",
Name: name,
Content: alias,
})
if err != nil {
return err
}
fmt.Printf("Record %q was created successfully to %q\n", cmd.Name(), args[0])
return nil
},
}
func init() {
dnsAddCmd.AddCommand(dnsALIASCmd)
dnsALIASCmd.Flags().StringP("name", "n", "", "Leave this blank to create a record for <domain name>, You may use the '*' wildcard here.")
dnsALIASCmd.Flags().StringP("alias", "a", "", "Alias for: Example: some-other-site.com")
dnsALIASCmd.Flags().IntP("ttl", "t", 3600, "The time in seconds to live (refresh rate) of the record.")
}
// CNAMECmd represents the CNAME command
var dnsCNAMECmd = &cobra.Command{
Use: "CNAME <domain name>",
Short: "Add CNAME record type to a domain",
Long: `Add a "CNAME" record that aliases a subdomain to another host.
These types of records are used when a server is reached by several names. Only use CNAME records on subdomains.`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
cmdExitOnUsageError(cmd, "invalid arguments")
}
return cmdCheckRequiredFlags(cmd, []string{
"alias",
"name",
})
},
RunE: func(cmd *cobra.Command, args []string) error {
name, err := cmd.Flags().GetString("name")
if err != nil {
return err
}
alias, err := cmd.Flags().GetString("alias")
if err != nil {
return err
}
ttl, err := cmd.Flags().GetInt("ttl")
if err != nil {
return err
}
domain, err := csDNS.GetDomain(gContext, args[0])
if err != nil {
return err
}
_, err = csDNS.CreateRecord(gContext, args[0], egoscale.DNSRecord{
DomainID: domain.ID,
TTL: ttl,
RecordType: "CNAME",
Name: name,
Content: alias,
})
if err != nil {
return err
}
fmt.Printf("Record %q was created successfully to %q\n", cmd.Name(), args[0])
return nil
},
}
func init() {
dnsAddCmd.AddCommand(dnsCNAMECmd)
dnsCNAMECmd.Flags().StringP("name", "n", "", "You may use the * wildcard here.")
dnsCNAMECmd.Flags().StringP("alias", "a", "", "Alias for: Example: some-other-site.com")
dnsCNAMECmd.Flags().IntP("ttl", "t", 3600, "The time in seconds to live (refresh rate) of the record.")
}
// HINFOCmd represents the HINFO command
var dnsHINFOCmd = &cobra.Command{
Use: "HINFO <domain name>",
Short: "Add HINFO record type to a domain",
Long: `Add an "HINFO" record is used to describe the CPU and OS of a host.`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
cmdExitOnUsageError(cmd, "invalid arguments")
}
return cmdCheckRequiredFlags(cmd, []string{
"cpu",
"os",
})
},
RunE: func(cmd *cobra.Command, args []string) error {
name, err := cmd.Flags().GetString("name")
if err != nil {
return err
}
cpu, err := cmd.Flags().GetString("cpu")
if err != nil {
return err
}
os, err := cmd.Flags().GetString("os")
if err != nil {
return err
}
ttl, err := cmd.Flags().GetInt("ttl")
if err != nil {
return err
}
domain, err := csDNS.GetDomain(gContext, args[0])
if err != nil {
return err
}
_, err = csDNS.CreateRecord(gContext, args[0], egoscale.DNSRecord{
DomainID: domain.ID,
TTL: ttl,
RecordType: "HINFO",
Name: name,
Content: fmt.Sprintf("%s %s", cpu, os),
})
if err != nil {
return err
}
fmt.Printf("Record %q was created successfully to %q\n", cmd.Name(), args[0])
return nil
},
}
func init() {
dnsAddCmd.AddCommand(dnsHINFOCmd)
dnsHINFOCmd.Flags().StringP("name", "n", "", "Leave this blank to create a record for <domain name>, You may use the '*' wildcard here.")
dnsHINFOCmd.Flags().StringP("cpu", "c", "", "Example: IBM-PC/AT")
dnsHINFOCmd.Flags().StringP("os", "o", "", "The operating system of the machine, example: Linux")
dnsHINFOCmd.Flags().IntP("ttl", "t", 3600, "The time in seconds to live (refresh rate) of the record.")
}
// MXCmd represents the MX command
var dnsMXCmd = &cobra.Command{
Use: "MX <domain name>",
Short: "Add MX record type to a domain",
Long: `Add a mail exchange record that points to a mail server or relay.
These types of records are used to describe which servers handle incoming email.`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
cmdExitOnUsageError(cmd, "invalid arguments")
}
return cmdCheckRequiredFlags(cmd, []string{
"mail-server-host",
"priority",
})
},
RunE: func(cmd *cobra.Command, args []string) error {
name, err := cmd.Flags().GetString("name")
if err != nil {
return err
}
mailSrv, err := cmd.Flags().GetString("mail-server-host")
if err != nil {
return err
}
priority, err := cmd.Flags().GetInt("priority")
if err != nil {
return err
}
ttl, err := cmd.Flags().GetInt("ttl")
if err != nil {
return err
}
domain, err := csDNS.GetDomain(gContext, args[0])
if err != nil {
return err
}
_, err = csDNS.CreateRecord(gContext, args[0], egoscale.DNSRecord{
DomainID: domain.ID,
TTL: ttl,
RecordType: "MX",
Name: name,
Content: mailSrv,
Prio: priority,
})
if err != nil {
return err
}
fmt.Printf("Record %q was created successfully to %q\n", cmd.Name(), args[0])
return nil
},
}
func init() {
dnsAddCmd.AddCommand(dnsMXCmd)
dnsMXCmd.Flags().StringP("name", "n", "", "Leave this blank to create a record for <domain name>")
dnsMXCmd.Flags().StringP("mail-server-host", "m", "", "Example: mail-server.example.com")
dnsMXCmd.Flags().IntP("priority", "p", 0, "Common values are for example 1, 5 or 10")
dnsMXCmd.Flags().IntP("ttl", "t", 3600, "The time in seconds to live (refresh rate) of the record.")
}
// NAPTRCmd represents the NAPTR command
var dnsNAPTRCmd = &cobra.Command{
Use: "NAPTR <domain name>",
Short: "Add NAPTR record type to a domain",
Long: `Add an "NAPTR" record to provide a means to map a resource that is not in
the domain name syntax to a label that is. More information can be found in RFC 2915.`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
cmdExitOnUsageError(cmd, "invalid arguments")
}
return cmdCheckRequiredFlags(cmd, []string{
"order",
"preference",
"service",
"regex",
"replacement",
})
},
RunE: func(cmd *cobra.Command, args []string) error {
name, err := cmd.Flags().GetString("name")
if err != nil {
return err
}
order, err := cmd.Flags().GetInt("order")
if err != nil {
return err
}
preference, err := cmd.Flags().GetInt("preference")
if err != nil {
return err
}
flags := ""
//flags
s, err := cmd.Flags().GetBool("s")
if err != nil {
return err
}
a, err := cmd.Flags().GetBool("a")
if err != nil {
return err
}
u, err := cmd.Flags().GetBool("u")
if err != nil {
return err
}
p, err := cmd.Flags().GetBool("p")
if err != nil {
return err
}
if s {
flags += "s"
}
if a {
flags += "a"
}
if u {
flags += "u"
}
if p {
flags += "p"
}
service, err := cmd.Flags().GetString("service")
if err != nil {
return err
}
regex, err := cmd.Flags().GetString("regex")
if err != nil {
return err
}
replacement, err := cmd.Flags().GetString("replacement")
if err != nil {
return err
}
ttl, err := cmd.Flags().GetInt("ttl")
if err != nil {
return err
}
domain, err := csDNS.GetDomain(gContext, args[0])
if err != nil {
return err
}
_, err = csDNS.CreateRecord(gContext, args[0], egoscale.DNSRecord{
DomainID: domain.ID,
TTL: ttl,
RecordType: "NAPTR",
Name: name,
Content: fmt.Sprintf("%d %d %q %q %q %q", order, preference, flags, service, regex, replacement),
})
if err != nil {
return err
}
fmt.Printf("Record %q was created successfully to %q\n", cmd.Name(), args[0])
return nil
},
}
func init() {
dnsAddCmd.AddCommand(dnsNAPTRCmd)
dnsNAPTRCmd.Flags().StringP("name", "n", "", "Leave this blank to create a record for <domain name>, You may use the '*' wildcard here.")
dnsNAPTRCmd.Flags().IntP("order", "o", 0, "Used to determine the processing order, lowest first.")
dnsNAPTRCmd.Flags().IntP("preference", "", 0, "Used to give weight to records with the same value in the 'order' field, low to high.")
dnsNAPTRCmd.Flags().StringP("service", "", "", "Service")
dnsNAPTRCmd.Flags().StringP("regex", "", "", "The substitution expression.")
dnsNAPTRCmd.Flags().StringP("replacement", "", "", "The next record to look up, which must be a fully-qualified domain name.")
//flags
dnsNAPTRCmd.Flags().BoolP("s", "", false, "Flag indicates the next lookup is for an SRV.")
dnsNAPTRCmd.Flags().BoolP("a", "", false, "Flag indicates the next lookup is for an A or AAAA record.")
dnsNAPTRCmd.Flags().BoolP("u", "", false, "Flag indicates the next record is the output of the regular expression as a URI.")
dnsNAPTRCmd.Flags().BoolP("p", "", false, "Flag indicates that processing should continue in a protocol-specific fashion.")
dnsNAPTRCmd.Flags().IntP("ttl", "t", 3600, "The time in seconds to live (refresh rate) of the record.")
}
// NSCmd represents the NS command
var dnsNSCmd = &cobra.Command{
Use: "NS <domain name>",
Short: "Add NS record type to a domain",
Long: `Add an "NS" record the delegates a domain to another name server.
You may only delegate subdomains (for example subdomain.yourdomain.com).`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
cmdExitOnUsageError(cmd, "invalid arguments")
}
return cmdCheckRequiredFlags(cmd, []string{
"name",
"name-server",
})
},
RunE: func(cmd *cobra.Command, args []string) error {
name, err := cmd.Flags().GetString("name")
if err != nil {
return err
}
mailSrv, err := cmd.Flags().GetString("mail-server-host")
if err != nil {
return err
}
ttl, err := cmd.Flags().GetInt("ttl")
if err != nil {
return err
}
domain, err := csDNS.GetDomain(gContext, args[0])
if err != nil {
return err
}
_, err = csDNS.CreateRecord(gContext, args[0], egoscale.DNSRecord{
DomainID: domain.ID,
TTL: ttl,
RecordType: "NS",
Name: name,
Content: mailSrv,
})
if err != nil {
return err
}
fmt.Printf("Record %q was created successfully to %q\n", cmd.Name(), args[0])
return nil
},
}
func init() {
dnsAddCmd.AddCommand(dnsNSCmd)
dnsNSCmd.Flags().StringP("name", "n", "", "You may use the * wildcard here.")
dnsNSCmd.Flags().StringP("name-server", "s", "", "Example: 'ns1.example.com'")
dnsNSCmd.Flags().IntP("ttl", "t", 3600, "The time in seconds to live (refresh rate) of the record.")
}
// POOLCmd represents the POOL command
var dnsPOOLCmd = &cobra.Command{
Use: "POOL <domain name>",
Short: "Add POOL record type to a domain",
Long: `Add a "POOL" record that aliases a subdomain to another host as
part of a pool of available CNAME records. This is a DNSimple custom record type.`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
cmdExitOnUsageError(cmd, "invalid arguments")
}
return cmdCheckRequiredFlags(cmd, []string{
"name",
"alias",
})
},
RunE: func(cmd *cobra.Command, args []string) error {
name, err := cmd.Flags().GetString("name")
if err != nil {
return err
}
alias, err := cmd.Flags().GetString("alias")
if err != nil {
return err
}
ttl, err := cmd.Flags().GetInt("ttl")
if err != nil {
return err
}
domain, err := csDNS.GetDomain(gContext, args[0])
if err != nil {
return err
}
_, err = csDNS.CreateRecord(gContext, args[0], egoscale.DNSRecord{
DomainID: domain.ID,
TTL: ttl,
RecordType: "POOL",
Name: name,
Content: alias,
})
if err != nil {
return err
}
fmt.Printf("Record %q was created successfully to %q\n", cmd.Name(), args[0])
return nil
},
}
func init() {
dnsAddCmd.AddCommand(dnsPOOLCmd)
dnsPOOLCmd.Flags().StringP("name", "n", "", "You may use the * wildcard here.")
dnsPOOLCmd.Flags().StringP("alias", "a", "", "Alias for: Example: 'some-other-site.com'")
dnsPOOLCmd.Flags().IntP("ttl", "t", 3600, "The time in seconds to live (refresh rate) of the record.")
}
// SRVCmd represents the SRV command
var dnsSRVCmd = &cobra.Command{
Use: "SRV <domain name>",
Short: "Add SRV record type to a domain",
Long: `Add an "SRV" record to specify the location of servers for a specific service.`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
cmdExitOnUsageError(cmd, "invalid arguments")
}
return cmdCheckRequiredFlags(cmd, []string{
"symbolic-name",
"protocol",
"priority",
"weight",
"port",
"target",
})
},
RunE: func(cmd *cobra.Command, args []string) error {
name, err := cmd.Flags().GetString("name")
if err != nil {
return err
}
if name != "" {
name = fmt.Sprintf(".%s", name)
}
symbName, err := cmd.Flags().GetString("symbolic-name")
if err != nil {
return err
}
protocol, err := cmd.Flags().GetString("protocol")
if err != nil {
return err
}
prio, err := cmd.Flags().GetInt("priority")
if err != nil {
return err
}
weight, err := cmd.Flags().GetInt("weight")
if err != nil {
return err
}
port, err := cmd.Flags().GetString("port")
if err != nil {
return err
}
target, err := cmd.Flags().GetString("target")
if err != nil {
return err
}
ttl, err := cmd.Flags().GetInt("ttl")
if err != nil {
return err
}
domain, err := csDNS.GetDomain(gContext, args[0])
if err != nil {
return err
}
_, err = csDNS.CreateRecord(gContext, args[0], egoscale.DNSRecord{
DomainID: domain.ID,
TTL: ttl,
RecordType: "SRV",
Name: fmt.Sprintf("_%s._%s%s", symbName, protocol, name),
Content: fmt.Sprintf("%d %s %s", weight, port, target),
Prio: prio,
})
if err != nil {
return err
}
if !gQuiet {
fmt.Printf("Record %q was created successfully to %q\n", cmd.Name(), args[0])
}
return nil
},
}
func init() {
dnsAddCmd.AddCommand(dnsSRVCmd)
dnsSRVCmd.Flags().StringP("name", "n", "", "Leave this blank to create a record for <domain name>, You may use the '*' wildcard here.")
dnsSRVCmd.Flags().StringP("symbolic-name", "s", "", "This will be a symbolic name for the service, like 'sip'. It might also be called Service at other DNS providers.")
dnsSRVCmd.Flags().StringP("protocol", "p", "", "This will usually be 'TCP' or 'UDP'.")
dnsSRVCmd.Flags().IntP("priority", "", 0, "Priority")
dnsSRVCmd.Flags().IntP("weight", "w", 0, "A relative weight for 'SRV' records with the same priority.")
dnsSRVCmd.Flags().StringP("port", "P", "", "The 'TCP' or 'UDP' port on which the service is found.")
dnsSRVCmd.Flags().StringP("target", "", "", "The canonical hostname of the machine providing the service.")
dnsSRVCmd.Flags().IntP("ttl", "t", 3600, "The time in seconds to live (refresh rate) of the record.")
}
// SSHFPCmd represents the SSHFP command
var dnsSSHFPCmd = &cobra.Command{
Use: "SSHFP <domain name>",
Short: "Add SSHFP record type to a domain",
Long: `Edit an "SSHFP" record to share your SSH fingerprint with others.`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
cmdExitOnUsageError(cmd, "invalid arguments")
}
return cmdCheckRequiredFlags(cmd, []string{
"algorithm",
"fingerprint-type",
})
},
RunE: func(cmd *cobra.Command, args []string) error {
name, err := cmd.Flags().GetString("name")
if err != nil {
return err
}
algo, err := cmd.Flags().GetInt("algorithm")
if err != nil {
return err
}
fingerIDType, err := cmd.Flags().GetInt("fingerprint-type")
if err != nil {
return err
}
fingerprint, err := cmd.Flags().GetString("fingerprint")
if err != nil {
return err
}
ttl, err := cmd.Flags().GetInt("ttl")
if err != nil {
return err
}
domain, err := csDNS.GetDomain(gContext, args[0])
if err != nil {
return err
}
_, err = csDNS.CreateRecord(gContext, args[0], egoscale.DNSRecord{
DomainID: domain.ID,
TTL: ttl,
RecordType: "SSHFP",
Name: name,
Content: fmt.Sprintf("%d %d %s", algo, fingerIDType, fingerprint),
})
if err != nil {
return err
}
fmt.Printf("Record %q was created successfully to %q\n", cmd.Name(), args[0])
return nil
},
}
func init() {
dnsAddCmd.AddCommand(dnsSSHFPCmd)
dnsSSHFPCmd.Flags().StringP("name", "n", "", "Leave this blank to create a record for <domain name>, You may use the '*' wildcard here.")
dnsSSHFPCmd.Flags().IntP("algorithm", "a", 0, "RSA(1) | DSA(2) | ECDSA(3) | ED25519(4)")
dnsSSHFPCmd.Flags().IntP("fingerprint-type", "", 0, "SHA1(1) | SHA256(2)")
dnsSSHFPCmd.Flags().StringP("fingerprint", "f", "", "Fingerprint")
dnsSSHFPCmd.Flags().IntP("ttl", "t", 3600, "The time in seconds to live (refresh rate) of the record.")
}
// TXTCmd represents the TXT command
var dnsTXTCmd = &cobra.Command{
Use: "TXT <domain name>",
Short: "Add TXT record type to a domain",
Long: `Add a "TXT" record. This is useful for domain records that are not covered by
the standard record types. For example, Google uses this type of record for domain verification.`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
cmdExitOnUsageError(cmd, "invalid arguments")
}
return cmdCheckRequiredFlags(cmd, []string{"content"})
},
RunE: func(cmd *cobra.Command, args []string) error {
name, err := cmd.Flags().GetString("name")
if err != nil {
return err
}
content, err := cmd.Flags().GetString("content")
if err != nil {
return err
}
ttl, err := cmd.Flags().GetInt("ttl")
if err != nil {
return err
}
domain, err := csDNS.GetDomain(gContext, args[0])
if err != nil {
return err
}
_, err = csDNS.CreateRecord(gContext, args[0], egoscale.DNSRecord{
DomainID: domain.ID,
TTL: ttl,
RecordType: "TXT",
Name: name,
Content: content,
})
if err != nil {
return err
}
fmt.Printf("Record %q was created successfully to %q\n", cmd.Name(), args[0])
return nil
},
}
func init() {
dnsAddCmd.AddCommand(dnsTXTCmd)
dnsTXTCmd.Flags().StringP("name", "n", "", "Leave this blank to create a record for <domain name>, You may use the '*' wildcard here.")
dnsTXTCmd.Flags().StringP("content", "c", "", "Content record")
dnsTXTCmd.Flags().IntP("ttl", "t", 3600, "The time in seconds to live (refresh rate) of the record.")
}
// URLCmd represents the URL command
var dnsURLCmd = &cobra.Command{
Use: "URL <domain name>",
Short: "Add URL record type to a domain",
Long: `Add an URL redirection record that points your domain to a URL.
This type of record uses an HTTP redirect to redirect visitors from a domain to a web site.`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
cmdExitOnUsageError(cmd, "invalid arguments")
}
return cmdCheckRequiredFlags(cmd, []string{"destination-url"})
},
RunE: func(cmd *cobra.Command, args []string) error {
name, err := cmd.Flags().GetString("name")
if err != nil {
return err
}
destURL, err := cmd.Flags().GetString("destination-url")
if err != nil {
return err
}
ttl, err := cmd.Flags().GetInt("ttl")
if err != nil {
return err
}
domain, err := csDNS.GetDomain(gContext, args[0])
if err != nil {
return err
}
_, err = csDNS.CreateRecord(gContext, args[0], egoscale.DNSRecord{
DomainID: domain.ID,
TTL: ttl,
RecordType: "URL",
Name: name,
Content: destURL,
})
if err != nil {
return err
}
fmt.Printf("Record %q was created successfully to %q\n", cmd.Name(), args[0])
return nil
},
}
func init() {
dnsAddCmd.AddCommand(dnsURLCmd)
dnsURLCmd.Flags().StringP("name", "n", "", "Leave this blank to create a record for <domain name>, You may use the '*' wildcard here.")
dnsURLCmd.Flags().StringP("destination-url", "d", "", "Example: https://www.example.com")
dnsURLCmd.Flags().IntP("ttl", "t", 3600, "The time in seconds to live (refresh rate) of the record.")
}