Exemple #1
0
    def create(cls, *, account_name, contacts, enabled, required_roles=list(), properties=None, auto_commit=True):
        if cls.get(account_name):
            raise AccountException('Account {} already exists'.format(account_name))

        for prop in cls.class_properties:
            if prop['required'] and (prop['key'] not in properties or not properties[prop['key']]):
                raise InquisitorError('Missing required property {}'.format(prop['name'], cls.__name__))

        res = Account()
        res.account_name = account_name
        res.contacts = contacts
        res.enabled = enabled
        res.required_roles = required_roles
        res.account_type_id = AccountType.get(cls.account_type).account_type_id

        if properties:
            for name, value in properties.items():
                prop = AccountProperty()
                prop.account_id = res.account_id
                prop.name = name
                prop.value = value.isoformat() if type(value) == datetime else value
                res.properties.append(prop)
                db.session.add(prop)

        db.session.add(res)
        if auto_commit:
            db.session.commit()

        return res
Exemple #2
0
    def get_typed_account(account):
        if type(account) in (int, str):
            account = Account.get(account)

        acct_type = AccountType.get(account.account_type_id).account_type
        account_class = get_plugin_by_name(PLUGIN_NAMESPACES['accounts'], acct_type)
        return account_class.get(account['account_id'])
Exemple #3
0
    def get(account):
        """Returns the class object identified by `account_id`

        Args:
            account (`int`, `str`): Unique ID of the account to load from database

        Returns:
            `Account` object if found, else None
        """
        account = Account.get(account)
        if not account:
            return None

        acct_type = AccountType.get(account.account_type_id).account_type
        account_class = get_plugin_by_name(PLUGIN_NAMESPACES['accounts'], acct_type)

        return account_class(account)
Exemple #4
0
from cloud_inquisitor.constants import ROLE_USER, AccountTypes
from cloud_inquisitor.database import db
from cloud_inquisitor.plugins import BaseView
from cloud_inquisitor.plugins.types.accounts import AWSAccount
from cloud_inquisitor.plugins.types.issues import RequiredTagsIssue
from cloud_inquisitor.plugins.types.resources import EC2Instance
from cloud_inquisitor.schema import (Account, Resource, ResourceType,
                                     ResourceProperty, IssueProperty, Issue,
                                     IssueType, AccountType)
from cloud_inquisitor.utils import MenuItem
from cloud_inquisitor.wrappers import check_auth, rollback

reqtag_type_id = IssueType.get(RequiredTagsIssue.issue_type).issue_type_id
ec2_type_id = ResourceType.get(EC2Instance.resource_type).resource_type_id
aws_account_type_id = AccountType.get(AWSAccount.account_type).account_type_id


class StatsGet(BaseView):
    URLS = ['/api/v1/stats']
    MENU_ITEMS = [
        MenuItem('default', 'Dashboard', 'dashboard', 'dashboard', order=1)
    ]

    @rollback
    @check_auth(ROLE_USER)
    def get(self):
        rfc26 = []
        accounts = list(AWSAccount.get_all(include_disabled=False).values())
        instances_by_account = self._get_instances_by_account()
        issues_by_account = self._get_issues_by_account()