Skip to content

Commit

Permalink
bring your own iden to the http extended api party
Browse files Browse the repository at this point in the history
  • Loading branch information
rakuy0 committed Sep 17, 2024
1 parent facf8af commit 09c16b7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 7 additions & 1 deletion synapse/cortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -4391,7 +4391,13 @@ async def addHttpExtApi(self, adef):
except Exception as e:
mesg = f'Invalid path for Extended HTTP API - cannot compile regular expression for [{path}] : {e}'
raise s_exc.BadArg(mesg=mesg) from None
adef['iden'] = s_common.guid()

if adef.get('iden') is None:
adef['iden'] = s_common.guid()

if self._exthttpapis.get(adef['iden']) is not None:
raise s_exc.DupIden(mesg=f'Duplicate iden specified for Extended HTTP API: {adef["iden"]}')

adef['created'] = s_common.now()
adef['updated'] = adef['created']
adef = s_schemas.reqValidHttpExtAPIConf(adef)
Expand Down
22 changes: 22 additions & 0 deletions synapse/tests/test_cortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -7900,17 +7900,23 @@ async def test_cortex_ext_httpapi(self):
'view': view.iden,
})

othr = s_common.guid()
info4 = await core.addHttpExtApi({
'iden': othr,
'path': 'another/item',
'owner': unfo.get('iden'),
'view': view.iden,
})
self.eq(info4.get('iden'), othr)

iden = info.get('iden')

adef = await core.getHttpExtApi(iden)
self.eq(adef, info)

adef = await core.getHttpExtApi(othr)
self.eq(adef, info4)

adef, args = await core.getHttpExtApiByPath('test/path/hehe/wow')
self.eq(adef, info)
self.eq(args, ('hehe', 'wow'))
Expand Down Expand Up @@ -7955,6 +7961,22 @@ async def test_cortex_ext_httpapi(self):

# Sad path

with self.raises(s_exc.SchemaViolation):
await core.addHttpExtApi({
'iden': 'lolnope',
'path': 'not/gonna/happen',
'owner': unfo.get('iden'),
'view': view.iden
})

with self.raises(s_exc.DupIden):
await core.addHttpExtApi({
'iden': othr,
'path': 'bad/dup',
'owner': unfo.get('iden'),
'view': view.iden
})

with self.raises(s_exc.SynErr):
await core.setHttpApiIndx(newp, 0)

Expand Down

0 comments on commit 09c16b7

Please sign in to comment.