vzcdn 0.1.3 → 0.1.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17369072c6982f75c6051118810f9a5a2ff1360f
4
- data.tar.gz: 5b5b170030343d0c6cef577dec0e4749a80d5641
3
+ metadata.gz: ec9cdba53621f9be97fde6eb72d0e923aa06db61
4
+ data.tar.gz: 0931da14e4d50284cf5daa83cc269c0bf308ca37
5
5
  SHA512:
6
- metadata.gz: 87b87d36051c63cb48c92824bae3f2993040f17ba15b02acd0740621c2a49c9b4cc67c38ddff91f16da1c7c5b535c6a6e3f7bcf908edfb397fe0cd7cc2734ac2
7
- data.tar.gz: a66b939d4ffdf552500f46546e960a5bb9b621909a9f77400be7756a377036ea5739a9f612d754e51dd281e2a379e6d986aecbed28e70df161df870de38fc3b7
6
+ metadata.gz: b9f20a06c369095c0cea23437d3321b936a0f6b72799f618bc1c1a699bc7a8aeeb224a0bb29eb4547488fc582054aea3e5751504a19783603294ba999fa96621
7
+ data.tar.gz: 05a60fe2606d87fea0d542647e8c4b518d3f4f90fdcb23f0872b27c9ecf50e40cdf1bdc09b9190976aa22f0af596ae80824d498d93c0a995d370a9a131eb6ad4
data/README.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  Commandline UI for Edgecast API
4
4
 
5
+ ##RELEASE NOTES
6
+ 2014/04/09 0.1.4
7
+ 1. Bug fix for "ec zone <id> pull"
8
+
9
+
5
10
  ## Installation
6
11
 
7
12
  Add this line to your application's Gemfile:
data/bin/ec CHANGED
@@ -3,6 +3,8 @@
3
3
  require 'vzcdn'
4
4
  require 'vzcdn/version'
5
5
 
6
+ $debug = false
7
+
6
8
  if ARGV[0] == "-v"
7
9
  puts "vzcdn version:" + Vzcdn::VERSION
8
10
  exit
@@ -11,8 +13,6 @@ end
11
13
  if ARGV[0] == "-d"
12
14
  $debug = true
13
15
  ARGV.shift
14
- else
15
- $debug = false
16
16
  end
17
17
 
18
18
  args = []
@@ -22,12 +22,14 @@ ARGV.each { |arg|
22
22
 
23
23
  begin
24
24
  VzcdnApp.invoke(args)
25
+ exit 0
25
26
  rescue Exception => e
26
27
  if e.class != SystemExit
27
28
  puts "ERROR:" + e.message
28
29
  if $debug
29
30
  raise e
30
31
  else
32
+ exit 1
31
33
  end
32
34
  end
33
35
  end
data/bin/vzcdn CHANGED
@@ -3,6 +3,8 @@
3
3
  require 'vzcdn'
4
4
  require 'vzcdn/version'
5
5
 
6
+ $debug = false
7
+
6
8
  if ARGV[0] == "-v"
7
9
  puts "vzcdn version:" + Vzcdn::VERSION
8
10
  exit
@@ -11,8 +13,6 @@ end
11
13
  if ARGV[0] == "-d"
12
14
  $debug = true
13
15
  ARGV.shift
14
- else
15
- $debug = false
16
16
  end
17
17
 
18
18
  args = []
@@ -22,12 +22,14 @@ ARGV.each { |arg|
22
22
 
23
23
  begin
24
24
  VzcdnApp.invoke(args)
25
+ exit 0
25
26
  rescue Exception => e
26
27
  if e.class != SystemExit
27
28
  puts "ERROR:" + e.message
28
29
  if $debug
29
30
  raise e
30
31
  else
32
+ exit 1
31
33
  end
32
34
  end
33
35
  end
data/lib/cloptions.rb ADDED
@@ -0,0 +1,103 @@
1
+ class ClOptions
2
+ def initialize(obj, options)
3
+ @obj = obj
4
+ @options = options
5
+ end
6
+
7
+ def handle_options(name, value)
8
+ puts "inside handle_options, name is " + name.to_s + ", value is " + value.to_s
9
+ took_value = false
10
+ valid = false
11
+ @options.each{|option|
12
+ if (option[:long_name] == name) || (option[:short_name] == name)
13
+ valid = true
14
+ if (option[:takes_value]) && (value == nil)
15
+ raise "option " + name + " requires value"
16
+ break
17
+ elsif option[:takes_value]
18
+ @obj.send(option[:method], value)
19
+ took_value = true
20
+ else
21
+ @obj.send(option[:method])
22
+ end
23
+ break
24
+ end
25
+ }
26
+ raise "Invalid option: " + name if !valid
27
+ took_value
28
+ end
29
+
30
+ def parse_longname(arg, m)
31
+ long_name = arg[m.begin(1)...m.end(1)]
32
+ option_value = nil
33
+ if arg[m.end(1)] == '='
34
+ option_value = arg[m.end(1)+1...arg.length]
35
+ end
36
+ return long_name, option_value
37
+ end
38
+
39
+ def parse_shortname (arg)
40
+ short_name = arg[1]
41
+ option_value = nil
42
+ if arg[2] == '='
43
+ option_value = arg[3...arg.length]
44
+ elsif arg.length > 2
45
+ short_name = arg[1...arg.length]
46
+ end
47
+ return short_name, option_value
48
+ end
49
+
50
+ def handle(args)
51
+ @args = [ ]
52
+ i = 0
53
+ while i < args.length
54
+ arg = args[i]
55
+
56
+ if arg == '--'
57
+ @args.concat args[i+1...args.length]
58
+ break
59
+ elsif m = arg.match(/\A--([a-z]+(-[a-z]+)*)/)
60
+ long_name, option_value = parse_longname(arg, m)
61
+ next_captured = false # next argument may be options argument
62
+ if (option_value == nil) && (i+1 < args.length)
63
+ option_value = args[i+1]
64
+ next_captured = true
65
+ end
66
+ took_value = handle_options long_name, option_value
67
+ i += 1 if took_value && next_captured
68
+ elsif arg[0] == '-'
69
+ short_name, option_value = parse_shortname(arg)
70
+ next_captured = false # next argument may be options argument
71
+ if (option_value == nil) && (i+1 < args.length)
72
+ option_value = args[i+1]
73
+ next_captured = true
74
+ end
75
+ took_value = handle_options short_name, option_value
76
+ i += 1 if took_value && next_captured
77
+ else
78
+ @args << arg
79
+ end
80
+ i += 1
81
+ end
82
+ @args
83
+ end
84
+ end
85
+
86
+ def parse_option(arg)
87
+
88
+ end
89
+
90
+ options = [ { short_name: 'd', long_name: 'debug', method: :set_debug, takes_value: false},
91
+ { short_name: 'o', long_name: 'output-file', method: :set_output, takes_value: true}]
92
+
93
+ $debug=false
94
+ def set_debug
95
+ $debug = true
96
+ end
97
+ def set_output(file_name)
98
+ puts "file name = " + file_name
99
+ end
100
+ opts = ClOptions.new(self, options)
101
+ args = opts.handle(ARGV)
102
+ puts "args are:" + args.to_s
103
+ puts "$debug = " + $debug.to_s
data/lib/command_proc.rb CHANGED
@@ -11,6 +11,10 @@ module CommandProc
11
11
  base.init_instances
12
12
  end
13
13
 
14
+ def getopt(obj, args, options)
15
+
16
+ end
17
+
14
18
  module ClassMethods
15
19
  def init_instances
16
20
  class_eval <<-CODE
@@ -47,7 +51,7 @@ module CommandProc
47
51
  command = args.shift
48
52
  instance.send(command, args)
49
53
  else
50
- puts "argument '" + command + "' not recognized as command"
54
+ raise("argument '" + command + "' not recognized as command")
51
55
  end
52
56
  end
53
57
 
data/lib/vzcdn/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vzcdn
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/zone.rb CHANGED
@@ -99,7 +99,7 @@ class Zone
99
99
  else
100
100
  name = @zname
101
101
  end
102
- name = name.sub(/\.\Z/, "")
102
+ name = name.sub(/\.\Z/, "") if ! name.nil?
103
103
  return id, name
104
104
  end
105
105
 
@@ -124,7 +124,6 @@ class Zone
124
124
  end
125
125
  if (zone.nil?)
126
126
  zone = Route.do.get_zone(id, name)
127
- File.open("orig.zone", "w").write(JSON.pretty_generate zone)
128
127
  Route.do.translate_zone(zone)
129
128
  end
130
129
  end
data/test/test_clui.rb CHANGED
@@ -4,19 +4,38 @@ require 'test/unit'
4
4
  require 'tmpdir'
5
5
  require 'tempfile'
6
6
 
7
- class TestClui < Test::Unit::TestCase
8
- def test_config
9
- Dir.mktmpdir do |dir|
10
- Dir.chdir(dir)
11
- `ec config init BED3 e22db149-7369-4d7b-9c53-38d38746ccea`
12
- assert(File.directory?(".vdms.d"), "missing .vdms.d directory")
13
- assert(File.exists?(".vdms.d/config"), "missing config file")
14
- assert_equal("BED3", `ec config get acct-num`.chomp, "get account-num failed")
7
+ bin_dir = File.expand_path '../bin'
8
+ lib_dir = File.expand_path '../lib'
9
+ $ruby_command = "ruby -I" + lib_dir + " " + bin_dir + "/ec "
10
+
11
+ test_directory = Dir.mktmpdir "steve"
12
+ Dir.chdir test_directory
13
+
14
+ class TestClui < MiniTest::Unit::TestCase
15
+ @@config_init = false
16
+ @@zones = nil
17
+ @@config_dir = ".vdms.d"
18
+
19
+ def setup
20
+ first_test unless @@config_init
21
+ end
22
+
23
+ def first_test
24
+ @@config_init = true
25
+ `ec config init BED3 e22db149-7369-4d7b-9c53-38d38746ccea`
26
+ if ENV["HTTP_PROXY"]
27
+ proxy = "http://" + ENV["HTTP_PROXY"]
28
+ `ec config set proxy #{proxy}`
15
29
  end
30
+ assert(File.directory?(@@config_dir), "missing " + @@config_dir + " directory")
31
+ assert(File.exists?(File.join(@@config_dir, "config")), "missing config file")
32
+ assert_equal("BED3", `ec config get acct-num`.chomp, "get account-num failed")
33
+ @@route = Route.do
16
34
  end
35
+
17
36
  def ctest_availables
18
- route = Route.new
19
- puts "zone types:" + route.get_available_zone_types.to_s
37
+ @@route.get_available_zone_types
38
+
20
39
  puts "record types:" + route.get_available_record_types.to_s
21
40
  puts "zone status:" + route.get_available_zone_statuses.to_s
22
41
  puts "route groups:" + route.get_available_route_groups.to_s
@@ -25,4 +44,62 @@ class TestClui < Test::Unit::TestCase
25
44
  puts "hc types:" + route.get_available_health_check_types.to_s
26
45
  puts "hc reints:" + route.get_available_health_check_reintegration_methods.to_s
27
46
  end
47
+
48
+ def call_ec(rest)
49
+ command = $ruby_command + rest
50
+ system(command)
51
+ end
52
+
53
+ def call_ec_io(rest)
54
+ out, err = capture_subprocess_io do
55
+ success = call_ec(rest)
56
+ end
57
+ return out, err, success
58
+ end
59
+
60
+ def assert_ec_output(rest, expected_out)
61
+ out, err, rc = call_ec_io(rest)
62
+ assert success, "'" + rest + "' failed"
63
+ assert_equal expected_out, out.chomp, "'" + rest + "' failed"
64
+ assert_equal '', err.chomp, "'" + rest + "' printed to stderr:" + err
65
+ end
66
+
67
+ def test_config
68
+ assert call_ec("config set myname 'my strange value'"), "'config set' failed"
69
+ assert_ec_output("config get myname", 'my strange value')
70
+ assert call_ec("config delete myname"), "'config delete myname' failed"
71
+ assert_ec_output("config get myname", '')
72
+ end
73
+
74
+ def get_zones
75
+ @@zones = @@route.get_all_zones unless @@zones
76
+ end
77
+
78
+ def zone_file(zone)
79
+ File.join(@@config_dir, "zones",
80
+ zone["DomainName"].sub(/\.\Z/, '') + '.' + zone["ZoneId"].to_s)
81
+ end
82
+
83
+ def test_pull_id
84
+ get_zones
85
+ zone = @@zones.sample
86
+ id = zone["ZoneId"].to_s
87
+ assert call_ec("zone #{id} pull"), "unable to pull zone #{id}"
88
+ assert File.exists?(zone_file zone), "file #{zone_file zone} not created"
89
+ File.delete(zone_file zone)
90
+ end
91
+
92
+ def test_pull_name
93
+ get_zones
94
+ zone = @@zones.sample
95
+ name = zone["DomainName"]
96
+ assert call_ec("zone #{name} pull"), "unable to pull zone #{name}"
97
+ assert File.exists?(zone_file zone), "file #{zone_file zone} not created"
98
+ File.delete(zone_file zone)
99
+ end
28
100
  end
101
+
102
+ rc = (Test::Unit::Runner.new.run(ARGV) || true)
103
+ FileUtils.remove_entry test_directory
104
+
105
+ exit rc
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vzcdn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Preston
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-04-08 00:00:00.000000000 Z
13
+ date: 2014-04-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
@@ -72,6 +72,7 @@ files:
72
72
  - bin/ec
73
73
  - bin/vzcdn
74
74
  - lib/args.rb
75
+ - lib/cloptions.rb
75
76
  - lib/clui_config.rb
76
77
  - lib/command_proc.rb
77
78
  - lib/common.rb