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

Side by Side Diff: chrome/common/extensions/docs/server2/gcs_file_system_provider.py

Issue 139303023: add GCS support to docs server (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: bumped versions Created 6 years, 11 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 unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import os
6
7 from caching_file_system import CachingFileSystem
8 import environment
9 from extensions_paths import LOCAL_GCS_DIR, LOCAL_GCS_DEBUG_CONF
10 from local_file_system import LocalFileSystem
11 from empty_dir_file_system import EmptyDirFileSystem
12
13
14 class CloudStorageFileSystemProvider(object):
15 '''Provides CloudStorageFileSystem bound to a GCS bucket.
16 '''
17 def __init__(self, object_store_creator):
18 self._object_store_creator = object_store_creator
19
20 def Create(self, bucket):
21 '''Creates a CloudStorageFileSystemProvider.
22
23 |bucket| is the name of GCS bucket, eg devtools-docs. It is expected
24 that this bucket has Read permission for this app in its ACLs
25
26 Optional configuration can be set in a local_debug/gcs_debug.conf file:
27 use_local_fs=True|False
28 access_token=<token>
29 remote_bucket_prefix=<prefix>
30
31 If running in Preview mode or in Development mode with use_local_fs set to
Jeffrey Yasskin 2014/01/29 01:08:08 Can you add some piece of this to chrome/common/ex
Renato Mangini (chromium) 2014/01/31 02:29:04 Done.
32 True, buckets and files are looked inside the local_debug folder instead
33 of in the real GCS server. Preview server does not support direct GCS
34 access, so it is always forced to use a LocalFileSystem.
35
36 For real GCS access in the Development mode (dev_appserver.py),
37 access_token and remote_bucket_prefix options can be
38 used to change the way GCS files are accessed. Both are ignored in a real
39 appengine instance.
40
41 "access_token" is always REQUIRED on dev_appengine, otherwise you will
42 get 404 (auth) errors. You can get one access_token valid for a few minutes
43 by typing:
44 gsutil -d ls 2>&1 | grep "Bearer" |
45 sed "s/.*Bearer \(.*\).r.nUser-Agent.*/access_token=\1/" )"
46
47 A sample output would be:
48 access_token=ya29.1.AADtN_VW5ibbfLHV5cMIK5ss4bHtVzBXpa4byjd
49
50 Now add this line to the local_debug/gcs_debug.conf file and restart the
51 appengine development server.
52
53 Remember that you will need a new access_token every ten minutes or
54 so. If you get 404 errors on log, update it. Access token is not
55 used for a deployed appengine app, only if you use dev_appengine.py
56
57 remote_bucket_prefix is useful if you want to test on your own GCS buckets
58 before using the real GCS buckets.
59
60 '''
61 if not environment.IsReleaseServer() and not environment.IsDevServer():
62 return LocalFileSystem(os.path.join(LOCAL_GCS_DIR, bucket))
63
64 debug_access_token = None
65 debug_bucket_prefix = None
66 use_local_fs = False
67
68 if environment.IsDevServer() and os.path.exists(LOCAL_GCS_DEBUG_CONF):
69 with open(LOCAL_GCS_DEBUG_CONF, "r") as token_file:
70 properties = dict(line.strip().split('=', 1) for line in token_file)
71 use_local_fs = properties.get('use_local_fs', 'False')=='True'
72 debug_access_token = properties.get('access_token', None)
73 debug_bucket_prefix = properties.get('remote_bucket_prefix', None)
74
75 if environment.IsDevServer() and use_local_fs:
76 return LocalFileSystem(os.path.join(LOCAL_GCS_DIR, bucket))
77
78 from gcs_file_system import CloudStorageFileSystem
Jeffrey Yasskin 2014/01/29 01:08:08 Comment why this is imported late.
Renato Mangini (chromium) 2014/01/31 02:29:04 Done.
79 return CloudStorageFileSystem(bucket,
80 debug_access_token, debug_bucket_prefix)
Jeffrey Yasskin 2014/01/29 01:08:08 Check the indentation.
Renato Mangini (chromium) 2014/01/31 02:29:04 Done.
81
82
83 @staticmethod
84 def ForEmpty():
85 class EmptyImpl(object):
86 def Create(self, bucket):
87 return EmptyDirFileSystem()
88 return EmptyImpl()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698