Пример #1
0
    def Register(self, org, username, password, options, connection_options,
                 locale):
        """
        This method registers the system using basic auth
        (username and password for a given org).
        For any option that is required but not included the default will be
        used.

        Options is a dict of strings that modify the outcome of this method.

        Note this method is registration ONLY.  Auto-attach is a separate process.
        """
        if self.is_registered():
            raise dbus.DBusException("This system is already registered")

        org = dbus_utils.dbus_to_python(org, expected_type=str)
        connection_options = dbus_utils.dbus_to_python(connection_options,
                                                       expected_type=dict)
        connection_options['username'] = dbus_utils.dbus_to_python(
            username, expected_type=str)
        connection_options['password'] = dbus_utils.dbus_to_python(
            password, expected_type=str)
        options = dbus_utils.dbus_to_python(options, expected_type=dict)
        locale = dbus_utils.dbus_to_python(locale, expected_type=str)

        Locale.set(locale)
        cp = self.build_uep(connection_options)

        register_service = RegisterService(cp)

        # Try to get organization from the list available organizations, when the list contains
        # only one item, then register_service.determine_owner_key will return this organization
        if not org:
            org = register_service.determine_owner_key(
                username=connection_options['username'],
                get_owner_cb=self._get_owner_cb,
                no_owner_cb=self._no_owner_cb)

        # When there is more organizations, then signal was triggered in callback method
        # _get_owner_cb, but some exception has to be raised here to not try registration process
        if not org:
            raise OrgNotSpecifiedException(
                username=connection_options['username'])

        consumer = register_service.register(org, **options)

        return json.dumps(consumer)
Пример #2
0
    def Register(self, org, username, password, options, connection_options,
                 locale):
        """
        This method registers the system using basic auth
        (username and password for a given org).
        For any option that is required but not included the default will be
        used.

        Options is a dict of strings that modify the outcome of this method.

        Note this method is registration ONLY.  Auto-attach is a separate process.
        """
        if self.is_registered():
            raise dbus.DBusException("This system is already registered")

        org = dbus_utils.dbus_to_python(org, expected_type=str)
        connection_options = dbus_utils.dbus_to_python(connection_options,
                                                       expected_type=dict)
        connection_options["username"] = dbus_utils.dbus_to_python(
            username, expected_type=str)
        connection_options["password"] = dbus_utils.dbus_to_python(
            password, expected_type=str)
        options = dbus_utils.dbus_to_python(options, expected_type=dict)
        locale = dbus_utils.dbus_to_python(locale, expected_type=str)

        with DBusSender() as dbus_sender:
            dbus_sender.set_cmd_line(sender=self.sender,
                                     cmd_line=self.cmd_line)
            Locale.set(locale)
            cp = self.build_uep(connection_options)

            register_service = RegisterService(cp)

            # Try to get organization from the list available organizations, when the list contains
            # only one item, then register_service.determine_owner_key will return this organization
            if not org:
                org = register_service.determine_owner_key(
                    username=connection_options["username"],
                    get_owner_cb=self._get_owner_cb,
                    no_owner_cb=self._no_owner_cb,
                )

            # When there is more organizations, then signal was triggered in callback method
            # _get_owner_cb, but some exception has to be raised here to not try registration process
            if not org:
                raise OrgNotSpecifiedException(
                    username=connection_options["username"])

            # Remove 'enable_content' option, because it will not be proceed in register service
            enable_content = self._remove_enable_content_option(options)

            consumer = register_service.register(org, **options)

            # When consumer is created, then we can try to enabled content, when it was
            # requested in options.
            if enable_content is True:
                self._enable_content(cp, consumer)

            dbus_sender.reset_cmd_line()

        return json.dumps(consumer)