Wizard: Add Satellite service and update mapper
This commit is contained in:
parent
58ec84c61e
commit
b6cdfdb102
5 changed files with 80 additions and 22 deletions
|
|
@ -7,9 +7,12 @@ import {
|
||||||
HelperTextItem,
|
HelperTextItem,
|
||||||
} from '@patternfly/react-core';
|
} from '@patternfly/react-core';
|
||||||
|
|
||||||
|
import { SATELLITE_SERVICE } from '../../../../../constants';
|
||||||
import { useAppDispatch, useAppSelector } from '../../../../../store/hooks';
|
import { useAppDispatch, useAppSelector } from '../../../../../store/hooks';
|
||||||
import {
|
import {
|
||||||
|
addEnabledService,
|
||||||
changeSatelliteRegistrationCommand,
|
changeSatelliteRegistrationCommand,
|
||||||
|
removeEnabledService,
|
||||||
selectSatelliteRegistrationCommand,
|
selectSatelliteRegistrationCommand,
|
||||||
} from '../../../../../store/wizardSlice';
|
} from '../../../../../store/wizardSlice';
|
||||||
import { useRegistrationValidation } from '../../../utilities/useValidation';
|
import { useRegistrationValidation } from '../../../utilities/useValidation';
|
||||||
|
|
@ -25,6 +28,11 @@ const SatelliteRegistrationCommand = () => {
|
||||||
'https://docs.redhat.com/en/documentation/red_hat_satellite/6.16/html-single/managing_hosts/index#Customizing_the_Registration_Templates_managing-hosts';
|
'https://docs.redhat.com/en/documentation/red_hat_satellite/6.16/html-single/managing_hosts/index#Customizing_the_Registration_Templates_managing-hosts';
|
||||||
|
|
||||||
const handleChange = (e: React.FormEvent, value: string) => {
|
const handleChange = (e: React.FormEvent, value: string) => {
|
||||||
|
if (!registrationCommand && !!value) {
|
||||||
|
dispatch(addEnabledService(SATELLITE_SERVICE));
|
||||||
|
} else if (!!registrationCommand && !value) {
|
||||||
|
dispatch(removeEnabledService(SATELLITE_SERVICE));
|
||||||
|
}
|
||||||
dispatch(changeSatelliteRegistrationCommand(value));
|
dispatch(changeSatelliteRegistrationCommand(value));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import { parseSizeUnit } from './parseSizeUnit';
|
||||||
import {
|
import {
|
||||||
CENTOS_9,
|
CENTOS_9,
|
||||||
FIRST_BOOT_SERVICE_DATA,
|
FIRST_BOOT_SERVICE_DATA,
|
||||||
|
SATELLITE_SERVICE_DATA,
|
||||||
RHEL_8,
|
RHEL_8,
|
||||||
RHEL_9,
|
RHEL_9,
|
||||||
RHEL_9_BETA,
|
RHEL_9_BETA,
|
||||||
|
|
@ -84,6 +85,8 @@ import {
|
||||||
selectUsers,
|
selectUsers,
|
||||||
selectMetadata,
|
selectMetadata,
|
||||||
selectFirewall,
|
selectFirewall,
|
||||||
|
selectSatelliteCaCertificate,
|
||||||
|
selectSatelliteRegistrationCommand,
|
||||||
} from '../../../store/wizardSlice';
|
} from '../../../store/wizardSlice';
|
||||||
import isRhel from '../../../Utilities/isRhel';
|
import isRhel from '../../../Utilities/isRhel';
|
||||||
import { FileSystemConfigurationType } from '../steps/FileSystem';
|
import { FileSystemConfigurationType } from '../steps/FileSystem';
|
||||||
|
|
@ -443,7 +446,9 @@ const getSatelliteCommand = (files?: File[]): string => {
|
||||||
const satelliteCommandFile = files?.find(
|
const satelliteCommandFile = files?.find(
|
||||||
(file) => file.path === '/usr/local/sbin/register-satellite-cmd'
|
(file) => file.path === '/usr/local/sbin/register-satellite-cmd'
|
||||||
);
|
);
|
||||||
return satelliteCommandFile?.data ? atob(satelliteCommandFile.data) : '';
|
return satelliteCommandFile?.data
|
||||||
|
? decodeURIComponent(atob(satelliteCommandFile.data))
|
||||||
|
: '';
|
||||||
};
|
};
|
||||||
|
|
||||||
const uploadTypeByTargetEnv = (imageType: ImageTypes): UploadTypes => {
|
const uploadTypeByTargetEnv = (imageType: ImageTypes): UploadTypes => {
|
||||||
|
|
@ -528,26 +533,42 @@ const getImageOptions = (
|
||||||
};
|
};
|
||||||
|
|
||||||
const getCustomizations = (state: RootState, orgID: string): Customizations => {
|
const getCustomizations = (state: RootState, orgID: string): Customizations => {
|
||||||
|
const satCert = selectSatelliteCaCertificate(state);
|
||||||
|
const files: File[] = [];
|
||||||
|
if (selectFirstBootScript(state)) {
|
||||||
|
files.push({
|
||||||
|
path: '/etc/systemd/system/custom-first-boot.service',
|
||||||
|
data: FIRST_BOOT_SERVICE_DATA,
|
||||||
|
data_encoding: 'base64',
|
||||||
|
ensure_parents: true,
|
||||||
|
});
|
||||||
|
files.push({
|
||||||
|
path: '/usr/local/sbin/custom-first-boot',
|
||||||
|
data: btoa(selectFirstBootScript(state)),
|
||||||
|
data_encoding: 'base64',
|
||||||
|
mode: '0774',
|
||||||
|
ensure_parents: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const satCmd = selectSatelliteRegistrationCommand(state);
|
||||||
|
if (satCmd && selectRegistrationType(state) === 'register-satellite') {
|
||||||
|
files.push({
|
||||||
|
path: '/etc/systemd/system/register-satellite.service',
|
||||||
|
data: SATELLITE_SERVICE_DATA,
|
||||||
|
data_encoding: 'base64',
|
||||||
|
ensure_parents: true,
|
||||||
|
});
|
||||||
|
files.push({
|
||||||
|
path: '/usr/local/sbin/register-satellite',
|
||||||
|
data: btoa(encodeURIComponent(satCmd)),
|
||||||
|
data_encoding: 'base64',
|
||||||
|
ensure_parents: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
containers: undefined,
|
containers: undefined,
|
||||||
directories: undefined,
|
directories: undefined,
|
||||||
files: selectFirstBootScript(state)
|
files: files.length > 0 ? files : undefined,
|
||||||
? [
|
|
||||||
{
|
|
||||||
path: '/etc/systemd/system/custom-first-boot.service',
|
|
||||||
data: FIRST_BOOT_SERVICE_DATA,
|
|
||||||
data_encoding: 'base64',
|
|
||||||
ensure_parents: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/usr/local/sbin/custom-first-boot',
|
|
||||||
data: btoa(selectFirstBootScript(state)),
|
|
||||||
data_encoding: 'base64',
|
|
||||||
mode: '0774',
|
|
||||||
ensure_parents: true,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: undefined,
|
|
||||||
subscription: getSubscription(state, orgID),
|
subscription: getSubscription(state, orgID),
|
||||||
packages: getPackages(state),
|
packages: getPackages(state),
|
||||||
payload_repositories: getPayloadRepositories(state),
|
payload_repositories: getPayloadRepositories(state),
|
||||||
|
|
@ -567,6 +588,12 @@ const getCustomizations = (state: RootState, orgID: string): Customizations => {
|
||||||
ignition: undefined,
|
ignition: undefined,
|
||||||
partitioning_mode: undefined,
|
partitioning_mode: undefined,
|
||||||
fips: undefined,
|
fips: undefined,
|
||||||
|
cacerts:
|
||||||
|
satCert && selectRegistrationType(state) === 'register-satellite'
|
||||||
|
? {
|
||||||
|
pem_certs: [satCert],
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -174,12 +174,13 @@ export function useRegistrationValidation(): StepValidation {
|
||||||
const token = match[1];
|
const token = match[1];
|
||||||
const decoded = jwtDecode(token);
|
const decoded = jwtDecode(token);
|
||||||
if (decoded.exp) {
|
if (decoded.exp) {
|
||||||
const currentTime = Date.now() / 1000;
|
const currentTimeSeconds = Date.now() / 1000;
|
||||||
if (decoded.exp < currentTime) {
|
const dayInSeconds = 86400;
|
||||||
|
if (decoded.exp < currentTimeSeconds + dayInSeconds) {
|
||||||
const expirationDate = new Date(decoded.exp * 1000);
|
const expirationDate = new Date(decoded.exp * 1000);
|
||||||
Object.assign(errors, {
|
Object.assign(errors, {
|
||||||
command:
|
command:
|
||||||
'The token is already expired. Expiration date: ' +
|
'The token is already expired or will expire by next day. Expiration date: ' +
|
||||||
expirationDate,
|
expirationDate,
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -261,6 +261,28 @@ WantedBy=graphical.target
|
||||||
|
|
||||||
export const FIRST_BOOT_SERVICE = 'custom-first-boot';
|
export const FIRST_BOOT_SERVICE = 'custom-first-boot';
|
||||||
|
|
||||||
|
export const SATELLITE_SERVICE_DATA = btoa(`[Unit]
|
||||||
|
Description=Custom first boot script
|
||||||
|
ConditionFileIsExecutable=/usr/local/sbin/register-satellite
|
||||||
|
ConditionPathExists=!/var/local/.register-satellite-done
|
||||||
|
Wants=network-online.target
|
||||||
|
After=network-online.target
|
||||||
|
After=osbuild-first-boot.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/usr/local/sbin/register-satellite
|
||||||
|
ExecStartPost=/usr/bin/touch /var/local/.register-satellite-done
|
||||||
|
RemainAfterExit=yes
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=basic.target
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
WantedBy=graphical.target
|
||||||
|
`);
|
||||||
|
|
||||||
|
export const SATELLITE_SERVICE = 'register-satellite';
|
||||||
|
|
||||||
// For use when calling content API (now required)
|
// For use when calling content API (now required)
|
||||||
export enum ContentOrigin {
|
export enum ContentOrigin {
|
||||||
'REDHAT' = 'red_hat',
|
'REDHAT' = 'red_hat',
|
||||||
|
|
|
||||||
|
|
@ -348,7 +348,7 @@ export const selectActivationKey = (state: RootState) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const selectSatelliteRegistrationCommand = (state: RootState) => {
|
export const selectSatelliteRegistrationCommand = (state: RootState) => {
|
||||||
return state.wizard.registration.satelliteRegistration.command;
|
return state.wizard.registration.satelliteRegistration?.command;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const selectSatelliteCaCertificate = (state: RootState) => {
|
export const selectSatelliteCaCertificate = (state: RootState) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue