How to use the restify.ConflictError function in restify

To help you get started, we’ve selected a few restify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github joyent / node-workflow / lib / api.js View on Github external
backend.getJob(req.params.uuid, function (err, job) {
            if (err) {
                return next(err.toRestError);
            } else if (job.execution === 'succeeded' ||
                            job.execution === 'failed') {
                return next(new restify.ConflictError(
                  'Finished jobs cannot be canceled'));
            } else {
                // If Request-Id hasn't been set, we'll set it to job UUID:
                if (!req.headers['request-id']) {
                    res.header('request-id',  req.params.uuid);
                }
                meta.req_id = req.id;

                return backend.updateJobProperty(
                  job.uuid,
                  'execution',
                  'canceled',
                  meta,
                  function (err) {
                    if (err) {
                        return next(new restify.InternalError(err));
github joyent / node-workflow / lib / api.js View on Github external
backend.getJob(req.params.uuid, function (err, job) {
            if (err) {
                return next(err.toRestError);
            } else if (job.execution !== 'waiting') {
                return next(new restify.ConflictError(
                  'Only waiting jobs can be resumed'));
            } else {
                // If Request-Id hasn't been set, we'll set it to job UUID:
                if (!req.headers['request-id']) {
                    res.header('request-id',  req.params.uuid);
                }
                meta.req_id = req.id;

                job.execution = (req.params.error) ? 'failed' : 'queued';
                var r = job.chain_results[job.chain_results.length - 1];
                r.result = (req.params.result) ? req.params.result :
                    ((req.params.error) ? '' : 'External task: OK');
                r.error = (req.params.error) ? req.params.error: '';
                r.finished_at = new Date().toISOString();
                job.chain_results[job.chain_results.length - 1] = r;
github joyent / sdc-adminui / lib / amon.js View on Github external
config: req.body.config || {},
        name: req.body.name
    };

    if (typeof (user) === 'undefined') {
        res.send(new restify.ConflictError('user must be provided!'));
        return next();
    }

    if (typeof (probe.type) === 'undefined') {
        res.send(new restify.ConflictError('type must be provided!'));
        return next();
    }

    if (typeof (probe.name) === 'undefined') {
        res.send(new restify.ConflictError('name must be provided!'));
        return next();
    }

    if (typeof (probe.config) !== 'object') {
        res.send(new restify.ConflictError('config is required'));
        return next();
    }


    if (typeof (req.body.machine) !== 'undefined') {
        probe.machine = req.body.machine;
    }

    if (typeof (req.body.agent) !== 'undefined') {
        probe.agent = req.body.agent;
    }
github joyent / sdc-adminui / lib / images.js View on Github external
function importRemote(req, res, next) {
    var uuid = req.params.uuid;
    var source = req.body.source;

    if (typeof (uuid) !== 'string') {
        return next(new restify.ConflictError('uuid required'));
    }

    if (typeof (source) !== 'string') {
        return next(new restify.ConflictError('source required'));
    }

    var options = {};
    options.skipOwnerCheck = req.body.skipOwnerCheck || true;

    req.sdc[req.dc].imgapi.adminImportRemoteImage(
        uuid,
        source,
        options,
        function (err, job, imgapiRes) {

        if (err) {
github joyent / sdc-adminui / lib / amon.js View on Github external
function createProbe(req, res, next) {
    var user = req.body.user;
    var probe = {
        type: req.body.type,
        contacts: ['email'],
        config: req.body.config || {},
        name: req.body.name
    };

    if (typeof (user) === 'undefined') {
        res.send(new restify.ConflictError('user must be provided!'));
        return next();
    }

    if (typeof (probe.type) === 'undefined') {
        res.send(new restify.ConflictError('type must be provided!'));
        return next();
    }

    if (typeof (probe.name) === 'undefined') {
        res.send(new restify.ConflictError('name must be provided!'));
        return next();
    }

    if (typeof (probe.config) !== 'object') {
        res.send(new restify.ConflictError('config is required'));
        return next();
github joyent / node-workflow / lib / api.js View on Github external
if (err.toRestError) {
                        return next(err.toRestError);
                    } else {
                        return next(new restify.InternalError(err));
                    }
                }
                if (count) {
                    res.header('x-count', count);
                }
                res.send(200, jobs);
                return next();
            };

        if (req.params.execution) {
            if (exec_values.indexOf(req.params.execution) === -1) {
                return next(new restify.ConflictError(
                  'Execution must be one of queued, failed, ' +
                  'succeeded, canceled or running'));
            }
        }

        if (req.params.offset) {
            req.params.offset = Number(req.params.offset);
        }

        if (req.params.limit) {
            req.params.limit = Number(req.params.limit);
        }

        return backend.getJobs(req.params, cb);
    }
github joyent / sdc-adminui / lib / auth.js View on Github external
if (err) {
            if (err.restCode === 'ResourceNotFound') {
                return next(new restify.ConflictError('The credentials provided are invalid'));
            } else {
                req.log.fatal(err, 'Error while retrieving user via UFDS');
                return next(new restify.InternalError('System Error: ' + err.message));
            }
        }
        var lockedTime = userLockTimes[username] || user.pwdaccountlockedtime;
        var isLocked = lockedTime && lockedTime > Date.now();
        if (isLocked) {
            return next(new restify.ConflictError(ACCOUNT_LOCKED_MESSAGE));
        }
        var pwdEndTime = user.pwdendtime;
        if (pwdEndTime && pwdEndTime <= Date.now()) {
            return next(new restify.ConflictError('Your password has already expired'));
        }
        return doAuth();
    });
github joyent / sdc-adminui / lib / auth.js View on Github external
req.ufds.authenticate(username, params.password, function (err, user) {
            if (err) {
                if (err.restCode === 'InvalidCredentials' || err.restCode === 'ResourceNotFound') {
                    if (userLoginAttempts[username] > MAX_LOGIN_ATTEMPTS) {
                        req.log.error({username: username}, ACCOUNT_LOCKED_MESSAGE + ' via slave UFDS');
                        userLockTimes[username] = Date.now() + LOCKED_TIME;
                        userLoginAttempts[username] = 0;
                    }
                    userLoginAttempts[username] += 1;
                    return next(new restify.ConflictError('The credentials provided are invalid'));
                }

                if (err.message === 'not connected') {
                    return next(new restify.InternalError('Service Unavailable: Not Connected to UFDS.'));
                }

                req.log.fatal(err, 'Error while attempting user auth via UFDS');
                return next(new restify.InternalError('System Error: ' + err.message));
            }
            if (isSlaveUfds) {
                req.log.warn(user, 'User has been authenticated with the slave UFDS');
            }
            delete userLockTimes[username];
            delete userLoginAttempts[username];

            if (user.isAdmin() === false && user.isReader() === false) {
github joyent / sdc-adminui / lib / auth.js View on Github external
req.ufds.getUser(username, function (err, user) {
        if (err) {
            if (err.restCode === 'ResourceNotFound') {
                return next(new restify.ConflictError('The credentials provided are invalid'));
            } else {
                req.log.fatal(err, 'Error while retrieving user via UFDS');
                return next(new restify.InternalError('System Error: ' + err.message));
            }
        }
        var lockedTime = userLockTimes[username] || user.pwdaccountlockedtime;
        var isLocked = lockedTime && lockedTime > Date.now();
        if (isLocked) {
            return next(new restify.ConflictError(ACCOUNT_LOCKED_MESSAGE));
        }
        var pwdEndTime = user.pwdendtime;
        if (pwdEndTime && pwdEndTime <= Date.now()) {
            return next(new restify.ConflictError('Your password has already expired'));
        }
        return doAuth();
    });
github joyent / sdc-adminui / lib / amon.js View on Github external
function createProbe(req, res, next) {
    var user = req.body.user;
    var probe = {
        type: req.body.type,
        contacts: ['email'],
        config: req.body.config || {},
        name: req.body.name
    };

    if (typeof (user) === 'undefined') {
        res.send(new restify.ConflictError('user must be provided!'));
        return next();
    }

    if (typeof (probe.type) === 'undefined') {
        res.send(new restify.ConflictError('type must be provided!'));
        return next();
    }

    if (typeof (probe.name) === 'undefined') {
        res.send(new restify.ConflictError('name must be provided!'));
        return next();
    }

    if (typeof (probe.config) !== 'object') {
        res.send(new restify.ConflictError('config is required'));
        return next();
    }


    if (typeof (req.body.machine) !== 'undefined') {
        probe.machine = req.body.machine;