Skip to content

Commit 60077ff

Browse files
authored
feat: nats event publisher + user events (#1629)
Signed-off-by: Miguel Martinez <[email protected]>
1 parent c6d1b2d commit 60077ff

39 files changed

+1247
-350
lines changed

app/controlplane/cmd/main.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package main
1717

1818
import (
1919
"context"
20+
"fmt"
2021
"os"
2122
"time"
2223

@@ -25,6 +26,7 @@ import (
2526
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/ca/ejbca"
2627
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/ca/fileca"
2728
"github.com/getsentry/sentry-go"
29+
"github.com/nats-io/nats.go"
2830
flag "github.com/spf13/pflag"
2931

3032
conf "github.com/chainloop-dev/chainloop/app/controlplane/internal/conf/controlplane/config/v1"
@@ -145,6 +147,7 @@ func main() {
145147
if err != nil {
146148
panic(err)
147149
}
150+
148151
app, cleanup, err := wireApp(&bc, credsWriter, logger, availablePlugins, ca)
149152
if err != nil {
150153
panic(err)
@@ -178,6 +181,21 @@ type app struct {
178181
tokenAuthSyncer *biz.APITokenSyncerUseCase
179182
}
180183

184+
// Connection to nats is optional, if not configured, pubsub will be disabled
185+
func newNatsConnection(c *conf.Bootstrap_NatsServer) (*nats.Conn, error) {
186+
uri := c.GetUri()
187+
if uri == "" {
188+
return nil, nil
189+
}
190+
191+
nc, err := nats.Connect(uri)
192+
if err != nil {
193+
return nil, fmt.Errorf("failed to connect to nats: %w", err)
194+
}
195+
196+
return nc, nil
197+
}
198+
181199
func filterSensitiveArgs(_ log.Level, keyvals ...interface{}) bool {
182200
for i := 0; i < len(keyvals); i++ {
183201
if keyvals[i] == "operation" {

app/controlplane/cmd/wire.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ import (
2525
"github.com/chainloop-dev/chainloop/app/controlplane/internal/dispatcher"
2626
"github.com/chainloop-dev/chainloop/app/controlplane/internal/server"
2727
"github.com/chainloop-dev/chainloop/app/controlplane/internal/service"
28+
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/auditor"
2829
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/authz"
2930
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/biz"
3031
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/ca"
@@ -49,7 +50,7 @@ func wireApp(*conf.Bootstrap, credentials.ReaderWriter, log.Logger, sdk.Availabl
4950
wire.Bind(new(biz.CASClient), new(*biz.CASClientUseCase)),
5051
serviceOpts,
5152
wire.Value([]biz.CASClientOpts{}),
52-
wire.FieldsOf(new(*conf.Bootstrap), "Server", "Auth", "Data", "CasServer", "ReferrerSharedIndex", "Onboarding", "PrometheusIntegration", "PolicyProviders"),
53+
wire.FieldsOf(new(*conf.Bootstrap), "Server", "Auth", "Data", "CasServer", "ReferrerSharedIndex", "Onboarding", "PrometheusIntegration", "PolicyProviders", "NatsServer"),
5354
wire.FieldsOf(new(*conf.Data), "Database"),
5455
dispatcher.New,
5556
authz.NewDatabaseEnforcer,
@@ -58,6 +59,8 @@ func wireApp(*conf.Bootstrap, credentials.ReaderWriter, log.Logger, sdk.Availabl
5859
newProtoValidator,
5960
newDataConf,
6061
newPolicyProviderConfig,
62+
newNatsConnection,
63+
auditor.NewAuditLogPublisher,
6164
),
6265
)
6366
}

app/controlplane/cmd/wire_gen.go

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/configs/config.devel.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ server:
1616
# certificate: "../../devel/devkeys/selfsigned/controlplane.crt"
1717
# private_key: "../../devel/devkeys/selfsigned/controlplane.key"
1818

19+
nats_server:
20+
uri: nats://0.0.0.0:4222
21+
1922
certificate_authority:
2023
file_ca:
2124
cert_path: ${FILE_CA_CERT_PATH:../../devel/devkeys/ca.pub}

app/controlplane/configs/samples/config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ cas_server:
3030
# Where to redirect the user to download artifacts from the CAS
3131
download_url: http://0.0.0.0:8001/download
3232

33+
# nats endpoint where to send events
34+
nats_server:
35+
uri: nats://0.0.0.0:4222
36+
3337
# Where to store credentials such as OCI registries or third party integrations secrets
3438
credentials_service:
3539
vault:

0 commit comments

Comments
 (0)