Merge pull request #74 in YUNIONIO/onecloud from ~LIZEXI/onecloud:hotfix/lzx-resolve-conflict-2.1.0-2018-08-18 to release/2.1.0

* commit '177a9724eb9fd137d873174aaee8ad3b73ef5283':
  vendor: dep ensure to update sqlchemy
  climc: secure options rename to insecure
This commit is contained in:
邱剑
2018-08-19 01:07:10 +08:00
3 changed files with 24 additions and 17 deletions
Generated
+1 -1
View File
@@ -902,7 +902,7 @@
branch = "master"
name = "yunion.io/x/sqlchemy"
packages = ["."]
revision = "8d8043b1fc6f8a9192f1d086520bb167a8423475"
revision = "a74ef73e555a1ed2e19b1a47e0567814c289eaf9"
[[projects]]
branch = "master"
+2 -2
View File
@@ -24,7 +24,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]"`
@@ -119,7 +119,7 @@ func newClientSession(options *BaseOptions) (*mcclient.ClientSession, error) {
client := mcclient.NewClient(options.OsAuthURL,
options.Timeout,
options.Debug,
options.Secure)
options.Insecure)
var cacheToken mcclient.TokenCredential
cacheFile, err := os.Open("/tmp/OS_AUTH_CACHE_TOKEN")
+21 -14
View File
@@ -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