Skip to content

Commit

Permalink
remove '::' from module statements
Browse files Browse the repository at this point in the history
These can fail with "uninitialized constant Berkshelf" if the
`module Berkshelf` hasn't already been declared, which under some
kind of extremely strange conditions is failing on sles-11 and
el-6 in our CI system.

There is probably some fascinating reason why this is failing on
only those two distros, and I am hoping I don't have to actually
learn why.

If you'd like a plausible story, something about LC_COLLATE env
vars being different and leading to different file globbing
behavior would be my guess.

Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed Apr 30, 2018
1 parent 13840e6 commit fa6488c
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 180 deletions.
36 changes: 19 additions & 17 deletions lib/berkshelf/api_client/chef_server_connection.rb
@@ -1,28 +1,30 @@
require "berkshelf/ridley_compat"

module Berkshelf::APIClient
require_relative "errors"
module Berkshelf
module APIClient
require_relative "errors"

class ChefServerConnection
attr_reader :client
class ChefServerConnection
attr_reader :client

def initialize(*args)
@client = Berkshelf::RidleyCompat.new(*args)
@url = args[0][:server_url]
end
def initialize(*args)
@client = Berkshelf::RidleyCompat.new(*args)
@url = args[0][:server_url]
end

def universe
response = client.get("universe")
def universe
response = client.get("universe")

[].tap do |cookbooks|
response.each do |name, versions|
versions.each do |version, attributes|
attributes[:location_path] = @url
cookbooks << RemoteCookbook.new(name, version, attributes) end
[].tap do |cookbooks|
response.each do |name, versions|
versions.each do |version, attributes|
attributes[:location_path] = @url
cookbooks << RemoteCookbook.new(name, version, attributes) end
end
end
rescue Ridley::Errors::HTTPNotFound
raise ServiceNotFound, "service not found at: #{@url}"
end
rescue Ridley::Errors::HTTPNotFound
raise ServiceNotFound, "service not found at: #{@url}"
end
end
end
96 changes: 49 additions & 47 deletions lib/berkshelf/api_client/connection.rb
@@ -1,53 +1,55 @@
require "berkshelf/ridley_compat"

module Berkshelf::APIClient
require_relative "errors"

class Connection
# @return [String]
attr_reader :url

# @return [Integer]
# how many retries to attempt on HTTP requests
attr_reader :retries

# @return [Float]
# time to wait between retries
attr_reader :retry_interval

# @param [String, Addressable::URI] url
#
# @option options [Integer] :open_timeout (3)
# how long to wait (in seconds) for connection open to the API server
# @option options [Integer] :timeout (30)
# how long to wait (in seconds) before getting a response from the API server
# @option options [Integer] :retries (3)
# how many retries to perform before giving up
# @option options [Float] :retry_interval (0.5)
# how long to wait (in seconds) between each retry
def initialize(url, options = {})
# it looks like Faraday mutates the URI argument it is given, when we ripped Faraday out of this
# API it stopped doing that. this may or may not be a breaking change (it broke some fairly
# brittle berkshelf tests). if it causes too much berkshelf chaos we could revert by uncommenting
# the next line. as it is removing this behavior feels more like fixing a bug.
#@url = url.normalize! if url.is_a?(Addressable::URI)
options = { retries: 3, retry_interval: 0.5, open_timeout: 30, timeout: 30 }.merge(options)
options[:server_url] = url

@client = Berkshelf::RidleyCompatJSON.new(**options)
end
module Berkshelf
module APIClient
require_relative "errors"

class Connection
# @return [String]
attr_reader :url

# @return [Integer]
# how many retries to attempt on HTTP requests
attr_reader :retries

# @return [Float]
# time to wait between retries
attr_reader :retry_interval

# @param [String, Addressable::URI] url
#
# @option options [Integer] :open_timeout (3)
# how long to wait (in seconds) for connection open to the API server
# @option options [Integer] :timeout (30)
# how long to wait (in seconds) before getting a response from the API server
# @option options [Integer] :retries (3)
# how many retries to perform before giving up
# @option options [Float] :retry_interval (0.5)
# how long to wait (in seconds) between each retry
def initialize(url, options = {})
# it looks like Faraday mutates the URI argument it is given, when we ripped Faraday out of this
# API it stopped doing that. this may or may not be a breaking change (it broke some fairly
# brittle berkshelf tests). if it causes too much berkshelf chaos we could revert by uncommenting
# the next line. as it is removing this behavior feels more like fixing a bug.
#@url = url.normalize! if url.is_a?(Addressable::URI)
options = { retries: 3, retry_interval: 0.5, open_timeout: 30, timeout: 30 }.merge(options)
options[:server_url] = url

@client = Berkshelf::RidleyCompatJSON.new(**options)
end

# Retrieves the entire universe of known cookbooks from the API source
#
# @raise [APIClient::TimeoutError]
#
# @return [Array<APIClient::RemoteCookbook>]
def universe
response = @client.get("universe")

[].tap do |cookbooks|
response.each do |name, versions|
versions.each { |version, attributes| cookbooks << RemoteCookbook.new(name, version, attributes) }
# Retrieves the entire universe of known cookbooks from the API source
#
# @raise [APIClient::TimeoutError]
#
# @return [Array<APIClient::RemoteCookbook>]
def universe
response = @client.get("universe")

[].tap do |cookbooks|
response.each do |name, versions|
versions.each { |version, attributes| cookbooks << RemoteCookbook.new(name, version, attributes) }
end
end
end
end
Expand Down
98 changes: 50 additions & 48 deletions lib/berkshelf/api_client/remote_cookbook.rb
@@ -1,54 +1,56 @@
require "json"
require "chef/mash"

module Berkshelf::APIClient
# A representation of cookbook metadata indexed by a Berkshelf API Server. Returned
# by sending messages to a {Berkshelf::APIClient} and used to download cookbooks
# indexed by the Berkshelf API Server.
class RemoteCookbook
# @return [String]
attr_reader :name
# @return [String]
attr_reader :version

# @param [String] name
# @param [String] version
# @param [Hash] attributes
def initialize(name, version, attributes = {})
@name = name
@version = version
@attributes = ::Mash.new(attributes)
end

# @return [Hash]
def dependencies
@attributes[:dependencies]
end

# @return [Hash]
def platforms
@attributes[:platforms]
end

# @return [Symbol]
def location_type
@attributes[:location_type].to_sym
end

# @return [String]
def location_path
@attributes[:location_path]
end

def to_hash
{
name: name,
version: version,
}
end

def to_json(options = {})
::JSON.pretty_generate(to_hash, options)
module Berkshelf
module APIClient
# A representation of cookbook metadata indexed by a Berkshelf API Server. Returned
# by sending messages to a {Berkshelf::APIClient} and used to download cookbooks
# indexed by the Berkshelf API Server.
class RemoteCookbook
# @return [String]
attr_reader :name
# @return [String]
attr_reader :version

# @param [String] name
# @param [String] version
# @param [Hash] attributes
def initialize(name, version, attributes = {})
@name = name
@version = version
@attributes = ::Mash.new(attributes)
end

# @return [Hash]
def dependencies
@attributes[:dependencies]
end

# @return [Hash]
def platforms
@attributes[:platforms]
end

# @return [Symbol]
def location_type
@attributes[:location_type].to_sym
end

# @return [String]
def location_path
@attributes[:location_path]
end

def to_hash
{
name: name,
version: version,
}
end

def to_json(options = {})
::JSON.pretty_generate(to_hash, options)
end
end
end
end

0 comments on commit fa6488c

Please sign in to comment.