Skip to content

Commit

Permalink
Fix: Allow 'Force' without IP address
Browse files Browse the repository at this point in the history
Adding host should allow use of 'force'
checkbox without IP address added, as the
idea is to allow adding host objects that
don't have DNS entries associated with them.

Fixes: freeipa#624
Signed-off-by: Carla Martinez <carlmart@redhat.com>
  • Loading branch information
carma12 committed Jan 30, 2025
1 parent 68584ac commit 35a50cf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
35 changes: 20 additions & 15 deletions src/components/modals/HostModals/AddHost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,6 @@ const AddHost = (props: PropsToAddHost) => {
pfError: ValidatedOptions.default,
});

useEffect(() => {
if (hostIpAddress === "") {
setForceCheckbox(false);
}
}, [hostIpAddress]);

const hostNameValidationHandler = (hostname: string) => {
if (hostname === "") {
const hostNameVal = {
Expand Down Expand Up @@ -218,8 +212,6 @@ const AddHost = (props: PropsToAddHost) => {
pfError: ValidatedOptions.error,
};
setHostIpAddressValidation(ipVal);
// Can not force DNS bypass without a valid IP address
setForceCheckbox(false);
}
}, [hostName, dnsZoneSelected, hostIpAddress]);

Expand Down Expand Up @@ -394,11 +386,12 @@ const AddHost = (props: PropsToAddHost) => {
name="forceCheckbox"
value="force"
onChange={handleForceCheckbox}
isDisabled={hostIpAddressValidation.isError || hostIpAddress === ""}
isDisabled={hostIpAddressValidation.isError}
/>
<HelperText>
<HelperTextItem variant="indeterminate">
Requires valid IP address
Allow adding host objects that does not have DNS entries
associated with them
</HelperTextItem>
</HelperText>
</div>
Expand Down Expand Up @@ -492,13 +485,25 @@ const AddHost = (props: PropsToAddHost) => {
}
const newHostPayload = {
fqdn: hostName + "." + dnsZone,
userclass: hostClass,
ip_address: hostIpAddress,
force: forceCheckbox,
description: description,
random: generateOtpCheckbox,
} as HostAddPayload;

// Add the rest of parameters if they are not empty
if (hostClass !== "") {
newHostPayload.userclass = hostClass;
}
if (hostIpAddress !== "") {
newHostPayload.ip_address = hostIpAddress;
}
if (forceCheckbox) {
newHostPayload.force = forceCheckbox;
}
if (description !== "") {
newHostPayload.description = description;
}
if (generateOtpCheckbox) {
newHostPayload.random = generateOtpCheckbox;
}

// Add host via API call
await executeHostAddCommand(newHostPayload).then((host) => {
if ("data" in host) {
Expand Down
17 changes: 10 additions & 7 deletions src/services/rpcHosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export interface HostAddPayload {
fqdn: string;
userclass?: string;
ip_address?: string;
force: boolean; // skip DNS check
random: boolean; // otp generation
force?: boolean; // skip DNS check
random?: boolean; // otp generation
description?: string;
}

Expand Down Expand Up @@ -109,13 +109,16 @@ const extendedApi = api.injectEndpoints({
[payloadData["fqdn"]],
{
version: API_VERSION_BACKUP,
userclass: payloadData["userclass"],
ip_address: payloadData["ip_address"],
force: payloadData["force"],
description: payloadData["description"],
random: payloadData["random"],
},
];
// Add the rest of parameters if they are not undefined
Object.keys(payloadData).forEach((key) => {
if (payloadData[key] !== undefined && key !== "fqdn") {
params[1][key] = payloadData[key];
}
});
console.log("params", params);

return getCommand({
method: "host_add",
params: params,
Expand Down

0 comments on commit 35a50cf

Please sign in to comment.