mirror of
https://github.com/harness/drone.git
synced 2025-05-04 10:10:14 +08:00
feature flag to allow multiple conversion extensions
This commit is contained in:
parent
7b42cd9bbd
commit
62f1086680
@ -320,6 +320,10 @@ type (
|
|||||||
SkipVerify bool `envconfig:"DRONE_CONVERT_PLUGIN_SKIP_VERIFY"`
|
SkipVerify bool `envconfig:"DRONE_CONVERT_PLUGIN_SKIP_VERIFY"`
|
||||||
CacheSize int `envconfig:"DRONE_CONVERT_PLUGIN_CACHE_SIZE" default:"10"`
|
CacheSize int `envconfig:"DRONE_CONVERT_PLUGIN_CACHE_SIZE" default:"10"`
|
||||||
Timeout time.Duration `envconfig:"DRONE_CONVERT_TIMEOUT" default:"1m"`
|
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.
|
// Validate provides the validation webhook configuration.
|
||||||
|
@ -78,6 +78,7 @@ func provideConfigPlugin(client *scm.Client, contents core.FileService, conf spe
|
|||||||
// configuration.
|
// configuration.
|
||||||
func provideConvertPlugin(client *scm.Client, fileService core.FileService, conf spec.Config, templateStore core.TemplateStore) core.ConvertService {
|
func provideConvertPlugin(client *scm.Client, fileService core.FileService, conf spec.Config, templateStore core.TemplateStore) core.ConvertService {
|
||||||
return converter.Combine(
|
return converter.Combine(
|
||||||
|
conf.Convert.Multi,
|
||||||
converter.Legacy(false),
|
converter.Legacy(false),
|
||||||
converter.Starlark(
|
converter.Starlark(
|
||||||
conf.Starlark.Enabled,
|
conf.Starlark.Enabled,
|
||||||
|
@ -22,12 +22,16 @@ import (
|
|||||||
|
|
||||||
// Combine combines the conversion services, provision support
|
// Combine combines the conversion services, provision support
|
||||||
// for multiple conversion utilities.
|
// for multiple conversion utilities.
|
||||||
func Combine(services ...core.ConvertService) core.ConvertService {
|
func Combine(multi bool, services ...core.ConvertService) core.ConvertService {
|
||||||
return &combined{services}
|
return &combined{multi: multi, sources: services}
|
||||||
}
|
}
|
||||||
|
|
||||||
type combined struct {
|
type combined struct {
|
||||||
sources []core.ConvertService
|
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) {
|
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 == "" {
|
if config.Data == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return config, nil
|
if c.multi {
|
||||||
|
req.Config = config
|
||||||
|
} else {
|
||||||
|
return config, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return req.Config, nil
|
return req.Config, nil
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ func TestCombine(t *testing.T) {
|
|||||||
service := mock.NewMockConvertService(controller)
|
service := mock.NewMockConvertService(controller)
|
||||||
service.EXPECT().Convert(noContext, args).Return(resp, nil)
|
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 {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
@ -58,7 +58,7 @@ func TestCombineErr(t *testing.T) {
|
|||||||
service := mock.NewMockConvertService(controller)
|
service := mock.NewMockConvertService(controller)
|
||||||
service.EXPECT().Convert(noContext, nil).Return(nil, resp)
|
service.EXPECT().Convert(noContext, nil).Return(nil, resp)
|
||||||
|
|
||||||
_, err := Combine(service).Convert(noContext, nil)
|
_, err := Combine(false, service).Convert(noContext, nil)
|
||||||
if err != resp {
|
if err != resp {
|
||||||
t.Errorf("expected convert service error")
|
t.Errorf("expected convert service error")
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ func TestCombineNoConfig(t *testing.T) {
|
|||||||
service3 := mock.NewMockConvertService(controller)
|
service3 := mock.NewMockConvertService(controller)
|
||||||
service3.EXPECT().Convert(noContext, args).Return(resp, nil)
|
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 {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
@ -110,7 +110,7 @@ func TestCombineEmptyConfig(t *testing.T) {
|
|||||||
service1 := mock.NewMockConvertService(controller)
|
service1 := mock.NewMockConvertService(controller)
|
||||||
service1.EXPECT().Convert(noContext, args).Return(nil, nil)
|
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 {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user