Skip to content

Commit a045f1e

Browse files
authored
chore: expose referrer config (#2472)
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
1 parent 2d52268 commit a045f1e

File tree

6 files changed

+40
-21
lines changed

6 files changed

+40
-21
lines changed

app/controlplane/cmd/wire_gen.go

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

app/controlplane/pkg/biz/biz.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ var ProviderSet = wire.NewSet(
5858
NewUserAccessSyncerUseCase,
5959
NewGroupUseCase,
6060
NewCASBackendChecker,
61+
NewIndexConfig,
6162
wire.Bind(new(PromObservable), new(*PrometheusUseCase)),
6263
wire.Struct(new(NewIntegrationUseCaseOpts), "*"),
6364
wire.Struct(new(NewUserUseCaseParams), "*"),

app/controlplane/pkg/biz/referrer.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,33 @@ type ReferrerUseCase struct {
3939
membershipUseCase *MembershipUseCase
4040
workflowRepo WorkflowRepo
4141
logger *log.Helper
42-
indexConfig *conf.ReferrerSharedIndex
42+
indexConfig *ReferrerSharedIndexConfig
4343
}
4444

45-
func NewReferrerUseCase(repo ReferrerRepo, wfRepo WorkflowRepo, membershipUseCase *MembershipUseCase, indexCfg *conf.ReferrerSharedIndex, l log.Logger) (*ReferrerUseCase, error) {
45+
type ReferrerSharedIndexConfig struct {
46+
Enabled bool
47+
AllowedOrgs []string
48+
}
49+
50+
func NewIndexConfig(cfg *conf.ReferrerSharedIndex) (*ReferrerSharedIndexConfig, error) {
51+
if err := cfg.ValidateOrgs(); err != nil {
52+
return nil, fmt.Errorf("invalid shared index config: %w", err)
53+
}
54+
55+
return &ReferrerSharedIndexConfig{
56+
Enabled: cfg.Enabled,
57+
AllowedOrgs: cfg.AllowedOrgs,
58+
}, nil
59+
}
60+
61+
func NewReferrerUseCase(repo ReferrerRepo, wfRepo WorkflowRepo, membershipUseCase *MembershipUseCase, indexCfg *ReferrerSharedIndexConfig, l log.Logger) (*ReferrerUseCase, error) {
4662
if l == nil {
4763
l = log.NewStdLogger(io.Discard)
4864
}
4965
logger := servicelogger.ScopedHelper(l, "biz/referrer")
5066

51-
if indexCfg != nil {
52-
if err := indexCfg.ValidateOrgs(); err != nil {
53-
return nil, fmt.Errorf("invalid shared index config: %w", err)
54-
}
55-
56-
if indexCfg.Enabled {
57-
logger.Infow("msg", "shared index enabled", "allowedOrgs", indexCfg.AllowedOrgs)
58-
}
67+
if indexCfg != nil && indexCfg.Enabled {
68+
logger.Infow("msg", "shared index enabled", "allowedOrgs", indexCfg.AllowedOrgs)
5969
}
6070

6171
return &ReferrerUseCase{

app/controlplane/pkg/biz/referrer_integration_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"sync"
2424
"testing"
2525

26-
conf "github.com/chainloop-dev/chainloop/app/controlplane/internal/conf/controlplane/config/v1"
2726
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/biz"
2827
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/biz/testhelpers"
2928
"github.com/chainloop-dev/chainloop/pkg/credentials"
@@ -88,7 +87,7 @@ func (s *referrerIntegrationTestSuite) TestGetFromRootInPublicSharedIndex() {
8887

8988
s.T().Run("it should appear if we whitelist org2", func(t *testing.T) {
9089
uc, err := biz.NewReferrerUseCase(s.Repos.Referrer, s.Repos.Workflow, s.Membership,
91-
&conf.ReferrerSharedIndex{
90+
&biz.ReferrerSharedIndexConfig{
9291
Enabled: true,
9392
AllowedOrgs: []string{s.org2.ID},
9493
}, nil)
@@ -464,7 +463,7 @@ func (s *referrerIntegrationTestSuite) SetupTest() {
464463
require.NoError(s.T(), err)
465464

466465
s.sharedEnabledUC, err = biz.NewReferrerUseCase(s.Repos.Referrer, s.Repos.Workflow, s.Membership,
467-
&conf.ReferrerSharedIndex{
466+
&biz.ReferrerSharedIndexConfig{
468467
Enabled: true,
469468
AllowedOrgs: []string{s.org1.ID},
470469
}, nil)

app/controlplane/pkg/biz/referrer_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"os"
2222
"testing"
2323

24-
conf "github.com/chainloop-dev/chainloop/app/controlplane/internal/conf/controlplane/config/v1"
2524
v1 "github.com/google/go-containerregistry/pkg/v1"
2625
"github.com/secure-systems-lab/go-securesystemslib/dsse"
2726
"github.com/stretchr/testify/assert"
@@ -32,36 +31,36 @@ import (
3231
func (s *referrerTestSuite) TestInitialization() {
3332
testCases := []struct {
3433
name string
35-
conf *conf.ReferrerSharedIndex
34+
conf *ReferrerSharedIndexConfig
3635
wantErrMsg string
3736
}{
3837
{
3938
name: "nil configuration",
4039
},
4140
{
4241
name: "disabled",
43-
conf: &conf.ReferrerSharedIndex{
42+
conf: &ReferrerSharedIndexConfig{
4443
Enabled: false,
4544
},
4645
},
4746
{
4847
name: "enabled but without orgs",
49-
conf: &conf.ReferrerSharedIndex{
48+
conf: &ReferrerSharedIndexConfig{
5049
Enabled: true,
5150
},
5251
wantErrMsg: "invalid shared index config: index is enabled, but no orgs are allowed",
5352
},
5453
{
5554
name: "enabled with invalid orgs",
56-
conf: &conf.ReferrerSharedIndex{
55+
conf: &ReferrerSharedIndexConfig{
5756
Enabled: true,
5857
AllowedOrgs: []string{"invalid"},
5958
},
6059
wantErrMsg: "invalid shared index config: invalid org id: invalid",
6160
},
6261
{
6362
name: "enabled with valid orgs",
64-
conf: &conf.ReferrerSharedIndex{
63+
conf: &ReferrerSharedIndexConfig{
6564
Enabled: true,
6665
AllowedOrgs: []string{"00000000-0000-0000-0000-000000000000"},
6766
},

app/controlplane/pkg/biz/testhelpers/wire_gen.go

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

0 commit comments

Comments
 (0)