Skip to content
Open
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
29 changes: 16 additions & 13 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ Mixlib::Install is a library for interacting with Chef Software Inc's software d
**Primary Goal**: Support the widest range of Ruby versions possible to ensure compatibility across diverse Chef environments.

**Recent Major Changes** (v3.13.0 - v3.15.0):
- **PR #417**: Added chef-ice product with package_manager parameter support
- Implemented platform normalization (`Util.normalize_platform_for_commercial`) for chef-ice
- Added package manager detection (`Util.determine_package_manager`) for automatic format selection
- Updated URL construction to use `m`, `p`, `pm` parameters for chef-ice (vs. `p`, `pv`, `m` for standard products)
- Modified shell and PowerShell scripts to handle chef-ice metadata URLs
- **PR #417**: Added chef-ice and inspec-enterprise product support with server-side pm derivation
- Server (omnitruck-service) derives package manager (`pm`) from platform automatically; no client-side detection
- Client sends platform as-is (`p=$platform`); no client-side normalization
- Single unified metadata URL for all products: `v`, `p`, `pv`, `m`, optional `pm`, optional `license_id`
- `-i <package_manager>` shell flag and `$package_manager` PowerShell parameter allow explicit pm override when needed
- Added `inspec-enterprise` product to product matrix
- **PR #408, #416**: Added commercial and trial API support for licensed Chef products
- Implemented license_id parameter for install scripts and API calls
- Added trial API automatic defaults enforcement (stable channel, latest version only with warnings)
Expand Down Expand Up @@ -284,10 +285,11 @@ The library includes sophisticated platform version compatibility logic:
- Fallback: Constructs filename from platform metadata if extraction fails
- Renames temp file to extracted/constructed filename
- Works with all download methods: wget, curl, fetch, perl, python
- **Chef-ICE Support**: Includes platform normalization and package manager detection functions
- `determine_package_manager()` - Detects package format based on platform
- `normalize_platform_name()` - Maps specific platforms to generic categories (linux, macos, windows, unix)
- Conditional URL construction based on product type (chef-ice vs. standard products)
- **Package Manager Override (`-i` flag)**: Optional flag for explicit pm control
- Default: omitted — server derives `pm` from platform automatically
- When `-i <pm>` is passed, appends `&pm=<value>` to the metadata URL
- No client-side `determine_package_manager()` or `normalize_platform_name()` functions
- Single unified metadata URL for all products, including chef-ice and inspec-enterprise

### PowerShell (install.ps1)
- Supports: http_proxy
Expand All @@ -304,10 +306,10 @@ The library includes sophisticated platform version compatibility logic:
- Parses JSON responses with `ConvertFrom-Json`
- Extracts `url` and `sha256` from JSON object
- Automatically routes to trial or commercial API based on license_id prefix
- **Chef-ICE Support**: Simplified parameters for Windows
- Uses `p=windows`, `m=<arch>`, `pm=msi` parameters for chef-ice
- Conditional logic to select appropriate metadata URL format based on product type
- Handles both chef-ice and standard product URL construction
- **Package Manager Override (`$package_manager`)**: Optional parameter for explicit pm control
- Default: empty — server derives `pm` from platform automatically
- When non-empty, appends `&pm=<value>` to the metadata URL
- No product-specific conditional URL branches; single unified URL for all products

### Script Options
- `download_url_override`: Direct URL instead of API lookup
Expand All @@ -316,6 +318,7 @@ The library includes sophisticated platform version compatibility logic:
- `license_id`: License ID for commercial/trial API access (format: `free-*`, `trial-*`, or standard license ID)
- `base_api_url` (shell): Override API endpoint (optional, auto-detected from license_id if not provided)
- `base_server_uri` (PowerShell): Override API endpoint (optional, auto-detected from license_id if not provided)
- `-i <pm>` / `$package_manager`: Explicit package manager override (e.g. `msi`, `zip`). Omit to let the server derive it from platform. Appends `&pm=<value>` to the metadata URL when set.

## API Usage Patterns

Expand Down
1 change: 1 addition & 0 deletions PRODUCT_MATRIX.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
| Chef Infra Server High Availability addon | ha |
| Harmony - Omnibus Integration Internal Test Project | harmony |
| Chef InSpec | inspec |
| Chef InSpec Enterprise | inspec-enterprise |
| Habitat Mac Bootstrapper | mac-bootstrapper |
| Management Console | manage |
| Chef Cloud Marketplace addon | marketplace |
Expand Down
62 changes: 11 additions & 51 deletions lib/mixlib/install/generator/bourne/scripts/fetch_metadata.sh.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,46 +25,6 @@
# $sha256:
############

# Determine package manager based on platform for commercial API
determine_package_manager() {
case "$platform" in
el|centos|rhel|fedora|amazon|rocky|opensuse*|sles|scientific)
echo "rpm"
;;
debian|ubuntu|linuxmint|raspbian)
echo "deb"
;;
mac_os_x|macos|solaris*|smartos|freebsd|aix|omnios)
echo "tar"
;;
*)
echo "tar"
;;
esac
}

# Normalize platform name for commercial API
normalize_platform_name() {
case "$platform" in
el|centos|rhel|fedora|rocky|scientific)
echo "linux"
;;
mac_os_x|macos)
echo "macos"
;;
debian|ubuntu|linuxmint|raspbian)
echo "linux"
;;
freebsd|aix|solaris*|smartos|omnios)
echo "unix"
;;
*)
# For anything else, use linux as default
echo "linux"
;;
esac
}

if [ -z "$download_url_override" ]; then
echo "Getting information for $project $channel $version for $platform..."

Expand Down Expand Up @@ -96,21 +56,21 @@ if [ -z "$download_url_override" ]; then
fi
fi

# For chef-ice product, add platform (p), machine (m), and package_manager (pm) parameters
if [ -n "$license_id" ]; then
if [ "$project" = "chef-ice" ]; then
package_manager=$(determine_package_manager)
platform_param=$(normalize_platform_name)
metadata_url="$base_api_url/$channel/$project/metadata?license_id=$license_id&v=$version&m=$machine&p=$platform_param&pm=$package_manager"
else
# For other products, use standard parameters
metadata_url="$base_api_url/$channel/$project/metadata?license_id=$license_id&v=$version&p=$platform&pv=$platform_version&m=$machine"
fi
license_param="&license_id=$license_id"
else
# Omnitruck URL parameters without license_id
metadata_url="$base_api_url/$channel/$project/metadata?v=$version&p=$platform&pv=$platform_version&m=$machine"
license_param=""
fi

if [ -n "$package_manager" ]; then
pm_param="&pm=$package_manager"
else
pm_param=""
fi

# Build the metadata URL.
metadata_url="$base_api_url/$channel/$project/metadata?v=$version&p=$platform&pv=$platform_version&m=$machine${license_param}${pm_param}"

do_download "$metadata_url" "$metadata_filename"

cat "$metadata_filename"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# $version: Requested version to be installed.
# $channel: Channel to install the product from
# $project: Project to be installed
# $package_manager: (Optional) Package manager override (e.g. rpm, deb, tar, msi).
# If omitted, the server derives it from the platform (p) parameter.
# $cmdline_filename: Name of the package downloaded on local disk.
# $cmdline_dl_dir: Name of the directory downloaded package will be saved to on local disk.
# $install_strategy: Method of package installations. default strategy is to always install upon exec. Set to "once" to skip if project is installed
Expand All @@ -18,9 +20,10 @@
# Defaults
channel="stable"
project="<%= default_product %>"
package_manager=""
<%= "license_id=\"#{license_id}\"" if license_id && !license_id.to_s.empty? %>

while getopts pnv:b:c:f:P:d:s:l:a:L: opt
while getopts pnv:b:c:f:P:d:s:l:a:L:i: opt
do
case "$opt" in

Expand All @@ -36,9 +39,10 @@ do
l) download_url_override="$OPTARG";;
a) checksum="$OPTARG";;
L) license_id="$OPTARG";;
i) package_manager="$OPTARG";;
\?) # unknown flag
echo >&2 \
"usage: $0 [-P project] [-b base_api_url] [-c release_channel] [-v version] [-f filename | -d download_dir] [-s install_strategy] [-l download_url_override] [-a checksum] [-L license_id]"
"usage: $0 [-P project] [-b base_api_url] [-c release_channel] [-v version] [-f filename | -d download_dir] [-s install_strategy] [-l download_url_override] [-a checksum] [-L license_id] [-i package_manager]"
exit 1;;
esac
done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ function Get-ProjectMetadata {
$architecture = 'auto',
# License ID for commercial API access
[string]
$license_id <%= "= '#{license_id}'" if license_id && !license_id.to_s.empty? %>
$license_id <%= "= '#{license_id}'" if license_id && !license_id.to_s.empty? %>,
# Package manager override (e.g. msi, zip). If omitted, the server derives it from platform.
[string]
$package_manager
)

# The following legacy switches are just aliases for the current channel
Expand Down Expand Up @@ -88,23 +91,28 @@ function Get-ProjectMetadata {
}
}

# For chef-ice product, add platform (p), machine (m), and package_manager (pm) parameters
# Only include pm param when the caller explicitly passed -package_manager;
# the server derives it from the platform (p) parameter otherwise.

if (-not [string]::IsNullOrEmpty($package_manager)) {
$pm_param = "&pm=$package_manager"
}
else {
$pm_param = ""
}

# License param (appended only when a license_id is present)
$license_param = ""
if (-not [string]::IsNullOrEmpty($license_id)) {
if ($project -eq "chef-ice") {
$package_manager = "msi"
$platform_param = "windows"
$metadata_url = "$base_server_uri$channel/$project/metadata?license_id=$license_id&v=$version&m=$architecture&p=$platform_param&pm=$package_manager"
}
else {
# For other products, use standard parameters
$metadata_url = "$base_server_uri$channel/$project/metadata?license_id=$license_id&v=$version&p=$platform&pv=$platform_version&m=$architecture"
}
$license_param = "&license_id=$license_id"
}
else {
# Omnitruck URL parameters without license_id
$metadata_url = "$base_server_uri$channel/$project/metadata?v=$version&p=$platform&pv=$platform_version&m=$architecture"
$license_param = ""
}

# Build the metadata URL.
$metadata_url = "$base_server_uri$channel/$project/metadata?v=$version&p=$platform&pv=$platform_version&m=$architecture$license_param$pm_param"

Write-Host "Downloading $project details from $metadata_url"
$response = (Get-WebContent $metadata_url).trim()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ function Install-Project {
$base_server_uri,
# License ID for commercial API access
[string]
$license_id <%= "= '#{license_id}'" if license_id && !license_id.to_s.empty? %>
$license_id <%= "= '#{license_id}'" if license_id && !license_id.to_s.empty? %>,
# Package manager override (e.g. msi, zip). If omitted, the server derives it from platform.
[string]
$package_manager
)

# Use CHEF_LICENSE_KEY environment variable if license_id not provided
Expand Down Expand Up @@ -106,7 +109,7 @@ function Install-Project {
$download_url = $download_url_override
$sha256 = $checksum
} else {
$package_metadata = Get-ProjectMetadata -project $project -channel $channel -version $version -prerelease:$prerelease -nightlies:$nightlies -architecture $architecture -base_server_uri $base_server_uri -license_id $license_id
$package_metadata = Get-ProjectMetadata -project $project -channel $channel -version $version -prerelease:$prerelease -nightlies:$nightlies -architecture $architecture -base_server_uri $base_server_uri -license_id $license_id -package_manager $package_manager
$download_url = $package_metadata.url
$sha256 = $package_metadata.sha256
}
Expand Down
5 changes: 5 additions & 0 deletions lib/mixlib/install/product_matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@
package_name "inspec"
end

product "inspec-enterprise" do
product_name "Chef InSpec Enterprise"
package_name "inspec-enterprise"
end

product "mac-bootstrapper" do
product_name "Habitat Mac Bootstrapper"
package_name "mac-bootstrapper"
Expand Down
1 change: 1 addition & 0 deletions mixlib-install.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Gem::Specification.new do |spec|

spec.add_dependency "mixlib-shellout"
spec.add_dependency "mixlib-versioning"
spec.add_dependency "ostruct"
spec.add_dependency "thor"
spec.required_ruby_version = ">= 2.6"
end
Loading
Loading