Compare commits

...

3 commits

Author SHA1 Message Date
fbe182580e Fix example usage
All checks were successful
ci/woodpecker/push/oci-image-build Pipeline was successful
2024-03-08 21:10:56 +01:00
4448d3afa1 Add flag validation 2024-03-08 21:10:34 +01:00
a603a56306 Add flag validation 2024-03-08 21:05:09 +01:00
2 changed files with 27 additions and 3 deletions

View file

@ -7,11 +7,9 @@ registry.
```yaml ```yaml
delete-tag: delete-tag:
image: rg.fr-par.scw.cloud/hamburghammer/scaleway-delete-image-plugin/plugin image: rg.fr-par.scw.cloud/hamburghammer/scaleway-delete-image-plugin
secrets: [token] secrets: [token]
settings: settings:
token:
from_secret: scaleway_token
image-name: foo/bar image-name: foo/bar
tag: latest tag: latest
region: fr-par region: fr-par

26
main.go
View file

@ -3,6 +3,7 @@ package main
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
@ -54,6 +55,14 @@ func (p *Plugin) Flags() []cli.Flag {
} }
func (p *Plugin) Execute(ctx context.Context) error { func (p *Plugin) Execute(ctx context.Context) error {
missingFlags := requiredFlags(p.Settings)
if len(missingFlags) != 0 {
log.Error().Msg("following flags are missing:")
for _, errMsg := range missingFlags {
log.Error().Msg("-" + errMsg)
}
return errors.New("missing required flags")
}
log.Info().Msg("start") log.Info().Msg("start")
token := p.Settings.Token token := p.Settings.Token
region := p.Settings.Region region := p.Settings.Region
@ -78,6 +87,23 @@ func (p *Plugin) Execute(ctx context.Context) error {
return nil return nil
} }
func requiredFlags(settings *Settings) []string {
var errorList []string
if settings.ImageName == "" {
errorList = append(errorList, "image-name")
}
if settings.Tag == "" {
errorList = append(errorList, "tag")
}
if settings.Region == "" {
errorList = append(errorList, "region")
}
if settings.Token == "" {
errorList = append(errorList, "token")
}
return errorList
}
func main() { func main() {
p := &Plugin{ p := &Plugin{
Settings: &Settings{}, Settings: &Settings{},