add source configuration workflow v6
CI / compose (push) Successful in 13m43s

This commit is contained in:
Marco0300
2026-09-04 11:06:26 +02:00
parent 992e92a2c9
commit ed8829f96d
6 changed files with 42 additions and 9 deletions
+9 -1
View File
@@ -1360,7 +1360,15 @@ class ApiHandler(BaseHTTPRequestHandler):
def update_source(self,sid,payload,db,user):
source=db.execute("SELECT * FROM sources WHERE id=? AND organization_id=?",(sid,user['organization_id'])).fetchone()
if not source:return self.send_json(404,{"error":"not_found"})
if 'enabled' not in payload:return self.send_json(400,{"error":"enabled_required"})
if 'config' in payload:
config=payload.get('config')
if not isinstance(config,dict) or contains_secret(config): return self.send_json(400,{"error":"invalid_source_config"})
adapter=adapter_for(source['kind']); validation=adapter.validate_config(config)
if not validation.valid: return self.send_json(400,{"error":"invalid_source_config","details":validation.errors})
db.execute("UPDATE sources SET config_json=?,updated_at=CURRENT_TIMESTAMP WHERE id=? AND organization_id=?",(json.dumps(config,sort_keys=True),sid,user['organization_id']))
self.audit(db,user,'source.configured',str(sid)); db.commit()
if 'enabled' not in payload:
row=db.execute("SELECT * FROM sources WHERE id=?",(sid,)).fetchone(); return self.send_json(200,row_json(row))
value=int(bool(payload['enabled']))
if value:
adapter=adapter_for(source['kind'])
+7
View File
@@ -74,6 +74,13 @@ class SourceApiTests(unittest.TestCase):
self.assertEqual(status, 201)
self.assertEqual(self.req('PATCH', f"/api/v1/sources/{website['id']}", {'enabled': True})[0], 409)
def test_source_configuration_can_be_saved_before_enablement(self):
status, source = self.req('POST', '/api/v1/sources', {'name': 'DNS', 'kind': 'dns', 'config': {}})
self.assertEqual(status, 201)
status, configured = self.req('PATCH', f"/api/v1/sources/{source['id']}", {'config': {'domains': ['example.co.za']}})
self.assertEqual(status, 200)
self.assertEqual(self.req('PATCH', f"/api/v1/sources/{source['id']}", {'enabled': True})[0], 200)
def test_fresh_schema_accepts_optional_source_kind_fail_closed(self):
status, source = self.req('POST', '/api/v1/sources', {'name': 'RDAP', 'kind': 'rdap', 'config': {}})
self.assertEqual(status, 201)