CSCfi/pebbles

View on GitHub

Showing 169 of 169 total issues

Function put has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

    def put(self, workspace_id):
        form = WorkspaceForm()
        if not form.validate_on_submit():
            logging.warning('validation error on updating workspace')
            return form.errors, 422
Severity: Minor
Found in pebbles/views/workspaces.py - 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

User has 31 functions (exceeds 20 allowed). Consider refactoring.
Open

class User(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.String(32), primary_key=True)
    # ext_id is mandatory and unique. ext_id can be used to retrieve database objects
Severity: Minor
Found in pebbles/models.py - About 3 hrs to fix

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

        def delete_service(self, namespace, application_session):
            self.logger.debug('deleting service %s' % application_session.get('name'))
            api = self.dynamic_client.resources.get(api_version='v1', kind='Service')
            api.delete(
                namespace=namespace,
    Severity: Major
    Found in pebbles/drivers/provisioning/kubernetes_driver.py and 1 other location - About 3 hrs to fix
    pebbles/drivers/provisioning/kubernetes_driver.py on lines 542..545

    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

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

        def delete_configmap(self, namespace, application_session):
            self.logger.debug('deleting configmap %s' % application_session.get('name'))
            api_configmap = self.dynamic_client.resources.get(api_version='v1', kind='ConfigMap')
            return api_configmap.delete(namespace=namespace, name=application_session.get('name'))
    Severity: Major
    Found in pebbles/drivers/provisioning/kubernetes_driver.py and 1 other location - About 3 hrs to fix
    pebbles/drivers/provisioning/kubernetes_driver.py on lines 441..444

    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

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

        def delete_deployment(self, namespace, application_session):
            self.logger.debug('deleting deployment %s' % application_session.get('name'))
            api_deployment = self.dynamic_client.resources.get(api_version='apps/v1', kind='Deployment')
            return api_deployment.delete(namespace=namespace, name=application_session.get('name'))
    Severity: Major
    Found in pebbles/drivers/provisioning/kubernetes_driver.py and 1 other location - About 3 hrs to fix
    pebbles/drivers/provisioning/kubernetes_driver.py on lines 507..510

    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

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

        def delete_ingress(self, namespace, application_session):
            self.logger.debug('deleting ingress %s' % application_session.get('name'))
            api = self.dynamic_client.resources.get(api_version='networking.k8s.io/v1', kind='Ingress')
            api.delete(namespace=namespace, name=application_session.get('name'))
    Severity: Major
    Found in pebbles/drivers/provisioning/kubernetes_driver.py and 1 other location - About 3 hrs to fix
    pebbles/drivers/provisioning/kubernetes_driver.py on lines 522..527

    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

    File controllers.py has 321 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import logging
    import os
    import time
    import traceback
    from random import randrange
    Severity: Minor
    Found in pebbles/worker/controllers.py - About 3 hrs to fix

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

          def process(self):
              # process sessions in increased intervals
              if time.time() < self.next_check_ts:
                  return
              self.update_next_check_ts(self.polling_interval_min, self.polling_interval_max)
      Severity: Minor
      Found in pebbles/worker/controllers.py - 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

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

          @auth.login_required
          @requires_admin
          def delete(self, service_announcement_id):
              announcement = ServiceAnnouncement.query.filter_by(id=service_announcement_id).first()
              if not announcement:
      Severity: Major
      Found in pebbles/views/service_announcements.py and 1 other location - About 3 hrs to fix
      pebbles/views/messages.py on lines 118..125

      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

          @auth.login_required
          @requires_admin
          def delete(self, message_id):
              message = Message.query.filter_by(id=message_id).first()
              if not message:
      Severity: Major
      Found in pebbles/views/messages.py and 1 other location - About 3 hrs to fix
      pebbles/views/service_announcements.py on lines 105..112

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

          def process(self):
              # process clusters in increased intervals
              if time.time() < self.next_check_ts:
                  return
              self.update_next_check_ts(self.polling_interval_min, self.polling_interval_max)
      Severity: Minor
      Found in pebbles/worker/controllers.py - 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

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

      class PBClient:
          def __init__(self, token, api_base_url, ssl_verify=True):
              self.token = token
              self.api_base_url = api_base_url
              self.ssl_verify = ssl_verify
      Severity: Minor
      Found in pebbles/client.py - About 3 hrs to fix

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

        Severity: Major
        Found in migrations/versions/998437d5ea7a_user_annotations.py and 1 other location - About 3 hrs to fix
        migrations/versions/c702dff56bb0_workspace_membership_join_policy.py on lines 0..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 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

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

        migrations/versions/998437d5ea7a_user_annotations.py on lines 0..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 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 init_api has 71 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        def init_api(app: Flask):
            from pebbles.views.alerts import AlertList, AlertView, SystemStatus, AlertReset
            from pebbles.views.application_categories import ApplicationCategoryList
            from pebbles.views.application_sessions import ApplicationSessionList, ApplicationSessionView, \
                ApplicationSessionLogs
        Severity: Major
        Found in pebbles/app.py - About 2 hrs to fix

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

              @auth.login_required
              @requires_admin
              @marshal_with(lock_fields)
              def get(self, lock_id):
                  q = Lock.query.filter_by(id=lock_id)
          Severity: Major
          Found in pebbles/views/locks.py and 2 other locations - About 2 hrs to fix
          pebbles/views/alerts.py on lines 86..95
          pebbles/views/tasks.py on lines 78..86

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

          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

          class AlertView(restful.Resource):
              @auth.login_required
              @requires_admin
              @marshal_with(alert_fields)
              def get(self, id):
          Severity: Major
          Found in pebbles/views/alerts.py and 2 other locations - About 2 hrs to fix
          pebbles/views/locks.py on lines 33..41
          pebbles/views/tasks.py on lines 78..86

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

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

              def patch(self, application_session_id):
                  user = g.user
          
                  # check that the user has rights to access the session
                  opts = dict(application_session_id=application_session_id)
          Severity: Minor
          Found in pebbles/views/application_sessions.py - 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 get_provisioning_config has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
          Open

          def get_provisioning_config(application):
              """Render provisioning config for application"""
          
              app_config = application.config if application.config else {}
              provisioning_config = application.base_config.copy()
          Severity: Minor
          Found in pebbles/utils.py - 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 do_deprovision has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
          Open

              def do_deprovision(self, token, application_session_id):
                  application_session = self.fetch_and_populate_application_session(token, application_session_id)
                  namespace = self.get_application_session_namespace(application_session)
                  # remove deployment
                  try:
          Severity: Minor
          Found in pebbles/drivers/provisioning/kubernetes_driver.py - 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