@@ -101,20 +101,26 @@ async def report_ac(agent_id: str, correlator_nonce: int):
101101 agent_id = agent_id .strip ()
102102 final_res = []
103103 ari = None
104+ dec = ace .ari_cbor .Decoder ()
105+ buf = io .StringIO ()
104106 # Load in adms
105107 # get command that made the report as first entry
106108 stmt = select (ExecutionSet ).where (and_ (ExecutionSet .agent_id == agent_id , ExecutionSet .correlator_nonce == correlator_nonce ) )
107109 async with get_async_session () as session :
108110 result : Result = await session .scalars (stmt )
109- result = result .one_or_none ()
110- exec_set_entry = ["time" ]
111+
112+ # there should only be one execution per agent per correlator_nonce
113+ # in the event that two occur pull the latest one
114+ result = result .all ()
115+ exec_set_dir = {}
116+
111117 if result :
118+ result = result [- 1 ]
112119 exec_set = result .entries .hex ()
113120 # use ACE to handle report set decoding
114121 in_text = '0x' + exec_set
115122 try :
116123 in_bytes = ace .cborutil .from_hexstr (in_text )
117- dec = ace .ari_cbor .Decoder ()
118124 ari = dec .decode (io .BytesIO (in_bytes ))
119125
120126 except Exception as err :
@@ -125,26 +131,28 @@ async def report_ac(agent_id: str, correlator_nonce: int):
125131 if type (ari .value ) == ace .ari .ExecutionSet :
126132 try :
127133 enc = ace .ari_text .Encoder ()
128- buf = io .StringIO ()
129134 # run through targets and their parameters to get all things parts translated
130135 for targ in ari .value .targets :
131- if targ .params :
132- for param in targ .params :
133- enc .encode (param , buf )
136+ buf = io .StringIO ()
137+ exec_set_entry = ["time" ]
138+ enc .encode (targ , buf )
139+ out_text_targ = buf .getvalue ()
140+ if targ is ace .LiteralARI and targ .type_id is ace .StructType .AC :
141+ for part in targ .value :
142+ buf = io .StringIO ()
143+ enc .encode (part , buf )
134144 out_text = buf .getvalue ()
135- ari_val = await transcoder .transcoder_put_await_str (out_text )
136- exec_set_entry .append (ari_val ['data' ])
145+ exec_set_entry .append (out_text )
137146 else :
138- enc .encode (targ , buf )
139- out_text = buf .getvalue ()
140- ari_val = await transcoder .transcoder_put_await_str (out_text )
141- exec_set_entry .append (ari_val ['data' ])
142-
147+ exec_set_entry .append (out_text_targ )
148+
149+ exec_set_dir [out_text_targ ] = [exec_set_entry ]
150+
143151 except Exception as err :
144152 logger .info (err )
145153
146154
147- final_res .append (exec_set_entry )
155+ # final_res.append(exec_set_entry)
148156 ari = None
149157 stmt = select (Report ).where (and_ (Report .agent_id == agent_id , Report .correlator_nonce == correlator_nonce ) )
150158 async with get_async_session () as session :
@@ -157,7 +165,6 @@ async def report_ac(agent_id: str, correlator_nonce: int):
157165 in_text = '0x' + rpt_set
158166 try :
159167 in_bytes = ace .cborutil .from_hexstr (in_text )
160- dec = ace .ari_cbor .Decoder ()
161168 ari = dec .decode (io .BytesIO (in_bytes ))
162169
163170 except Exception as err :
@@ -173,13 +180,17 @@ async def report_ac(agent_id: str, correlator_nonce: int):
173180 for item in rpt .items :
174181 buf = io .StringIO ()
175182 enc .encode (item , buf )
176- out_text = buf .getvalue ()
177- ari_val = await transcoder .transcoder_put_await_str (out_text )
178- addition .append (ari_val ['data' ])
183+ out_text = buf .getvalue ()
184+ addition .append (out_text )
185+ buf = io .StringIO ()
186+ enc .encode (rpt .source , buf )
187+ out_text = buf .getvalue ()
188+
189+ exec_set_dir [out_text ].append (addition )
179190 except Exception as err :
180191 logger .error (err )
181-
182- if addition not in final_res :
183- final_res . append ( addition )
184- return final_res
192+
193+
194+
195+ return list ( exec_set_dir . values ())
185196
0 commit comments