bke_chef-rundeck 2.2.2

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.
@@ -0,0 +1,79 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Author:: John Keiser (<jkeiser@opscode.com>)
4
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ require 'chef/config'
21
+ require 'uri'
22
+ # These are needed so that JSON can inflate search results
23
+ require 'chef/node'
24
+ require 'chef/role'
25
+ require 'chef/environment'
26
+ require 'chef/data_bag'
27
+ require 'chef/data_bag_item'
28
+
29
+ class PartialSearch
30
+
31
+ attr_accessor :rest
32
+
33
+ def initialize(url=nil)
34
+ @rest = ::Chef::ServerAPI.new(url || ::Chef::Config[:chef_server_url])
35
+ end
36
+
37
+ # Search Solr for objects of a given type, for a given query. If you give
38
+ # it a block, it will handle the paging for you dynamically.
39
+ def search(type, query='*:*', args={}, &block)
40
+ raise ArgumentError, "Type must be a string or a symbol!" unless (type.kind_of?(String) || type.kind_of?(Symbol))
41
+
42
+ sort = args.include?(:sort) ? args[:sort] : 'X_CHEF_id_CHEF_X asc'
43
+ start = args.include?(:start) ? args[:start] : 0
44
+ rows = args.include?(:rows) ? args[:rows] : 1000
45
+ query_string = "search/#{type}?q=#{escape(query)}&sort=#{escape(sort)}&start=#{escape(start)}&rows=#{escape(rows)}"
46
+ if args[:keys]
47
+ response = @rest.post_rest(query_string, args[:keys])
48
+ response_rows = response['rows'].map { |row| row['data'] }
49
+ else
50
+ response = @rest.get_rest(query_string)
51
+ response_rows = response['rows']
52
+ end
53
+ if block
54
+ response_rows.each { |o| block.call(o) unless o.nil?}
55
+ unless (response["start"] + response_rows.length) >= response["total"]
56
+ nstart = response["start"] + rows
57
+ args_hash = {
58
+ :keys => args[:keys],
59
+ :sort => sort,
60
+ :start => nstart,
61
+ :rows => rows
62
+ }
63
+ search(type, query, args_hash, &block)
64
+ end
65
+ true
66
+ else
67
+ [ response_rows, response["start"], response["total"] ]
68
+ end
69
+ end
70
+
71
+ def list_indexes
72
+ response = @rest.get_rest("search")
73
+ end
74
+
75
+ private
76
+ def escape(s)
77
+ s && URI.escape(s.to_s)
78
+ end
79
+ end
@@ -0,0 +1,110 @@
1
+ require 'spec_helper'
2
+ require 'nokogiri'
3
+
4
+ describe 'ChefRundeck' do
5
+ before do
6
+ # setup for the following tests
7
+ ChefRundeck.config_file = "#{ENV['TRAVIS_BUILD_DIR']}/spec/support/client.rb"
8
+ ChefRundeck.username = ENV['USER']
9
+ ChefRundeck.web_ui_url = 'https://manage.opscode.com'
10
+ ChefRundeck.project_config = "#{ENV['TRAVIS_BUILD_DIR']}/spec/support/chef-rundeck.json"
11
+ ChefRundeck.cache_timeout = 0
12
+ ChefRundeck.environment = :development
13
+ ChefRundeck.configure
14
+ end
15
+ it 'fetch to root should return 200' do
16
+ get '/'
17
+ expect(last_response).to be_ok
18
+ end
19
+ it 'fetched document should be parseable by Nokogiri without errors' do
20
+ get '/'
21
+ expect(Nokogiri::XML(last_response.body).document.errors).to be_empty
22
+ end
23
+ it 'data for node1 should contain tag attribute with Chef node object\'s tag, role, recipes in run list and environment' do
24
+ get '/'
25
+ expect(last_response).to be_ok
26
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node1.chefrundeck.local']/@tags").text()).to include("role1")
27
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node1.chefrundeck.local']/@tags").text()).to include("cookbook::default")
28
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node1.chefrundeck.local']/@tags").text()).to include("tag1")
29
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node1.chefrundeck.local']/@tags").text()).to include("development")
30
+ end
31
+ it 'data for node1 should contain custom role attribute with Chef node object\'s role' do
32
+ get '/'
33
+ expect(last_response).to be_ok
34
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node1.chefrundeck.local']/@roles").text()).to include("role1")
35
+ end
36
+ it 'data for node1 should contain custom recipes attribute with Chef node object\'s run list' do
37
+ get '/'
38
+ expect(last_response).to be_ok
39
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node1.chefrundeck.local']/@recipes").text()).to include("cookbook::default")
40
+ end
41
+ it 'data for node1 should contain custom environment attribute with Chef node object\'s environment' do
42
+ get '/'
43
+ expect(last_response).to be_ok
44
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node1.chefrundeck.local']/@environment").text()).to eq("development")
45
+ end
46
+ it 'data for node1 should contain default ChefRundeck username' do
47
+ get '/'
48
+ expect(last_response).to be_ok
49
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node1.chefrundeck.local']/@username").text()).to eq(ChefRundeck.username)
50
+ end
51
+ it 'fetched document for first test project should be node1 only' do
52
+ get '/node1_systems'
53
+ expect(last_response).to be_ok
54
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node1.chefrundeck.local']").length()).to eq(1)
55
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node2.chefrundeck.local']").length()).to eq(0)
56
+ end
57
+ it 'fetched document should be node1 only verify hostname override' do
58
+ get '/node1_systems'
59
+ expect(last_response).to be_ok
60
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node1.chefrundeck.local']/@hostname").text()).to eq("10.0.0.1")
61
+ end
62
+ it 'fetched document node data should contain custom username' do
63
+ get '/node1_systems'
64
+ expect(last_response).to be_ok
65
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node1.chefrundeck.local']/@username").text()).to eq("rundeck")
66
+ end
67
+ it 'fetched document should be node2 only verify hostname' do
68
+ get '/node2_systems'
69
+ expect(last_response).to be_ok
70
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node2.chefrundeck.local']/@hostname").text()).to eq("node2.chefrundeck.local")
71
+ end
72
+ it 'fetched document should be node2 only' do
73
+ get '/node2_systems'
74
+ expect(last_response).to be_ok
75
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node1.chefrundeck.local']").length()).to eq(0)
76
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node2.chefrundeck.local']").length()).to eq(1)
77
+ end
78
+ it 'check custom attributes on node2 only' do
79
+ get '/node2_systems'
80
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node2.chefrundeck.local']/attribute").length()).to eq(2)
81
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node2.chefrundeck.local']/attribute")[0].text).to eq("linux")
82
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node2.chefrundeck.local']/attribute")[1].text).to eq("centos")
83
+ end
84
+ it 'fetched document node data should use application default' do
85
+ get '/node2_systems'
86
+ expect(last_response).to be_ok
87
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node2.chefrundeck.local']/@username").text()).to eq(ChefRundeck.username)
88
+ end
89
+ context 'when partial search is enabled' do
90
+ before do
91
+ ChefRundeck.partial_search = true
92
+ end
93
+ it 'check partial search' do
94
+ get '/node2_systems'
95
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node2.chefrundeck.local']/attribute").length()).to eq(2)
96
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node2.chefrundeck.local']/attribute")[0].text).to eq("linux")
97
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node2.chefrundeck.local']/attribute")[1].text).to eq("centos")
98
+ end
99
+ it 'fetched document should be node1 only verify hostname override' do
100
+ get '/node1_systems'
101
+ expect(last_response).to be_ok
102
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node1.chefrundeck.local']/@hostname").text).to eq("10.0.0.1")
103
+ end
104
+ it 'fetched document should be node2 only verify hostname' do
105
+ get '/node2_systems'
106
+ expect(last_response).to be_ok
107
+ expect(Nokogiri::XML(last_response.body).xpath("//project/node[@name='node2.chefrundeck.local']/@hostname").text).to eq("node2.chefrundeck.local")
108
+ end
109
+ end
110
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'chef-rundeck'
4
+ require 'sinatra'
5
+ require 'rspec'
6
+ require 'rack/test'
7
+
8
+
9
+ set :environment, :test
10
+ set :run, false
11
+ set :raise_errors, true
12
+ set :logging, false
13
+
14
+ def app
15
+ ChefRundeck.new
16
+ end
17
+
18
+ RSpec.configure do |config|
19
+ config.include Rack::Test::Methods
20
+ end
@@ -0,0 +1,12 @@
1
+ {
2
+ "node1_systems": {
3
+ "pattern": "fqdn:node1*",
4
+ "username": "rundeck",
5
+ "hostname": "ipaddress"
6
+ },
7
+ "node2_systems": {
8
+ "pattern": "fqdn:node2*",
9
+ "hostname": "fqdn",
10
+ "attributes": ["os", "platform"]
11
+ }
12
+ }
@@ -0,0 +1,7 @@
1
+ log_level :debug
2
+ log_location STDOUT
3
+ chef_server_url "https://api.opscode.com/organizations/chef-rundeck"
4
+ web_ui_url "https://manage.opscode.com"
5
+ client_key "#{ENV["TRAVIS_BUILD_DIR"]}" + "/spec/support/travis.pem"
6
+ node_name "travis"
7
+ username "travis"
@@ -0,0 +1,8 @@
1
+ #!/bin/sh
2
+
3
+ # um ... so, obviously, don't run this on a Chef-managed workstation.
4
+ mkdir -p /etc/chef/
5
+ cp spec/support/client.rb /etc/chef/client.rb
6
+ cp spec/support/trav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WAz/9cUPxQSmHWFAxx0lYZEsxAS3gM+Xut4QrnnhYilVXH+vnmn5D/7
17
+ LskYQXz3OyxPTU/jDEwYnZrvQqGu7iuDgDnAK1MKEO5UbJmiG0WrKKWEiR0T6L9Z
18
+ i9akFi8k1u77bxZC66k/7tqLwgn6ZP5rlEbJ118CgYB6iOih5wahfJu1zlfvDyyq
19
+ O9OFx/F5rD/PbahsJzQRIoGFewkkzrvdFa3cIMki2Obp+ehFpOmG/uy1EsXHOv78
20
+ hGhuO1u9sJAneo4sEWQgkdseN+ZtP2snetn6E+a0A0ipImWkloWWL76gZjaYAHN7
21
+ yW1O4nq5uiPj/qAX46owAQKBgCz4bKDvoKhE2RwQy2NUMFSzmwhK2HBFgTHuC2IY
22
+ YunUHRiIu55widmQwQePiXJHtGllShzdQ+LnCDTj8Abn9MJpP3/hjnJWuZ1I066n
23
+ NIk2dJH7nOEl1ppqgsrBF0Dp/VkhWhtQuUHfvmOHmbXKDUhY9FIEJlRwnVwAisBg
24
+ udddAoGAYRZaR2KP6JdCicWYhaBpP8QbVEXo/ZUBaVhzWyK6bqwvcHLs96rG9CNp
25
+ mvy0PVJl+RR39tMKOulpDbmtkREoQkFbPYVPQxFI3WEZUMfrxmUOqH8rPIYYsnGG
26
+ PZjw+7+W0DwD1Gzln2evglRE+45j0PutsNAPrcasAlXxHkuJTZs=
27
+ -----END RSA PRIVATE KEY-----
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bke_chef-rundeck
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.2.2
5
+ platform: ruby
6
+ authors:
7
+ - Shane Blaufuss
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-04-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: chef
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mixlib-cli
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.9
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.2.9
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Provides a resource endpoint for RunDeck from a Chef Server
84
+ email: wsdsysadmin@buckle.com
85
+ executables:
86
+ - bke_chef-rundeck
87
+ extensions: []
88
+ extra_rdoc_files:
89
+ - LICENSE
90
+ - README.md
91
+ files:
92
+ - ".document"
93
+ - ".travis.yml"
94
+ - LICENSE
95
+ - NOTICE
96
+ - README.md
97
+ - Rakefile
98
+ - VERSION
99
+ - bin/bke_chef-rundeck
100
+ - changelog.md
101
+ - chef-rundeck.gemspec
102
+ - gemfiles/Gemfile.chef-10
103
+ - gemfiles/Gemfile.chef-11
104
+ - lib/bke_chef-rundeck.rb
105
+ - lib/partial_search.rb
106
+ - spec/bke_chef-rundeck_spec.rb
107
+ - spec/spec.opts
108
+ - spec/spec_helper.rb
109
+ - spec/support/chef-rundeck.json
110
+ - spec/support/client.rb
111
+ - spec/support/setup-test.sh
112
+ - spec/support/travis.pem
113
+ homepage: https://github.com/buckle/chef-rundeck
114
+ licenses: []
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.7.5
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Integrates Chef with RunDeck
136
+ test_files: []