You've already forked woodpecker
mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-11-29 21:48:14 +02:00
Remove plugin-only option from secrets (#2213)
This commit is contained in:
@@ -41,14 +41,13 @@ type Registry struct {
|
||||
}
|
||||
|
||||
type Secret struct {
|
||||
Name string
|
||||
Value string
|
||||
Match []string
|
||||
PluginOnly bool
|
||||
Name string
|
||||
Value string
|
||||
AllowedPlugins []string
|
||||
}
|
||||
|
||||
func (s *Secret) Available(container *yaml_types.Container) bool {
|
||||
return (len(s.Match) == 0 || utils.MatchImage(container.Image, s.Match...)) && (!s.PluginOnly || container.IsPlugin())
|
||||
return (len(s.AllowedPlugins) == 0 || utils.MatchImage(container.Image, s.AllowedPlugins...)) && (len(s.AllowedPlugins) == 0 || container.IsPlugin())
|
||||
}
|
||||
|
||||
type secretMap map[string]Secret
|
||||
|
||||
@@ -28,33 +28,28 @@ import (
|
||||
|
||||
func TestSecretAvailable(t *testing.T) {
|
||||
secret := Secret{
|
||||
Match: []string{"golang"},
|
||||
PluginOnly: false,
|
||||
AllowedPlugins: []string{},
|
||||
}
|
||||
assert.True(t, secret.Available(&yaml_types.Container{
|
||||
Image: "golang",
|
||||
Commands: yaml_base_types.StringOrSlice{"echo 'this is not a plugin'"},
|
||||
}))
|
||||
assert.False(t, secret.Available(&yaml_types.Container{
|
||||
Image: "not-golang",
|
||||
Commands: yaml_base_types.StringOrSlice{"echo 'this is not a plugin'"},
|
||||
}))
|
||||
|
||||
// secret only available for "golang" plugin
|
||||
secret = Secret{
|
||||
Match: []string{"golang"},
|
||||
PluginOnly: true,
|
||||
AllowedPlugins: []string{"golang"},
|
||||
}
|
||||
assert.True(t, secret.Available(&yaml_types.Container{
|
||||
Image: "golang",
|
||||
Commands: yaml_base_types.StringOrSlice{},
|
||||
}))
|
||||
assert.False(t, secret.Available(&yaml_types.Container{
|
||||
Image: "not-golang",
|
||||
Commands: yaml_base_types.StringOrSlice{},
|
||||
Image: "golang",
|
||||
Commands: yaml_base_types.StringOrSlice{"echo 'this is not a plugin'"},
|
||||
}))
|
||||
assert.False(t, secret.Available(&yaml_types.Container{
|
||||
Image: "not-golang",
|
||||
Commands: yaml_base_types.StringOrSlice{"echo 'this is not a plugin'"},
|
||||
Commands: yaml_base_types.StringOrSlice{},
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user