@@ -53,26 +53,26 @@ func (s *catalogAddressRefStore) get(
5353 ignoreTransaction bool ,
5454 key datastore.AddressRefKey ,
5555) (datastore.AddressRef , error ) {
56- // Create a bidirectional stream
57- stream , err := s .client .DataAccess ()
58- if err != nil {
59- return datastore.AddressRef {}, fmt .Errorf ("failed to create data access stream: %w" , err )
60- }
61-
6256 // Create the find request with the key converted to a filter
6357 filter := s .keyToFilter (key )
6458 findRequest := & pb.AddressReferenceFindRequest {
6559 KeyFilter : filter ,
6660 IgnoreTransaction : ignoreTransaction ,
6761 }
6862
69- // Send the request
63+ // Create the request
7064 request := & pb.DataAccessRequest {
7165 Operation : & pb.DataAccessRequest_AddressReferenceFindRequest {
7266 AddressReferenceFindRequest : findRequest ,
7367 },
7468 }
7569
70+ // Create a bidirectional stream with the initial request for HMAC
71+ stream , err := s .client .DataAccess (request )
72+ if err != nil {
73+ return datastore.AddressRef {}, fmt .Errorf ("failed to create data access stream: %w" , err )
74+ }
75+
7676 if sendErr := stream .Send (request ); sendErr != nil {
7777 return datastore.AddressRef {}, fmt .Errorf ("failed to send find request: %w" , sendErr )
7878 }
@@ -120,12 +120,6 @@ func (s *catalogAddressRefStore) get(
120120
121121// Fetch returns a copy of all AddressRef in the catalog.
122122func (s * catalogAddressRefStore ) Fetch (_ context.Context ) ([]datastore.AddressRef , error ) {
123- // Create a bidirectional stream
124- stream , err := s .client .DataAccess ()
125- if err != nil {
126- return nil , fmt .Errorf ("failed to create data access stream: %w" , err )
127- }
128-
129123 // Create the find request with an empty filter to get all records
130124 // We only filter by domain and environment to get all records for this store's scope
131125 filter := & pb.AddressReferenceKeyFilter {
@@ -138,13 +132,19 @@ func (s *catalogAddressRefStore) Fetch(_ context.Context) ([]datastore.AddressRe
138132 KeyFilter : filter ,
139133 }
140134
141- // Send the request
135+ // Create the request
142136 request := & pb.DataAccessRequest {
143137 Operation : & pb.DataAccessRequest_AddressReferenceFindRequest {
144138 AddressReferenceFindRequest : findRequest ,
145139 },
146140 }
147141
142+ // Create a bidirectional stream with the initial request for HMAC
143+ stream , err := s .client .DataAccess (request )
144+ if err != nil {
145+ return nil , fmt .Errorf ("failed to create data access stream: %w" , err )
146+ }
147+
148148 if sendErr := stream .Send (request ); sendErr != nil {
149149 return nil , fmt .Errorf ("failed to send find request: %w" , sendErr )
150150 }
@@ -212,12 +212,6 @@ func (s *catalogAddressRefStore) Filter(
212212}
213213
214214func (s * catalogAddressRefStore ) Add (_ context.Context , record datastore.AddressRef ) error {
215- // Create a bidirectional stream
216- stream , err := s .client .DataAccess ()
217- if err != nil {
218- return fmt .Errorf ("failed to create data access stream: %w" , err )
219- }
220-
221215 // Convert the datastore record to protobuf
222216 protoRef := s .addressRefToProto (record )
223217
@@ -227,13 +221,19 @@ func (s *catalogAddressRefStore) Add(_ context.Context, record datastore.Address
227221 Semantics : pb .EditSemantics_SEMANTICS_INSERT ,
228222 }
229223
230- // Send the edit request
224+ // Create the request
231225 editReq := & pb.DataAccessRequest {
232226 Operation : & pb.DataAccessRequest_AddressReferenceEditRequest {
233227 AddressReferenceEditRequest : editRequest ,
234228 },
235229 }
236230
231+ // Create a bidirectional stream with the initial request for HMAC
232+ stream , err := s .client .DataAccess (editReq )
233+ if err != nil {
234+ return fmt .Errorf ("failed to create data access stream: %w" , err )
235+ }
236+
237237 if sendErr := stream .Send (editReq ); sendErr != nil {
238238 return fmt .Errorf ("failed to send edit request: %w" , sendErr )
239239 }
@@ -259,12 +259,6 @@ func (s *catalogAddressRefStore) Add(_ context.Context, record datastore.Address
259259}
260260
261261func (s * catalogAddressRefStore ) Upsert (_ context.Context , record datastore.AddressRef ) error {
262- // Create a bidirectional stream
263- stream , err := s .client .DataAccess ()
264- if err != nil {
265- return fmt .Errorf ("failed to create data access stream: %w" , err )
266- }
267-
268262 // Convert the datastore record to protobuf
269263 protoRef := s .addressRefToProto (record )
270264
@@ -274,13 +268,19 @@ func (s *catalogAddressRefStore) Upsert(_ context.Context, record datastore.Addr
274268 Semantics : pb .EditSemantics_SEMANTICS_UPSERT ,
275269 }
276270
277- // Send the edit request
271+ // Create the request
278272 request := & pb.DataAccessRequest {
279273 Operation : & pb.DataAccessRequest_AddressReferenceEditRequest {
280274 AddressReferenceEditRequest : editRequest ,
281275 },
282276 }
283277
278+ // Create a bidirectional stream with the initial request for HMAC
279+ stream , err := s .client .DataAccess (request )
280+ if err != nil {
281+ return fmt .Errorf ("failed to create data access stream: %w" , err )
282+ }
283+
284284 if sendErr := stream .Send (request ); sendErr != nil {
285285 return fmt .Errorf ("failed to send edit request: %w" , sendErr )
286286 }
@@ -319,12 +319,6 @@ func (s *catalogAddressRefStore) Update(ctx context.Context, record datastore.Ad
319319 }
320320
321321 // Record exists, proceed with updating it
322- // Create a bidirectional stream
323- stream , streamErr := s .client .DataAccess ()
324- if streamErr != nil {
325- return fmt .Errorf ("failed to create data access stream: %w" , streamErr )
326- }
327-
328322 // Convert the datastore record to protobuf
329323 protoRef := s .addressRefToProto (record )
330324
@@ -334,13 +328,19 @@ func (s *catalogAddressRefStore) Update(ctx context.Context, record datastore.Ad
334328 Semantics : pb .EditSemantics_SEMANTICS_UPDATE ,
335329 }
336330
337- // Send the edit request
331+ // Create the request
338332 editReq := & pb.DataAccessRequest {
339333 Operation : & pb.DataAccessRequest_AddressReferenceEditRequest {
340334 AddressReferenceEditRequest : editRequest ,
341335 },
342336 }
343337
338+ // Create a bidirectional stream with the initial request for HMAC
339+ stream , streamErr := s .client .DataAccess (editReq )
340+ if streamErr != nil {
341+ return fmt .Errorf ("failed to create data access stream: %w" , streamErr )
342+ }
343+
344344 if sendErr := stream .Send (editReq ); sendErr != nil {
345345 return fmt .Errorf ("failed to send edit request: %w" , sendErr )
346346 }
0 commit comments