本文整理汇总了Python中sentry.utils.hashlib.md5_text函数的典型用法代码示例。如果您正苦于以下问题:Python md5_text函数的具体用法?Python md5_text怎么用?Python md5_text使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了md5_text函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, request, organization, flow, auth_provider=None,
provider_key=None):
assert provider_key or auth_provider
self.request = request
self.auth_provider = auth_provider
self.organization = organization
self.flow = flow
if auth_provider:
provider = auth_provider.get_provider()
elif provider_key:
provider = manager.get(provider_key)
else:
raise NotImplementedError
self.provider = provider
if flow == self.FLOW_LOGIN:
self.pipeline = provider.get_auth_pipeline()
elif flow == self.FLOW_SETUP_PROVIDER:
self.pipeline = provider.get_setup_pipeline()
else:
raise NotImplementedError
# we serialize the pipeline to be [AuthView().get_ident(), ...] which
# allows us to determine if the pipeline has changed during the auth
# flow or if the user is somehow circumventing a chunk of it
self.signature = md5_text(
' '.join(av.get_ident() for av in self.pipeline)
).hexdigest()
示例2: _get_event_user
def _get_event_user(self, project, data):
user_data = data.get('sentry.interfaces.User')
if not user_data:
return
euser = EventUser(
project=project,
ident=user_data.get('id'),
email=user_data.get('email'),
username=user_data.get('username'),
ip_address=user_data.get('ip_address'),
)
if not euser.tag_value:
return
cache_key = 'euser:{}:{}'.format(
project.id,
md5_text(euser.tag_value).hexdigest(),
)
cached = default_cache.get(cache_key)
if cached is None:
try:
with transaction.atomic(using=router.db_for_write(EventUser)):
euser.save()
except IntegrityError:
pass
default_cache.set(cache_key, '', 3600)
return euser
示例3: _get_project_enhancements_config
def _get_project_enhancements_config(project):
enhancements = project.get_option('sentry:grouping_enhancements')
enhancements_base = project.get_option('sentry:grouping_enhancements_base')
if not enhancements and not enhancements_base:
return DEFAULT_ENHANCEMENTS_CONFIG
if enhancements_base is None or enhancements_base not in ENHANCEMENT_BASES:
enhancements_base = DEFAULT_ENHANCEMENT_BASE
# Instead of parsing and dumping out config here, we can make a
# shortcut
from sentry.utils.cache import cache
from sentry.utils.hashlib import md5_text
cache_key = 'grouping-enhancements:' + \
md5_text('%s|%s' % (enhancements_base, enhancements)).hexdigest()
rv = cache.get(cache_key)
if rv is not None:
return rv
try:
rv = Enhancements.from_config_string(
enhancements or '', bases=[enhancements_base]).dumps()
except InvalidEnhancerConfig:
rv = DEFAULT_ENHANCEMENTS_CONFIG
cache.set(cache_key, rv)
return rv
示例4: _finish_login_pipeline
def _finish_login_pipeline(self, identity):
"""
The login flow executes both with anonymous and authenticated users.
Upon completion a few branches exist:
If the identity is already linked, the user should be logged in
and redirected immediately.
Otherwise, the user is presented with a confirmation window. That window
will show them the new account that will be created, and if they're
already authenticated an optional button to associate the identity with
their account.
"""
auth_provider = self.auth_provider
user_id = identity['id']
lock = locks.get(
'sso:auth:{}:{}'.format(
auth_provider.id,
md5_text(user_id).hexdigest(),
),
duration=5,
)
with TimedRetryPolicy(5)(lock.acquire):
try:
auth_identity = AuthIdentity.objects.select_related('user').get(
auth_provider=auth_provider,
ident=user_id,
)
except AuthIdentity.DoesNotExist:
auth_identity = None
# Handle migration of identity keys
if not auth_identity and isinstance(user_id, MigratingIdentityId):
try:
auth_identity = AuthIdentity.objects.select_related('user').get(
auth_provider=auth_provider,
ident=user_id.legacy_id,
)
auth_identity.update(ident=user_id.id)
except AuthIdentity.DoesNotExist:
auth_identity = None
if not auth_identity:
return self._handle_unknown_identity(identity)
# If the User attached to this AuthIdentity is not active,
# we want to clobber the old account and take it over, rather than
# getting logged into the inactive account.
if not auth_identity.user.is_active:
# Current user is also not logged in, so we have to
# assume unknown.
if not self.request.user.is_authenticated():
return self._handle_unknown_identity(identity)
auth_identity = self._handle_attach_identity(identity)
return self._handle_existing_identity(auth_identity, identity)
示例5: test_query_hash
def test_query_hash(self):
recent_search = RecentSearch.objects.create(
organization=self.organization,
user=self.user,
type=0,
query='hello',
)
recent_search = RecentSearch.objects.get(id=recent_search.id)
assert recent_search.query_hash == md5_text(recent_search.query).hexdigest()
示例6: make_key
def make_key(model, prefix, kwargs):
kwargs_bits = []
for k, v in sorted(six.iteritems(kwargs)):
k = __prep_key(model, k)
v = smart_text(__prep_value(model, k, v))
kwargs_bits.append("%s=%s" % (k, v))
kwargs_bits = ":".join(kwargs_bits)
return "%s:%s:%s" % (prefix, model.__name__, md5_text(kwargs_bits).hexdigest())
示例7: _make_key
def _make_key(self, model, filters):
"""
Returns a Redis-compatible key for the model given filters.
"""
return 'b:k:%s:%s' % (
model._meta, md5_text(
'&'.
join('%s=%s' % (k, self._coerce_val(v)) for k, v in sorted(six.iteritems(filters)))
).hexdigest(),
)
示例8: for_tags
def for_tags(cls, project_id, values):
"""
Finds matching EventUser objects from a list of tag values.
Return a dictionary of {tag_value: event_user}.
"""
hashes = [md5_text(v.split(':', 1)[-1]).hexdigest() for v in values]
return {e.tag_value: e for e in cls.objects.filter(
project_id=project_id,
hash__in=hashes,
)}
示例9: get_conf_version
def get_conf_version(self, project):
"""
Returns a version string that represents the current configuration state.
If any option changes or new options added, the version will change.
>>> plugin.get_conf_version(project)
"""
options = self.get_conf_options(project)
return md5_text('&'.join(sorted('%s=%s' % o
for o in six.iteritems(options)))).hexdigest()[:3]
示例10: get
def get(self, request):
results = status_checks.check_all()
return Response({
'problems': [
{
'id': md5_text(problem.message).hexdigest(),
'message': problem.message,
'severity': problem.severity,
'url': problem.url,
}
for problem in sorted(itertools.chain.from_iterable(results.values()),
reverse=True)
],
'healthy': {type(check).__name__: not problems for check, problems in results.items()},
})
示例11: get_gravatar_url
def get_gravatar_url(email, size=None, default='mm'):
if email is None:
email = ''
gravatar_url = "%s/avatar/%s" % (settings.SENTRY_GRAVATAR_BASE_URL,
md5_text(email.lower()).hexdigest())
properties = {}
if size:
properties['s'] = six.text_type(size)
if default:
properties['d'] = default
if properties:
gravatar_url += "?" + urlencode(properties)
return gravatar_url
示例12: get_event_payload
def get_event_payload(self, event):
props = {
'event_id': event.event_id,
'project_id': event.project.slug,
'transaction': event.get_tag('transaction') or '',
'release': event.get_tag('sentry:release') or '',
'environment': event.get_tag('environment') or '',
'type': event.get_event_type(),
}
props['tags'] = [[k.format(tagstore.get_standardized_key(k)), v]
for k, v in event.get_tags()]
for key, value in six.iteritems(event.interfaces):
if key == 'request':
headers = value.headers
if not isinstance(headers, dict):
headers = dict(headers or ())
props.update({
'request_url': value.url,
'request_method': value.method,
'request_referer': headers.get('Referer', ''),
})
elif key == 'exception':
exc = value.values[0]
props.update({
'exception_type': exc.type,
'exception_value': exc.value,
})
elif key == 'logentry':
props.update({
'message': value.formatted or value.message,
})
elif key in ('csp', 'expectct', 'expectstable', 'hpkp'):
props.update({
'{}_{}'.format(key.rsplit('.', 1)[-1].lower(), k): v
for k, v in six.iteritems(value.to_json())
})
elif key == 'user':
user_payload = {}
if value.id:
user_payload['user_id'] = value.id
if value.email:
user_payload['user_email_hash'] = md5_text(value.email).hexdigest()
if value.ip_address:
user_payload['user_ip_trunc'] = anonymize_ip(value.ip_address)
if user_payload:
props.update(user_payload)
return props
示例13: is_limited
def is_limited(self, key, limit, project=None, window=None):
if window is None:
window = self.window
key_hex = md5_text(key).hexdigest()
bucket = int(time() / window)
if project:
key = 'rl:%s:%s:%s' % (key_hex, project.id, bucket)
else:
key = 'rl:%s:%s' % (key_hex, bucket)
with self.cluster.map() as client:
result = client.incr(key)
client.expire(key, window)
return result.value > limit
示例14: __init__
def __init__(self, request, organization, provider_key, provider_model=None, config=None):
if config is None:
config = {}
self.request = request
self.organization = organization
self.state = RedisSessionStore(request, self.pipeline_name)
self.provider = self.provider_manager.get(provider_key)
self.provider_model = provider_model
self.config = config
self.provider.set_config(config)
self.pipeline = self.get_pipeline_views()
# we serialize the pipeline to be ['fqn.PipelineView', ...] which
# allows us to determine if the pipeline has changed during the auth
# flow or if the user is somehow circumventing a chunk of it
pipe_ids = ['{}.{}'.format(type(v).__module__, type(v).__name__) for v in self.pipeline]
self.signature = md5_text(*pipe_ids).hexdigest()
示例15: get_fingerprinting_config_for_project
def get_fingerprinting_config_for_project(project):
from sentry.grouping.fingerprinting import FingerprintingRules, \
InvalidFingerprintingConfig
rules = project.get_option('sentry:fingerprinting_rules')
if not rules:
return FingerprintingRules([])
from sentry.utils.cache import cache
from sentry.utils.hashlib import md5_text
cache_key = 'fingerprinting-rules:' + md5_text(rules).hexdigest()
rv = cache.get(cache_key)
if rv is not None:
return FingerprintingRules.from_json(rv)
try:
rv = FingerprintingRules.from_config_string(
rules or '')
except InvalidFingerprintingConfig:
rv = FingerprintingRules([])
cache.set(cache_key, rv.to_json())
return rv