saltstack/salt

View on GitHub
salt/runners/digicertapi.py

Summary

Maintainability
F
5 days
Test Coverage

File digicertapi.py has 585 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
'''
Support for Digicert.  Heavily based on the Venafi runner by Joseph Hall (jphall@saltstack.com).

Before using this module you need to register an account with Digicert's CertCentral.
Severity: Major
Found in salt/runners/digicertapi.py - About 1 day to fix

    Function get_certificate has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_certificate(order_id=None, certificate_id=None, minion_id=None, cert_format='pem_all', filename=None):
        '''
        Retrieve a certificate by order_id or certificate_id and write it to stdout or a filename.
    
        A list of permissible cert_formats is here:
    Severity: Minor
    Found in salt/runners/digicertapi.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 order_certificate has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

    def order_certificate(minion_id, common_name, organization_id, validity_years,
                          cert_key_passphrase=None, signature_hash=None, key_len=2048,
                          dns_names=None, organization_units=None, server_platform=None,
                          custom_expiration_date=None, comments=None, disable_renewal_notifications=False,
                          product_type_hint=None, renewal_of_order_id=None):
    Severity: Minor
    Found in salt/runners/digicertapi.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 gen_key has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def gen_key(minion_id, dns_name=None, password=None, key_len=2048):
        '''
        Generate and return a private_key. If a ``dns_name`` is passed in, the
        private_key will be cached under that name.
    
    
    Severity: Minor
    Found in salt/runners/digicertapi.py - About 55 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

    Avoid too many return statements within this function.
    Open

        return {'certificate': cert}
    Severity: Major
    Found in salt/runners/digicertapi.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

              return {'certificate': {'filename': filename,
      Severity: Major
      Found in salt/runners/digicertapi.py - About 30 mins to fix

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

        def gen_csr(
                minion_id,
                dns_name,
                organization_id,
                ou_name=None,
        Severity: Minor
        Found in salt/runners/digicertapi.py - 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

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

            if keygen_type == "RSA":
                if HAS_M2:
                    gen = RSA.gen_key(key_len, 65537)
                    private_key = gen.as_pem(cipher='des_ede3_cbc', callback=lambda x: six.b(password))
                else:
        Severity: Major
        Found in salt/runners/digicertapi.py and 1 other location - About 1 day to fix
        salt/runners/venafiapi.py on lines 149..166

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

        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 del_cached_domain(domains):
            '''
            Delete cached domains from the master
        
            CLI Example:
        Severity: Major
        Found in salt/runners/digicertapi.py and 1 other location - About 7 hrs to fix
        salt/runners/venafiapi.py on lines 643..669

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

        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 _id_map(minion_id, dns_name):
            '''
            Maintain a relationship between a minion and a dns name
            '''
            bank = 'digicert/minions'
        Severity: Major
        Found in salt/runners/digicertapi.py and 1 other location - About 4 hrs to fix
        salt/runners/venafiapi.py on lines 368..379

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

        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

            subject = '/C={0}/ST={1}/L={2}/O={3}'.format(
                org_details['dict']['country'],
                org_details['dict']['state'],
                org_details['dict']['city'],
                org_details['dict']['display_name'])
        Severity: Major
        Found in salt/runners/digicertapi.py and 1 other location - About 2 hrs to fix
        salt/state.py on lines 2101..2107

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

        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 show_rsa(minion_id, dns_name):
            '''
            Show a private RSA key
        
            CLI Example:
        Severity: Major
        Found in salt/runners/digicertapi.py and 1 other location - About 1 hr to fix
        salt/runners/venafiapi.py on lines 611..626

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

        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

            with salt.utils.files.fopen(tmppriv, 'w') as if_:
                if_.write(salt.utils.stringutils.to_str(data['private_key']))
        Severity: Major
        Found in salt/runners/digicertapi.py and 5 other locations - About 40 mins to fix
        salt/crypt.py on lines 1119..1123
        salt/daemons/masterapi.py on lines 982..983
        salt/fileserver/azurefs.py on lines 293..294
        salt/runners/venafiapi.py on lines 209..210
        salt/wheel/key.py on lines 419..420

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

        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