sewer icon indicating copy to clipboard operation
sewer copied to clipboard

Refactor the loop in check_authorization_status

Open rozgonik opened this issue 4 years ago • 3 comments

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

rozgonik avatar Mar 15 '20 17:03 rozgonik

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%) :arrow_up:

codecov[bot] avatar Mar 15 '20 17:03 codecov[bot]

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

komuw avatar Mar 16 '20 00:03 komuw

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

mmaney avatar Sep 10 '20 20:09 mmaney