Skip to content

Commit 4069cb3

Browse files
authored
Merge pull request #149 from github/kpaulisse-remove-hardcode
Set URI port without re-setting the constants
2 parents a171724 + 5f3ece9 commit 4069cb3

24 files changed

+32
-22
lines changed

.travis.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
language: ruby
44
install: true
55
script: "script/cibuild"
6-
dist: precise
6+
7+
before_install:
8+
- gem install bundler -v 1.15.4
79

810
matrix:
911
include:
1012
# Build with latest ruby
11-
- rvm: 2.4.1
13+
- rvm: 2.4
1214
env: RUBOCOP_TEST="true" RSPEC_TEST="true"
1315
# Build with older ruby versions
14-
- rvm: 2.3.4
16+
- rvm: 2.3.2
1517
env: RUBOCOP_TEST="false" RSPEC_TEST="true"
16-
- rvm: 2.2
18+
- rvm: 2.2.3
1719
env: RUBOCOP_TEST="false" RSPEC_TEST="true"
1820
- rvm: 2.1
1921
env: RUBOCOP_TEST="false" RSPEC_TEST="true"

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.0
1+
1.4.1

doc/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
</tr>
99
</thead><tbody>
1010
<tr valign=top>
11+
<td>1.4.1</td>
12+
<td>2017-10-02</td>
13+
<td>
14+
<li><a href="https://github.com/github/octocatalog-diff/pull/149">#149</a>: (Internal) Set ports on PuppetDB URLs without altering constants</li>
15+
</td>
16+
</tr>
17+
<tr valign=top>
1118
<td>1.4.0</td>
1219
<td>2017-08-03</td>
1320
<td>

lib/octocatalog-diff/puppetdb.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@
55

66
require 'uri'
77

8-
# Redefine constants to match PuppetDB defaults.
9-
# This code avoids warnings about redefining constants.
10-
URI::HTTP.send(:remove_const, :DEFAULT_PORT) if URI::HTTP.const_defined?(:DEFAULT_PORT)
11-
URI::HTTP.const_set(:DEFAULT_PORT, 8080)
12-
URI::HTTPS.send(:remove_const, :DEFAULT_PORT) if URI::HTTPS.const_defined?(:DEFAULT_PORT)
13-
URI::HTTPS.const_set(:DEFAULT_PORT, 8081)
14-
158
module OctocatalogDiff
169
# A standard way to connect to PuppetDB from the various scripts in this repository.
1710
class PuppetDB
11+
DEFAULT_HTTPS_PORT = 8081
12+
DEFAULT_HTTP_PORT = 8080
13+
1814
# Allow connections to be read (used in tests for now)
1915
attr_reader :connections
2016

@@ -54,7 +50,7 @@ def initialize(options = {})
5450
urls.map { |url| parse_url(url) }
5551
elsif options.key?(:puppetdb_host)
5652
is_ssl = options.fetch(:puppetdb_ssl, true)
57-
default_port = is_ssl ? URI::HTTPS::DEFAULT_PORT : URI::HTTP::DEFAULT_PORT
53+
default_port = is_ssl ? DEFAULT_HTTPS_PORT : DEFAULT_HTTP_PORT
5854
port = options.fetch(:puppetdb_port, default_port).to_i
5955
[{ ssl: is_ssl, host: options[:puppetdb_host], port: port }]
6056
elsif ENV['PUPPETDB_URL'] && !ENV['PUPPETDB_URL'].empty?
@@ -64,7 +60,7 @@ def initialize(options = {})
6460
# This will get the env var and see if it equals 'true'; the result
6561
# of this == comparison is the true/false boolean we need.
6662
is_ssl = ENV.fetch('PUPPETDB_SSL', 'true') == 'true'
67-
default_port = is_ssl ? URI::HTTPS::DEFAULT_PORT : URI::HTTP::DEFAULT_PORT
63+
default_port = is_ssl ? DEFAULT_HTTPS_PORT : DEFAULT_HTTP_PORT
6864
port = ENV.fetch('PUPPETDB_PORT', default_port).to_i
6965
[{ ssl: is_ssl, host: ENV['PUPPETDB_HOST'], port: port }]
7066
else
@@ -152,6 +148,10 @@ def _get(path)
152148
# @return [Hash] { ssl: true/false, host: <String>, port: <Integer> }
153149
def parse_url(url)
154150
uri = URI(url)
151+
if URI.split(url)[3].nil?
152+
uri.port = uri.scheme == 'https' ? DEFAULT_HTTPS_PORT : DEFAULT_HTTP_PORT
153+
end
154+
155155
raise ArgumentError, "URL #{url} has invalid scheme" unless uri.scheme =~ /^https?$/
156156
{ ssl: uri.scheme == 'https', host: uri.host, port: uri.port }
157157
rescue URI::InvalidURIError => exc

octocatalog-diff.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require_relative 'lib/octocatalog-diff/version'
22
require 'json'
33

4-
DEFAULT_PUPPET_VERSION = '4.10.0'.freeze
4+
DEFAULT_PUPPET_VERSION = '4.10.8'.freeze
55

66
Gem::Specification.new do |s|
77
s.required_ruby_version = '>= 2.0.0'
@@ -30,6 +30,7 @@ EOF
3030
s.add_runtime_dependency 'hashdiff', '>= 0.3.0'
3131
s.add_runtime_dependency 'rugged', '>= 0.25.0b2'
3232

33+
s.add_development_dependency 'bundler', '1.15.4'
3334
s.add_development_dependency 'rspec', '~> 3.4.0'
3435
s.add_development_dependency 'rake', '11.2.2'
3536
s.add_development_dependency 'parallel_tests', '2.7.1'

script/bootstrap

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ echo 'Starting script/bootstrap'
44

55
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
66

7-
# FIXME: Remove when CI is switched to Travis
8-
if env | grep ^JANKY_ >/dev/null 2>&1 ; then
9-
export PATH=/usr/share/rbenv/shims:$PATH
10-
export RBENV_VERSION=2.1.2-github
11-
fi
12-
137
rm -rf "${DIR}/.bundle"
148
rm -f "${DIR}/.puppet_version"
159
set -e

script/cibuild

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,27 @@
66
# with one or more Puppet versions, with PUPPET_VERSIONS set to a space-separated list
77
# of versions to test.
88

9-
[ -z "$PUPPET_VERSIONS" ] && export PUPPET_VERSIONS='3.8.7 4.10.0 5.0.0'
9+
[ -z "$PUPPET_VERSIONS" ] && export PUPPET_VERSIONS='3.8.7 4.10.8 5.0.0'
1010
[ -z "$RUBOCOP_TEST" ] && export RUBOCOP_TEST='true'
1111
[ -z "$RSPEC_TEST" ] && export RSPEC_TEST='true'
1212

1313
echo 'Starting script/cibuild'
1414

1515
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
16+
env
1617

1718
# Create a temporary file to capture output of various steps.
1819
export OUTPUT_FILE="$(mktemp)"
1920
function cleanup() {
2021
rm -rf "$OUTPUT_FILE"
22+
rm -f "${DIR}/.ruby-version"
2123
}
2224
trap cleanup EXIT
2325

26+
# Create "$DIR/.ruby-version" from the current ruby version, so it propagates through
27+
# to the clean environment under which Puppet runs.
28+
ruby -e "print RUBY_VERSION" > "${DIR}/.ruby-version"
29+
2430
# Bootstrapping
2531
function bootstrap() {
2632
echo "Bootstrapping..."

vendor/cache/bundler-1.15.4.gem

330 KB
Binary file not shown.
-241 KB
Binary file not shown.

vendor/cache/facter-2.4.6.gem

-241 KB
Binary file not shown.

0 commit comments

Comments
 (0)