Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1481)

Unified Diff: appengine/chromium_build_logs/third_party/oauth2client/file.py

Issue 1260293009: make version of ts_mon compatible with appengine (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: clean up code Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/chromium_build_logs/third_party/oauth2client/file.py
diff --git a/appengine/chromium_build_logs/third_party/oauth2client/file.py b/appengine/chromium_build_logs/third_party/oauth2client/file.py
index d71e8883dafeae8a2a6030415ad069dfd3f7c8f7..9d0ae7fabf2f52df552973f17b1ec39cf3cb5ee7 100644
--- a/appengine/chromium_build_logs/third_party/oauth2client/file.py
+++ b/appengine/chromium_build_logs/third_party/oauth2client/file.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2010 Google Inc.
+# Copyright 2014 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -21,12 +21,14 @@ credentials.
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
import os
-import stat
import threading
-from anyjson import simplejson
-from client import Storage as BaseStorage
-from client import Credentials
+from oauth2client.client import Credentials
+from oauth2client.client import Storage as BaseStorage
+
+
+class CredentialsFileSymbolicLinkError(Exception):
+ """Credentials files must not be symbolic links."""
class Storage(BaseStorage):
@@ -36,6 +38,11 @@ class Storage(BaseStorage):
self._filename = filename
self._lock = threading.Lock()
+ def _validate_file(self):
+ if os.path.islink(self._filename):
+ raise CredentialsFileSymbolicLinkError(
+ 'File: %s is a symbolic link.' % self._filename)
+
def acquire_lock(self):
"""Acquires any lock necessary to access this Storage.
@@ -55,8 +62,12 @@ class Storage(BaseStorage):
Returns:
oauth2client.client.Credentials
+
+ Raises:
+ CredentialsFileSymbolicLinkError if the file is a symbolic link.
"""
credentials = None
+ self._validate_file()
try:
f = open(self._filename, 'rb')
content = f.read()
@@ -79,21 +90,33 @@ class Storage(BaseStorage):
simple version of "touch" to ensure the file has been created.
"""
if not os.path.exists(self._filename):
- old_umask = os.umask(0177)
+ old_umask = os.umask(0o177)
try:
open(self._filename, 'a+b').close()
finally:
os.umask(old_umask)
-
def locked_put(self, credentials):
"""Write Credentials to file.
Args:
credentials: Credentials, the credentials to store.
+
+ Raises:
+ CredentialsFileSymbolicLinkError if the file is a symbolic link.
"""
self._create_file_if_needed()
- f = open(self._filename, 'wb')
+ self._validate_file()
+ f = open(self._filename, 'w')
f.write(credentials.to_json())
f.close()
+
+ def locked_delete(self):
+ """Delete Credentials file.
+
+ Args:
+ credentials: Credentials, the credentials to store.
+ """
+
+ os.unlink(self._filename)

Powered by Google App Engine
This is Rietveld 408576698