'Write token to credential file.
Mocked in libcloud.test.common.google.GoogleTestCase.'

def _write_token_to_file(self):

    filename = os.path.expanduser(self.credential_file)
    filename = os.path.realpath(filename)
    try:
        data = json.dumps(self.token)
        write_flags = ((os.O_CREAT | os.O_WRONLY) | os.O_TRUNC)
        with os.fdopen(os.open(filename, write_flags, int('600', 8)), 'w') as f:
            f.write(data)
    except:
        e = sys.exc_info()[1]
        LOG.info('Failed    to    write    auth    token    to    file    "%s":    %s', filename, str(e))
