示例#1
0
class WorkspaceAdminUtils:
    def __init__(self, config):
        wsurl = config.get('workspace-url')
        self.atoken = config.get('workspace-admin-token')
        self.noadmin = False
        if self.atoken is None or self.atoken == '':
            self.noadmin = True
            self.atoken = os.environ.get('KB_AUTH_TOKEN', None)
        self.ws = Workspace(wsurl, token=self.atoken)

    def list_objects(self, params):
        """
        Provide something that acts like a standard listObjects
        """
        if self.noadmin:
            return self.ws.list_objects(params)
        return self.ws.administer({'command': 'listObjects', 'params': params})

    def get_objects2(self, params):
        """
        Provide something that acts like a standard getObjects
        """
        if self.noadmin:
            return self.ws.get_objects2(params)
        return self.ws.administer({'command': 'getObjects', 'params': params})

    def get_workspace_info(self, params):
        """
        Provide something that acts like a standard getObjects
        """
        if self.noadmin:
            return self.ws.get_workspace_info(params)
        return self.ws.administer({
            'command': 'getWorkspaceInfo',
            'params': params
        })
示例#2
0
def get_ws_admins(ws_id, ws_url, admin_token):
    ws = Workspace(url=ws_url, token=admin_token)
    perms = ws.administer({
        "command": "getPermissionsMass",
        "params": {
            "workspaces": [{
                "id": ws_id
            }]
        }
    })['perms'][0]

    admins = list()
    for u in perms:
        if perms[u] == "a":
            admins.append(u)
    return admins