Add slack integration

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2025-10-15 23:41:59 +02:00
parent 8302b11614
commit de004ce8d7
38 changed files with 2621 additions and 1578 deletions

View File

@@ -17,15 +17,16 @@ package probod
import (
"encoding/json"
"fmt"
"strings"
"github.com/getprobo/probo/pkg/connector"
)
type (
connectorConfig struct {
Name string `json:"name"`
Type connector.ProtocolType `json:"type"`
Config connector.Connector `json:"-"`
Provider string `json:"provider"`
Protocol connector.ProtocolType `json:"protocol"`
Config connector.Connector `json:"-"`
}
connectorConfigOAuth2 struct {
@@ -40,19 +41,19 @@ type (
func (c *connectorConfig) UnmarshalJSON(data []byte) error {
var tmp struct {
Name string `json:"name"`
Type connector.ProtocolType `json:"type"`
RawConfig json.RawMessage `json:"config"`
Provider string `json:"provider"`
Protocol string `json:"protocol"`
RawConfig json.RawMessage `json:"config"`
}
if err := json.Unmarshal(data, &tmp); err != nil {
return fmt.Errorf("cannot unmarshal connector config: %w", err)
}
c.Name = tmp.Name
c.Type = tmp.Type
c.Provider = strings.ToUpper(tmp.Provider)
c.Protocol = connector.ProtocolType(strings.ToUpper(tmp.Protocol))
switch tmp.Type {
switch c.Protocol {
case connector.ProtocolOAuth2:
var config connectorConfigOAuth2
if err := json.Unmarshal(tmp.RawConfig, &config); err != nil {
@@ -70,7 +71,7 @@ func (c *connectorConfig) UnmarshalJSON(data []byte) error {
c.Config = &oauth2Connector
default:
return fmt.Errorf("unknown connector type: %q", tmp.Type)
return fmt.Errorf("unknown connector protocol: %q", c.Protocol)
}
return nil

View File

@@ -45,6 +45,7 @@ import (
"github.com/getprobo/probo/pkg/saferedirect"
"github.com/getprobo/probo/pkg/server"
"github.com/getprobo/probo/pkg/server/api"
"github.com/getprobo/probo/pkg/slack"
"github.com/getprobo/probo/pkg/trust"
"github.com/prometheus/client_golang/prometheus"
"go.gearno.de/kit/httpclient"
@@ -72,6 +73,7 @@ type (
TrustCenter trustCenterConfig `json:"trust-center"`
AWS awsConfig `json:"aws"`
Mailer mailerConfig `json:"mailer"`
Slack slackConfig `json:"slack"`
Connectors []connectorConfig `json:"connectors"`
OpenAI openaiConfig `json:"openai"`
ChromeDPAddr string `json:"chrome-dp-addr"`
@@ -143,6 +145,9 @@ func New() *Implm {
Addr: "localhost:1025",
},
},
Slack: slackConfig{
SenderInterval: 60,
},
CustomDomains: customDomainsConfig{
RenewalInterval: 3600,
ProvisionInterval: 30,
@@ -204,6 +209,7 @@ func (impl *Implm) Run(
return fmt.Errorf("cannot get trust auth token secret bytes: %w", err)
}
awsConfig := awsconfig.NewConfig(
l,
httpclient.DefaultPooledClient(
@@ -239,7 +245,7 @@ func (impl *Implm) Run(
defaultConnectorRegistry := connector.NewConnectorRegistry()
for _, connector := range impl.cfg.Connectors {
if err := defaultConnectorRegistry.Register(connector.Name, connector.Config); err != nil {
if err := defaultConnectorRegistry.Register(connector.Provider, connector.Config); err != nil {
return fmt.Errorf("cannot register connector: %w", err)
}
}
@@ -338,6 +344,7 @@ func (impl *Implm) Run(
pgClient,
s3Client,
impl.cfg.AWS.Bucket,
impl.cfg.Hostname,
impl.cfg.EncryptionKey,
impl.cfg.TrustAuth.TokenSecret,
authService,
@@ -408,6 +415,18 @@ func (impl *Implm) Run(
},
)
slackSenderCtx, stopSlackSender := context.WithCancel(context.Background())
slackSender := slack.NewSender(pgClient, l.Named("slack-sender"), impl.cfg.EncryptionKey, slack.Config{
Interval: time.Duration(impl.cfg.Slack.SenderInterval) * time.Second,
})
wg.Go(
func() {
if err := slackSender.Run(slackSenderCtx); err != nil {
cancel(fmt.Errorf("slack sender crashed: %w", err))
}
},
)
exportJobExporterCtx, stopExportJobExporter := context.WithCancel(context.Background())
wg.Go(
func() {
@@ -430,6 +449,7 @@ func (impl *Implm) Run(
<-ctx.Done()
stopMailer()
stopSlackSender()
stopExportJobExporter()
stopApiServer()
stopTrustCenterServer()

View File

@@ -0,0 +1,21 @@
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package probod
type (
slackConfig struct {
SenderInterval int `json:"sender-interval"`
}
)