feature flag to allow multiple conversion extensions
This commit is contained in:
parent
7b42cd9bbd
commit
62f1086680
4 changed files with 20 additions and 7 deletions
|
@ -320,6 +320,10 @@ type (
|
|||
SkipVerify bool `envconfig:"DRONE_CONVERT_PLUGIN_SKIP_VERIFY"`
|
||||
CacheSize int `envconfig:"DRONE_CONVERT_PLUGIN_CACHE_SIZE" default:"10"`
|
||||
Timeout time.Duration `envconfig:"DRONE_CONVERT_TIMEOUT" default:"1m"`
|
||||
|
||||
// this flag can be removed once we solve for
|
||||
// https://github.com/harness/drone/pull/2994#issuecomment-795955312
|
||||
Multi bool `envconfig:"DRONE_CONVERT_MULTI" default:"1m"`
|
||||
}
|
||||
|
||||
// Validate provides the validation webhook configuration.
|
||||
|
|
|
@ -78,6 +78,7 @@ func provideConfigPlugin(client *scm.Client, contents core.FileService, conf spe
|
|||
// configuration.
|
||||
func provideConvertPlugin(client *scm.Client, fileService core.FileService, conf spec.Config, templateStore core.TemplateStore) core.ConvertService {
|
||||
return converter.Combine(
|
||||
conf.Convert.Multi,
|
||||
converter.Legacy(false),
|
||||
converter.Starlark(
|
||||
conf.Starlark.Enabled,
|
||||
|
|
|
@ -22,12 +22,16 @@ import (
|
|||
|
||||
// Combine combines the conversion services, provision support
|
||||
// for multiple conversion utilities.
|
||||
func Combine(services ...core.ConvertService) core.ConvertService {
|
||||
return &combined{services}
|
||||
func Combine(multi bool, services ...core.ConvertService) core.ConvertService {
|
||||
return &combined{multi: multi, sources: services}
|
||||
}
|
||||
|
||||
type combined struct {
|
||||
sources []core.ConvertService
|
||||
|
||||
// this feature flag can be removed once we solve for
|
||||
// https://github.com/harness/drone/pull/2994#issuecomment-795955312
|
||||
multi bool
|
||||
}
|
||||
|
||||
func (c *combined) Convert(ctx context.Context, req *core.ConvertArgs) (*core.Config, error) {
|
||||
|
@ -42,7 +46,11 @@ func (c *combined) Convert(ctx context.Context, req *core.ConvertArgs) (*core.Co
|
|||
if config.Data == "" {
|
||||
continue
|
||||
}
|
||||
return config, nil
|
||||
if c.multi {
|
||||
req.Config = config
|
||||
} else {
|
||||
return config, nil
|
||||
}
|
||||
}
|
||||
return req.Config, nil
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ func TestCombine(t *testing.T) {
|
|||
service := mock.NewMockConvertService(controller)
|
||||
service.EXPECT().Convert(noContext, args).Return(resp, nil)
|
||||
|
||||
result, err := Combine(service).Convert(noContext, args)
|
||||
result, err := Combine(false, service).Convert(noContext, args)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
|
@ -58,7 +58,7 @@ func TestCombineErr(t *testing.T) {
|
|||
service := mock.NewMockConvertService(controller)
|
||||
service.EXPECT().Convert(noContext, nil).Return(nil, resp)
|
||||
|
||||
_, err := Combine(service).Convert(noContext, nil)
|
||||
_, err := Combine(false, service).Convert(noContext, nil)
|
||||
if err != resp {
|
||||
t.Errorf("expected convert service error")
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ func TestCombineNoConfig(t *testing.T) {
|
|||
service3 := mock.NewMockConvertService(controller)
|
||||
service3.EXPECT().Convert(noContext, args).Return(resp, nil)
|
||||
|
||||
result, err := Combine(service1, service2, service3).Convert(noContext, args)
|
||||
result, err := Combine(false, service1, service2, service3).Convert(noContext, args)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
|
@ -110,7 +110,7 @@ func TestCombineEmptyConfig(t *testing.T) {
|
|||
service1 := mock.NewMockConvertService(controller)
|
||||
service1.EXPECT().Convert(noContext, args).Return(nil, nil)
|
||||
|
||||
result, err := Combine(service1).Convert(noContext, args)
|
||||
result, err := Combine(false, service1).Convert(noContext, args)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue