Exemplo n.º 1
0
    def create(self, data: dict) -> dict:
        concept = {}

        try:
            concept["title"] = data["title"]
        except KeyError:
            raise SuperdeskApiError.badRequestError(
                "[{name}] missing title when creating tag: {data}".format(name=self.name, data=data)
            )

        sd_type = data.get("type", "subject")
        try:
            concept["type"] = self.convept_map_inv[sd_type]
        except KeyError:
            logger.warning("no mapping for superdesk type {sd_type!r}".format(sd_type=sd_type))
            concept["type"] = "topic"

        r_data = self._request("concept/create", concept)

        if r_data["error"]:
            raise SuperdeskApiError.proxyError(
                "iMatrics concept creation failed: {msg}".format(msg=r_data.get("response", ""))
            )

        return {}
Exemplo n.º 2
0
 def _request(self, service, data=None, method="POST", params=None):
     url = urljoin(self.base_url, service)
     r = requests.request(method, url, json=data, auth=(self.user, self.key), params=params, timeout=TIMEOUT)
     if r.status_code != 200:
         raise SuperdeskApiError.proxyError(
             "Unexpected return code ({status_code}) from {name}: {msg}".format(
                 name=self.name,
                 status_code=r.status_code,
                 msg=r.text,
             )
         )
     return r.json()
Exemplo n.º 3
0
def revoke_google_token(token_id: ObjectId) -> None:
    """Revoke a token"""
    token, session = _get_token_and_sesion(token_id)
    oauth2_token_service = superdesk.get_resource_service("oauth2_token")
    resp = session.revoke_token(REVOKE_ENDPOINT, token["access_token"])
    if not resp.ok:
        raise SuperdeskApiError.proxyError(
            f"Can't revoke token {token_id} (HTTP status {resp.status_code}): {resp.text}"
        )
    oauth2_token_service.delete({config.ID_FIELD: token_id})
    ingest_providers_service = superdesk.get_resource_service("ingest_providers")
    provider = ingest_providers_service.find_one(req=None, _id=token_id)
    if provider is not None:
        ingest_providers_service.update(provider[config.ID_FIELD], updates={"config.email": None}, original=provider)
    logger.info(f"OAUTH token {token_id!r} has been revoked")