本文整理汇总了Python中sentry.utils.hashlib.md5_text函数的典型用法代码示例。如果您正苦于以下问题:Python md5_text函数的具体用法?Python md5_text怎么用?Python md5_text使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了md5_text函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:WhoTrades,项目名称:sentry,代码行数:30,代码来源:helper.py
示例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
开发者ID:mvaled,项目名称:sentry,代码行数:30,代码来源:event_manager.py
示例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
开发者ID:getsentry,项目名称:sentry,代码行数:26,代码来源:api.py
示例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)
开发者ID:hosmelq,项目名称:sentry,代码行数:60,代码来源:helper.py
示例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()
开发者ID:yaoqi,项目名称:sentry,代码行数:9,代码来源:test_recentsearch.py
示例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())
开发者ID:ForkRepo,项目名称:sentry,代码行数:9,代码来源:manager.py
示例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(),
)
开发者ID:alexandrul,项目名称:sentry,代码行数:10,代码来源:redis.py
示例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,
)}
开发者ID:NuttasitBoonwat,项目名称:sentry,代码行数:11,代码来源:eventuser.py
示例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]
开发者ID:alexandrul,项目名称:sentry,代码行数:11,代码来源:v1.py
示例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()},
})
开发者ID:ForkRepo,项目名称:sentry,代码行数:15,代码来源:system_health.py
示例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
开发者ID:duanshuaimin,项目名称:sentry,代码行数:15,代码来源:avatar.py
示例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
开发者ID:getsentry,项目名称:sentry-plugins,代码行数:48,代码来源:plugin.py
示例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
开发者ID:ForkRepo,项目名称:sentry,代码行数:17,代码来源:redis.py
示例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()
开发者ID:hosmelq,项目名称:sentry,代码行数:20,代码来源:__init__.py
示例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
开发者ID:getsentry,项目名称:sentry,代码行数:21,代码来源:api.py
示例16: fetch_file
def fetch_file(url, project=None, release=None, allow_scraping=True):
"""
Pull down a URL, returning a UrlResult object.
Attempts to fetch from the cache.
"""
if release:
result = fetch_release_file(url, release)
else:
result = None
cache_key = 'source:cache:v3:%s' % (
md5_text(url).hexdigest(),
)
if result is None:
if not allow_scraping or not url.startswith(('http:', 'https:')):
error = {
'type': EventError.JS_MISSING_SOURCE,
'url': expose_url(url),
}
raise CannotFetchSource(error)
logger.debug('Checking cache for url %r', url)
result = cache.get(cache_key)
if result is not None:
# We got a cache hit, but the body is compressed, so we
# need to decompress it before handing it off
body = zlib.decompress(result[1])
result = (result[0], force_text(body), result[2])
if result is None:
# lock down domains that are problematic
domain = urlparse(url).netloc
domain_key = 'source:blacklist:v2:%s' % (
md5_text(domain).hexdigest(),
)
domain_result = cache.get(domain_key)
if domain_result:
domain_result['url'] = url
raise CannotFetchSource(domain_result)
headers = {}
if project and is_valid_origin(url, project=project):
token = project.get_option('sentry:token')
if token:
headers['X-Sentry-Token'] = token
logger.debug('Fetching %r from the internet', url)
http_session = http.build_session()
try:
response = http_session.get(
url,
allow_redirects=True,
verify=False,
headers=headers,
timeout=settings.SENTRY_SOURCE_FETCH_TIMEOUT,
)
except Exception as exc:
logger.debug('Unable to fetch %r', url, exc_info=True)
if isinstance(exc, RestrictedIPAddress):
error = {
'type': EventError.RESTRICTED_IP,
'url': expose_url(url),
}
elif isinstance(exc, SuspiciousOperation):
error = {
'type': EventError.SECURITY_VIOLATION,
'url': expose_url(url),
}
elif isinstance(exc, (RequestException, ZeroReturnError)):
error = {
'type': EventError.JS_GENERIC_FETCH_ERROR,
'value': six.text_type(type(exc)),
'url': expose_url(url),
}
else:
logger.exception(six.text_type(exc))
error = {
'type': EventError.UNKNOWN_ERROR,
'url': expose_url(url),
}
# TODO(dcramer): we want to be less aggressive on disabling domains
cache.set(domain_key, error or '', 300)
logger.warning('Disabling sources to %s for %ss', domain, 300,
exc_info=True)
raise CannotFetchSource(error)
# requests' attempts to use chardet internally when no encoding is found
# and we want to avoid that slow behavior
if not response.encoding:
response.encoding = 'utf-8'
body = response.text
z_body = zlib.compress(force_bytes(body))
headers = {k.lower(): v for k, v in response.headers.items()}
cache.set(cache_key, (headers, z_body, response.status_code), 60)
#.........这里部分代码省略.........
开发者ID:bsergean,项目名称:sentry,代码行数:101,代码来源:processor.py
示例17: _generate_cache_version
def _generate_cache_version(self):
return md5_text("&".join(sorted(f.attname for f in self.model._meta.fields))).hexdigest()[:3]
开发者ID:ForkRepo,项目名称:sentry,代码行数:2,代码来源:manager.py
示例18: fetch_file
def fetch_file(url, project=None, release=None, dist=None, allow_scraping=True):
"""
Pull down a URL, returning a UrlResult object.
Attempts to fetch from the cache.
"""
# If our url has been truncated, it'd be impossible to fetch
# so we check for this early and bail
if url[-3:] == '...':
raise http.CannotFetch(
{
'type': EventError.JS_MISSING_SOURCE,
'url': http.expose_url(url),
}
)
if release:
with metrics.timer('sourcemaps.release_file'):
result = fetch_release_file(url, release, dist)
else:
result = None
cache_key = 'source:cache:v4:%s' % (md5_text(url).hexdigest(), )
if result is None:
if not allow_scraping or not url.startswith(('http:', 'https:')):
error = {
'type': EventError.JS_MISSING_SOURCE,
'url': http.expose_url(url),
}
raise http.CannotFetch(error)
logger.debug('Checking cache for url %r', url)
result = cache.get(cache_key)
if result is not None:
# Previous caches would be a 3-tuple instead of a 4-tuple,
# so this is being maintained for backwards compatibility
try:
encoding = result[4]
except IndexError:
encoding = None
# We got a cache hit, but the body is compressed, so we
# need to decompress it before handing it off
result = http.UrlResult(
result[0], result[1], zlib.decompress(result[2]), result[3], encoding
)
if result is None:
headers = {}
verify_ssl = False
if project and is_valid_origin(url, project=project):
verify_ssl = bool(project.get_option('sentry:verify_ssl', False))
token = project.get_option('sentry:token')
if token:
token_header = project.get_option('sentry:token_header') or 'X-Sentry-Token'
headers[token_header] = token
with metrics.timer('sourcemaps.fetch'):
result = http.fetch_file(url, headers=headers, verify_ssl=verify_ssl)
z_body = zlib.compress(result.body)
cache.set(
cache_key,
(url,
result.headers,
z_body,
result.status,
result.encoding),
get_max_age(result.headers))
# If we did not get a 200 OK we just raise a cannot fetch here.
if result.status != 200:
raise http.CannotFetch(
{
'type': EventError.FETCH_INVALID_HTTP_CODE,
'value': result.status,
'url': http.expose_url(url),
}
)
# Make sure the file we're getting back is six.binary_type. The only
# reason it'd not be binary would be from old cached blobs, so
# for compatibility with current cached files, let's coerce back to
# binary and say utf8 encoding.
if not isinstance(result.body, six.binary_type):
try:
result = http.UrlResult(
result.url, result.headers,
result.body.encode('utf8'), result.status, result.encoding
)
except UnicodeEncodeError:
error = {
'type': EventError.FETCH_INVALID_ENCODING,
'value': 'utf8',
'url': http.expose_url(url),
}
raise http.CannotFetch(error)
# For JavaScript files, check if content is something other than JavaScript/JSON (i.e. HTML)
# NOTE: possible to have JS files that don't actually end w/ ".js", but
# this should catch 99% of cases
if url.endswith('.js'):
#.........这里部分代码省略.........
开发者ID:Kayle009,项目名称:sentry,代码行数:101,代码来源:processor.py
示例19: hash_from_tag
def hash_from_tag(cls, value):
return md5_text(value.split(':', 1)[-1]).hexdigest()
开发者ID:Kayle009,项目名称:sentry,代码行数:2,代码来源:eventuser.py
示例20: build_hash
def build_hash(self):
value = self.ident or self.username or self.email or self.ip_address
if not value:
return None
return md5_text(value).hexdigest()
开发者ID:NuttasitBoonwat,项目名称:sentry,代码行数:5,代码来源:eventuser.py
注:本文中的sentry.utils.hashlib.md5_text函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论