def get(self): acls_json = [] acls = AclsModel.return_all() for acl in acls: acl_part = AclsModel.to_json(acl) host_group_acls = HostGroupAclsModel.by_acl_id(acl.id) host_group = HostGroupsModel.by_id(host_group_acls.host_group_id) acl_part['host_groups'] = HostGroupsModel.to_json(host_group) user_group_acls = UserGroupAclModel.by_acl_id(acl.id) user_group = UserGroupsModel.by_id(user_group_acls.user_group_id) acl_part['user_groups'] = UserGroupsModel.to_json(user_group) acls_json.append(acl_part) return acls_json
def get(self, id): # parser = reqparse.RequestParser() # parser.add_argument('id', help='This field cannot be blank', required=True) # data = parser.parse_args() # acl = AclsModel.by_id(data['id']) acl = AclsModel.by_id(id) acl_part = AclsModel.to_json(acl) host_group_acls = HostGroupAclsModel.by_acl_id(acl.id) host_group = HostGroupsModel.by_id(host_group_acls.host_group_id) acl_part['host_groups'] = HostGroupsModel.to_json(host_group) user_group_acls = UserGroupAclModel.by_acl_id(acl.id) user_group = UserGroupsModel.by_id(user_group_acls.user_group_id) acl_part['user_groups'] = UserGroupsModel.to_json(user_group) return acl_part
def get(self, name): host_group = HostGroupsModel.by_name(name) host_groups_part = HostGroupsModel.to_json(host_group) host_group_acls = HostGroupAclsModel.by_host_group_id(host_group.id) host_groups_part['acls'] = [] for hgacls in host_group_acls: acl = AclsModel.by_id(hgacls.acl_id) host_groups_part['acls'].append(AclsModel.to_json(acl)) host_host_groups = HostHostGroupsModel.by_host_group_id(host_group.id) host_groups_part['hosts'] = [] for hhg in host_host_groups: host = HostsModel.by_id(hhg.host_id) host_groups_part['hosts'].append( HostsModel.to_json(host) if host else None) return host_groups_part
def get(self, name): usergroup = UserGroupsModel.by_name(name) usergroups_part = UserGroupsModel.to_json(usergroup) userusergroups = UserUserGroupsModel.by_user_group_id(usergroup.id) usergroups_part['users'] = [] for uug in userusergroups: user = UserModel.by_id(uug.user_id) usergroups_part['users'].append(UserModel.to_json(user)) usergroupacls = UserGroupAclModel.by_user_group_id(usergroup.id) usergroups_part['acls'] = [] for uga in usergroupacls: acl = AclsModel.by_id(uga.acl_id) usergroups_part['acls'].append(AclsModel.to_json(acl)) return usergroups_part
def get(self): users = UserModel.return_all() groups = UserGroupsModel.return_all() roles = UserRolesModel.return_all() keys = SshKeysModel.return_all() userkeys = UserKeysModel.return_all() hosts = HostsModel.return_all() hostgroups = HostGroupsModel.return_all() acls = AclsModel.return_all() sessions = SessionsModel.return_all() events = EventsModel.return_all() return { 'users': { 'count': len(users['users']) }, 'usergroups': { 'count': len(groups) }, 'userroles': { 'count': len(roles) }, 'keys': { 'count': len(keys) }, 'userkeys': { 'count': len(userkeys) }, 'hosts': { 'count': len(hosts), 'keys': len(list(set([x.ssh_key_id for x in hosts]))) }, 'hostgroups': { 'count': len(hostgroups) }, 'acls': { 'count': len(acls), 'allow': len([x for x in acls if x.action == 'allow']), }, 'sessions': { 'count': len(sessions), 'active': len([s for s in sessions if s.status != 'closed']), 'errors': len([s for s in sessions if s.err_msg != '']) }, 'events': { 'count': len(events), 'last_5': list(reversed([EventsModel.to_json(x) for x in events[-5:]])) } }