Skip to content

Commit 093fe09

Browse files
committed
apply suggestions
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
1 parent d366c9a commit 093fe09

2 files changed

Lines changed: 40 additions & 19 deletions

File tree

app/controlplane/plugins/sdk/v1/fanout.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,20 @@ func WithInputMaterial(materialType schemaapi.CraftingSchema_Material_MaterialTy
119119
}
120120

121121
type NewParams struct {
122-
ID, Name, Version, Description string
123-
Logger log.Logger
124-
InputSchema *InputSchema
122+
ID string
123+
Name string
124+
Version string
125+
Description string
126+
Logger log.Logger
127+
InputSchema *InputSchema
125128
}
126129

127130
func NewFanOut(p *NewParams, opts ...NewOpt) (*FanOutIntegration, error) {
128-
base, err := NewIntegrationBase(p.ID, p.Name, p.Version, p.Description, []string{IntegrationKindFanOut}, p.InputSchema)
131+
base, err := NewIntegrationBase(
132+
&IntegrationBaseOptions{
133+
p.ID, p.Name, p.Version, p.Description, []string{IntegrationKindFanOut}, p.InputSchema,
134+
},
135+
)
129136
if err != nil {
130137
return nil, err
131138
}
@@ -195,15 +202,15 @@ func validateInputs(c *FanOutIntegration) error {
195202
// Methods to be implemented by the specific integration
196203

197204
func (i *FanOutIntegration) Register(_ context.Context, _ *RegistrationRequest) (*RegistrationResponse, error) {
198-
return nil, fmt.Errorf("not implemented")
205+
return nil, fmt.Errorf("method Register not implemented")
199206
}
200207

201208
func (i *FanOutIntegration) Attach(_ context.Context, _ *AttachmentRequest) (*AttachmentResponse, error) {
202-
return nil, fmt.Errorf("not implemented")
209+
return nil, fmt.Errorf("method Attach not implemented")
203210
}
204211

205212
func (i *FanOutIntegration) Execute(_ context.Context, _ *ExecutionRequest) error {
206-
return fmt.Errorf("not implemented")
213+
return fmt.Errorf("method Execute not implemented")
207214
}
208215

209216
// List of loaded integrations

app/controlplane/plugins/sdk/v1/integrations.go

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,46 +67,60 @@ type IntegrationBase struct {
6767
attachmentJSONSchema []byte
6868
}
6969

70+
// IntegrationBaseOptions holds the options for creating a new IntegrationBase
71+
type IntegrationBaseOptions struct {
72+
ID string
73+
Name string
74+
Version string
75+
Description string
76+
Kinds []string
77+
Schema *InputSchema
78+
}
79+
7080
// NewIntegrationBase helper to create a new IntegrationBase
71-
func NewIntegrationBase(id, name, version, description string, kinds []string, schema *InputSchema) (*IntegrationBase, error) {
81+
func NewIntegrationBase(opts *IntegrationBaseOptions) (*IntegrationBase, error) {
7282
var (
7383
registrationJSONSchema, attachmentJSONSchema []byte
7484
err error
7585
)
7686

87+
if opts == nil {
88+
return nil, fmt.Errorf("options are required")
89+
}
90+
7791
// Validate basic metadata
78-
if id == "" {
92+
if opts.ID == "" {
7993
return nil, fmt.Errorf("id is required")
8094
}
8195

82-
if version == "" {
96+
if opts.Version == "" {
8397
return nil, fmt.Errorf("version is required")
8498
}
8599

86-
if len(kinds) == 0 {
100+
if len(opts.Kinds) == 0 {
87101
return nil, fmt.Errorf("kinds is required")
88102
}
89103

90-
if schema == nil {
104+
if opts.Schema == nil {
91105
return nil, fmt.Errorf("input schema is required")
92106
}
93107

94108
// Generate JSON schemas
95-
registrationJSONSchema, err = GenerateJSONSchema(schema.Registration)
109+
registrationJSONSchema, err = GenerateJSONSchema(opts.Schema.Registration)
96110
if err != nil {
97111
return nil, fmt.Errorf("failed to generate registration JSON schema: %w", err)
98112
}
99113

100-
attachmentJSONSchema, err = GenerateJSONSchema(schema.Attachment)
114+
attachmentJSONSchema, err = GenerateJSONSchema(opts.Schema.Attachment)
101115
if err != nil {
102116
return nil, fmt.Errorf("failed to generate attachment JSON schema: %w", err)
103117
}
104118
return &IntegrationBase{
105-
ID: id,
106-
Name: name,
107-
Version: version,
108-
Description: description,
109-
Kinds: kinds,
119+
ID: opts.ID,
120+
Name: opts.Name,
121+
Version: opts.Version,
122+
Description: opts.Description,
123+
Kinds: opts.Kinds,
110124
registrationJSONSchema: registrationJSONSchema,
111125
attachmentJSONSchema: attachmentJSONSchema,
112126
}, nil

0 commit comments

Comments
 (0)