How to use the aj.api.http.HttpPlugin function in aj

To help you get started, we’ve selected a few aj examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ajenti / ajenti / plugins / core / views / resource_server.py View on Github external
import json
import os
from jadi import component

import aj
from aj.api.http import url, HttpPlugin
from aj.plugins import PluginManager

from aj.api.endpoint import endpoint


@component(HttpPlugin)
class ResourcesHandler(HttpPlugin):
    def __init__(self, http_context):
        self.cache = {}
        self.use_cache = not aj.debug
        self.mgr = PluginManager.get(aj.context)

    def __wrap_js(self, name, js):
        return '''
            try {
                %s
            } catch (err) {
                console.warn('Plugin load error:');
                console.warn(' * %s');
                console.error('  ', err);
            }
        ''' % (js, name)
github ajenti / ajenti / plugins / core / views / resource_server.py View on Github external
import json
import os
from jadi import component

import aj
from aj.api.http import url, HttpPlugin
from aj.plugins import PluginManager

from aj.api.endpoint import endpoint


@component(HttpPlugin)
class ResourcesHandler(HttpPlugin):
    def __init__(self, http_context):
        self.cache = {}
        self.use_cache = not aj.debug
        self.mgr = PluginManager.get(aj.context)

    def __wrap_js(self, name, js):
        return '''
            try {
                %s
            } catch (err) {
                console.warn('Plugin load error:');
                console.warn(' * %s');
                console.error('  ', err);
            }
        ''' % (js, name)
github ajenti / ajenti / plugins / settings / views.py View on Github external
import json
import random
import socket
from OpenSSL.crypto import *

import aj
from jadi import component
from aj.api.http import url, HttpPlugin

from aj.api.endpoint import endpoint


@component(HttpPlugin)
class Handler(HttpPlugin):
    def __init__(self, context):
        self.context = context

    @url(r'/api/settings/generate-client-certificate')
    @endpoint(api=True)
    def handle_api_generate_client_certificate(self, http_context):
        data = json.loads(http_context.body)

        key = PKey()
        key.generate_key(TYPE_RSA, 4096)
        ca_key = load_privatekey(FILETYPE_PEM, open(aj.config.data['ssl']['certificate']).read())
        ca_cert = load_certificate(FILETYPE_PEM, open(aj.config.data['ssl']['certificate']).read())
        cert = X509()
        cert.get_subject().countryName = data['c']
        cert.get_subject().stateOrProvinceName = data['st']
github ajenti / ajenti / plugins / filesystem / views.py View on Github external
import errno
import grp
import json
import os
import psutil
import pwd
import shutil
from jadi import component

from aj.api.http import url, HttpPlugin
from aj.api.endpoint import endpoint, EndpointError, EndpointReturn
from aj.auth import authorize


@component(HttpPlugin)
class Handler(HttpPlugin):
    def __init__(self, context):
        self.context = context

    @url(r'/api/filesystem/mountpoints')
    @authorize('filesystem:read')
    @endpoint(api=True)
    def handle_api_fs_mountpoints(self, http_context):
        return [x.mountpoint for x in psutil.disk_partitions()]

    @url(r'/api/filesystem/read/(?P
github ajenti / ajenti / plugins / datetime / views.py View on Github external
import logging
import subprocess
import time
from datetime import datetime
from jadi import component

from aj.api.http import url, HttpPlugin
from aj.auth import authorize
from aj.api.endpoint import endpoint, EndpointError
from aj.plugins.datetime.api import TZManager


@component(HttpPlugin)
class Handler(HttpPlugin):
    def __init__(self, context):
        self.context = context
        self.manager = TZManager.any(self.context)

    @url(r'/api/datetime/tz/get')
    @endpoint(api=True)
    def handle_api_tz_get(self, http_context):
        time.tzset()
        return {
            'tz': self.manager.get_tz(),
            'offset': self.manager.get_offset(),
        }

    @url(r'/api/datetime/tz/set/(?P.+)')
    @authorize('datetime:write')
    @endpoint(api=True)
github ajenti / ajenti / plugins / plugins / views.py View on Github external
import os
import requests
import shutil
import subprocess

import aj
from jadi import component
from aj.api.http import url, HttpPlugin
from aj.plugins import PluginManager, PluginDependency, BinaryDependency

from aj.api.endpoint import endpoint, EndpointError


@component(HttpPlugin)
class Handler(HttpPlugin):
    def __init__(self, context):
        self.context = context

    def __serialize_exception(self, e):
        if not e:
            return

        d = {
            'cls': e.__class__.__name__,
            'message': str(e),
            'type': 'generic',
        }

        if isinstance(e, PluginDependency.Unsatisfied):
            d['pluginName'] = e.dependency.plugin_name
github ajenti / ajenti / plugins / dashboard / views.py View on Github external
import json
from jadi import component

from aj.api.http import url, HttpPlugin

from aj.api.endpoint import endpoint
from aj.plugins.dashboard.api import Widget


@component(HttpPlugin)
class Handler(HttpPlugin):
    def __init__(self, context):
        self.context = context
        self.widgets = dict((x.id, x) for x in Widget.all(self.context))

    @url(r'/api/dashboard/widgets')
    @endpoint(api=True)
    def handle_api_widgets(self, http_context):
        return [
            {
                'id': w.id,
                'name': w.name,
                'template': w.template,
                'config_template': w.config_template,
            } for w in self.widgets.values()
        ]
github ajenti / ajenti / plugins / filesystem / views.py View on Github external
import errno
import grp
import json
import os
import psutil
import pwd
import shutil
from jadi import component

from aj.api.http import url, HttpPlugin
from aj.api.endpoint import endpoint, EndpointError, EndpointReturn
from aj.auth import authorize


@component(HttpPlugin)
class Handler(HttpPlugin):
    def __init__(self, context):
        self.context = context

    @url(r'/api/filesystem/mountpoints')
    @authorize('filesystem:read')
    @endpoint(api=True)
    def handle_api_fs_mountpoints(self, http_context):
        return [x.mountpoint for x in psutil.disk_partitions()]

    @url(r'/api/filesystem/read/(?P
github ajenti / ajenti / plugins / core / views / main.py View on Github external
import gevent
import json
import logging
import six
import subprocess
from jadi import component

import aj
from aj.api.http import url, HttpPlugin
from aj.plugins import PluginManager, DirectoryPluginProvider

from aj.api.endpoint import endpoint


@component(HttpPlugin)
class Handler(HttpPlugin):
    def __init__(self, context):
        self.context = context

    @url('/')
    @endpoint(page=True, auth=False)
    def handle_root(self, http_context):
        if self.context.identity:
            return http_context.redirect('/view/')
        else:
            return http_context.redirect('/view/login/normal')

    @url('/view/.*')
    @endpoint(page=True, auth=False)
    def handle_view(self, http_context):
        if aj.dev:
github ajenti / ajenti / plugins / auth_users / views.py View on Github external
from jadi import component

import aj
from aj.api.http import url, HttpPlugin

from aj.api.endpoint import endpoint
from aj.plugins.auth_users.api import UsersAuthenticationProvider


@component(HttpPlugin)
class Handler(HttpPlugin):
    def __init__(self, context):
        self.context = context
        self.manager = UsersAuthenticationProvider(self.context)

    @url(r'/api/auth-users/set-password/(?P.+)')
    @endpoint(api=True)
    def handle_api_set_password(self, http_context, username):
        password = http_context.body
        self.context.worker.reload_master_config()
        aj.config.data.setdefault('auth', {}).setdefault('users', {}).setdefault(username, {})['password'] = self.manager.hash_password(password)
        aj.config.save()