Beispiel #1
0
def install_custom_examples():
    if EXAMPLES.AUTO_LOAD.get():
        from desktop.auth.backend import rewrite_user
        from beeswax.management.commands import beeswax_install_examples
        from useradmin.models import install_sample_user

        user = rewrite_user(install_sample_user())

        if has_connectors():
            interpreters = [{
                'type': connector['id'],
                'dialect': connector['dialect']
            } for connector in _get_installed_connectors(category='editor')]
        else:
            interpreters = [
                {
                    'type': interpreter['dialect'],
                    'dialect': interpreter['dialect']
                } for interpreter in get_ordered_interpreters(user)
                # Only for hive/impala currently, would also need to port to Notebook install examples.
                if interpreter['dialect'] in ('hive', 'impala')
            ]

        queries = EXAMPLES.QUERIES.get()
        tables = EXAMPLES.TABLES.get(
        )  # No-op. Only for the saved query samples, not the tables currently.

        LOG.info(
            'Installing custom examples queries: %(queries)s, tables: %(tables)s for dialects %(dialects)s '
            'belonging to user %(user)s' % {
                'queries':
                queries,
                'tables':
                tables,
                'dialects':
                [interpreter['dialect'] for interpreter in interpreters],
                'user':
                user
            })

        result = []

        for interpreter in interpreters:
            successes, errors = beeswax_install_examples.Command().handle(
                dialect=interpreter['dialect'],
                user=user,
                interpreter=interpreter,
                queries=queries,
                tables=tables,
                request=None)
            LOG.info(
                'Dialect %(dialect)s installed samples: %(successes)s, %(errors)s,'
                % {
                    'dialect': interpreter['dialect'],
                    'successes': successes,
                    'errors': errors,
                })
            result.append((successes, errors))

        return result
Beispiel #2
0
def get_api(user, connector_id):
    if has_connectors() and connector_id != 'dummy':
        connectors = _get_installed_connectors(user=user,
                                               connector_id=int(connector_id))
        connector = connectors[0]
        dialect = connector['dialect']
    else:
        connector = None  # Could get the interpreter if Connectors are off
        dialect = connector_id

    if dialect == 'dummy':
        return Base(user, connector_id)
    else:
        raise PopupException(
            _('Indexer connector dialect not recognized: %s') % dialect)
    def handle(self, *args, **options):
        LOG.info('Installing %s examples as %s' %
                 (options.get('dialect') or 'all', options['username']))

        user = User.objects.get(username=options['username'])
        dialect = options.get('dialect')

        dialects = [{
            'id': connector['id'],
            'dialect': connector['dialect']
        } for connector in _get_installed_connectors(category='editor')
                    if dialect is None or connector['dialect'] == dialect]

        tables = None

        for dialect in dialects:
            EditorCommand().handle(
                app_name=dialect['dialect'],  # Unused?
                user=user,
                tables=tables,
                dialect=dialect['dialect'],
                interpreter={'type': dialect['id']})
Beispiel #4
0
def get_connectors_instances(request):
    return JsonResponse(
        {'connectors': _group_by_category(_get_installed_connectors())})
Beispiel #5
0
def get_installed_connectors(request):
  return JsonResponse({
    'connectors': _group_category_connectors(
      _get_installed_connectors()
    ),
  })
Beispiel #6
0
def update_app_permissions(**kwargs):
    """
  Keep in sync apps and connectors permissions into the database table.
  Map app + action to a HuePermission.

  v2
  Based on the connectors.
  Permissions are either based on connectors instances or Hue specific actions.
  Permissions can be deleted or added dynamically.

  v1
  This is a 'migrate' callback.

  We never delete permissions automatically, because apps might come and go.

  Note that signing up to the "migrate" signal is not necessarily the best thing we can do, since some apps might not
  have models, but nonetheless, "migrate" is typically run when apps are installed.
  """
    created_tables = connection.introspection.table_names()

    if ENABLE_ORGANIZATIONS.get(
    ) and 'useradmin_organization' not in created_tables:
        return

    if u'useradmin_huepermission' in created_tables:  # Check if Useradmin has been installed.
        current = {}

        try:
            for dp in HuePermission.objects.all():
                current.setdefault(dp.app, {})[dp.action] = dp
        except:
            LOG.exception('failed to get permissions')
            return

        updated = 0
        uptodate = 0
        added = []

        if ENABLE_CONNECTORS.get():
            old_apps = list(current.keys())
            ConnectorPerm = collections.namedtuple('ConnectorPerm',
                                                   'name nice_name settings')
            apps = [
                ConnectorPerm(name=connector['name'],
                              nice_name=connector['nice_name'],
                              settings=[])
                for connector in _get_installed_connectors()
            ]
        else:
            old_apps = []
            apps = appmanager.DESKTOP_APPS

        for app in apps:
            app_name = app.name
            permission_description = "Access the %s connection" % app.nice_name if ENABLE_CONNECTORS.get(
            ) else "Launch this application"
            actions = set([("access", permission_description)])
            actions.update(getattr(app.settings, "PERMISSION_ACTIONS", []))

            if app_name not in current:
                current[app_name] = {}
            if app_name in old_apps:
                old_apps.remove(app_name)

            for action, description in actions:
                c = current[app_name].get(action)
                if c:
                    if c.description != description:
                        c.description = description
                        c.save()
                        updated += 1
                    else:
                        uptodate += 1
                else:
                    new_dp = HuePermission(app=app_name,
                                           action=action,
                                           description=description)
                    if ENABLE_CONNECTORS.get():
                        new_dp.connector = Connector.objects.get(id=app_name)
                    new_dp.save()
                    added.append(new_dp)

        # Only with v2
        deleted, _ = HuePermission.objects.filter(app__in=old_apps).delete()

        # Add all permissions to default group except some.
        default_group = get_default_user_group()
        if default_group:
            for new_dp in added:
                if not (new_dp.app == 'useradmin' and new_dp.action == 'access') and \
                    not (new_dp.app == 'useradmin' and new_dp.action == 'superuser') and \
                    not (new_dp.app == 'metastore' and new_dp.action == 'write') and \
                    not (new_dp.app == 'hbase' and new_dp.action == 'write') and \
                    not (new_dp.app == 'security' and new_dp.action == 'impersonate') and \
                    not (new_dp.app == 'filebrowser' and new_dp.action == 's3_access' and not is_idbroker_enabled('s3a')) and \
                    not (new_dp.app == 'filebrowser' and new_dp.action == 'gs_access' and not is_idbroker_enabled('gs')) and \
                    not (new_dp.app == 'filebrowser' and new_dp.action == 'adls_access') and \
                    not (new_dp.app == 'filebrowser' and new_dp.action == 'abfs_access') and \
                    not (new_dp.app == 'oozie' and new_dp.action == 'disable_editor_access'):
                    GroupPermission.objects.create(group=default_group,
                                                   hue_permission=new_dp)

        available = HuePermission.objects.count()
        stale = available - len(added) - updated - uptodate

        if len(added) or updated or stale or deleted:
            LOG.info(
                "HuePermissions: %d added, %d updated, %d up to date, %d stale, %d deleted"
                % (len(added), updated, uptodate, stale, deleted))