diff --git a/Gopkg.lock b/Gopkg.lock index 54cf079fea..ef2494ff04 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1705,22 +1705,22 @@ [[projects]] branch = "master" - digest = "1:5ef22fef33e8bfb5e66901f9adba50f5d594ad20263a132fdc62801033eb7712" + digest = "1:53c214ff8c2fd57db0962140b9a5e57b01b63066e7de7fe6897a633d15b78248" name = "yunion.io/x/jsonutils" packages = ["."] pruneopts = "UT" - revision = "ff8561d72c32ba4eb91ee660f6f2ca9e6f64d268" + revision = "028b9007e455103eabacf3e6d71b5ce5060c3984" [[projects]] branch = "master" - digest = "1:d4ebc35bc25d8a3d3a264bb80f9b1a07c344283410d7f78f6d9d2dab1858a82f" + digest = "1:b098c5b757b7622dfeed71f9cdcf0621a42051b88967286b0e1bcfb8a910fc86" name = "yunion.io/x/log" packages = [ ".", "hooks", ] pruneopts = "UT" - revision = "0b4a12f87d57e3293568174ddbcb91da97d3b5ec" + revision = "71a36f55dcfcfa2c8b2477c339e2c7ebd78c731d" [[projects]] branch = "master" @@ -1762,19 +1762,19 @@ [[projects]] branch = "master" - digest = "1:71e1d99440696f89cfdd93aba9f349fbd6a1273b30114ff5b6e5ba2457832b80" + digest = "1:ea481ba82e96a2a5c70d259fc0766ea18d7b6f59c74d3cac38a456e8c6c3e828" name = "yunion.io/x/sqlchemy" packages = ["."] pruneopts = "UT" - revision = "1214fd27cb9c02b2d650557a76cfaa8c13220b54" + revision = "bf5e3b0d446dae4e9bf66cc82bfbb8c7d6b56dfd" [[projects]] branch = "master" - digest = "1:6a0bb09937441c871c34278e62ea9c80320a6b9894d63261f5c4246c07aeb510" + digest = "1:cfa79b54c4ec8d1fe6b1599846b3975c50212f58114d807a6db69bbee5a16b7a" name = "yunion.io/x/structarg" packages = ["."] pruneopts = "UT" - revision = "f370514c4558e64e798bd83abaff263dabef9f3a" + revision = "5b725f46d67547e7fb603b2118eddc5358ac2a39" [solve-meta] analyzer-name = "dep" diff --git a/pkg/cloudcommon/policy/token_test.go b/pkg/cloudcommon/policy/token_test.go index c8930eb9bd..b7b9b0f9ae 100644 --- a/pkg/cloudcommon/policy/token_test.go +++ b/pkg/cloudcommon/policy/token_test.go @@ -14,7 +14,6 @@ package policy -/* import ( "testing" @@ -35,7 +34,7 @@ func TestSerialize(t *testing.T) { jsonEmb := jsonutils.Marshal(&emb) - t.Logf("%s", jsonEmb) + t.Logf("json: %s", jsonEmb) nemb := SEmbed{} @@ -44,6 +43,39 @@ func TestSerialize(t *testing.T) { t.Errorf("fail to unmarshal: %s", err) } else { jsonEmb2 := jsonutils.Marshal(&nemb) - t.Logf("%s", jsonEmb2) + t.Logf("unmarshal: %s", jsonEmb2) } -}*/ +} + +func TestSerialize2(t *testing.T) { + type SEmbed struct { + UserCred mcclient.TokenCredential + } + type SUnEmbed struct { + UserCred struct { + TokenCredential mcclient.TokenCredential + } + } + token := &SPolicyTokenCredential{ + &mcclient.SSimpleToken{ + User: "Test", + }, + } + + emb := SEmbed{} + emb.UserCred = token + + jsonEmb := jsonutils.Marshal(&emb) + + t.Logf("json: %s", jsonEmb) + + nemb := SUnEmbed{} + + err := jsonEmb.Unmarshal(&nemb) + if err != nil { + t.Errorf("fail to unmarshal: %s", err) + } else { + jsonEmb2 := jsonutils.Marshal(&nemb) + t.Logf("unmarshal: %s", jsonEmb2) + } +} diff --git a/vendor/yunion.io/x/jsonutils/OWNERS b/vendor/yunion.io/x/jsonutils/OWNERS new file mode 100644 index 0000000000..790f34ecb2 --- /dev/null +++ b/vendor/yunion.io/x/jsonutils/OWNERS @@ -0,0 +1,12 @@ +# See the OWNERS docs at https://go.k8s.io/owners +reviewers: + - swordqiu + - yousong + - wanyaoqi + - Zexi + - ioito + - tb365 +approvers: + - swordqiu + - yousong + - wanyaoqi diff --git a/vendor/yunion.io/x/jsonutils/unmarshal.go b/vendor/yunion.io/x/jsonutils/unmarshal.go index a66d6bcc39..e507e40821 100644 --- a/vendor/yunion.io/x/jsonutils/unmarshal.go +++ b/vendor/yunion.io/x/jsonutils/unmarshal.go @@ -429,7 +429,32 @@ func (this *JSONDict) unmarshalValue(val reflect.Value) error { case reflect.Struct: return this.unmarshalStruct(val) case reflect.Interface: - val.Set(reflect.ValueOf(this.data)) + if val.Type().Implements(gotypes.ISerializableType) { + objPtr, err := gotypes.NewSerializable(val.Type()) + if err != nil { + return err + } + if objPtr == nil { + val.Set(reflect.ValueOf(this.data)) + return nil + } + err = this.unmarshalValue(reflect.ValueOf(objPtr)) + if err != nil { + return err + } + // + // XXX + // + // cannot unmarshal nested anonymous interface + // as nested anonymous interface is treated as a named field + // please use jsonutils.Deserialize to descrialize such interface + // ... + // objPtr = gotypes.Transform(val.Type(), objPtr) + // + val.Set(reflect.ValueOf(objPtr).Convert(val.Type())) + } else { + return fmt.Errorf("Do not known how to deserialize json into this interface type %s", val.Type()) + } case reflect.Ptr: kind := val.Type().Elem().Kind() if kind == reflect.Struct || kind == reflect.Map { diff --git a/vendor/yunion.io/x/log/OWNERS b/vendor/yunion.io/x/log/OWNERS new file mode 100644 index 0000000000..2f0953c8a0 --- /dev/null +++ b/vendor/yunion.io/x/log/OWNERS @@ -0,0 +1,13 @@ +# See the OWNERS docs at https://go.k8s.io/owners +reviewers: + - swordqiu + - yousong + - wanyaoqi + - Zexi + - ioito + - tb365 +approvers: + - swordqiu + - yousong + - wanyaoqi + - Zexi diff --git a/vendor/yunion.io/x/sqlchemy/OWNERS b/vendor/yunion.io/x/sqlchemy/OWNERS new file mode 100644 index 0000000000..790f34ecb2 --- /dev/null +++ b/vendor/yunion.io/x/sqlchemy/OWNERS @@ -0,0 +1,12 @@ +# See the OWNERS docs at https://go.k8s.io/owners +reviewers: + - swordqiu + - yousong + - wanyaoqi + - Zexi + - ioito + - tb365 +approvers: + - swordqiu + - yousong + - wanyaoqi diff --git a/vendor/yunion.io/x/structarg/OWNERS b/vendor/yunion.io/x/structarg/OWNERS new file mode 100644 index 0000000000..790f34ecb2 --- /dev/null +++ b/vendor/yunion.io/x/structarg/OWNERS @@ -0,0 +1,12 @@ +# See the OWNERS docs at https://go.k8s.io/owners +reviewers: + - swordqiu + - yousong + - wanyaoqi + - Zexi + - ioito + - tb365 +approvers: + - swordqiu + - yousong + - wanyaoqi