Ejemplo n.º 1
0
 def downloadFile(self, user, fileId):
     headers = getHeaders(user=user)
     url = url_join(configService.getHost(), "/api/generic/file/download",
                    str(fileId))
     response = requestService.post(url, headers=headers)
     rawData = requestService.get(json.loads(
         response.content)["signed_url"],
                                  headers=None).content
     return rawData
Ejemplo n.º 2
0
def ping():
    """
    Ping the API.

    """
    headers = getHeaders()

    url = url_join(configService.getHost(), 'ping')
    response = requestService.get(url, headers=headers)

    return json.loads(response.content)
Ejemplo n.º 3
0
    def getEntities(self, user, entityClass, count, filterParams={}):
        countParameter = min(count, 50) if count is not None else None
        searchParams = {"search": 1, "cursor": -1, "count": countParameter}

        params = {**searchParams, **filterParams}

        headers = getHeaders(user=user)
        url = url_join(configService.getHost(), "/api/generic/",
                       entityClass.__entityName__)
        response = requestService.get(url, params=params, headers=headers)
        resp = json.loads(response.content)
        items = resp["items"]
        expectedResults = min(resp["total"],
                              count) if count is not None else resp["total"]
        while len(items) < expectedResults:
            params["cursor"] = resp["next_cursor"]
            response = requestService.get(url, headers=headers, params=params)
            resp = json.loads(response.content)
            items.extend(resp["items"])
        return listToClass(items, entityClass, user)
Ejemplo n.º 4
0
 def getPermissions(self, entity):
     entityName = entity.__entityName__
     headers = getHeaders(entity.__user__)
     url = url_join(
         configService.getHost(),
         "api/generic/",
         "acl",
         entityName.replace("-", "_"),
         str(entity.id),
     )
     response = requestService.get(url, headers=headers)
     resp = json.loads(response.content)
     return listToClass(resp["group_permissions"], Permission, entity)
Ejemplo n.º 5
0
    def getEntity(self, user, entityClass, id, isDeleted="both"):
        if getattr(entityClass, "__isLegacy__", None):
            return self.getLegacyEntity(user, entityClass, id)

        identifier = 'guid' if getattr(entityClass, "__hasGuid__",
                                       None) else 'id'

        params = {"is_deleted": isDeleted, "get_single": 1, identifier: id}

        headers = getHeaders(user=user)
        url = url_join(configService.getHost(), "/api/generic/",
                       entityClass.__entityName__)
        response = requestService.get(url, headers=headers, params=params)
        return entityClass(json.loads(response.content), user)
Ejemplo n.º 6
0
 def authenticate(self, username, apikey):
     url = url_join(configService.getHost(), "api/generic/user/info")
     response = requestService.get(url, headers={"apikey": apikey})
     user = json.loads(response.content)
     user["api_key"] = apikey
     return User(user)
Ejemplo n.º 7
0
 def getUser(self, username, apikey):
     url = url_join(configService.getHost(), f"api/generic/user/{username}")
     response = requestService.get(url, headers={"apikey": apikey})
     user = json.loads(response.content)
     return User(user)
Ejemplo n.º 8
0
 def getLegacyEntity(self, user, entityClass, id):
     headers = getHeaders(user=user)
     url = url_join(configService.getHost(), "/api/generic/",
                    entityClass.__entityName__, str(id))
     response = requestService.get(url, headers=headers)
     return entityClass(json.loads(response.content), user)