Skip to content

Commit

Permalink
Merge pull request #451 from subutai-io/sysnet
Browse files Browse the repository at this point in the history
Sysnet
  • Loading branch information
crioto authored Jun 4, 2018
2 parents ef7e0b8 + b86363a commit e4b0cb1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
14 changes: 9 additions & 5 deletions download/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ func List(repo string, r *http.Request) []byte {
owner := strings.ToLower(r.URL.Query().Get("owner"))
token := strings.ToLower(r.URL.Query().Get("token"))
version := r.URL.Query().Get("version")
verified := r.URL.Query().Get("verified")
if name == "" {
name = subname
}
Expand Down Expand Up @@ -362,7 +363,8 @@ func List(repo string, r *http.Request) []byte {
item := FormatItem(db.Info(k), repo)
log.Debug(fmt.Sprintf("File #%+v (hash: %+v) in formatted way: %+v", i, k, item))
if (name == "" || (name != "" && ((subname != "" && strings.Contains(item.Name, subname)) || name == item.Name || strings.HasPrefix(name, item.Name+"-subutai-template")))) &&
(version == "" || (version != "" && (item.Version == version || (version == "latest" && checkVersion(items, item) != -1)))) {
(version == "" || (version != "" && (item.Version == version || (version == "latest" && checkVersion(items, item) != -1)))) &&
(verified != "true" || In(item.Owner, []string{"subutai", "jenkins", "docker", "travis", "appveyor", "devops"})) {
if version == "latest" {
positionOlderItem := checkVersion(items, item)
if positionOlderItem != len(items) {
Expand Down Expand Up @@ -416,10 +418,12 @@ func processVersion(version string) string {
return version
}

func In(str string, list []string) bool {
func In(str []string, list []string) bool {
for _, s := range list {
if s == str {
return true
for _, t := range str {
if s == t {
return true
}
}
}
return false
Expand All @@ -440,7 +444,7 @@ func GetVerified(list []string, name, repo, versionTemplate string) ListItem {
if info["name"] == name || (strings.HasPrefix(info["name"], name+"-subutai-template") && repo == "template") {
for _, owner := range db.FileField(info["id"], "owner") {
itemVersion, _ := semver.Make(info["version"])
if In(owner, []string{"subutai", "jenkins", "docker", "travis", "appveyor", "devops"}) {
if In([]string{owner}, []string{"subutai", "jenkins", "docker", "travis", "appveyor", "devops"}) {
if itemVersion.GTE(latestVersion) && len(versionTemplate) == 0 {
log.Debug(fmt.Sprintf("First if %+v", k))
latestVersion = itemVersion
Expand Down
10 changes: 5 additions & 5 deletions download/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import (

func TestIn(t *testing.T) {
type args struct {
str string
str []string
list []string
}
tests := []struct {
name string
args args
want bool
}{
{"TestIn-1", args{"in", []string{"string", "in", "slice"}}, true},
{"TestIn-2", args{"in", []string(nil)}, false},
{"TestIn-3", args{"", []string{"", "in", "slice"}}, true},
{"TestIn-4", args{"outside", []string{"", "in", "slice"}}, false},
{"TestIn-1", args{[]string{"in"}, []string{"string", "in", "slice"}}, true},
{"TestIn-2", args{[]string{"in"}, []string(nil)}, false},
{"TestIn-3", args{[]string{""}, []string{"", "in", "slice"}}, true},
{"TestIn-4", args{[]string{"outside"}, []string{"", "in", "slice"}}, false},
// TODO: Add test cases.
}
for _, tt := range tests {
Expand Down
2 changes: 1 addition & 1 deletion template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ func allFieldsPresent(templateData *download.ListItem) (bool, string) {
fieldName := typeOfT.Field(i).Name
fieldValue := f.Interface()

if (download.In(fieldName, requiredFields) && fieldValue == "") ||
if (download.In([]string{fieldName}, requiredFields) && fieldValue == "") ||
(fieldName == "Owner" && len(templateData.Owner) == 0) {
message := fieldName + " field required"
return false, message
Expand Down

0 comments on commit e4b0cb1

Please sign in to comment.