elide secrets

This commit is contained in:
Josh Harvey 2016-12-18 15:39:17 +02:00
parent 504a85b8c4
commit ef0f1e02e9
4 changed files with 324 additions and 169 deletions

View file

@ -1,4 +1,4 @@
const R = require('ramda') const _ = require('lodash/fp')
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
@ -42,11 +42,11 @@ function selectedAccounts () {
.then(data => { .then(data => {
if (!data) return [] if (!data) return []
const accountCodes = R.uniq(data.config.map(mapAccount) const accountCodes = _.uniq(data.config.map(mapAccount)
.filter(R.identity)) .filter(_.identity))
return R.sortBy(R.prop('display'), accountCodes.map(mapSchema) return _.sortBy(_.get('display'), accountCodes.map(mapSchema)
.filter(R.identity)) .filter(_.identity))
}) })
} }
@ -60,14 +60,14 @@ function mergeAccount (oldAccount, newAccount) {
const newFields = newAccount.fields const newFields = newAccount.fields
const updateWithData = oldField => { const updateWithData = oldField => {
const newField = R.find(r => r.code === oldField.code, newFields) const newField = _.find(r => r.code === oldField.code, newFields)
const newValue = newField ? newField.value : null const newValue = _.isUndefined(newField) ? oldField.value : newField.value
return R.assoc('value', newValue, oldField) return _.set('value', newValue, oldField)
} }
const updatedFields = oldAccount.fields.map(updateWithData) const updatedFields = oldAccount.fields.map(updateWithData)
return R.assoc('fields', updatedFields, oldAccount) return _.set('fields', updatedFields, oldAccount)
} }
function getAccounts (accountCode) { function getAccounts (accountCode) {
@ -76,17 +76,26 @@ function getAccounts (accountCode) {
return fetchAccounts() return fetchAccounts()
.then(accounts => { .then(accounts => {
if (R.isEmpty(accounts)) return [schema] if (_.isEmpty(accounts)) return [schema]
const account = R.find(r => r.code === accountCode, accounts) const account = _.find(r => r.code === accountCode, accounts)
const mergedAccount = mergeAccount(schema, account) const mergedAccount = mergeAccount(schema, account)
return updateAccounts(mergedAccount, accounts) return updateAccounts(mergedAccount, accounts)
}) })
} }
function elideSecrets (account) {
const elideSecret = field => field.fieldType === 'password'
? _.set('value', !_.isNil(field.value), field)
: field
return _.set('fields', account.fields.map(elideSecret), account)
}
function getAccount (accountCode) { function getAccount (accountCode) {
return getAccounts(accountCode) return getAccounts(accountCode)
.then(accounts => R.find(r => r.code === accountCode, accounts)) .then(accounts => _.find(r => r.code === accountCode, accounts))
.then(elideSecrets)
} }
function save (accounts) { function save (accounts) {
@ -95,20 +104,20 @@ function save (accounts) {
function updateAccounts (newAccount, accounts) { function updateAccounts (newAccount, accounts) {
const accountCode = newAccount.code const accountCode = newAccount.code
const isPresent = R.any(R.propEq('code', accountCode), accounts) const isPresent = _.some(_.matchesProperty('code', accountCode), accounts)
const updateAccount = r => r.code === accountCode const updateAccount = r => r.code === accountCode
? newAccount ? newAccount
: r : r
return isPresent return isPresent
? R.map(updateAccount, accounts) ? _.map(updateAccount, accounts)
: R.append(newAccount, accounts) : _.concat(accounts, newAccount)
} }
function updateAccount (account) { function updateAccount (account) {
return getAccounts(account.code) return getAccounts(account.code)
.then(accounts => { .then(accounts => {
const merged = mergeAccount(R.find(R.propEq('code', account.code), accounts), account) const merged = mergeAccount(_.find(_.matchesProperty('code', account.code), accounts), account)
return save(updateAccounts(merged, accounts)) return save(updateAccounts(merged, accounts))
}) })
.then(() => getAccount(account.code)) .then(() => getAccount(account.code))

View file

@ -31,8 +31,6 @@ function status () {
bid: parseFloat(ratesRec.rates.bid), bid: parseFloat(ratesRec.rates.bid),
ask: parseFloat(ratesRec.rates.ask) ask: parseFloat(ratesRec.rates.ask)
}] }]
console.log('DEBUG76: %j', ratesRec.rates)
console.log('DEBUG77: %j', rates)
return {up, lastPing, rates} return {up, lastPing, rates}
}) })
}) })

File diff suppressed because one or more lines are too long

View file

@ -381,6 +381,12 @@ p {
font-weight: bold; font-weight: bold;
} }
.lamassuAdminSaving {
font-size: 18px;
font-weight: normal;
text-align: right;
}
.lamassuAdminNavBar { .lamassuAdminNavBar {
margin: 0; margin: 0;
padding: 0 0 60px 0; padding: 0 0 60px 0;