def load(self, dependencies): api = dependencies['api'] config = dependencies['config'] token_changed_subscribe = dependencies['token_changed_subscribe'] provd_client = ProvdClient(**config['provd']) token_changed_subscribe(provd_client.set_token) service_sip = build_service_sip(provd_client) service_sccp = build_service_sccp(provd_client) service_custom = build_service_custom(provd_client) api.add_resource( LineEndpointAssociationSip, '/lines/<int:line_id>/endpoints/sip/<uuid:endpoint_uuid>', endpoint='line_endpoint_sip', resource_class_args=(service_sip, line_dao, endpoint_sip_dao), ) api.add_resource( LineEndpointAssociationSccp, '/lines/<int:line_id>/endpoints/sccp/<int:endpoint_id>', endpoint='line_endpoint_sccp', resource_class_args=(service_sccp, line_dao, endpoint_sccp_dao), ) api.add_resource( LineEndpointAssociationCustom, '/lines/<int:line_id>/endpoints/custom/<int:endpoint_id>', endpoint='line_endpoint_custom', resource_class_args=(service_custom, line_dao, endpoint_custom_dao), )
def load(self, dependencies): api = dependencies['api'] config = dependencies['config'] service_id = config['wizard']['service_id'] service_key = config['wizard']['service_key'] auth_config = dict(config['auth']) auth_config.pop('username', None) auth_config.pop('password', None) if not service_id or not service_key: logger.info( 'failed to load the wizard plugin: missing service_id or service_key' ) return auth_client = AuthClient(username=service_id, password=service_key, **auth_config) provd_client = ProvdClient(**config['provd']) service = build_service(provd_client, auth_client, infos_dao) api.add_resource(WizardResource, '/wizard', endpoint='wizard', resource_class_args=(service, )) api.add_resource(WizardDiscoverResource, '/wizard/discover', resource_class_args=(service, ))
def load(self, dependencies): api = dependencies['api'] config = dependencies['config'] token_changed_subscribe = dependencies['token_changed_subscribe'] provd_client = ProvdClient(**config['provd']) token_changed_subscribe(provd_client.set_token) pjsip_doc = dependencies['pjsip_doc'] endpoint_service = build_endpoint_service(provd_client, pjsip_doc) template_service = build_template_service(provd_client, pjsip_doc) api.add_resource( SipItem, '/endpoints/sip/<uuid:uuid>', endpoint='endpoint_sip', resource_class_args=(endpoint_service, sip_dao, transport_dao), ) api.add_resource( SipList, '/endpoints/sip', resource_class_args=(endpoint_service, sip_dao, transport_dao), ) api.add_resource( SipTemplateItem, '/endpoints/sip/templates/<uuid:uuid>', endpoint='endpoint_sip_templates', resource_class_args=(template_service, sip_dao, transport_dao), ) api.add_resource( SipTemplateList, '/endpoints/sip/templates', resource_class_args=(template_service, sip_dao, transport_dao), )
def create_helper(host='127.0.0.1', port='8666', token=TOKEN): client = ProvdClient(host=host, port=port, prefix='', https=False, token=token) return ProvdHelper(client)
def load(self, dependencies): api = dependencies['api'] config = dependencies['config'] token_changed_subscribe = dependencies['token_changed_subscribe'] provd_client = ProvdClient(**config['provd']) token_changed_subscribe(provd_client.set_token) device_dao = build_device_dao(provd_client) device_updater = build_device_updater(provd_client) service = build_service(provd_client, device_updater) api.add_resource( LineDeviceAssociation, '/lines/<int:line_id>/devices/<device_id>', endpoint='line_devices', resource_class_args=(line_dao, device_dao, service), ) api.add_resource( LineDeviceGet, '/lines/<int:line_id>/devices', resource_class_args=(line_dao, device_dao, service), ) api.add_resource( DeviceLineGet, '/devices/<device_id>/lines', resource_class_args=(line_dao, device_dao, service), )
def get_provd_client(): client = g.get('wazo_provd_client') if not client: client = g.wazo_provd_client = ProvdClient(**app.config['provd']) client.set_token(current_user.get_id()) client.set_tenant(current_user.get_tenant_uuid()) add_tenant_to(client) return client
def load(self, dependencies): api = dependencies['api'] config = dependencies['config'] token_changed_subscribe = dependencies['token_changed_subscribe'] provd_client = ProvdClient(**config['provd']) token_changed_subscribe(provd_client.set_token) self.load_sip(api, provd_client) self.load_sccp(api, provd_client) self.load_custom(api, provd_client)
def remove_null_values(): config = _load_config() provd_client = ProvdClient(**config['provd']) _wait_for_provd(provd_client) auth_client = AuthClient(**config['auth']) token = auth_client.token.new('wazo_user', expiration=5 * 60) provd_client.set_token(token['token']) configs = provd_client.configs.list_device()['configs'] for config in configs: provd_client.configs.update(_remove_null_value(config))
def reconfigure_all_devices(): config = _load_config() provd_client = ProvdClient(**config['provd']) _wait_for_provd(provd_client) auth_client = AuthClient(**config['auth']) token = auth_client.token.new('wazo_user', expiration=5*60) provd_client.set_token(token['token']) devices = provd_client.devices.list(recurse=True)['devices'] for device in devices: provd_client.devices.reconfigure(device['id']) provd_client.devices.synchronize(device['id'])
def load(self, dependencies): api = dependencies['api'] config = dependencies['config'] token_changed_subscribe = dependencies['token_changed_subscribe'] provd_client = ProvdClient(**config['provd']) token_changed_subscribe(provd_client.set_token) service = build_service(provd_client) api.add_resource( LineItem, '/lines/<int:id>', endpoint='lines', resource_class_args=(service, ), ) api.add_resource(LineList, '/lines', resource_class_args=(service, ))
def load(self, dependencies): api = dependencies['api'] config = dependencies['config'] token_changed_subscribe = dependencies['token_changed_subscribe'] provd_client = ProvdClient(**config['provd']) token_changed_subscribe(provd_client.set_token) registrar_dao = build_dao(provd_client) service = build_service(registrar_dao, provd_client) api.add_resource(RegistrarList, '/registrars', resource_class_args=(service,)) api.add_resource( RegistrarItem, '/registrars/<id>', endpoint='registrars', resource_class_args=(service,), )
def load(self, dependencies): api = dependencies['api'] config = dependencies['config'] token_changed_subscribe = dependencies['token_changed_subscribe'] provd_client = ProvdClient(**config['provd']) token_changed_subscribe(provd_client.set_token) dao = build_dao(provd_client) service = build_service(dao, provd_client) api.add_resource( DeviceItem, '/devices/<id>', endpoint='devices', resource_class_args=(service,), ) api.add_resource(DeviceList, '/devices', resource_class_args=(service,)) api.add_resource( DeviceAutoprov, '/devices/<id>/autoprov', resource_class_args=(service,) ) api.add_resource( DeviceSynchronize, '/devices/<id>/synchronize', resource_class_args=(service,), ) api.add_resource( UnallocatedDeviceList, '/devices/unallocated', resource_class_args=(service,), ) api.add_resource( UnallocatedDeviceItem, '/devices/unallocated/<id>', resource_class_args=(service,), )
def load(self, dependencies): config = dependencies['config'] bus_consumer = dependencies['bus_consumer'] token_changed_subscribe = dependencies['token_changed_subscribe'] provd_client = ProvdClient(**config['provd']) token_changed_subscribe(provd_client.set_token) instant_bus_publisher = InstantBusPublisher.from_config( config['bus'], config['uuid'], ) device_notifier = DeviceNotifier(instant_bus_publisher) service = DefaultSIPTemplateService(sip_dao, transport_dao) tenant_event_handler = TenantEventHandler( tenant_dao, service, provd_client, device_notifier, ) tenant_event_handler.subscribe(bus_consumer)
def main(): config = _read_config() setup_logging(config['log_filename'], debug=config['debug']) if 'host' not in config['prov_server']: logger.error('error: no provd host specified. Exiting.') sys.exit(1) user = config['user'] if user: change_user(user) auth_client = AuthClient(**config['auth']) provd_client = ProvdClient(**config['prov_server']) token_renewer = TokenRenewer(auth_client) token_renewer.subscribe_to_token_change(provd_client.set_token) sink = ProvServerDHCPInfoSink(provd_client) with token_renewer: try: pidfile = PidFile(config['pid_filename']) try: source = UnixSocketDHCPInfoSource(config['unix_server_addr'], True) try: signum = signal.SIGTERM old_handler = signal.signal(signum, _sig_handler) try: agent = Agent(source, sink) agent.run() finally: signal.signal(signum, old_handler) finally: source.close() finally: pidfile.close() finally: sink.close()
def setup_provd_client(context): context.provd_client = ProvdClient(**context.wazo_config['provd']) context.provd_client.set_token(context.token) context.token_pubsub.subscribe('new-token-id', context.provd_client.set_token)
def new_from_config(cls, provd_config): return cls(ProvdClient(**provd_config))
def load(self, dependencies): api = dependencies['api'] config = dependencies['config'] token_changed_subscribe = dependencies['token_changed_subscribe'] provd_client = ProvdClient(**config['provd']) token_changed_subscribe(provd_client.set_token) service = build_service(provd_client) service_callservice = build_service_callservice() service_forward = build_service_forward() api.add_resource( UserItem, '/users/<uuid:id>', '/users/<int:id>', endpoint='users', resource_class_args=(service,), ) api.add_resource( UserList, '/users', endpoint='users_list', resource_class_args=(service,) ) api.add_resource( UserServiceDND, '/users/<uuid:user_id>/services/dnd', '/users/<int:user_id>/services/dnd', resource_class_args=(service_callservice,), ) api.add_resource( UserServiceIncallFilter, '/users/<uuid:user_id>/services/incallfilter', '/users/<int:user_id>/services/incallfilter', resource_class_args=(service_callservice,), ) api.add_resource( UserServiceList, '/users/<uuid:user_id>/services', '/users/<int:user_id>/services', resource_class_args=(service_callservice,), ) api.add_resource( UserForwardBusy, '/users/<uuid:user_id>/forwards/busy', '/users/<int:user_id>/forwards/busy', resource_class_args=(service_forward,), ) api.add_resource( UserForwardNoAnswer, '/users/<uuid:user_id>/forwards/noanswer', '/users/<int:user_id>/forwards/noanswer', resource_class_args=(service_forward,), ) api.add_resource( UserForwardUnconditional, '/users/<uuid:user_id>/forwards/unconditional', '/users/<int:user_id>/forwards/unconditional', resource_class_args=(service_forward,), ) api.add_resource( UserForwardList, '/users/<uuid:user_id>/forwards', '/users/<int:user_id>/forwards', resource_class_args=(service_forward,), )
def new_cli_provisioning_client(provd_args): prov_client = ProvdClient(**provd_args) return ProvisioningClient(prov_client)
'password': key_file['service_key'] } } config = load_config() auth_client = AuthClient(**config['auth']) token_data = auth_client.token.new(expiration=300) logging.basicConfig(level=logging.INFO) logger = logging.getLogger('reset_unassociated_devices_to_autoprov') logger.debug('Fetching wrongly configured devices...') confd_client = ConfdClient(token=token_data['token'], **config['confd']) provd_client = ProvdClient(token=token_data['token'], **config['provd']) session = requests.Session() session.headers = { 'Accept': 'application/json', 'Content-Type': 'application/json', 'X-Auth-Token': token_data['token'], } devices = provd_client.devices.list()['devices'] lines = confd_client.lines.list(recurse=True)['items'] configured_device_ids = { device['id'] for device in devices
def load(self, dependencies): api = dependencies['api'] config = dependencies['config'] token_changed_subscribe = dependencies['token_changed_subscribe'] set_auth_client_config(config['auth']) provd_client = ProvdClient(**config['provd']) token_changed_subscribe(provd_client.set_token) user_service = build_user_service(provd_client) wazo_user_service = build_wazo_user_service() user_voicemail_service = build_uv_service() voicemail_service = build_voicemail_service() line_service = build_line_service(provd_client) sip_service = build_sip_service(provd_client) sccp_service = build_sccp_service() line_sip_service = build_le_service(provd_client, 'sip', sip_service) line_sccp_service = build_le_service(provd_client, 'sccp', sccp_service) extension_service = build_extension_service(provd_client) user_line_service = build_ul_service() line_extension_service = build_line_extension_service() call_permission_service = build_call_permission_service() user_call_permission_service = build_user_call_permission_service() incall_service = build_incall_service() incall_extension_service = build_incall_extension_service() context_service = build_context_service() creators = { 'user': UserCreator(user_service), 'wazo_user': WazoUserCreator(wazo_user_service), 'line': LineCreator(line_service), 'voicemail': VoicemailCreator(voicemail_service), 'sip': SipCreator(sip_service), 'sccp': SccpCreator(sccp_service), 'extension': ExtensionCreator(extension_service), 'extension_incall': ExtensionCreator(extension_service), 'incall': IncallCreator(incall_service), 'call_permissions': CallPermissionCreator(call_permission_service), 'context': ContextCreator(context_service), } entry_creator = EntryCreator(creators) associators = OrderedDict([ ('wazo_user', WazoUserAssociator(wazo_user_service)), ('voicemail', VoicemailAssociator(user_voicemail_service)), ('sip', SipAssociator(line_sip_service)), ('sccp', SccpAssociator(line_sccp_service)), ('line', LineAssociator(user_line_service)), ('extension', ExtensionAssociator(line_extension_service)), ('incall', IncallAssociator(incall_extension_service)), ( 'call_permissions', CallPermissionAssociator(user_call_permission_service, call_permission_service), ), ]) entry_associator = EntryAssociator(associators) entry_finder = EntryFinder( user_dao, voicemail_dao, user_voicemail_dao, line_dao, user_line_dao, line_extension_dao, sip_dao, sccp_dao, extension_dao, incall_dao, call_permission_dao, user_call_permission_dao, ) entry_updater = EntryUpdater(creators, associators, entry_finder) import_service = ImportService(entry_creator, entry_associator, entry_updater) api.add_resource(UserImportResource, '/users/import', resource_class_args=(import_service, )) export_service = ExportService(user_export_dao, auth_client) api.add_resource(UserExportResource, '/users/export', resource_class_args=(export_service, ))
def load(self, dependencies): api = dependencies['api'] config = dependencies['config'] token_changed_subscribe = dependencies['token_changed_subscribe'] provd_client = ProvdClient(**config['provd']) token_changed_subscribe(provd_client.set_token) service = build_service(provd_client) service_association = build_user_funckey_template_service(provd_client) # Funckey destination plugin api.add_resource(FuncKeyDestination, '/funckeys/destinations', endpoint='func_keys') # Funckey Template plugin api.add_resource(FuncKeyTemplateList, '/funckeys/templates', resource_class_args=(service, )) api.add_resource( FuncKeyTemplateItem, '/funckeys/templates/<int:id>', endpoint='func_keys_templates', resource_class_args=(service, ), ) api.add_resource( FuncKeyTemplateItemPosition, '/funckeys/templates/<int:id>/<int:position>', resource_class_args=(service, ), ) # User-Funckey plugin api.add_resource( UserFuncKeyItemPosition, '/users/<uuid:user_id>/funckeys/<int:position>', '/users/<int:user_id>/funckeys/<int:position>', resource_class_args=(service, user_dao, template_dao), ) api.add_resource( UserFuncKeyList, '/users/<uuid:user_id>/funckeys', '/users/<int:user_id>/funckeys', resource_class_args=(service, user_dao, template_dao), ) # User-Funckey Template plugin api.add_resource( UserFuncKeyTemplateAssociation, '/users/<uuid:user_id>/funckeys/templates/<int:template_id>', '/users/<int:user_id>/funckeys/templates/<int:template_id>', resource_class_args=(service_association, user_dao, template_dao), ) api.add_resource( UserFuncKeyTemplateGet, '/users/<uuid:user_id>/funckeys/templates', '/users/<int:user_id>/funckeys/templates', resource_class_args=(service_association, user_dao, template_dao), ) api.add_resource( FuncKeyTemplateUserGet, '/funckeys/templates/<int:template_id>/users', resource_class_args=(service_association, user_dao, template_dao), )