blob: 7382edd651ff11a8b6814849b84d75149a9cfc24 [file] [log] [blame]
Andy Bavier89a95422016-11-02 14:38:39 -04001import os
2import base64
3from collections import defaultdict
4from django.db.models import F, Q
5from xos.config import Config
6from synchronizers.base.syncstep import *
7from core.models.site import Controller, SiteDeployment, SiteDeployment
8from core.models.user import User
9from core.models.controlleruser import ControllerUser
10from synchronizers.base.ansible import *
11from xos.logger import observer_logger as logger
12import json
13
14class SyncControllerUsers(SyncStep):
15 provides=[User]
16 requested_interval=0
17 observes=ControllerUser
18 playbook='sync_controller_users.yaml'
19
20 def map_sync_inputs(self, controller_user):
21 if not controller_user.controller.admin_user:
22 logger.info("controller %r has no admin_user, skipping" % controller_user.controller)
23 return
24
25 if not controller_user.user.site:
26 raise Exception('Siteless user %s'%controller_user.user.email)
27
28 if controller_user.user.email == controller_user.controller.admin_user:
29 logger.info("user %s is the admin_user at controller %r, skipping" % (controller_user.user.email, controller_user.controller))
30 return
31
32 user_fields = {
33 'endpoint':controller_user.controller.auth_url,
34 'name': controller_user.user.email,
35 'firstname': controller_user.user.firstname,
36 'lastname': controller_user.user.lastname,
37 'phone': controller_user.user.phone,
38 'user_url': controller_user.user.user_url,
39 'public_key': controller_user.user.public_key,
40 'is_active': controller_user.user.is_active,
41 'is_admin': controller_user.user.is_admin,
42 'is_readonly': controller_user.user.is_readonly,
43 'is_appuser': controller_user.user.is_appuser,
44 'password': controller_user.user.remote_password,
45 'admin_user': controller_user.controller.admin_user,
46 'admin_password': controller_user.controller.admin_password,
47 'ansible_tag':'%s@%s'%(controller_user.user.email.replace('@','-at-'),controller_user.controller.name),
48 }
49 return user_fields
50
51 def map_sync_outputs(self, controller_user, res):
52 #controller_user.kuser_id = res[0]['user']['id']
53 controller_user.kuser_id = 'not implemented'
54 controller_user.backend_status = '1 - OK'
55 controller_user.save()
56
57 def delete_record(self, controller_user):
58 """
59 if controller_user.kuser_id:
60 driver = self.driver.admin_driver(controller=controller_user.controller)
61 driver.delete_user(controller_user.kuser_id)
62 """
63 pass