async def update_network_config(network_config: NetworkConfig, aroio: Aroio = Depends(get_auth_aroio)): """Update the network configuration. Returns the updated network configuration.""" if not network_config.lan.valid_ipv4_addresses_or_none(): raise ForbiddenException(detail="Incorrect format of IPv4 addresses.") aroio.configuration.network = network_config datasource.save(aroio=aroio) return aroio.configuration.network
async def change_aroio_password(form: AroioPasswordForm, aroio: Aroio = Depends(get_auth_aroio)): """`new_password` replaces password for Aroio. `old_password` is required for authentication.""" auth = Authentication.verify_password(hashed=aroio.password, plain=form.old_password) if not auth: raise UnauthorizedException(detail="Wrong password") aroio.password = Authentication.hash_password(password=form.new_password) datasource.save(aroio=aroio) return create_access_token(data={"sub": aroio.dict()})
async def delete_filter(filter_id: int, aroio: Aroio = Depends(get_auth_aroio)): """Deletes filter with the given filter_id.""" filter_to_delete = -1 for idx, f in enumerate(aroio.configuration.convolver.filters): if f.id == filter_id: filter_to_delete = idx if filter_to_delete == -1: raise NotFoundException( detail=f'Filter to delete not found. Filter id: {filter_to_delete}' ) aroio.configuration.convolver.filters.pop(filter_to_delete) datasource.save(aroio=aroio)
async def create_filter(filter: Filter, aroio: Aroio = Depends(get_auth_aroio)): """Creates a new filter in the database. Returns the created filter with its id""" filters = aroio.configuration.convolver.filters if len(filters) >= 10: raise ForbiddenException( detail="Only 10 filters are allowed with the userconfig.txt pattern" ) # compute next possible filter id by maximum id filter_id = max([f.id for f in filters]) + 1 filter_in_db = FilterInDb(id=filter_id, **filter.dict()) aroio.configuration.convolver.filters.append(filter_in_db) datasource.save(aroio=aroio) return filter_in_db
def update_aroio_setup(setup: AroioSetup, aroio: Aroio = Depends(get_auth_aroio)): """Changing the base Aroio setup with name, password, description and authentication_enabled. Returns new access token, that must be used for further use of this API. For authentication the current password must be given""" authorized = Authentication.verify_password(plain=setup.verify_password, hashed=aroio.password) if not authorized: raise UnauthorizedException( detail="Not authorized changing authorization parameters", headers={"WWW-Authenticate": "Bearer"}) aroio.name = setup.name aroio.description = setup.description aroio.authentication_enabled = setup.authentication_enabled datasource.save(aroio=aroio) return create_access_token(data={"sub": aroio.dict()})
async def update_audio_config(webinterface_config: WebinterfaceConfig, aroio: Aroio = Depends(get_auth_aroio)): """Update the webinterface configuration.""" aroio.configuration.webinterface = webinterface_config datasource.save(aroio=aroio) return aroio.configuration.webinterface
async def update_audio_config(output_config: OutputConfig, aroio: Aroio = Depends(get_auth_aroio)): """Update the streaming configuration.""" aroio.configuration.audio.output_configuration = output_config datasource.save(aroio=aroio) return aroio.configuration.audio.output_configuration
async def update_streaming_config(streaming_config: StreamingConfig, aroio: Aroio = Depends(get_auth_aroio)): """Update the streaming configuration.""" aroio.configuration.streaming = streaming_config datasource.save(aroio=aroio) return aroio.configuration.streaming
async def update_system_config(system_config: SystemConfig, aroio: Aroio = Depends(get_auth_aroio)): """Update the system configuration.""" aroio.configuration.system = system_config datasource.save(aroio=aroio) return aroio.configuration.system
async def update_convolver_config(convolver: ConvolverConfig, aroio: Aroio = Depends(get_auth_aroio)): """Update the Convolver configuration.""" aroio.configuration.convolver = convolver datasource.save(aroio=aroio) return aroio.configuration.convolver
async def update_configuration(config: Configuration, aroio: Aroio = Depends(get_auth_aroio)): """Update the complete configuration. Returns the updated configuration.""" aroio.configuration = config datasource.save(aroio=aroio) return aroio.configuration