| Index: chrome/common/extensions/docs/server2/gcs_file_system_provider.py
|
| diff --git a/chrome/common/extensions/docs/server2/gcs_file_system_provider.py b/chrome/common/extensions/docs/server2/gcs_file_system_provider.py
|
| index 22369ae27dc145a6236bb66984bbabaf33f1b677..f355e64cbdb6c9a4572100b0068cd58379cc5bf0 100644
|
| --- a/chrome/common/extensions/docs/server2/gcs_file_system_provider.py
|
| +++ b/chrome/common/extensions/docs/server2/gcs_file_system_provider.py
|
| @@ -4,12 +4,16 @@
|
|
|
| import os
|
| import environment
|
| +import logging
|
|
|
| from caching_file_system import CachingFileSystem
|
| from empty_dir_file_system import EmptyDirFileSystem
|
| +from environment import IsTest
|
| from extensions_paths import LOCAL_GCS_DIR, LOCAL_GCS_DEBUG_CONF
|
| +from gcs_file_system import CloudStorageFileSystem
|
| from local_file_system import LocalFileSystem
|
| -from path_util import IsDirectory, ToDirectory
|
| +from path_util import ToDirectory
|
| +
|
|
|
| class CloudStorageFileSystemProvider(object):
|
| '''Provides CloudStorageFileSystem bound to a GCS bucket.
|
| @@ -25,66 +29,33 @@ class CloudStorageFileSystemProvider(object):
|
|
|
| Optional configuration can be set in a local_debug/gcs_debug.conf file:
|
| use_local_fs=True|False
|
| - access_token=<token>
|
| remote_bucket_prefix=<prefix>
|
|
|
| If running in Preview mode or in Development mode with use_local_fs set to
|
| - True, buckets and files are looked inside the local_debug folder instead
|
| - of in the real GCS server. Preview server does not support direct GCS
|
| - access, so it is always forced to use a LocalFileSystem.
|
| -
|
| - For real GCS access in the Development mode (dev_appserver.py),
|
| - access_token and remote_bucket_prefix options can be
|
| - used to change the way GCS files are accessed. Both are ignored in a real
|
| - appengine instance.
|
| -
|
| - "access_token" is always REQUIRED on dev_appengine, otherwise you will
|
| - get 404 (auth) errors. You can get one access_token valid for a few minutes
|
| - by typing:
|
| - gsutil -d ls 2>&1 | grep "Bearer" |
|
| - sed "s/.*Bearer \(.*\).r.nUser-Agent.*/access_token=\1/" )"
|
| -
|
| - A sample output would be:
|
| - access_token=ya29.1.AADtN_VW5ibbfLHV5cMIK5ss4bHtVzBXpa4byjd
|
| -
|
| - Now add this line to the local_debug/gcs_debug.conf file and restart the
|
| - appengine development server.
|
| -
|
| - Remember that you will need a new access_token every ten minutes or
|
| - so. If you get 404 errors on log, update it. Access token is not
|
| - used for a deployed appengine app, only if you use dev_appengine.py.
|
| -
|
| - remote_bucket_prefix is useful if you want to test on your own GCS buckets
|
| - before using the real GCS buckets.
|
| -
|
| + True, buckets and files are looked for inside the local_debug folder instead
|
| + of in the real GCS server.
|
| '''
|
| - if not environment.IsReleaseServer() and not environment.IsDevServer():
|
| - bucket_local_path = os.path.join(LOCAL_GCS_DIR, bucket)
|
| - if IsDirectory(bucket_local_path):
|
| - return LocalFileSystem(bucket_local_path)
|
| - else:
|
| - return EmptyDirFileSystem()
|
| + if IsTest():
|
| + return EmptyDirFileSystem()
|
|
|
| - debug_access_token = None
|
| debug_bucket_prefix = None
|
| use_local_fs = False
|
| -
|
| - if environment.IsDevServer() and os.path.exists(LOCAL_GCS_DEBUG_CONF):
|
| + if os.path.exists(LOCAL_GCS_DEBUG_CONF):
|
| with open(LOCAL_GCS_DEBUG_CONF, "r") as token_file:
|
| properties = dict(line.strip().split('=', 1) for line in token_file)
|
| use_local_fs = properties.get('use_local_fs', 'False')=='True'
|
| - debug_access_token = properties.get('access_token', None)
|
| debug_bucket_prefix = properties.get('remote_bucket_prefix', None)
|
| + logging.debug('gcs: prefixing all bucket names with %s' %
|
| + debug_bucket_prefix)
|
|
|
| - if environment.IsDevServer() and use_local_fs:
|
| + if use_local_fs:
|
| return LocalFileSystem(ToDirectory(os.path.join(LOCAL_GCS_DIR, bucket)))
|
|
|
| - # gcs_file_system has strong dependencies on runtime appengine APIs,
|
| - # so we only import it when we are sure we are not on preview.py or tests.
|
| - from gcs_file_system import CloudStorageFileSystem
|
| - return CachingFileSystem(CloudStorageFileSystem(bucket,
|
| - debug_access_token, debug_bucket_prefix),
|
| - self._object_store_creator)
|
| + if debug_bucket_prefix:
|
| + bucket = debug_bucket_prefix + bucket
|
| +
|
| + return CachingFileSystem(CloudStorageFileSystem(bucket),
|
| + self._object_store_creator)
|
|
|
| @staticmethod
|
| def ForEmpty():
|
|
|