Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #20468: adapt rudder-compliance script for python 3 #687

Conversation

ncharles
Copy link
Member

Copy link

@juhnny5 juhnny5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added 2/3 things that can be improved.

for j in directives_compliance_output[i]:
directive_name = id_to_name(directives, j)
directive_compliance = directives_compliance_output[i][j]

print '** ' + directive_name + ': ' + str(directive_compliance) + '%'
print('** ' + directive_name + ': ' + str(directive_compliance) + '%')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it more readable, you should use the f-strings

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f-string was introduced in Python 3.6, yet some distro are not using it (sles12 is using python 3.4)
i'm looking for an alternative


csv_content.append([ i, j, directive_compliance ])

print ''
print('')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To display an empty line, a "print()" is enough

@@ -20,7 +20,7 @@ from requests.packages.urllib3.exceptions import InsecureRequestWarning, Insecur
# Configuration - BEGIN
api_version = "latest"
api_url = "https://rudder.example.com/rudder/api"
api_token = "dTxvl4eL8p3YqvwefVbaJLdy8DyEt7Vw"
api_token = "z7v9j0hsNnrjRvBnLvL01ioUwVJpTgHs"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why specify in hard the API key and the API url ? Why not do it via options to the script and give it default values (like: "https://localhost/rudder" for the endpoint)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it was done like that :)
I don't have a much better reason than that

rules_compliance_output.append([id, compliance])

# Human-readable output
for i in rules_compliance_output:
print "* Rule " + id_to_name(rules, i[0]) + ": " + str(i[1]) + '%'
print("* Rule " + id_to_name(rules, i[0]) + ": " + str(i[1]) + '%')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it more readable, you should use the f-strings

@ncharles
Copy link
Member Author

PR updated with a new commit

@ncharles
Copy link
Member Author

PR updated with a new commit

@juhnny5
Copy link

juhnny5 commented Dec 23, 2021

Everything is ok, @amousset you can merge this PR.

@@ -4,40 +4,45 @@
# Name: rudder-compliance
# Synopsis: Get compliance output Rules and Directives
# Requirements: requests Python module
# Author: Matthieu Cerda <matthieu.cerda@normation.com>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😢

api_url = "https://rudder.example.com/rudder/api"
api_token = "dTxvl4eL8p3YqvwefVbaJLdy8DyEt7Vw"
default_api_url = "https://rudder.example.com/rudder/api"
default_api_token = "z7v9j0hsNnrjRvBnLvL01ioUwVJpTgHs"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it does not make sense to have default values here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as I think of it why not it clearly shows where to replace the values

@Normation-Quality-Assistant

OK, squash merging this PR

@Normation-Quality-Assistant Normation-Quality-Assistant force-pushed the bug_20468/adapt_rudder_compliance_script_for_python_3 branch from 479175c to 0f79308 Compare December 27, 2021 13:25
@Normation-Quality-Assistant Normation-Quality-Assistant merged commit 0f79308 into Normation:master Dec 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants