bundler-pgs 0.0.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.
data/.gitignore ADDED
@@ -0,0 +1,20 @@
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
18
+ /.idea
19
+ /coverage*
20
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bundler-pgs.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Thomas Baustert
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,78 @@
1
+ # Bundler Private Gem Server Patch
2
+
3
+ **This stuff is currently experimental!**
4
+
5
+ Patch for bundler to support credentials for sources that are not stored in Gemfile.lock.
6
+ Useful when running an additional private gem server besides rubygems.org.
7
+
8
+ Example:
9
+
10
+ # Gemfile
11
+ source "http://_:_@gems.mycompany.com"
12
+
13
+ # Gemfile.lock
14
+ GEM
15
+ remote: https://rubygems.org/
16
+ remote: http://_:_@gems.thomasbaustert.de/
17
+
18
+ ## Warning
19
+
20
+ This comes with no warranty!
21
+
22
+ To prevent bundler from storing a source url to your private gem server with credentials I had to **patch** bundler.
23
+ See `lib/bundler-pgs/bundler_patch.rb` for details.
24
+
25
+ As long as the internal implementation of fetching a gem from an url does not change everything is fine.
26
+ In case a newer version of bundler change this code part the url might be stored in Gemfile.lock
27
+ with the credentials again.
28
+
29
+ Currently bundler version 1.3.5 is supported.
30
+
31
+ ## Usage
32
+
33
+ Install the gem on **every** server using bundler, e.g. ci, staging and production:
34
+
35
+ $ gem install bundler-pgs # pgs = private gem server :)
36
+
37
+ Add your private gem server url with `_` (underscore) as placeholder for the credentials:
38
+
39
+ # Gemfile
40
+ source "http://rubygems.org"
41
+ source "http://_:_@gems.mycompany.com"
42
+
43
+ Add your credentials to `~/.gem/gemserver_credential` on **every** server using bundler, e.g. ci, staging and production:
44
+
45
+ # ~/.gem/gemserver_credential
46
+ ---
47
+ default:
48
+ source: "http://_:_@gems.mycompany.com"
49
+ user: gem
50
+ password: secret
51
+
52
+ Change mod:
53
+
54
+ $ chmod 600 ~/.gem/gemserver_credential
55
+
56
+ Use the bundler patch by running `pundle` instead of `bundle`, e.g.:
57
+
58
+ $ pundle install
59
+
60
+ This will load the patch and runs bundler as usual.
61
+
62
+ You will also need to change the bundle command for capistrano:
63
+
64
+ # config/deploy.rb
65
+ ...
66
+ require "bundler/capistrano"
67
+ set :bundle_cmd, "pundle"
68
+
69
+ ## Caveats
70
+
71
+ * Does not work with [rubygems-bundler](https://github.com/mpapis/rubygems-bundler) and [bundler-unload](https://github.com/mpapis/bundler-unload) yet.
72
+
73
+ ## Contact
74
+
75
+ For comments and question feel free to contact me: business@thomasbaustert.de
76
+
77
+ Copyright © 2013 [Thomas Baustert](http://thomasbaustert.de), released under the MIT license
78
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/pundle ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Trap interrupts to quit cleanly. See
4
+ # https://twitter.com/mitchellh/status/283014103189053442
5
+ Signal.trap("INT") { exit 1 }
6
+
7
+ require 'bundler'
8
+ # Check if an older version of bundler is installed
9
+ $:.each do |path|
10
+ if path =~ %r'/bundler-0.(\d+)' && $1.to_i < 9
11
+ err = "Looks like you have a version of bundler that's older than 0.9.\n"
12
+ err << "Please remove your old versions.\n"
13
+ err << "An easy way to do this is by running `gem cleanup bundler`."
14
+ abort(err)
15
+ end
16
+ end
17
+
18
+ require 'bundler/cli'
19
+ require 'bundler/friendly_errors'
20
+
21
+ require 'bundler-pgs'
22
+ puts "[bundler-pgs] v#{Bundler::Pgs::VERSION} is loaded"
23
+ puts "[bundler-pgs] patching bundler"
24
+
25
+ Bundler.with_friendly_errors { Bundler::CLI.start }
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bundler-pgs/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "bundler-pgs"
8
+ gem.version = Bundler::Pgs::VERSION
9
+ gem.authors = ["Thomas Baustert"]
10
+ gem.email = ["business@thomasbaustert.de"]
11
+ gem.description = %q{bundler patch to support private gem server (pgs)}
12
+ gem.summary = %q{bundler patch to support private gem server (pgs)}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'bundler'
21
+ end
@@ -0,0 +1,22 @@
1
+ ##
2
+ # Extend bundler DSL to allow using convenient method in Gemfile.
3
+ # This is optional and not really necessary.
4
+ #
5
+ # Examples:
6
+ # source "https://rubygems.org"
7
+ # private_gem_server
8
+ # private_gem_server("fooserver")
9
+ #
10
+ module Bundler
11
+ class Dsl
12
+ include BundlerPatch::CredentialFile
13
+
14
+ def private_gem_server(name = "default")
15
+ with_credential_file do |credential_filename|
16
+ yaml = YAML.load_file(credential_filename)
17
+ yaml[name]["source"].to_s.strip
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,92 @@
1
+ require "yaml"
2
+ require 'bundler'
3
+
4
+ ##
5
+ # Patches Bundler::RubygemsIntegration bundler to use url with the credentials.
6
+ #
7
+ module Bundler
8
+ class RubygemsIntegration
9
+ def download_gem(spec, uri, path)
10
+ new_uri = ::BundlerPatch::UriResolver.resolve(uri)
11
+ Gem::RemoteFetcher.fetcher.download(spec, new_uri, path)
12
+ end
13
+ end
14
+ end
15
+
16
+ ##
17
+ # Patches Bundler::Fetcher bundler to use url with the credentials.
18
+ #
19
+ module Bundler
20
+ class Fetcher
21
+ alias_method :orig_initialize, :initialize
22
+
23
+ def initialize(remote_uri)
24
+ new_uri = ::BundlerPatch::UriResolver.resolve(remote_uri)
25
+ orig_initialize(new_uri)
26
+ end
27
+ end
28
+ end
29
+
30
+ ##
31
+ # Replaces credential placeholder (e.g. http://_:_@....) with the credentials from the credentials file.
32
+ #
33
+ module BundlerPatch
34
+ class UriResolver
35
+ extend BundlerPatch::CredentialFile
36
+
37
+ def self.resolve(uri)
38
+ if uri_with_hidden_credentials?(uri)
39
+ new_uri = uri_with_credentials(uri)
40
+ Bundler.ui.debug "[bundler-pgs] uri with credentials: '#{new_uri}'"
41
+ new_uri
42
+ else
43
+ uri
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ ##
50
+ # Return given url with credentials, e.g. +http://_:_@example.com+ to +http://gem:secret@gems.mycompany.com+.
51
+ #
52
+ # Example of file:
53
+ # ---
54
+ # default:
55
+ # source: "http://_:_@gems.mycompany.com"
56
+ # user: gem
57
+ # password: secret
58
+ #
59
+ def self.uri_with_credentials(orig_uri)
60
+ new_uri = with_credential_file do |credential_filename|
61
+ yaml = YAML.load_file(credential_filename)
62
+
63
+ new_uri = nil
64
+ if orig_uri.user == "_"
65
+ credentials = yaml["default"]
66
+
67
+ new_uri = orig_uri.dup
68
+ new_uri.user = credentials["user"].to_s.strip
69
+ new_uri.password = credentials["password"].to_s.strip
70
+ end
71
+
72
+ new_uri
73
+ end
74
+
75
+ new_uri || orig_uri
76
+ end
77
+
78
+ def self.uri_with_hidden_credentials?(uri)
79
+ user_exists?(uri) && password_exists?(uri)
80
+ end
81
+
82
+ def self.user_exists?(uri)
83
+ !uri.user.to_s.strip.empty?
84
+ end
85
+
86
+ def self.password_exists?(uri)
87
+ !uri.password.to_s.strip.empty?
88
+ end
89
+
90
+ end
91
+
92
+ end
@@ -0,0 +1,12 @@
1
+ module BundlerPatch
2
+ module CredentialFile
3
+
4
+ def with_credential_file(&block)
5
+ credential_filename = File.join(ENV["HOME"], ".gem", "gemserver_credentials")
6
+ if File.exists?(credential_filename)
7
+ yield(credential_filename) if block_given?
8
+ end
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,5 @@
1
+ module Bundler
2
+ module Pgs
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ require 'bundler/version'
2
+
3
+ unless ["1.3.5"].include?(Bundler::VERSION)
4
+ puts "\nWarning: You are using bundler #{Bundler::VERSION} and bundler-pgs patch might not work for this version."
5
+ puts "Make sure your Gemfile.lock does not contain your credentials after running pundle!"
6
+ puts ""
7
+ end
8
+
9
+ require "bundler-pgs/version"
10
+ require "bundler-pgs/credential_file"
11
+ require "bundler-pgs/bundler_patch"
12
+ require "bundler-pgs/bundler_dsl_extension"
13
+
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bundler-pgs
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.2
6
+ platform: ruby
7
+ authors:
8
+ - Thomas Baustert
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ requirement: !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ! '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ type: :runtime
29
+ prerelease: false
30
+ description: bundler patch to support private gem server (pgs)
31
+ email:
32
+ - business@thomasbaustert.de
33
+ executables:
34
+ - pundle
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - bin/pundle
44
+ - bundler-pgs.gemspec
45
+ - lib/bundler-pgs.rb
46
+ - lib/bundler-pgs/bundler_dsl_extension.rb
47
+ - lib/bundler-pgs/bundler_patch.rb
48
+ - lib/bundler-pgs/credential_file.rb
49
+ - lib/bundler-pgs/version.rb
50
+ homepage: ''
51
+ licenses: []
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 1.8.25
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: bundler patch to support private gem server (pgs)
74
+ test_files: []