diff --git a/libraries/chef_artifact.rb b/libraries/chef_artifact.rb index ff740cf..0bcd4bb 100644 --- a/libraries/chef_artifact.rb +++ b/libraries/chef_artifact.rb @@ -8,22 +8,22 @@ module Artifact module File # Returns true if the given file is a symlink. - # + # # @param path [String] the path to the file to test - # + # # @return [Boolean] def symlink?(path) if windows? require 'chef/win32/file' return Chef::ReservedNames::Win32::File.symlink?(path) end - ::File.symlink?(path) + ::File.symlink?(path) end # Returns the value of the readlink method. - # + # # @param path [String] the path to a symlink - # + # # @return [String] the path that the symlink points to def readlink(path) if windows? @@ -34,11 +34,11 @@ def readlink(path) end # Generates a command to execute that either uses the Unix cp - # command or the Windows copy command. + # command or the Windows copy command. # # @param source [String] the file to copy # @param destination [String] the path to copy the source to - # + # # @return [String] a useable command to copy a file def copy_command_for(source, destination) if windows? @@ -62,7 +62,7 @@ class << self # # @param environment [String] the environment # @param source [String] the deployment source to load configuration for - # + # # @return [Chef::DataBagItem] the data bag item def data_bag_config_for(environment, source) data_bag_item = if Chef::Config[:solo] @@ -155,7 +155,7 @@ def get_s3_object(bucket_name, object_name) # Nexus source. # # @param location [String] the artifact_location - # + # # @return [Boolean] true when the location is a colon-separated value def from_nexus?(location) !from_http?(location) && location.split(":").length > 2 @@ -173,9 +173,9 @@ def from_s3?(location) # Returns true when the artifact is believed to be from an # http source. - # + # # @param location [String] the artifact_location - # + # # @return [Boolean] true when the location matches http or https. def from_http?(location) location_of_type(location, %w(http https)) @@ -211,6 +211,15 @@ def snapshot?(version) version.end_with?("-SNAPSHOT") end + # Convenience method for determining whether a String is "release" + # + # @param version [String] the version of the configured artifact to check + # + # @return [Boolean] true when version matches (case-insensitive) "release" + def release?(version) + version.casecmp("release") == 0 + end + # Returns the currently deployed version of an artifact given that artifacts # installation directory by reading what directory the 'current' symlink # points to. @@ -218,10 +227,10 @@ def snapshot?(version) # indicated by the 'current' key is returned. # # @param deploy_to_dir [String] the directory where an artifact is installed - # + # # @example # Chef::Artifact.get_current_deployed_version("/opt/my_deploy_dir") => "2.0.65" - # + # # @return [String] the currently deployed version of the given artifact def get_current_deployed_version(deploy_to_dir) @@ -238,12 +247,12 @@ def get_current_deployed_version(deploy_to_dir) end # Looks for the given data bag in the cache and if not found, will load a - # data bag item named for the chef_environment, '_wildcard', or the old + # data bag item named for the chef_environment, '_wildcard', or the old # 'nexus' value. # # @param environment [String] the environment # @param data_bag [String] the data bag to load - # + # # @return [Chef::Mash] the data bag item in Mash form def encrypted_data_bag_for(environment, data_bag) @encrypted_data_bags = {} unless @encrypted_data_bags @@ -268,7 +277,7 @@ def encrypted_data_bags # Loads an entry from the encrypted_data_bags class variable. # # @param data_bag [String] the data bag to find - # + # # @return [type] [description] def get_from_data_bags_cache(data_bag) encrypted_data_bags[data_bag] @@ -280,15 +289,17 @@ def get_from_data_bags_cache(data_bag) # # @param data_bag [String] # @param data_bag_item [String] - # + # # @raise [Chef::Artifact::DataBagEncryptionError] when the data bag cannot be decrypted # or transformed into a Mash for some reason (Chef 10 vs Chef 11 data bag changes). - # + # # @return [Chef::Mash] def encrypted_data_bag_item(data_bag, data_bag_item) Mash.from_hash(Chef::EncryptedDataBagItem.load(data_bag, data_bag_item).to_hash) rescue Net::HTTPServerException => e nil + rescue ArgumentError, Errno::ENOENT + Mash.from_hash(Chef::DataBagItem.load(data_bag, data_bag_item).to_hash) rescue NoMethodError raise DataBagEncryptionError.new end diff --git a/libraries/chef_artifact_nexus.rb b/libraries/chef_artifact_nexus.rb index 26dec9a..078b892 100644 --- a/libraries/chef_artifact_nexus.rb +++ b/libraries/chef_artifact_nexus.rb @@ -28,7 +28,7 @@ def remote # @return [String] the version number that latest resolves to or the passed in value def get_actual_version(coordinates) artifact = NexusCli::Artifact.new(coordinates) - if Chef::Artifact.latest?(artifact.version) || Chef::Artifact.snapshot?(artifact.version) + if Chef::Artifact.release?(artifact.version) || Chef::Artifact.latest?(artifact.version) || Chef::Artifact.snapshot?(artifact.version) REXML::Document.new(remote.get_artifact_info(coordinates)).elements["//version"].text else artifact.version diff --git a/providers/deploy.rb b/providers/deploy.rb index 6ec1217..e0ab09e 100644 --- a/providers/deploy.rb +++ b/providers/deploy.rb @@ -50,7 +50,8 @@ def load_current_resource if Chef::Artifact.from_nexus?(@new_resource.artifact_location) chef_gem "nexus_cli" do - version "4.0.2" + version "4.1.1" + action :upgrade end @nexus_configuration_object = new_resource.nexus_configuration diff --git a/providers/file.rb b/providers/file.rb index c6b3265..5a11337 100644 --- a/providers/file.rb +++ b/providers/file.rb @@ -3,7 +3,7 @@ # Provider:: file # # Author:: Kyle Allan () -# +# # Copyright 2013, Riot Games # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,7 +32,8 @@ def load_current_resource if Chef::Artifact.from_nexus?(new_resource.location) chef_gem "nexus_cli" do - version "4.0.2" + version "4.1.1" + action :upgrade end @nexus_configuration = new_resource.nexus_configuration @@ -58,7 +59,7 @@ def load_current_resource run_proc :after_download end elsif Chef::Artifact.from_nexus?(file_location) - unless ::File.exists?(new_resource.path) && checksum_valid? && (!Chef::Artifact.snapshot?(file_location) || !Chef::Artifact.latest?(file_location)) + unless ::File.exists?(new_resource.path) && checksum_valid? && (!Chef::Artifact.snapshot?(file_location) || !Chef::Artifact.latest?(file_location) || !Chef::Artifact.release?(file_location)) begin if ::File.exists?(new_resource.path) if Digest::SHA1.file(new_resource.path).hexdigest != nexus_connection.get_artifact_sha(file_location) @@ -102,7 +103,7 @@ def checksum_valid? if cached_checksum_exists? if Chef::Artifact.from_nexus?(file_location) - if Chef::Artifact.snapshot?(file_location) || Chef::Artifact.latest?(file_location) + if Chef::Artifact.snapshot?(file_location) || Chef::Artifact.latest?(file_location) || Chef::Artifact.release?(file_location) return Digest::SHA1.file(new_resource.path).hexdigest == nexus_connection.get_artifact_sha(file_location) end end @@ -147,7 +148,7 @@ def run_proc(name) execute_run_proc("artifact_file", new_resource, name) end - # Scrubs the file_location and returns the path to + # Scrubs the file_location and returns the path to # the resource's checksum file. # # @return [String] @@ -178,7 +179,7 @@ def cached_checksum_exists? ::File.exists?(cached_checksum) end - # Writes a file to file_cache_path. This file contains a SHA256 digest of the + # Writes a file to file_cache_path. This file contains a SHA256 digest of the # artifact file. Returns the result of the file.puts command, which will be nil. # # @return [NilClass] diff --git a/providers/package.rb b/providers/package.rb index 0a5e429..9e770cd 100644 --- a/providers/package.rb +++ b/providers/package.rb @@ -26,7 +26,8 @@ def load_current_resource if Chef::Artifact.from_nexus?(new_resource.location) chef_gem "nexus_cli" do - version "4.0.2" + version "4.1.1" + action :upgrade end require 'nexus_cli' artifact = NexusCli::Artifact.new(new_resource.location) diff --git a/spec/libraries/chef_artifact_spec.rb b/spec/libraries/chef_artifact_spec.rb index 9da3cb4..ff43fb0 100644 --- a/spec/libraries/chef_artifact_spec.rb +++ b/spec/libraries/chef_artifact_spec.rb @@ -30,7 +30,7 @@ it "loads an encrypted data bag" do expect(data_bag_config_for.symbolize_keys).to eq(data_bag_item) - end + end end context "when loading legacy data bag format" do @@ -137,7 +137,7 @@ it "looks for the '_wildcard' data bag item" do described_class.stub(:encrypted_data_bag_item).and_return(nil, data_bag_item) described_class.should_receive(:encrypted_data_bag_item).with(data_bag, "_wildcard") - expect(encrypted_data_bag_for).to eq(data_bag_item) + expect(encrypted_data_bag_for).to eq(data_bag_item) end it "looks for the 'nexus' data bag item" do @@ -205,6 +205,12 @@ specify { described_class.latest?('3.0.1').should eq(false) } end + describe ":release?" do + specify { described_class.latest?('release').should eq(true) } + specify { described_class.latest?('RELease').should eq(true) } + specify { described_class.latest?('3.0.1').should eq(false) } + end + describe ":snapshot?" do specify { described_class.snapshot?('1.0.0-SNAPSHOT').should eq(true) } specify { described_class.snapshot?('3.0.1').should eq(false) }