From 8f10bed30addb3cf00811380b91bdbade97ac85e Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Wed, 12 Dec 2018 06:24:54 +0000 Subject: [PATCH 1/2] vendor: run "dep ensure" --- vendor/yunion.io/x/pkg/trace/trace.go | 2 ++ .../x/pkg/util/osprofile/osprofile.go | 2 +- .../yunion.io/x/pkg/util/secrules/secrules.go | 19 ++++-------- vendor/yunion.io/x/sqlchemy/conditions.go | 15 +--------- vendor/yunion.io/x/sqlchemy/filter.go | 5 ---- vendor/yunion.io/x/sqlchemy/functions.go | 10 ++----- vendor/yunion.io/x/sqlchemy/insert.go | 2 +- vendor/yunion.io/x/sqlchemy/query.go | 1 - vendor/yunion.io/x/sqlchemy/update.go | 30 ++++++++----------- 9 files changed, 24 insertions(+), 62 deletions(-) diff --git a/vendor/yunion.io/x/pkg/trace/trace.go b/vendor/yunion.io/x/pkg/trace/trace.go index 8d6e4564bc..dd60bd143a 100644 --- a/vendor/yunion.io/x/pkg/trace/trace.go +++ b/vendor/yunion.io/x/pkg/trace/trace.go @@ -6,6 +6,7 @@ import ( "strings" "time" + "yunion.io/x/log" "yunion.io/x/pkg/util/timeutils" "yunion.io/x/pkg/utils" ) @@ -235,4 +236,5 @@ func (tr *STrace) AddClientRequestHeader(header http.Header) { } func SubmitTrace(trace *STrace) { + log.Infof("%s", trace) } diff --git a/vendor/yunion.io/x/pkg/util/osprofile/osprofile.go b/vendor/yunion.io/x/pkg/util/osprofile/osprofile.go index 09cb355365..7d7c92d87f 100644 --- a/vendor/yunion.io/x/pkg/util/osprofile/osprofile.go +++ b/vendor/yunion.io/x/pkg/util/osprofile/osprofile.go @@ -106,7 +106,7 @@ func GetOSProfileFromImageProperties(imgProp map[string]string, hypervisor strin } var imgHypers []string imgHyperStr, ok := imgProp["hypervisor"] - if ok && len(imgHyperStr) > 0 { + if ok { imgHypers = strings.Split(imgHyperStr, ",") } else { imgHypers = []string{} diff --git a/vendor/yunion.io/x/pkg/util/secrules/secrules.go b/vendor/yunion.io/x/pkg/util/secrules/secrules.go index 037bb62d45..6437ff1ae9 100644 --- a/vendor/yunion.io/x/pkg/util/secrules/secrules.go +++ b/vendor/yunion.io/x/pkg/util/secrules/secrules.go @@ -127,21 +127,12 @@ func ParseSecurityRule(pattern string) (*SecurityRule, error) { return nil, ErrInvalidAction } } else if status == SEG_IP { - // NOTE regutils.MatchCIDR actually also matches IP address without prefix length if regutils.MatchCIDR(seg) { - if idx := strings.Index(seg, "/"); idx > -1 { - if _, ipnet, err := net.ParseCIDR(seg); err != nil { - return nil, ErrInvalidNet - } else { - rule.IPNet = ipnet - } - } else if ip := net.ParseIP(seg); ip != nil { - rule.IPNet = &net.IPNet{ - IP: ip, - Mask: net.CIDRMask(32, 32), - } - } else { - return nil, ErrInvalidIPAddr + _, rule.IPNet, _ = net.ParseCIDR(seg) + } else if regutils.MatchIPAddr(seg) { + rule.IPNet = &net.IPNet{ + IP: net.ParseIP(seg), + Mask: net.CIDRMask(32, 32), } } else { rule.IPNet = &net.IPNet{ diff --git a/vendor/yunion.io/x/sqlchemy/conditions.go b/vendor/yunion.io/x/sqlchemy/conditions.go index 59fd7ed8fb..064d60c437 100644 --- a/vendor/yunion.io/x/sqlchemy/conditions.go +++ b/vendor/yunion.io/x/sqlchemy/conditions.go @@ -159,25 +159,12 @@ func IsEmpty(f IQueryField) ICondition { return &c } -type SIsNullOrEmptyCondition struct { - SSingleCondition -} - -func (c *SIsNullOrEmptyCondition) WhereClause() string { - return fmt.Sprintf("%s IS NULL OR LENGTH(%s) = 0", c.field.Reference(), c.field.Reference()) -} - -func IsNullOrEmpty(f IQueryField) ICondition { - c := SIsNullOrEmptyCondition{NewSingleCondition(f)} - return &c -} - type SIsNotEmptyCondition struct { SSingleCondition } func (c *SIsNotEmptyCondition) WhereClause() string { - return fmt.Sprintf("%s IS NOT NULL AND LENGTH(%s) > 0", c.field.Reference(), c.field.Reference()) + return fmt.Sprintf("LENGTH(%s) > 0", c.field.Reference()) } func IsNotEmpty(f IQueryField) ICondition { diff --git a/vendor/yunion.io/x/sqlchemy/filter.go b/vendor/yunion.io/x/sqlchemy/filter.go index 9689d83492..855fcba11f 100644 --- a/vendor/yunion.io/x/sqlchemy/filter.go +++ b/vendor/yunion.io/x/sqlchemy/filter.go @@ -107,11 +107,6 @@ func (q *SQuery) IsEmpty(f string) *SQuery { return q.Filter(cond) } -func (q *SQuery) IsNullOrEmpty(f string) *SQuery { - cond := IsNullOrEmpty(q.Field(f)) - return q.Filter(cond) -} - func (q *SQuery) IsNotEmpty(f string) *SQuery { cond := IsNotEmpty(q.Field(f)) return q.Filter(cond) diff --git a/vendor/yunion.io/x/sqlchemy/functions.go b/vendor/yunion.io/x/sqlchemy/functions.go index 237cdb31f5..c55920f836 100644 --- a/vendor/yunion.io/x/sqlchemy/functions.go +++ b/vendor/yunion.io/x/sqlchemy/functions.go @@ -38,14 +38,8 @@ func NewFunctionField(name string, funcexp string, fields ...IQueryField) SFunct return ff } -func COUNT(name string, field ...IQueryField) IQueryField { - var expr string - if len(field) == 0 { - expr = "COUNT(*)" - } else { - expr = "COUNT(%s)" - } - ff := NewFunctionField(name, expr, field...) +func COUNT(name string) IQueryField { + ff := NewFunctionField(name, "COUNT(*)") return &ff } diff --git a/vendor/yunion.io/x/sqlchemy/insert.go b/vendor/yunion.io/x/sqlchemy/insert.go index 65b8100248..c7442588f0 100644 --- a/vendor/yunion.io/x/sqlchemy/insert.go +++ b/vendor/yunion.io/x/sqlchemy/insert.go @@ -37,7 +37,7 @@ func (t *STableSpec) insertSqlPrep(dataFields map[string]interface{}) (string, [ createdAtFields = append(createdAtFields, k) names = append(names, fmt.Sprintf("`%s`", k)) format = append(format, "UTC_TIMESTAMP()") - } else if ov != nil && (!c.IsZero(ov) || !c.IsText()) && !isAutoInc { + } else if ov != nil && !c.IsZero(ov) && !isAutoInc { v := c.ConvertFromValue(ov) values = append(values, v) names = append(names, fmt.Sprintf("`%s`", k)) diff --git a/vendor/yunion.io/x/sqlchemy/query.go b/vendor/yunion.io/x/sqlchemy/query.go index 60b2cd7cd5..b72b412856 100644 --- a/vendor/yunion.io/x/sqlchemy/query.go +++ b/vendor/yunion.io/x/sqlchemy/query.go @@ -450,7 +450,6 @@ func (q *SQuery) AllStringMap() ([]map[string]string, error) { if err != nil { return nil, err } - defer rows.Close() results := make([]map[string]string, 0) for rows.Next() { result, err := q.rowScan2StringMap(rows) diff --git a/vendor/yunion.io/x/sqlchemy/update.go b/vendor/yunion.io/x/sqlchemy/update.go index 3a6512d2fb..f88e1a6bde 100644 --- a/vendor/yunion.io/x/sqlchemy/update.go +++ b/vendor/yunion.io/x/sqlchemy/update.go @@ -83,16 +83,17 @@ func (us *SUpdateSession) saveUpdate(dt interface{}) (map[string]SUpdateDiff, er setters := make(map[string]SUpdateDiff) for _, c := range us.tableSpec.columns { k := c.Name() - of := ofields[k] + of, ok := ofields[k] + if !ok { + continue + } nf := fields[k] - if !gotypes.IsNil(of) { - if c.IsPrimary() && !c.IsZero(of) { // skip update primary key - primaries[k] = of - continue - } else if c.IsKeyIndex() && !c.IsZero(of) { - keyIndexes[k] = of - continue - } + if c.IsPrimary() && !c.IsZero(of) { // skip update primary key + primaries[k] = of + continue + } else if c.IsKeyIndex() && !c.IsZero(of) { + keyIndexes[k] = of + continue } nc, ok := c.(*SIntegerColumn) if ok && nc.IsAutoVersion { @@ -107,9 +108,6 @@ func (us *SUpdateSession) saveUpdate(dt interface{}) (map[string]SUpdateDiff, er if reflect.DeepEqual(of, nf) { continue } - if c.IsZero(nf) && c.IsText() { - nf = nil - } setters[k] = SUpdateDiff{old: of, new: nf, col: c} } @@ -127,12 +125,8 @@ func (us *SUpdateSession) saveUpdate(dt interface{}) (map[string]SUpdateDiff, er } else { buf.WriteString(", ") } - if gotypes.IsNil(v.new) { - buf.WriteString(fmt.Sprintf("`%s` = NULL", k)) - } else { - buf.WriteString(fmt.Sprintf("`%s` = ?", k)) - vars = append(vars, v.col.ConvertFromValue(v.new)) - } + buf.WriteString(fmt.Sprintf("`%s` = ?", k)) + vars = append(vars, v.col.ConvertFromValue(v.new)) } for _, versionField := range versionFields { buf.WriteString(fmt.Sprintf(", `%s` = `%s` + 1", versionField, versionField)) From 8f8c1a1f1593be121b45778c00318a9399734d0e Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Wed, 12 Dec 2018 06:36:52 +0000 Subject: [PATCH 2/2] vendor: run "dep ensure -v -update yunion.io/x/jsonutils" --- Gopkg.lock | 4 +- vendor/yunion.io/x/jsonutils/marshal.go | 77 ++++++++++++------------- vendor/yunion.io/x/jsonutils/utils.go | 14 +++++ 3 files changed, 53 insertions(+), 42 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 97e5f4c360..4975c42bc7 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1310,11 +1310,11 @@ [[projects]] branch = "master" - digest = "1:a2346cf0c965791c281a428a3e9bf522913941028e4c814a774af7f3cc2360b0" + digest = "1:30c2a461ac89edba03106741bfd399b5b19354f5a1c8879816e459775e762ae7" name = "yunion.io/x/jsonutils" packages = ["."] pruneopts = "UT" - revision = "814e036849815935e5957ebd03bd0f4fc992fe83" + revision = "3dc94f21b85b0975a07c9cbe6854acf6fd63b77d" [[projects]] branch = "master" diff --git a/vendor/yunion.io/x/jsonutils/marshal.go b/vendor/yunion.io/x/jsonutils/marshal.go index 97630bb987..f1e60f0388 100644 --- a/vendor/yunion.io/x/jsonutils/marshal.go +++ b/vendor/yunion.io/x/jsonutils/marshal.go @@ -130,51 +130,48 @@ func struct2JSONPairs(val reflect.Value) []JSONPair { structType := val.Type() objPairs := make([]JSONPair, 0) for i := 0; i < structType.NumField(); i += 1 { - fieldType := structType.Field(i) - if !gotypes.IsFieldExportable(fieldType.Name) { // unexportable field, ignore + sf := structType.Field(i) + + // ignore unexported field altogether + if !gotypes.IsFieldExportable(sf.Name) { continue } - if fieldType.Anonymous { - nextVal := val.Field(i) - switch fieldType.Type.Kind() { - case reflect.Struct: // embbed struct - nextVal = val.Field(i) - case reflect.Interface: // embbed interface - CHECKINTERFACE: - for { - switch nextVal.Type().Kind() { - case reflect.Interface: - nextVal = nextVal.Elem() - case reflect.Ptr: - nextVal = reflect.Indirect(nextVal) - case reflect.Struct: - break CHECKINTERFACE - default: - log.Warningf("embeded interface point to a non struct data %s", nextVal.Type()) - break CHECKINTERFACE - } - } - default: - log.Warningf("unsupport anonymous embeded type %s", fieldType.Type.Name()) - continue - } - newPairs := struct2JSONPairs(nextVal) - objPairs = append(objPairs, newPairs...) - } else { - jsonInfo := parseJsonMarshalInfo(fieldType.Tag) - if jsonInfo.ignore { + if sf.Anonymous { + fv := val.Field(i) + + // T, *T + switch fv.Kind() { + case reflect.Ptr, reflect.Interface: + // ignore nil values completely + if !fv.IsValid() || fv.IsNil() { + continue + } + fv = fv.Elem() + } + // note that we regard anonymous interface field the + // same as with anonymous struct field. This is + // different from how encoding/json handles struct + // field of interface type. + if fv.Kind() == reflect.Struct { + newPairs := struct2JSONPairs(fv) + objPairs = append(objPairs, newPairs...) continue } - key := jsonInfo.name - if len(key) == 0 { - key = utils.CamelSplit(fieldType.Name, "_") - } - val := marshalValue(val.Field(i), &jsonInfo) - if val != nil && val != JSONNull { - objPair := JSONPair{key: key, val: val} - objPairs = append(objPairs, objPair) - } + } + + jsonInfo := parseJsonMarshalInfo(sf.Tag) + if jsonInfo.ignore { + continue + } + key := jsonInfo.name + if len(key) == 0 { + key = utils.CamelSplit(sf.Name, "_") + } + val := marshalValue(val.Field(i), &jsonInfo) + if val != nil && val != JSONNull { + objPair := JSONPair{key: key, val: val} + objPairs = append(objPairs, objPair) } } return objPairs diff --git a/vendor/yunion.io/x/jsonutils/utils.go b/vendor/yunion.io/x/jsonutils/utils.go index 5c80a2c90b..cfd77eee04 100644 --- a/vendor/yunion.io/x/jsonutils/utils.go +++ b/vendor/yunion.io/x/jsonutils/utils.go @@ -93,3 +93,17 @@ func GetAnyString(json JSONObject, keys []string) string { } return "" } + +func GetArrayOfPrefix(json JSONObject, prefix string) []JSONObject { + retArray := make([]JSONObject, 0) + idx := 0 + for { + obj, _ := json.Get(fmt.Sprintf("%s.%d", prefix, idx)) + if obj == nil || obj == JSONNull { + break + } + retArray = append(retArray, obj) + idx += 1 + } + return retArray +}