|
| 1 | +package webhooks |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "slices" |
| 6 | + |
| 7 | + "github.com/google/uuid" |
| 8 | +) |
| 9 | + |
| 10 | +const WebhookKeyPrefix = "wh" |
| 11 | + |
| 12 | +const WebhooksChannel = "sandbox-webhooks" |
| 13 | + |
| 14 | +func DeriveKey(teamID uuid.UUID) string { |
| 15 | + return fmt.Sprintf("%s:%s", WebhookKeyPrefix, teamID.String()) |
| 16 | +} |
| 17 | + |
| 18 | +type SandboxLifecycleEvent string |
| 19 | + |
| 20 | +const ( |
| 21 | + SandboxLifecycleEventCreate SandboxLifecycleEvent = "create" |
| 22 | + SandboxLifecycleEventKill SandboxLifecycleEvent = "kill" |
| 23 | + SandboxLifecycleEventPause SandboxLifecycleEvent = "pause" |
| 24 | + SandboxLifecycleEventResume SandboxLifecycleEvent = "resume" |
| 25 | + SandboxLifecycleEventUpdate SandboxLifecycleEvent = "update" |
| 26 | +) |
| 27 | + |
| 28 | +var AllowedLifecycleEvents = []string{ |
| 29 | + string(SandboxLifecycleEventCreate), |
| 30 | + string(SandboxLifecycleEventKill), |
| 31 | + string(SandboxLifecycleEventPause), |
| 32 | + string(SandboxLifecycleEventResume), |
| 33 | + string(SandboxLifecycleEventUpdate), |
| 34 | +} |
| 35 | + |
| 36 | +func IsLifecycleEvent(event string) bool { |
| 37 | + return slices.Contains(AllowedLifecycleEvents, event) |
| 38 | +} |
| 39 | + |
| 40 | +type SandboxWebhooksMetaData struct { |
| 41 | + Events []SandboxLifecycleEvent `json:"events"` |
| 42 | + URL string `json:"url"` |
| 43 | +} |
0 commit comments