From 8e8a636d239f4ae471dfea70cf4a5cf5bfb3f653 Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Fri, 17 Aug 2018 12:30:33 +0800 Subject: [PATCH 1/2] climc: secure options rename to insecure --- cmd/climc/climc.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/climc/climc.go b/cmd/climc/climc.go index af582a1693..175543ccc8 100644 --- a/cmd/climc/climc.go +++ b/cmd/climc/climc.go @@ -21,7 +21,7 @@ type BaseOptions struct { Debug bool `help:"Show debug information"` Version bool `help:"Show version"` Timeout int `default:"600" help:"Number of seconds to wait for a response"` - Secure bool `default:"False" help:"do server cert verification if URL is https"` + Insecure bool `default:"False" help:"Allow skip server cert verification if URL is https" short-token:"k"` OsUsername string `default:"$OS_USERNAME" help:"Username, defaults to env[OS_USERNAME]"` OsPassword string `default:"$OS_PASSWORD" help:"Password, defaults to env[OS_PASSWORD]"` // OsProjectId string `default:"$OS_PROJECT_ID" help:"Proejct ID, defaults to env[OS_PROJECT_ID]"` @@ -116,7 +116,7 @@ func newClientSession(options *BaseOptions) (*mcclient.ClientSession, error) { client := mcclient.NewClient(options.OsAuthURL, options.Timeout, options.Debug, - options.Secure) + options.Insecure) token, err := client.Authenticate(options.OsUsername, options.OsPassword, options.OsDomainName, From c42db3568b0ee0c2e18e11549a028d8125a2969b Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Fri, 17 Aug 2018 09:41:04 +0000 Subject: [PATCH 2/2] vendor: dep ensure to update sqlchemy e2ab646 Fix insertion for auto_inc fields --- Gopkg.lock | 2 +- vendor/yunion.io/x/sqlchemy/insert.go | 35 ++++++++++++++++----------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 5b287504a8..85f7166e2f 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -896,7 +896,7 @@ branch = "master" name = "yunion.io/x/sqlchemy" packages = ["."] - revision = "8d8043b1fc6f8a9192f1d086520bb167a8423475" + revision = "a74ef73e555a1ed2e19b1a47e0567814c289eaf9" [[projects]] branch = "master" diff --git a/vendor/yunion.io/x/sqlchemy/insert.go b/vendor/yunion.io/x/sqlchemy/insert.go index 06e3518d81..d9f10406c1 100644 --- a/vendor/yunion.io/x/sqlchemy/insert.go +++ b/vendor/yunion.io/x/sqlchemy/insert.go @@ -13,15 +13,7 @@ func (t *STableSpec) Insert(dt interface{}) error { return t.insert(dt, false) } -func (t *STableSpec) insert(dt interface{}, debug bool) error { - beforeInsertFunc := reflect.ValueOf(dt).MethodByName("BeforeInsert") - if beforeInsertFunc.IsValid() && !beforeInsertFunc.IsNil() { - beforeInsertFunc.Call([]reflect.Value{}) - } - - // dataType := reflect.TypeOf(dt).Elem() - dataValue := reflect.ValueOf(dt).Elem() - +func (t *STableSpec) insertSqlPrep(dataFields map[string]interface{}) (string, []interface{}, error) { var autoIncField string createdAtFields := make([]string, 0) @@ -29,7 +21,6 @@ func (t *STableSpec) insert(dt interface{}, debug bool) error { format := make([]string, 0) values := make([]interface{}, 0) - fields := reflectutils.FetchStructFieldNameValueInterfaces(dataValue) for _, c := range t.columns { isAutoInc := false nc, ok := c.(*SIntegerColumn) @@ -40,7 +31,7 @@ func (t *STableSpec) insert(dt interface{}, debug bool) error { k := c.Name() dtc, ok := c.(*SDateTimeColumn) - ov := fields[k] + ov := dataFields[k] if ok && (dtc.IsCreatedAt || dtc.IsUpdatedAt) { createdAtFields = append(createdAtFields, k) @@ -57,8 +48,9 @@ func (t *STableSpec) insert(dt interface{}, debug bool) error { panic(fmt.Sprintf("multiple auto_increment columns: %q, %q", autoIncField, k)) } autoIncField = k + } else { + return "", nil, fmt.Errorf("cannot insert for null primary key %q", k) } - return fmt.Errorf("cannot insert for null primary key %q", k) } else if !c.IsSupportDefault() && len(c.Default()) > 0 && ov != nil && c.IsZero(ov) { // empty text value val := c.ConvertFromString(c.Default()) values = append(values, val) @@ -71,6 +63,21 @@ func (t *STableSpec) insert(dt interface{}, debug bool) error { t.name, strings.Join(names, ", "), strings.Join(format, ", ")) + return insertSql, values, nil +} + +func (t *STableSpec) insert(data interface{}, debug bool) error { + beforeInsertFunc := reflect.ValueOf(data).MethodByName("BeforeInsert") + if beforeInsertFunc.IsValid() && !beforeInsertFunc.IsNil() { + beforeInsertFunc.Call([]reflect.Value{}) + } + + dataValue := reflect.ValueOf(data).Elem() + dataFields := reflectutils.FetchStructFieldNameValueInterfaces(dataValue) + insertSql, values, err := t.insertSqlPrep(dataFields) + if err != nil { + return err + } if DEBUG_SQLCHEMY || debug { log.Debugf("%s values: %s", insertSql, values) @@ -115,11 +122,11 @@ func (t *STableSpec) insert(dt interface{}, debug bool) error { q = q.Equals(c.Name(), lastId) } } else { - q = q.Equals(c.Name(), fields[c.Name()]) + q = q.Equals(c.Name(), dataFields[c.Name()]) } } } - err = q.First(dt) + err = q.First(data) if err != nil { err := fmt.Errorf("query after insert failed: %v", err) return err