Move all opens in auth_token to be in context
This commit switches the use of open() to be in a with context. This will prevent leaking file descriptors because using a context provides an inherent close(). Prior to this commit it was possible that an exception or error during the write() call could prevent close() from running. Change-Id: Ib13fe651d41f0eafea23a1c96c6c64d405de7e49
This commit is contained in:
@@ -1217,9 +1217,8 @@ class AuthProtocol(object):
|
|||||||
'/v2.0/certificates/signing')
|
'/v2.0/certificates/signing')
|
||||||
|
|
||||||
def write_cert_file(data):
|
def write_cert_file(data):
|
||||||
certfile = open(self.signing_cert_file_name, 'w')
|
with open(self.signing_cert_file_name, 'w') as certfile:
|
||||||
certfile.write(data)
|
certfile.write(data)
|
||||||
certfile.close()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
#todo check response
|
#todo check response
|
||||||
@@ -1238,9 +1237,8 @@ class AuthProtocol(object):
|
|||||||
'/v2.0/certificates/ca')
|
'/v2.0/certificates/ca')
|
||||||
try:
|
try:
|
||||||
#todo check response
|
#todo check response
|
||||||
certfile = open(self.ca_file_name, 'w')
|
with open(self.ca_file_name, 'w') as certfile:
|
||||||
certfile.write(data)
|
certfile.write(data)
|
||||||
certfile.close()
|
|
||||||
except (AssertionError, KeyError):
|
except (AssertionError, KeyError):
|
||||||
self.LOG.warn(
|
self.LOG.warn(
|
||||||
"Unexpected response from keystone service: %s", data)
|
"Unexpected response from keystone service: %s", data)
|
||||||
|
Reference in New Issue
Block a user