Write handles the writing of bundles.
(ctx context.Context, request *v1.BundleWriteRequest)
| 33 | |
| 34 | // Write handles the writing of bundles. |
| 35 | func (r *BundleServer) Write(ctx context.Context, request *v1.BundleWriteRequest) (*v1.BundleWriteResponse, error) { |
| 36 | ctx, span := internal.Tracer.Start(ctx, "bundle.write") |
| 37 | defer span.End() |
| 38 | |
| 39 | v := request.Validate() |
| 40 | if v != nil { |
| 41 | return nil, status.Error(GetStatus(v), v.Error()) // Return validation error |
| 42 | } |
| 43 | |
| 44 | for _, bundle := range request.GetBundles() { |
| 45 | for _, operation := range bundle.GetOperations() { |
| 46 | err := validation.ValidateBundleOperation(operation) |
| 47 | if err != nil { |
| 48 | return nil, status.Error(GetStatus(err), err.Error()) // Return operation validation error |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | var bundles []storage.Bundle |
| 54 | for _, b := range request.GetBundles() { |
| 55 | bundles = append(bundles, storage.Bundle{ |
| 56 | Name: b.GetName(), |
| 57 | DataBundle: b, |
| 58 | TenantID: request.GetTenantId(), |
| 59 | }) |
| 60 | } |
| 61 | |
| 62 | names, err := r.bw.Write(ctx, bundles) |
| 63 | if err != nil { |
| 64 | span.RecordError(err) |
| 65 | span.SetStatus(otelCodes.Error, err.Error()) |
| 66 | slog.ErrorContext(ctx, err.Error()) |
| 67 | return nil, status.Error(GetStatus(err), err.Error()) |
| 68 | } |
| 69 | |
| 70 | return &v1.BundleWriteResponse{ |
| 71 | Names: names, |
| 72 | }, nil |
| 73 | } |
| 74 | |
| 75 | // Read handles the reading of bundles. |
| 76 | func (r *BundleServer) Read(ctx context.Context, request *v1.BundleReadRequest) (*v1.BundleReadResponse, error) { |
nothing calls this directly
no test coverage detected