Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 150 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# IDE
.vscode/
.idea/
*.swp
*.swo

# OS
.DS_Store
Thumbs.db

# Database
*.db
*.sqlite

# Docker
.dockerignore

#Kiro
.kiro
hiring-challenge-devops-python.*
135 changes: 135 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# Server Inventory Management API

## Overview

REST API for managing server inventory with CRUD operations. Built with FastAPI and PostgreSQL.

**Base URL**: `http://localhost:8000`

## Quick Start

```bash
# Start with Docker
docker compose up -d

# Check health
curl http://localhost:8000/health
```

## Endpoints

### Health Check
```bash
GET /health
# Response: {"status": "healthy", "database": "connected", "server_count": 5}
```

### Server Operations

| Method | Endpoint | Description |
|--------|----------|-------------|
| `POST` | `/servers` | Create server |
| `GET` | `/servers` | List all servers |
| `GET` | `/servers/{id}` | Get server by ID |
| `PUT` | `/servers/{id}` | Update server |
| `DELETE` | `/servers/{id}` | Delete server |

## Examples

### Create Server
```bash
curl -X POST http://localhost:8000/servers \
-H "Content-Type: application/json" \
-d '{
"hostname": "web-server-01",
"ip_address": "192.168.1.100",
"state": "active"
}'
```

**Response (201)**:
```json
{
"id": 1,
"hostname": "web-server-01",
"ip_address": "192.168.1.100",
"state": "active",
"created_at": "2023-12-01T10:00:00Z",
"updated_at": "2023-12-01T10:00:00Z"
}
```

### List Servers
```bash
curl http://localhost:8000/servers
```

### Get Server
```bash
curl http://localhost:8000/servers/1
```

### Update Server
```bash
curl -X PUT http://localhost:8000/servers/1 \
-H "Content-Type: application/json" \
-d '{"state": "offline"}'
```

### Delete Server
```bash
curl -X DELETE http://localhost:8000/servers/1
```

## Data Model

```json
{
"id": 1,
"hostname": "web-server-01",
"ip_address": "192.168.1.100",
"state": "active",
"created_at": "2023-12-01T10:00:00Z",
"updated_at": "2023-12-01T10:00:00Z"
}
```

**Fields**:
- `hostname`: Unique server name (1-255 chars)
- `ip_address`: Valid IPv4/IPv6 address
- `state`: `active`, `offline`, or `retired`

## Error Responses

| Code | Description | Example |
|------|-------------|---------|
| `409` | Conflict (duplicate hostname/IP) | `{"detail": "Server with hostname 'web-01' already exists"}` |
| `404` | Server not found | `{"detail": "Server not found"}` |
| `422` | Validation error | `{"detail": "Invalid IP address format"}` |

## Validation Rules

- **Hostname**: Must be unique, 1-255 characters
- **IP Address**: Must be valid IPv4 or IPv6
- **State**: Must be `active`, `offline`, or `retired` (case-sensitive)

## Interactive Documentation

- **Swagger UI**: http://localhost:8000/docs
- **ReDoc**: http://localhost:8000/redoc

## Configuration

Set via environment variables:

```bash
export DATABASE_HOST=localhost
export DATABASE_PORT=5432
export DATABASE_NAME=server_inventory
export DATABASE_USER=inventory_user
export DATABASE_PASSWORD=inventory_password
export API_HOST=0.0.0.0
export API_PORT=8000
```

For complete examples and deployment details see `COMMAND_REFERENCE.md`
Loading