in guacamole/src/main/frontend/src/app/import/services/connectionParseService.js [430:538]
function getFieldTransformer() {
return getProtocolParameterOptions().then(protocols => connection => {
// Ensure that a protocol was specified for this connection
const protocol = connection.protocol;
if (!protocol)
connection.errors.push(new ParseError({
message: 'Missing required protocol field',
key: 'IMPORT.ERROR_REQUIRED_PROTOCOL_CONNECTION'
}));
// Ensure that a valid protocol was specified for this connection
if (!protocols[protocol])
connection.errors.push(new ParseError({
message: 'Invalid protocol: ' + protocol,
key: 'IMPORT.ERROR_INVALID_PROTOCOL',
variables: { PROTOCOL: protocol }
}));
// Ensure that a name was specified for this connection
if (!connection.name)
connection.errors.push(new ParseError({
message: 'Missing required name field',
key: 'IMPORT.ERROR_REQUIRED_NAME_CONNECTION'
}));
// Ensure that the specified user list, if any, is an array
const users = connection.users;
if (users) {
// Ensure all users in the array are trimmed strings
if (Array.isArray(users))
connection.users = users.map(user => String(user).trim());
else
connection.errors.push(new ParseError({
message: 'Invalid users list - must be an array',
key: 'IMPORT.ERROR_INVALID_USERS_TYPE'
}));
}
// Ensure that the specified user group list, if any, is an array
const groups = connection.groups;
if (groups) {
// Ensure all groups in the array are trimmed strings
if (Array.isArray(groups))
connection.groups = groups.map(group => String(group).trim());
else
connection.errors.push(new ParseError({
message: 'Invalid groups list - must be an array',
key: 'IMPORT.ERROR_INVALID_USER_GROUPS_TYPE'
}));
}
// If the protocol is not valid, there's no point in trying to check
// parameter case sensitivity
if (!protocols[protocol])
return connection;
_.forEach(connection.parameters, (value, name) => {
// An explicit null value for a parameter is valid - do not
// process it further
if (value === null)
return;
// All non-null connection parameters must be strings.
const stringValue = String(value);
// Convert the provided value to the format that would match
// the lookup object format
const comparisonValue = stringValue.toLowerCase().trim();
// The validated / corrected option value for this connection
// parameter, if any
const validOptionValue = _.get(
protocols, [protocol, name, comparisonValue]);
// If the provided value fuzzily matches a valid option value,
// use the valid option value instead
if (validOptionValue)
connection.parameters[name] = validOptionValue;
// Even if no option is found, the value must be a string
else
connection.parameters[name] = stringValue;
});
_.forEach(connection.attributes, (value, name) => {
// An explicit null value for an attribute is valid - do not
// process it further
if (value === null)
return;
// All non-null connection attributes must be strings
connection.attributes[name] = String(value);
});
return connection;
});
}