summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/services/cephx.py
blob: ccda38796119f2a69e7683c1b1608c33f43170fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# -*- coding: utf-8 -*-
from __future__ import absolute_import

from .ceph_service import CephService


class CephX(object):
    @classmethod
    def _entities_map(cls, entity_type=None):
        auth_dump = CephService.send_command("mon", "auth list")
        result = {}
        for auth_entry in auth_dump['auth_dump']:
            entity = auth_entry['entity']
            if not entity_type or entity.startswith('{}.'.format(entity_type)):
                entity_id = entity[entity.find('.')+1:]
                result[entity_id] = auth_entry
        return result

    @classmethod
    def _clients_map(cls):
        return cls._entities_map("client")

    @classmethod
    def list_clients(cls):
        return [client for client in cls._clients_map()]

    @classmethod
    def get_client_key(cls, client_id):
        return cls._clients_map()[client_id]['key']