Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | 'use strict'; // Modules const _ = require('lodash'); /* * Helper to build mysql command strings */ const buildMysqlString = (cmd, {username, service, password = null} = {}) => { if (password) return `${cmd} -u${username} -h${service} -p${password}`; else return `${cmd} -u${username} -h${service}`; }; /* * Helper to get memcached related tooling commands */ const getMemcachedTooling = (services, app = 'app') => _(services) .map(service => ({ name: service.relationship, description: `Connects to the ${service.relationship} relationship`, cmd: `netcat ${service.service} ${service.port}`, service: app, level: 'app', })) .value(); /* * Helper to get mysql related tooling commands */ const getMySqlTooling = services => _(services) .map(service => ({ name: service.relationship, description: `Connects to the ${service.relationship} relationship`, cmd: buildMysqlString('mysql', service), connect: `${buildMysqlString('mysql', service)}`, dump: `${buildMysqlString('mysqldump', service)}`, default: service.path, service: service.service, level: 'app', })) .value(); /* * Helper to get postgres related tooling commands */ const getPostgresTooling = services => _(services) .map(service => ({ name: service.relationship, description: `Connects to the ${service.relationship} relationship`, cmd: `psql -U${service.username} -h${service.service}`, connect: `psql -U${service.username} -h${service.service}`, dump: `pg_dump -U${service.username} -h${service.service}`, default: 'main', env: {PGPASSWORD: service.password}, service: service.service, level: 'app', })) .value(); /* * Helper to get platform cli related tooling commands */ const getPlatformCliTooling = (service = 'app') => ({platform: {service}}); /* * Helper to get php related tooling commands */ const getPhpTooling = (service = 'app') => ({composer: {service}, php: {service}}); /* * Helper to get redis related tooling commands */ const getRedisTooling = services => _(services) .map(service => ({ name: service.relationship, description: `Connects to the ${service.relationship} relationship`, cmd: 'redis-cli', service: service.service, level: 'app', })) .value(); /* * Helper to map lagoon type data to a lando service */ const getAppToolingByType = app => { switch (app.platformsh.type) { case 'php': return getPhpTooling(app.name); default: return {}; }; }; /* * Helper to map lagoon type data to a lando service */ const getServiceToolingByType = ({type, services} = {}, app = 'app') => { switch (type) { case 'mariadb': return getMySqlTooling(services); case 'memcached': return getMemcachedTooling(services, app); case 'mysql': return getMySqlTooling(services); case 'postgresql': return getPostgresTooling(services); case 'redis': return getRedisTooling(services); case 'redis-persistent': return getRedisTooling(services); default: return {}; }; }; /* * Maps parsed platform config into related Lando things */ exports.getAppTooling = app => _.merge({}, getPlatformCliTooling(app.name), getAppToolingByType(app)); /* * Helper to get relatable services eg services for which the closest app has a relationship */ exports.getRelatableServices = (relationships = {}) => _(relationships) .map(relationship => relationship) .flatten() .map('service') .uniqBy() .value(); /* * Maps parsed platform config into related Lando things */ exports.getServiceTooling = (services, relationships, app = 'app') => { // Group the relationships by the service const parsedRelationships = _(relationships) .map((relationship, name) => _.merge({}, relationship[0], {relationship: name})) .groupBy('service') .value(); // Groups the services by the service type const parsedServices = _(services) .groupBy('platformsh.type') .map((service, type) => _.merge({}, {type}, { services: _.flatten(_.map(service, s => parsedRelationships[s.name])), })) .value(); // Build the tooling array return _(parsedServices) .map(service => getServiceToolingByType(service, app)) .flatten() .filter(service => service.name) .map(service => ([service.name, _.omit(service, 'name')])) .fromPairs() .value(); }; |