本文整理汇总了Python中sentry.models.ProjectKey类的典型用法代码示例。如果您正苦于以下问题:Python ProjectKey类的具体用法?Python ProjectKey怎么用?Python ProjectKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProjectKey类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: forwards
def forwards(self, orm):
from sentry.models import ProjectKey
for project in orm['sentry.Project'].objects.all():
if orm['sentry.ProjectKey'].objects.filter(project=project, user=None).exists():
continue
orm['sentry.ProjectKey'].objects.create(
project=project,
public_key=ProjectKey.generate_api_key(),
secret_key=ProjectKey.generate_api_key(),
)
示例2: project_key
def project_key(self):
from sentry.models import ProjectKey
if not settings.SENTRY_PROJECT:
return None
key = None
try:
if settings.SENTRY_PROJECT_KEY is not None:
key = ProjectKey.objects.get(
id=settings.SENTRY_PROJECT_KEY,
project=settings.SENTRY_PROJECT,
)
else:
key = ProjectKey.get_default(settings.SENTRY_PROJECT)
except Exception as exc:
# if the relation fails to query or is missing completely, lets handle
# it gracefully
self.error_logger.warn('internal-error.unable-to-fetch-project', extra={
'project_id': settings.SENTRY_PROJECT,
'project_key': settings.SENTRY_PROJECT_KEY,
'error_message': six.text_type(exc),
})
if key is None:
self.error_logger.warn('internal-error.no-project-available', extra={
'project_id': settings.SENTRY_PROJECT,
'project_key': settings.SENTRY_PROJECT_KEY,
})
return key
示例3: project_key_from_auth
def project_key_from_auth(self, auth):
if not auth.public_key:
raise APIUnauthorized('Invalid api key')
# Make sure the key even looks valid first, since it's
# possible to get some garbage input here causing further
# issues trying to query it from cache or the database.
if not ProjectKey.looks_like_api_key(auth.public_key):
raise APIUnauthorized('Invalid api key')
try:
pk = ProjectKey.objects.get_from_cache(public_key=auth.public_key)
except ProjectKey.DoesNotExist:
raise APIUnauthorized('Invalid api key')
# a secret key may not be present which will be validated elsewhere
if not constant_time_compare(pk.secret_key, auth.secret_key or pk.secret_key):
raise APIUnauthorized('Invalid api key')
if not pk.is_active:
raise APIUnauthorized('API key is disabled')
if not pk.roles.store:
raise APIUnauthorized('Key does not allow event storage access')
return pk
示例4: _get_project_key
def _get_project_key(self, request):
dsn = request.GET.get('dsn')
try:
key = ProjectKey.from_dsn(dsn)
except ProjectKey.DoesNotExist:
return
return key
示例5: _get_project_key
def _get_project_key(self, request):
try:
dsn = request.GET['dsn']
except KeyError:
return
try:
key = ProjectKey.from_dsn(dsn)
except ProjectKey.DoesNotExist:
return
return key
示例6: get
def get(self, request, project):
data = options.get('sentry:docs')
project_key = ProjectKey.get_default(project)
context = {
'platforms': data['platforms'],
}
if project_key:
context['dsn'] = project_key.dsn_private
context['dsnPublic'] = project_key.dsn_public
return Response(context)
示例7: send
def send(self, **kwargs):
# Report the issue to an upstream Sentry if active
# NOTE: we don't want to check self.is_enabled() like normal, since
# is_enabled behavior is overridden in this class. We explicitly
# want to check if the remote is active.
if self.remote.is_active():
from sentry import options
# Append some extra tags that are useful for remote reporting
super_kwargs = copy.deepcopy(kwargs)
super_kwargs['tags']['install-id'] = options.get('sentry:install-id')
super(SentryInternalClient, self).send(**super_kwargs)
if not is_current_event_safe():
return
# These imports all need to be internal to this function as this class
# is set up by django while still parsing LOGGING settings and we
# cannot import this stuff until settings are finalized.
from sentry.models import ProjectKey
from sentry.web.api import StoreView
from django.test import RequestFactory
key = None
if settings.SENTRY_PROJECT_KEY is not None:
key = ProjectKey.objects.filter(
id=settings.SENTRY_PROJECT_KEY,
project=settings.SENTRY_PROJECT).first()
if key is None:
key = ProjectKey.get_default(settings.SENTRY_PROJECT)
if key is None:
return
client_string = 'raven-python/%s' % (raven.VERSION,)
headers = {
'HTTP_X_SENTRY_AUTH': get_auth_header(
protocol=self.protocol_version,
timestamp=time.time(),
client=client_string,
api_key=key.public_key,
api_secret=key.secret_key,
),
'HTTP_CONTENT_ENCODING': self.get_content_encoding(),
}
self.request_factory = self.request_factory or RequestFactory()
request = self.request_factory.post(
'/api/store',
data=self.encode(kwargs),
content_type='application/octet-stream',
**headers
)
StoreView.as_view()(
request,
project_id=six.text_type(settings.SENTRY_PROJECT),
)
示例8: get
def get(self, request, project, platform):
data = load_doc(platform)
if not data:
raise ResourceDoesNotExist
project_key = ProjectKey.get_default(project)
return Response({
'id': data['id'],
'name': data['name'],
'html': replace_keys(data['html'], project_key),
'link': data['link'],
})
示例9: authenticate_credentials
def authenticate_credentials(self, token):
try:
key = ProjectKey.from_dsn(token)
except ProjectKey.DoesNotExist:
raise AuthenticationFailed('Invalid token')
if not key.is_active:
raise AuthenticationFailed('Invalid token')
with configure_scope() as scope:
scope.set_tag("api_token_type", self.token_name)
scope.set_tag("api_project_key", key.id)
return (AnonymousUser(), key)
示例10: get
def get(self, request, project):
data = load_doc('_platforms')
if data is None:
raise RuntimeError('Docs not built')
project_key = ProjectKey.get_default(project)
context = {
'platforms': data['platforms'],
}
if project_key:
context['dsn'] = project_key.dsn_private
context['dsnPublic'] = project_key.dsn_public
return Response(context)
示例11: test_get_dsn_with_port
def test_get_dsn_with_port(self):
key = ProjectKey(project_id=1, public_key='public', secret_key='secret')
with self.Settings(SENTRY_URL_PREFIX='http://example.com:81'):
self.assertEquals(key.get_dsn(), 'http://public:[email protected]:81/1')
示例12: save
def save(self, *args, **kwargs):
if not self.public_key:
self.public_key = ProjectKey.generate_api_key()
if not self.secret_key:
self.secret_key = ProjectKey.generate_api_key()
super(ProjectKey, self).save(*args, **kwargs)
示例13: test_get_dsn_with_endpoint_setting
def test_get_dsn_with_endpoint_setting(self):
key = ProjectKey(project_id=1, public_key='public', secret_key='secret')
with self.settings(SENTRY_ENDPOINT='http://endpoint.com'):
self.assertEquals(key.get_dsn(), 'http://public:[email protected]/1')
示例14: test_get_dsn_with_port
def test_get_dsn_with_port(self):
key = ProjectKey(project_id=1, public_key='public', secret_key='secret')
with self.options({'system.url-prefix': 'http://example.com:81'}):
self.assertEquals(key.get_dsn(), 'http://public:[email protected]:81/1')