本文整理汇总了Python中sentry.models.TagKey.is_reserved_key方法的典型用法代码示例。如果您正苦于以下问题:Python TagKey.is_reserved_key方法的具体用法?Python TagKey.is_reserved_key怎么用?Python TagKey.is_reserved_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sentry.models.TagKey
的用法示例。
在下文中一共展示了TagKey.is_reserved_key方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from sentry.models import TagKey [as 别名]
# 或者: from sentry.models.TagKey import is_reserved_key [as 别名]
def get(self, request, group, key):
"""
List a Tag's Values
```````````````````
Return a list of values associated with this key for an issue.
:pparam string issue_id: the ID of the issue to retrieve.
:pparam string key: the tag key to look the values up for.
:auth: required
"""
# XXX(dcramer): kill sentry prefix for internal reserved tags
if TagKey.is_reserved_key(key):
lookup_key = 'sentry:{0}'.format(key)
else:
lookup_key = key
tagkey = TagKey.objects.filter(
project=group.project_id,
key=lookup_key,
status=TagKeyStatus.VISIBLE,
)
if not tagkey.exists():
raise ResourceDoesNotExist
queryset = GroupTagValue.objects.filter(
group=group,
key=lookup_key,
)
sort = request.GET.get('sort')
if sort == 'date':
order_by = '-last_seen'
paginator_cls = DateTimePaginator
elif sort == 'age':
order_by = '-first_seen'
paginator_cls = DateTimePaginator
elif sort == 'freq':
order_by = '-times_seen'
paginator_cls = OffsetPaginator
else:
order_by = '-id'
paginator_cls = Paginator
if key == 'user':
serializer_cls = UserTagValueSerializer()
else:
serializer_cls = None
return self.paginate(
request=request,
queryset=queryset,
order_by=order_by,
paginator_cls=paginator_cls,
on_results=lambda x: serialize(x, request.user, serializer_cls),
)
示例2: get
# 需要导入模块: from sentry.models import TagKey [as 别名]
# 或者: from sentry.models.TagKey import is_reserved_key [as 别名]
def get(self, request, organization, project, team, group_id, key):
try:
# TODO(tkaemming): This should *actually* redirect, see similar
# comment in ``GroupEndpoint.convert_args``.
group, _ = get_group_with_redirect(
group_id,
queryset=Group.objects.filter(project=project),
)
except Group.DoesNotExist:
raise Http404
if TagKey.is_reserved_key(key):
lookup_key = 'sentry:{0}'.format(key)
else:
lookup_key = key
# validate existance as it may be deleted
try:
TagKey.objects.get(
project=group.project_id,
key=lookup_key,
status=TagKeyStatus.VISIBLE,
)
except TagKey.DoesNotExist:
raise Http404
queryset = GroupTagValue.objects.filter(
group=group,
key=lookup_key,
)
def row_iter():
yield ('value', 'times_seen', 'last_seen', 'first_seen')
for row in queryset.iterator():
yield (
row.value.encode('utf-8'),
str(row.times_seen),
row.last_seen.strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
row.first_seen.strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
)
pseudo_buffer = Echo()
writer = csv.writer(pseudo_buffer)
response = StreamingHttpResponse(
(writer.writerow(r) for r in row_iter()),
content_type='text/csv'
)
response['Content-Disposition'] = 'attachment; filename="{}-{}.csv"'.format(
group.qualified_short_id or group.id, slugify(key)
)
return response
示例3: get
# 需要导入模块: from sentry.models import TagKey [as 别名]
# 或者: from sentry.models.TagKey import is_reserved_key [as 别名]
def get(self, request, group, key):
"""
Retrieve Tag Details
````````````````````
Returns details for given tag key related to an issue.
:pparam string issue_id: the ID of the issue to retrieve.
:pparam string key: the tag key to look the values up for.
:auth: required
"""
# XXX(dcramer): kill sentry prefix for internal reserved tags
if TagKey.is_reserved_key(key):
lookup_key = 'sentry:{0}'.format(key)
else:
lookup_key = key
try:
tag_key = TagKey.objects.get(
project=group.project_id,
key=lookup_key,
status=TagKeyStatus.VISIBLE,
)
except TagKey.DoesNotExist:
raise ResourceDoesNotExist
try:
group_tag_key = GroupTagKey.objects.get(
group=group,
key=lookup_key,
)
except GroupTagKey.DoesNotExist:
raise ResourceDoesNotExist
total_values = GroupTagValue.get_value_count(group.id, lookup_key)
top_values = GroupTagValue.get_top_values(group.id, lookup_key, limit=9)
data = {
'id': str(tag_key.id),
'key': key,
'name': tag_key.get_label(),
'uniqueValues': group_tag_key.values_seen,
'totalValues': total_values,
'topValues': serialize(top_values, request.user),
}
return Response(data)
示例4: get
# 需要导入模块: from sentry.models import TagKey [as 别名]
# 或者: from sentry.models.TagKey import is_reserved_key [as 别名]
def get(self, request, project, key):
if TagKey.is_reserved_key(key):
lookup_key = 'sentry:{0}'.format(key)
else:
lookup_key = key
try:
tagkey = TagKey.objects.get(
project=project,
key=lookup_key,
status=TagKeyStatus.VISIBLE,
)
except TagKey.DoesNotExist:
raise ResourceDoesNotExist
return Response(serialize(tagkey, request.user))
示例5: get
# 需要导入模块: from sentry.models import TagKey [as 别名]
# 或者: from sentry.models.TagKey import is_reserved_key [as 别名]
def get(self, request, organization, project, team, group_id, key):
try:
# TODO(tkaemming): This should *actually* redirect, see similar
# comment in ``GroupEndpoint.convert_args``.
group, _ = get_group_with_redirect(
group_id,
queryset=Group.objects.filter(project=project),
)
except Group.DoesNotExist:
raise Http404
if TagKey.is_reserved_key(key):
lookup_key = 'sentry:{0}'.format(key)
else:
lookup_key = key
# validate existance as it may be deleted
try:
TagKey.objects.get(
project=group.project_id,
key=lookup_key,
status=TagKeyStatus.VISIBLE,
)
except TagKey.DoesNotExist:
raise Http404
if key == 'user':
callbacks = [attach_eventuser(project.id)]
else:
callbacks = []
queryset = RangeQuerySetWrapper(
GroupTagValue.objects.filter(
group_id=group.id,
key=lookup_key,
),
callbacks=callbacks,
)
filename = '{}-{}'.format(
group.qualified_short_id or group.id,
key,
)
return self.to_csv_response(queryset, filename, key=key)
示例6: get
# 需要导入模块: from sentry.models import TagKey [as 别名]
# 或者: from sentry.models.TagKey import is_reserved_key [as 别名]
def get(self, request, project, key):
"""
List a Tag's Values
```````````````````
Return a list of values associated with this key. The `query`
parameter can be used to to perform a "starts with" match on
values.
:pparam string organization_slug: the slug of the organization.
:pparam string project_slug: the slug of the project.
:pparam string key: the tag key to look up.
:auth: required
"""
if TagKey.is_reserved_key(key):
lookup_key = "sentry:{0}".format(key)
else:
lookup_key = key
try:
tagkey = TagKey.objects.get(project=project, key=lookup_key, status=TagKeyStatus.VISIBLE)
except TagKey.DoesNotExist:
raise ResourceDoesNotExist
base_queryset = TagValue.objects.filter(project=project, key=tagkey.key)
query = request.GET.get("query")
if query:
if is_postgres():
# not quite optimal, but best we can do with ORM
queryset = TagValue.objects.filter(id__in=base_queryset.order_by("-times_seen")[:10000])
else:
# MySQL can't handle an `IN` with a `LIMIT` clause
queryset = base_queryset
queryset = queryset.filter(value__contains=query)
else:
queryset = TagValue.objects.filter(project=project, key=tagkey.key)
return self.paginate(
request=request, queryset=queryset, order_by="-times_seen", on_results=lambda x: serialize(x, request.user)
)
示例7: delete
# 需要导入模块: from sentry.models import TagKey [as 别名]
# 或者: from sentry.models.TagKey import is_reserved_key [as 别名]
def delete(self, request, project, key):
"""
Remove all occurrences of the given tag key.
{method} {path}
"""
if TagKey.is_reserved_key(key):
lookup_key = 'sentry:{0}'.format(key)
else:
lookup_key = key
try:
tagkey = TagKey.objects.get(
project=project,
key=lookup_key,
)
except TagKey.DoesNotExist:
raise ResourceDoesNotExist
updated = TagKey.objects.filter(
id=tagkey.id,
status=TagKeyStatus.VISIBLE,
).update(status=TagKeyStatus.PENDING_DELETION)
if updated:
delete_tag_key.delay(object_id=tagkey.id)
self.create_audit_entry(
request=request,
organization=project.organization,
target_object=tagkey.id,
event=AuditLogEntryEvent.TAGKEY_REMOVE,
data=tagkey.get_audit_log_data(),
)
return Response(status=204)
示例8: get
# 需要导入模块: from sentry.models import TagKey [as 别名]
# 或者: from sentry.models.TagKey import is_reserved_key [as 别名]
def get(self, request, group, key):
"""
List a Tag's Values
```````````````````
Return a list of values associated with this key for an issue.
:pparam string issue_id: the ID of the issue to retrieve.
:pparam string key: the tag key to look the values up for.
:auth: required
"""
# XXX(dcramer): kill sentry prefix for internal reserved tags
if TagKey.is_reserved_key(key):
lookup_key = 'sentry:{0}'.format(key)
else:
lookup_key = key
tagkey = TagKey.objects.filter(
project=group.project_id,
key=lookup_key,
status=TagKeyStatus.VISIBLE,
)
if not tagkey.exists():
raise ResourceDoesNotExist
queryset = GroupTagValue.objects.filter(
group=group,
key=lookup_key,
)
return self.paginate(
request=request,
queryset=queryset,
order_by='-id',
on_results=lambda x: serialize(x, request.user),
)
示例9: validate_data
# 需要导入模块: from sentry.models import TagKey [as 别名]
# 或者: from sentry.models.TagKey import is_reserved_key [as 别名]
#.........这里部分代码省略.........
self.log.debug('Discarded invalid tag key: %r', type(k))
data['errors'].append({
'type': EventError.INVALID_DATA,
'name': 'tags',
'value': pair,
})
continue
if not isinstance(v, six.string_types):
try:
v = six.text_type(v)
except Exception:
self.log.debug('Discarded invalid tag value: %s=%r',
k, type(v))
data['errors'].append({
'type': EventError.INVALID_DATA,
'name': 'tags',
'value': pair,
})
continue
if len(k) > MAX_TAG_KEY_LENGTH or len(v) > MAX_TAG_VALUE_LENGTH:
self.log.debug('Discarded invalid tag: %s=%s', k, v)
data['errors'].append({
'type': EventError.INVALID_DATA,
'name': 'tags',
'value': pair,
})
continue
# support tags with spaces by converting them
k = k.replace(' ', '-')
if TagKey.is_reserved_key(k):
self.log.debug('Discarding reserved tag key: %s', k)
data['errors'].append({
'type': EventError.INVALID_DATA,
'name': 'tags',
'value': pair,
})
continue
if not TagKey.is_valid_key(k):
self.log.debug('Discarded invalid tag key: %s', k)
data['errors'].append({
'type': EventError.INVALID_DATA,
'name': 'tags',
'value': pair,
})
continue
if not TagValue.is_valid_value(v):
self.log.debug('Discard invalid tag value: %s', v)
data['errors'].append({
'type': EventError.INVALID_DATA,
'name': 'tags',
'value': pair,
})
continue
tags.append((k, v))
data['tags'] = tags
for k in list(iter(data)):
if k in CLIENT_RESERVED_ATTRS:
continue
示例10: validate_data
# 需要导入模块: from sentry.models import TagKey [as 别名]
# 或者: from sentry.models.TagKey import is_reserved_key [as 别名]
#.........这里部分代码省略.........
self.log.info('Discarded invalid tag key: %r', type(k))
data['errors'].append({
'type': EventError.INVALID_DATA,
'name': 'tags',
'value': pair,
})
continue
if not isinstance(v, six.string_types):
try:
v = six.text_type(v)
except Exception:
self.log.info('Discarded invalid tag value: %s=%r',
k, type(v))
data['errors'].append({
'type': EventError.INVALID_DATA,
'name': 'tags',
'value': pair,
})
continue
if len(k) > MAX_TAG_KEY_LENGTH or len(v) > MAX_TAG_VALUE_LENGTH:
self.log.info('Discarded invalid tag: %s=%s', k, v)
data['errors'].append({
'type': EventError.INVALID_DATA,
'name': 'tags',
'value': pair,
})
continue
# support tags with spaces by converting them
k = k.replace(' ', '-')
if TagKey.is_reserved_key(k):
self.log.info('Discarding reserved tag key: %s', k)
data['errors'].append({
'type': EventError.INVALID_DATA,
'name': 'tags',
'value': pair,
})
continue
if not TagKey.is_valid_key(k):
self.log.info('Discarded invalid tag key: %s', k)
data['errors'].append({
'type': EventError.INVALID_DATA,
'name': 'tags',
'value': pair,
})
continue
tags.append((k, v))
data['tags'] = tags
for k in data.keys():
if k in CLIENT_RESERVED_ATTRS:
continue
value = data.pop(k)
if not value:
self.log.info('Ignored empty interface value: %s', k)
continue
try:
interface = get_interface(k)
示例11: validate_data
# 需要导入模块: from sentry.models import TagKey [as 别名]
# 或者: from sentry.models.TagKey import is_reserved_key [as 别名]
#.........这里部分代码省略.........
tags = []
for pair in data["tags"]:
try:
k, v = pair
except ValueError:
self.log.info("Discarded invalid tag value: %r", pair)
data["errors"].append({"type": EventError.INVALID_DATA, "name": "tags", "value": pair})
continue
if not isinstance(k, six.string_types):
try:
k = six.text_type(k)
except Exception:
self.log.info("Discarded invalid tag key: %r", type(k))
data["errors"].append({"type": EventError.INVALID_DATA, "name": "tags", "value": pair})
continue
if not isinstance(v, six.string_types):
try:
v = six.text_type(v)
except Exception:
self.log.info("Discarded invalid tag value: %s=%r", k, type(v))
data["errors"].append({"type": EventError.INVALID_DATA, "name": "tags", "value": pair})
continue
if len(k) > MAX_TAG_KEY_LENGTH or len(v) > MAX_TAG_VALUE_LENGTH:
self.log.info("Discarded invalid tag: %s=%s", k, v)
data["errors"].append({"type": EventError.INVALID_DATA, "name": "tags", "value": pair})
continue
# support tags with spaces by converting them
k = k.replace(" ", "-")
if TagKey.is_reserved_key(k):
self.log.info("Discarding reserved tag key: %s", k)
data["errors"].append({"type": EventError.INVALID_DATA, "name": "tags", "value": pair})
continue
if not TagKey.is_valid_key(k):
self.log.info("Discarded invalid tag key: %s", k)
data["errors"].append({"type": EventError.INVALID_DATA, "name": "tags", "value": pair})
continue
tags.append((k, v))
data["tags"] = tags
for k in data.keys():
if k in CLIENT_RESERVED_ATTRS:
continue
value = data.pop(k)
if not value:
self.log.info("Ignored empty interface value: %s", k)
continue
try:
interface = get_interface(k)
except ValueError:
self.log.info("Ignored unknown attribute: %s", k)
data["errors"].append({"type": EventError.INVALID_ATTRIBUTE, "name": k})
continue
if type(value) != dict:
# HACK(dcramer): the exception interface supports a list as the
# value. We should change this in a new protocol version.