Esempio n. 1
0
    def handle(self, *args, **options):
        nrc_client = NotificationsConfig.get_client()

        kanaal_name = "test"
        Kanaal(kanaal_name, "test")

        data = {
            "kanaal": kanaal_name,
            "hoofdObject": "https://example.com",
            "resource": "test",
            "resourceUrl": "https://example.com",
            "actie": "create",
            "aanmaakdatum": "2019-01-01T12:00:00Z",
            "kenmerken": {},
        }

        try:
            nrc_client.create("notificaties", data)
            self.stdout.write(
                self.style.SUCCESS(
                    f"Notification successfully sent to {nrc_client.base_url}!"
                ))
        except Exception as e:
            self.stdout.write(
                self.style.ERROR(
                    f"Something went wrong while sending the notification to {nrc_client.base_url}"
                ))
            raise CommandError(e)
Esempio n. 2
0
def _test_nrc_config() -> list:
    if not apps.is_installed("vng_api_common.notifications"):
        return []

    from vng_api_common.notifications.models import NotificationsConfig

    nrc_config = NotificationsConfig.get_solo()

    nrc_client = NotificationsConfig.get_client()

    has_nrc_auth = nrc_client.auth is not None

    checks = [
        (_("NRC"), nrc_config.api_root, nrc_config.api_root.endswith("/")),
        (
            _("Credentials for NRC"),
            _("Configured") if has_nrc_auth else _("Missing"),
            has_nrc_auth,
        ),
    ]

    # check if permissions in AC are fine
    if has_nrc_auth:
        error = False

        try:
            nrc_client.list("kanaal")
        except requests.ConnectionError:
            error = True
            message = _("Could not connect with NRC")
        except ClientError as exc:
            error = True
            message = _(
                "Cannot retrieve kanalen: HTTP {status_code} - {error_code}"
            ).format(status_code=exc.args[0]["status"],
                     error_code=exc.args[0]["code"])
        else:
            message = _("Can retrieve kanalen")

        checks.append(
            (_("NRC connection and authorizations"), message, not error))

    return checks