@openshift-assisted/ui-lib
Version:
React component library for the Assisted Installer UI
103 lines • 6.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useInfraEnvProxies = exports.useNetworkingFormik = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const Yup = tslib_1.__importStar(require("yup"));
const common_1 = require("../common");
const utils_1 = require("../../../common/components/clusterConfiguration/utils");
const networkConfigurationValidation_1 = require("./networkConfigurationValidation");
const helpers_1 = require("../helpers");
const ClusterDeploymentNetworkingForm_1 = require("./ClusterDeploymentNetworkingForm");
const hooks_1 = require("../../../common/hooks");
const common_2 = require("../../../common");
const use_translation_wrapper_1 = require("../../../common/hooks/use-translation-wrapper");
const getInfraEnvProxy = (infraEnvs) => {
const infraEnvWithProxy = infraEnvs.find((ie) => { var _a, _b, _c, _d, _e, _f; return ((_b = (_a = ie.spec) === null || _a === void 0 ? void 0 : _a.proxy) === null || _b === void 0 ? void 0 : _b.httpProxy) || ((_d = (_c = ie.spec) === null || _c === void 0 ? void 0 : _c.proxy) === null || _d === void 0 ? void 0 : _d.httpsProxy) || ((_f = (_e = ie.spec) === null || _e === void 0 ? void 0 : _e.proxy) === null || _f === void 0 ? void 0 : _f.noProxy); });
return {
infraEnvWithProxy,
sameProxies: infraEnvs.every((ie) => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
return ((_b = (_a = ie.spec) === null || _a === void 0 ? void 0 : _a.proxy) === null || _b === void 0 ? void 0 : _b.httpProxy) === ((_d = (_c = infraEnvWithProxy === null || infraEnvWithProxy === void 0 ? void 0 : infraEnvWithProxy.spec) === null || _c === void 0 ? void 0 : _c.proxy) === null || _d === void 0 ? void 0 : _d.httpProxy) &&
((_f = (_e = ie.spec) === null || _e === void 0 ? void 0 : _e.proxy) === null || _f === void 0 ? void 0 : _f.httpsProxy) === ((_h = (_g = infraEnvWithProxy === null || infraEnvWithProxy === void 0 ? void 0 : infraEnvWithProxy.spec) === null || _g === void 0 ? void 0 : _g.proxy) === null || _h === void 0 ? void 0 : _h.httpsProxy) &&
((_k = (_j = ie.spec) === null || _j === void 0 ? void 0 : _j.proxy) === null || _k === void 0 ? void 0 : _k.noProxy) === ((_m = (_l = infraEnvWithProxy === null || infraEnvWithProxy === void 0 ? void 0 : infraEnvWithProxy.spec) === null || _l === void 0 ? void 0 : _l.proxy) === null || _m === void 0 ? void 0 : _m.noProxy);
}),
};
};
const getNetworkConfigurationValidationSchema = (initialValues, hostSubnets) => Yup.lazy((values) => Yup.object().shape({
clusterNetworkHostPrefix: (0, common_2.hostPrefixValidationSchema)(values.clusterNetworkCidr),
clusterNetworkCidr: (0, common_2.ipBlockValidationSchema)(values.serviceNetworkCidr),
serviceNetworkCidr: (0, common_2.ipBlockValidationSchema)(values.clusterNetworkCidr),
apiVips: (0, common_2.vipArrayValidationSchema)(hostSubnets, values, initialValues.apiVips),
ingressVips: (0, common_2.vipArrayValidationSchema)(hostSubnets, values, initialValues.ingressVips),
sshPublicKey: common_2.sshPublicKeyValidationSchema,
hostSubnet: common_2.hostSubnetValidationSchema,
httpProxy: (0, common_2.httpProxyValidationSchema)({ values, pairValueName: 'httpsProxy' }),
httpsProxy: (0, common_2.httpProxyValidationSchema)({ values, pairValueName: 'httpProxy' }),
noProxy: common_2.noProxyValidationSchema,
}));
const useNetworkingFormik = ({ clusterDeployment, agentClusterInstall, agents, }) => {
const initialValues = react_1.default.useMemo(() => {
const cluster = (0, helpers_1.getAICluster)({
clusterDeployment,
agentClusterInstall,
agents,
});
return Object.assign(Object.assign({}, (0, networkConfigurationValidation_1.getNetworkInitialValues)(cluster, ClusterDeploymentNetworkingForm_1.defaultNetworkSettings)), { enableProxy: false, editProxy: false });
}, []);
const validationSchema = react_1.default.useMemo(() => {
const cluster = (0, helpers_1.getAICluster)({
clusterDeployment,
agentClusterInstall,
agents,
});
const hostSubnets = (0, utils_1.getHostSubnets)(cluster);
return getNetworkConfigurationValidationSchema(initialValues, hostSubnets);
}, [initialValues, clusterDeployment, agentClusterInstall, agents]);
return {
initialValues,
validationSchema,
};
};
exports.useNetworkingFormik = useNetworkingFormik;
const useInfraEnvProxies = ({ agents, fetchInfraEnv }) => {
const [infraEnvs, setInfraEnvs] = react_1.default.useState();
const [infraEnvsError, setInfraEnvsError] = react_1.default.useState();
const { infraEnvWithProxy, sameProxies } = getInfraEnvProxy(infraEnvs || []);
const infraEnvsMetadata = agents
.map((a) => {
var _a, _b, _c;
return ({
name: (_b = (_a = a.metadata) === null || _a === void 0 ? void 0 : _a.labels) === null || _b === void 0 ? void 0 : _b[common_1.INFRAENV_AGENTINSTALL_LABEL_KEY],
namespace: (_c = a.metadata) === null || _c === void 0 ? void 0 : _c.namespace,
});
})
.filter((ie) => ie.name && ie.namespace)
.sort();
const memoInfraEnvs = (0, hooks_1.useDeepCompareMemoize)(infraEnvsMetadata);
const { t } = (0, use_translation_wrapper_1.useTranslation)();
react_1.default.useEffect(() => {
const fetch = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
setInfraEnvs(undefined);
setInfraEnvsError(undefined);
const infraEnvRequests = memoInfraEnvs.map((ie) => fetchInfraEnv(ie.name, ie.namespace));
try {
const infraEnvResults = yield Promise.all(infraEnvRequests);
setInfraEnvs(infraEnvResults);
}
catch (e) {
const error = e;
setInfraEnvsError(error.message || t('ai:Could not fetch infra environments'));
}
});
void fetch();
}, [memoInfraEnvs, fetchInfraEnv, setInfraEnvs, setInfraEnvsError, t]);
return {
infraEnvWithProxy,
sameProxies,
infraEnvsError,
infraEnvsLoading: !infraEnvs,
};
};
exports.useInfraEnvProxies = useInfraEnvProxies;
//# sourceMappingURL=use-networking-formik.js.map