bcgov/common-object-management-service

View on GitHub
app/src/services/storage.js

Summary

Maintainability
F
5 days
Test Coverage
A
100%

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

    objectStorageService has 24 functions (exceeds 20 allowed). Consider refactoring.
    Open

    const objectStorageService = {
      /**
       * @private
       * @function _getS3Client
       * The AWS S3Client used for interacting with S3 compatible storage
    Severity: Minor
    Found in app/src/services/storage.js - About 2 hrs to fix

      Function listAllObjectVersions has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        async listAllObjectVersions({
          filePath = undefined, bucketId = undefined, precisePath = true, filterLatest = false
        } = {}) {
          const key = filePath ?? (await utils.getBucket(bucketId)).key;
          const path = key !== DELIMITER ? key : '';
      Severity: Minor
      Found in app/src/services/storage.js - About 1 hr to fix

        Function listAllObjectVersions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          async listAllObjectVersions({
            filePath = undefined, bucketId = undefined, precisePath = true, filterLatest = false
          } = {}) {
            const key = filePath ?? (await utils.getBucket(bucketId)).key;
            const path = key !== DELIMITER ? key : '';
        Severity: Minor
        Found in app/src/services/storage.js - About 25 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

        TODO found
        Open

              // TODO: Consider adding API param support for Server Side Encryption
        Severity: Minor
        Found in app/src/services/storage.js by fixme

        TODO found
        Open

                // TODO: Consider adding API param support for Server Side Encryption
        Severity: Minor
        Found in app/src/services/storage.js by fixme

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

          async listObjectVersion({
            filePath = undefined, keyMarker = undefined, maxKeys = undefined, bucketId = undefined
          } = {}) {
            const data = await utils.getBucket(bucketId);
            const prefix = data.key !== DELIMITER ? data.key : '';
        Severity: Major
        Found in app/src/services/storage.js and 1 other location - About 6 hrs to fix
        app/src/services/storage.js on lines 362..375

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

        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

          async listObjectsV2({
            filePath = undefined, continuationToken = undefined, maxKeys = undefined, bucketId = undefined
          } = {}) {
            const data = await utils.getBucket(bucketId);
            const prefix = data.key !== DELIMITER ? data.key : '';
        Severity: Major
        Found in app/src/services/storage.js and 1 other location - About 6 hrs to fix
        app/src/services/storage.js on lines 386..399

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

        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 6 locations. Consider refactoring.
        Open

          async deleteObjectTagging({ filePath, s3VersionId = undefined, bucketId = undefined }) {
            const data = await utils.getBucket(bucketId);
            const params = {
              Bucket: data.bucket,
              Key: filePath,
        Severity: Major
        Found in app/src/services/storage.js and 5 other locations - About 3 hrs to fix
        app/src/services/storage.js on lines 117..126
        app/src/services/storage.js on lines 186..194
        app/src/services/storage.js on lines 219..228
        app/src/services/storage.js on lines 263..271
        app/src/services/storage.js on lines 532..541

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

        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 6 locations. Consider refactoring.
        Open

          async readObject({ filePath, s3VersionId = undefined, bucketId = undefined }) {
            const data = await utils.getBucket(bucketId);
            const params = {
              Bucket: data.bucket,
              Key: filePath,
        Severity: Major
        Found in app/src/services/storage.js and 5 other locations - About 3 hrs to fix
        app/src/services/storage.js on lines 117..126
        app/src/services/storage.js on lines 136..145
        app/src/services/storage.js on lines 186..194
        app/src/services/storage.js on lines 219..228
        app/src/services/storage.js on lines 263..271

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

        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 6 locations. Consider refactoring.
        Open

          async deleteObject({ filePath, s3VersionId = undefined, bucketId = undefined }) {
            const data = await utils.getBucket(bucketId);
            const params = {
              Bucket: data.bucket,
              Key: filePath,
        Severity: Major
        Found in app/src/services/storage.js and 5 other locations - About 3 hrs to fix
        app/src/services/storage.js on lines 136..145
        app/src/services/storage.js on lines 186..194
        app/src/services/storage.js on lines 219..228
        app/src/services/storage.js on lines 263..271
        app/src/services/storage.js on lines 532..541

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

        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 6 locations. Consider refactoring.
        Open

          async getObjectAcl({ filePath, s3VersionId = undefined, bucketId = undefined }) {
            const data = await utils.getBucket(bucketId);
            const params = {
              Bucket: data.bucket,
              Key: filePath,
        Severity: Major
        Found in app/src/services/storage.js and 5 other locations - About 3 hrs to fix
        app/src/services/storage.js on lines 117..126
        app/src/services/storage.js on lines 136..145
        app/src/services/storage.js on lines 219..228
        app/src/services/storage.js on lines 263..271
        app/src/services/storage.js on lines 532..541

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

        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 6 locations. Consider refactoring.
        Open

          async getObjectTagging({ filePath, s3VersionId = undefined, bucketId = undefined }) {
            const data = await utils.getBucket(bucketId);
            const params = {
              Bucket: data.bucket,
              Key: filePath,
        Severity: Major
        Found in app/src/services/storage.js and 5 other locations - About 3 hrs to fix
        app/src/services/storage.js on lines 117..126
        app/src/services/storage.js on lines 136..145
        app/src/services/storage.js on lines 186..194
        app/src/services/storage.js on lines 263..271
        app/src/services/storage.js on lines 532..541

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

        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 6 locations. Consider refactoring.
        Open

          async headObject({ filePath, s3VersionId = undefined, bucketId = undefined }) {
            const data = await utils.getBucket(bucketId);
            const params = {
              Bucket: data.bucket,
              Key: filePath,
        Severity: Major
        Found in app/src/services/storage.js and 5 other locations - About 3 hrs to fix
        app/src/services/storage.js on lines 117..126
        app/src/services/storage.js on lines 136..145
        app/src/services/storage.js on lines 186..194
        app/src/services/storage.js on lines 219..228
        app/src/services/storage.js on lines 532..541

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

        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

              if (DeleteMarkers) deleteMarkers.push(
                ...DeleteMarkers
                  .filter(object => !precisePath || utils.isAtPath(path, object.Key))
                  .filter(object => !filterLatest || object.IsLatest === true)
              );
        Severity: Major
        Found in app/src/services/storage.js and 1 other location - About 1 hr to fix
        app/src/services/storage.js on lines 341..345

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

        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

              if (Versions) versions.push(
                ...Versions
                  .filter(object => !precisePath || utils.isAtPath(path, object.Key))
                  .filter(object => !filterLatest || object.IsLatest === true)
              );
        Severity: Major
        Found in app/src/services/storage.js and 1 other location - About 1 hr to fix
        app/src/services/storage.js on lines 336..340

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

        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

              Tagging: Object.entries({ ...tags }).map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join('&')
        Severity: Major
        Found in app/src/services/storage.js and 1 other location - About 1 hr to fix
        app/src/services/storage.js on lines 588..588

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

        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

                Tagging: Object.entries({ ...tags }).map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join('&')
        Severity: Major
        Found in app/src/services/storage.js and 1 other location - About 1 hr to fix
        app/src/services/storage.js on lines 457..457

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

        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