Skip to content

Refactor the loop in check_authorization_status - #149

Open
rozgonik wants to merge 1 commit into
komuw:masterfrom
rozgonik:master
Open

Refactor the loop in check_authorization_status#149
rozgonik wants to merge 1 commit into
komuw:masterfrom
rozgonik:master

Conversation

@rozgonik

@rozgonik rozgonik commented Mar 15, 2020

Copy link
Copy Markdown
Contributor

What have you changed?

Changed the while loop with an implicit counter to an explicit for cycle.
Also the "Checks done" and the "Max checks allowed" counter in the StopIteration exception makes no sense, because the two values will be the same (and equal to ACME_AUTH_STATUS_MAX_CHECKS) every time the exception kicks in.
I do not want to fiddle with the exception message, so made the counters reference the same value.

Why did you change it?

@mmaney suggested the refactoring of this method's cycle at #148 in his comment.

Further refactoring can be done in the following way:

for [...]
    [...]
    if authorization_status in desired_status:
        self.logger.info("check_authorization_status_success")
        return check_authorization_status_response
raise StopIteration(
    "Checks done={0}. Max checks allowed={0}. Interval between checks={1}seconds.".format(
        self.ACME_AUTH_STATUS_MAX_CHECKS,
        self.ACME_AUTH_STATUS_WAIT_PERIOD,
    )
)

However it breaks the convention of ending the method with a logger call and a return statement.
To be consistent I opted to implement a variant with less changes.

(When submitting the original PR I had difficulties finding time for doing a proper refactor, that's why #148 was a quick-n-dirty fix.)

Update:
Sorry for the noise about the force-pushes.
(FYI: black==18.9b0 and the latest black==19.10b0 has different rulesets about trailing commas.)

@codecov

codecov Bot commented Mar 15, 2020

Copy link
Copy Markdown

Codecov Report

Merging #149 into master will increase coverage by 0.06%.
The diff coverage is 50%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #149      +/-   ##
=========================================
+ Coverage   86.44%   86.5%   +0.06%     
=========================================
  Files          14      14              
  Lines         944     941       -3     
=========================================
- Hits          816     814       -2     
+ Misses        128     127       -1
Impacted Files Coverage Δ
sewer/client.py 92.33% <50%> (+0.25%) ⬆️

@rozgonik
rozgonik force-pushed the master branch 2 times, most recently from a35a833 to 2d6660d Compare March 15, 2020 17:31
@komuw

komuw commented Mar 16, 2020

Copy link
Copy Markdown
Owner

@mmaney I'm happy with this PR if you are.

@mmaney mmaney self-assigned this Sep 10, 2020
@mmaney mmaney added this to the 0.8.5 milestone Sep 10, 2020
@mmaney

mmaney commented Sep 10, 2020

Copy link
Copy Markdown
Collaborator

Another old bug/PR that will be part of the get_certificate refactoring work.

@mmaney mmaney added the refactoring a sizable chunk of code needs to change label Sep 19, 2020
@mmaney mmaney modified the milestones: 0.8.5, 0.9 Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring a sizable chunk of code needs to change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants