├── lib ├── private_gem │ ├── version.rb │ ├── templates │ │ └── newgem │ │ │ ├── test │ │ │ ├── minitest_helper.rb.tt │ │ │ └── test_newgem.rb.tt │ │ │ ├── Rakefile.tt │ │ │ ├── Gemfile.tt │ │ │ ├── bin │ │ │ └── newgem.tt │ │ │ ├── gitignore.tt │ │ │ ├── lib │ │ │ ├── newgem │ │ │ │ └── version.rb.tt │ │ │ └── newgem.rb.tt │ │ │ ├── README.md.tt │ │ │ └── newgem.gemspec.tt │ ├── tasks.rb │ └── cli.rb └── private_gem.rb ├── Gemfile ├── .gitignore ├── Rakefile ├── bin └── private_gem ├── Gemfile.lock ├── test ├── minitest_helper.rb ├── test_private_gem.rb └── test_configuration.rb ├── .github └── workflows │ └── actions.yml ├── private_gem.gemspec ├── README.md └── LICENSE /lib/private_gem/version.rb: -------------------------------------------------------------------------------- 1 | module PrivateGem 2 | VERSION = '1.2.1' 3 | end 4 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in private_gem.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /lib/private_gem/templates/newgem/test/minitest_helper.rb.tt: -------------------------------------------------------------------------------- 1 | require 'bundler/setup' 2 | require '<%= config[:namespaced_path] %>' 3 | 4 | require 'minitest/autorun' 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /_yardoc/ 4 | /coverage/ 5 | /doc/ 6 | /pkg/ 7 | /spec/reports/ 8 | /tmp/ 9 | *.bundle 10 | *.so 11 | *.o 12 | *.a 13 | mkmf.log 14 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/setup' 2 | require 'bundler/gem_tasks' 3 | require 'rake/testtask' 4 | require 'bump/tasks' 5 | 6 | Rake::TestTask.new(:test) { } 7 | task default: :test 8 | -------------------------------------------------------------------------------- /lib/private_gem/templates/newgem/Rakefile.tt: -------------------------------------------------------------------------------- 1 | require 'bundler/setup' 2 | require 'private_gem/tasks' 3 | require 'rake/testtask' 4 | 5 | Rake::TestTask.new(:test) { } 6 | 7 | task :default => :test 8 | -------------------------------------------------------------------------------- /lib/private_gem/templates/newgem/Gemfile.tt: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | source <%= PrivateGem.server.inspect %> 3 | 4 | # Specify your gem's dependencies in <%= config[:name] %>.gemspec 5 | gemspec 6 | -------------------------------------------------------------------------------- /lib/private_gem/templates/newgem/bin/newgem.tt: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | root = File.expand_path('../..', __FILE__) 4 | $LOAD_PATH << "#{root}/lib" if File.exist?("#{root}/Gemfile") 5 | require '<%= config[:namespaced_path] %>' 6 | -------------------------------------------------------------------------------- /lib/private_gem/templates/newgem/gitignore.tt: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | *.bundle 11 | *.so 12 | *.o 13 | *.a 14 | mkmf.log 15 | -------------------------------------------------------------------------------- /lib/private_gem/templates/newgem/lib/newgem/version.rb.tt: -------------------------------------------------------------------------------- 1 | <%- config[:constant_array].each_with_index do |c,i| -%> 2 | <%= ' '*i %>module <%= c %> 3 | <%- end -%> 4 | <%= ' '*config[:constant_array].size %>VERSION = '0.0.1' 5 | <%- (config[:constant_array].size-1).downto(0) do |i| -%> 6 | <%= ' '*i %>end 7 | <%- end -%> 8 | -------------------------------------------------------------------------------- /lib/private_gem/templates/newgem/test/test_newgem.rb.tt: -------------------------------------------------------------------------------- 1 | require_relative 'minitest_helper' 2 | 3 | describe <%= config[:constant_name] %> do 4 | it 'has a version number' do 5 | ::<%= config[:constant_name] %>::VERSION.wont_be_nil 6 | end 7 | 8 | it 'does something useful' do 9 | flunk 'It does nothing useful!' 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /bin/private_gem: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'bundler' 4 | root = File.expand_path('../..', __FILE__) 5 | $LOAD_PATH << "#{root}/lib" if File.exist?("#{root}/Gemfile") 6 | require 'private_gem' 7 | 8 | require 'bundler/friendly_errors' 9 | Bundler.with_friendly_errors do 10 | require 'private_gem/cli' 11 | PrivateGem::CLI.start(ARGV, :debug => true) 12 | end 13 | -------------------------------------------------------------------------------- /lib/private_gem/templates/newgem/lib/newgem.rb.tt: -------------------------------------------------------------------------------- 1 | require '<%= config[:namespaced_path] %>/version' 2 | 3 | <%- config[:constant_array].each_with_index do |c,i| -%> 4 | <%= ' '*i %>module <%= c %> 5 | <%- end -%> 6 | <%= ' '*config[:constant_array].size %># Your code goes here... 7 | <%- (config[:constant_array].size-1).downto(0) do |i| -%> 8 | <%= ' '*i %>end 9 | <%- end -%> 10 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | private_gem (1.2.1) 5 | bundler (> 2.2, < 3.0) 6 | thor 7 | 8 | GEM 9 | remote: https://rubygems.org/ 10 | specs: 11 | bump (0.10.0) 12 | byebug (11.1.3) 13 | maxitest (4.4.1) 14 | minitest (>= 5.0.0, < 5.18.0) 15 | minitest (5.17.0) 16 | rake (13.0.6) 17 | thor (1.2.1) 18 | 19 | PLATFORMS 20 | ruby 21 | 22 | DEPENDENCIES 23 | bump 24 | byebug 25 | maxitest 26 | private_gem! 27 | rake 28 | 29 | BUNDLED WITH 30 | 2.4.9 31 | -------------------------------------------------------------------------------- /test/minitest_helper.rb: -------------------------------------------------------------------------------- 1 | require 'bundler/setup' 2 | 3 | # ensure everyone has the same env 4 | Bundler::ORIGINAL_ENV.delete_if { |k| k.start_with?("BUNDLE_HTTP") } 5 | 6 | # ensure no 1-off ~/.bundle/config breaks tests 7 | require 'tmpdir' 8 | original = File.expand_path("~/.bundle/config") 9 | if File.exist?(original) 10 | dir = Dir.mktmpdir 11 | Bundler::ORIGINAL_ENV["HOME"] = dir 12 | Dir.mkdir "#{dir}/.bundle" 13 | File.write("#{dir}/.bundle/config", File.read(original).gsub(/.*BUNDLE_HTTP.*/, "")) 14 | end 15 | 16 | require 'private_gem' 17 | 18 | require 'maxitest/global_must' 19 | require 'maxitest/autorun' 20 | require 'maxitest/timeout' 21 | -------------------------------------------------------------------------------- /.github/workflows/actions.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | push: 4 | branches: [master] 5 | pull_request: 6 | branches: [master] 7 | jobs: 8 | test: 9 | runs-on: ubuntu-latest 10 | strategy: 11 | matrix: 12 | ruby: ['2.6', '2.7', '3.0', '3.1'] # keep in sync with gemspec 13 | name: ${{ matrix.ruby }} rake 14 | steps: 15 | - uses: zendesk/checkout@v2 16 | - uses: zendesk/setup-ruby@v1 17 | with: 18 | ruby-version: ${{ matrix.ruby }} 19 | bundler-cache: true # runs 'bundle install' and caches installed gems automatically 20 | - name: rake 21 | run: | 22 | gem install thor 23 | bundle config https://some-fake-gem-server.com 123:456 24 | bundle exec rake 25 | -------------------------------------------------------------------------------- /lib/private_gem/templates/newgem/README.md.tt: -------------------------------------------------------------------------------- 1 | # <%=config[:constant_name]%> 2 | 3 | TODO: Write a gem description 4 | 5 | ## Installation 6 | 7 | Add this line to your application's Gemfile: 8 | 9 | ```ruby 10 | gem '<%= config[:name] %>' 11 | ``` 12 | 13 | And then execute: 14 | 15 | ```Bash 16 | bundle 17 | ``` 18 | 19 | Or install it yourself as: 20 | 21 | ```Bash 22 | gem install <%= config[:name] %> 23 | ``` 24 | 25 | ## Usage 26 | 27 | TODO: Write usage instructions here 28 | 29 | ## Contributing 30 | 31 | 1. Create your feature branch (`git checkout -b my-new-feature`) 32 | 2. Commit your changes (`git commit -am 'Add some feature'`) 33 | 3. Push to the branch (`git push origin my-new-feature`) 34 | 4. Create a new Pull Request 35 | -------------------------------------------------------------------------------- /private_gem.gemspec: -------------------------------------------------------------------------------- 1 | require './lib/private_gem/version' 2 | 3 | Gem::Specification.new do |spec| 4 | spec.name = 'private_gem' 5 | spec.version = PrivateGem::VERSION 6 | spec.authors = ['Mick Staugaard'] 7 | spec.email = ['mick@staugaard.com'] 8 | spec.summary = 'Keeps your private gems private' 9 | spec.homepage = 'https://github.com/zendesk/private_gem' 10 | spec.license = 'Apache License Version 2.0' 11 | 12 | spec.files = Dir.glob('lib/**/*') 13 | spec.executables = Dir.glob('bin/**/*').map {|f| File.basename(f)} 14 | 15 | spec.add_dependency 'bundler', '> 2.2', '< 3.0' 16 | spec.add_dependency 'thor' 17 | 18 | spec.add_development_dependency 'maxitest' 19 | spec.add_development_dependency 'bump' 20 | spec.add_development_dependency 'rake' 21 | spec.add_development_dependency 'byebug' 22 | 23 | spec.required_ruby_version = '>= 2.6' # keep in sync with .github/workflows/actions.yml 24 | end 25 | -------------------------------------------------------------------------------- /lib/private_gem/templates/newgem/newgem.gemspec.tt: -------------------------------------------------------------------------------- 1 | require './lib/<%= config[:namespaced_path] %>/version' 2 | 3 | Gem::Specification.new do |spec| 4 | spec.name = <%= config[:name].inspect %> 5 | spec.version = <%= config[:constant_name] %>::VERSION 6 | spec.authors = [<%= config[:author].inspect %>] 7 | spec.email = [<%= config[:email].inspect %>] 8 | spec.summary = %q{TODO: Write a short summary. Required.} 9 | spec.description = %q{TODO: Write a longer description. Optional.} 10 | spec.homepage = '' 11 | spec.license = 'PRIVATE' 12 | 13 | spec.metadata['allowed_push_host'] = <%= PrivateGem.server.inspect %> 14 | 15 | spec.files = Dir.glob('lib/**/*') 16 | spec.executables = Dir.glob('bin/**/*').map {|f| File.basename(f)} 17 | 18 | spec.add_development_dependency 'private_gem' 19 | spec.add_development_dependency 'bundler' 20 | spec.add_development_dependency 'rake' 21 | spec.add_development_dependency 'minitest' 22 | end 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Private Gem 2 | 3 | - rake tasks for building and pushing gems to a private gem server, with added protection against pushing to rubygems.org 4 | - generator for creating new private gems 5 | 6 | 7 | ## Rake Tasks 8 | 9 | ```ruby 10 | # Rakefile 11 | require 'private_gem/tasks' 12 | ``` 13 | 14 | * `rake build` build a local `.gem` file 15 | * `rake install` build and install the local gem 16 | * `rake release` tag and push gem to private gem server 17 | 18 | (Based on the tasks from `bundler/gem_tasks`) 19 | 20 | 21 | ## Private Gem Generator 22 | 23 | ```bash 24 | private_gem new my_private_library 25 | create my_private_library/Gemfile 26 | create my_private_library/Rakefile 27 | create my_private_library/README.md 28 | ... 29 | ``` 30 | 31 | Generates a new local gem called `my_private_library` with the `private_gem` Rake tasks preinstalled. 32 | 33 | 34 | ## License 35 | 36 | Copyright 2014 Zendesk 37 | 38 | Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at 39 | 40 | www.apache.org/licenses/LICENSE-2.0 41 | 42 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 43 | -------------------------------------------------------------------------------- /lib/private_gem.rb: -------------------------------------------------------------------------------- 1 | require 'private_gem/version' 2 | require 'bundler' 3 | require 'uri' 4 | 5 | module PrivateGem 6 | def self.server 7 | urls_with_credentials = Bundler.settings.all.select do |n| 8 | url = URI.parse(n) 9 | url && ['http', 'https'].include?(url.scheme) 10 | end 11 | 12 | hosts_with_credentials = Bundler.settings.all.select do |n| 13 | n =~ /^([-_a-z\d]+\.)+[a-z]+$/ 14 | end 15 | 16 | if (private_gem_server = Bundler.settings['private_gem_server']) 17 | if urls_with_credentials.include?(private_gem_server) 18 | return private_gem_server 19 | end 20 | 21 | private_gem_server_uri = URI.parse(private_gem_server) 22 | if private_gem_server_uri && hosts_with_credentials.include?(private_gem_server_uri.host) 23 | return private_gem_server 24 | end 25 | 26 | abort("You don't have any configured credentials for the private gem server at #{private_gem_server}") 27 | end 28 | 29 | if urls_with_credentials.empty? 30 | abort("You don't have any configured private gem credentials.") 31 | end 32 | 33 | if urls_with_credentials.size > 1 34 | msg = "You have multiple private gem servers defined:\n" 35 | urls_with_credentials.each do |s| 36 | msg << " #{s}\n" 37 | end 38 | abort("#{msg}You need to select which private gem server to use using `bundle config private_gem_server URL_OF_GEM_SERVER`") 39 | end 40 | 41 | urls_with_credentials.first 42 | end 43 | 44 | def self.credentials 45 | Bundler.settings[server] || Bundler.settings[URI.parse(server).host] 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /lib/private_gem/tasks.rb: -------------------------------------------------------------------------------- 1 | require 'private_gem' 2 | require 'bundler/gem_helper' 3 | 4 | module PrivateGem 5 | module GemHelperPatches 6 | def install 7 | super 8 | 9 | Rake::Task[:release].clear_comments 10 | Rake::Task[:release].comment = "Create tag v#{version} and build and push #{name}-#{version}.gem to your private gem server" 11 | 12 | task :verify_gemspec do 13 | verify_allowed_push_host 14 | end 15 | 16 | Rake::Task[:build].enhance([:verify_gemspec]) 17 | end 18 | 19 | protected 20 | 21 | def rubygem_push(path) 22 | if PrivateGem.server && PrivateGem.credentials 23 | Bundler.ui.confirm sh([ 24 | "curl", 25 | "--silent", "--fail", 26 | "--data-binary", "@#{path}", 27 | "--user", PrivateGem.credentials, 28 | "--header", "Content-Type: application/octet-stream", 29 | "#{PrivateGem.server}api/v1/gems" 30 | ]) 31 | 32 | Bundler.ui.confirm "Pushed #{name} #{version} to #{PrivateGem.server}." 33 | else 34 | raise "Your private gem server credentials aren't set." 35 | end 36 | end 37 | 38 | def verify_allowed_push_host 39 | allowed_push_host = gemspec.metadata['allowed_push_host'] 40 | 41 | if allowed_push_host != PrivateGem.server 42 | abort_message = %Q~ 43 | Please add the following to #{File.basename(spec_path)} (to prevent accidental pushes to rubygems.org): 44 | gemspec.metadata['allowed_push_host'] = '#{PrivateGem.server}' 45 | ~.gsub(/^ +/m, '') 46 | abort(abort_message + "\n") 47 | end 48 | end 49 | end 50 | end 51 | 52 | Bundler::GemHelper.send(:prepend, PrivateGem::GemHelperPatches) 53 | 54 | Bundler::GemHelper.install_tasks 55 | -------------------------------------------------------------------------------- /test/test_private_gem.rb: -------------------------------------------------------------------------------- 1 | require_relative 'minitest_helper' 2 | 3 | describe PrivateGem do 4 | it 'has a version number' do 5 | PrivateGem::VERSION.wont_be_nil 6 | end 7 | 8 | describe "CLI" do 9 | around do |test| 10 | Dir.mktmpdir do |dir| 11 | Dir.chdir(dir) { test.call } 12 | end 13 | end 14 | 15 | it "shows version" do 16 | privat_gem("version").must_equal "#{PrivateGem::VERSION}\n" 17 | end 18 | 19 | it "shows help" do 20 | privat_gem("help").must_include "private_gem new" 21 | end 22 | 23 | it "fails on unknown command" do 24 | privat_gem("sdfsfddfs", fail: true) 25 | end 26 | 27 | it "shows help for subcommands" do 28 | privat_gem("help new").must_include "--bin" 29 | end 30 | 31 | describe "new" do 32 | before do 33 | dir = "#{Bundler::ORIGINAL_ENV["HOME"]}/.bundle" 34 | Dir.mkdir dir unless Dir.exist? dir 35 | File.write "#{dir}/config", 'BUNDLE_HTTPS://FOO__IO/BAR/: "user:pass"' 36 | end 37 | 38 | it "generates a new project" do 39 | privat_gem("new foo") 40 | Dir.chdir("foo") do 41 | File.exist?(".gitignore").must_equal true 42 | File.exist?("bin/foo").must_equal false 43 | end 44 | end 45 | 46 | it "generates a new project with binary" do 47 | privat_gem("new foo -b") 48 | File.exist?("foo/bin/foo").must_equal true 49 | end 50 | end 51 | 52 | def privat_gem(command="", options={}) 53 | sh("#{Bundler.root}/bin/private_gem #{command}", options) 54 | end 55 | 56 | def sh(command, options={}) 57 | result = Bundler.with_unbundled_env { `#{command} #{"2>&1" unless options[:keep_output]}` } 58 | raise "#{options[:fail] ? "SUCCESS" : "FAIL"} #{command}\n#{result}" if $?.success? == !!options[:fail] 59 | result 60 | end 61 | end 62 | end 63 | -------------------------------------------------------------------------------- /lib/private_gem/cli.rb: -------------------------------------------------------------------------------- 1 | require 'bundler/cli' 2 | require 'thor' 3 | 4 | module PrivateGem 5 | class CLI < Thor 6 | include Thor::Actions 7 | 8 | default_task :help 9 | 10 | desc 'version', 'show version' 11 | def version 12 | puts PrivateGem::VERSION 13 | end 14 | 15 | desc 'new GEM [OPTIONS]', 'Creates a skeleton for a private ruby gem' 16 | method_option :bin, :type => :boolean, :default => false, :aliases => '-b', :banner => 'Generate a binary for your gem.' 17 | def new(gem_name) 18 | name = gem_name.chomp('/') # remove trailing slash if present 19 | underscored_name = name.tr('-', '_') 20 | namespaced_path = name.tr('-', '/') 21 | target = File.join(Dir.pwd, name) 22 | constant_name = name.split('_').map{|p| p[0..0].upcase + p[1..-1] }.join 23 | constant_name = constant_name.split('-').map{|q| q[0..0].upcase + q[1..-1] }.join('::') if constant_name =~ /-/ 24 | constant_array = constant_name.split('::') 25 | git_user_name = `git config user.name`.chomp 26 | git_user_email = `git config user.email`.chomp 27 | opts = { 28 | :name => name, 29 | :underscored_name => underscored_name, 30 | :namespaced_path => namespaced_path, 31 | :constant_name => constant_name, 32 | :constant_array => constant_array, 33 | :author => git_user_name.empty? ? 'TODO: Write your name' : git_user_name, 34 | :email => git_user_email.empty? ? 'TODO: Write your email address' : git_user_email 35 | } 36 | 37 | template 'newgem/Gemfile.tt', "#{target}/Gemfile", opts 38 | template "newgem/Rakefile.tt", "#{target}/Rakefile", opts 39 | template "newgem/README.md.tt", "#{target}/README.md", opts 40 | template "newgem/gitignore.tt", "#{target}/.gitignore", opts 41 | template "newgem/newgem.gemspec.tt", "#{target}/#{name}.gemspec", opts 42 | template "newgem/lib/newgem.rb.tt", "#{target}/lib/#{namespaced_path}.rb", opts 43 | template "newgem/lib/newgem/version.rb.tt", "#{target}/lib/#{namespaced_path}/version.rb", opts 44 | template "newgem/test/minitest_helper.rb.tt", "#{target}/test/minitest_helper.rb", opts 45 | template "newgem/test/test_newgem.rb.tt", "#{target}/test/test_#{namespaced_path}.rb", opts 46 | if options[:bin] 47 | template "newgem/bin/newgem.tt", "#{target}/bin/#{name}", opts 48 | end 49 | 50 | Dir.chdir(target) { `git init; git add .` } 51 | end 52 | 53 | def self.source_root 54 | File.expand_path(File.join(File.dirname(__FILE__), 'templates')) 55 | end 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /test/test_configuration.rb: -------------------------------------------------------------------------------- 1 | require_relative 'minitest_helper' 2 | 3 | describe 'PrivateGem.server' do 4 | let(:bundler_settings) { {} } 5 | let(:private_gem_server_host) { 'gems.company.com' } 6 | let(:private_gem_server) { "https://#{private_gem_server_host}/" } 7 | 8 | class AbortException < RuntimeError 9 | end 10 | 11 | around do |test| 12 | PrivateGem.stub(:abort, -> (msg) { raise AbortException.new(msg) }) do 13 | test.call 14 | end 15 | end 16 | 17 | around do |test| 18 | def bundler_settings.all 19 | keys 20 | end 21 | 22 | Bundler.stub(:settings, bundler_settings) do 23 | test.call 24 | end 25 | end 26 | 27 | describe 'PrivateGem.server' do 28 | describe 'when private_gem_server is present' do 29 | describe 'when only private_gem_server is present' do 30 | let(:bundler_settings) do 31 | { 32 | 'private_gem_server' => private_gem_server 33 | } 34 | end 35 | 36 | it 'aborts complaining about missing credentials' do 37 | -> { PrivateGem.server }.must_raise(AbortException).message.must_match %r{You don't have any configured credentials for the private gem server at https://gems.company.com/} 38 | end 39 | end 40 | 41 | describe 'when no credentials for private_gem_server are present' do 42 | let(:bundler_settings) do 43 | { 44 | 'private_gem_server' => private_gem_server, 45 | 'https://gems.other-company.com/' => 'user:pass' 46 | } 47 | end 48 | 49 | it 'aborts complaining about missing credentials' do 50 | -> { PrivateGem.server }.must_raise(AbortException).message.must_match %r{You don't have any configured credentials for the private gem server at https://gems.company.com/} 51 | end 52 | end 53 | 54 | describe 'when credentials for private_gem_server are present' do 55 | let(:bundler_settings) do 56 | { 57 | 'private_gem_server' => private_gem_server, 58 | 'https://gems.other-company.com/' => 'user:pass', 59 | private_gem_server => 'user:pass' 60 | } 61 | end 62 | 63 | it 'returns private_gem_server' do 64 | PrivateGem.server.must_equal 'https://gems.company.com/' 65 | end 66 | end 67 | 68 | describe 'when credentials for private_gem_server host are present' do 69 | let(:bundler_settings) do 70 | { 71 | 'private_gem_server' => private_gem_server, 72 | 'other-company.com' => 'user:pass', 73 | private_gem_server_host => 'user:pass' 74 | } 75 | end 76 | 77 | it 'returns private_gem_server' do 78 | PrivateGem.server.must_equal 'https://gems.company.com/' 79 | end 80 | end 81 | end 82 | 83 | describe 'when private_gem_server is not present' do 84 | describe 'and no credentials are present' do 85 | it 'aborts complaining about missing credentials' do 86 | -> { PrivateGem.server }.must_raise(AbortException).message.must_match %r{You don't have any configured private gem credentials} 87 | end 88 | end 89 | 90 | describe 'and credentials for one server are present' do 91 | let(:bundler_settings) do 92 | { 93 | 'https://gems.company.com/' => 'user:pass' 94 | } 95 | end 96 | 97 | it 'returns that one server' do 98 | PrivateGem.server.must_equal 'https://gems.company.com/' 99 | end 100 | end 101 | 102 | describe 'and credentials for multiple servers are present' do 103 | let(:bundler_settings) do 104 | { 105 | 'https://gems.company.com/' => 'user:pass', 106 | 'https://gems.other-company.com/' => 'user:pass' 107 | } 108 | end 109 | 110 | it 'aborts asking you to set private_gem_server' do 111 | -> { PrivateGem.server }.must_raise(AbortException).message.must_match %r{You need to select which private gem server to use using `bundle config private_gem_server URL_OF_GEM_SERVER`} 112 | end 113 | end 114 | end 115 | end 116 | 117 | describe 'PrivateGem.credentials' do 118 | describe 'when credentials for private_gem_server are present' do 119 | let(:bundler_settings) do 120 | { 121 | 'private_gem_server' => private_gem_server, 122 | 'https://gems.other-company.com/' => 'otheruser:otherpass', 123 | private_gem_server => 'user:pass' 124 | } 125 | end 126 | 127 | it 'returns the credentials of the private_gem_server' do 128 | PrivateGem.credentials.must_equal 'user:pass' 129 | end 130 | end 131 | 132 | describe 'when credentials for private_gem_server host are present' do 133 | let(:bundler_settings) do 134 | { 135 | 'private_gem_server' => private_gem_server, 136 | 'gems.other-company.com' => 'otheruser:otherpass', 137 | private_gem_server_host => 'user:pass' 138 | } 139 | end 140 | 141 | it 'returns the credentials of the private_gem_server' do 142 | PrivateGem.credentials.must_equal 'user:pass' 143 | end 144 | end 145 | end 146 | end 147 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS --------------------------------------------------------------------------------