mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-31 01:35:56 +08:00
update vendor
This commit is contained in:
@@ -133,9 +133,9 @@ require (
|
||||
k8s.io/kubernetes v1.12.3
|
||||
yunion.io/x/jsonutils v0.0.0-20191005115334-bb1c187fc0e7
|
||||
yunion.io/x/log v0.0.0-20190629062853-9f6483a7103d
|
||||
yunion.io/x/pkg v0.0.0-20191112153320-4346cc308eed
|
||||
yunion.io/x/pkg v0.0.0-20191121110824-e03b47b93fe0
|
||||
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
|
||||
yunion.io/x/sqlchemy v0.0.0-20191119025555-5948646b39e6
|
||||
yunion.io/x/sqlchemy v0.0.0-20191122085525-2d3bfdb3f51c
|
||||
yunion.io/x/structarg v0.0.0-20190809075558-115bed041de3
|
||||
)
|
||||
|
||||
|
||||
@@ -663,11 +663,11 @@ yunion.io/x/log v0.0.0-20190629062853-9f6483a7103d h1:59zrDL7Ft+hDukguJRmLr/Gdu/
|
||||
yunion.io/x/log v0.0.0-20190629062853-9f6483a7103d/go.mod h1:LC6f/4FozL0iaAbnFt2eDX9jlsyo3WiOUPm03d7+U4U=
|
||||
yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf h1:OsKC+2ghZHwp+Ztm/MwKlLKKRiE7QcPG8eTp0GmsHbg=
|
||||
yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
|
||||
yunion.io/x/pkg v0.0.0-20191112153320-4346cc308eed h1:seECXVsAP+wTuxIo8VpyQ9U2zPPf0fsxb1zvmbsLo90=
|
||||
yunion.io/x/pkg v0.0.0-20191112153320-4346cc308eed/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
|
||||
yunion.io/x/pkg v0.0.0-20191121110824-e03b47b93fe0 h1:gMENCnVkKO5BlwtbKSKW5liEeHk8FHDxxcFXZcdhlxk=
|
||||
yunion.io/x/pkg v0.0.0-20191121110824-e03b47b93fe0/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
|
||||
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e h1:v+EzIadodSwkdZ/7bremd7J8J50Cise/HCylsOJngmo=
|
||||
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e/go.mod h1:0iFKpOs1y4lbCxeOmq3Xx/0AcQoewVPwj62eRluioEo=
|
||||
yunion.io/x/sqlchemy v0.0.0-20191119025555-5948646b39e6 h1:vgltfojqVRXxWiBt+8bgrSmO7F0cSNAbG6Ktn1SLIq8=
|
||||
yunion.io/x/sqlchemy v0.0.0-20191119025555-5948646b39e6/go.mod h1:FTdwPdGhMgh4E+UFXc9klI1Ok34fMuybTT+jLhOaIjI=
|
||||
yunion.io/x/sqlchemy v0.0.0-20191122085525-2d3bfdb3f51c h1:4zMTt6JASU+hwm9AOb1sQkAgXlKbludSIQ6G7i7mPPA=
|
||||
yunion.io/x/sqlchemy v0.0.0-20191122085525-2d3bfdb3f51c/go.mod h1:FTdwPdGhMgh4E+UFXc9klI1Ok34fMuybTT+jLhOaIjI=
|
||||
yunion.io/x/structarg v0.0.0-20190809075558-115bed041de3 h1:bfC8EhXYvyGYldRWlzxiCM39Zfj3s3+zham9mW2h2LE=
|
||||
yunion.io/x/structarg v0.0.0-20190809075558-115bed041de3/go.mod h1:EP6NSv2C0zzqBDTKumv8hPWLb3XvgMZDHQRfyuOrQng=
|
||||
|
||||
Vendored
+2
-2
@@ -798,7 +798,7 @@ yunion.io/x/jsonutils
|
||||
# yunion.io/x/log v0.0.0-20190629062853-9f6483a7103d
|
||||
yunion.io/x/log
|
||||
yunion.io/x/log/hooks
|
||||
# yunion.io/x/pkg v0.0.0-20191112153320-4346cc308eed
|
||||
# yunion.io/x/pkg v0.0.0-20191121110824-e03b47b93fe0
|
||||
yunion.io/x/pkg/errors
|
||||
yunion.io/x/pkg/gotypes
|
||||
yunion.io/x/pkg/prettytable
|
||||
@@ -830,7 +830,7 @@ yunion.io/x/pkg/util/workqueue
|
||||
yunion.io/x/pkg/utils
|
||||
# yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
|
||||
yunion.io/x/s3cli
|
||||
# yunion.io/x/sqlchemy v0.0.0-20191119025555-5948646b39e6
|
||||
# yunion.io/x/sqlchemy v0.0.0-20191122085525-2d3bfdb3f51c
|
||||
yunion.io/x/sqlchemy
|
||||
# yunion.io/x/structarg v0.0.0-20190809075558-115bed041de3
|
||||
yunion.io/x/structarg
|
||||
|
||||
+21
-15
@@ -46,6 +46,20 @@ func (jfc *SJointFilterClause) GetJointModelName() string {
|
||||
return jfc.JointModel[:len(jfc.JointModel)-1]
|
||||
}
|
||||
|
||||
func condFunc(field sqlchemy.IQueryField, params []string, cond func(field sqlchemy.IQueryField, val string) sqlchemy.ICondition) sqlchemy.ICondition {
|
||||
if len(params) == 1 {
|
||||
return cond(field, params[0])
|
||||
} else if len(params) > 1 {
|
||||
conds := make([]sqlchemy.ICondition, len(params))
|
||||
for i := range params {
|
||||
conds[i] = cond(field, params[i])
|
||||
}
|
||||
return sqlchemy.OR(conds...)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (fc *SFilterClause) QueryCondition(q *sqlchemy.SQuery) sqlchemy.ICondition {
|
||||
field := q.Field(fc.field)
|
||||
if field == nil {
|
||||
@@ -78,25 +92,17 @@ func (fc *SFilterClause) QueryCondition(q *sqlchemy.SQuery) sqlchemy.ICondition
|
||||
return sqlchemy.LT(field, fc.params[0])
|
||||
}
|
||||
case "like":
|
||||
if len(fc.params) == 1 {
|
||||
return sqlchemy.Like(field, fc.params[0])
|
||||
}
|
||||
return condFunc(field, fc.params, sqlchemy.Like)
|
||||
case "contains":
|
||||
if len(fc.params) == 1 {
|
||||
return sqlchemy.Contains(field, fc.params[0])
|
||||
}
|
||||
return condFunc(field, fc.params, sqlchemy.Contains)
|
||||
case "startswith":
|
||||
if len(fc.params) == 1 {
|
||||
return sqlchemy.Startswith(field, fc.params[0])
|
||||
}
|
||||
return condFunc(field, fc.params, sqlchemy.Startswith)
|
||||
case "endswith":
|
||||
if len(fc.params) == 1 {
|
||||
return sqlchemy.Endswith(field, fc.params[0])
|
||||
}
|
||||
return condFunc(field, fc.params, sqlchemy.Endswith)
|
||||
case "equals":
|
||||
if len(fc.params) == 1 {
|
||||
return sqlchemy.Equals(field, fc.params[0])
|
||||
}
|
||||
return condFunc(field, fc.params, func(f sqlchemy.IQueryField, p string) sqlchemy.ICondition {
|
||||
return sqlchemy.Equals(f, p)
|
||||
})
|
||||
case "notequals":
|
||||
if len(fc.params) == 1 {
|
||||
return sqlchemy.NOT(sqlchemy.Equals(field, fc.params[0]))
|
||||
|
||||
+13
@@ -206,6 +206,19 @@ func (ar IPV4AddrRange) EndIp() IPV4Addr {
|
||||
return ar.end
|
||||
}
|
||||
|
||||
func (ar IPV4AddrRange) Merge(ar2 IPV4AddrRange) (*IPV4AddrRange, bool) {
|
||||
if ar.IsOverlap(ar2) || ar.end+1 == ar2.start || ar2.end+1 == ar.start {
|
||||
if ar2.start < ar.start {
|
||||
ar.start = ar2.start
|
||||
}
|
||||
if ar2.end > ar.end {
|
||||
ar.end = ar2.end
|
||||
}
|
||||
return &ar, true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (ar IPV4AddrRange) IsOverlap(ar2 IPV4AddrRange) bool {
|
||||
if ar.start > ar2.end || ar.end < ar2.start {
|
||||
return false
|
||||
|
||||
+87
-1
@@ -16,7 +16,10 @@ package secrules
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net"
|
||||
"sort"
|
||||
|
||||
"yunion.io/x/pkg/util/netutils"
|
||||
)
|
||||
|
||||
type SecurityRuleSet []SecurityRule
|
||||
@@ -55,6 +58,12 @@ func (srs SecurityRuleSet) String() string {
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func (srs SecurityRuleSet) Equals(srs1 SecurityRuleSet) bool {
|
||||
sort.Sort(srs)
|
||||
sort.Sort(srs1)
|
||||
return srs.equals(srs1)
|
||||
}
|
||||
|
||||
func (srs SecurityRuleSet) equals(srs1 SecurityRuleSet) bool {
|
||||
if len(srs) != len(srs1) {
|
||||
return false
|
||||
@@ -191,5 +200,82 @@ func (srs SecurityRuleSet) collapse() SecurityRuleSet {
|
||||
// save that contains, intersects
|
||||
}
|
||||
}
|
||||
return srs1
|
||||
for i := range srs1 {
|
||||
sr := &srs1[i]
|
||||
if sr.PortStart <= 1 && sr.PortEnd >= 65535 {
|
||||
sr.PortStart = -1
|
||||
sr.PortEnd = -1
|
||||
}
|
||||
}
|
||||
|
||||
//merge cidr
|
||||
sort.Slice(srs1, func(i, j int) bool {
|
||||
sr0 := &srs1[i]
|
||||
sr1 := &srs1[j]
|
||||
if sr0.Protocol != sr1.Protocol {
|
||||
return sr0.Protocol < sr1.Protocol
|
||||
}
|
||||
|
||||
if sr0.GetPortsString() != sr1.GetPortsString() {
|
||||
return sr0.GetPortsString() < sr1.GetPortsString()
|
||||
}
|
||||
range0 := netutils.NewIPV4AddrRangeFromIPNet(sr0.IPNet)
|
||||
range1 := netutils.NewIPV4AddrRangeFromIPNet(sr1.IPNet)
|
||||
if range0.StartIp() != range1.StartIp() {
|
||||
return range0.StartIp() < range1.StartIp()
|
||||
}
|
||||
if range0.EndIp() != range1.EndIp() {
|
||||
return range0.EndIp() < range1.EndIp()
|
||||
}
|
||||
return sr0.Priority < sr1.Priority
|
||||
})
|
||||
|
||||
// 将端口和协议相同的规则归类
|
||||
needMerged := []SecurityRuleSet{}
|
||||
for i, j := 0, 0; i < len(srs1); i++ {
|
||||
if i == 0 {
|
||||
needMerged = append(needMerged, SecurityRuleSet{srs1[i]})
|
||||
continue
|
||||
}
|
||||
last := needMerged[j][len(needMerged[j])-1]
|
||||
if last.Protocol == srs1[i].Protocol && last.GetPortsString() == srs1[i].GetPortsString() {
|
||||
needMerged[j] = append(needMerged[j], srs1[i])
|
||||
continue
|
||||
}
|
||||
needMerged = append(needMerged, SecurityRuleSet{srs1[i]})
|
||||
j++
|
||||
}
|
||||
|
||||
result := SecurityRuleSet{}
|
||||
for _, srs := range needMerged {
|
||||
result = append(result, srs.mergeNet()...)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (srs SecurityRuleSet) mergeNet() SecurityRuleSet {
|
||||
result := SecurityRuleSet{}
|
||||
ranges := []netutils.IPV4AddrRange{}
|
||||
for i := 0; i < len(srs); i++ {
|
||||
if i == 0 {
|
||||
ranges = append(ranges, netutils.NewIPV4AddrRangeFromIPNet(srs[i].IPNet))
|
||||
continue
|
||||
}
|
||||
preNet := ranges[len(ranges)-1]
|
||||
nextNet := netutils.NewIPV4AddrRangeFromIPNet(srs[i].IPNet)
|
||||
if net, ok := preNet.Merge(nextNet); ok {
|
||||
ranges[len(ranges)-1] = *net
|
||||
continue
|
||||
}
|
||||
ranges = append(ranges, nextNet)
|
||||
}
|
||||
nets := []*net.IPNet{}
|
||||
for _, addr := range ranges {
|
||||
nets = append(nets, addr.ToIPNets()...)
|
||||
}
|
||||
for _, net := range nets {
|
||||
srs[0].IPNet = net
|
||||
result = append(result, srs[0])
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
+11
-4
@@ -16,8 +16,8 @@ package timeutils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/pkg/util/regutils"
|
||||
)
|
||||
@@ -108,10 +108,17 @@ func ParseIsoNoSecondTime(str string) (time.Time, error) {
|
||||
|
||||
func toFullIsoNanoTimeFormat(str string) string {
|
||||
// 2019-09-17T20:50:17.66667134+08:00
|
||||
// 2019-11-19T18:54:48.084-08:00
|
||||
subsecStr := str[20:]
|
||||
pos := strings.IndexByte(subsecStr, 'Z')
|
||||
if pos < 0 {
|
||||
pos = strings.IndexByte(subsecStr, '+')
|
||||
pos := -1
|
||||
for _, s := range []byte{'Z', '+', '-'} {
|
||||
pos = strings.IndexByte(subsecStr, s)
|
||||
if pos >= 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if pos < 0 { //避免-1越界
|
||||
return str
|
||||
}
|
||||
leftOver := subsecStr[pos:]
|
||||
subsecStr = subsecStr[:pos]
|
||||
|
||||
+14
-5
@@ -1,6 +1,6 @@
|
||||
# sqlchemy
|
||||
|
||||
A golang lightweight ORM library inspired by sqlalchemy.
|
||||
A lightweight golang ORM library inspired by python sqlalchemy.
|
||||
|
||||
Features
|
||||
----------------
|
||||
@@ -13,7 +13,7 @@ Features
|
||||
Quick Examples
|
||||
----------------
|
||||
|
||||
## Table Schema definition
|
||||
## Table Schema
|
||||
|
||||
Table schema is defined by struct field tags
|
||||
|
||||
@@ -32,9 +32,9 @@ Table schema is defined by struct field tags
|
||||
Notes string `default:"default notes"`
|
||||
}
|
||||
|
||||
## Create table instance
|
||||
## Table initialization
|
||||
|
||||
Create a table from a struct
|
||||
Create a table from a struct schema
|
||||
|
||||
tablespec := sqlchemy.NewTableSpecFromStruct(TestTable{}, "testtable")
|
||||
|
||||
@@ -63,10 +63,12 @@ Synchronize database table schema and make it consistent with the struct definti
|
||||
// select * from testtable where id = '981b10ed-b6f9-4120-8a77-a3b03e343143'
|
||||
// query by field name, in which the name is unique in the query
|
||||
q := ti.Query().Equals("id", "981b10ed-b6f9-4120-8a77-a3b03e343143")
|
||||
|
||||
// query by field instance, in which the field name might be ambiguous
|
||||
q := ti.Query().Filter(sqlchemy.Equals(ti.Field("id"), "981b10ed-b6f9-4120-8a77-a3b03e343143"))
|
||||
|
||||
// joint query
|
||||
|
||||
// select * from t1 join t2 on t1.id=t2.testtable_id where t2.created_at > '2019-11-02'
|
||||
q := ti.Query("name").Join(t2, sqlchemy.Equals(ti.Field("id"), t2.Field("testtable_id"))).Filter(sqlchermy.GT(t2.Field("created_at"), '2019-11-02')
|
||||
|
||||
@@ -86,7 +88,8 @@ Synchronize database table schema and make it consistent with the struct definti
|
||||
if err != nil {
|
||||
log.Fatalf("fetch object error %s", err)
|
||||
}
|
||||
// first single row into a string map, where strMap is map[string]string
|
||||
|
||||
// fetch single row into a string map, where strMap is map[string]string
|
||||
strMap, err := q.FirstStringMap()
|
||||
if err != nil {
|
||||
log.Fatalf("fetch object error %s", err)
|
||||
@@ -99,6 +102,7 @@ Synchronize database table schema and make it consistent with the struct definti
|
||||
if err != nil {
|
||||
log.Fatalf("query failure: %s", err)
|
||||
}
|
||||
|
||||
// fetch rows into string maps, where maps is []map[string]string
|
||||
maps, err := q.AllStringMap()
|
||||
if err != nil {
|
||||
@@ -128,6 +132,11 @@ Query can be used as a subquery in other queries.
|
||||
// the primary key has been populated by the BeforeInsert hook
|
||||
err = tablespec.Insert(&dt1)
|
||||
|
||||
// insert or update
|
||||
// insert the object if no primary key conflict, otherwise, update the record
|
||||
err = tablespec.InsertOrUpdate(&dt1)
|
||||
|
||||
|
||||
## Update
|
||||
|
||||
// update the field
|
||||
|
||||
+1
-1
@@ -351,7 +351,7 @@ func (t *SLikeCondition) WhereClause() string {
|
||||
return tupleConditionWhereClause(&t.STupleCondition, SQL_OP_LIKE)
|
||||
}
|
||||
|
||||
func Like(f IQueryField, v interface{}) ICondition {
|
||||
func Like(f IQueryField, v string) ICondition {
|
||||
c := SLikeCondition{NewTupleCondition(f, v)}
|
||||
return &c
|
||||
}
|
||||
|
||||
+2
-2
@@ -31,7 +31,7 @@ func (tq *SQuery) Filter(cond ICondition) *SQuery {
|
||||
return tq
|
||||
}
|
||||
|
||||
func (q *SQuery) Like(f string, v interface{}) *SQuery {
|
||||
func (q *SQuery) Like(f string, v string) *SQuery {
|
||||
cond := Like(q.Field(f), v)
|
||||
return q.Filter(cond)
|
||||
}
|
||||
@@ -51,7 +51,7 @@ func (q *SQuery) Endswith(f string, v string) *SQuery {
|
||||
return q.Filter(cond)
|
||||
}
|
||||
|
||||
func (q *SQuery) NotLike(f string, v interface{}) *SQuery {
|
||||
func (q *SQuery) NotLike(f string, v string) *SQuery {
|
||||
cond := Like(q.Field(f), v)
|
||||
return q.Filter(NOT(cond))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user