"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sshPublicKeyListValidationSchema = exports.sshPublicKeyValidationSchema = void 0;
const tslib_1 = require("tslib");
const Yup = tslib_1.__importStar(require("yup"));
const utils_1 = require("../components/ui/formik/utils");
const regexes_1 = require("./regexes");
const sshPublicKeyValidationSchema = (t) => Yup.string().test('ssh-public-key', t('ai:SSH public key must consist of "[TYPE] key [[EMAIL]]", supported types are: ssh-rsa, ssh-ed25519, ecdsa-[VARIANT]. A single key can be provided only.'), (value) => {
    if (!value) {
        return true;
    }
    return !!(0, utils_1.trimSshPublicKey)(value).match(regexes_1.SSH_PUBLIC_KEY_REGEX);
});
exports.sshPublicKeyValidationSchema = sshPublicKeyValidationSchema;
const sshPublicKeyListValidationSchema = (t) => Yup.string()
    .test('ssh-public-keys', t('ai:SSH public key must consist of "[TYPE] key [[EMAIL]]", supported types are: ssh-rsa, ssh-ed25519, ecdsa-[VARIANT].'), (value) => {
    if (!value) {
        return true;
    }
    return ((0, utils_1.trimSshPublicKey)(value)
        .split('\n')
        .find((line) => !line.match(regexes_1.SSH_PUBLIC_KEY_REGEX)) === undefined);
})
    .test('ssh-public-keys-unique', t('ai:SSH public keys must be unique.'), (value) => {
    if (!value) {
        return true;
    }
    const keyList = (0, utils_1.trimSshPublicKey)(value).split('\n');
    return new Set(keyList).size === keyList.length;
});
exports.sshPublicKeyListValidationSchema = sshPublicKeyListValidationSchema;
//# sourceMappingURL=sshValidation.js.map