##// END OF EJS Templates
file-store: changed for stream upload endpoint.
milka -
r4611:29d668ad stable
parent child
Show More
@@ -21,7 +21,6
21 import os
21 import os
22 import time
22 import time
23 import errno
23 import errno
24 import shutil
25 import hashlib
24 import hashlib
26
25
27 from rhodecode.lib.ext_json import json
26 from rhodecode.lib.ext_json import json
@@ -212,10 +211,19 class LocalFileStorage(object):
212 filename, path = self.resolve_name(uid_filename, dest_directory)
211 filename, path = self.resolve_name(uid_filename, dest_directory)
213 stored_file_dir = os.path.dirname(path)
212 stored_file_dir = os.path.dirname(path)
214
213
215 file_obj.seek(0)
214 no_body_seek = kwargs.pop('no_body_seek', False)
215 if no_body_seek:
216 pass
217 else:
218 file_obj.seek(0)
216
219
217 with open(path, "wb") as dest:
220 with open(path, "wb") as dest:
218 shutil.copyfileobj(file_obj, dest)
221 length = 256 * 1024
222 while 1:
223 buf = file_obj.read(length)
224 if not buf:
225 break
226 dest.write(buf)
219
227
220 metadata = {}
228 metadata = {}
221 if extra_metadata:
229 if extra_metadata:
@@ -27,11 +27,14 def pyramid_ext_json(info):
27 """
27 """
28 def _render(value, system):
28 def _render(value, system):
29 request = system.get('request')
29 request = system.get('request')
30 indent = None
30 if request is not None:
31 if request is not None:
31 response = request.response
32 response = request.response
32 ct = response.content_type
33 ct = response.content_type
33 if ct == response.default_content_type:
34 if ct == response.default_content_type:
34 response.content_type = 'application/json'
35 response.content_type = 'application/json'
35 return json.dumps(value)
36 indent = getattr(request, 'ext_json_indent', None)
37
38 return json.dumps(value, indent=indent)
36
39
37 return _render
40 return _render
@@ -749,8 +749,11 class User(Base, BaseModel):
749
749
750 def get_artifact_token(self, cache=True):
750 def get_artifact_token(self, cache=True):
751 artifacts_tokens = UserApiKeys.query()\
751 artifacts_tokens = UserApiKeys.query()\
752 .filter(UserApiKeys.user == self)\
752 .filter(UserApiKeys.user == self) \
753 .filter(or_(UserApiKeys.expires == -1,
754 UserApiKeys.expires >= time.time())) \
753 .filter(UserApiKeys.role == UserApiKeys.ROLE_ARTIFACT_DOWNLOAD)
755 .filter(UserApiKeys.role == UserApiKeys.ROLE_ARTIFACT_DOWNLOAD)
756
754 if cache:
757 if cache:
755 artifacts_tokens = artifacts_tokens.options(
758 artifacts_tokens = artifacts_tokens.options(
756 FromCache("sql_cache_short", "get_user_artifact_token_%s" % self.user_id))
759 FromCache("sql_cache_short", "get_user_artifact_token_%s" % self.user_id))
@@ -760,6 +763,24 class User(Base, BaseModel):
760 return artifacts_tokens[0].api_key
763 return artifacts_tokens[0].api_key
761 return 'NO_ARTIFACT_TOKEN_AVAILABLE'
764 return 'NO_ARTIFACT_TOKEN_AVAILABLE'
762
765
766 def get_or_create_artifact_token(self):
767 artifacts_tokens = UserApiKeys.query()\
768 .filter(UserApiKeys.user == self) \
769 .filter(or_(UserApiKeys.expires == -1,
770 UserApiKeys.expires >= time.time())) \
771 .filter(UserApiKeys.role == UserApiKeys.ROLE_ARTIFACT_DOWNLOAD)
772
773 artifacts_tokens = artifacts_tokens.all()
774 if artifacts_tokens:
775 return artifacts_tokens[0].api_key
776 else:
777 from rhodecode.model.auth_token import AuthTokenModel
778 artifact_token = AuthTokenModel().create(
779 self, 'auto-generated-artifact-token',
780 lifetime=-1, role=UserApiKeys.ROLE_ARTIFACT_DOWNLOAD)
781 Session.commit()
782 return artifact_token.api_key
783
763 @classmethod
784 @classmethod
764 def get(cls, user_id, cache=False):
785 def get(cls, user_id, cache=False):
765 if not user_id:
786 if not user_id:
@@ -60,6 +60,9 class RepoGroupModel(BaseModel):
60 return self._get_instance(RepoGroup, repo_group,
60 return self._get_instance(RepoGroup, repo_group,
61 callback=RepoGroup.get_by_group_name)
61 callback=RepoGroup.get_by_group_name)
62
62
63 def get_repo_group(self, repo_group):
64 return self._get_repo_group(repo_group)
65
63 @LazyProperty
66 @LazyProperty
64 def repos_path(self):
67 def repos_path(self):
65 """
68 """
@@ -270,6 +270,8 function registerRCRoutes() {
270 pyroutes.register('repo_artifacts_list', '/%(repo_name)s/artifacts', ['repo_name']);
270 pyroutes.register('repo_artifacts_list', '/%(repo_name)s/artifacts', ['repo_name']);
271 pyroutes.register('repo_artifacts_new', '/%(repo_name)s/artifacts/new', ['repo_name']);
271 pyroutes.register('repo_artifacts_new', '/%(repo_name)s/artifacts/new', ['repo_name']);
272 pyroutes.register('repo_artifacts_store', '/%(repo_name)s/artifacts/store', ['repo_name']);
272 pyroutes.register('repo_artifacts_store', '/%(repo_name)s/artifacts/store', ['repo_name']);
273 pyroutes.register('repo_artifacts_stream_script', '/_file_store/stream-upload-script', []);
274 pyroutes.register('repo_artifacts_stream_store', '/_file_store/stream-upload', []);
273 pyroutes.register('repo_artifacts_update', '/%(repo_name)s/artifacts/update/%(uid)s', ['repo_name', 'uid']);
275 pyroutes.register('repo_artifacts_update', '/%(repo_name)s/artifacts/update/%(uid)s', ['repo_name', 'uid']);
274 pyroutes.register('repo_automation', '/%(repo_name)s/settings/automation', ['repo_name']);
276 pyroutes.register('repo_automation', '/%(repo_name)s/settings/automation', ['repo_name']);
275 pyroutes.register('repo_automation_update', '/%(repo_name)s/settings/automation/%(entry_id)s/update', ['repo_name', 'entry_id']);
277 pyroutes.register('repo_automation_update', '/%(repo_name)s/settings/automation/%(entry_id)s/update', ['repo_name', 'entry_id']);
General Comments 0
You need to be logged in to leave comments. Login now