feat(canary): Generator interface for token-type plugins

- ArtifactKind enum: url, file, text, connection_string
- Artifact struct discriminated by Kind
- TriggerResponse value-typed (handler writes; generator stays pure)
- Generator interface: Type, Generate, Trigger
This commit is contained in:
CarterPerez-dev 2026-05-12 02:40:00 -04:00
parent 697f4909d7
commit 6cc724c19f
1 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,45 @@
// ©AngelaMos | 2026
// generator.go
package generators
import (
"context"
"net/http"
"github.com/CarterPerez-dev/cybersecurity-projects/canary-token-generator/backend/internal/event"
"github.com/CarterPerez-dev/cybersecurity-projects/canary-token-generator/backend/internal/token"
)
type ArtifactKind string
const (
KindURL ArtifactKind = "url"
KindFile ArtifactKind = "file"
KindText ArtifactKind = "text"
KindConnectionString ArtifactKind = "connection_string"
)
type Artifact struct {
Kind ArtifactKind
URL string
Filename string
Content []byte
ContentType string
ConnectionString string
DestinationURL string
}
type TriggerResponse struct {
StatusCode int
ContentType string
Body []byte
RedirectURL string
ExtraHeaders map[string]string
}
type Generator interface {
Type() token.Type
Generate(ctx context.Context, t *token.Token, baseURL string) (Artifact, error)
Trigger(ctx context.Context, t *token.Token, r *http.Request) (*event.Event, *TriggerResponse, error)
}