puppet-http 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9bd4d0b16f3c260e8cdd6169558c17fbefea51df
4
+ data.tar.gz: 388fdcef73102773b2a39e77fbdcdb59ae0b97fd
5
+ SHA512:
6
+ metadata.gz: f439cd956ff2d9645265a3960e434a2546e956d5425e14f65c9cf158471427ae952af100690d5824a89060b2da6b3410f62b716317cb04da5b9b287848212fe7
7
+ data.tar.gz: 0b7b43fae48dc74504bba87517bfe807f0e109a61ec091b3f7da8df78b4a97a9b0df7ecf2f2f098e9151b675a890b973d6bfff3dfb5fb35caad768411b90a5fb
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ .idea
12
+ *.gem
13
+ *.DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ before_install: gem install bundler -v 1.10.5
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in puppet-http.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 DeathKing<deathking0622@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # puppet-http
2
+
3
+ **DO CONSIDER TWICE BEFORE USING IN PRODUCTION ENVIRONMENT!!!**
4
+
5
+ Certificates are never nightmares! This gem allows your Puppet agent talk to master via HTTP easily, thus you won't
6
+ get any trouble in certificate issuing.
7
+
8
+ ## Installation
9
+
10
+ ```
11
+ $ gem install 'puppet-http'
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ As to agent side, just using:
17
+
18
+ ```
19
+ $ puppet http_agent the-rest-option-as-usual
20
+ ```
21
+
22
+ The usage of master side depends on how you boot the master. If you trigger master via commandline, namely, using
23
+ WEBrick mode, just type:
24
+
25
+ ```
26
+ $ puppet http_master the-rest-option-as-usual
27
+ ```
28
+
29
+ If you run your master as a Rack middleware, the steps are as follows:
30
+
31
+ 1. turn off your frond-end web server SSL features!
32
+ 2. edit your `config.ru` file, add a line `require 'puppet/http'` at the very beginning, and also change
33
+ `$0 = "master"` into `$0 = "http_master"`.
34
+
35
+ Here's a modified `config.ru` example:
36
+
37
+ ```ruby
38
+ # a config.ru, for use with every rack-compatible webserver.
39
+ # SSL needs to be handled outside this, though.
40
+
41
+ # if puppet is not in your RUBYLIB:
42
+ # $LOAD_PATH.unshift('/opt/puppet/lib')
43
+
44
+ require 'puppet/http' # <-- add this line
45
+
46
+ $0 = "http_master" # <-- change this line
47
+
48
+ # if you want debugging:
49
+ # ARGV << "--debug"
50
+
51
+ ARGV << "--rack"
52
+
53
+ # Rack applications typically don't start as root. Set --confdir and --vardir
54
+ # to prevent reading configuration from ~puppet/.puppet/puppet.conf and writing
55
+ # to ~puppet/.puppet
56
+ ARGV << "--confdir" << "/etc/puppet"
57
+ ARGV << "--vardir" << "/var/lib/puppet"
58
+
59
+ # NOTE: it's unfortunate that we have to use the "CommandLine" class
60
+ # here to launch the app, but it contains some initialization logic
61
+ # (such as triggering the parsing of the config file) that is very
62
+ # important. We should do something less nasty here when we've
63
+ # gotten our API and settings initialization logic cleaned up.
64
+ #
65
+ # Also note that the "$0 = master" line up near the top here is
66
+ # the magic that allows the CommandLine class to know that it's
67
+ # supposed to be running master.
68
+ #
69
+ # --cprice 2012-05-22
70
+
71
+ require 'puppet/util/command_line'
72
+ # we're usually running inside a Rack::Builder.new {} block,
73
+ # therefore we need to call run *here*.
74
+ run Puppet::Util::CommandLine.new.execute
75
+ ```
76
+
77
+ ## TODO
78
+
79
+ Maybe we need some tests?
80
+
81
+ ## Mechanism
82
+
83
+ Somehow, Puppet will search certain places to find out a what so called `ApplicationSubcommand`. If there's a file
84
+ whose name is `my_app.rb` under the relative path `lib\puppet\application\` to following paths:
85
+
86
+ 1. all the gems' directory
87
+ 2. Puppet modules' directory
88
+ 3. `libdirs`
89
+ 4. the `$LOAD_PATH` of Ruby interpreter
90
+
91
+ In addition, the file `my_app.rb` is supposed to:
92
+
93
+ 1. be a subclass(directly or indirectly) of `Puppet::Application`
94
+ 2. define under the namespace `Puppet::Application`
95
+ 3. have a CamlCase class name
96
+
97
+ For example, the class definition of `my_app.rb` should be:
98
+
99
+ ```ruby
100
+ class Puppet::Application::MyApp < Puppet::Application
101
+
102
+ # Your code goes here
103
+ ```
104
+
105
+ Thus, when you boot puppet using `puppet my_app`, the file will be loaded and executed. We use this way to load
106
+ customize script and perform some dirty monkey patchings to disable the Puppet SSL feature.
107
+
108
+ ## Development && Contributing
109
+
110
+ Feel free to report bugs and send pull request!
111
+
112
+ ## License
113
+
114
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
115
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "puppet/http"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ # a config.ru, for use with every rack-compatible webserver.
2
+ # SSL needs to be handled outside this, though.
3
+
4
+ # if puppet is not in your RUBYLIB:
5
+ # $LOAD_PATH.unshift('/opt/puppet/lib')
6
+
7
+ require 'puppet/http' # <-- this line is newly added
8
+
9
+ $0 = "http_master" # <-- this line has been modified
10
+
11
+ # if you want debugging:
12
+ # ARGV << "--debug"
13
+
14
+ ARGV << "--rack"
15
+
16
+ # Rack applications typically don't start as root. Set --confdir and --vardir
17
+ # to prevent reading configuration from ~puppet/.puppet/puppet.conf and writing
18
+ # to ~puppet/.puppet
19
+ ARGV << "--confdir" << "/etc/puppet"
20
+ ARGV << "--vardir" << "/var/lib/puppet"
21
+
22
+ # NOTE: it's unfortunate that we have to use the "CommandLine" class
23
+ # here to launch the app, but it contains some initialization logic
24
+ # (such as triggering the parsing of the config file) that is very
25
+ # important. We should do something less nasty here when we've
26
+ # gotten our API and settings initialization logic cleaned up.
27
+ #
28
+ # Also note that the "$0 = master" line up near the top here is
29
+ # the magic that allows the CommandLine class to know that it's
30
+ # supposed to be running master.
31
+ #
32
+ # --cprice 2012-05-22
33
+
34
+ require 'puppet/util/command_line'
35
+ # we're usually running inside a Rack::Builder.new {} block,
36
+ # therefore we need to call run *here*.
37
+ run Puppet::Util::CommandLine.new.execute
38
+
@@ -0,0 +1,15 @@
1
+ require 'puppet/application/agent'
2
+ require 'puppet/patch'
3
+
4
+ class Puppet::Application::HttpAgent < Puppet::Application::Agent
5
+
6
+ def wait_for_certificates
7
+ # Logging is necessary to make user aware of they are currently using an unsafe transmission.
8
+ Puppet.debug "Puppet HTTPAgent won't fetch certificate."
9
+ end
10
+
11
+ def fingerprint
12
+ raise RuntimeError, "HTTPAgent has no fingerprint."
13
+ end
14
+
15
+ end
@@ -0,0 +1,35 @@
1
+ require 'puppet/patch'
2
+ require 'puppet/application/master'
3
+
4
+ class Puppet::Application::HttpMaster < Puppet::Application::Master
5
+
6
+ def setup_ssl
7
+ # Logging is necessary to make user aware of they are currently using an unsafe transmission.
8
+ Puppet.debug "Puppet HTTPMaster won't setup SSL environment."
9
+ end
10
+
11
+ def main
12
+ require 'etc'
13
+
14
+ if Puppet.features.root?
15
+ begin
16
+ Puppet::Util.chuser
17
+ rescue => detail
18
+ Puppet.log_exception(detail, "Could not change user to #{Puppet[:user]}: #{detail}")
19
+ exit(39)
20
+ end
21
+ end
22
+
23
+ if options[:rack]
24
+ start_rack_master
25
+ else
26
+ start_webrick_master
27
+ end
28
+ end
29
+
30
+ def start_webrick_master
31
+ require 'puppet/patch/webrick'
32
+ super
33
+ end
34
+
35
+ end
@@ -0,0 +1,9 @@
1
+ # Here's the situation: Puppet will search all the gems directory to find a validate
2
+ # *ApplicationSubcommand*. But some how, rack use Bundler to load the gem. In this
3
+ # situation, the Puppet autoloader won't search bundler directory to get the file we
4
+ # want. So we have to inject our gem directory to $LOAD_PATH so that enables
5
+ # *http_master*. Maybe we have a better way to do that, right? -- DeathKing 2015-09-08
6
+
7
+ if defined? ::Bundler
8
+ $LOAD_PATH.unshift(File.expand_path(__FILE__) + "../")
9
+ end
@@ -0,0 +1,5 @@
1
+ module Puppet
2
+ module Http
3
+ VERSION = "0.1.3"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require 'puppet/patch/http_pool'
@@ -0,0 +1,12 @@
1
+ require 'puppet/network/http/connection'
2
+
3
+ module Puppet::Network::HTTP
4
+ class HttpConnection < Connection
5
+
6
+ def initialize(host, port, options = {})
7
+ verify = Puppet::SSL::Validator.no_validator
8
+ super host, port, options.merge(:use_ssl => false, :verify => verify)
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ require 'puppet/network/http_pool'
2
+ require 'puppet/patch/http_connection'
3
+
4
+ module Puppet::Network::HttpPool
5
+
6
+ # Ya, this is a magic trick yet to be dangerous. Be very careful because this might infect
7
+ # both self.http_instance and self.http_ssl_instance. After execute this code, that two
8
+ # methods both return a HTTP connection in any condition.
9
+ @http_client_class = Puppet::Network::HTTP::HttpConnection
10
+
11
+ end
@@ -0,0 +1,39 @@
1
+ require 'puppet/network/http/webrick'
2
+
3
+ class Puppet::Network::HTTP::WEBrick
4
+
5
+ def listen(address, port)
6
+ @server = create_server(address, port)
7
+
8
+ # @server.listeners.each { |l| l.start_immediately = false }
9
+
10
+ @server.mount('/', Puppet::Network::HTTP::WEBrickREST)
11
+
12
+ raise "WEBrick server is already listening" if @listening
13
+ @listening = true
14
+ @thread = Thread.new do
15
+ @server.start do |sock|
16
+ timeout = 10.0
17
+ if ! IO.select([sock],nil,nil,timeout)
18
+ raise "Client did not send data within %.1f seconds of connecting" % timeout
19
+ end
20
+ # sock.accept
21
+ @server.run(sock)
22
+ end
23
+ end
24
+ sleep 0.1 until @server.status == :Running
25
+ end
26
+
27
+ def create_server(address, port)
28
+ arguments = {:BindAddress => address, :Port => port, :DoNotReverseLookup => true}
29
+ arguments.merge!(setup_logger)
30
+ # arguments.merge!(setup_ssl)
31
+
32
+ BasicSocket.do_not_reverse_lookup = true
33
+
34
+ server = WEBrick::HTTPServer.new(arguments)
35
+ # server.ssl_context.ciphers = CIPHERS
36
+ server
37
+ end
38
+
39
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'puppet/http/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "puppet-http"
8
+ spec.version = Puppet::Http::VERSION
9
+ spec.authors = ["DeathKing"]
10
+ spec.email = ["deathking0622@gmail.com"]
11
+
12
+ spec.summary = %q{Enable Puppet master/agent communicate via HTTP.}
13
+ spec.description = %q{Enable Puppet master/agent communicate via HTTP.}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+
25
+ # We have to carefully deal with puppet dependency, because it seems that Gem couldn't recognize
26
+ # Puppet installed via install.rb script which will cause a gem install then. For now, we just assume
27
+ # user have already installed Puppet. -- DeathKing 2015-09-06
28
+
29
+ # spec.add_runtime_dependency "puppet"
30
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppet-http
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - DeathKing
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Enable Puppet master/agent communicate via HTTP.
42
+ email:
43
+ - deathking0622@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - CODE_OF_CONDUCT.md
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/setup
57
+ - ext/rack/config.ru
58
+ - lib/puppet/application/http_agent.rb
59
+ - lib/puppet/application/http_master.rb
60
+ - lib/puppet/http.rb
61
+ - lib/puppet/http/version.rb
62
+ - lib/puppet/patch.rb
63
+ - lib/puppet/patch/http_connection.rb
64
+ - lib/puppet/patch/http_pool.rb
65
+ - lib/puppet/patch/webrick.rb
66
+ - puppet-http.gemspec
67
+ homepage: ''
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.4.6
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Enable Puppet master/agent communicate via HTTP.
91
+ test_files: []