def put(self, request, sentry_app): if not features.has('organizations:internal-catchall', sentry_app.owner, actor=request.user): return Response(status=404) serializer = SentryAppSerializer(data=request.DATA, partial=True) if serializer.is_valid(): result = serializer.object updated_app = Updater.run( sentry_app=sentry_app, name=result.get('name'), webhook_url=result.get('webhookUrl'), redirect_url=result.get('redirectUrl'), is_alertable=result.get('isAlertable'), scopes=result.get('scopes'), events=result.get('events'), overview=result.get('overview'), ) return Response(serialize(updated_app, request.user)) return Response(serializer.errors, status=400)
def put(self, request, sentry_app): if not features.has('organizations:internal-catchall', sentry_app.owner, actor=request.user): return Response(status=404) serializer = SentryAppSerializer(data=request.DATA, partial=True) if serializer.is_valid(): result = serializer.object updated_app = Updater.run( sentry_app=sentry_app, name=result.get('name'), webhook_url=result.get('webhookUrl'), redirect_url=result.get('redirectUrl'), is_alertable=result.get('isAlertable'), scopes=result.get('scopes'), events=result.get('events'), overview=result.get('overview'), ) return Response(serialize(updated_app, request.user)) return Response(serializer.errors, status=400)
def post(self, request, organization): data = { "name": request.json_body.get("name"), "user": request.user, "author": request.json_body.get("author"), "organization": self._get_user_org(request), "webhookUrl": request.json_body.get("webhookUrl"), "redirectUrl": request.json_body.get("redirectUrl"), "isAlertable": request.json_body.get("isAlertable"), "isInternal": request.json_body.get("isInternal"), "verifyInstall": request.json_body.get("verifyInstall"), "scopes": request.json_body.get("scopes", []), "events": request.json_body.get("events", []), "schema": request.json_body.get("schema", {}), "overview": request.json_body.get("overview"), "allowedOrigins": request.json_body.get("allowedOrigins", []), } if self._has_hook_events(request) and not features.has( "organizations:integrations-event-hooks", organization, actor=request.user): return Response( { "non_field_errors": [ "Your organization does not have access to the 'error' resource subscription." ] }, status=403, ) serializer = SentryAppSerializer(data=data) if serializer.is_valid(): data["redirect_url"] = data["redirectUrl"] data["webhook_url"] = data["webhookUrl"] data["is_alertable"] = data["isAlertable"] data["verify_install"] = data["verifyInstall"] data["allowed_origins"] = data["allowedOrigins"] creator = InternalCreator if data.get("isInternal") else Creator sentry_app = creator.run(request=request, **data) return Response(serialize(sentry_app), status=201) # log any errors with schema if "schema" in serializer.errors: for error_message in serializer.errors["schema"]: name = "sentry_app.schema_validation_error" log_info = { "schema": json.dumps(data["schema"]), "user_id": request.user.id, "sentry_app_name": data["name"], "organization_id": organization.id, "error_message": error_message, } logger.info(name, extra=log_info) analytics.record(name, **log_info) return Response(serializer.errors, status=400)
def post(self, request, organization): data = { 'name': request.json_body.get('name'), 'user': request.user, 'author': request.json_body.get('author'), 'organization': self._get_user_org(request), 'webhookUrl': request.json_body.get('webhookUrl'), 'redirectUrl': request.json_body.get('redirectUrl'), 'isAlertable': request.json_body.get('isAlertable'), 'scopes': request.json_body.get('scopes', []), 'events': request.json_body.get('events', []), 'schema': request.json_body.get('schema', {}), 'overview': request.json_body.get('overview'), } serializer = SentryAppSerializer(data=data) if serializer.is_valid(): data['redirect_url'] = data['redirectUrl'] data['webhook_url'] = data['webhookUrl'] data['is_alertable'] = data['isAlertable'] sentry_app = Creator.run(request=request, **data) return Response(serialize(sentry_app), status=201) return Response(serializer.errors, status=400)
def put(self, request, sentry_app): if not features.has('organizations:sentry-apps', sentry_app.owner, actor=request.user): return Response(status=404) serializer = SentryAppSerializer( sentry_app, data=request.data, partial=True, ) if serializer.is_valid(): result = serializer.validated_data updated_app = Updater.run( user=request.user, sentry_app=sentry_app, name=result.get('name'), author=result.get('author'), status=result.get('status'), webhook_url=result.get('webhookUrl'), redirect_url=result.get('redirectUrl'), is_alertable=result.get('isAlertable'), scopes=result.get('scopes'), events=result.get('events'), schema=result.get('schema'), overview=result.get('overview'), ) return Response(serialize(updated_app, request.user)) return Response(serializer.errors, status=400)
def post(self, request, organization): data = { 'name': request.json_body.get('name'), 'user': request.user, 'author': request.json_body.get('author'), 'organization': self._get_user_org(request), 'webhookUrl': request.json_body.get('webhookUrl'), 'redirectUrl': request.json_body.get('redirectUrl'), 'isAlertable': request.json_body.get('isAlertable'), 'scopes': request.json_body.get('scopes', []), 'events': request.json_body.get('events', []), 'schema': request.json_body.get('schema', {}), 'overview': request.json_body.get('overview'), } serializer = SentryAppSerializer(data=data) if serializer.is_valid(): data['redirect_url'] = data['redirectUrl'] data['webhook_url'] = data['webhookUrl'] data['is_alertable'] = data['isAlertable'] sentry_app = Creator.run( request=request, **data ) return Response(serialize(sentry_app), status=201) return Response(serializer.errors, status=400)
def put(self, request, sentry_app): if self._has_hook_events(request) and not features.has( "organizations:integrations-event-hooks", sentry_app.owner, actor=request.user ): return Response( { "non_field_errors": [ "Your organization does not have access to the 'error' resource subscription." ] }, status=403, ) # isInternal is not field of our model but it is a field of the serializer data = request.data.copy() data["isInternal"] = sentry_app.status == SentryAppStatus.INTERNAL serializer = SentryAppSerializer(sentry_app, data=data, partial=True, access=request.access) if serializer.is_valid(): result = serializer.validated_data updated_app = Updater.run( user=request.user, sentry_app=sentry_app, name=result.get("name"), author=result.get("author"), status=result.get("status"), webhook_url=result.get("webhookUrl"), redirect_url=result.get("redirectUrl"), is_alertable=result.get("isAlertable"), verify_install=result.get("verifyInstall"), scopes=result.get("scopes"), events=result.get("events"), schema=result.get("schema"), overview=result.get("overview"), allowed_origins=result.get("allowedOrigins"), ) return Response(serialize(updated_app, request.user, access=request.access)) # log any errors with schema if "schema" in serializer.errors: for error_message in serializer.errors["schema"]: name = "sentry_app.schema_validation_error" log_info = { "schema": json.dumps(request.data["schema"]), "user_id": request.user.id, "sentry_app_id": sentry_app.id, "sentry_app_name": sentry_app.name, "organization_id": sentry_app.owner.id, "error_message": error_message, } logger.info(name, extra=log_info) analytics.record(name, **log_info) return Response(serializer.errors, status=400)
def put(self, request, sentry_app): serializer = SentryAppSerializer(data=request.DATA, partial=True) if serializer.is_valid(): result = serializer.object updated_app = Updater.run( sentry_app=sentry_app, name=result.get('name'), webhook_url=result.get('webhook_url'), scopes=result.get('scopes'), ) return Response(serialize(updated_app, request.user)) return Response(serializer.errors, status=400)
def post(self, request): serializer = SentryAppSerializer(data=request.json_body) if not serializer.is_valid(): return Response({'errors': serializer.errors}, status=422) sentry_app = Creator.run( name=request.json_body.get('name'), organization=self._get_user_org(request), scopes=request.json_body.get('scopes'), webhook_url=request.json_body.get('webhook_url'), ) return Response(serialize(sentry_app), status=201)
def post(self, request): serializer = SentryAppSerializer(data=request.json_body) if not serializer.is_valid(): return Response({'errors': serializer.errors}, status=422) sentry_app = Creator.run( name=request.json_body.get('name'), organization=self._get_user_org(request), scopes=request.json_body.get('scopes'), webhook_url=request.json_body.get('webhook_url'), ) return Response(serialize(sentry_app), status=201)
def put(self, request, sentry_app): if not features.has('organizations:sentry-apps', sentry_app.owner, actor=request.user): return Response(status=404) if self._has_hook_events(request) and not features.has( 'organizations:integrations-event-hooks', sentry_app.owner, actor=request.user): return Response( { "non_field_errors": [ "Your organization does not have access to the 'error' resource subscription.", ] }, status=403) serializer = SentryAppSerializer( sentry_app, data=request.data, partial=True, ) if serializer.is_valid(): result = serializer.validated_data updated_app = Updater.run( user=request.user, sentry_app=sentry_app, name=result.get('name'), author=result.get('author'), status=result.get('status'), webhook_url=result.get('webhookUrl'), redirect_url=result.get('redirectUrl'), is_alertable=result.get('isAlertable'), verify_install=result.get('verifyInstall'), scopes=result.get('scopes'), events=result.get('events'), schema=result.get('schema'), overview=result.get('overview'), ) return Response(serialize(updated_app, request.user)) return Response(serializer.errors, status=400)
def post(self, request, organization): data = { "name": request.json_body.get("name"), "user": request.user, "author": request.json_body.get("author"), "organization": self._get_user_org(request), "webhookUrl": request.json_body.get("webhookUrl"), "redirectUrl": request.json_body.get("redirectUrl"), "isAlertable": request.json_body.get("isAlertable"), "isInternal": request.json_body.get("isInternal"), "verifyInstall": request.json_body.get("verifyInstall"), "scopes": request.json_body.get("scopes", []), "events": request.json_body.get("events", []), "schema": request.json_body.get("schema", {}), "overview": request.json_body.get("overview"), } if self._has_hook_events(request) and not features.has( "organizations:integrations-event-hooks", organization, actor=request.user ): return Response( { "non_field_errors": [ "Your organization does not have access to the 'error' resource subscription." ] }, status=403, ) serializer = SentryAppSerializer(data=data) if serializer.is_valid(): data["redirect_url"] = data["redirectUrl"] data["webhook_url"] = data["webhookUrl"] data["is_alertable"] = data["isAlertable"] data["verify_install"] = data["verifyInstall"] creator = InternalCreator if data.get("isInternal") else Creator sentry_app = creator.run(request=request, **data) return Response(serialize(sentry_app), status=201) return Response(serializer.errors, status=400)
def post(self, request, organization): data = { 'name': request.json_body.get('name'), 'user': request.user, 'author': request.json_body.get('author'), 'organization': self._get_user_org(request), 'webhookUrl': request.json_body.get('webhookUrl'), 'redirectUrl': request.json_body.get('redirectUrl'), 'isAlertable': request.json_body.get('isAlertable'), 'isInternal': request.json_body.get('isInternal'), 'verifyInstall': request.json_body.get('verifyInstall'), 'scopes': request.json_body.get('scopes', []), 'events': request.json_body.get('events', []), 'schema': request.json_body.get('schema', {}), 'overview': request.json_body.get('overview'), } if self._has_hook_events(request) and not features.has( 'organizations:integrations-event-hooks', organization, actor=request.user): return Response( { "non_field_errors": [ "Your organization does not have access to the 'error' resource subscription.", ] }, status=403) serializer = SentryAppSerializer(data=data) if serializer.is_valid(): data['redirect_url'] = data['redirectUrl'] data['webhook_url'] = data['webhookUrl'] data['is_alertable'] = data['isAlertable'] data['verify_install'] = data['verifyInstall'] creator = InternalCreator if data.get('isInternal') else Creator sentry_app = creator.run(request=request, **data) return Response(serialize(sentry_app), status=201) return Response(serializer.errors, status=400)
def post(self, request, organization): serializer = SentryAppSerializer(data=request.json_body) if serializer.is_valid(): result = serializer.object sentry_app = Creator.run( name=result.get('name'), organization=self._get_user_org(request), scopes=result.get('scopes'), events=result.get('events'), webhook_url=result.get('webhookUrl'), redirect_url=result.get('redirectUrl'), is_alertable=result.get('isAlertable'), overview=result.get('overview'), ) return Response(serialize(sentry_app), status=201) return Response({'errors': serializer.errors}, status=422)
def post(self, request, organization): serializer = SentryAppSerializer(data=request.json_body) if serializer.is_valid(): result = serializer.object sentry_app = Creator.run( name=result.get('name'), organization=self._get_user_org(request), scopes=result.get('scopes'), events=result.get('events'), webhook_url=result.get('webhookUrl'), redirect_url=result.get('redirectUrl'), is_alertable=result.get('isAlertable'), overview=result.get('overview'), ) return Response(serialize(sentry_app), status=201) return Response(serializer.errors, status=422)
def put(self, request, sentry_app): if not features.has('organizations:sentry-apps', sentry_app.owner, actor=request.user): return Response(status=404) data = { 'user': request.user, 'sentry_app': sentry_app, 'name': request.json_body.get('name'), 'status': request.json_body.get('status'), 'author': request.json_body.get('author'), 'webhookUrl': request.json_body.get('webhookUrl'), 'redirectUrl': request.json_body.get('redirectUrl'), 'isAlertable': request.json_body.get('isAlertable'), 'scopes': request.json_body.get('scopes'), 'events': request.json_body.get('events'), 'schema': request.json_body.get('schema'), 'overview': request.json_body.get('overview'), } serializer = SentryAppSerializer( instance=sentry_app, data=data, partial=True, ) if serializer.is_valid(): result = serializer.object data['redirect_url'] = data['redirectUrl'] data['webhook_url'] = data['webhookUrl'] data['is_alertable'] = data['isAlertable'] data['scopes'] = result.get('scopes') data['events'] = result.get('events') updated_app = Updater.run(**data) return Response(serialize(updated_app, request.user)) return Response(serializer.errors, status=400)
def put(self, request, sentry_app): if not features.has('organizations:sentry-apps', sentry_app.owner, actor=request.user): return Response(status=404) data = { 'user': request.user, 'sentry_app': sentry_app, 'name': request.json_body.get('name'), 'status': request.json_body.get('status'), 'author': request.json_body.get('author'), 'webhookUrl': request.json_body.get('webhookUrl'), 'redirectUrl': request.json_body.get('redirectUrl'), 'isAlertable': request.json_body.get('isAlertable'), 'scopes': request.json_body.get('scopes'), 'events': request.json_body.get('events'), 'schema': request.json_body.get('schema'), 'overview': request.json_body.get('overview'), } serializer = SentryAppSerializer( instance=sentry_app, data=data, partial=True, ) if serializer.is_valid(): result = serializer.object data['redirect_url'] = data['redirectUrl'] data['webhook_url'] = data['webhookUrl'] data['is_alertable'] = data['isAlertable'] data['scopes'] = result.get('scopes') data['events'] = result.get('events') updated_app = Updater.run(**data) return Response(serialize(updated_app, request.user)) return Response(serializer.errors, status=400)
def post(self, request: Request, organization) -> Response: data = { "name": request.json_body.get("name"), "user": request.user, "author": request.json_body.get("author"), "organization": organization, "webhookUrl": request.json_body.get("webhookUrl"), "redirectUrl": request.json_body.get("redirectUrl"), "isAlertable": request.json_body.get("isAlertable"), "isInternal": request.json_body.get("isInternal"), "verifyInstall": request.json_body.get("verifyInstall"), "scopes": request.json_body.get("scopes", []), "events": request.json_body.get("events", []), "schema": request.json_body.get("schema", {}), "overview": request.json_body.get("overview"), "allowedOrigins": request.json_body.get("allowedOrigins", []), "popularity": request.json_body.get("popularity") if is_active_superuser(request) else None, } if self._has_hook_events(request) and not features.has( "organizations:integrations-event-hooks", organization, actor=request.user): return Response( { "non_field_errors": [ "Your organization does not have access to the 'error' resource subscription." ] }, status=403, ) serializer = SentryAppSerializer( data=data, access=request.access, context={ "features": { "organizations:alert-rule-ui-component": features.has("organizations:alert-rule-ui-component", organization, actor=request.user) } }, ) if serializer.is_valid(): data["redirect_url"] = data["redirectUrl"] data["webhook_url"] = data["webhookUrl"] data["is_alertable"] = data["isAlertable"] data["verify_install"] = data["verifyInstall"] data["allowed_origins"] = data["allowedOrigins"] data["is_internal"] = data.get("isInternal") creator = InternalCreator if data.get("isInternal") else Creator try: sentry_app = creator.run(request=request, **data) except ValidationError as e: # we generate and validate the slug here instead of the serializer since the slug never changes return Response(e.detail, status=400) return Response(serialize(sentry_app, access=request.access), status=201) # log any errors with schema if "schema" in serializer.errors: for error_message in serializer.errors["schema"]: name = "sentry_app.schema_validation_error" log_info = { "schema": json.dumps(data["schema"]), "user_id": request.user.id, "sentry_app_name": data["name"], "organization_id": organization.id, "error_message": error_message, } logger.info(name, extra=log_info) analytics.record(name, **log_info) return Response(serializer.errors, status=400)