Skip to content

Commit

Permalink
Log a message if we fail to read or write auth token from file.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kami committed Jul 30, 2016
1 parent 2f02aec commit 25c414e
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions libcloud/common/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
except ImportError:
import json

import logging
import base64
import errno
import time
Expand Down Expand Up @@ -101,6 +102,8 @@

UTC_TIMESTAMP_FORMAT = '%Y-%m-%dT%H:%M:%SZ'

LOG = logging.getLogger(__name__)


def _utcnow():
"""
Expand Down Expand Up @@ -680,17 +683,21 @@ def _get_token_from_file(self):
except (IOError, ValueError):
# Note: File related errors (IOError) and errors related to json
# parsing of the data (ValueError) are not fatal.
pass
e = sys.exc_info()[1]
LOG.info('Failed to read cached auth token from file "%s": %s',
filename, str(e))

return token

def _write_token_to_file(self):
"""
Write token to credential file.
Mocked in libcloud.test.common.google.GoogleTestCase.
"""
filename = os.path.expanduser(self.credential_file)
filename = os.path.realpath(filename)

try:
filename = os.path.expanduser(self.credential_file)
filename = os.path.realpath(filename)
data = json.dumps(self.token)
write_flags = os.O_CREAT | os.O_WRONLY | os.O_TRUNC
with os.fdopen(os.open(filename, write_flags,
Expand All @@ -700,7 +707,9 @@ def _write_token_to_file(self):
# Note: Failed to write (cache) token in a file is not fatal. It
# simply means degraded performance since we will need to acquire a
# new token each time script runs.
pass
e = sys.exc_info()[1]
LOG.info('Failed to write auth token to file "%s": %s',
filename, str(e))


class GoogleBaseConnection(ConnectionUserAndKey, PollingConnection):
Expand Down

0 comments on commit 25c414e

Please sign in to comment.