caged_chef 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in caged_chef.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Brandon Dennis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # CagedChef
2
+
3
+ CagedChef is a middleware for Faraday.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'caged_chef'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install caged_chef
18
+
19
+ ## Usage
20
+
21
+ ````ruby
22
+ url = 'https://example.chef.com'
23
+
24
+ chef_auth_options = {
25
+ key: '/path/to/client/private/key',
26
+ host: url,
27
+ user_id: 'your-chef-user-id'
28
+ }
29
+
30
+ faraday = Faraday.new(url: url) do |faraday|
31
+ faraday.request :chef_auth, chef_auth_options
32
+ # other faraday settings
33
+ end
34
+
35
+ response = faraday.run_request('http_method', "#{url}/some/path", "body", {})
36
+ ````
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'caged_chef/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "caged_chef"
8
+ gem.version = CagedChef::VERSION
9
+ gem.authors = ["Brandon Dennis"]
10
+ gem.email = ["toady00@gmail.com"]
11
+ gem.description = %q{Chef Auth middleware for Faraday}
12
+ gem.summary = %q{Provides a simple middleware for Faraday requests to use mixlib-authentication to interact with a chef server}
13
+ gem.homepage = ""
14
+ gem.license = "MIT"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_development_dependency "bundler", "~> 1.3"
22
+ gem.add_development_dependency "rake"
23
+
24
+ gem.add_dependency "mixlib-authentication", "~> 1.3.0"
25
+ gem.add_dependency "faraday", "~> 0.8.7"
26
+ end
@@ -0,0 +1,46 @@
1
+ require 'mixlib/authentication/signedheaderauth'
2
+ require 'openSSL'
3
+ require 'faraday'
4
+
5
+ module CagedChef
6
+ class ChefAuth < Faraday::Middleware
7
+
8
+ def initialize(app, options = {})
9
+ super(app)
10
+
11
+ @app = app
12
+ @options = options
13
+ @key = @options[:key]
14
+ end
15
+
16
+ def call(env)
17
+ @env = env
18
+ @env[:request_headers] = signed_headers
19
+ @app.call @env
20
+ end
21
+
22
+ private
23
+ def mixlib_headers
24
+ {
25
+ http_method: @env[:method],
26
+ path: @env[:url].request_uri,
27
+ body: @env[:body],
28
+ host: @options[:host],
29
+ user_id: @options[:user_id],
30
+ timestamp: Time.now.utc.to_s
31
+ }
32
+ end
33
+
34
+ def key
35
+ OpenSSL::PKey::RSA.new(File.read(@key))
36
+ end
37
+
38
+ def signing_object
39
+ Mixlib::Authentication::SignedHeaderAuth.signing_object(mixlib_headers)
40
+ end
41
+
42
+ def signed_headers
43
+ signing_object.sign key
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module CagedChef
2
+ VERSION = "0.0.1"
3
+ end
data/lib/caged_chef.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'faraday'
2
+ require 'caged_chef/version'
3
+
4
+ module CagedChef
5
+ autoload :CagedChef, 'caged_chef/chef_auth'
6
+
7
+ if Faraday.respond_to? :register_middleware
8
+ Faraday.register_middleware :request, :caged_chef => lambda { CagedChef }
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: caged_chef
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brandon Dennis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
21
+ none: false
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ none: false
28
+ prerelease: false
29
+ type: :development
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ none: false
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ none: false
44
+ prerelease: false
45
+ type: :development
46
+ - !ruby/object:Gem::Dependency
47
+ name: mixlib-authentication
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ~>
51
+ - !ruby/object:Gem::Version
52
+ version: 1.3.0
53
+ none: false
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ version: 1.3.0
59
+ none: false
60
+ prerelease: false
61
+ type: :runtime
62
+ - !ruby/object:Gem::Dependency
63
+ name: faraday
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.7
69
+ none: false
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ version: 0.8.7
75
+ none: false
76
+ prerelease: false
77
+ type: :runtime
78
+ description: Chef Auth middleware for Faraday
79
+ email:
80
+ - toady00@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - caged_chef.gemspec
91
+ - lib/caged_chef.rb
92
+ - lib/caged_chef/chef_auth.rb
93
+ - lib/caged_chef/version.rb
94
+ homepage: ''
95
+ licenses:
96
+ - MIT
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ none: false
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ none: false
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 1.8.24
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: Provides a simple middleware for Faraday requests to use mixlib-authentication to interact with a chef server
119
+ test_files: []