当前位置: 首页>>代码示例>>Python>>正文


Python util.JsonOutput类代码示例

本文整理汇总了Python中cloudrunner_server.api.util.JsonOutput的典型用法代码示例。如果您正苦于以下问题:Python JsonOutput类的具体用法?Python JsonOutput怎么用?Python JsonOutput使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了JsonOutput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: profiles

    def profiles(self, name=None, *args):
        def shares(p):
            return [sh.serialize(
                skip=['id', 'profile_id', 'password']) for sh in p]

        def nodes(ns):
            return [n.name for n in ns]

        def shares_details(p):
            return [sh.serialize(
                skip=['id', 'profile_id', 'password'],
                rel=[('shared_nodes', 'nodes', nodes)]
            ) for sh in p]
        if name:
            prof = CloudProfile.my(request).filter(
                CloudProfile.name == name).first()

            return O.profile(prof.serialize(
                skip=['id', 'owner_id', 'share_id', 'password', 'arguments'],
                rel=[('shares', 'shares', shares_details)]))
        else:
            profs = [p.serialize(
                skip=['id', 'owner_id', 'share_id', 'password', 'arguments'],
                rel=[('shares', 'shares', shares)])
                for p in CloudProfile.my(request).all()]
            return O._anon(
                profiles=profs,
                quota=dict(allowed=request.user.tier.cloud_profiles))
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:28,代码来源:clouds.py

示例2: login

    def login(self, **kwargs):

        if not kwargs:
            kwargs = request.json

        username = kwargs.get('username')
        password = kwargs['password']
        token = kwargs.get('token')
        expire = int(kwargs.get('expire', DEFAULT_EXP))
        if not username and token:
            # Recover
            t = request.db.query(Token).filter(
                Token.value == token, Token.scope == 'RECOVER').first()
            if not t:
                return O.error(msg="The recovery key is invalid "
                               "or expired.")
            username = t.user.username
            t.user.set_password(password)
            request.db.add(t.user)
            request.db.delete(t)
            request.db.commit()

        user = request.db.query(User).join(Org).outerjoin(
            Token, Permission).filter(
                User.enabled == True,  # noqa
                User.username == username,
                User.password == hash_token(password)).first()
        if not user:
            return O.error(msg='Cannot login')

        try:
            expire = int(expire)
            if expire < 0 or expire > MAX_EXP:
                return O.error(msg='Invalid expire timeout, '
                               'should be between 1 and %d minutes' % MAX_EXP)
        except:
            expire = DEFAULT_EXP
        token = User.create_token(request, user.id,
                                  minutes=expire,
                                  scope='LOGIN')

        permissions = [p.name for p in user.permissions]
        md = hashlib.md5()
        md.update(user.email)
        email_hash = md.hexdigest()
        cached_token = dict(uid=user.id, org=user.org.name, token=token.value,
                            tier=user.org.tier.serialize(skip=['id']),
                            permissions=permissions, email=user.email,
                            email_hash=email_hash)

        cache = CacheRegistry()
        cache.add_token(username, cached_token, expire)

        return O.login(user=username,
                       email=user.email,
                       email_hash=email_hash,
                       token=token.value,
                       expire=token.expires_at,
                       org=user.org.name,
                       perms=permissions)
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:60,代码来源:auth.py

示例3: revisions

    def revisions(self, repository, *args, **kwargs):
        path = "/".join(args)
        path.rstrip("/")
        if not path.startswith("/"):
            path = "/" + path

        path, _, script = path.rpartition('/')
        path = path + '/'

        scr = Script.visible(request,
                             repository,
                             path).filter(Script.name == script).first()
        if not scr:
            return O.error(msg="Script not found")

        revisions = sorted([r.serialize(
            skip=['id', 'script_id', 'draft', 'content', 'meta'],
            rel=[("created_at", "created_at", lambda d: d)])
            for r in scr.history
            if not r.draft], key=lambda r: r["created_at"], reverse=True)
        return O.history(
            script=scr.name,
            owner=scr.owner.username,
            revisions=revisions
        )
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:25,代码来源:library.py

示例4: script_create

    def script_create(self, name=None, **kwargs):
        name = name or kwargs['name']
        if not Script.valid_name(name):
            return O.error(msg="Invalid script name")
        content = kwargs['content']
        mime = kwargs.get('mime', 'text/plain')
        meta = kwargs.get('meta')
        folder_name = kwargs['folder']
        repository, _, folder_path = folder_name.partition("/")
        folder_path = "/" + folder_path
        if not folder_path.endswith('/'):
            folder_path += "/"

        folder = Folder.editable(request, repository, folder_path).first()
        if not folder or not folder.repository.editable(request):
            return O.error(msg="Folder %s is not editable" % folder_name)

        scr = Script(name=name,
                     owner_id=request.user.id,
                     folder=folder,
                     mime_type=mime)
        request.db.add(scr)
        request.db.commit()
        request._model_id = scr.id

        if isinstance(meta, dict):
            meta = json.dumps(meta)

        rev = Revision(content=content, script_id=scr.id,
                       meta=meta)

        request.db.add(rev)
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:32,代码来源:library.py

示例5: start

    def start(self, name, *args, **kwargs):
        kwargs = kwargs or request.json
        LOG.info("Received rebuild job [%s] from: %s" % (
            name, request.client_addr))

        if not getattr(request, "user", None):
            key = kwargs.pop('key', None)
            if not key:
                return O.error(msg="Missing auth key")

            api_key = get_api_key(key)
            if not api_key:
                return abort(401)
            request.user = cached_user(api_key.user)

        depl = request.db.query(Deployment).filter(
            Deployment.name == name).first()
        if not depl:
            return O.error(msg="Deployment '%s' not found" % depl)
        if depl.status not in ['Pending', 'Stopped']:
            return O.error(msg="Deployment must be Pending or Stopped "
                           "to be Started.")

        request.db.commit()
        task_ids = _execute(depl, env=kwargs)

        return O.success(msg="Started", task_ids=task_ids)
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:27,代码来源:execute.py

示例6: deployments

    def deployments(self, name=None, **kwargs):
        skip = ['id', 'owner_id']

        def _encode(s):
            try:
                return json.loads(s)
            except ValueError:
                return {}
        if name:
            depl = Deployment.my(request).filter(
                Deployment.name == name).first()
            if depl:
                return O.deployment(**depl.serialize(
                    skip=skip,
                    rel=[('content', 'content',
                          lambda p: _encode(p))]))
            else:
                return O.error(msg="Cannot find deployment '%s'" % name)
        else:
            depl = sorted([d.serialize(skip=skip)
                           for d in Deployment.my(request).all()],
                          key=lambda d: d['name'])
            return O._anon(deployments=depl,
                           quota=dict(allowed=request.user.tier.deployments))
        return O.none()
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:25,代码来源:deployments.py

示例7: activate

    def activate(self, **kwargs):
        if request.method != "POST":
            return O.none()
        if not kwargs:
            kwargs = request.json
        username = kwargs['user']
        key = kwargs['code']
        user = request.db.query(User).join(Org, ApiKey).filter(
            User.username == username,
            ApiKey.value == key, ApiKey.enabled == True).first()  # noqa
        if not user:
            user = request.db.query(User).join(Org, ApiKey).filter(
                User.username == username,
                User.enabled == True).first()  # noqa
            if user:
                return O.error(msg="Already enabled")
            else:
                return O.error(msg="User not found")

        user.enabled = True
        api_key = request.db.query(ApiKey).filter(ApiKey.value == key).one()
        new_key = ApiKey(user=user)

        request.db.delete(api_key)
        request.db.add(user)
        request.db.add(new_key)
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:26,代码来源:auth.py

示例8: repository_update

    def repository_update(self, name=None, **kwargs):
        new_name = kwargs.get('new_name')
        repository = Repository.own(request).filter(
            Repository.name == name).one()

        if not repository:
            return O.error("Cannot find repo")

        enabled = kwargs.get("enabled")
        if enabled and enabled in ['1', 'true', 'True']:
            repository.enabled = True
        elif not repository.editable(request):
            return O.error(msg="Cannot edit this repo")
        elif new_name:
            repository.name = new_name
        private = kwargs.get('private')
        if private:
            private = private not in ['0', 'false', 'False']
            repository.private = private

        if repository.type != 'cloudrunner':
            if kwargs.get('user'):
                repository.credentials.auth_user = kwargs.get('user')
            if kwargs.get('pass'):
                if kwargs['pass'] == '---empty---':
                    repository.credentials.auth_pass = ""
                else:
                    repository.credentials.auth_pass = kwargs.get('pass')
            if kwargs.get('args'):
                if kwargs['args'] == '---empty---':
                    repository.credentials.auth_args = ""
                else:
                    repository.credentials.auth_args = kwargs.get('args')

        request.db.add(repository)
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:35,代码来源:library.py

示例9: preview

    def preview(self, *args, **kwargs):
        if not args:
            return O.error(msg="Path not provided")
        content = kwargs['content']

        content = expand_script(content)

        return O.preview(content=content)
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:8,代码来源:library.py

示例10: repository_delete

 def repository_delete(self, *args, **kwargs):
     name = args[0]
     repository = Repository.own(request).filter(
         Repository.name == name).one()
     if not repository.removable(request):
         return O.error(msg="Cannot edit/delete this repo")
     if repository.type == "cloudrunner" and any(
         [f for f in repository.folders
             if f.name != "/" or f.full_name != "/"]):
         return O.error(msg="Cannot remove repo, "
                        "not empty")
     request.db.delete(repository)
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:12,代码来源:library.py

示例11: add_share

    def add_share(self, profile, *args, **kwargs):
        name = kwargs.get('name')
        node_quota = int(kwargs.get('node_quota', 0))
        if not name:
            return O.error(msg="Name if required")

        prof = CloudProfile.my(request).filter(
            CloudProfile.name == profile).first()
        if not prof:
            return O.error(msg="Cloud Profile '%s' not found" % profile)

        share = CloudShare(name=name, password=random_token(length=64),
                           node_quota=node_quota, profile=prof)
        request.db.add(share)
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:14,代码来源:clouds.py

示例12: restart

    def restart(self, name, *args, **kwargs):
        name = name or kwargs['name']

        depl = Deployment.my(request).filter(Deployment.name == name).first()
        if not depl:
            return O.error(msg="Cannot find deployment '%s'" % name)

        content = json.loads(depl.content)
        _validate(content)
        request.db.commit()
        depl.status = "Starting"
        task_ids = _execute(depl, **kwargs)

        return O.success(status="ok", task_ids=task_ids)
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:14,代码来源:deployments.py

示例13: repo

    def repo(self, *args, **kwargs):
        if not args:
            repos = Repository.visible(request).all()
            tier = request.user.tier
            repositories = sorted([r.serialize(
                skip=['id', 'org_id', 'owner_id', 'linked_id'],
                rel=[('owner.username', 'owner')],
                editable=lambda r: r.editable(request))
                for r in repos],
                key=lambda l: l['name'])
            return O._anon(repositories=repositories,
                           quota=dict(total=tier.total_repos,
                                      user=tier.total_repos,
                                      external=tier.external_repos == "True"))
        else:
            repo_name = args[0]
            repo = Repository.visible(request).filter(
                Repository.name == repo_name).first()

            def get_creds(repo):
                parents = [p for p in repo.parents
                           if p.org.name == request.user.org]
                if parents:
                    return dict(auth_user=parents[0].credentials.auth_user)
                else:
                    return {}

            if repo.type == 'cloudrunner':
                return O.repository(repo.serialize(
                    skip=['id', 'org_id', 'owner_id', 'linked_id'],
                    rel=[('owner.username', 'owner')],
                    editable=lambda r: r.editable(request)))
            else:
                if repo.editable(request):
                    return O.repository(repo.serialize(
                        skip=['id', 'org_id', 'owner_id', 'linked_id'],
                        rel=[('owner.username', 'owner'),
                             ('linked', 'credentials', get_creds),
                             # ('credentials.auth_user', 'key'),
                             # ('credentials.auth_pass', 'secret'),
                             # ('credentials.auth_args', 'args')
                             ],
                        editable=lambda r: True))
                else:
                    return O.repository(**repo.serialize(
                        skip=['id', 'org_id', 'owner_id', 'linked_id'],
                        rel=[('owner.username', 'owner')],
                        editable=lambda r: True))
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:48,代码来源:library.py

示例14: groups

 def groups(self, name=None, *args):
     def modifier(roles):
         return [dict(as_user=role.as_user, servers=role.servers)
                 for role in roles]
     if name:
         group = Group.visible(request).filter(Group.name == name).first()
         return O.group(group.serialize(
             skip=['id', 'org_id'],
             rel=[('roles', 'roles', modifier)]))
     else:
         groups = [u.serialize(
             skip=['id', 'org_id'],
             rel=[('roles', 'roles', modifier)])
             for u in Group.visible(request).all()]
         return O._anon(groups=groups,
                        quota=dict(allowed=request.user.tier.groups))
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:16,代码来源:groups.py

示例15: rm_group

    def rm_group(self, name, *args):
        group = Group.visible(request).filter(Group.name == name).first()
        if not group:
            return O.error(msg="Group not found")

        request.db.delete(group)
        request.db.commit()
开发者ID:CloudRunnerIO,项目名称:cloudrunner-server,代码行数:7,代码来源:groups.py


注:本文中的cloudrunner_server.api.util.JsonOutput类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。