Compare commits

..

2 commits

Author SHA1 Message Date
Csaba 797eff5b2a Change bearer token expiry to 1 week
All checks were successful
Amarillo/amarillo-gitea/amarillo-core/pipeline/head This commit looks good
2024-05-22 14:53:10 +02:00
Csaba b9b47dfc2a Updated Jenkinfile to use grfs-exporter
All checks were successful
Amarillo/amarillo-gitea/amarillo-core/pipeline/head This commit looks good
2024-04-22 15:06:02 +02:00
5 changed files with 5 additions and 30 deletions

2
Jenkinsfile vendored
View file

@ -7,7 +7,7 @@ pipeline {
DOCKER_REGISTRY_URL = 'https://git.gerhardt.io'
OWNER = 'amarillo'
IMAGE_NAME = 'amarillo'
AMARILLO_DISTRIBUTION = '0.1'
AMARILLO_DISTRIBUTION = '0.2'
TAG = "${AMARILLO_DISTRIBUTION}.${BUILD_NUMBER}"
PLUGINS = 'amarillo-metrics amarillo-enhancer amarillo-grfs-exporter'
DEPLOY_WEBHOOK_URL = 'http://amarillo.mfdz.de:8888/mitanand'

View file

@ -5,8 +5,7 @@ import os.path
import re
from glob import glob
from fastapi import APIRouter, Body, HTTPException, status, Depends, BackgroundTasks
import requests
from fastapi import APIRouter, Body, HTTPException, status, Depends
from datetime import datetime
from amarillo.models.Carpool import Carpool
@ -14,8 +13,6 @@ from amarillo.models.User import User
from amarillo.services.oauth2 import get_current_user, verify_permission
from amarillo.tests.sampledata import examples
from amarillo.services.config import config
from amarillo.utils.utils import assert_folder_exists
logger = logging.getLogger(__name__)
@ -24,20 +21,6 @@ router = APIRouter(
tags=["carpool"]
)
#TODO: housekeeping for outdated trips
def enhance_trip(carpool: Carpool):
response = requests.post(f"{config.enhancer_url}", carpool.model_dump_json())
enhanced_carpool = Carpool(**json.loads(response.content))
#TODO: use data/enhanced directory
folder = f'data/enhanced/{carpool.agency}'
filename = f'{folder}/{carpool.id}.json'
assert_folder_exists(folder)
with open(filename, 'w', encoding='utf-8') as f:
f.write(enhanced_carpool.model_dump_json())
@router.post("/",
operation_id="addcarpool",
summary="Add a new or update existing carpool",
@ -49,7 +32,7 @@ def enhance_trip(carpool: Carpool):
"description": "Agency does not exist"},
})
async def post_carpool(background_tasks: BackgroundTasks, carpool: Carpool = Body(..., examples=examples),
async def post_carpool(carpool: Carpool = Body(..., examples=examples),
requesting_user: User = Depends(get_current_user)) -> Carpool:
verify_permission(f"{carpool.agency}:write", requesting_user)
@ -58,8 +41,6 @@ async def post_carpool(background_tasks: BackgroundTasks, carpool: Carpool = Bod
await store_carpool(carpool)
background_tasks.add_task(enhance_trip, carpool)
return carpool
# TODO 403
@ -110,11 +91,7 @@ async def _delete_carpool(agency_id: str, carpool_id: str):
# load and store, to receive pyinotify events and have file timestamp updated
await save_carpool(cp, 'data/trash')
logger.info(f"Saved carpool {agency_id}:{carpool_id} in trash.")
try:
os.remove(f"data/carpool/{agency_id}/{carpool_id}.json")
os.remove(f"data/enhanced/{agency_id}/{carpool_id}.json", )
except FileNotFoundError:
pass
os.remove(f"data/carpool/{agency_id}/{carpool_id}.json")
try:
from amarillo.plugins.metrics import trips_deleted_counter

View file

@ -8,6 +8,5 @@ class Config(BaseSettings):
env: str = 'DEV'
graphhopper_base_url: str = 'https://api.mfdz.de/gh'
stop_sources_file: str = 'data/stop_sources.json'
enhancer_url: str = 'http://localhost:8001'
config = Config(_env_file='config', _env_file_encoding='utf-8')

View file

@ -20,7 +20,7 @@ from amarillo.services.secrets import secrets
SECRET_KEY = secrets.secret_key
ALGORITHM = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES = 30
ACCESS_TOKEN_EXPIRE_MINUTES = 7*24*60
logging.config.fileConfig('logging.conf', disable_existing_loggers=False)
logger = logging.getLogger("main")

View file

@ -65,7 +65,6 @@ class UserService:
logger.error(message)
raise HTTPException(status_code=400, detail=message)
#TODO: fix duplicate None api key
def add(self, user_conf: User):
user_id = user_conf.user_id