ActivateSourceSession registers the active nonce and resets the snapshot version counter for one source.
( ctx context.Context, actor MutationActor, source ResourceSource, sessionNonce string, )
| 171 | |
| 172 | // ActivateSourceSession registers the active nonce and resets the snapshot version counter for one source. |
| 173 | func (k *Kernel) ActivateSourceSession( |
| 174 | ctx context.Context, |
| 175 | actor MutationActor, |
| 176 | source ResourceSource, |
| 177 | sessionNonce string, |
| 178 | ) error { |
| 179 | if ctx == nil { |
| 180 | return errors.New("resources: activate source session context is required") |
| 181 | } |
| 182 | |
| 183 | normalizedActor, err := normalizeActor(actor) |
| 184 | if err != nil { |
| 185 | return err |
| 186 | } |
| 187 | if normalizedActor.Kind == MutationActorKindExtension { |
| 188 | return fmt.Errorf("%w: extension actors cannot activate source sessions", ErrPermissionDenied) |
| 189 | } |
| 190 | |
| 191 | normalizedSource := source.Normalize() |
| 192 | if err := normalizedSource.Validate("source"); err != nil { |
| 193 | return err |
| 194 | } |
| 195 | trimmedNonce := strings.TrimSpace(sessionNonce) |
| 196 | if trimmedNonce == "" { |
| 197 | return fmt.Errorf("%w: session_nonce is required", ErrValidation) |
| 198 | } |
| 199 | |
| 200 | unlock := k.lockSource(normalizedSource) |
| 201 | defer unlock() |
| 202 | |
| 203 | return k.withImmediateTransaction(ctx, "activate source session", func(exec sqlExecutor) error { |
| 204 | updatedAt := store.FormatTimestamp(k.now()) |
| 205 | if _, err := exec.ExecContext( |
| 206 | ctx, |
| 207 | activateSourceStateQuery, |
| 208 | normalizedSource.Kind, |
| 209 | normalizedSource.ID, |
| 210 | trimmedNonce, |
| 211 | updatedAt, |
| 212 | ); err != nil { |
| 213 | return fmt.Errorf( |
| 214 | "resources: activate source session %q/%q: %w", |
| 215 | normalizedSource.Kind, |
| 216 | normalizedSource.ID, |
| 217 | err, |
| 218 | ) |
| 219 | } |
| 220 | return nil |
| 221 | }) |
| 222 | } |
| 223 | |
| 224 | // ResetSource deletes all source-owned records and source state in one transaction. |
| 225 | func (k *Kernel) ResetSource(ctx context.Context, actor MutationActor, source ResourceSource) error { |
nothing calls this directly
no test coverage detected