-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat(releases): Add an endpoint for artifact bundles #13448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
477402a
feat(releases): Add an endpoint for artifact bundles
jan-auer 0a627ba
fix(assemble): Scope file access during upload
jan-auer a8dd6dc
ref(assemble): Pass scope identifiers to assemble status cache
jan-auer 0c6c6d2
Merge branch 'master' into feat/release-artifacts-assemble
jan-auer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/sentry/api/endpoints/organization_release_assemble.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
from __future__ import absolute_import | ||
|
||
import jsonschema | ||
from rest_framework.response import Response | ||
|
||
from sentry.api.bases.organization import OrganizationReleasesBaseEndpoint | ||
from sentry.api.exceptions import ResourceDoesNotExist | ||
from sentry.models import Release | ||
from sentry.tasks.assemble import get_assemble_status, set_assemble_status, \ | ||
AssembleTask, ChunkFileState | ||
from sentry.utils import json | ||
|
||
|
||
class OrganizationReleaseAssembleEndpoint(OrganizationReleasesBaseEndpoint): | ||
def post(self, request, organization, version): | ||
""" | ||
Handle an artifact bundle and merge it into the release | ||
``````````````````````````````````````````````````````` | ||
|
||
:auth: required | ||
""" | ||
|
||
try: | ||
release = Release.objects.get( | ||
organization_id=organization.id, | ||
version=version, | ||
) | ||
except Release.DoesNotExist: | ||
raise ResourceDoesNotExist | ||
|
||
if not self.has_release_permission(request, organization, release): | ||
raise ResourceDoesNotExist | ||
|
||
schema = { | ||
"type": "object", | ||
"properties": { | ||
"checksum": { | ||
"type": "string", | ||
"pattern": "^[0-9a-f]{40}$", | ||
}, | ||
"chunks": { | ||
"type": "array", | ||
"items": { | ||
"type": "string", | ||
"pattern": "^[0-9a-f]{40}$", | ||
} | ||
} | ||
}, | ||
"required": ["checksum", "chunks"], | ||
"additionalProperties": False, | ||
} | ||
|
||
try: | ||
data = json.loads(request.body) | ||
jsonschema.validate(data, schema) | ||
except jsonschema.ValidationError as e: | ||
return Response({'error': str(e).splitlines()[0]}, | ||
status=400) | ||
except BaseException as e: | ||
return Response({'error': 'Invalid json body'}, | ||
status=400) | ||
|
||
checksum = data.get('checksum', None) | ||
chunks = data.get('chunks', []) | ||
|
||
state, detail = get_assemble_status(AssembleTask.ARTIFACTS, organization.id, checksum) | ||
if state == ChunkFileState.OK: | ||
return Response({ | ||
'state': state, | ||
'detail': None, | ||
'missingChunks': [], | ||
}, status=200) | ||
elif state is not None: | ||
return Response({ | ||
'state': state, | ||
'detail': detail, | ||
'missingChunks': [], | ||
}) | ||
|
||
# There is neither a known file nor a cached state, so we will | ||
# have to create a new file. Assure that there are checksums. | ||
# If not, we assume this is a poll and report NOT_FOUND | ||
if not chunks: | ||
return Response({ | ||
'state': ChunkFileState.NOT_FOUND, | ||
'missingChunks': [], | ||
}, status=200) | ||
|
||
set_assemble_status(AssembleTask.ARTIFACTS, organization.id, checksum, | ||
ChunkFileState.CREATED) | ||
|
||
from sentry.tasks.assemble import assemble_artifacts | ||
assemble_artifacts.apply_async( | ||
kwargs={ | ||
'org_id': organization.id, | ||
'version': version, | ||
'checksum': checksum, | ||
'chunks': chunks, | ||
} | ||
) | ||
|
||
return Response({ | ||
'state': ChunkFileState.CREATED, | ||
'missingChunks': [], | ||
}, status=200) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.