-class Worker:
- # these semaphores are acquired before creating/destroying an account
- _create_sem = threading.Semaphore(1)
- _destroy_sem = threading.Semaphore(1)
+ def configure(self, rec):
+ """Write <rec['keys']> to my authorized_keys file."""
+ logger.verbose('%s: in accounts:configure'%self.name)
+ new_keys = rec['keys']
+ if new_keys != self.keys:
+ self.keys = new_keys
+ gid = grp.getgrnam("slices")[2]
+ pw_info = pwd.getpwnam(self.name)
+ uid = pw_info[2]
+ pw_dir = pw_info[5]
+
+ dot_ssh = pw_dir + '/.ssh'
+ if not os.access(dot_ssh, os.F_OK): os.mkdir(dot_ssh)
+
+ auth_keys = dot_ssh + '/authorized_keys'
+ tools.write_file(auth_keys, lambda f: f.write(new_keys))
+
+ os.chmod(dot_ssh, 0700)
+ os.chmod(auth_keys, 0600)
+
+ os.chown(dot_ssh, uid, gid)
+ os.chown(auth_keys, uid, gid)