bolt 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bolt might be problematic. Click here for more details.

Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/exe/bolt +1 -1
  3. data/lib/bolt.rb +0 -3
  4. data/lib/bolt/cli.rb +66 -32
  5. data/lib/bolt/config.rb +19 -0
  6. data/lib/bolt/executor.rb +21 -16
  7. data/lib/bolt/node.rb +13 -10
  8. data/lib/bolt/node/errors.rb +22 -0
  9. data/lib/bolt/node/ssh.rb +25 -2
  10. data/lib/bolt/node/winrm.rb +14 -2
  11. data/lib/bolt/node_uri.rb +15 -14
  12. data/lib/bolt/result.rb +22 -0
  13. data/lib/bolt/version.rb +1 -1
  14. data/vendored/puppet/lib/puppet/application/script.rb +7 -1
  15. data/vendored/puppet/lib/puppet/configurer.rb +1 -1
  16. data/vendored/puppet/lib/puppet/defaults.rb +18 -1
  17. data/vendored/puppet/lib/puppet/functions/run_command.rb +5 -2
  18. data/vendored/puppet/lib/puppet/functions/run_script.rb +5 -2
  19. data/vendored/puppet/lib/puppet/functions/run_task.rb +7 -2
  20. data/vendored/puppet/lib/puppet/gettext/config.rb +47 -26
  21. data/vendored/puppet/lib/puppet/graph/relationship_graph.rb +6 -0
  22. data/vendored/puppet/lib/puppet/indirector/node/ldap.rb +19 -3
  23. data/vendored/puppet/lib/puppet/module.rb +8 -7
  24. data/vendored/puppet/lib/puppet/network/http/webrick.rb +1 -0
  25. data/vendored/puppet/lib/puppet/pops/loader/loader_paths.rb +9 -0
  26. data/vendored/puppet/lib/puppet/pops/loader/module_loaders.rb +8 -0
  27. data/vendored/puppet/lib/puppet/pops/types/p_error_type.rb +12 -0
  28. data/vendored/puppet/lib/puppet/pops/types/p_object_type.rb +9 -3
  29. data/vendored/puppet/lib/puppet/pops/types/ruby_generator.rb +65 -24
  30. data/vendored/puppet/lib/puppet/provider/mount.rb +25 -8
  31. data/vendored/puppet/lib/puppet/provider/package/dnf.rb +1 -1
  32. data/vendored/puppet/lib/puppet/provider/package/gem.rb +1 -1
  33. data/vendored/puppet/lib/puppet/provider/package/pkg.rb +3 -0
  34. data/vendored/puppet/lib/puppet/provider/service/launchd.rb +1 -1
  35. data/vendored/puppet/lib/puppet/provider/zfs/zfs.rb +20 -1
  36. data/vendored/puppet/lib/puppet/type/mount.rb +6 -2
  37. data/vendored/puppet/lib/puppet/type/yumrepo.rb +9 -0
  38. data/vendored/puppet/lib/puppet/version.rb +1 -1
  39. data/vendored/puppet/lib/puppet_pal.rb +33 -7
  40. metadata +45 -83
  41. data/.gitignore +0 -33
  42. data/.gitmodules +0 -12
  43. data/.rspec +0 -2
  44. data/.rubocop.yml +0 -61
  45. data/.travis.yml +0 -18
  46. data/CODE_OF_CONDUCT.md +0 -46
  47. data/CONTRIBUTING.md +0 -27
  48. data/Gemfile +0 -9
  49. data/INSTALL.md +0 -70
  50. data/LICENSE +0 -201
  51. data/README.md +0 -353
  52. data/Rakefile +0 -27
  53. data/Vagrantfile +0 -13
  54. data/appveyor.yml +0 -29
  55. data/bolt.gemspec +0 -50
  56. data/docs/writing_tasks_and_plans.pdf +0 -0
  57. data/metadata.json +0 -13
  58. data/tasks/init.json +0 -3
  59. data/tasks/init.rb +0 -44
  60. data/ux/bolt-CLI-spec.md +0 -186
  61. data/vendored/puppet/lib/puppet/external/nagios/grammar.ry +0 -248
  62. data/vendored/puppet/lib/puppet/external/nagios/makefile +0 -9
  63. data/vendored/puppet/lib/puppet/face/help/action.erb +0 -86
  64. data/vendored/puppet/lib/puppet/face/help/face.erb +0 -114
  65. data/vendored/puppet/lib/puppet/face/help/global.erb +0 -16
  66. data/vendored/puppet/lib/puppet/face/help/man.erb +0 -152
  67. data/vendored/puppet/lib/puppet/generate/templates/type/pcore.erb +0 -42
  68. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/.fixtures.yml.erb +0 -7
  69. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/.gitignore +0 -18
  70. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/.rubocop.yml +0 -42
  71. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/.yardopts +0 -1
  72. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/Gemfile +0 -18
  73. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/README.md.erb +0 -89
  74. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/Rakefile +0 -32
  75. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/examples/init.pp.erb +0 -12
  76. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/manifests/init.pp.erb +0 -48
  77. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/metadata.json.erb +0 -1
  78. data/vendored/puppet/lib/puppet/module_tool/skeleton/templates/generator/spec/classes/init_spec.rb.erb +0 -6
  79. data/vendored/puppet/lib/puppet/pops/model/ast.pp +0 -695
  80. data/vendored/puppet/lib/puppet/pops/parser/egrammar.ra +0 -937
  81. data/vendored/puppet/lib/puppet/pops/resource/resource_type_set.pcore +0 -22
  82. data/vendored/puppet/lib/puppet/util/libuser.conf +0 -15
  83. data/vendored/puppet/lib/puppet/vendor/deep_merge/CHANGELOG +0 -45
  84. data/vendored/puppet/lib/puppet/vendor/deep_merge/Gemfile +0 -3
  85. data/vendored/puppet/lib/puppet/vendor/deep_merge/LICENSE +0 -21
  86. data/vendored/puppet/lib/puppet/vendor/deep_merge/PUPPET_README.md +0 -6
  87. data/vendored/puppet/lib/puppet/vendor/deep_merge/README.md +0 -113
  88. data/vendored/puppet/lib/puppet/vendor/deep_merge/Rakefile +0 -19
  89. data/vendored/puppet/lib/puppet/vendor/deep_merge/deep_merge.gemspec +0 -35
  90. data/vendored/puppet/lib/puppet/vendor/pathspec/CHANGELOG.md +0 -2
  91. data/vendored/puppet/lib/puppet/vendor/pathspec/LICENSE +0 -201
  92. data/vendored/puppet/lib/puppet/vendor/pathspec/PUPPET_README.md +0 -6
  93. data/vendored/puppet/lib/puppet/vendor/pathspec/README.md +0 -53
  94. data/vendored/puppet/lib/puppet/vendor/semantic_puppet/locales/config.yaml +0 -21
data/Rakefile DELETED
@@ -1,27 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
- require "rubocop/rake_task"
4
-
5
- desc "Run all RSpec tests"
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- desc "Run RSpec tests that don't require VM fixtures"
9
- RSpec::Core::RakeTask.new(:unit) do |t|
10
- t.rspec_opts = '--tag ~vagrant'
11
- end
12
-
13
- desc "Run RSpec tests that don't require VM fixtures or orchestrator"
14
- RSpec::Core::RakeTask.new(:windows) do |t|
15
- t.rspec_opts = '--tag ~vagrant --tag ~orchestrator'
16
- end
17
-
18
- RuboCop::RakeTask.new(:rubocop) do |t|
19
- t.options = ['--display-cop-names', '--display-style-guide']
20
- end
21
-
22
- desc "Run tests and style checker"
23
- task test: %w[spec rubocop]
24
-
25
- task :default do
26
- system "rake --tasks"
27
- end
@@ -1,13 +0,0 @@
1
- Vagrant.configure("2") do |config|
2
- config.vm.define :windows do |windows|
3
- windows.vm.box = "mwrock/WindowsNano"
4
- windows.vm.network :forwarded_port, guest: 22, host: 2222, id: "ssh"
5
- windows.vm.guest = :windows
6
- windows.vm.communicator = "winrm"
7
- end
8
-
9
- config.vm.define :linux do |linux|
10
- linux.vm.box = "bento/centos-6.7"
11
- linux.vm.network :forwarded_port, guest: 22, host: 2224, id: "ssh"
12
- end
13
- end
@@ -1,29 +0,0 @@
1
- # See https://www.appveyor.com/docs/lang/ruby/
2
- version: 0.1.0.{build}-{branch}
3
- cache:
4
- - .bundle
5
-
6
- matrix:
7
- fast_finish: true
8
-
9
- environment:
10
- matrix:
11
- - RUBY_VERSION: 200
12
- - RUBY_VERSION: 24
13
-
14
- install:
15
- - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH%
16
- - git submodule update --init --recursive
17
- - bundle config --local path .bundle
18
- - bundle install --jobs 3 --retry 3
19
-
20
- build: off
21
-
22
- before_test:
23
- - ruby -v
24
- - gem -v
25
- - bundle -v
26
- - type Gemfile.lock
27
-
28
- test_script:
29
- - bundle exec rake windows
@@ -1,50 +0,0 @@
1
- lib = File.expand_path('../lib', __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
-
4
- require 'bolt/version'
5
-
6
- # --recurse-submodules only available in newer git
7
- output = `git submodule -q foreach 'git ls-files lib | sed "s|^|$path/|"'`
8
- vendored_files = output.split
9
- bolt_files = `git ls-files -z`.split("\x0").reject do |f|
10
- f.match(%r{^(test|spec|features)/})
11
- end
12
-
13
- Gem::Specification.new do |spec|
14
- spec.name = "bolt"
15
- spec.version = Bolt::VERSION
16
- spec.authors = ["Puppet"]
17
- spec.email = ["puppet@puppet.com"]
18
-
19
- spec.summary = "Execute commands remotely over SSH and WinRM"
20
- spec.description = "Execute commands remotely over SSH and WinRM"
21
- spec.homepage = "https://github.com/puppetlabs/bolt"
22
- spec.license = "Apache-2.0"
23
- spec.files = bolt_files + vendored_files
24
- spec.bindir = "exe"
25
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
- spec.require_paths = ["lib"]
27
-
28
- spec.required_ruby_version = "~> 2.0"
29
-
30
- spec.add_dependency "net-ssh", "~> 4.0"
31
- spec.add_dependency "net-sftp", "~> 2.0"
32
- spec.add_dependency "winrm", "~> 2.0"
33
- spec.add_dependency "winrm-fs", "~> 1.0"
34
- spec.add_dependency "concurrent-ruby", "~> 1.0"
35
- spec.add_dependency "orchestrator_client", "~> 0.2.1"
36
-
37
- # Dependencies of our vendored puppet, etc
38
- spec.add_dependency "gettext-setup", "< 1", ">= 0.10"
39
- spec.add_dependency "locale", "~> 2.1"
40
- spec.add_dependency "minitar", "~> 0.6.1"
41
- spec.add_dependency "win32-dir", "= 0.4.9"
42
- spec.add_dependency "win32-process", "= 0.7.5"
43
- spec.add_dependency "win32-security", "= 0.2.5"
44
- spec.add_dependency "win32-service", "= 0.8.8"
45
- spec.add_dependency "CFPropertyList", "~> 2.2"
46
-
47
- spec.add_development_dependency "bundler", "~> 1.14"
48
- spec.add_development_dependency "rake", "~> 10.0"
49
- spec.add_development_dependency "rspec", "~> 3.0"
50
- end
@@ -1,13 +0,0 @@
1
- {
2
- "name": "puppetlabs-bolt",
3
- "version": "0.1.0",
4
- "author": "puppetlabs",
5
- "summary": "bolt ",
6
- "license": "Apache-2.0",
7
- "source": "https://github.com/puppetlabs/bolt",
8
- "project_page": "https://github.com/puppetlabs/bolt",
9
- "issues_url": "https://tickets.puppetlabs.com/browse/BOLT/",
10
- "dependencies": [],
11
- "data_provider": null
12
- }
13
-
@@ -1,3 +0,0 @@
1
- {
2
- "description": "This task serves a bridge between bolt and orchestrator and is not intended to be run directly"
3
- }
@@ -1,44 +0,0 @@
1
- #!/opt/puppetlabs/puppet/bin/ruby
2
-
3
- require 'base64'
4
- require 'json'
5
- require 'open3'
6
- require 'tempfile'
7
-
8
- def write_file(path, content, mode)
9
- source = Base64.decode64(content)
10
- File.open(path, 'w') do |f|
11
- f.chmod(mode)
12
- f.write(source)
13
- end
14
- { success: true }
15
- end
16
-
17
- def command(command)
18
- stdout, stderr, p = Open3.capture3(command)
19
- { stdout: stdout,
20
- stderr: stderr,
21
- exit_code: p.exitstatus }
22
- end
23
-
24
- def script(content)
25
- tf = Tempfile.new('bolt_script')
26
- source = Base64.decode64(content)
27
- tf.chmod(0o700)
28
- tf.write(source)
29
- tf.close
30
- command(tf.path)
31
- end
32
-
33
- params = JSON.parse(STDIN.read)
34
-
35
- result = case params['action']
36
- when 'command'
37
- command(params['command'])
38
- when 'upload'
39
- write_file(params['path'], params['content'], params['mode'])
40
- when 'script'
41
- script(params['content'])
42
- end
43
-
44
- puts result.to_json
@@ -1,186 +0,0 @@
1
- ## bolt
2
-
3
- ### NAME
4
- `$ bolt` - Runs ad-hoc tasks on your nodes via ssh or winrm.
5
-
6
- ### SYNOPSIS
7
- ~~~
8
- $ bolt task run <task-name> [<parameter>=<value> ...] [<target-pattern>] [--help, -h] [--format, -f <output-format>]
9
- $ bolt plan run <plan-file>
10
- $ bolt command run '<command>'
11
- $ bolt script run '<path>'
12
- $ bolt file upload
13
- $ bolt file download
14
- ~~~
15
-
16
- ##### Compare to PE CLI
17
- ~~~
18
- $ puppet task run <task-name> [<parameter>=<value> ...]
19
- $ puppet task run exec command='<command>'
20
- ~~~
21
-
22
-
23
- ### DESCRIPTION
24
- `$ bolt` runs ad-hoc tasks, commands and scripts on your nodes via ssh or winrm. Use a plan to run multiple tasks in a particular order.
25
-
26
- ### GLOBAL OPTIONS
27
-
28
- Option | Description
29
- ----------------------------- | --------------------------
30
- --help <br>-h | Show help page for bolt or for a specific task with <task-name>
31
- --format <br>-f | Specify an output format. <br>Options: <br>`human`(default): interleaves stdout output from multiple nodes <br>`oneline`:provides one line summary for each node <br>`json`:
32
- --outputdir | Specify a directory to save output logs (1 file per node).
33
- --shell | 'cmd' or 'powershell' when using winrm.
34
-
35
- ### SELECT A TARGET
36
-
37
- Option | Description
38
- ----------------------------- | --------------------------
39
- --nodes <br>-n | Enter a list of nodes to run the task on. (Comma-separated. No quotes.) <br> `@<file-name>` Or provide a file with one nodename per line.
40
-
41
- ### TASK OPTIONS
42
-
43
- Option | Description
44
- ----------------------------- | --------------------------
45
- --params <br>-p | Enter a string containing JSON parameters <br> `@<file-name>` Or provide a file with JSON parameters.
46
-
47
-
48
- ### OUTPUT
49
-
50
-
51
-
52
- **View output per node while task/command/script is running on single or multiple nodes.**
53
-
54
- **--human format (default)**
55
-
56
- ~~~
57
- $ bolt [task/command/script] run [options...]
58
- Starting [task/command/script]...
59
- Nodes: 3
60
-
61
- Started on node-1...
62
- Started on node-2...
63
- Started on node-3...
64
- Finished on node-1
65
- status: [succeeded/failed/<task-specific staus>]
66
- STDOUT:
67
- [stdout output...]
68
- STDERR:
69
- [stderr output...]
70
- Finished on node-2
71
- status: [succeeded/failed/<task-specific staus>]
72
- STDOUT:
73
- [stdout output...]
74
- STDERR:
75
- [stderr output...]
76
- Finished on node-3
77
- status: [succeeded/failed/<task-specific staus>]
78
- STDOUT:
79
- [stdout output...]
80
- STDERR:
81
- [stderr output...]
82
-
83
-
84
- [Task/Command/Script] completed. 3/3 nodes succeeded.
85
- Duration: 27 sec
86
- ~~~
87
-
88
- - colors should match puppet job run output for started, finished, and errors.
89
- - For tasks, capitalization of the finished node results comes from module (eg. status vs. Status).
90
- - status will be succeeded or failed for command and scripts; task status may be something else specified by task.
91
- - STDOUT or STDERR labels will be printed only if the outout from that stream is non-empty.
92
-
93
-
94
-
95
- **View output per node while task/command/script is running on single or multiple nodes.**
96
-
97
- **--oneline format**
98
-
99
- - stdout, stderr and messages from bolt are interleaved as they are output
100
- - every line is prefixed with node name, timestamp, and `err`, `out`, or `msg` accordingly.
101
- - nodename, timestamp and output type are space separated.
102
- - timestamp format is HH:MM:SS
103
-
104
- ~~~
105
- $ bolt [task/command/script] run [options...]
106
- Starting [task/command/script]...
107
- Nodes: 3
108
-
109
- node-1 HH:MM:SS msg started
110
- node-1 HH:MM:SS err [stderr output]
111
- node-1 HH:MM:SS out [stdout output]
112
- node-2 HH:MM:SS msg started
113
- node-3 HH:MM:SS msg started
114
- node-2 HH:MM:SS out [stdout output]
115
- node-1 HH:MM:SS msg finished, succeeded
116
- node-3 HH:MM:SS out [stdout output]
117
- node-3 HH:MM:SS msg finished, failed
118
- node-2 HH:MM:SS msg finished, succeeded
119
-
120
-
121
- [Task/Command/Script] completed. 2/3 nodes succeeded.
122
- Duration: [duration]
123
- ~~~
124
-
125
-
126
-
127
- **View the response for each node when the node has finished (unstructured STDOUT):**
128
- ~~~
129
- ...
130
-
131
- Finished on covfefe-2
132
- Status: completed
133
- Loaded plugins: fastestmirror
134
- Loading mirror speeds from cached hostfile
135
- * base: mirror.web-ster.com
136
- * extras: centos-distro.1gservers.com
137
- * updates: mirror.hmc.edu
138
- Resolving Dependencies
139
- --> Running transaction check
140
- ---> Package openssl.x86_64 1:1.0.1e-60.el7 will be a downgrade
141
- ---> Package openssl.x86_64 1:1.0.1e-60.el7_3.1 will be erased
142
- ---> Package openssl-libs.x86_64 1:1.0.1e-60.el7 will be a downgrade
143
- ---> Package openssl-libs.x86_64 1:1.0.1e-60.el7_3.1 will be erased
144
- --> Finished Dependency Resolution
145
-
146
- Dependencies Resolved
147
-
148
- ================================================================================
149
- Package Arch Version Repository Size
150
- ================================================================================
151
- Downgrading:
152
- openssl x86_64 1:1.0.1e-60.el7 base 713 k
153
- openssl-libs x86_64 1:1.0.1e-60.el7 base 958 k
154
-
155
- Transaction Summary
156
- ================================================================================
157
- Downgrade 2 Packages
158
-
159
- Total download size: 1.6 M
160
- Downloading packages:
161
- --------------------------------------------------------------------------------
162
- Total 6.0 MB/s | 1.6 MB 00:00
163
- Running transaction check
164
- Running transaction test
165
- Transaction test succeeded
166
- Running transaction
167
- Installing : 1:openssl-libs-1.0.1e-60.el7.x86_64 1/4
168
- Installing : 1:openssl-1.0.1e-60.el7.x86_64 2/4
169
- Cleanup : 1:openssl-1.0.1e-60.el7_3.1.x86_64 3/4
170
- Cleanup : 1:openssl-libs-1.0.1e-60.el7_3.1.x86_64 4/4
171
- Verifying : 1:openssl-libs-1.0.1e-60.el7.x86_64 1/4
172
- Verifying : 1:openssl-1.0.1e-60.el7.x86_64 2/4
173
- Verifying : 1:openssl-1.0.1e-60.el7_3.1.x86_64 3/4
174
- Verifying : 1:openssl-libs-1.0.1e-60.el7_3.1.x86_64 4/4
175
-
176
- Removed:
177
- openssl.x86_64 1:1.0.1e-60.el7_3.1 openssl-libs.x86_64 1:1.0.1e-60.el7_3.1
178
-
179
- list:
180
- openssl.x86_64 1:1.0.1e-60.el7 openssl-libs.x86_64 1:1.0.1e-60.el7
181
-
182
- Complete!
183
- ~~~
184
-
185
- **View output per node while task plan is running.**
186
- - TBD
@@ -1,248 +0,0 @@
1
- # vim: syntax=ruby
2
- class Nagios::Parser
3
-
4
- token DEFINE NAME PARAM LCURLY RCURLY VALUE RETURN
5
-
6
- rule
7
- decls: decl { return val[0] if val[0] }
8
- | decls decl {
9
- if val[1].nil?
10
- result = val[0]
11
- else
12
- if val[0].nil?
13
- result = val[1]
14
- else
15
- result = [ val[0], val[1] ].flatten
16
- end
17
- end
18
- }
19
- ;
20
-
21
- decl: object { result = [val[0]] }
22
- | RETURN { result = nil }
23
- ;
24
-
25
- object: DEFINE NAME LCURLY returns vars RCURLY {
26
- result = Nagios::Base.create(val[1],val[4])
27
- }
28
- ;
29
-
30
- vars: var
31
- | vars var {
32
- val[1].each {|p,v|
33
- val[0][p] = v
34
- }
35
- result = val[0]
36
- }
37
- ;
38
-
39
- var: PARAM VALUE returns { result = {val[0] => val[1]} }
40
- | PARAM returns { result = {val[0] => "" } }
41
- ;
42
-
43
- returns: RETURN
44
- | RETURN returns
45
- ;
46
-
47
- end
48
-
49
- ----inner
50
- require 'strscan'
51
-
52
- class ::Nagios::Parser::SyntaxError < RuntimeError; end
53
-
54
- def parse(src)
55
- if src.respond_to?("force_encoding") then
56
- src.force_encoding("ASCII-8BIT")
57
- end
58
- @ss = StringScanner.new(src)
59
-
60
- # state variables
61
- @in_parameter_value = false
62
- @in_object_definition = false
63
- @done = false
64
-
65
- @line = 1
66
- @yydebug = true
67
-
68
- do_parse
69
- end
70
-
71
- # This tokenizes the outside of object definitions,
72
- # and detects when we start defining an object.
73
- # We ignore whitespaces, comments and inline comments.
74
- # We yield when finding newlines, the "define" keyword,
75
- # the object name and the opening curly bracket.
76
- def tokenize_outside_definitions
77
- case
78
- when (chars = @ss.skip(/[ \t]+/)) # ignore whitespace /\s+/
79
- ;
80
-
81
- when (text = @ss.scan(/\#.*$/)) # ignore comments
82
- ;
83
-
84
- when (text = @ss.scan(/;.*$/)) # ignore inline comments
85
- ;
86
-
87
- when (text = @ss.scan(/\n/)) # newline
88
- [:RETURN, text]
89
-
90
- when (text = @ss.scan(/\b(define)\b/)) # the "define" keyword
91
- [:DEFINE, text]
92
-
93
- when (text = @ss.scan(/[^{ \t\n]+/)) # the name of the object being defined (everything not an opening curly bracket or a separator)
94
- [:NAME, text]
95
-
96
- when (text = @ss.scan(/\{/)) # the opening curly bracket - we enter object definition
97
- @in_object_definition = true
98
- [:LCURLY, text]
99
-
100
- else
101
- text = @ss.string[@ss.pos .. -1]
102
- raise ScanError, "can not match: '#{text}'"
103
- end # case
104
- end
105
-
106
- # This tokenizes until we find the parameter name.
107
- def tokenize_parameter_name
108
- case
109
- when (chars = @ss.skip(/[ \t]+/)) # ignore whitespace /\s+/
110
- ;
111
-
112
- when (text = @ss.scan(/\#.*$/)) # ignore comments
113
- ;
114
-
115
- when (text = @ss.scan(/;.*$/)) # ignore inline comments
116
- ;
117
-
118
- when (text = @ss.scan(/\n/)) # newline
119
- [:RETURN, text]
120
-
121
- when (text = @ss.scan(/\}/)) # closing curly bracket : end of definition
122
- @in_object_definition = false
123
- [:RCURLY, text]
124
-
125
- when (not @in_parameter_value and (text = @ss.scan(/\S+/))) # This is the name of the parameter
126
- @in_parameter_value = true
127
- [:PARAM, text]
128
-
129
- else
130
- text = @ss.string[@ss.pos .. -1]
131
- raise ScanError, "can not match: '#{text}'"
132
- end # case
133
- end
134
-
135
- # This tokenizes the parameter value.
136
- # There is a special handling for lines containing semicolons :
137
- # - unescaped semicolons are line comments (and should stop parsing of the line)
138
- # - escaped (with backslash \) semicolons should be kept in the parameter value (without the backslash)
139
- def tokenize_parameter_value
140
- case
141
- when (chars = @ss.skip(/[ \t]+/)) # ignore whitespace /\s+/
142
- ;
143
-
144
- when (text = @ss.scan(/\#.*$/)) # ignore comments
145
- ;
146
-
147
- when (text = @ss.scan(/\n/)) # newline
148
- @in_parameter_value = false
149
- [:RETURN, text]
150
-
151
- when (text = @ss.scan(/.+$/)) # Value of parameter
152
- @in_parameter_value = false
153
-
154
- # Special handling of inline comments (;) and escaped semicolons (\;)
155
-
156
- # We split the string on escaped semicolons (\;),
157
- # Then we rebuild it as long as there are no inline comments (;)
158
- # We join the rebuilt string with unescaped semicolons (on purpose)
159
- array = text.split('\;', 0)
160
-
161
- text = ""
162
-
163
- array.each do |elt|
164
-
165
- # Now we split at inline comments. If we have more than 1 element in the array
166
- # it means we have an inline comment, so we are able to stop parsing
167
- # However we still want to reconstruct the string with its first part (before the comment)
168
- linearray = elt.split(';', 0)
169
-
170
- # Let's reconstruct the string with a (unescaped) semicolon
171
- if text != "" then
172
- text += ';'
173
- end
174
- text += linearray[0]
175
-
176
- # Now we can stop
177
- if linearray.length > 1 then
178
- break
179
- end
180
- end
181
-
182
-
183
- # We strip the text to remove spaces between end of string and beginning of inline comment
184
- [:VALUE, text.strip]
185
-
186
- else
187
- text = @ss.string[@ss.pos .. -1]
188
- raise ScanError, "can not match: '#{text}'"
189
- end # case
190
- end
191
-
192
- # This tokenizes inside an object definition.
193
- # Two cases : parameter name and parameter value
194
- def tokenize_inside_definitions
195
- if @in_parameter_value
196
- tokenize_parameter_value
197
- else
198
- tokenize_parameter_name
199
- end
200
- end
201
-
202
- # The lexer. Very simple.
203
- def token
204
- text = @ss.peek(1)
205
- @line += 1 if text == "\n"
206
-
207
- token = if @in_object_definition
208
- tokenize_inside_definitions
209
- else
210
- tokenize_outside_definitions
211
- end
212
- token
213
- end
214
-
215
- def next_token
216
- return if @ss.eos?
217
-
218
- # skips empty actions
219
- until _next_token = token or @ss.eos?; end
220
- _next_token
221
- end
222
-
223
- def yydebug
224
- 1
225
- end
226
-
227
- def yywrap
228
- 0
229
- end
230
-
231
- def on_error(token, value, vstack )
232
- # text = @ss.string[@ss.pos .. -1]
233
- text = @ss.peek(20)
234
- msg = ""
235
- unless value.nil?
236
- msg = "line #{@line}: syntax error at value '#{value}' : #{text}"
237
- else
238
- msg = "line #{@line}: syntax error at token '#{token}' : #{text}"
239
- end
240
- if @ss.eos?
241
- msg = "line #{@line}: Unexpected end of file"
242
- end
243
- if token == '$end'.intern
244
- puts "okay, this is silly"
245
- else
246
- raise ::Nagios::Parser::SyntaxError, msg
247
- end
248
- end