theforeman/foreman_ansible

View on GitHub

Showing 105 of 105 total issues

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

    userEvent.type(
      screen.getByLabelText(/startTime/),
      futureDate
        .toISOString()
        .split('T')[1]
webpack/routes/HostgroupJobs/__test__/HostgroupJobs.test.js on lines 83..89

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

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

export const advancedMockFactory = query => (
  variables,
  data,
  { errors = [], currentUser = null, refetchData = null } = {}
) => {
Severity: Minor
Found in webpack/testHelper.js - About 35 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

Method import_playbooks has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def import_playbooks(playbooks_names)
      playbooks = playbooks(playbooks_names)
      result = { created: {}, updated: {} }
      playbooks.each do |playbook|
        parsed_playbook = parse_playbook playbook
Severity: Minor
Found in app/services/foreman_ansible/playbooks_importer.rb - About 35 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

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

  const renameData = data => ({
    ansibleRoles: data.host.ownAnsibleRoles.nodes,
    totalCount: data.host.ownAnsibleRoles.totalCount,
  });
webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/index.js on lines 31..34
webpack/components/AnsibleHostDetail/components/RolesTab/AllRolesModal/index.js on lines 54..57

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

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

  const renameData = data => ({
    variables: data.host.ansibleVariablesWithOverrides.nodes,
    totalCount: data.host.ansibleVariablesWithOverrides.totalCount,
  });
webpack/components/AnsibleHostDetail/components/RolesTab/AllRolesModal/index.js on lines 54..57
webpack/components/AnsibleHostDetail/components/RolesTab/index.js on lines 24..27

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

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

  const renameData = data => ({
    allAnsibleRoles: data.host.allAnsibleRoles.nodes,
    totalCount: data.host.allAnsibleRoles.totalCount,
  });
webpack/components/AnsibleHostDetail/components/AnsibleVariableOverrides/index.js on lines 31..34
webpack/components/AnsibleHostDetail/components/RolesTab/index.js on lines 24..27

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

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

    render(
      <TestComponent
        hostId={hostId}
        mocks={mocks.concat(editModalOpenMocks).concat(assignRolesErrorMock)}
        canEditHost
webpack/components/AnsibleHostDetail/components/RolesTab/__test__/EditRoles.test.js on lines 32..38

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

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

    render(
      <TestComponent
        hostId={hostId}
        mocks={mocks.concat(editModalOpenMocks).concat(assignRolesSuccessMock)}
        canEditHost
webpack/components/AnsibleHostDetail/components/RolesTab/__test__/EditRoles.test.js on lines 61..67

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

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

  class Managed
    apipie :class do
      property :all_ansible_roles, array_of: 'AnsibleRole', desc: 'Returns all ansible roles assigned to the host, both its own and inherited from the host group and its parents'
      property :ansible_roles, array_of: 'AnsibleRole', desc: 'Returns ansible roles directly assigned to the host'
      property :inherited_ansible_roles, array_of: 'AnsibleRole', desc: 'Returns only ansible roles assigned to the host\'s host group and its parents'
Severity: Minor
Found in app/models/concerns/foreman_ansible/host_managed_extensions.rb and 1 other location - About 30 mins to fix
app/models/concerns/foreman_ansible/hostgroup_extensions.rb on lines 57..66

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

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

class Hostgroup
  apipie :class do
    property :all_ansible_roles, array_of: 'AnsibleRole', desc: 'Returns all ansible roles assigned to the host group, both its own and inherited from parent host groups'
    property :ansible_roles, array_of: 'AnsibleRole', desc: 'Returns ansible roles directly assigned to the host group'
    property :inherited_ansible_roles, array_of: 'AnsibleRole', desc: 'Returns only the inherited ansible roles assigned to the host group\'s parents'
Severity: Minor
Found in app/models/concerns/foreman_ansible/hostgroup_extensions.rb and 1 other location - About 30 mins to fix
app/models/concerns/foreman_ansible/host_managed_extensions.rb on lines 91..100

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

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

Avoid too many return statements within this function.
Open

      return emptyWrapper(
        <EmptyState
          {...{
            ...defaultEmptyStateProps,
            ...allowPrimaryAction(
Severity: Major
Found in webpack/components/withLoading.js - About 30 mins to fix

    Unescaped parameter value
    Open

    <%= will_paginate_with_info @ansible_variables %>

    Cross-site scripting (or XSS) is #3 on the 2013 [OWASP Top Ten](https://www.owasp.org/index.php/Top_10_2013-A3-Cross-Site_Scripting_(XSS\)) web security risks and it pops up nearly everywhere.

    XSS occurs when a user-controlled value is displayed on a web page without properly escaping it, allowing someone to inject Javascript or HTML into the page which will be interpreted and executed by the browser..

    In Rails 2.x, values need to be explicitly escaped (e.g., by using the h method). Since Rails 3.x, auto-escaping in views is enabled by default. However, one can still use the raw or html_safe methods to output a value directly.

    See the Ruby Security Guide for more details.

    Query Parameters and Cookies

    ERB example:

    <%= params[:query].html_safe %>

    Brakeman looks for several situations that can allow XSS. The simplest is like the example above: a value from the params or cookies is being directly output to a view. In such cases, it will issue a warning like:

    Unescaped parameter value near line 3: params[:query]

    By default, Brakeman will also warn when a parameter or cookie value is used as an argument to a method, the result of which is output unescaped to a view.

    For example:

    <%= raw some_method(cookie[:name]) %>

    This raises a warning like:

    Unescaped cookie value near line 5: some_method(cookies[:oreo])

    However, the confidence level for this warning will be weak, because it is not directly outputting the cookie value.

    Some methods are known to Brakeman to either be dangerous (link_to is one) or safe (escape_once). Users can specify safe methods using the --safe-methods option. Alternatively, Brakeman can be set to only warn when values are used directly with the --report-direct option.

    Model Attributes

    Because (many) models come from database values, Brakeman mistrusts them by default.

    For example, if @user is an instance of a model set in an action like

    def set_user
      @user = User.first
    end

    and there is a view with

    <%= @user.name.html_safe %>

    Brakeman will raise a warning like

    Unescaped model attribute near line 3: User.first.name

    If you trust all your data (although you probably shouldn't), this can be disabled with --ignore-model-output.

    Avoid too many return statements within this function.
    Open

        return wrapper(<Component {...rest} {...renamedData} />);
    Severity: Major
    Found in webpack/components/withLoading.js - About 30 mins to fix

      Unescaped parameter value
      Open

      <%= will_paginate_with_info @ansible_roles %>

      Cross-site scripting (or XSS) is #3 on the 2013 [OWASP Top Ten](https://www.owasp.org/index.php/Top_10_2013-A3-Cross-Site_Scripting_(XSS\)) web security risks and it pops up nearly everywhere.

      XSS occurs when a user-controlled value is displayed on a web page without properly escaping it, allowing someone to inject Javascript or HTML into the page which will be interpreted and executed by the browser..

      In Rails 2.x, values need to be explicitly escaped (e.g., by using the h method). Since Rails 3.x, auto-escaping in views is enabled by default. However, one can still use the raw or html_safe methods to output a value directly.

      See the Ruby Security Guide for more details.

      Query Parameters and Cookies

      ERB example:

      <%= params[:query].html_safe %>

      Brakeman looks for several situations that can allow XSS. The simplest is like the example above: a value from the params or cookies is being directly output to a view. In such cases, it will issue a warning like:

      Unescaped parameter value near line 3: params[:query]

      By default, Brakeman will also warn when a parameter or cookie value is used as an argument to a method, the result of which is output unescaped to a view.

      For example:

      <%= raw some_method(cookie[:name]) %>

      This raises a warning like:

      Unescaped cookie value near line 5: some_method(cookies[:oreo])

      However, the confidence level for this warning will be weak, because it is not directly outputting the cookie value.

      Some methods are known to Brakeman to either be dangerous (link_to is one) or safe (escape_once). Users can specify safe methods using the --safe-methods option. Alternatively, Brakeman can be set to only warn when values are used directly with the --report-direct option.

      Model Attributes

      Because (many) models come from database values, Brakeman mistrusts them by default.

      For example, if @user is an instance of a model set in an action like

      def set_user
        @user = User.first
      end

      and there is a view with

      <%= @user.name.html_safe %>

      Brakeman will raise a warning like

      Unescaped model attribute near line 3: User.first.name

      If you trust all your data (although you probably shouldn't), this can be disabled with --ignore-model-output.

      Unescaped parameter value
      Open

              :rowsData => @rows,

      Cross-site scripting (or XSS) is #3 on the 2013 [OWASP Top Ten](https://www.owasp.org/index.php/Top_10_2013-A3-Cross-Site_Scripting_(XSS\)) web security risks and it pops up nearly everywhere.

      XSS occurs when a user-controlled value is displayed on a web page without properly escaping it, allowing someone to inject Javascript or HTML into the page which will be interpreted and executed by the browser..

      In Rails 2.x, values need to be explicitly escaped (e.g., by using the h method). Since Rails 3.x, auto-escaping in views is enabled by default. However, one can still use the raw or html_safe methods to output a value directly.

      See the Ruby Security Guide for more details.

      Query Parameters and Cookies

      ERB example:

      <%= params[:query].html_safe %>

      Brakeman looks for several situations that can allow XSS. The simplest is like the example above: a value from the params or cookies is being directly output to a view. In such cases, it will issue a warning like:

      Unescaped parameter value near line 3: params[:query]

      By default, Brakeman will also warn when a parameter or cookie value is used as an argument to a method, the result of which is output unescaped to a view.

      For example:

      <%= raw some_method(cookie[:name]) %>

      This raises a warning like:

      Unescaped cookie value near line 5: some_method(cookies[:oreo])

      However, the confidence level for this warning will be weak, because it is not directly outputting the cookie value.

      Some methods are known to Brakeman to either be dangerous (link_to is one) or safe (escape_once). Users can specify safe methods using the --safe-methods option. Alternatively, Brakeman can be set to only warn when values are used directly with the --report-direct option.

      Model Attributes

      Because (many) models come from database values, Brakeman mistrusts them by default.

      For example, if @user is an instance of a model set in an action like

      def set_user
        @user = User.first
      end

      and there is a view with

      <%= @user.name.html_safe %>

      Brakeman will raise a warning like

      Unescaped model attribute near line 3: User.first.name

      If you trust all your data (although you probably shouldn't), this can be disabled with --ignore-model-output.

      Avoid too many return statements within this function.
      Open

        return 'custom';
      Severity: Major
      Found in webpack/components/AnsibleHostDetail/components/JobsTab/JobsTabHelper.js - About 30 mins to fix

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

            case 'weekly':
              return `${date.getMinutes()} ${date.getHours()} * * ${date.getDay()}`;
        webpack/components/AnsibleHostDetail/components/JobsTab/NewRecurringJobHelper.js on lines 39..40

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

        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

            case 'monthly':
              return `${date.getMinutes()} ${date.getHours()} ${date.getDate()} * *`;
        webpack/components/AnsibleHostDetail/components/JobsTab/NewRecurringJobHelper.js on lines 37..38

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

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

        const EditableAction = ({
          onValidationError,
          toggleWorking,
          onSubmitSuccess,
          open,

        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

        Method partial_hostname_match has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def partial_hostname_match(hostname)
                return @host unless @host.new_record?
                hosts = Host.where(Host.arel_table[:name].matches("#{hostname}.%"))
                if hosts.count > 1
                  msg = "More than 1 host found for name #{hostname}, "
        Severity: Minor
        Found in app/services/foreman_ansible/ansible_report_importer.rb - 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

        Severity
        Category
        Status
        Source
        Language