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

      Object.entries(s3Resp.Metadata).forEach(([key, value]) => {
        const metadata = `x-amz-meta-${key}`;
        res.set(metadata, value);
        exposedHeaders.push(metadata);
      });
Severity: Major
Found in app/src/controllers/object.js and 1 other location - About 1 hr to fix
app/src/controllers/bucket.js on lines 48..52

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

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 updateUser has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

  updateUser: async (userId, data, etrx = undefined) => {
    let trx;
    try {
      // Check if any user values have changed
      const oldUser = await service.readUser(userId);
Severity: Minor
Found in app/src/services/user.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

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

exports.up = function (knex) {
  return Promise.resolve()
    // Create bucket tables
    .then(() => knex.schema.createTable('bucket', table => {
      table.uuid('bucketId').primary();
Severity: Minor
Found in app/src/db/migrations/20221014000000_003-multi-bucket.js - About 1 hr to fix

    Function processNextJob has 43 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      async processNextJob() {
        let job;
    
        try {
          const response = await objectQueueService.dequeue();
    Severity: Minor
    Found in app/src/components/queueManager.js - About 1 hr to fix

      Function createBucketChild has 42 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        async createBucketChild(req, res, next) {
          try {
            // Get Parent bucket data
            const parentBucketId = addDashesToUuid(req.params.bucketId);
            const parentBucket = await bucketService.read(parentBucketId);
      Severity: Minor
      Found in app/src/controllers/bucket.js - About 1 hr to fix

        Function Encrypt has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        const Encrypt = opts => {
          // Provide good default options if possible.
          const options = Object.assign(
            {
              fields: []
        Severity: Minor
        Found in app/src/db/models/mixins/encrypt.js - About 1 hr to fix

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

            return Promise.resolve()
              .then(() => knex.schema.alterTable('version_tag', table => {
                table.timestamp('updatedAt', { useTz: true }).defaultTo(knex.fn.now()).alter();
              }))
          app/src/db/migrations/20230503000000_007-default-updatedat.js on lines 38..44
          app/src/db/migrations/20230503000000_007-default-updatedat.js on lines 38..47
          app/src/db/migrations/20230503000000_007-default-updatedat.js on lines 38..50
          app/src/db/migrations/20230503000000_007-default-updatedat.js on lines 38..53
          app/src/db/migrations/20230503000000_007-default-updatedat.js on lines 38..56
          app/src/db/migrations/20230503000000_007-default-updatedat.js on lines 38..59
          app/src/db/migrations/20230503000000_007-default-updatedat.js on lines 38..62
          app/src/db/migrations/20230503000000_007-default-updatedat.js on lines 38..65
          app/src/db/migrations/20230503000000_007-default-updatedat.js on lines 38..68

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

          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 modifiers has 41 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            static get modifiers() {
              return {
                filterUserId(query, value) {
                  filterOneOrMany(query, value, 'userId');
                },
          Severity: Minor
          Found in app/src/db/models/tables/user.js - About 1 hr to fix

            Function addTags has 40 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              async addTags(req, res, next) {
                try {
                  const bucketId = req.currentObject?.bucketId;
                  const objId = addDashesToUuid(req.params.objectId);
                  const objPath = req.currentObject?.path;
            Severity: Minor
            Found in app/src/controllers/object.js - About 1 hr to fix

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

                Function createUser has a Cognitive Complexity of 13 (exceeds 5 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

                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 syncMetadata has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  syncMetadata: 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 1 hr to fix

                  Function copy has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    copy: async (sourceVersionId, targetVersionId, objectId, targetEtag, targetLastModified,
                      userId = SYSTEM_USER, etrx = undefined) => {
                      let trx;
                      try {
                        trx = etrx ? etrx : await Version.startTransaction();
                  Severity: Minor
                  Found in app/src/services/version.js - About 1 hr to fix

                    Function deleteTags has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      async deleteTags(req, res, next) {
                        try {
                          const bucketId = req.currentObject?.bucketId;
                          const objId = addDashesToUuid(req.params.objectId);
                          const objPath = req.currentObject?.path;
                    Severity: Minor
                    Found in app/src/controllers/object.js - About 1 hr to fix

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

                              const version = await versionService.create({
                                ...data,
                                etag: s3Response.ETag,
                                s3VersionId: s3VersionId,
                                isLatest: true,
                      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 1113..1119

                      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

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

                                version = await versionService.create({
                                  ...data,
                                  etag: s3Response.ETag,
                                  s3VersionId: s3VersionId,
                                  isLatest: true,
                      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 362..368

                      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

                      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/readObject.js and 1 other location - About 1 hr to fix
                      k6/searchObject.js on lines 34..45

                      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

                            const data = {
                              bucketId,
                              copySource: objPath,
                              filePath: objPath,
                              metadata: newMetadata,
                      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 439..452

                      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

                            const data = {
                              bucketId: bucketId,
                              copySource: objPath,
                              filePath: objPath,
                              metadata: metadata,
                      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 831..844

                      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('bucketPerms', {
                                is: true,
                                then: type.uuidv4
                                  .required()
                      Severity: Major
                      Found in app/src/validators/objectPermission.js and 1 other location - About 1 hr to fix
                      app/src/validators/bucketPermission.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

                      Severity
                      Category
                      Status
                      Source
                      Language