commands/credentials.js
'use strict' const co = require('co')const cli = require('heroku-cli-util')const {sortBy} = require('lodash')const util = require('../lib/util') Function `run` has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Function `run` has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.function * run (context, heroku) { const fetcher = require('../lib/fetcher')(heroku) const {app, args, flags} = context let showCredentials = co.wrap(function * () { const host = require('../lib/host') let addon = yield fetcher.addon(app, args.database) let attachments = [] let credentials = [] function presentCredential (cred) { let credAttachments = [] if (cred !== 'default') { credAttachments = attachments.filter(a => a.namespace === `credential:${cred}`) } else { credAttachments = attachments.filter(a => a.namespace === null) } return util.presentCredentialAttachments(app, credAttachments, credentials, cred) } credentials = yield heroku.get(`/postgres/v0/databases/${addon.name}/credentials`, { host: host(addon) }) let isDefaultCredential = (cred) => cred.name !== 'default' credentials = sortBy(credentials, isDefaultCredential, 'name') attachments = yield heroku.get(`/addons/${addon.name}/addon-attachments`) Similar blocks of code found in 4 locations. Consider refactoring. cli.warn(`${cli.color.cmd('pg:credentials')} has recently changed. Please use ${cli.color.cmd('pg:credentials:url')} for the previous output.`) cli.table(credentials, { columns: [ {key: 'name', label: 'Credential', format: presentCredential}, {key: 'state', label: 'State'} ] }) }) if (flags.reset) {Similar blocks of code found in 4 locations. Consider refactoring. cli.error(`${cli.color.cmd('pg:credentials --reset')} is deprecated. Please use ${cli.color.cmd('pg:credentials:rotate')} instead.`) } else { yield showCredentials() }} Similar blocks of code found in 2 locations. Consider refactoring.module.exports = { topic: 'pg', command: 'credentials', description: 'show information on credentials in the database', needsApp: true, needsAuth: true, flags: [{name: 'reset', description: 'DEPRECATED'}], args: [{name: 'database', optional: true}], run: cli.command({preauth: true}, co.wrap(run))}