Skip to content

Commit

Permalink
fixup! Fixes #36688 - Provide option to use wget for the new Register…
Browse files Browse the repository at this point in the history
… Host feature
  • Loading branch information
goarsna committed Aug 23, 2023
1 parent d0fb66c commit 4eeee55
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 71 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v2/registration_commands_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RegistrationCommandsController < V2::BaseController
param :update_packages, :bool, desc: N_("Update all packages on the host")
param :repo, String, desc: N_("Repository URL / details, for example for Debian OS family: 'deb http://deb.example.com/ buster 1.0', for Red Hat and SUSE OS family: 'http://yum.theforeman.org/client/latest/el8/x86_64/'")
param :repo_gpg_key_url, String, desc: N_("URL of the GPG key for the repository")
param :use_wget, :bool, desc: N_("Use wget instead of curl")
param :download_utility, String, desc: N_("The download utility to use for host registration")
end
def create
unless os_with_template?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def global_registration_vars
update_packages: params['update_packages'],
repo: params['repo'],
repo_gpg_key_url: params['repo_gpg_key_url'],
use_wget: params['use_wget'],
download_utility: params['download_utility'],
}

params.permit(permitted)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,27 @@ def registration_args
end

def insecure
if use_wget
registration_params['insecure'] ? ' --no-check-certificate' : ''
if registration_params['insecure']
if download_utility == 'curl'
' --insecure'
else
' --no-check-certificate'
end
else
registration_params['insecure'] ? ' --insecure' : ''
''
end
end

def application
use_wget ? 'wget --no-verbose -O-' : 'curl -sS'
if download_utility == 'curl'
'curl -sS'
else
'wget --no-verbose -O-'
end
end

def use_wget
return registration_params['use_wget']
def download_utility
return registration_params['download_utility']
end

def registration_url(proxy = nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export LC_ALL=C LANG=C
<%= "\n# Ignore subman errors: [#{@ignore_subman_errors}]" unless @ignore_subman_errors.nil? -%>
<%= "\n# Lifecycle environment id: [#{@lifecycle_environment_id}]" if @lifecycle_environment_id.present? -%>
<%= "\n# Activation keys: [#{activation_keys}]" if activation_keys.present? -%>
<%= "\n# Use wget: [#{@use_wget}]" unless @use_wget.nil? -%>
<%= "\n# Download utility: [#{@download_utility}]" unless @download_utility.nil? -%>


if ! [ $(id -u) = 0 ]; then
Expand Down Expand Up @@ -87,10 +87,10 @@ elif [ -f /etc/debian_version ]; then
<%= save_to_file('/etc/apt/sources.list.d/foreman_registration.list', @repo) %>
<%
if @use_wget
gpg_key_download_command="wget --no-verbose -O-"
else
if @download_utility == 'curl'
gpg_key_download_command="curl --silent --show-error"
else
gpg_key_download_command="wget --no-verbose -O-"
end
%>
Expand All @@ -107,16 +107,16 @@ fi
<% end -%>
<%
if @use_wget
data_keyword = "--post-data"
else
if @download_utility == 'curl'
data_keyword = "--data"
else
data_keyword = "--post-data"
end

if @use_wget
registration_command="wget --no-verbose -O- --ca-certificate"
else
if @download_utility == 'curl'
registration_command="curl --silent --show-error --request POST --cacert"
else
registration_command="wget --no-verbose -O- --ca-certificate"
end
%>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { STATUS } from '../../../../constants';
import { DownloadUtilities } from '../components/fields/DownloadUtility'

export const generalComponentProps = {
organizationId: 0,
Expand All @@ -21,8 +22,8 @@ export const generalComponentProps = {
handleInsecure: () => {},
handleInvalidField: () => {},
isLoading: false,
useWget: false,
handleUseWget: () => {},
downloadUtility: DownloadUtilities.curl,
handleDownloadUtility: () => {},
};
export const advancedComponentProps = {
configParams: {},
Expand Down Expand Up @@ -102,9 +103,9 @@ export const updatePackagesProps = {
isLoading: false,
};

export const useWgetProps = {
useWget: false,
handleUseWget: () => {},
export const downloadUtilityProps = {
downloadUtility: DownloadUtilities.curl,
handleDownloadUtility: () => {},
isLoading: false,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import HostGroup from './fields/HostGroup';
import OperatingSystem from './fields/OperatingSystem';
import SmartProxy from './fields/SmartProxy';
import Insecure from './fields/Insecure';
import UseWget from './fields/UseWget';
import DownloadUtility, { DownloadUtilities } from './fields/DownloadUtility';

const General = ({
organizationId,
Expand All @@ -29,8 +29,8 @@ const General = ({
handleInsecure,
handleInvalidField,
isLoading,
useWget,
handleUseWget,
downloadUtility,
handleDownloadUtility,
}) => (
<>
<Taxonomies
Expand Down Expand Up @@ -68,9 +68,9 @@ const General = ({
isLoading={isLoading}
/>

<UseWget
useWget={useWget}
handleUseWget={handleUseWget}
<DownloadUtility
downloadUtility={downloadUtility}
handleDownloadUtility={handleDownloadUtility}
isLoading={isLoading}
/>

Expand Down Expand Up @@ -106,8 +106,8 @@ General.propTypes = {
handleInsecure: PropTypes.func.isRequired,
handleInvalidField: PropTypes.func.isRequired,
isLoading: PropTypes.bool.isRequired,
useWget: PropTypes.bool.isRequired,
handleUseWget: PropTypes.func.isRequired,
downloadUtility: PropTypes.oneOf([DownloadUtilities.curl, DownloadUtilities.wget]).isRequired,
handleDownloadUtility: PropTypes.func.isRequired,
};

General.defaultProps = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react';
import PropTypes from 'prop-types';

import {
FormGroup,
FormSelect,
FormSelectOption,
} from '@patternfly/react-core';

import { translate as __ } from '../../../../../common/I18n';

export const DownloadUtilities = {
curl: 'curl',
wget: 'wget',
}
const DownloadUtility = ({ downloadUtility, handleDownloadUtility, isLoading }) => (
<FormGroup label={__('Download utility')} fieldId="reg_download_utility">
<FormSelect
ouiaId="reg_download_utility"
value={downloadUtility}
onChange={v => handleDownloadUtility(v)}
className="without_select2"
id="reg_download_utility"
isDisabled={isLoading}
>
{_.map(DownloadUtilities, (key, value) => (
<FormSelectOption key={key} value={value} label={value} />
))}
</FormSelect>
</FormGroup>
);

DownloadUtility.propTypes = {
downloadUtility: PropTypes.oneOf([DownloadUtilities.curl, DownloadUtilities.wget]),
handleHostGroup: PropTypes.func.isRequired,
isLoading: PropTypes.bool.isRequired,
};

DownloadUtility.defaultProps = {
downloadUtility: DownloadUtilities.curl,
};

export default DownloadUtility;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import Advanced from './components/Advanced';
import Actions from './components/Actions';
import Command from './components/Command';
import './RegistrationCommandsPage.scss';
import { DownloadUtilities } from './components/fields/DownloadUtility';

const RegistrationCommandsPage = () => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -91,7 +92,7 @@ const RegistrationCommandsPage = () => {
const [repo, setRepo] = useState('');
const [repoGpgKeyUrl, setRepoGpgKeyUrl] = useState('');
const [invalidFields, setInvalidFields] = useState([]);
const [useWget, setUseWget] = useState(false);
const [downloadUtility, setDownloadUtility] = useState(DownloadUtilities.curl);

// Command
const command = useSelector(selectCommand);
Expand Down Expand Up @@ -133,7 +134,7 @@ const RegistrationCommandsPage = () => {
repo,
repoGpgKeyUrl,
updatePackages,
useWget,
downloadUtility,
...pluginValues,
};

Expand Down Expand Up @@ -267,8 +268,8 @@ const RegistrationCommandsPage = () => {
handleInvalidField={handleInvalidField}
invalidFields={invalidFields}
isLoading={isLoading}
useWget={useWget}
handleUseWget={setUseWget}
downloadUtility={downloadUtility}
handleDownloadUtility={setDownloadUtility}
/>

<Slot
Expand Down

0 comments on commit 4eeee55

Please sign in to comment.