Documentation
¶
Overview ¶
Package domain 은 알림 채널과 보낼 메시지다(nullus-plan#63, 설계 docs/11_기능설계/Nullus_알림_채널_설계.md).
Index ¶
Constants ¶
const EventTest sharednotify.EventType = "test"
EventTest 는 채널 설정을 확인하는 테스트 전송이다. 구독하는 이벤트가 아니다.
Variables ¶
var ErrChannelNotFound = errors.New("notification channel not found")
ErrChannelNotFound 는 채널이 없거나 다른 조직의 것일 때다.
Functions ¶
func IsKnownEvent ¶
func IsKnownEvent(t sharednotify.EventType) bool
IsKnownEvent 는 구독할 수 있는 이벤트인지 본다.
Types ¶
type Channel ¶
type Channel struct {
ID string
OrgID string
Name string
Type ChannelType
Settings Settings
Secret string
Events []sharednotify.EventType
Active bool
CreatedAt time.Time
UpdatedAt time.Time
// SecretUnreadable 은 저장된 비밀을 풀지 못했다는 뜻이다(ENCRYPTION_KEY 교체 등). 저장하지 않는
// 상태다 — 저장소가 읽을 때 정한다. 이 채널은 보내지 못하고, 비밀을 다시 입력해야 고쳐진다.
SecretUnreadable bool
}
Channel 은 조직의 알림 채널 하나다.
Secret 은 채널마다 하나다 — Telegram 봇 토큰, Slack 웹훅 URL, SMTP 비밀번호. 저장소가 암호화해 두고, API 는 내보내지 않는다(SecretHint 만).
func (*Channel) ApplyUpdate ¶
func (c *Channel) ApplyUpdate(u ChannelUpdate) error
ApplyUpdate 는 갱신을 적용하고 검증한다. 실패하면 채널을 바꾸지 않는다. 채널 종류는 바꿀 수 없다.
func (*Channel) SecretHint ¶
SecretHint 는 화면이 "어떤 자격증명이 들어 있는지" 알아볼 만큼만 보여 준다. 비밀 자체는 담지 않는다.
func (*Channel) Subscribes ¶
func (c *Channel) Subscribes(e sharednotify.EventType) bool
Subscribes 는 이 채널이 그 이벤트를 받는지다.
type ChannelType ¶
type ChannelType string
ChannelType 은 알림을 보내는 길이다.
const ( ChannelTelegram ChannelType = "telegram" // ChannelEmail 은 SMTP 로 보내는 메일이다. 이름은 기존 알림 규칙·설정(email)과 맞춘다. ChannelEmail ChannelType = "email" ChannelSlack ChannelType = "slack" )
type ChannelUpdate ¶
type ChannelUpdate struct {
Name *string
Settings *Settings
Secret *string
Events *[]sharednotify.EventType
Active *bool
}
ChannelUpdate 는 바꿀 칸만 담는다. nil 은 그대로 둔다 — 특히 Secret 은 화면이 모르는 값이라 비워 보내면 기존 값을 지킨다.
type Delivery ¶
type Delivery struct {
ID string
OrgID string
ChannelID string
ChannelName string
ChannelType ChannelType
Event sharednotify.EventType
Status DeliveryStatus
Title string
Attempts int
Error string
CreatedAt time.Time
}
Delivery 는 발송 이력 한 줄이다 — 이벤트 하나가 채널 하나로 간 결과(재시도 포함).
type DeliveryStatus ¶
type DeliveryStatus string
DeliveryStatus 는 채널 하나로 보낸 결과다.
const ( DeliverySent DeliveryStatus = "sent" DeliveryFailed DeliveryStatus = "failed" )
type EventSpec ¶
type EventSpec struct {
Type sharednotify.EventType `json:"type"`
// DefaultOn 은 새 채널에서 미리 골라 둘지다. 성공 알림은 잡음이라 끈다.
DefaultOn bool `json:"default_on"`
// Description 은 화면이 번역이 없을 때 보여 줄 설명이다.
Description string `json:"description"`
}
EventSpec 은 구독할 수 있는 이벤트 하나다.
func EventCatalog ¶
func EventCatalog() []EventSpec
EventCatalog 는 지금 생산자가 있는 이벤트다 — 백업 결과(B3-3), 스택 심각 경보(#87), 설치 OSS 의 새 CVE(#78). 생산자가 생길 때 여기에 더한다.
type Message ¶
type Message struct {
Event sharednotify.EventType
Severity sharednotify.Severity
Title string
Summary string
Fields []sharednotify.Field
OccurredAt time.Time
}
Message 는 채널로 보낼 내용이다. 채널마다 모양(Slack mrkdwn · Telegram HTML · 메일 본문)은 보내는 쪽 어댑터가 정한다.
type SMTPSecurity ¶
type SMTPSecurity string
SMTPSecurity 는 SMTP 연결 보호 방식이다.
const ( // SMTPStartTLS 는 평문으로 붙어 STARTTLS 로 올린다(587). 서버가 지원하지 않으면 보내지 않는다. SMTPStartTLS SMTPSecurity = "starttls" // SMTPTLS 는 처음부터 TLS 로 붙는다(465). SMTPTLS SMTPSecurity = "tls" // SMTPNone 은 암호화하지 않는다 — 인증 없는 사내 릴레이 전용이다. SMTPNone SMTPSecurity = "none" )
type Settings ¶
type Settings struct {
// Telegram
ChatID string `json:"chat_id,omitempty"`
// Email(SMTP)
SMTPHost string `json:"smtp_host,omitempty"`
SMTPPort int `json:"smtp_port,omitempty"`
SMTPSecurity SMTPSecurity `json:"smtp_security,omitempty"`
Username string `json:"username,omitempty"`
From string `json:"from,omitempty"`
To []string `json:"to,omitempty"`
}
Settings 는 비밀이 아닌 채널 설정이다. 채널 종류에 맞는 칸만 남는다(Validate 가 나머지를 지운다).
type ValidationError ¶
ValidationError 는 채널 설정 한 칸이 잘못됐다는 뜻이다. Field 는 API 의 필드 이름이다.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string