Skip to content

Commit a443f9d

Browse files
committed
Inittial commit
0 parents  commit a443f9d

36 files changed

+1038
-0
lines changed

.coveragerc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[run]
2+
branch = True
3+
omit = *migrations*,
4+
*urls*,
5+
*test*,
6+
*admin*,
7+
./manage.py,
8+
./vbos/config/*,
9+
./vbos/wsgi.py,
10+
*__init__*

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.*
2+
!.coveragerc
3+
!.env

.gitignore

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
MANIFEST
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*.cover
47+
.hypothesis/
48+
49+
# Translations
50+
*.mo
51+
*.pot
52+
53+
# Django stuff:
54+
*.log
55+
.static_storage/
56+
.media/
57+
local_settings.py
58+
59+
# Flask stuff:
60+
instance/
61+
.webassets-cache
62+
63+
# Scrapy stuff:
64+
.scrapy
65+
66+
# Sphinx documentation
67+
docs/_build/
68+
69+
# PyBuilder
70+
target/
71+
72+
# Jupyter Notebook
73+
.ipynb_checkpoints
74+
75+
# pyenv
76+
.python-version
77+
78+
# celery beat schedule file
79+
celerybeat-schedule
80+
81+
# SageMath parsed files
82+
*.sage.py
83+
84+
# Environments
85+
.env
86+
.venv
87+
env/
88+
venv/
89+
ENV/
90+
env.bak/
91+
venv.bak/
92+
93+
# Spyder project settings
94+
.spyderproject
95+
.spyproject
96+
97+
# Rope project settings
98+
.ropeproject
99+
100+
# mkdocs documentation
101+
/site
102+
103+
# django staticfiles
104+
/static
105+
106+
# mypy
107+
.mypy_cache/

Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM python:3.13-slim as base
2+
FROM base as builder
3+
4+
# Allows docker to cache installed dependencies between builds
5+
RUN apt-get update && apt-get -y install libpq-dev gcc
6+
COPY ./requirements.txt requirements.txt
7+
RUN pip3 install --no-cache-dir --target=packages -r requirements.txt
8+
9+
FROM base as runtime
10+
COPY --from=builder packages /usr/lib/python3.12/site-packages
11+
ENV PYTHONPATH=/usr/lib/python3.12/site-packages
12+
13+
# Security Context
14+
RUN useradd -m nonroot
15+
USER nonroot
16+
17+
COPY . code
18+
WORKDIR code
19+
20+
EXPOSE 8000
21+
# Run the production server
22+
CMD gunicorn --bind 0.0.0.0:$PORT --access-logfile - vbos.wsgi:application

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# vbos-backend
2+
3+
[![Build Status](https://travis-ci.org/developmentseed/vbos-backend.svg?branch=master)](https://travis-ci.org/developmentseed/vbos-backend)
4+
[![Built with](https://img.shields.io/badge/Built_with-Cookiecutter_Django_Rest-F7B633.svg)](https://github.com/agconti/cookiecutter-django-rest)
5+
6+
VBOS Django application and data services. Check out the project's [documentation](http://developmentseed.github.io/vbos-backend/).
7+
8+
# Prerequisites
9+
10+
- [Docker](https://docs.docker.com/docker-for-mac/install/)
11+
12+
# Local Development
13+
14+
Start the dev server for local development:
15+
```bash
16+
docker-compose up
17+
```
18+
19+
Run a command inside the docker container:
20+
21+
```bash
22+
docker-compose run --rm web [command]
23+
```

conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pytest
2+
3+
# Ensures pytest waits for the database to load
4+
# https://pytest-django.readthedocs.io/en/latest/faq.html#how-can-i-give-database-access-to-all-my-tests-without-the-django-db-marker
5+
@pytest.fixture(autouse=True)
6+
def enable_db_access_for_all_tests(db):
7+
pass

docker-compose.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
services:
2+
postgres:
3+
environment:
4+
- POSTGRES_USER=postgres
5+
- POSTGRES_PASSWORD=postgres
6+
- POSTGRES_HOST=postgres
7+
- POSTGRES_DB=vbos
8+
image: postgis/postgis:17-3.5
9+
platform: linux/x86_64
10+
restart: always
11+
healthcheck:
12+
test: ["CMD-SHELL", "pg_isready -U postgres"]
13+
interval: 10s
14+
timeout: 10s
15+
retries: 5
16+
web:
17+
restart: always
18+
environment:
19+
- DJANGO_SECRET_KEY=local
20+
build: ./
21+
command: >
22+
bash -c "python3 wait_for_postgres.py &&
23+
./manage.py migrate &&
24+
./manage.py runserver 0.0.0.0:8000"
25+
volumes:
26+
- ./:/code
27+
ports:
28+
- "8000:8000"
29+
depends_on:
30+
- postgres
31+
documentation:
32+
restart: always
33+
build: ./
34+
command: "python3 -m mkdocs serve"
35+
volumes:
36+
- ./:/code
37+
ports:
38+
- "8001:8001"

docs/api/authentication.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Authentication
2+
For clients to authenticate, the token key should be included in the Authorization HTTP header. The key should be prefixed by the string literal "Token", with whitespace separating the two strings. For example:
3+
4+
```
5+
Authorization: Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b
6+
```
7+
8+
Unauthenticated responses that are denied permission will result in an HTTP `401 Unauthorized` response with an appropriate `WWW-Authenticate` header. For example:
9+
10+
```
11+
WWW-Authenticate: Token
12+
```
13+
14+
The curl command line tool may be useful for testing token authenticated APIs. For example:
15+
16+
```bash
17+
curl -X GET http://127.0.0.1:8000/api/v1/example/ -H 'Authorization: Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b'
18+
```
19+
20+
## Retrieving Tokens
21+
Authorization tokens are issued and returned when a user registers. A registered user can also retrieve their token with the following request:
22+
23+
**Request**:
24+
25+
`POST` `api-token-auth/`
26+
27+
Parameters:
28+
29+
Name | Type | Description
30+
---|---|---
31+
username | string | The user's username
32+
password | string | The user's password
33+
34+
**Response**:
35+
```json
36+
{
37+
"token" : "9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b"
38+
}
39+
```

docs/api/users.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Users
2+
Supports registering, viewing, and updating user accounts.
3+
4+
## Register a new user account
5+
6+
**Request**:
7+
8+
`POST` `/users/`
9+
10+
Parameters:
11+
12+
Name | Type | Required | Description
13+
-----------|--------|----------|------------
14+
username | string | Yes | The username for the new user.
15+
password | string | Yes | The password for the new user account.
16+
first_name | string | No | The user's given name.
17+
last_name | string | No | The user's family name.
18+
email | string | No | The user's email address.
19+
20+
*Note:*
21+
22+
- Not Authorization Protected
23+
24+
**Response**:
25+
26+
```json
27+
Content-Type application/json
28+
201 Created
29+
30+
{
31+
"id": "6d5f9bae-a31b-4b7b-82c4-3853eda2b011",
32+
"username": "richard",
33+
"first_name": "Richard",
34+
"last_name": "Hendriks",
35+
"email": "[email protected]",
36+
"auth_token": "132cf952e0165a274bf99e115ab483671b3d9ff6"
37+
}
38+
```
39+
40+
The `auth_token` returned with this response should be stored by the client for
41+
authenticating future requests to the API. See [Authentication](authentication.md).
42+
43+
44+
## Get a user's profile information
45+
46+
**Request**:
47+
48+
`GET` `/users/:id`
49+
50+
Parameters:
51+
52+
*Note:*
53+
54+
- **[Authorization Protected](authentication.md)**
55+
56+
**Response**:
57+
58+
```json
59+
Content-Type application/json
60+
200 OK
61+
62+
{
63+
"id": "6d5f9bae-a31b-4b7b-82c4-3853eda2b011",
64+
"username": "richard",
65+
"first_name": "Richard",
66+
"last_name": "Hendriks",
67+
"email": "[email protected]",
68+
}
69+
```
70+
71+
72+
## Update your profile information
73+
74+
**Request**:
75+
76+
`PUT/PATCH` `/users/:id`
77+
78+
Parameters:
79+
80+
Name | Type | Description
81+
-----------|--------|---
82+
first_name | string | The first_name of the user object.
83+
last_name | string | The last_name of the user object.
84+
email | string | The user's email address.
85+
86+
87+
88+
*Note:*
89+
90+
- All parameters are optional
91+
- **[Authorization Protected](authentication.md)**
92+
93+
**Response**:
94+
95+
```json
96+
Content-Type application/json
97+
200 OK
98+
99+
{
100+
"id": "6d5f9bae-a31b-4b7b-82c4-3853eda2b011",
101+
"username": "richard",
102+
"first_name": "Richard",
103+
"last_name": "Hendriks",
104+
"email": "[email protected]",
105+
}
106+
```

docs/index.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# vbos-backend
2+
3+
[![Build Status](https://travis-ci.org/developmentseed/vbos-backend.svg?branch=master)](https://travis-ci.org/developmentseed/vbos-backend)
4+
[![Built with](https://img.shields.io/badge/Built_with-Cookiecutter_Django_Rest-F7B633.svg)](https://github.com/agconti/cookiecutter-django-rest)
5+
6+
VBOS Django application and data services. Check out the project's [documentation](http://developmentseed.github.io/vbos-backend/).
7+
8+
# Prerequisites
9+
10+
- [Docker](https://docs.docker.com/docker-for-mac/install/)
11+
12+
# Initialize the project
13+
14+
Start the dev server for local development:
15+
16+
```bash
17+
docker-compose up
18+
```
19+
20+
Create a superuser to login to the admin:
21+
22+
```bash
23+
docker-compose run --rm web ./manage.py createsuperuser
24+
```

0 commit comments

Comments
 (0)