Skip to content

Commit

Permalink
Rootpath fix (#16)
Browse files Browse the repository at this point in the history
resolves #15

and sets the analysed url as env var

correct values are:

OGCAPI_URL=https://soilwise-he.containers.wur.nl/cat/
OGCAPI_COLLECTION=metadata:main
  • Loading branch information
pvgenuchten authored Jun 14, 2024
1 parent 7bde6bb commit 571fc28
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
__pycache__/
.env
.env
/bin/
/include/
/lib/
/pyvenv.cfg
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ RUN apt-get update && apt-get install --yes \

RUN adduser --uid 1000 --gecos '' --disabled-password linky

ENV OGCAPI_URL=http://localhost
ENV OGCAPI_COLLECTION=metadata:main
ENV ROOTPATH=/
ENV POSTGRES_HOST=host.docker.internal
ENV POSTGRES_PORT=5432
ENV POSTGRES_DB=postgres
Expand Down
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ The benefit of latter is that it provides more information then a simple ping to

OGC is in the process of adopting the [OGC API - Records](https://github.com/opengeospatial/ogcapi-records) specification. A standardised API to interact with Catalogues. The specification includes a datamodel for metadata. This tool assesses the linkage section of any record in an OGC API - Records.

Set the endpoint to be analysed as 2 environment variables

```
export OGCAPI_URL=https://soilwise-he.containers.wur.nl/cat/
export OGCAPI_COLLECTION=metadata:main
```

## Source Code Brief Desrciption

Expand All @@ -49,11 +55,21 @@ More specifically the following parameters must be specified

## API
The api.py file creates a FastAPI in order to retrieve links statuses.
Run the command below
* python -m uvicorn api:app --reload --host 0.0.0.0 --port 8000
Run the command below:
```
python -m uvicorn api:app --reload --host 0.0.0.0 --port 8000
```
To view the service of the FastAPI on [http://127.0.0.1:8000/docs]

# Docker
## Deploy `linky` at a path

You can set `ROOTPATH` env var to run the api at a path (default is at root)

```
export ROOTPATH=/linky
```

## Docker
A Docker instance must be running for the linkchecker command to work.

## CI/CD
Expand Down
3 changes: 2 additions & 1 deletion src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
database = Database(DATABASE_URL)

# FastAPI app instance
app = FastAPI()
rootpath=os.environ.get("ROOTPATH") or "/"
app = FastAPI(root_path=rootpath)

# Define response model
class StatusResponse(BaseModel):
Expand Down
9 changes: 5 additions & 4 deletions src/linkchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@

# base catalog

base = "https://soilwise-he.containers.wur.nl/cat/"
base = os.environ.get("OGCAPI_URL") or "https://demo.pycsw.org/gisdata"
collection = os.environ.get("OGCAPI_COLLECTION") or "metadata:main"

# Remove comment'
catalogue_json_url = base + "collections/metadata:main/items?f=json"
catalogue_json_url = base + "collections/" + collection + "/items?f=json"

def setup_database():
# Connect to the database
Expand Down Expand Up @@ -132,7 +133,7 @@ def main():
total_pages, numbers_returned = get_pagination_info(catalogue_json_url)

# Base URL
base_url = base + 'collections/metadata:main/items?offset='
base_url = base + 'collections/' + collection + '/items?offset='

# Generate URLs for each page
urls = [base_url + str(i * numbers_returned) + "&f=html" for i in range(total_pages)]
Expand All @@ -146,7 +147,7 @@ def main():

# Define the formats to be removed
formats_to_remove = [
'collections/metadata:main/items?offset',
'collections/' + collection + '/items?offset',
'?f=json'
]

Expand Down

0 comments on commit 571fc28

Please sign in to comment.