Create a sandbox record in the store
(ctx context.Context, sandbox api.Sandbox)
| 52 | |
| 53 | // Create a sandbox record in the store |
| 54 | func (s *sandboxStore) Create(ctx context.Context, sandbox api.Sandbox) (api.Sandbox, error) { |
| 55 | ctx, span := tracing.StartSpan(ctx, |
| 56 | tracing.Name(spanSandboxPrefix, "Create"), |
| 57 | tracing.WithAttribute("sandbox.id", sandbox.ID), |
| 58 | tracing.WithNamespace(ctx), |
| 59 | ) |
| 60 | defer span.End() |
| 61 | |
| 62 | ns, err := namespaces.NamespaceRequired(ctx) |
| 63 | if err != nil { |
| 64 | return api.Sandbox{}, err |
| 65 | } |
| 66 | |
| 67 | sandbox.CreatedAt = time.Now().UTC() |
| 68 | sandbox.UpdatedAt = sandbox.CreatedAt |
| 69 | |
| 70 | if err := s.validate(&sandbox); err != nil { |
| 71 | return api.Sandbox{}, fmt.Errorf("failed to validate sandbox: %w", err) |
| 72 | } |
| 73 | |
| 74 | if err := update(ctx, s.db, func(tx *bbolt.Tx) error { |
| 75 | parent, err := createSandboxBucket(tx, ns) |
| 76 | if err != nil { |
| 77 | return fmt.Errorf("create error: %w", err) |
| 78 | } |
| 79 | |
| 80 | if err := s.write(parent, &sandbox, false); err != nil { |
| 81 | return fmt.Errorf("write error: %w", err) |
| 82 | } |
| 83 | |
| 84 | span.SetAttributes( |
| 85 | tracing.Attribute("sandbox.CreatedAt", sandbox.CreatedAt.Format(time.RFC3339)), |
| 86 | ) |
| 87 | return nil |
| 88 | }); err != nil { |
| 89 | return api.Sandbox{}, err |
| 90 | } |
| 91 | |
| 92 | return sandbox, nil |
| 93 | } |
| 94 | |
| 95 | // Update the sandbox with the provided sandbox object and fields |
| 96 | func (s *sandboxStore) Update(ctx context.Context, sandbox api.Sandbox, fieldpaths ...string) (api.Sandbox, error) { |
nothing calls this directly
no test coverage detected