Example #1
0
    async def _getAuthToken(self, realm: URL, service: str) -> None:
        """
        Obtain an authorization token from the registry.
        """
        # See https://docs.docker.com/registry/spec/auth/token/

        url = realm.set("service", service)

        self.log.info("Authenticating at {url}...", url=url)

        response = await self._httpGET(url)
        json = await response.json()

        try:
            self._auth.token = json["token"]
        except KeyError:
            raise ProtocolError(realm, "got auth response with no token")
def redirect(
    request: IRequest, location: URL, origin: Optional[str] = None
) -> KleinRenderable:
    """
    Perform a redirect.
    """
    if origin is not None:
        try:
            location = location.set(origin, request.uri.decode("utf-8"))
        except ValueError:
            return badRequestResponse(request, "Invalid origin URI")

    log.debug(
        "Redirect {source} -> {destination}",
        source=request.uri.decode("utf-8"), destination=location.asText(),
    )
    url = location.asText().encode("utf-8")

    request.setHeader(HeaderName.contentType.value, ContentType.html.value)
    request.setHeader(HeaderName.location.value, url)
    request.setResponseCode(http.FOUND)

    return RedirectPage(location=location)
Example #3
0
def redirect(request: IRequest,
             location: URL,
             origin: Optional[str] = None) -> KleinRenderable:
    """
    Perform a redirect.
    """
    if origin is not None:
        try:
            location = location.set(origin, request.uri.decode("utf-8"))
        except ValueError:
            return badRequestResponse(request, "Invalid origin URI")

    log.debug(
        "Redirect {source} -> {destination}",
        source=request.uri.decode("utf-8"),
        destination=location.asText(),
    )
    url = location.asText().encode("utf-8")

    request.setHeader(HeaderName.contentType.value, ContentType.html.value)
    request.setHeader(HeaderName.location.value, url)
    request.setResponseCode(http.FOUND)

    return RedirectPage(location)