Add Activation Key Support For Customer Portal

This patch adds support to register with the hosted customer portal
using activation keys.  If an activation key is present in either
the REG_ACTIVATION_KEY or rh_registration.activation_key, it will
use that value instead of username and password credentials when
registering with Satellite or the hosted Customer Portal.  This
patch also enforces that an org must be set in either the REG_ORG
or rh_registration.org to use the activation key.

Change-Id: If40dd78ba793d508afb1a5ab345470ee5929afb0
This commit is contained in:
Ryan Brady 2014-11-26 10:25:31 -05:00
parent 37ec06cd0b
commit bf8b77a8ea
2 changed files with 51 additions and 47 deletions

View File

@ -64,12 +64,20 @@ if [ -n "${REG_SERVER_URL:-}" ]; then
opts="$opts --serverurl=$REG_SERVER_URL" opts="$opts --serverurl=$REG_SERVER_URL"
fi fi
if [ -n "${REG_USER:-}" ]; then if [ -n "${REG_ACTIVATION_KEY:-}" ]; then
opts="$opts --username $REG_USER" opts="$opts --activationkey=$REG_ACTIVATION_KEY"
fi
if [ -n "${REG_PASSWORD:-}" ]; then if [ -z "${REG_ORG:-}" ]; then
opts="$opts --password $REG_PASSWORD" echo "WARNING: REG_ACTIVATION_KEY set without REG_ORG."
fi
else
if [ -n "${REG_PASSWORD:-}" ]; then
opts="$opts --password $REG_PASSWORD"
fi
if [ -n "${REG_USER:-}" ]; then
opts="$opts --username $REG_USER"
fi
fi fi
if [ -n "${REG_MACHINE_NAME:-}" ]; then if [ -n "${REG_MACHINE_NAME:-}" ]; then
@ -79,18 +87,19 @@ fi
if [ -n "${REG_ORG:-}" ]; then if [ -n "${REG_ORG:-}" ]; then
opts="$opts --org $REG_ORG" opts="$opts --org $REG_ORG"
fi fi
if [ -n "${REG_REPOS:-}" ]; then
for repo in $REG_REPOS; do
repos="$repos --enable $repo"
done
fi
if [ -n "${REG_TYPE:-}" ]; then
opts="$opts --type=$REG_TYPE"
fi
case "${REG_METHOD:-}" in case "${REG_METHOD:-}" in
portal) portal)
if [ -n "${REG_ACTIVATION_KEY:-}" ]; then
echo "WARNING: Activation keys are not supported by the customer portal at this time."
fi
if [ -n "${REG_REPOS:-}" ]; then
for repo in $REG_REPOS; do
repos="$repos --enable $repo"
done
fi
subscription-manager register $opts subscription-manager register $opts
if [ -z "${REG_AUTO_ATTACH:-}" ]; then if [ -z "${REG_AUTO_ATTACH:-}" ]; then
subscription-manager attach $attach_opts subscription-manager attach $attach_opts
@ -99,12 +108,6 @@ case "${REG_METHOD:-}" in
;; ;;
satellite) satellite)
repos="$repos --enable ${satellite_repo}" repos="$repos --enable ${satellite_repo}"
if [ -n "${REG_REPOS:-}" ]; then
for repo in $REG_REPOS; do
repos="$repos --enable $repo"
done
fi
rpm -Uvh "$REG_SAT_URL/pub/katello-ca-consumer-latest.noarch.rpm" || true rpm -Uvh "$REG_SAT_URL/pub/katello-ca-consumer-latest.noarch.rpm" || true
subscription-manager register $opts subscription-manager register $opts
subscription-manager $repos subscription-manager $repos
@ -115,5 +118,5 @@ case "${REG_METHOD:-}" in
;; ;;
*) *)
echo "WARNING: only 'portal' and 'satellite' are valid values for REG_METHOD." echo "WARNING: only 'portal' and 'satellite' are valid values for REG_METHOD."
exit 0 exit 0 # keeps the stack from failing if you don't set a value in REG_METHOD
esac esac

View File

@ -5,6 +5,7 @@ set -o pipefail
opts= opts=
attach_opts= attach_opts=
repos="repos --enable rhel-7-server-rpms" repos="repos --enable rhel-7-server-rpms"
satellite_repo="rhel-7-server-rh-common-beta-rpms"
if [ -n "${REG_AUTO_ATTACH:-}" ]; then if [ -n "${REG_AUTO_ATTACH:-}" ]; then
opts="$opts --auto-attach" opts="$opts --auto-attach"
@ -30,8 +31,6 @@ else
fi fi
fi fi
if [ -n "${REG_BASE_URL:-}" ]; then if [ -n "${REG_BASE_URL:-}" ]; then
opts="$opts --baseurl=$REG_BASE_URL" opts="$opts --baseurl=$REG_BASE_URL"
fi fi
@ -48,12 +47,20 @@ if [ -n "${REG_SERVER_URL:-}" ]; then
opts="$opts --serverurl=$REG_SERVER_URL" opts="$opts --serverurl=$REG_SERVER_URL"
fi fi
if [ -n "${REG_USER:-}" ]; then if [ -n "${REG_ACTIVATION_KEY:-}" ]; then
opts="$opts --username $REG_USER" opts="$opts --activationkey=$REG_ACTIVATION_KEY"
fi
if [ -n "${REG_PASSWORD:-}" ]; then if [ -z "${REG_ORG:-}" ]; then
opts="$opts --password $REG_PASSWORD" echo "WARNING: REG_ACTIVATION_KEY set without REG_ORG."
fi
else
if [ -n "${REG_PASSWORD:-}" ]; then
opts="$opts --password $REG_PASSWORD"
fi
if [ -n "${REG_USER:-}" ]; then
opts="$opts --username $REG_USER"
fi
fi fi
if [ -n "${REG_MACHINE_NAME:-}" ]; then if [ -n "${REG_MACHINE_NAME:-}" ]; then
@ -64,18 +71,18 @@ if [ -n "${REG_ORG:-}" ]; then
opts="$opts --org $REG_ORG" opts="$opts --org $REG_ORG"
fi fi
if [ -n "${REG_REPOS:-}" ]; then
for repo in $REG_REPOS; do
repos="$repos --enable $repo"
done
fi
if [ -n "${REG_TYPE:-}" ]; then
opts="$opts --type=$REG_TYPE"
fi
case "${REG_METHOD:-}" in case "${REG_METHOD:-}" in
portal) portal)
if [ -n "${REG_ACTIVATION_KEY:-}" ]; then
echo "WARNING: Activation keys are not supported by the customer portal at this time."
fi
if [ -n "${REG_REPOS:-}" ]; then
for repo in $REG_REPOS; do
repos="$repos --enable $repo"
done
fi
subscription-manager register $opts subscription-manager register $opts
if [ -z "${REG_AUTO_ATTACH:-}" ]; then if [ -z "${REG_AUTO_ATTACH:-}" ]; then
subscription-manager attach $attach_opts subscription-manager attach $attach_opts
@ -83,13 +90,7 @@ case "${REG_METHOD:-}" in
subscription-manager $repos subscription-manager $repos
;; ;;
satellite) satellite)
repos="$repos --enable rhel-7-server-rh-common-beta-rpms" repos="$repos --enable ${satellite_repo}"
if [ -n "${REG_REPOS:-}" ]; then
for repo in $REG_REPOS; do
repos="$repos --enable $repo"
done
fi
rpm -Uvh "$REG_SAT_URL/pub/katello-ca-consumer-latest.noarch.rpm" || true rpm -Uvh "$REG_SAT_URL/pub/katello-ca-consumer-latest.noarch.rpm" || true
subscription-manager register $opts subscription-manager register $opts
subscription-manager $repos subscription-manager $repos
@ -98,5 +99,5 @@ case "${REG_METHOD:-}" in
;; ;;
*) *)
echo "WARNING: only 'portal' and 'satellite' are valid values for REG_METHOD." echo "WARNING: only 'portal' and 'satellite' are valid values for REG_METHOD."
exit 1 exit 1 # RHEL requires registration, fail image build if REG_Method isn't set
esac esac