Exemplo n.º 1
0
    async def landing_page(self, **kwargs) -> ORJSONResponse:
        """Landing page.

        Called with `GET /`.

        Returns:
            API landing page, serving as an entry point to the API.
        """
        request = kwargs["request"]
        base_url = str(request.base_url)
        landing_page = LandingPage(
            title="Arturo STAC API",
            description="Arturo raster datastore",
            links=[
                Link(
                    rel=Relations.self,
                    type=MimeTypes.json,
                    href=str(base_url),
                ),
                Link(
                    rel=Relations.docs,
                    type=MimeTypes.html,
                    title="OpenAPI docs",
                    href=urljoin(base_url, "/docs"),
                ),
                Link(
                    rel=Relations.conformance,
                    type=MimeTypes.json,
                    title=
                    "STAC/WFS3 conformance classes implemented by this server",
                    href=urljoin(base_url, "/conformance"),
                ),
                Link(
                    rel=Relations.search,
                    type=MimeTypes.geojson,
                    title="STAC search",
                    href=urljoin(base_url, "/search"),
                ),
                Link(
                    rel="data",
                    type=MimeTypes.json,
                    href=urljoin(base_url, "/collections"),
                ),
            ],
        )
        collections = await self._all_collections_func(request=request)
        if collections:
            for coll in collections:
                coll_link = CollectionLinks(collection_id=coll.id,
                                            request=request).link_self()
                coll_link.rel = Relations.child
                coll_link.title = coll.title
                landing_page.links.append(coll_link)
        return ORJSONResponse(landing_page.dict(exclude_none=True))
Exemplo n.º 2
0
    def landing_page(self, **kwargs) -> LandingPage:
        """Landing page.

        Called with `GET /`.

        Returns:
            API landing page, serving as an entry point to the API.
        """
        base_url = str(kwargs["request"].base_url)
        landing_page = LandingPage(
            id=self.landing_page_id,
            title=self.title,
            description=self.description,
            stac_version=self.stac_version,
            links=[
                Link(
                    rel=Relations.self,
                    type=MimeTypes.json,
                    href=base_url,
                ),
                Link(
                    rel="data",
                    type=MimeTypes.json,
                    href=urljoin(base_url, "collections"),
                ),
                Link(
                    rel=Relations.docs,
                    type=MimeTypes.html,
                    title="OpenAPI docs",
                    href=urljoin(str(base_url), "docs"),
                ),
                Link(
                    rel=Relations.conformance,
                    type=MimeTypes.json,
                    title=
                    "STAC/WFS3 conformance classes implemented by this server",
                    href=urljoin(str(base_url), "conformance"),
                ),
                Link(
                    rel=Relations.search,
                    type=MimeTypes.geojson,
                    title="STAC search",
                    href=urljoin(str(base_url), "search"),
                ),
            ],
        )
        collections = self.all_collections(request=kwargs["request"])
        for coll in collections:
            coll_link = CollectionLinks(collection_id=coll.id,
                                        base_url=str(base_url)).self()
            coll_link.rel = Relations.child
            coll_link.title = coll.title
            landing_page.links.append(coll_link)
        return landing_page
Exemplo n.º 3
0
 def collection(self) -> Link:
     """Create the `collection` link."""
     return Link(
         rel=Relations.collection,
         type=MimeTypes.json,
         href=urljoin(self.base_url, f"/collections/{self.collection_id}"),
     )
Exemplo n.º 4
0
def test_api_paging_extension():
    item_collection = request(ITEM_COLLECTION)
    item_collection["links"] += [
        {
            "title": "next page",
            "rel": "next",
            "method": "GET",
            "href": "http://next"
        },
        {
            "title": "previous page",
            "rel": "previous",
            "method": "POST",
            "href": "http://prev",
            "body": {
                "key": "value"
            },
        },
    ]
    model = ItemCollection(**item_collection)
    links = model.to_dict()["links"]

    # Make sure we can mix links and pagination links
    normal_link = Link(**links[0])
    assert normal_link.rel == "self"
    next_link = PaginationLink(**links[1])
    assert next_link.rel == "next"
    previous_link = PaginationLink(**links[2])
    assert previous_link.rel == "previous"
    assert previous_link.body == {"key": "value"}
Exemplo n.º 5
0
 def link_items(self) -> Link:
     """Create the `item` link."""
     return Link(
         rel="items",
         type=MimeTypes.geojson,
         href=self.resolve(f"/collections/{self.collection_id}/items"),
     )
Exemplo n.º 6
0
 def link_parent(self) -> Link:
     """Create the `parent` link."""
     return Link(
         rel=Relations.parent,
         type=MimeTypes.json,
         href=self.base_url,
     )
Exemplo n.º 7
0
 def collection_link(self, rel=Relations.collection) -> Link:
     """Create a link to a collection."""
     return Link(
         rel=rel,
         type=MimeTypes.json,
         href=self.resolve(f"/collections/{self.collection_id}"),
     )
Exemplo n.º 8
0
 def item(self) -> Link:
     """Create the `item` link."""
     return Link(
         rel=Relations.item,
         type=MimeTypes.geojson,
         href=urljoin(self.base_url, f"/collections/{self.collection_id}/items"),
     )
Exemplo n.º 9
0
 def link_self(self) -> Link:
     """Create the self link."""
     return Link(
         rel=Relations.self,
         type=MimeTypes.geojson,
         href=self.resolve(
             f"/collections/{self.collection_id}/items/{self.item_id}"),
     )
Exemplo n.º 10
0
def test_api_landing_page():
    LandingPage(
        description="stac-api landing page",
        stac_extensions=["eo", "proj"],
        links=[Link(
            href="http://link",
            rel="self",
        )],
    )
Exemplo n.º 11
0
 def link_tiles(self) -> Link:
     """Create the `tiles` link."""
     return Link(
         rel=Relations.alternate,
         type=MimeTypes.json,
         title="tiles",
         href=self.resolve(
             f"/collections/{self.collection_id}/items/{self.item_id}/tiles",
         ),
     )
Exemplo n.º 12
0
 def landing_page(self, **kwargs) -> LandingPage:
     """Landing page."""
     landing_page = LandingPage(
         title="Arturo STAC API",
         description="Arturo raster datastore",
         links=[
             Link(
                 rel=Relations.self,
                 type=MimeTypes.json,
                 href=str(kwargs["request"].base_url),
             ),
             Link(
                 rel=Relations.docs,
                 type=MimeTypes.html,
                 title="OpenAPI docs",
                 href=urljoin(str(kwargs["request"].base_url), "/docs"),
             ),
             Link(
                 rel=Relations.conformance,
                 type=MimeTypes.json,
                 title=
                 "STAC/WFS3 conformance classes implemented by this server",
                 href=urljoin(str(kwargs["request"].base_url),
                              "/conformance"),
             ),
             Link(
                 rel=Relations.search,
                 type=MimeTypes.geojson,
                 title="STAC search",
                 href=urljoin(str(kwargs["request"].base_url), "/search"),
             ),
         ],
     )
     collections = self.all_collections(request=kwargs["request"])
     for coll in collections:
         coll_link = CollectionLinks(
             collection_id=coll.id,
             base_url=str(kwargs["request"].base_url)).self()
         coll_link.rel = Relations.child
         coll_link.title = coll.title
         landing_page.links.append(coll_link)
     return landing_page
Exemplo n.º 13
0
 def tiles(self) -> Link:
     """Create the `tiles` link"""
     return Link(
         rel=Relations.alternate,
         type=MimeTypes.json,
         title="tiles",
         href=urljoin(
             self.base_url,
             f"/collections/{self.collection_id}/items/{self.item_id}/tiles",
         ),
     )
Exemplo n.º 14
0
 def root(self) -> Link:
     """Return the catalog root"""
     return Link(rel=Relations.root,
                 type=MimeTypes.json,
                 href=urljoin(self.base_url, "/"))
Exemplo n.º 15
0
 def link_root(self) -> Link:
     """Return the catalog root."""
     return Link(rel=Relations.root,
                 type=MimeTypes.json,
                 href=self.base_url)
Exemplo n.º 16
0
 def link_self(self) -> Link:
     """Return the self link."""
     return Link(rel=Relations.self, type=MimeTypes.json, href=self.url)