本文整理汇总了Python中clacks.common.Environment类的典型用法代码示例。如果您正苦于以下问题:Python Environment类的具体用法?Python Environment怎么用?Python Environment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Environment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_error
def make_error(code, topic=None, details=None, **kwargs):
# Add topic to make it usable inside of the error messages
if not kwargs:
kwargs = {}
kwargs.update(dict(topic=topic))
# Assemble message
text = ClacksErrorHandler._codes[code] % kwargs
# Assemble error information
env = Environment.getInstance()
db = env.get_mongo_db('clacks').errors
data = dict(code=code, topic=topic, text=text,
kwargs=kwargs, trace=traceback.format_stack(),
details=details,
timestamp=datetime.now(), user=None)
# Write to db and update uuid
__id = str(db.save(data))
# First, catch unconverted exceptions
if not code in ClacksErrorHandler._codes:
return code
return '<%s> %s' % (__id, text)
示例2: setSambaPassword
def setSambaPassword(self, user, object_dn, password):
"""
Set a new samba-password for a user
"""
# Do we have read permissions for the requested attribute
env = Environment.getInstance()
topic = "%s.objects.%s.attributes.%s" % (env.domain, "User", "sambaNTPassword")
aclresolver = PluginRegistry.getInstance("ACLResolver")
if not aclresolver.check(user, topic, "w", base=object_dn):
self.__log.debug(
"user '%s' has insufficient permissions to write %s on %s, required is %s:%s"
% (user, "isLocked", object_dn, topic, "w")
)
raise ACLException(C.make_error("PERMISSION_ACCESS", topic, target=object_dn))
topic = "%s.objects.%s.attributes.%s" % (env.domain, "User", "sambaLMPassword")
aclresolver = PluginRegistry.getInstance("ACLResolver")
if not aclresolver.check(user, topic, "w", base=object_dn):
self.__log.debug(
"user '%s' has insufficient permissions to write %s on %s, required is %s:%s"
% (user, "isLocked", object_dn, topic, "w")
)
raise ACLException(C.make_error("PERMISSION_ACCESS", topic, target=object_dn))
# Set the password and commit the changes
lm, nt = smbpasswd.hash(password)
user = ObjectProxy(object_dn)
user.sambaNTPassword = nt
user.sambaLMPassword = lm
user.commit()
示例3: __init__
def __init__(self, *args, **kwargs):
self.log = logging.getLogger(__name__)
self.env = Environment.getInstance()
self.__secret = self.env.config.get('http.cookie-secret', default="TecloigJink4")
self.__consumer = None
super(WSHandler, self).__init__(*args, **kwargs)
示例4: main
def main():
env = Environment.getInstance()
config = env.config
# Load configuration
path = config.get('backend-monitor.audit-log', default='/var/lib/clacks/ldap-audit.log')
modifier = config.get('backend-monitor.modifier')
user = config.get('core.id')
password = config.get('amqp.key')
url = parseURL(makeAuthURL(config.get('amqp.url'), user, password))
# Connect to Clacks BUS
proxy = AMQPServiceProxy(url['source'] + "/" + env.domain)
# Main loop
while True:
sleep(1)
# Wait for file to pop up
if not os.path.exists(path):
continue
# Wait for file to be file
if not os.path.isfile(path):
continue
# Check if it is effectively readable
try:
with open(path) as f:
pass
except IOError as e:
continue
# Listen for changes
monitor(path, modifier, proxy)
示例5: accountUnlockable
def accountUnlockable(self, user, object_dn):
index = PluginRegistry.getInstance("ObjectIndex")
# Do we have read permissions for the requested attribute
env = Environment.getInstance()
topic = "%s.objects.%s.attributes.%s" % (env.domain, "User", "isLocked")
aclresolver = PluginRegistry.getInstance("ACLResolver")
if not aclresolver.check(user, topic, "r", base=object_dn):
self.__log.debug(
"user '%s' has insufficient permissions to read %s on %s, required is %s:%s"
% (user, "isLocked", object_dn, topic, "r")
)
raise ACLException(C.make_error("PERMISSION_ACCESS", topic, target=object_dn))
res = index.search({"dn": object_dn, "userPassword": {"$size": 1}}, {"userPassword": 1})
if res.count():
hsh = res[0]["userPassword"][0]
else:
# No password hash -> cannot lock/unlock account
return False
# Try to detect the responsible password method-class
pwd_o = self.detect_method_by_hash(hsh)
if not pwd_o:
# Could not identify password method
return False
return pwd_o.isUnlockable(hsh)
示例6: setUp
def setUp(self):
""" Stuff to be run before every test """
Environment.config = os.path.join(os.path.dirname(os.path.realpath(__file__)))
Environment.noargs = True
self.env = Environment.getInstance()
self.mgr = LibinstManager()
keyring = """-----BEGIN PGP P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helperAddRepositoryTypes()
self.assertTrue(self.mgr.createDistribution("debian", "deb"))
self.assertTrue(self.mgr.createRelease("debian", "lenny"))
self.assertTrue(self.mgr.createRelease("debian", "lenny/5.0.4"))
self.assertTrue(self.mgr.createRelease("debian", "squeeze"))
示例7: __init__
def __init__(self):
self.env = env = Environment.getInstance()
self.log = logging.getLogger(__name__)
self.log.debug("initializing asterisk number resolver")
self.__default_image = Image.open(pkg_resources.resource_filename("amires", "data/phone.png"))
# Load resolver
for entry in pkg_resources.iter_entry_points("phone.resolver"):
module = entry.load()
self.log.debug("loading resolver module '%s'" % module.__name__)
obj = module()
self.resolver[module.__name__] = {
'object': obj,
'priority': obj.priority,
}
# Load renderer
for entry in pkg_resources.iter_entry_points("notification.renderer"):
module = entry.load()
self.log.debug("loading renderer module '%s'" % module.__name__)
self.renderer[module.__name__] = {
'object': module(),
'priority': module.priority,
}
self.last_event = None
示例8: setUserPassword
def setUserPassword(self, user, object_dn, password):
"""
Set a new password for a user
"""
# Do we have read permissions for the requested attribute
env = Environment.getInstance()
topic = "%s.objects.%s.attributes.%s" % (env.domain, "User", "userPassword")
aclresolver = PluginRegistry.getInstance("ACLResolver")
if not aclresolver.check(user, topic, "w", base=object_dn):
self.__log.debug(
"user '%s' has insufficient permissions to write %s on %s, required is %s:%s"
% (user, "isLocked", object_dn, topic, "w")
)
raise ACLException(C.make_error("PERMISSION_ACCESS", topic, target=object_dn))
user = ObjectProxy(object_dn)
method = user.passwordMethod
# Try to detect the responsible password method-class
pwd_o = self.get_method_by_method_type(method)
if not pwd_o:
raise PasswordException(C.make_error("PASSWORD_UNKNOWN_HASH", type=method))
# Generate the new password hash usind the detected method
pwd_str = pwd_o.generate_password_hash(password, method)
# Set the password and commit the changes
user.userPassword = pwd_str
user.commit()
示例9: __init__
def __init__(self):
env = Environment.getInstance()
self.log = logging.getLogger(__name__)
self.log.debug("initializing AMQP service provider")
self.env = env
self.__cr = None
self.__cmdWorker = None
示例10: lockAccountPassword
def lockAccountPassword(self, user, object_dn):
"""
Locks the account password for the given DN
"""
# Do we have read permissions for the requested attribute
env = Environment.getInstance()
topic = "%s.objects.%s.attributes.%s" % (env.domain, "User", "userPassword")
aclresolver = PluginRegistry.getInstance("ACLResolver")
if not aclresolver.check(user, topic, "w", base=object_dn):
self.__log.debug(
"user '%s' has insufficient permissions to write %s on %s, required is %s:%s"
% (user, "isLocked", object_dn, topic, "w")
)
raise ACLException(C.make_error("PERMISSION_ACCESS", topic, target=object_dn))
# Get the object for the given dn
user = ObjectProxy(object_dn)
# Check if there is a userPasswort available and set
if not "userPassword" in user.get_attributes():
raise PasswordException(C.make_error("PASSWORD_NO_ATTRIBUTE"))
if not user.userPassword:
raise PasswordException(C.make_error("PASSWORD_NOT_AVAILABLE"))
# Try to detect the responsible password method-class
pwd_o = self.detect_method_by_hash(user.userPassword)
if not pwd_o:
raise PasswordException(C.make_error("PASSWORD_METHOD_UNKNOWN"))
# Lock the hash and save it
user.userPassword = pwd_o.lock_account(user.userPassword)
user.commit()
示例11: main
def main():
""" Main programm which is called when the clacks agent process gets started.
It does the main forking os related tasks. """
# Set process list title
os.putenv('SPT_NOENV', 'non_empty_value')
setproctitle("clacks-agent")
# Inizialize core environment
env = Environment.getInstance()
if not env.base:
env.log.critical("Clacks agent needs a 'core.base' do operate on")
exit(1)
env.log.info("Clacks %s is starting up (server id: %s)" % (VERSION, env.id))
if env.config.get('core.profile'):
import cProfile
import clacks.common.lsprofcalltree
p = cProfile.Profile()
p.runctx('mainLoop(env)', globals(), {'env': env})
#pylint: disable=E1101
k = clacks.common.lsprofcalltree.KCacheGrind(p)
data = open('prof.kgrind', 'w+')
k.output(data)
data.close()
else:
mainLoop(env)
示例12: __init__
def __init__(self):
env = Environment.getInstance()
self.env = env
self.log = logging.getLogger(__name__)
# Read config values
self.__puppet_user = env.config.get("puppet.user",
default=env.config.get("client.user", default="clacks"))
self.__target_dir = env.config.get("puppet.target", default="/etc/puppet")
self.__puppet_command = env.config.get("puppet.command", default="/usr/bin/puppet")
self.__report_dir = env.config.get("puppet.report-dir", default="/var/log/puppet")
self.__base_dir = getpwnam(self.__puppet_user).pw_dir
# Initialize if not already done
if not self.puppetIsInitialized():
self.puppetInitialize(True)
# Start log listener
wm = pyinotify.WatchManager()
# pylint: disable-msg=E1101
wm.add_watch(self.__report_dir, pyinotify.IN_CREATE, rec=True, auto_add=True) #@UndefinedVariable
notifier = pyinotify.ThreadedNotifier(wm, PuppetLogWatcher())
env.threads.append(notifier)
notifier.start()
示例13: __init__
def __init__(self):
conn = get_system_bus()
dbus.service.Object.__init__(self, conn, '/org/clacks/puppet')
self.env = Environment.getInstance()
self.log = logging.getLogger(__name__)
self.logdir = self.env.config.get("puppet.report-dir",
"/var/log/puppet")
# Check puppet configuration
config = ConfigParser.ConfigParser()
config.read('/etc/puppet/puppet.conf')
try:
if config.get("main", "report", "false") != "true":
raise OptionMissing("puppet has no reporting enabled")
if config.get("main", "reportdir", "") != self.logdir:
raise OptionMissing("reportdir configured in " \
"/etc/puppet/puppet.conf and %s do not match" % self.env.config.get('core.config'))
if config.get("main", "reports", "") != "store_clacks":
raise OptionMissing("storage module probably not compatible")
except OptionMissing:
self.hint("configuration section for puppet is incomplete")
except ConfigParser.NoOptionError:
self.hint("configuration section for puppet is incomplete")
示例14: setUp
def setUp(self):
""" Stuff to be run before every test """
Environment.config = "sample_test.conf"
Environment.noargs = True
self.env = Environment.getInstance()
self.plugin = SampleModule()
示例15: __init__
def __init__(self):
env = Environment.getInstance()
self.env = env
self.__dr = DBusRunner.get_instance()
self.__bus = None
# Register for resume events
zope.event.subscribers.append(self.__handle_events)