示例#1
0
    def create_account(self, username, password):

        account = self.Account(username=username)
        account.set_password(password)

        session = self.Session()
        session.add(account)
        session.commit()

        return Account(id=account.id)
示例#2
0
文件: api.py 项目: epuzanov/OpenTAXII
 def _user_to_account(self, user, roles, tags):
     log.info("TRACE: _user_to_account")
     role = roles[user["role_id"]]
     account = AccountEntity(
         id=user["id"],
         username=user["email"],
         is_admin=role["perm_site_admin"],
         permissions={})
     if role["perm_auth"]:
         if role["perm_sighting"]:
             perm = "modify"
         else:
             perm = "read"
         account.permissions["default"] = perm
         for tag in tags:
             if (role["perm_site_admin"] or (role["perm_admin"]
                     and tag["org_id"] in ('0', user["org_id"]))
                     or (tag["org_id"] in ('0', user["org_id"])
                     and tag["user_id"] in ('0', user["id"]))):
                 collection_id = tag["name"][17:].strip('"')
                 account.permissions[collection_id] = perm
     return account
示例#3
0
    def get_account(self, token):

        account_id = self._get_account_id(token)

        if not account_id:
            return

        account = self.Account.query.get(account_id)

        if not account:
            return

        return Account(id=account.id)
示例#4
0
import argparse
import structlog
import yaml

from opentaxii.entities import Account
from opentaxii.cli import app
from opentaxii.local import context
from opentaxii.utils import sync_conf_dict_into_db

log = structlog.getLogger(__name__)

local_admin = Account(id=None,
                      username="******",
                      permissions=None,
                      is_admin=True)


def sync_data_configuration():
    parser = argparse.ArgumentParser(
        description="Create services/collections/accounts",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument("config", help="YAML file with data configuration")
    parser.add_argument(
        "-f",
        "--force-delete",
        dest="force_deletion",
        action="store_true",
        help=("force deletion of collections and their content blocks "
              "if collection is not defined in configuration file"),
        required=False)
    args = parser.parse_args()
示例#5
0
文件: auth.py 项目: s-tip/stip-txs
 def authenticate(self, username, api_key):
     stip_user = auth_by_api_key(username, api_key)
     if stip_user is None:
         return
     return Account(id=stip_user.id, username=stip_user.username)
示例#6
0
 def authenticate(self, username, password):
     stip_user = django.contrib.auth.authenticate(username=username,
                                                  password=password)
     if stip_user is None:
         return
     return Account(id=stip_user.id, username=stip_user.username)