razor-client 1.0.0 → 1.1.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.
data/NEWS.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Razor Client Release Notes
2
2
 
3
+ ## 1.1.0 - 2015-11-12
4
+
5
+ * IMPROVEMENT: By default, `razor` will point to port 8150.
6
+ * IMPROVEMENT: Better display of several views/collections.
7
+
3
8
  ## 1.0.0 - 2015-06-08
4
9
 
5
10
  * NEW: Fit collection output to STDIN size for easier viewing.
@@ -42,9 +42,13 @@ module Razor::CLI
42
42
  # Allow both '+column' as overrides.
43
43
  item_spec = (item_format_spec[1] or {})
44
44
  item_label = item_format_spec[0]
45
- item_column = (item_spec['+column'] or item_label)
46
45
  begin
47
- value = Razor::CLI::Views.transform(item[item_column], item_spec['+format'])
46
+ value = if item_spec.has_key?('+all-columns')
47
+ Razor::CLI::Views.transform(item, item_spec['+format'])
48
+ else
49
+ item_column = (item_spec['+column'] or item_label)
50
+ Razor::CLI::Views.transform(item[item_column], item_spec['+format'])
51
+ end
48
52
  [item_label, value]
49
53
  rescue Razor::CLI::HideColumnError
50
54
  nil
@@ -3,6 +3,42 @@ require 'multi_json'
3
3
  require 'yaml'
4
4
  require 'forwardable'
5
5
 
6
+ # Needed to make the client work on Ruby 1.8.7
7
+ unless URI.respond_to?(:encode_www_form)
8
+ module URI
9
+ def self.encode_www_form_component(str)
10
+ str = str.to_s
11
+ if HTML5ASCIIINCOMPAT.include?(str.encoding)
12
+ str = str.encode(Encoding::UTF_8)
13
+ else
14
+ str = str.dup
15
+ end
16
+ str.force_encoding(Encoding::ASCII_8BIT)
17
+ str.gsub!(/[^*\-.0-9A-Z_a-z]/, TBLENCWWWCOMP_)
18
+ str.force_encoding(Encoding::US_ASCII)
19
+ end
20
+ def self.encode_www_form(enum)
21
+ enum.map do |k,v|
22
+ if v.nil?
23
+ encode_www_form_component(k)
24
+ elsif v.respond_to?(:to_ary)
25
+ v.to_ary.map do |w|
26
+ str = encode_www_form_component(k)
27
+ unless w.nil?
28
+ str << '='
29
+ str << encode_www_form_component(w)
30
+ end
31
+ end.join('&')
32
+ else
33
+ str = encode_www_form_component(k)
34
+ str << '='
35
+ str << encode_www_form_component(v)
36
+ end
37
+ end.join('&')
38
+ end
39
+ end
40
+ end
41
+
6
42
  module Razor::CLI
7
43
  class Navigate
8
44
  extend Forwardable
@@ -2,11 +2,21 @@ require 'uri'
2
2
  require 'optparse'
3
3
  require 'forwardable'
4
4
 
5
+ # Needed to make the client work on Ruby 1.8.7
6
+ unless URI::Generic.method_defined?(:hostname)
7
+ module URI
8
+ def hostname
9
+ v = self.host
10
+ /\A\[(.*)\]\z/ =~ v ? $1 : v
11
+ end
12
+ end
13
+ end
14
+
5
15
  module Razor::CLI
6
16
 
7
17
  class Parse
8
18
  extend Forwardable
9
- DEFAULT_RAZOR_API = "http://localhost:8080/api"
19
+ DEFAULT_RAZOR_API = "http://localhost:8150/api"
10
20
 
11
21
  def_delegator 'navigate', 'query?'
12
22
 
@@ -54,7 +54,11 @@ class Razor::CLI::TableFormat
54
54
  def average_width(headings)
55
55
  # The 3 here = 2 for width gap + 1 for the column separator.
56
56
  # The 1 is for the last separator.
57
- @average_width ||= (((`stty size | cut -d ' ' -f 2` || 80).to_i - (headings.count * 3) - 1) / headings.count)
57
+ console_width = `stty size | cut -d ' ' -f 2`
58
+ if console_width.nil? || console_width.to_i <= 0
59
+ console_width = 80
60
+ end
61
+ @average_width ||= ((console_width.to_i - (headings.count * 3) - 1) / headings.count)
58
62
  end
59
63
 
60
64
  def content_width(header, doc)
@@ -58,10 +58,15 @@ module Razor::CLI
58
58
  obj['msg']
59
59
  end
60
60
  def event_entities(hash)
61
+ hash ||= {}
61
62
  shallow_hash(Hash[hash].keep_if {|k,_| ['task', 'policy', 'broker', 'repo', 'node', 'command'].include?(k)})
62
63
  end
63
64
  def event_misc(hash)
65
+ hash ||= {}
64
66
  shallow_hash(Hash[hash].delete_if {|k,_|['task', 'policy', 'broker', 'repo', 'node', 'msg', 'command'].include?(k)})
65
67
  end
68
+ def node_log_entry(hash)
69
+ shallow_hash(Hash[hash].delete_if {|k,_|['event', 'timestamp', 'severity'].include?(k)})
70
+ end
66
71
  end
67
72
  end
@@ -18,7 +18,7 @@ module Razor
18
18
  #
19
19
  # The next line is the one that our packaging tools modify, so please make
20
20
  # sure that any change to it is discussed and agreed first.
21
- version = '1.0.0'
21
+ version = '1.1.0'
22
22
 
23
23
  if version == "DEVELOPMENT"
24
24
  root = File.expand_path("../../..", File.dirname(__FILE__))
@@ -52,6 +52,8 @@ collections:
52
52
  dhcp_mac:
53
53
  +format: mac
54
54
  state:
55
+ policy:
56
+ +format: select_name
55
57
  last_checkin:
56
58
  +format: if_present
57
59
  metadata:
@@ -75,10 +77,14 @@ collections:
75
77
  log:
76
78
  +short:
77
79
  +layout: table
78
- # +show:
79
- # event:
80
- # task:
81
- # timestamp:
80
+ +show:
81
+ name:
82
+ timestamp:
83
+ severity:
84
+ event:
85
+ entry:
86
+ +all-columns:
87
+ +format: node_log_entry
82
88
  policies:
83
89
  +short:
84
90
  +layout: table
@@ -201,6 +207,7 @@ collections:
201
207
  +show:
202
208
  name:
203
209
  timestamp:
210
+ severity:
204
211
  message:
205
212
  +column: entry
206
213
  +format: event_msg
@@ -215,6 +222,7 @@ collections:
215
222
  +show:
216
223
  name:
217
224
  timestamp:
225
+ severity:
218
226
  message:
219
227
  +column: entry
220
228
  +format: full_event_msg
@@ -84,9 +84,11 @@ describe Razor::CLI::Format do
84
84
 
85
85
  context 'tabular display' do
86
86
  it "works right when columns do not match up" do
87
- doc = {"spec"=>"http://api.puppetlabs.com/razor/v1/collections/nodes/log",
87
+ doc = {"spec"=>"http://api.puppetlabs.com/razor/v1/collections/some/table",
88
88
  "items"=>[{'a' => 'b', 'c' => 'd'},
89
89
  {'b' => 'c', 'e' => 'f'}]}
90
+ Razor::CLI::Views.instance_variable_set('@views',
91
+ {'collections' => {'some' => {'table' => {'+short' => {'+layout' => 'table'}}}}})
90
92
  result = format doc
91
93
  result.should ==
92
94
  # The framework seems to be adding unnecessary spaces at the end of each data line;
@@ -113,8 +115,10 @@ describe Razor::CLI::Format do
113
115
  end
114
116
 
115
117
  it "works right with unicode" do
116
- doc = {"spec"=>"http://api.puppetlabs.com/razor/v1/collections/nodes/log",
118
+ doc = {"spec"=>"http://api.puppetlabs.com/razor/v1/collections/some/table",
117
119
  "items"=>[{'a' => 'ᓱᓴᓐ ᐊᒡᓗᒃᑲᖅ'}]}
120
+ Razor::CLI::Views.instance_variable_set('@views',
121
+ {'collections' => {'some' => {'table' => {'+short' => {'+layout' => 'table'}}}}})
118
122
  result = format doc
119
123
  result.should ==
120
124
  # The framework seems to be adding unnecessary spaces at the end of each data line;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: razor-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-06-05 00:00:00.000000000 Z
12
+ date: 2015-11-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mime-types