prey/prey-node-client

View on GitHub
lib/agent/utils/prey-configuration/preyconf.js

Summary

Maintainability
D
2 days
Test Coverage

File preyconf.js has 340 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const fs = require('fs');
const { join } = require('path');
const configPath = require('../../../common').system.paths.config;
const logger = require('../../common').logger.prefix('preyconf');
const storage = require('../storage');
Severity: Minor
Found in lib/agent/utils/prey-configuration/preyconf.js - About 4 hrs to fix

    Function readWithoutVerification has 46 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    const readWithoutVerification = (cb) => {
      const extractedData = {};
      let nameBefore = '';
      let content = '';
      try {
    Severity: Minor
    Found in lib/agent/utils/prey-configuration/preyconf.js - About 1 hr to fix

      Function verifyPreyConfData has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      const verifyPreyConfData = (doNotVerifyApiDeviceKey = false) => {
        const dataToFix = {};
        let somethingWrong = false;
        resetDefaultValues();
        let content = '';
      Severity: Minor
      Found in lib/agent/utils/prey-configuration/preyconf.js - About 1 hr to fix

        Function correctPreyConf has 41 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        const correctPreyConf = (preyConfDataToWrite, callback) => {
          let allFileContents = '';
        
          allFileContents = getFileContent(join(__dirname, '../../../../prey.conf.default'));
          if (allFileContents === '') {
        Severity: Minor
        Found in lib/agent/utils/prey-configuration/preyconf.js - About 1 hr to fix

          Function dataToSavePreyConf has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          const dataToSavePreyConf = () => {
            let allFileContents = '';
            try {
              allFileContents = getFileContent(exports.preyConfPath);
              if (allFileContents === '') {
          Severity: Minor
          Found in lib/agent/utils/prey-configuration/preyconf.js - About 1 hr to fix

            Function verifyPreyConf has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            const verifyPreyConf = () => {
              resetDefaultValues();
              let allFileContents = '';
              try {
                allFileContents = getFileContent(exports.preyConfPath);
            Severity: Minor
            Found in lib/agent/utils/prey-configuration/preyconf.js - About 1 hr to fix

              Function saveDataToDb has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              const saveDataToDb = (dataToSave, cb) => {
                try {
                  // eslint-disable-next-line consistent-return
                  getDataDb('preyconf', (err, stored) => {
                    if (err) {
              Severity: Minor
              Found in lib/agent/utils/prey-configuration/preyconf.js - About 1 hr to fix

                Avoid deeply nested control flow statements.
                Open

                            if (match) {
                              const value = match[1];
                              const matchValue = reqPreyConf[count].possiblevalues.exec(value);
                              if (matchValue) {
                                preyConfData[reqPreyConf[count].name] = value;
                Severity: Major
                Found in lib/agent/utils/prey-configuration/preyconf.js - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                              if (preyConfDataToWrite) {
                                dataToInsert = preyConfDataToWrite[reqPreyConf[count].name] ? preyConfDataToWrite[reqPreyConf[count].name] : '';
                              } else {
                                dataToInsert = reqPreyConf[count].default
                                || ((typeof reqPreyConf[count].default === 'boolean') && reqPreyConf[count].default === false) ? reqPreyConf[count].default : '';
                  Severity: Major
                  Found in lib/agent/utils/prey-configuration/preyconf.js - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                if (line.match(reqPreyConf[count].value)) {
                                  if (reqPreyConf[count].word === 'api_key') {
                                    apiKeyValue = true;
                                  } else if (reqPreyConf[count].word === 'device_key') {
                                    deviceKeyValue = true;
                    Severity: Major
                    Found in lib/agent/utils/prey-configuration/preyconf.js - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                    if (reqPreyConf[count].possiblevalues) {
                                      if (reqPreyConf[count].value && !reqPreyConf[count].value.test(line)) {
                                        somethingWrong = true;
                                        dataToFix[reqPreyConf[count].name] = false;
                                      }
                      Severity: Major
                      Found in lib/agent/utils/prey-configuration/preyconf.js - About 45 mins to fix

                        Consider simplifying this complex logical expression.
                        Open

                          if (!dataToVerify || !dataFromDb
                          || (typeof dataToVerify) !== 'object' || (typeof dataFromDb) !== 'object'
                          || Object.keys(dataToVerify).length === 0
                          || Object.keys(dataFromDb).length === 0) { return callback(false); }
                        Severity: Major
                        Found in lib/agent/utils/prey-configuration/preyconf.js - About 40 mins to fix

                          Function saveDataToDb has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                          const saveDataToDb = (dataToSave, cb) => {
                            try {
                              // eslint-disable-next-line consistent-return
                              getDataDb('preyconf', (err, stored) => {
                                if (err) {
                          Severity: Minor
                          Found in lib/agent/utils/prey-configuration/preyconf.js - About 35 mins to fix

                          Cognitive Complexity

                          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                          A method's cognitive complexity is based on a few simple rules:

                          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                          • Code is considered more complex for each "break in the linear flow of the code"
                          • Code is considered more complex when "flow breaking structures are nested"

                          Further reading

                          Identical blocks of code found in 2 locations. Consider refactoring.
                          Open

                            try {
                              storage.do('query', { type: 'keys', column: 'id', data: whatToGet }, (err, stored) => {
                                if (err) {
                                  return callback(err, null);
                                }
                          Severity: Major
                          Found in lib/agent/utils/prey-configuration/preyconf.js and 1 other location - About 2 hrs to fix
                          lib/utils/configutil.js on lines 10..22

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 90.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          Similar blocks of code found in 2 locations. Consider refactoring.
                          Open

                                  }, (errUpdate) => {
                                    if (errUpdate) {
                                      logger.error(`Error while updating preyconf: ${errUpdate}`);
                                      return cb(errUpdate);
                                    }
                          Severity: Minor
                          Found in lib/agent/utils/prey-configuration/preyconf.js and 1 other location - About 35 mins to fix
                          lib/agent/utils/prey-configuration/preyconf.js on lines 328..334

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 47.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          Similar blocks of code found in 2 locations. Consider refactoring.
                          Open

                                  storage.do('set', { type: 'keys', id: 'preyconf', data: { value: JSON.stringify(dataToSave) } }, (errSetting) => {
                                    if (errSetting) {
                                      logger.error(`Error while setting preyconf: ${errSetting}`);
                                      return cb(errSetting);
                                    }
                          Severity: Minor
                          Found in lib/agent/utils/prey-configuration/preyconf.js and 1 other location - About 35 mins to fix
                          lib/agent/utils/prey-configuration/preyconf.js on lines 320..326

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 47.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          Similar blocks of code found in 3 locations. Consider refactoring.
                          Open

                            try {
                              allFileContents = getFileContent(exports.preyConfPath);
                              if (allFileContents === '') {
                                throw breakException;
                              }
                          Severity: Minor
                          Found in lib/agent/utils/prey-configuration/preyconf.js and 2 other locations - About 35 mins to fix
                          lib/agent/utils/prey-configuration/preyconf.js on lines 34..41
                          lib/agent/utils/prey-configuration/preyconf.js on lines 75..82

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 46.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          Similar blocks of code found in 3 locations. Consider refactoring.
                          Open

                            try {
                              content = getFileContent(exports.preyConfPath);
                              if (content === '') {
                                throw breakException;
                              }
                          Severity: Minor
                          Found in lib/agent/utils/prey-configuration/preyconf.js and 2 other locations - About 35 mins to fix
                          lib/agent/utils/prey-configuration/preyconf.js on lines 34..41
                          lib/agent/utils/prey-configuration/preyconf.js on lines 192..199

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 46.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          Similar blocks of code found in 3 locations. Consider refactoring.
                          Open

                            try {
                              allFileContents = getFileContent(exports.preyConfPath);
                              if (allFileContents === '') {
                                throw breakException;
                              }
                          Severity: Minor
                          Found in lib/agent/utils/prey-configuration/preyconf.js and 2 other locations - About 35 mins to fix
                          lib/agent/utils/prey-configuration/preyconf.js on lines 75..82
                          lib/agent/utils/prey-configuration/preyconf.js on lines 192..199

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 46.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          There are no issues that match your filters.

                          Category
                          Status