Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions lib/mixlib/install/generator/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,34 @@ def get_script(name, context = {})
self.class.get_script(name, context)
end

def license_availble?
options.license_id && !options.license_id.to_s.empty?
end

def license_type
return nil unless license_availble?

case options.license_id
when /trial/
"trial"
when /free/
"free"
else
"commercial"
end
end

def omnitruck_endpoint
case license_type
when "trial", "free"
Mixlib::Install::Dist::TRIAL_API_ENDPOINT
when "commercial"
Mixlib::Install::Dist::COMMERCIAL_API_ENDPOINT
else
Mixlib::Install::Dist::OMNITRUCK_ENDPOINT
end
end

def install_sh_from_upstream
uri = URI.parse(options.options[:new_omnibus_download_url])
response = Net::HTTP.get_response(uri)
Expand Down
10 changes: 5 additions & 5 deletions lib/mixlib/install/generator/bourne.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def self.install_sh(context)
install_command << get_script("check_product.sh")
install_command << get_script("platform_detection.sh")
install_command << get_script("proxy_env.sh")
install_command << get_script("fetch_metadata.sh", context)
install_command << get_script("fetch_package.sh")
install_command << get_script("fetch_metadata.sh", context.merge(omnitruck_endpoint: omnitruck_endpoint))
install_command << get_script("fetch_package.sh", context.merge(omnitruck_endpoint: omnitruck_endpoint))
install_command << get_script("install_package.sh")
install_command.join("\n\n")
end
Expand All @@ -49,8 +49,8 @@ def install_command
install_command << get_script("check_product.sh")
install_command << get_script("platform_detection.sh")
install_command << get_script("proxy_env.sh")
install_command << get_script("fetch_metadata.sh")
install_command << get_script("fetch_package.sh")
install_command << get_script("fetch_metadata.sh", omnitruck_endpoint: omnitruck_endpoint)
install_command << get_script("fetch_package.sh", omnitruck_endpoint: omnitruck_endpoint)
install_command << get_script("install_package.sh")

install_command.join("\n\n")
Expand All @@ -63,7 +63,7 @@ def render_variables
channel=#{options.channel}
EOS
# Add license_id if provided
if options.license_id && !options.license_id.to_s.empty?
if license_availble?
vars += "license_id=#{options.license_id}\n"
end
vars += install_command_vars
Expand Down
70 changes: 20 additions & 50 deletions lib/mixlib/install/generator/bourne/scripts/fetch_metadata.sh.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# $platform_version:
# $machine:
# $tmp_dir:
#
# $license_id
# $package_manager:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this new package_manager do and or used for? how does this affect linux clients?

# Outputs:
# $download_url:
# $sha256:
Expand All @@ -24,65 +25,34 @@ if test "x$download_url_override" = "x"; then

# Use commercial API if license_id is provided, otherwise use omnitruck
if test "x$license_id" != "x"; then
# Check if license_id starts with 'free-' or 'trial-' for trial API
case "$license_id" in
free-*|trial-*)
# Trial API endpoint
base_api_url="https://chefdownload-trial.chef.io"
;;
*)
# Commercial API endpoint
base_api_url="https://chefdownload-commercial.chef.io"
;;
esac
metadata_url="$base_api_url/$channel/$project/metadata?v=$version&p=$platform&pv=$platform_version&m=$machine&license_id=$license_id"
if [ ${project} = "chef-ice" ]; then
metadata_url="<%= omnitruck_endpoint %>/$channel/$project/metadata?v=$version&p=$platform&m=$machine&pm=$package_manager&license_id=$license_id"
else
metadata_url="<%= omnitruck_endpoint %>/$channel/$project/metadata?v=$version&p=$platform&pv=$platform_version&m=$machine&license_id=$license_id"
fi
else
# Omnitruck endpoint
metadata_url="<%= base_url %>/$channel/$project/metadata?v=$version&p=$platform&pv=$platform_version&m=$machine"
fi

do_download "$metadata_url" "$metadata_filename"

meta_response=$(cat "$metadata_filename")
modify_response $meta_response $metadata_filename
cat "$metadata_filename"

echo ""

# Commercial and trial APIs return JSON, omnitruck returns text format
if test "x$license_id" != "x"; then
# Parse JSON response from commercial/trial API
# Check if response looks like JSON
if grep -q '^{' "$metadata_filename" 2>/dev/null; then
# Extract url and sha256 from JSON
# Try using sed for simple JSON parsing (more portable than jq)
download_url=`sed -n 's/.*"url":"\([^"]*\)".*/\1/p' "$metadata_filename"`
sha256=`sed -n 's/.*"sha256":"\([^"]*\)".*/\1/p' "$metadata_filename"`

if test "x$download_url" != "x" && test "x$sha256" != "x"; then
echo "downloaded metadata file looks valid..."
else
echo "downloaded metadata file is corrupted or an uncaught error was encountered in downloading the file..."
report_bug
exit 1
fi
else
echo "downloaded metadata file is corrupted or an uncaught error was encountered in downloading the file..."
report_bug
exit 1
fi
# check that all the mandatory fields in the downloaded metadata are there
if grep '^url' $metadata_filename > /dev/null && grep '^sha256' $metadata_filename > /dev/null; then
echo "downloaded metadata file looks valid..."
else
# Parse text response from omnitruck
if grep '^url' $metadata_filename > /dev/null && grep '^sha256' $metadata_filename > /dev/null; then
echo "downloaded metadata file looks valid..."
download_url=`awk '$1 == "url" { print $2 }' "$metadata_filename"`
sha256=`awk '$1 == "sha256" { print $2 }' "$metadata_filename"`
else
echo "downloaded metadata file is corrupted or an uncaught error was encountered in downloading the file..."
# this generally means one of the download methods downloaded a 404 or something like that and then reported a successful exit code,
# and this should be fixed in the function that was doing the download.
report_bug
exit 1
fi
echo "downloaded metadata file is corrupted or an uncaught error was encountered in downloading the file..."
# this generally means one of the download methods downloaded a 404 or something like that and then reported a successful exit code,
# and this should be fixed in the function that was doing the download.
report_bug
exit 1
fi

download_url=`awk '$1 == "url" { print $2 }' "$metadata_filename"`
sha256=`awk '$1 == "sha256" { print $2 }' "$metadata_filename"`
else
download_url=$download_url_override
# Set sha256 to empty string if checksum not set
Expand Down
169 changes: 0 additions & 169 deletions lib/mixlib/install/generator/bourne/scripts/fetch_package.sh

This file was deleted.

Loading
Loading