Skip to content

Commit

Permalink
Merge pull request #216 from ivanilves/release-v1.2.12
Browse files Browse the repository at this point in the history
Bugfix release: 1.2.12
  • Loading branch information
vonrabbe authored Jan 21, 2020
2 parents f8fde35 + 29726ba commit d6888d7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
10 changes: 9 additions & 1 deletion api/v1/registry/client/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (t *token) Exists(key string) bool {
_, defined := t.items[key]

if !defined && WaitBetween != 0 {
log.Debugf("Locking token operations for %v (key: %s)", WaitBetween, key)
log.Debugf("[EXISTS] Locking token operations for %v (key: %s)", WaitBetween, key)
time.Sleep(WaitBetween)
}

Expand All @@ -38,6 +38,14 @@ func (t *token) Exists(key string) bool {

// Get gets token for a passed key
func (t *token) Get(key string) auth.Token {
t.mux.Lock()
defer t.mux.Unlock()

if WaitBetween != 0 {
log.Debugf("[GET] Locking token operations for %v (key: %s)", WaitBetween, key)
time.Sleep(WaitBetween)
}

return t.items[key]
}

Expand Down
33 changes: 32 additions & 1 deletion api/v1/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"html/template"
"io"
"regexp"
"runtime"
"strings"
"time"
Expand Down Expand Up @@ -235,6 +236,26 @@ func getPushPrefix(prefix, defaultPrefix string) string {
return prefix
}

func validatePushPrefix(prefix string) error {
const ex = `^/[a-z0-9_][a-z0-9_\-\.\/]+/$`

if prefix == "/" {
return nil
}

matched, err := regexp.MatchString(ex, prefix)

if err != nil {
return err
}

if !matched {
return fmt.Errorf("Push prefix \"%s\" does not match valid pattern: %s", prefix, ex)
}

return nil
}

// CollectPushTags blends passed collection with information fetched from [local] "push" registry,
// makes required comparisons between them and spits organized info back as collection.Collection
func (api *API) CollectPushTags(cn *collection.Collection, push PushConfig) (*collection.Collection, error) {
Expand All @@ -257,7 +278,13 @@ func (api *API) CollectPushTags(cn *collection.Collection, push PushConfig) (*co
go func(repo *repository.Repository, i int, done chan error) {
refs[i] = repo.Ref()

pushPath, perr := pushPathTemplate(getPushPrefix(push.Prefix, repo.PushPrefix()), repo.PushPath(push.PathSeparator), repo.Name())
pushPrefix := getPushPrefix(push.Prefix, repo.PushPrefix())
if err := validatePushPrefix(pushPrefix); err != nil {
done <- err
return
}

pushPath, perr := pushPathTemplate(pushPrefix, repo.PushPath(push.PathSeparator), repo.Name())
if perr != nil {
done <- perr
return
Expand Down Expand Up @@ -439,6 +466,10 @@ func (api *API) PushTags(cn *collection.Collection, push PushConfig) error {
for _, tg := range tags {
srcRef := repo.Name() + ":" + tg.Name()
pushPrefix := getPushPrefix(push.Prefix, repo.PushPrefix())
if err := validatePushPrefix(pushPrefix); err != nil {
done <- err
return
}
pushPath := repo.PushPath(push.PathSeparator)
fullPath, perr := pushPathTemplate(pushPrefix, pushPath, repo.Name())
if perr != nil {
Expand Down
8 changes: 8 additions & 0 deletions api/v1/v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,11 @@ func TestMakePushTagTemplate(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "SNAPSHOT-16.3.1-"+curDate, actualDate)
}

func TestValidatePushPrefix(t *testing.T) {
assert.NoError(t, validatePushPrefix("/"))
assert.NoError(t, validatePushPrefix("/foo/bar/"))

assert.Error(t, validatePushPrefix("/baz"))
assert.Error(t, validatePushPrefix("http://localhost:5000"))
}
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/jessevdk/go-flags"
log "github.com/sirupsen/logrus"

v1 "github.com/ivanilves/lstags/api/v1"
"github.com/ivanilves/lstags/config"
Expand Down Expand Up @@ -49,10 +50,10 @@ var exitCode = 0
var doNotFail = false

func suicide(err error, critical bool) {
fmt.Printf("%s\n", err.Error())

if !doNotFail || critical {
os.Exit(1)
log.Fatal(err.Error())
} else {
log.Error(err.Error())
}

exitCode = 254 // not typical error code, for "git grep" friendliness
Expand Down

0 comments on commit d6888d7

Please sign in to comment.