forked from wrenn/wrenn
Implement a channels system for notifying teams via external providers
(Discord, Slack, Teams, Google Chat, Telegram, Matrix, webhook) when
lifecycle events occur (capsule/template/host state changes).
- Channel CRUD API under /v1/channels (JWT-only auth)
- Test endpoint to verify config before saving (POST /v1/channels/test)
- Secret rotation endpoint (PUT /v1/channels/{id}/config)
- AES-256-GCM encryption for provider secrets (WRENN_ENCRYPTION_KEY)
- Redis stream event publishing from audit logger
- Background dispatcher with consumer group and retry (10s, 30s)
- Webhook delivery with HMAC-SHA256 signing (X-WRENN-SIGNATURE)
- shoutrrr integration for chat providers
- Secrets never exposed in API responses
226 lines
5.2 KiB
Go
226 lines
5.2 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: channels.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const deleteChannelByTeam = `-- name: DeleteChannelByTeam :exec
|
|
DELETE FROM channels WHERE id = $1 AND team_id = $2
|
|
`
|
|
|
|
type DeleteChannelByTeamParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
TeamID pgtype.UUID `json:"team_id"`
|
|
}
|
|
|
|
func (q *Queries) DeleteChannelByTeam(ctx context.Context, arg DeleteChannelByTeamParams) error {
|
|
_, err := q.db.Exec(ctx, deleteChannelByTeam, arg.ID, arg.TeamID)
|
|
return err
|
|
}
|
|
|
|
const getChannelByTeam = `-- name: GetChannelByTeam :one
|
|
SELECT id, team_id, name, provider, config, event_types, created_at, updated_at FROM channels WHERE id = $1 AND team_id = $2
|
|
`
|
|
|
|
type GetChannelByTeamParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
TeamID pgtype.UUID `json:"team_id"`
|
|
}
|
|
|
|
func (q *Queries) GetChannelByTeam(ctx context.Context, arg GetChannelByTeamParams) (Channel, error) {
|
|
row := q.db.QueryRow(ctx, getChannelByTeam, arg.ID, arg.TeamID)
|
|
var i Channel
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.TeamID,
|
|
&i.Name,
|
|
&i.Provider,
|
|
&i.Config,
|
|
&i.EventTypes,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const insertChannel = `-- name: InsertChannel :one
|
|
INSERT INTO channels (id, team_id, name, provider, config, event_types)
|
|
VALUES ($1, $2, $3, $4, $5, $6)
|
|
RETURNING id, team_id, name, provider, config, event_types, created_at, updated_at
|
|
`
|
|
|
|
type InsertChannelParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
TeamID pgtype.UUID `json:"team_id"`
|
|
Name string `json:"name"`
|
|
Provider string `json:"provider"`
|
|
Config []byte `json:"config"`
|
|
EventTypes []string `json:"event_types"`
|
|
}
|
|
|
|
func (q *Queries) InsertChannel(ctx context.Context, arg InsertChannelParams) (Channel, error) {
|
|
row := q.db.QueryRow(ctx, insertChannel,
|
|
arg.ID,
|
|
arg.TeamID,
|
|
arg.Name,
|
|
arg.Provider,
|
|
arg.Config,
|
|
arg.EventTypes,
|
|
)
|
|
var i Channel
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.TeamID,
|
|
&i.Name,
|
|
&i.Provider,
|
|
&i.Config,
|
|
&i.EventTypes,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listChannelsByTeam = `-- name: ListChannelsByTeam :many
|
|
SELECT id, team_id, name, provider, config, event_types, created_at, updated_at FROM channels WHERE team_id = $1 ORDER BY created_at DESC
|
|
`
|
|
|
|
func (q *Queries) ListChannelsByTeam(ctx context.Context, teamID pgtype.UUID) ([]Channel, error) {
|
|
rows, err := q.db.Query(ctx, listChannelsByTeam, teamID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Channel
|
|
for rows.Next() {
|
|
var i Channel
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.TeamID,
|
|
&i.Name,
|
|
&i.Provider,
|
|
&i.Config,
|
|
&i.EventTypes,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listChannelsForEvent = `-- name: ListChannelsForEvent :many
|
|
SELECT id, team_id, name, provider, config, event_types, created_at, updated_at FROM channels
|
|
WHERE team_id = $1
|
|
AND $2::text = ANY(event_types)
|
|
ORDER BY created_at
|
|
`
|
|
|
|
type ListChannelsForEventParams struct {
|
|
TeamID pgtype.UUID `json:"team_id"`
|
|
EventType string `json:"event_type"`
|
|
}
|
|
|
|
func (q *Queries) ListChannelsForEvent(ctx context.Context, arg ListChannelsForEventParams) ([]Channel, error) {
|
|
rows, err := q.db.Query(ctx, listChannelsForEvent, arg.TeamID, arg.EventType)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Channel
|
|
for rows.Next() {
|
|
var i Channel
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.TeamID,
|
|
&i.Name,
|
|
&i.Provider,
|
|
&i.Config,
|
|
&i.EventTypes,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateChannel = `-- name: UpdateChannel :one
|
|
UPDATE channels SET name = $3, event_types = $4, updated_at = NOW()
|
|
WHERE id = $1 AND team_id = $2
|
|
RETURNING id, team_id, name, provider, config, event_types, created_at, updated_at
|
|
`
|
|
|
|
type UpdateChannelParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
TeamID pgtype.UUID `json:"team_id"`
|
|
Name string `json:"name"`
|
|
EventTypes []string `json:"event_types"`
|
|
}
|
|
|
|
func (q *Queries) UpdateChannel(ctx context.Context, arg UpdateChannelParams) (Channel, error) {
|
|
row := q.db.QueryRow(ctx, updateChannel,
|
|
arg.ID,
|
|
arg.TeamID,
|
|
arg.Name,
|
|
arg.EventTypes,
|
|
)
|
|
var i Channel
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.TeamID,
|
|
&i.Name,
|
|
&i.Provider,
|
|
&i.Config,
|
|
&i.EventTypes,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updateChannelConfig = `-- name: UpdateChannelConfig :one
|
|
UPDATE channels SET config = $3, updated_at = NOW()
|
|
WHERE id = $1 AND team_id = $2
|
|
RETURNING id, team_id, name, provider, config, event_types, created_at, updated_at
|
|
`
|
|
|
|
type UpdateChannelConfigParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
TeamID pgtype.UUID `json:"team_id"`
|
|
Config []byte `json:"config"`
|
|
}
|
|
|
|
func (q *Queries) UpdateChannelConfig(ctx context.Context, arg UpdateChannelConfigParams) (Channel, error) {
|
|
row := q.db.QueryRow(ctx, updateChannelConfig, arg.ID, arg.TeamID, arg.Config)
|
|
var i Channel
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.TeamID,
|
|
&i.Name,
|
|
&i.Provider,
|
|
&i.Config,
|
|
&i.EventTypes,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|