bcgov/common-object-management-service

View on GitHub

Showing 131 of 363 total issues

File object.js has 793 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const Problem = require('api-problem');
const cors = require('cors');
const { v4: uuidv4, NIL: SYSTEM_USER } = require('uuid');

const {
Severity: Major
Found in app/src/controllers/object.js - About 1 day to fix

    Function syncVersions has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring.
    Open

      syncVersions: async (object, userId = SYSTEM_USER, etrx = undefined) => {
        let trx;
        try {
          trx = etrx ? etrx : await Version.startTransaction();
    
    
    Severity: Minor
    Found in app/src/services/sync.js - About 1 day 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

    Function up has 123 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    exports.up = function (knex) {
      return Promise.resolve()
        // Create public schema COMS tables
        .then(() => knex.schema.createTable('identity_provider', table => {
          table.string('idp', 255).primary();
    Severity: Major
    Found in app/src/db/migrations/20220130133615_000-init.js - About 4 hrs to fix

      Function updateObject has 116 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        async updateObject(req, res, next) {
          try {
            const userId = await userService.getCurrentUserId(getCurrentIdentity(req.currentUser, SYSTEM_USER));
      
            // Preflight existence check for bucketId
      Severity: Major
      Found in app/src/controllers/object.js - About 4 hrs to fix

        Function createObject has 110 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          async createObject(req, res, next) {
            try {
              const userId = await userService.getCurrentUserId(getCurrentIdentity(req.currentUser, SYSTEM_USER));
        
              // Preflight CREATE permission check if bucket scoped and OIDC authenticated
        Severity: Major
        Found in app/src/controllers/object.js - About 4 hrs to fix

          Function syncVersions has 109 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            syncVersions: async (object, userId = SYSTEM_USER, etrx = undefined) => {
              let trx;
              try {
                trx = etrx ? etrx : await Version.startTransaction();
          
          
          Severity: Major
          Found in app/src/services/sync.js - About 4 hrs to fix

            Function modifiers has 107 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              static get modifiers() {
                const Version = require('./version');
            
                return {
                  filterIds(query, value) {
            Severity: Major
            Found in app/src/db/models/tables/objectModel.js - About 4 hrs to fix

              File sync.js has 343 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              const { NIL: SYSTEM_USER, v4: uuidv4, validate: uuidValidate } = require('uuid');
              
              const log = require('../components/log')(module.filename);
              const utils = require('../db/models/utils');
              
              
              Severity: Minor
              Found in app/src/services/sync.js - About 4 hrs to fix

                Function updateObject has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
                Open

                  async updateObject(req, res, next) {
                    try {
                      const userId = await userService.getCurrentUserId(getCurrentIdentity(req.currentUser, SYSTEM_USER));
                
                      // Preflight existence check for bucketId
                Severity: Minor
                Found in app/src/controllers/object.js - About 4 hrs 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

                Function currentUser has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
                Open

                const currentUser = async (req, res, next) => {
                  const authorization = req.get('Authorization');
                  const currentUser = {
                    authType: AuthType.NONE
                  };
                Severity: Minor
                Found in app/src/middleware/authentication.js - About 3 hrs 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

                Function createInvite has 91 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  async createInvite(req, res, next) {
                    let resource, type;
                
                    try {
                      // Reject if expiresAt is more than 30 days away
                Severity: Major
                Found in app/src/controllers/invite.js - About 3 hrs to fix

                  File storage.js has 317 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  const {
                    CopyObjectCommand,
                    DeleteObjectCommand,
                    DeleteObjectTaggingCommand,
                    GetBucketEncryptionCommand,
                  Severity: Minor
                  Found in app/src/services/storage.js - About 3 hrs to fix

                    Function createObject has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
                    Open

                      async createObject(req, res, next) {
                        try {
                          const userId = await userService.getCurrentUserId(getCurrentIdentity(req.currentUser, SYSTEM_USER));
                    
                          // Preflight CREATE permission check if bucket scoped and OIDC authenticated
                    Severity: Minor
                    Found in app/src/controllers/object.js - About 3 hrs 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

                    Function modifiers has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
                    Open

                      static get modifiers() {
                        const Version = require('./version');
                    
                        return {
                          filterIds(query, value) {
                    Severity: Minor
                    Found in app/src/db/models/tables/objectModel.js - About 3 hrs 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

                    Function createInvite has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
                    Open

                      async createInvite(req, res, next) {
                        let resource, type;
                    
                        try {
                          // Reject if expiresAt is more than 30 days away
                    Severity: Minor
                    Found in app/src/controllers/invite.js - About 3 hrs 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

                    Function syncTags has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
                    Open

                      syncTags: async (version, path, bucketId = undefined, userId = SYSTEM_USER, etrx = undefined) => {
                        let trx;
                        try {
                          trx = etrx ? etrx : await Version.startTransaction();
                          let response = [];
                    Severity: Minor
                    Found in app/src/services/sync.js - About 3 hrs 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

                    utils has 27 functions (exceeds 20 allowed). Consider refactoring.
                    Open

                    const utils = {
                      /**
                       * @function addDashesToUuid
                       * Yields a lowercase uuid `str` that has dashes inserted, or `str` if not a string.
                       * @param {string} str The input string uuid
                    Severity: Minor
                    Found in app/src/components/utils.js - About 3 hrs to fix

                      Function response has 76 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                            const response = await Promise.all(s3Versions.map(async s3Version => {
                              // S3 Object is in non-versioned bucket
                              if (s3Version.VersionId === 'null') {
                                const mimeType = await storageService.headObject({
                                  filePath: comsObject.path,
                      Severity: Major
                      Found in app/src/services/sync.js - About 3 hrs to fix

                        Function syncObject has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
                        Open

                          syncObject: async (path, bucketId, userId = SYSTEM_USER, etrx = undefined) => {
                            let trx;
                            try {
                              trx = etrx ? etrx : await ObjectModel.startTransaction();
                        
                        
                        Severity: Minor
                        Found in app/src/services/sync.js - About 2 hrs 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

                        Function currentUpload has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                        Open

                        const currentUpload = (strict = false) => {
                          return (req, _res, next) => {
                            // Check Content-Length Header
                            const contentLength = parseInt(req.get('Content-Length'));
                            // TODO: Figure out what's killing and returning a 400 in response stack
                        Severity: Minor
                        Found in app/src/middleware/upload.js - About 2 hrs 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

                        Severity
                        Category
                        Status
                        Source
                        Language