cmdb 3.0.0rc4 → 3.0.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: c88c245ee9bc31f0fe4f261b3d688402b0f06be1
4
- data.tar.gz: 0e6b981474487959202b1bc16a85e5411754c818
3
+ metadata.gz: 1f4287917beeab0bb0a6ac9d486f2f6c2c5cf81d
4
+ data.tar.gz: 488206107b1515b2ecb4933690a718d8541ff4ae
5
5
  SHA512:
6
- metadata.gz: a613be0d9de98744ba0b86d799d6f3685e46632a8d8373cb6ba1b1b473b326a26ce6b95912be9b60f31f5090ca2a883784fdf89d0e3362a9a5acbc6d15953887
7
- data.tar.gz: 337b285e2ed120e8b543fe4cc0e1c9e0e1af759589aee4072c022bc76a793272b934185c12db54b2bd9860fe2a325c5c879423f4b38b45423f08ebde01d29b16
6
+ metadata.gz: ead52e74f5ee6565fbbd78cce0db6397fd3b9ae55fa74583d283b911a7f98508b1eb31072bee6ebc8d4167375f2dc2fe1ebc716af9c8b2bf6f1b206c98275688
7
+ data.tar.gz: 41f23de1b60dbb5606b9262b304d37f08d93f1b979032681cb1ba23dd50e515dc8423535544754ed48fe9b4e89bbc36394c56c0eddc9e22d6e2bad77182c90f8
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cmdb (3.0.0rc4)
4
+ cmdb (3.0.0)
5
5
  trollop (~> 2.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -17,39 +17,46 @@ Maintained by
17
17
 
18
18
  ## Why should I use this gem?
19
19
 
20
- CMDB supports two primary use cases:
20
+ With CMDB, you can:
21
21
 
22
22
  1. Decouple your modern (12-factor) application from the CM mechanism that is used to deploy it,
23
23
  transforming CMDB keys and values into the enviroment variables that your app expects.
24
24
  2. Deploy legacy applications that expect their configuration to be
25
25
  written to disk files by rewriting files at app-load time, substituting
26
26
  CMDB variables into the files as required.
27
+ 3. Explore your CMDB contents from the command line using a beautiful shell.
27
28
 
28
29
  CMDB has three primary interfaces:
29
30
 
30
31
  1. The `cmdb shim` command populates the environment with values and/or rewrites hardcoded
31
32
  config files, then spawns your application.
32
- 2. The `CMDB::Interface` object provides a programmatic API for querying CMDBs. Its `#to_env`
33
+ 2. The `cmdb shell` command navigates your k/v store using filesystem-like
34
+ metaphors (`ls`, `cd`, and so forth) with color output and tab completion
35
+ 3. The `CMDB::Interface` object provides a programmatic API for querying CMDBs. Its `#to_env`
33
36
  method transforms the whole configuration into an environment-friendly hash if you prefer to seed the
34
37
  environment yourself, without using the shim.
35
- 3. The `cmdb shell` command navigates your k/v store using filesystem-like
36
- metaphors (`ls`, `cd`, and so forth)
37
38
 
38
39
  # Data Model
39
40
 
40
- CMDB models all data sources as hierarchical trees whose nodes are named, and
41
- whose leaf nodes can contain a piece of data: strings, numbers, booleans, or
42
- lists are all supported data types. Maps are disallowed on order to prevent
43
- ambiguity; a map always represents a subtree of the k/v store, never a value.
41
+ CMDB models all data sources as trees whose nodes are named, and whose leaf
42
+ nodes can contain a piece of data: strings, numbers, booleans, or arrays.
44
43
 
45
- This model is a "least common denominator" simplification of the data models of
46
- YML, JSON, ZooKeeper and etcd; by disallowing maps as the values of keys, it
47
- avoids ambiguity over whether a map should be treated as a subtree or as a
48
- distinct value.
44
+ Maps are disallowed on order to prevent ambiguity; a map always represents a
45
+ subtree of the k/v store, never a value. Mixed-type arrays are disallowed
46
+ because they can cause problems with strongly-typed languages. Nil is
47
+ disallowed as a value because writing nil means "delete the key."
48
+
49
+ Paths within a tree -- and therefore CMDB keys -- are identified using a dot
50
+ notation similar to Java properties; for instance, `production.http.listen_port`
51
+ might be an Integer-valued key that tells your microservice which HTTP port
52
+ to listen on in the production environment; `production.database.host` might be
53
+ the database host, and so forth. The names of keys are determined by the tree
54
+ structure of your k/v store, and when you set a key through CMDB, its position
55
+ in the tree is derived from its key name.
49
56
 
50
57
  ## Source Prefixes
51
58
 
52
- Some CMDB sources have a `prefix`, indicating that _all_ keys contained in
59
+ CMDB sources have a `prefix`, meaning that _all_ keys contained in
53
60
  that source begin with the same prefix. No two sources may share a prefix,
54
61
  ensuring that sources don't "hide" each others' data. The prefix of a source is
55
62
  usually automatically determined by the final component of its URL, e.g. the
@@ -63,7 +70,7 @@ disjoint; there is no such thing as "inheritance" in the CMDB data model.
63
70
 
64
71
  When keys are exported to the environment, the prefix is stripped from the
65
72
  key name; however, CMDB _still_ prevents overlap in this case.
66
-
73
+
67
74
  Inheritance may be supported in future as an optional behavior, but is omitted
68
75
  for the time being because in practice, it causes more problems than it solves.
69
76
 
@@ -135,13 +142,13 @@ Examples:
135
142
  use this source with the `myapp` source in the example above!)
136
143
 
137
144
  If no sources are specified on the command line, CMDB will run an auto-detect
138
- algorithm to check for network agents listening at localhost.
145
+ algorithm to check for network agents listening at localhost.
139
146
 
140
147
  To learn more about sources and prefixes, see "Data model," below.
141
148
 
142
149
  ## Invoke the CMDB Shell
143
150
 
144
- To enter an interactive sh-like shell, just type `cmdb shell`.
151
+ To enter an interactive sh-like shell, just type `cmdb shell`.
145
152
 
146
153
  ## Invoke the CMDB Shim
147
154
 
@@ -181,7 +188,7 @@ found, it substitutes the corresponding CMDB key's value.
181
188
 
182
189
  Replacement tokens look like this: `<<name.of.my.key>>` and can appear anywhere in a file as a YAML
183
190
  or JSON _value_ (but never a key). Unlike environment variables, replacement tokens always use
184
- the fully-qualified key name, including prefix.
191
+ the fully-qualified key name, including prefix.
185
192
 
186
193
  Replacement tokens should appear inside string literals in your configuration files so they don't
187
194
  invalidate syntax or render the files unparsable by other tools.
data/TODO.md CHANGED
@@ -1,10 +1,2 @@
1
- 1) Move array validation stuff (same type, etc) out of File source so Consul
2
- can use it. Or decide to ditch this constraint ... hmm ...
3
-
4
- 2) Create a Shell.new helper to enable embedding of shells into other apps
5
-
6
- 3) Extract padding/truncation/excerpting code into Text module; deal with
1
+ 1) Extract padding/truncation/excerpting code into Text module; deal with
7
2
  corner cases better.
8
-
9
- 4) Move CMDB separator logic (join/split) into toplevel methods of CMDB;
10
- DRY out Shell#expand_path
@@ -127,17 +127,17 @@ module CMDB
127
127
 
128
128
  module_function
129
129
 
130
- # Split a dotted-notation CMDB key into its constituent parts and return an
130
+ # Split a dot-notation CMDB key into its constituent parts and return an
131
131
  # Array. Optionally limit the amount of splitting done by passing parts > 0.
132
132
  #
133
133
  # @return [Array]
134
- # @param [String] key dotted-notation key
134
+ # @param [String] key dot-notation key
135
135
  # @param [Integer] parts number of total parts to return
136
136
  def split(key, parts=0)
137
137
  key.split(SEPARATOR, parts)
138
138
  end
139
139
 
140
- # Transform a list of key components into a dotted-notation key.
140
+ # Transform a list of key components into a dot-notation key.
141
141
  #
142
142
  # @return [String]
143
143
  def join(*pieces)
@@ -95,6 +95,33 @@ module CMDB
95
95
  def prefixed?(key)
96
96
  prefix.nil? || (key.index(prefix) == 0 && key[prefix.size] == '.')
97
97
  end
98
+
99
+ # Check whether a CMDB value conforms to the extra-strict constraints
100
+ # that we place on certain object types.
101
+ #
102
+ # @return [Object] always returns value (unless it raises)
103
+ # @param [String] dot-notation key, used to describe errors
104
+ # @param [Object] value
105
+ # @raise [BadValue] if the value is bad
106
+ def validate!(key, value)
107
+ case value
108
+ when Array
109
+ if value.any? { |e| e.is_a?(Hash) }
110
+ raise BadValue.new(uri, key, value, 'hashes not allowed inside arrays')
111
+ elsif value.all? { |e| e.is_a?(String) } ||
112
+ value.all? { |e| e.is_a?(Numeric) } ||
113
+ value.all? { |e| e == true } ||
114
+ value.all? { |e| e == false }
115
+ value
116
+ else
117
+ raise BadValue.new(uri, key, value, 'mismatched or disallowed element types')
118
+ end
119
+ when String, Numeric, TrueClass, FalseClass, NilClass
120
+ value
121
+ else
122
+ raise BadValue.new(uri, key, value)
123
+ end
124
+ end
98
125
  end
99
126
  end
100
127
 
@@ -27,7 +27,8 @@ module CMDB
27
27
  when String
28
28
  response = json_parse(response)
29
29
  item = response.first
30
- item['Value'] && json_parse(Base64.decode64(item['Value']))
30
+ item['Value'] && value = json_parse(Base64.decode64(item['Value']))
31
+ validate!(key, value)
31
32
  when 404
32
33
  nil
33
34
  else
@@ -49,6 +50,7 @@ module CMDB
49
50
  if value.nil?
50
51
  status = http_delete path_to(key)
51
52
  else
53
+ validate!(key, value)
52
54
  status = http_put path_to(key), value
53
55
  end
54
56
 
@@ -80,6 +82,7 @@ module CMDB
80
82
  key.sub(@useless,'')
81
83
  next unless item['Value']
82
84
  value = json_parse(Base64.decode64(item['Value']))
85
+ validate!(key, value)
83
86
  yield(key, value)
84
87
  end
85
88
 
@@ -38,13 +38,18 @@ module CMDB
38
38
 
39
39
  @data = {}
40
40
  flatten(raw_data, @prefix, @data)
41
+
42
+ # File sources are static; we can check them for data errors at load
43
+ # time. Do this by each'ing, which validates values as a side effect.
44
+ each_pair { |_,_| }
41
45
  end
42
46
 
43
47
  # Get the value of key.
44
48
  #
45
49
  # @return [Object] the key's value, or nil if not found
46
50
  def get(key)
47
- @data[key]
51
+ value = @data[key]
52
+ validate!(key, value)
48
53
  end
49
54
 
50
55
  # Enumerate the keys and values in this source.
@@ -53,7 +58,10 @@ module CMDB
53
58
  # @yieldparam [String] key
54
59
  # @yieldparam [Object] value
55
60
  def each_pair(&_block)
56
- @data.each_pair { |k, v| yield(k, v) }
61
+ @data.each_pair do |key, value|
62
+ validate!(key, value)
63
+ yield(key, value)
64
+ end
57
65
  end
58
66
 
59
67
  private
@@ -64,24 +72,8 @@ module CMDB
64
72
  case value
65
73
  when Hash
66
74
  flatten(value, key, output)
67
- when Array
68
- if value.any? { |e| e.is_a?(Hash) }
69
- # mismatched arrays: not allowed
70
- raise BadValue.new(uri, key, value, 'hashes not allowed inside arrays')
71
- elsif value.all? { |e| e.is_a?(String) } ||
72
- value.all? { |e| e.is_a?(Numeric) } ||
73
- value.all? { |e| e == true } ||
74
- value.all? { |e| e == false }
75
- output[key] = value
76
- else
77
- # mismatched arrays: not allowed
78
- raise BadValue.new(uri, key, value, 'mismatched/unsupported element types')
79
- end
80
- when String, Numeric, TrueClass, FalseClass
81
- output[key] = value
82
75
  else
83
- # nil and anything else: not allowed
84
- raise BadValue.new(uri, key, value)
76
+ output[key] = value
85
77
  end
86
78
  end
87
79
  end
@@ -99,7 +99,7 @@ module CMDB
99
99
  end
100
100
 
101
101
  # Convert dotted notation to slash-separated notation without an initial
102
- # slash. Remove prefix if it is present in the dotted-notation key.
102
+ # slash. Remove prefix if it is present in the dot-notation key.
103
103
  def dot_to_slash(key)
104
104
  pieces = CMDB.split(key)
105
105
  pieces.shift if pieces[0] == @prefix
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module CMDB
3
- VERSION = '3.0.0rc4'.freeze
3
+ VERSION = '3.0.0'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0rc4
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - RightScale
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-25 00:00:00.000000000 Z
11
+ date: 2016-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trollop
@@ -102,9 +102,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
102
  version: '2.1'
103
103
  required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  requirements:
105
- - - ">"
105
+ - - ">="
106
106
  - !ruby/object:Gem::Version
107
- version: 1.3.1
107
+ version: '0'
108
108
  requirements: []
109
109
  rubyforge_project:
110
110
  rubygems_version: 2.4.5.1