pe-razor-client 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e6c2760d424fcb90751a22b65217172feab26b6c
4
- data.tar.gz: 51cca0cde398a43684ed9398eb709322874a817d
3
+ metadata.gz: 699354279b91bfa3600d9b7c0cda040067a5b9f8
4
+ data.tar.gz: 929d073ad3f2272b1c5175bf5e664d09d273aba6
5
5
  SHA512:
6
- metadata.gz: 455603cb50328105b7fdf55e7e5454c01eab1d7f1043494f5619a98615cf9dd646c1d5ff3884a828e59a7ac569ad44af120e0e9e66332d37b6b4627471b18b5c
7
- data.tar.gz: 26a4ba1316f72362e66501b9d7595b72886f4b1665dee5ef5a90d53235486f3574a209671e011e42fd88a027b3b9c76469fe3e409db2ba12b233f6865cc1b6dc
6
+ metadata.gz: 1c82a4c3b8c71c37a7f660fa638cb753801d41700f25f7d136c3a8a1229d74e94b068929da845cc5bbae97718897ccd881102251ea55459b7acd8d61fac6747d
7
+ data.tar.gz: a6f7638bfd1af09182b9f25273e90d3e5a80cd21c711d7f4df4b9797c6faf6f9bf2bdbcaf74b41fd67425d93943dfa9d2891271e12bd3e7f7d8872d163097c81
data/NEWS.md CHANGED
@@ -1,9 +1,23 @@
1
1
  # Razor Client Release Notes
2
2
 
3
- ## Next - TBD
3
+ ## Next - Next
4
4
 
5
+ * IMPROVEMENT: By default, `razor` will point to port 8151.
6
+
7
+ ## 1.0.0 - 2015-06-08
8
+
9
+ * NEW: Fit collection output to STDIN size for easier viewing.
5
10
  * NEW: RAZOR_CA_FILE environment variable allows TLS/SSL certificate
6
11
  verification for requests.
12
+ * NEW: The default API protocol and port are HTTPS over TLS/SSL on port 8151.
13
+ * NEW: Utilizes `aliases` property in command metadata to better guess datatypes
14
+ for aliases.
15
+ * IMPROVEMENT: `razor hooks` now displays as a table.
16
+ * IMPROVEMENT: Better output for `razor events ##`.
17
+ * IMPROVEMENT: Exits with an error code of 1 when a `razor` command fails.
18
+ * BUGFIX: `razor events` no longer causes exception.
19
+ * BUGFIX: `razor commands ## errors` no longer causes exception.
20
+ * BUGFIX: Hook output message can now be any datatype.
7
21
 
8
22
  ## 0.16.0 - 2015-01-05
9
23
 
@@ -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
@@ -8,7 +8,7 @@ class Razor::CLI::TableFormat
8
8
  headings = (column_overrides or get_headers(doc))
9
9
  row do
10
10
  headings.each do |header|
11
- column(header, :width => get_width(header, doc))
11
+ column(header, :width => column_width!(headings, header, doc))
12
12
  end
13
13
  end
14
14
  doc.each do |page|
@@ -23,12 +23,52 @@ class Razor::CLI::TableFormat
23
23
  capture_output.strip
24
24
  end
25
25
 
26
- def get_width(header, doc)
26
+ # This method has the side effect of modifying the remaining extra_width.
27
+ # It pulls everything together to come up with a single value for the column.
28
+ def column_width!(headings, header, doc)
29
+ content_width = content_width(header, doc)
30
+ average_width = average_width(headings)
31
+ # Is the column too wide and can we do anything about it?
32
+ if content_width > average_width && extra_width(headings, doc) > 0
33
+ # Determine how much room we'd need to make to accommodate the content.
34
+ remaining = content_width - average_width
35
+ # Add back in what we can.
36
+ width = average_width + [@extra_width, remaining].min
37
+ # The new width can't be negative.
38
+ @extra_width = [@extra_width - remaining, 0].max
39
+ width
40
+ else
41
+ [content_width, average_width].min
42
+ end
43
+ end
44
+
45
+ # This calculates how much leeway would exist in all columns if we were to
46
+ # use an auto-sized fixed width for the whole table.
47
+ def extra_width(headings, doc)
48
+ @extra_width ||= headings.map do |header|
49
+ [average_width(headings) - content_width(header, doc), 0].max
50
+ end.inject(:+)
51
+ end
52
+
53
+ # This calculates what an auto-sized fixed-width table's column width would be.
54
+ def average_width(headings)
55
+ # The 3 here = 2 for width gap + 1 for the column separator.
56
+ # The 1 is for the last separator.
57
+ console_width = `stty size | cut -d ' ' -f 2 2>/dev/null`
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)
62
+ end
63
+
64
+ def content_width(header, doc)
65
+ # Find longest item, including the header
27
66
  (doc.map do |page|
28
67
  (page[header] or '').to_s.length
29
68
  end << header.to_s.length).max
30
69
  end
31
70
 
71
+ # Traverse all headers to compile a unique list.
32
72
  def get_headers(doc)
33
73
  [].tap do |headers|
34
74
  doc.map do |page|
@@ -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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pe-razor-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet Labs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-27 00:00:00.000000000 Z
11
+ date: 2015-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mime-types
@@ -80,7 +80,11 @@ executables:
80
80
  extensions: []
81
81
  extra_rdoc_files: []
82
82
  files:
83
+ - LICENSE
84
+ - NEWS.md
85
+ - README.md
83
86
  - bin/razor
87
+ - lib/razor.rb
84
88
  - lib/razor/cli.rb
85
89
  - lib/razor/cli/command.rb
86
90
  - lib/razor/cli/document.rb
@@ -93,10 +97,6 @@ files:
93
97
  - lib/razor/cli/version.rb
94
98
  - lib/razor/cli/views.rb
95
99
  - lib/razor/cli/views.yaml
96
- - lib/razor.rb
97
- - NEWS.md
98
- - README.md
99
- - LICENSE
100
100
  - spec/cli/command_spec.rb
101
101
  - spec/cli/format_spec.rb
102
102
  - spec/cli/navigate_spec.rb
@@ -151,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
151
  version: '0'
152
152
  requirements: []
153
153
  rubyforge_project:
154
- rubygems_version: 2.0.14
154
+ rubygems_version: 2.4.2
155
155
  signing_key:
156
156
  specification_version: 4
157
157
  summary: Razor is an advanced provisioning application