Skip to content

Commit e25e6eb

Browse files
authored
doc(integrations): create template (#144)
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
1 parent 7afd4bd commit e25e6eb

26 files changed

+922
-115
lines changed

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ linters:
1212
- nakedret
1313
- revive
1414
- gosec
15-
- depguard
1615
- asciicheck
1716
- whitespace
1817
- errorlint

app/cli/internal/action/integration_add_deptrack.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import (
1919
"context"
2020

2121
pb "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1"
22-
deptrack "github.com/chainloop-dev/chainloop/app/controlplane/extensions/dependencytrack/v1"
23-
cxpb "github.com/chainloop-dev/chainloop/app/controlplane/extensions/dependencytrack/v1/api"
22+
deptrack "github.com/chainloop-dev/chainloop/app/controlplane/extensions/core/dependencytrack/v1"
23+
cxpb "github.com/chainloop-dev/chainloop/app/controlplane/extensions/core/dependencytrack/v1/api"
2424
"google.golang.org/protobuf/types/known/anypb"
2525
)
2626

app/cli/internal/action/workflow_integration_attach.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"context"
2020

2121
pb "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1"
22-
cxpb "github.com/chainloop-dev/chainloop/app/controlplane/extensions/dependencytrack/v1/api"
22+
cxpb "github.com/chainloop-dev/chainloop/app/controlplane/extensions/core/dependencytrack/v1/api"
2323
"google.golang.org/protobuf/types/known/anypb"
2424
)
2525

app/controlplane/Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ api:
1111
cd ./api && buf generate
1212
cd ./extensions && buf generate
1313

14-
.PHONY: api-integrations
14+
.PHONY: api-extensions
1515
# generate integrations proto bindings
16-
api-integrations:
17-
cd ./integrations && buf generate
16+
api-extensions:
17+
cd ./extensions && buf generate
1818

1919
.PHONY: build
2020
# build
@@ -43,13 +43,13 @@ test-unit:
4343
# lint
4444
lint:
4545
buf lint api
46-
buf lint integrations
46+
buf lint extensions
4747
buf lint internal/conf
4848
golangci-lint run
4949

5050
.PHONY: generate
5151
# generate proto bindings, wire injectors, and ent models
52-
generate: api config api-integrations
52+
generate: api config api-extensions
5353
go generate ./...
5454

5555
.PHONY: all

app/controlplane/cmd/main.go

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

1818
import (
1919
"context"
20-
"fmt"
2120
"os"
2221
"time"
2322

2423
"github.com/getsentry/sentry-go"
2524
flag "github.com/spf13/pflag"
2625

27-
"github.com/chainloop-dev/chainloop/app/controlplane/extensions/sdk/v1"
2826
"github.com/chainloop-dev/chainloop/app/controlplane/internal/biz"
2927
"github.com/chainloop-dev/chainloop/app/controlplane/internal/conf"
3028
"github.com/chainloop-dev/chainloop/app/controlplane/internal/server"
3129
credsConfig "github.com/chainloop-dev/chainloop/internal/credentials/api/credentials/v1"
3230
"github.com/chainloop-dev/chainloop/internal/servicelogger"
3331

34-
deptrack "github.com/chainloop-dev/chainloop/app/controlplane/extensions/dependencytrack/v1"
3532
"github.com/go-kratos/kratos/v2"
3633
"github.com/go-kratos/kratos/v2/config"
3734
"github.com/go-kratos/kratos/v2/config/env"
@@ -127,21 +124,6 @@ func main() {
127124
}
128125
}
129126

130-
// Load the available third party integrations
131-
// In the future this code will iterate over a dynamic directory of plugins
132-
// and try to load them one by one
133-
func loadExtensions(l log.Logger) (sdk.Loaded, error) {
134-
var res sdk.Loaded
135-
136-
var d sdk.FanOut
137-
d, err := deptrack.NewIntegration(l)
138-
if err != nil {
139-
return nil, fmt.Errorf("failed to load dependency track extension: %w", err)
140-
}
141-
142-
return append(res, d), nil
143-
}
144-
145127
type app struct {
146128
*kratos.App
147129
// Periodic job that expires unfinished attestation processes older than a given threshold

app/controlplane/cmd/wire.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package main
2222

2323
import (
24+
"github.com/chainloop-dev/chainloop/app/controlplane/extensions"
2425
"github.com/chainloop-dev/chainloop/app/controlplane/internal/biz"
2526
"github.com/chainloop-dev/chainloop/app/controlplane/internal/conf"
2627
"github.com/chainloop-dev/chainloop/app/controlplane/internal/data"
@@ -48,7 +49,7 @@ func wireApp(*conf.Bootstrap, credentials.ReaderWriter, log.Logger) (*app, func(
4849
serviceOpts,
4950
wire.Value([]biz.CASClientOpts{}),
5051
wire.FieldsOf(new(*conf.Bootstrap), "Server", "Auth", "Data", "CasServer"),
51-
loadExtensions,
52+
extensions.Load,
5253
dispatcher.New,
5354
newApp,
5455
),

app/controlplane/cmd/wire_gen.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Chainloop Extensions
2+
3+
Chainloop extensions are a way to extend the functionality of the Chainloop.
4+
5+
Currently we only support one type, fan-out extensions. FanOut extensions implement logic that will get executed when attestations or materials are received,
6+
7+
## Anatomy of a FanOut Extension
8+
9+
### Lifecycle
10+
11+
An fanOut extension goes through 4 different stages. Loading, Registration, Attachment and Execution
12+
13+
#### Loading
14+
15+
Loading is when the extension gets enabled in the Chainloop Control plane. This is implemented via the extension constructor. At this time is when you, as a developer, can configure the identity of the extension and what kind of input you are expecting to receive. Materials, attestations or both.
16+
17+
Example:
18+
19+
- Load the dependency track instance extension
20+
21+
#### Registration
22+
23+
Registration is when a specific instance of the extension is configured on a Chainloop organization. A registered instance is then available to be attached to any workflow, more on that later.
24+
25+
Example:
26+
27+
- Register a dependency track instance by receiving its URL and API key. At this stage, the extension will make sure that the provided information is valid and store it for later use.
28+
29+
#### Attachment
30+
31+
Attachment happens when a registered instance is attached to a Workflow. This means that any attestations or materials that are received by the workflow will be sent to the attached extension for processing.
32+
33+
Example:
34+
35+
- Tell the already registered dependency track instance to send the SBOMs to a specific project.
36+
37+
#### Execution
38+
39+
This is the actual execution of the extension. This is where the extension will do its work. i.e call a workflow, or send a notification.
40+
41+
Example:
42+
43+
In the dependency track use-case we will
44+
45+
- Get the instance URL and API key from the state stored during the registration phase
46+
- Get the specific project where we want to post the SBOMs from the attachment phase
47+
- Send the SBOMs to the dependency track instance
48+
49+
## How to create a new extension
50+
51+
52+
We offer a starter template in `./core/template`. Just copy it to a new folder and follow the steps shown in its readme.
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
version: v1
22
plugins:
33
- name: go
4-
out: .
5-
opt: paths=source_relative
6-
- name: go-grpc
74
out: .
85
opt:
96
- paths=source_relative
10-
- name: go-http
11-
out: .
12-
opt: paths=source_relative
137
- name: validate
148
out: .
15-
opt: paths=source_relative,lang=go
9+
opt:
10+
- paths=source_relative
11+
- lang=go
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### Dependency-Track fan-out Extension
2+
3+
This extension implements sending cycloneDX Software Bill of Materials (SBOM) to Dependency-Track.
4+
5+
See https://docs.chainloop.dev/guides/dependency-track/

0 commit comments

Comments
 (0)