|
| 1 | +package notification |
| 2 | + |
| 3 | +import ( |
| 4 | + "net/http" |
| 5 | + |
| 6 | + "buf.build/gen/go/openstatus/api/connectrpc/gosimple/openstatus/notification/v1/notificationv1connect" |
| 7 | + notificationv1 "buf.build/gen/go/openstatus/api/protocolbuffers/go/openstatus/notification/v1" |
| 8 | + "connectrpc.com/connect" |
| 9 | + "github.com/openstatusHQ/cli/internal/api" |
| 10 | + "github.com/urfave/cli/v3" |
| 11 | +) |
| 12 | + |
| 13 | +func NewNotificationClient(apiKey string) notificationv1connect.NotificationServiceClient { |
| 14 | + return notificationv1connect.NewNotificationServiceClient( |
| 15 | + api.DefaultHTTPClient, |
| 16 | + api.ConnectBaseURL, |
| 17 | + connect.WithInterceptors(api.NewAuthInterceptor(apiKey)), |
| 18 | + connect.WithProtoJSON(), |
| 19 | + ) |
| 20 | +} |
| 21 | + |
| 22 | +func NewNotificationClientWithHTTPClient(httpClient *http.Client, apiKey string) notificationv1connect.NotificationServiceClient { |
| 23 | + return notificationv1connect.NewNotificationServiceClient( |
| 24 | + httpClient, |
| 25 | + api.ConnectBaseURL, |
| 26 | + connect.WithInterceptors(api.NewAuthInterceptor(apiKey)), |
| 27 | + connect.WithProtoJSON(), |
| 28 | + ) |
| 29 | +} |
| 30 | + |
| 31 | +func providerToString(p notificationv1.NotificationProvider) string { |
| 32 | + switch p { |
| 33 | + case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_DISCORD: |
| 34 | + return "discord" |
| 35 | + case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_EMAIL: |
| 36 | + return "email" |
| 37 | + case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_GOOGLE_CHAT: |
| 38 | + return "google_chat" |
| 39 | + case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_GRAFANA_ONCALL: |
| 40 | + return "grafana_oncall" |
| 41 | + case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_NTFY: |
| 42 | + return "ntfy" |
| 43 | + case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_PAGERDUTY: |
| 44 | + return "pagerduty" |
| 45 | + case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_OPSGENIE: |
| 46 | + return "opsgenie" |
| 47 | + case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_SLACK: |
| 48 | + return "slack" |
| 49 | + case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_SMS: |
| 50 | + return "sms" |
| 51 | + case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_TELEGRAM: |
| 52 | + return "telegram" |
| 53 | + case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_WEBHOOK: |
| 54 | + return "webhook" |
| 55 | + case notificationv1.NotificationProvider_NOTIFICATION_PROVIDER_WHATSAPP: |
| 56 | + return "whatsapp" |
| 57 | + default: |
| 58 | + return "unknown" |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +func opsgenieRegionToString(r notificationv1.OpsgenieRegion) string { |
| 63 | + switch r { |
| 64 | + case notificationv1.OpsgenieRegion_OPSGENIE_REGION_US: |
| 65 | + return "us" |
| 66 | + case notificationv1.OpsgenieRegion_OPSGENIE_REGION_EU: |
| 67 | + return "eu" |
| 68 | + default: |
| 69 | + return "unknown" |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +func NotificationCmd() *cli.Command { |
| 74 | + return &cli.Command{ |
| 75 | + Name: "notification", |
| 76 | + Aliases: []string{"n"}, |
| 77 | + Usage: "Manage notifications", |
| 78 | + Commands: []*cli.Command{ |
| 79 | + GetNotificationListCmd(), |
| 80 | + GetNotificationInfoCmd(), |
| 81 | + }, |
| 82 | + } |
| 83 | +} |
0 commit comments