本文整理汇总了Python中spacewalk.common.rhnTranslate._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_package_path
def get_package_path(server_id, pkg_spec, channel):
log_debug(3, server_id, pkg_spec, channel)
if isinstance(pkg_spec, ListType):
pkg = pkg_spec[:4]
#Insert EPOCH
pkg.insert(1, None)
else:
pkg = parseRPMFilename(pkg_spec)
if pkg is None:
log_debug(4, "Error", "Requested weird package", pkg_spec)
raise rhnFault(17, _("Invalid RPM package %s requested") % pkg_spec)
statement = """
select p.id, p.path path, pe.epoch epoch
from
rhnPackageArch pa,
rhnChannelPackage cp,
rhnPackage p,
rhnPackageEVR pe,
rhnServerChannel sc,
rhnPackageName pn,
rhnChannel c
where 1=1
and c.label = :channel
and pn.name = :name
and sc.server_id = :server_id
and pe.version = :ver
and pe.release = :rel
and c.id = sc.channel_id
and c.id = cp.channel_id
and pa.label = :arch
and pn.id = p.name_id
and p.id = cp.package_id
and p.evr_id = pe.id
and sc.channel_id = cp.channel_id
and p.package_arch_id = pa.id
"""
h = rhnSQL.prepare(statement)
pkg = map(str, pkg)
h.execute(name = pkg[0], ver = pkg[2], rel = pkg[3], arch = pkg[4],
channel = channel, server_id = server_id)
rs = h.fetchall_dict()
if not rs:
log_debug(4, "Error", "Non-existant package requested", server_id,
pkg_spec, channel)
raise rhnFault(17, _("Invalid RPM package %s requested") % pkg_spec)
# It is unlikely for this query to return more than one row,
# but it is possible
# (having two packages with the same n, v, r, a and different epoch in
# the same channel is prohibited by the RPM naming scheme; but extra
# care won't hurt)
max_row = rs[0]
for each in rs[1:]:
# Compare the epoch as string
if _none2emptyString(each['epoch']) > _none2emptyString(max_row['epoch']):
max_row = each
# Set the flag for the proxy download accelerator
rhnFlags.set("Download-Accelerator-Path", max_row['path'])
return check_package_file(max_row['path'], max_row['id'], pkg_spec), max_row['id']
示例2: _verifyProxyAuthToken
def _verifyProxyAuthToken(auth_token):
""" verifies the validity of a proxy auth token
NOTE: X-RHN-Proxy-Auth described in proxy/broker/rhnProxyAuth.py
"""
log_debug(4, auth_token)
token, hostname = splitProxyAuthToken(auth_token)
hostname = hostname.strip()
ipv4_regex = '^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$'
# This ipv6 regex was develeoped by Stephen Ryan at Dataware.
# (http://forums.intermapper.com/viewtopic.php?t=452) It is licenced
# under a Creative Commons Attribution-ShareAlike 3.0 Unported
# License, so we are free to use it as long as we attribute it to him.
ipv6_regex = '^((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?$'
hostname_is_ip_address = re.match(ipv4_regex, hostname) or re.match(ipv6_regex, hostname)
headers = rhnFlags.get('outputTransportOptions')
if len(token) < 5:
# Bad auth information; decline any action
log_debug(4, "incomplete proxy authentication token: %s"
% auth_token)
headers['X-RHN-Proxy-Auth-Error'] = '%s:%s' % (
1003, _("incomplete proxy authentication token: %s") % auth_token)
if not hostname_is_ip_address:
headers['X-RHN-Proxy-Auth-Origin'] = hostname
raise rhnFault(1003) # Invalid session key
log_debug(5, "proxy auth token: %s, hostname: %s"
% (repr(token), hostname or 'n/a'))
proxyId, proxyUser, rhnServerTime, expireOffset, signature = token[:5]
computed = computeSignature(CFG.SECRET_KEY, proxyId, proxyUser,
rhnServerTime, expireOffset)
if computed != signature:
log_error("Proxy signature failed: proxy id='%s', proxy user='%s'" %
(proxyId, proxyUser))
log_debug(4, "Sent proxy signature %s does not match ours %s." % (
signature, computed))
headers['X-RHN-Proxy-Auth-Error'] = '%s:%s' % (
1003, _("Sent proxy signature %s does not match ours %s.") % (
signature, computed))
if not hostname_is_ip_address:
headers['X-RHN-Proxy-Auth-Origin'] = hostname
raise rhnFault(1003) # Invalid session key
# Convert the expiration/time to floats:
rhnServerTime = float(rhnServerTime)
expireOffset = float(expireOffset)
if rhnServerTime + expireOffset < time.time():
log_debug(4, "Expired proxy authentication token")
headers['X-RHN-Proxy-Auth-Error'] = '%s:%s' % (1004, "Expired")
if not hostname_is_ip_address:
headers['X-RHN-Proxy-Auth-Origin'] = hostname
raise rhnFault(1004) # Expired client authentication token
log_debug(4, "Proxy auth OK: sigs match; not an expired token")
return 1
示例3: auth_client
def auth_client(self, token):
""" Authenticate a system based on the same authentication tokens
the client is sending for GET requests
"""
log_debug(3)
# Build a UserDictCase out of the token
dict = UserDictCase(token)
# Set rhnFlags so that we can piggyback on apacheAuth's auth_client
rhnFlags.set('AUTH_SESSION_TOKEN', dict)
# XXX To clean up apacheAuth.auth_client's logging, this is not about
# GET requests
result = apacheAuth.auth_client()
if not result:
raise rhnFault(33, _("Invalid session key"))
log_debug(4, "Client auth OK")
# We checked it already, so we're sure it's there
client_id = dict['X-RHN-Server-Id']
server = rhnServer.search(client_id)
if not server:
raise rhnFault(8, _("This server ID no longer exists"))
# XXX: should we check if the username still has access to it?
# probably not, because there is no known good way we can
# update the server system_id on the client side when
# permissions change... Damn it. --gafton
self.server = server
self.server_id = client_id
self.user = dict['X-RHN-Auth-User-Id']
return server
示例4: exitWithTraceback
def exitWithTraceback(e, msg, exitnum, mail=0):
tbOut = StringIO()
Traceback(mail, ostream=tbOut, with_locals=1)
log_error(-1, _('ERROR: %s %s: %s') %
(e.__class__.__name__, msg, e))
log_error(-1, _('TRACEBACK: %s') % tbOut.getvalue())
sys.exit(exitnum)
示例5: check_user_password
def check_user_password(username, password):
""" Do some minimal checks on the data thrown our way. """
# username is required
if not username:
raise rhnFault(11)
# password is required
if not password:
raise rhnFault(12)
if len(username) < CFG.MIN_USER_LEN:
raise rhnFault(13, _("username should be at least %d characters")
% CFG.MIN_USER_LEN)
if len(username) > CFG.MAX_USER_LEN:
raise rhnFault(700, _("username should be less than %d characters")
% CFG.MAX_USER_LEN)
username = username[:CFG.MAX_USER_LEN]
# Invalid characters
# ***NOTE*** Must coordinate with web and installer folks about any
# changes to this set of characters!!!!
invalid_re = re.compile(".*[\s&+%'`\"=#]", re.I)
tmp = invalid_re.match(username)
if tmp is not None:
pos = tmp.regs[0]
raise rhnFault(15, _("username = `%s', invalid character `%s'") % (
username, username[pos[1] - 1]))
# use new password validation method
validate_new_password(password)
return username, password
示例6: getSourcePackagePath
def getSourcePackagePath(self, pkgFilename):
""" OVERLOADS getSourcePackagePath in common/rhnRepository.
snag src.rpm and nosrc.rpm from local repo, after ensuring
we are authorized to fetch it.
"""
log_debug(3, pkgFilename)
if pkgFilename[-8:] != '.src.rpm' and pkgFilename[-10:] != '.nosrc.rpm':
raise rhnFault(17, _("Invalid SRPM package requested: %s")
% pkgFilename)
# Connect to the server to get an authorization for downloading this
# package
server = rpclib.Server(self.rhnParentXMLRPC, proxy=self.httpProxy,
username=self.httpProxyUsername,
password=self.httpProxyPassword)
if self.caChain:
server.add_trusted_cert(self.caChain)
try:
retval = server.proxy.package_source_in_channel(
pkgFilename, self.channelName, self.clientInfo)
except xmlrpclib.Fault, e:
raise rhnFault(1000,
_("Error retrieving source package: %s") % str(e)), None, sys.exc_info()[2]
示例7: validate_new_password
def validate_new_password(password):
""" Perform all the checks required for new passwords """
log_debug(3, "Entered validate_new_password")
#
# We're copying the code because we don't want to
# invalidate any of the existing passwords.
#
# Validate password based on configurable length
# regular expression
if not password:
raise rhnFault(12)
if len(password) < CFG.MIN_PASSWD_LEN:
raise rhnFault(14, _("password must be at least %d characters")
% CFG.MIN_PASSWD_LEN)
if len(password) > CFG.MAX_PASSWD_LEN:
raise rhnFault(701, _("Password must be shorter than %d characters")
% CFG.MAX_PASSWD_LEN)
password = password[:CFG.MAX_PASSWD_LEN]
invalid_re = re.compile(
r"[^ A-Za-z0-9`[email protected]#$%^&*()-_=+[{\]}\\|;:'\",<.>/?~]")
asterisks_re = re.compile(r"^\**$")
# make sure the password isn't all *'s
tmp = asterisks_re.match(password)
if tmp is not None:
raise rhnFault(15, "password cannot be all asterisks '*'")
# make sure we have only printable characters
tmp = invalid_re.search(password)
if tmp is not None:
pos = tmp.regs[0]
raise rhnFault(15,
_("password contains character `%s'") % password[pos[1] - 1])
示例8: authzOrg
def authzOrg(self, info):
# This function is a lot more complicated than it should be; the
# corner case is pushes without a channel; we have to deny regular
# users the ability to push to their org.
# If the org id is not specified, default to the user's org id
if not info.has_key("orgId"):
info["orgId"] = self.org_id
log_debug(4, "info[orgId]", info["orgId"], "org id", self.org_id)
org_id = info["orgId"]
if org_id == "":
# Satellites are not allowwd to push in the null org
raise rhnFault(4, _("You are not authorized to manage packages in the null org"))
if org_id and self.org_id != org_id:
# Not so fast...
raise rhnFault(32, _("You are not allowed to manage packages in the %s org") % org_id)
# Org admins and channel admins have full privileges; we could use
# user_manages_channes, except for the case where there are no chanels
if self.isOrgAdmin() or self.isChannelAdmin():
log_debug(4, "Org authorized (org_admin or channel_admin)")
return
# regular user at this point... check if the user manages any channels
if user_manages_channels(self.user_id):
log_debug(4, "Org authorized (user manages a channel)")
return
# ok, you're a regular user who doesn't manage any channels.
# take a hike.
raise rhnFault(32, _("You are not allowed to perform administrative tasks"))
示例9: getxml
def getxml(self):
# see if there were any template strings loaded from the db,
# {label:value}
templateOverrides = rhnFlags.get('templateOverrides')
# update the templateValues in the module
if templateOverrides:
for label in templateOverrides.keys():
# only care about values we've defined defaults for...
if label in templateValues:
templateValues[label] = templateOverrides[label]
s = StringIO()
s.write("\n")
if self.text:
s.write(_("Error Message:\n %s\n") % self.text.strip())
if self.code:
s.write(_("Error Class Code: %s\n") % self.code)
if self.arrayText:
cinfo = self.arrayText % templateValues
s.write(_("Error Class Info: %s\n") % cinfo.rstrip())
if self.explain:
s.write(_("Explanation: %s") % Explain)
if not self.code:
return xmlrpclib.Fault(1, s.getvalue())
return xmlrpclib.Fault(-self.code, s.getvalue())
示例10: prepRhnCert
def prepRhnCert(options):
""" minor prepping of the RHN cerficate
writing to default storage location
"""
# NOTE: default_db MUST be populated in /etc/rhn/rhn.conf before this
# function is run.
# validateSatCert() must have been run prior to this as well (it
# populates "/var/log/entitlementCert"
if options.rhn_cert and options.rhn_cert != DEFAULT_RHN_CERT_LOCATION:
try:
cert = openGzippedFile(options.rhn_cert).read()
except (IOError, OSError), e:
msg = _('ERROR: "%s" (specified in commandline)\n' "could not be opened and read:\n%s") % (
options.rhn_cert,
str(e),
)
sys.stderr.write(msg + "\n")
raise
cert = string.strip(cert)
try:
writeRhnCert(options, cert)
except (IOError, OSError), e:
msg = _('ERROR: "%s" could not be opened\nand/or written to:\n%s') % (DEFAULT_RHN_CERT_LOCATION, str(e))
sys.stderr.write(msg + "\n")
raise
示例11: validate_system_input
def validate_system_input(self, data):
""" check the input data """
if not hash_validate(data, "os_release", "architecture", "profile_name"):
log_error("Incomplete data hash")
raise rhnFault(21, _("Required data missing"))
# we require either a username and a password or a token
if not hash_validate(data, "username", "password") and \
not hash_validate(data, "token"):
raise rhnFault(21, _("Required members missing"))
示例12: __new_user_db
def __new_user_db(username, password, email, org_id, org_password):
encrypted_password = CFG.encrypted_passwords
log_debug(3, username, email, encrypted_password)
# now search it in the database
h = rhnSQL.prepare("""
select w.id, w.password, ui.use_pam_authentication
from web_contact w, rhnUserInfo ui
where w.login_uc = upper(:username)
and w.id = ui.user_id
""")
h.execute(username=username)
data = h.fetchone_dict()
pre_existing_user = 0
if not data:
# the username is not there, check the reserved user table
h = rhnSQL.prepare("""
select login, password from rhnUserReserved
where login_uc = upper(:username)
""")
h.execute(username=username)
data = h.fetchone_dict()
if not data: # nope, not reserved either
raise rhnFault(1, _("Username `%s' has not been reserved") % username)
else:
pre_existing_user = 1
if not pre_existing_user and not email:
# New accounts have to specify an e-mail address
raise rhnFault(30, _("E-mail address not specified"))
# we have to perform PAM authentication if data has a field called
# 'use_pam_authentication' and its value is 'Y', and we do have a PAM
# service set in the config file.
# Note that if the user is only reserved we don't do PAM authentication
if data.get('use_pam_authentication') == 'Y' and CFG.pam_auth_service:
# Check the password with PAM
import rhnAuthPAM
if rhnAuthPAM.check_password(username, password, CFG.pam_auth_service) <= 0:
# Bad password
raise rhnFault(2)
# We don't care about the password anymore, replace it with something
import time
password = 'pam:%.8f' % time.time()
else:
# Regular authentication
if check_password(password, data["password"]) == 0:
# Bad password
raise rhnFault(2)
# creation of user was never supported in spacewalk but this call was mis-used
# to check username/password in the past
# so let's skip other checks and return now
return 0
示例13: auth_system
def auth_system(self):
if CFG.DISABLE_ISS:
raise rhnFault(2005, _('ISS is disabled on this satellite.'))
if not rhnSQL.fetchone_dict("select 1 from rhnISSSlave where slave = :hostname and enabled = 'Y'",
hostname=idn_puny_to_unicode(self.remote_hostname)):
raise rhnFault(2004,
_('Server "%s" is not enabled for ISS.')
% self.remote_hostname)
return self.remote_hostname
示例14: auth_username_password
def auth_username_password(username, password):
user = search(username)
if not user:
raise rhnFault(2, _("Invalid username/password combination"))
if not user.check_password(password):
raise rhnFault(2, _("Invalid username/password combination"))
return user
示例15: check_package_file
def check_package_file(rel_path, logpkg, raisepkg):
if rel_path is None:
log_error("Package path null for package id", logpkg)
raise rhnFault(17, _("Invalid RPM package %s requested") % raisepkg)
filePath = "%s/%s" % (CFG.MOUNT_POINT, rel_path)
if not os.access(filePath, os.R_OK):
# Package not found on the filesystem
log_error("Package not found", filePath)
raise rhnFault(17, _("Package not found"))
return filePath