// Helper to set caches const setCaches = (options, lando) => { // Get the github user github.authenticate({type: 'token', token: options['github-auth']}); return github.users.get({}) .then(user => { // Reset this apps metacache const metaData = lando.cache.get(`${options.name}.meta.cache`) || {}; lando.cache.set(`${options.name}.meta.cache`, _.merge({}, metaData, {email: user.data.email}), {persist: true}); // Reset github tokens const tokens = lando.cache.get(githubTokenCache) || []; const cache = {token: options['github-auth'], user: user.data.login, date: _.toInteger(_.now() / 1000)}; lando.cache.set(githubTokenCache, sortTokens(tokens, [cache]), {persist: true}); }); }
api.getAccountInfo().then(me => { // Get the project const project = _.find(me.projects, {name: options['platformsh-site']}); // Or error if there is no spoon if (_.isEmpty(project)) throw Error(`${options['platformsh-site']} does not appear to be a platform.sh site!`); // This is a good token, lets update our cache const cache = {token: options['platformsh-auth'], email: me.mail, date: _.toInteger(_.now() / 1000)}; // Update lando's store of platformsh machine tokens const tokens = lando.cache.get(platformshTokenCache) || []; lando.cache.set(platformshTokenCache, utils.sortTokens(tokens, [cache]), {persist: true}); // Update app metdata const metaData = lando.cache.get(`${options.name}.meta.cache`); lando.cache.set(`${options.name}.meta.cache`, _.merge({}, metaData, cache), {persist: true}); return {config: { id: _.get(project, 'id', 'lando'), }}; })
// Helper to populate defaults const getDefaults = (task, options) => { // Set interactive options _.forEach(['code', 'database', 'files'], name => { task.options[name].interactive.choices = answers => { return utils.getPantheonInquirerEnvs( answers.auth, options.id, [], options._app.log); }; task.options[name].interactive.default = options.env; }); // Get the framework flavor const flavor = frameworkType(options.framework); // Set envvars task.env = { LANDO_DB_PULL_COMMAND: buildDbPullCommand(options), LANDO_DB_USER_TABLE: flavor === 'pressy' ? 'wp_users' : 'users', LANDO_LEIA: _.toInteger(options._app._config.leia), }; return task; }
/* * This event is intended to make sure we reset the active token and cache when it is passed in * via the lando pull or lando push commands */ _.forEach(['pull', 'push'], command => { app.events.on(`post-${command}`, (config, answers) => { // Only run if answer.auth is set, this allows these commands to all be // overriden without causing a failure here if (answers.auth) { const api = new PlatformshApiClient({api_token: answers.auth}); return api.getAccountInfo().then(me => { // This is a good token, lets update our cache const cache = {token: answers.auth, email: me.mail, date: _.toInteger(_.now() / 1000)}; // Update lando's store of platformsh machine tokens const tokens = lando.cache.get(app.platformsh.tokenCache) || []; lando.cache.set(app.platformsh.tokenCache, utils.sortTokens(tokens, [cache]), {persist: true}); // Update app metdata const metaData = lando.cache.get(`${app.name}.meta.cache`); lando.cache.set(`${app.name}.meta.cache`, _.merge({}, metaData, cache), {persist: true}); }); } }); });
api.auth().then(() => Promise.all([api.getSites(), api.getUser()])) // Parse the dataz and set the things .then(results => { // Get our site and email const site = _.head(_.filter(results[0], site => site.name === options['pantheon-site'])); const user = results[1]; // Error if site doesn't exist if (_.isEmpty(site)) throw Error(`${site} does not appear to be a Pantheon site!`); // This is a good token, lets update our cache const cache = {token: options['pantheon-auth'], email: user.email, date: _.toInteger(_.now() / 1000)}; // Update lando's store of pantheon machine tokens const tokens = lando.cache.get(pantheonTokenCache) || []; lando.cache.set(pantheonTokenCache, utils.sortTokens(tokens, [cache]), {persist: true}); // Update app metdata const metaData = lando.cache.get(`${options.name}.meta.cache`); lando.cache.set(`${options.name}.meta.cache`, _.merge({}, metaData, cache), {persist: true}); // Add some stuff to our landofile return {config: { framework: _.get(site, 'framework', 'drupal'), site: _.get(site, 'name', options.name), id: _.get(site, 'id', 'lando'), }}; })
}; _.forEach(logLevels, (word, num) => { const log = new Log({logLevelConsole: _.toInteger(num)}); log.transports.console.should.have.property('level', word); });
// Set the app caches, validate tokens and update token cache _.forEach(['pull', 'push', 'switch'], command => { app.events.on(`post-${command}`, (config, answers) => { // Only run if answer.auth is set, this allows these commands to all be // overriden without causing a failure here if (answers.auth) { const api = new PantheonApiClient(answers.auth, app.log); return api.auth().then(() => api.getUser().then(results => { const cache = {token: answers.auth, email: results.email, date: _.toInteger(_.now() / 1000)}; // Reset this apps metacache lando.cache.set(app.metaCache, _.merge({}, app.meta, cache), {persist: true}); // Set lando's store of pantheon machine tokens lando.cache.set(app.pantheonTokenCache, utils.sortTokens(app.pantheonTokens, [cache]), {persist: true}); // Wipe out the apps tooling cache to reset with the new MT lando.cache.remove(`${app.name}.tooling.cache`); })) // Throw some sort of error // NOTE: this provides some error handling when we are completely non-interactive .catch(err => { throw (_.has(err, 'response.data')) ? new Error(err.response.data) : err; }); } }); });
let code = 200; if (_.includes(last, ':')) { if (_.toInteger(last.split(':')[1]) === counter[url]) code = 200; else code = last.split(':')[0]; } else { code = isFinite(_.last(url.split('.'))) ? _.last(url.split('.')) : 200; return (_.startsWith(code, 2)) ? Promise.resolve() : Promise.reject({response: {status: _.toInteger(code)}}); }, }));
// Faking processing time setTimeout(() => { post = _.find(posts, ['id', _.toInteger(postId)]); if(_.isNull(post)) { throw new Error({'success': false}) } resolve({'success': true, 'data': post}) }, 2000);
// set quantity of item /** * Set quantity of CartItem * @param {number} qty represents Quantity of an Item */ Quantity(qty) { qty = _.toInteger(qty) // allow to clear an item for cart if (qty < 0) { qty = 0 } // set this data to CartItem this._quantity = qty }
this._request(url, function (error, json) { if (error) return callback(error, json); let data = { "id": json.rsp.course.id, "title": json.rsp.course.title, "versions": _.flatten(_.toArray(json.rsp.course.versions[1])), "registrations": _.toInteger(json.rsp.course.registrations), "size": _.toInteger(json.rsp.course.size), "tags": _.flatten(_.toArray(json.rsp.course.tags)), "learningStandard": json.rsp.course.learningStandard, "createDate": json.rsp.course.createDate } return callback(error, data); });
var getCourseAttributeValue = function (name, value) { switch (_.get(COURSE_ATTRIBUTES, name)) { case "boolean": return _.lowerCase(value) === 'true' ? true : false; case "number": return _.toNumber(value); case "integer": return _.toInteger(value); // Value is a string by default. default: return value; } }
this._request(url, function (error, json) { if (error) return callback(error, json); let data = []; let courseList = toArray(json.rsp.courselist.course); courseList.forEach(function (course) { data.push({ "id": course.id, "title": course.title, "registrations": _.toInteger(course.registrations), "size": _.toInteger(course.size), "tags": _.flatten(_.toArray(course.tags)), "learningStandard": course.learningStandard, "createDate": course.createDate }); }); return callback(error, data); });
// See https://www.npmjs.com/package/request request.post(requestOptions, function (error, response, body) { if (error) return callback(error); // See https://www.npmjs.com/package/xml2js parseString(body, { explicitArray: false, mergeAttrs: true }, function (err, json) { if (err) throw err; if (VERBOSE) { console.log(body); console.log(util.inspect(json, false, null)); } let error; if (json.rsp.stat === 'fail') { error = new Error(json.rsp.err.msg); json = { "error": { "code": _.toInteger(json.rsp.err.code), "message": json.rsp.err.msg } }; } callback(error, json); }); });