bcgov/common-object-management-service

View on GitHub

Showing 363 of 363 total issues

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

export default function () {

  // make the http request
  const res = http.get(url, params);

Severity: Major
Found in k6/searchObject.js and 1 other location - About 1 hr to fix
k6/readObject.js on lines 40..51

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 66.

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

      userId: Joi.alternatives()
        .conditional('objectPerms', {
          is: true,
          then: type.uuidv4
            .required()
Severity: Major
Found in app/src/validators/bucketPermission.js and 1 other location - About 1 hr to fix
app/src/validators/objectPermission.js on lines 14..23

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 66.

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

Function relationMappings has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  static get relationMappings() {
    const Bucket = require('./bucket');
    const ObjectPermission = require('./objectPermission');
    const BucketPermission = require('./bucketPermission');
    const Version = require('./version');
Severity: Minor
Found in app/src/db/models/tables/objectModel.js - About 1 hr to fix

    Function associateMetadata has 38 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      associateMetadata: async (versionId, metadata, currentUserId = SYSTEM_USER, etrx = undefined) => {
        let trx;
        try {
          trx = etrx ? etrx : await Metadata.startTransaction();
          let response = [];
    Severity: Minor
    Found in app/src/services/metadata.js - About 1 hr to fix

      Function relationMappings has 37 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        static get relationMappings() {
          const ObjectModel = require('./objectModel');
          const Metadata = require('./metadata');
          const Tag = require('./tag');
      
      
      Severity: Minor
      Found in app/src/db/models/tables/version.js - About 1 hr to fix

        Function fetchMetadataForVersion has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          fetchMetadataForVersion: async (params, etrx = undefined) => {
            let trx;
            try {
              trx = etrx ? etrx : await Metadata.startTransaction();
        
        
        Severity: Minor
        Found in app/src/services/metadata.js - About 1 hr to fix

          Function deleteObject has 36 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            async deleteObject(req, res, next) {
              try {
                const objId = addDashesToUuid(req.params.objectId);
                const userId = await userService.getCurrentUserId(getCurrentIdentity(req.currentUser, SYSTEM_USER));
          
          
          Severity: Minor
          Found in app/src/controllers/object.js - About 1 hr to fix

            Function fetchTagsForVersion has 36 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              fetchTagsForVersion: async (params, etrx = undefined) => {
                let trx;
                try {
                  trx = etrx ? etrx : await Tag.startTransaction();
            
            
            Severity: Minor
            Found in app/src/services/tag.js - About 1 hr to fix

              Function down has 36 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              exports.down = function (knex) {
                return Promise.resolve()
                  // re-add columns originalName and mimeType to object table
                  .then(() => knex.schema.alterTable('object', table => {
                    table.string('originalName', 255);
              Severity: Minor
              Found in app/src/db/migrations/20220516000000_001-version.js - About 1 hr to fix

                Function checkGrantPermissions has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                  checkGrantPermissions: async (data, etrx = undefined) => {
                    let trx;
                    try {
                      trx = etrx ? etrx : await Bucket.startTransaction();
                
                
                Severity: Minor
                Found in app/src/services/bucket.js - About 1 hr 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

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

                        if (data.metadata && Object.keys(data.metadata).length) {
                          await metadataService.associateMetadata(version.id, getKeyValue(data.metadata), userId, trx);
                        }
                Severity: Major
                Found in app/src/controllers/object.js and 1 other location - About 1 hr to fix
                app/src/controllers/object.js on lines 372..374

                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 63.

                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

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

                  async readObject(req, res, next) {
                    try {
                      const objId = addDashesToUuid(req.params.objectId);
                
                      // target S3 version
                Severity: Minor
                Found in app/src/controllers/object.js - About 1 hr to fix

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

                          if (data.metadata && Object.keys(data.metadata).length) {
                            await metadataService.associateMetadata(version.id, getKeyValue(data.metadata), userId, trx);
                          }
                  Severity: Major
                  Found in app/src/controllers/object.js and 1 other location - About 1 hr to fix
                  app/src/controllers/object.js on lines 1131..1133

                  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 63.

                  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

                  Function currentUpload has 34 lines of code (exceeds 25 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 1 hr to fix

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

                      _deriveObjectId: async (s3Object, path, bucketId) => {
                        let objId = uuidv4();
                    
                        if (typeof s3Object === 'object') { // If regular S3 Object
                          const TagSet = await storageService.getObjectTagging({ filePath: path, bucketId: bucketId })
                    Severity: Minor
                    Found in app/src/services/sync.js - About 1 hr to fix

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

                        createUser: async (data, etrx = undefined) => {
                          let trx;
                          try {
                            let response;
                            trx = etrx ? etrx : await User.startTransaction();
                      Severity: Minor
                      Found in app/src/services/user.js - About 1 hr to fix

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

                          return Promise.resolve()
                            // Drop lastSyncRequestedDate from bucket table
                            .then(() => knex.schema.alterTable('bucket', table => {
                              table.dropColumn('lastSyncRequestedDate');
                            }))
                        app/src/db/migrations/20230518000000_008-filename-etag.js on lines 23..31

                        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 62.

                        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

                              const params = {
                                metadata: metadata && Object.keys(metadata).length ? metadata : undefined,
                                privacyMask: req.currentUser.authType !== 'BASIC' ? getConfigBoolean('server.privacyMask') : false
                              };
                        Severity: Major
                        Found in app/src/controllers/metadata.js and 1 other location - About 1 hr to fix
                        app/src/controllers/tag.js on lines 23..26

                        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 62.

                        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

                              const params = {
                                tag: tagging && Object.keys(tagging).length ? tagging : undefined,
                                privacyMask: req.currentUser.authType !== 'BASIC' ? getConfigBoolean('server.privacyMask') : false
                              };
                        Severity: Major
                        Found in app/src/controllers/tag.js and 1 other location - About 1 hr to fix
                        app/src/controllers/metadata.js on lines 22..25

                        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 62.

                        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

                          static get modifiers() {
                            return {
                              filterActive(query, value) {
                                if (value !== undefined) query.where('active', value);
                              },
                        Severity: Major
                        Found in app/src/db/models/tables/permission.js and 1 other location - About 1 hr to fix
                        app/src/db/models/tables/identityProvider.js on lines 30..39

                        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 62.

                        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

                        Severity
                        Category
                        Status
                        Source
                        Language