Skip to content

Commit

Permalink
Merge pull request #77 from sivchari/add-quote
Browse files Browse the repository at this point in the history
add quote
  • Loading branch information
sakajunquality authored Apr 23, 2024
2 parents 5d8e8ee + 696d9d1 commit 65dee0b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 6 additions & 1 deletion flow/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"os"
"strconv"
"strings"

"github.com/sakajunquality/cloud-pubsub-events/gcrevent"
Expand Down Expand Up @@ -32,7 +33,7 @@ func New(c *Config) (*Flow, error) {
return f, nil
}

func (f *Flow) ProcessGCREvent(ctx context.Context, e gcrevent.Event) error {
func (f *Flow) ProcessGCREvent(ctx context.Context, e gcrevent.Event, quote bool) error {
if e.Action != gcrevent.ActionInsert {
return nil
}
Expand All @@ -51,5 +52,9 @@ func (f *Flow) ProcessGCREvent(ctx context.Context, e gcrevent.Event) error {
return fmt.Errorf("image format invalid: %s", *e.Tag)
}

if quote {
version = strconv.Quote(version)
}

return f.processImage(ctx, image, version)
}
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"encoding/json"
"flag"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -38,7 +39,14 @@ var (
f *flow.Flow
)

var (
q *bool
)

func main() {
q = flag.Bool("q", true, "if true, the version is quoted. Default is true.")
flag.Parse()

cfg, err := getConfig()
if err != nil {
fmt.Fprintf(os.Stderr, "Cloud not read the file:%s.\n", err)
Expand Down Expand Up @@ -101,7 +109,7 @@ func handlePubSubMessage(w http.ResponseWriter, r *http.Request) {
return
}

err = f.ProcessGCREvent(ctx, event)
err = f.ProcessGCREvent(ctx, event, *q)
log.Printf("process: %s", err)

res := &Response{
Expand Down

0 comments on commit 65dee0b

Please sign in to comment.