nettica 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,7 @@
1
+ == 0.2.0 / 2008-01-28
2
+
3
+ * Expanded api in command line script
4
+
1
5
  == 0.1.0 / 2008-01-28
2
6
 
3
7
  * Initial release
@@ -7,6 +7,8 @@ require 'rubygems'
7
7
  require 'nettica/client'
8
8
 
9
9
  options = OpenStruct.new
10
+ options.ttl = 0
11
+ options.priority = 0
10
12
 
11
13
  opts = OptionParser.new do |opts|
12
14
  opts.banner = "Usage: nettica -u username -p password -c command"
@@ -20,13 +22,46 @@ opts = OptionParser.new do |opts|
20
22
  opts.on("-p", "--password PASSWORD", "Nettica password to use for authentication") do |val|
21
23
  options.password = val
22
24
  end
23
- opts.on("-c", "--command COMMAND", [:list_zones, :get_service_info],
25
+ opts.on("-d", "--domain DOMAIN_NAME", "Domain name to apply command to") do |val|
26
+ options.domain = val
27
+ end
28
+ opts.on("-h", "--host HOST_NAME", "Hostname to act upon") do |val|
29
+ options.host = val
30
+ end
31
+ opts.on("-i", "--ip IP", "IP address") do |val|
32
+ options.ip = val
33
+ end
34
+ opts.on("-r", "--recordtype RECORD_TYPE", "Domain record type (A, CNAME, MX, F, TXT,", "SRV)") do |val|
35
+ options.recordtype = val
36
+ end
37
+ opts.on("-t", "--ttl TIME_TO_LIVE", "TTL for domain entries", Integer) do |val|
38
+ options.ttl = val
39
+ end
40
+ opts.on("-o", "--priority PRIORITY", "Priority for MX/F records", Integer) do |val|
41
+ options.priority = val
42
+ end
43
+ opts.on("-g", "--group GROUP", "Domain group") do |val|
44
+ options.group = val
45
+ end
46
+ opts.on("-m", "--master MASTER", "Master domain") do |val|
47
+ options.master = val
48
+ end
49
+ opts.on("-a", "--data DATA", "IP when creating/deleting records") do |val|
50
+ options.data = val
51
+ end
52
+
53
+ opts.on("-c", "--command COMMAND",
54
+ [:list_zones, :get_service_info, :update_record, :delete_record, :apply_template,
55
+ :list_domain, :create_secondary_zone, :delete_zone, :create_zone, :add_record],
24
56
  "Command to execute against nettica service.",
25
- "One of list_zones, get_service_info") do |val|
57
+ "One of list_zones, get_service_info,",
58
+ "list_domain, update_record, delete_record,",
59
+ "apply_template, create_secondary_zone,",
60
+ "delete_zone, create_zone, add_record") do |val|
26
61
  options.command = val
27
62
  end
28
63
 
29
- opts.on_tail("-h", "--help", "Show this message") do
64
+ opts.on_tail("--help", "Show this message") do
30
65
  puts opts
31
66
  exit
32
67
  end
@@ -34,11 +69,43 @@ end
34
69
 
35
70
  begin
36
71
  args = opts.parse!(ARGV)
72
+ p options
37
73
  raise "Missing required flag" if ! options.username || ! options.password || ! options.command
74
+
38
75
  rescue Exception => e
39
76
  puts e, "", opts
40
77
  exit
41
78
  end
42
79
 
80
+ result = nil
43
81
  client = Nettica::Client.new(options.username, options.password)
44
- puts client.send(options.command).inspect
82
+ case options.command
83
+ when :list_zones
84
+ result = client.list_zones()
85
+ when :get_service_info
86
+ result = client.get_service_info()
87
+ when :list_domain
88
+ result = client.list_domain(options.domain)
89
+ when :update_record
90
+ dr = client.create_domain_record(options.domain, options.host, options.recordtype,
91
+ options.data, options.ttl, options.priority)
92
+ # result = client.update_record(dr, ?)
93
+ when :delete_record
94
+ dr = client.create_domain_record(options.domain, options.host, options.recordtype,
95
+ options.data, options.ttl, options.priority)
96
+ result = client.delete_record(dr)
97
+ when :apply_template
98
+ result = client.apply_template(options.domain, options.group)
99
+ when :create_secondary_zone
100
+ result = client.create_secondary_zone(options.domain, options.master, options.ip)
101
+ when :delete_zone
102
+ result = client.delete_zone(options.domain)
103
+ when :create_zone
104
+ result = client.create_zone(options.domain)
105
+ when :add_record
106
+ dr = client.create_domain_record(options.domain, options.host, options.recordtype,
107
+ options.data, options.ttl, options.priority)
108
+ result = client.add_record(dr)
109
+ end
110
+
111
+ puts result.inspect
@@ -1,3 +1,3 @@
1
1
  class Nettica
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -26,10 +26,35 @@ module Nettica
26
26
  # data - SOAP::SOAPString
27
27
  # ttl - SOAP::SOAPInt
28
28
  # priority - SOAP::SOAPInt
29
- def self.create_domain_record(domainName = nil, hostName = nil, recordType = nil, data = nil, ttl = nil, priority = nil)
29
+ def create_domain_record(domainName = nil, hostName = nil, recordType = nil, data = nil, ttl = 0, priority = 0)
30
+ valid_ttls = [0, 1, 60, 300, 600, 900, 1800, 2700, 3600, 7200, 14400, 28800, 43200, 64800, 86400, 172800]
31
+ raise "Ttl must be one of #{valid_ttls.join(',')}" if ttl && ! valid_ttls.include?(ttl)
32
+
33
+ mx_prio = [5, 10, 20, 30, 40, 50, 60, 70, 80, 90]
34
+ f_prio = [1, 2, 3]
35
+ raise "MX priority must be one of #{mx_prio.join(',')}" if recordType == "MX" and ! mx_prio.include?(priority)
36
+ raise "F priority must be one of #{f_prio.join(',')}" if recordType == "F" and ! f_prio.include?(priority)
37
+
38
+ valid_types = ["A", "CNAME", "MX", "F", "TXT", "SRV"]
39
+ raise "Record type must be one of #{valid_types.join(',')}" if recordType && ! valid_types.include?(recordType)
40
+
30
41
  DomainRecord.new(domainName, hostName, recordType, data, ttl, priority)
31
42
  end
32
43
 
44
+ def decode_status(result)
45
+ case result.result.status
46
+ when 200: "Success"
47
+ when 401: "Access Denied"
48
+ when 404: "Not Found"
49
+ when 430: "Domain Exists"
50
+ when 431: "Record already exists"
51
+ when 432: "Invalid record type. Must be A, CNAME, MX, F, TXT, SRV"
52
+ when 450: "No Service"
53
+ when 451: "No credits"
54
+ when 460: "Your service has expired"
55
+ end
56
+ end
57
+
33
58
  def update_record(old_domain_record, new_domain_record)
34
59
  @proxy.updateRecord(UpdateRecord.new(@username, @password, old_domain_record, new_domain_record)).updateRecordResult
35
60
  end
@@ -62,8 +87,8 @@ module Nettica
62
87
  @proxy.deleteZone(DeleteZone.new(@username, @password, domainName)).deleteZoneResult
63
88
  end
64
89
 
65
- def create_zone(domainName, ipAddress)
66
- @proxy.createZone(CreateZone.new(@username, @password, domainName, ipAddress)).createZoneResult
90
+ def create_zone(domainName)
91
+ @proxy.createZone(CreateZone.new(@username, @password, domainName, "")).createZoneResult
67
92
  end
68
93
 
69
94
  def add_record(domain_record)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nettica
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Conway