fix(region): vendor update (#17854)

This commit is contained in:
屈轩
2023-08-27 04:56:32 +08:00
committed by GitHub
parent 3eb8486299
commit 7a1cb3910b
40 changed files with 1401 additions and 172 deletions

View File

@@ -285,9 +285,9 @@ dep:
GOPROXY ?= direct
mod:
GOPROXY=$(GOPROXY) go get -d $(patsubst %,%@master,$(shell GO111MODULE=on go mod edit -print | sed -n -e 's|.*\(yunion.io/x/[a-z].*\) v.*|\1|p'))
go mod tidy
go mod vendor -v
GOPROXY=$(GOPROXY) GONOSUMDB=yunion.io/x go get -d $(patsubst %,%@master,$(shell GO111MODULE=on go mod edit -print | sed -n -e 's|.*\(yunion.io/x/[a-z].*\) v.*|\1|p'))
GOPROXY=$(GOPROXY) GONOSUMDB=yunion.io/x go mod tidy
GOPROXY=$(GOPROXY) GONOSUMDB=yunion.io/x go mod vendor -v
define helpText
Build with docker

8
go.mod
View File

@@ -104,16 +104,16 @@ require (
moul.io/http2curl/v2 v2.3.0
yunion.io/x/log v1.0.1-0.20230411060016-feb3f46ab361
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900
yunion.io/x/pkg v1.0.1-0.20230420104238-bbd084afbdfe
yunion.io/x/pkg v1.0.1-0.20230711090507-0aafe0f0c9db
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
yunion.io/x/sqlchemy v1.1.2-0.20230422192549-7a9668176f46
yunion.io/x/sqlchemy v1.1.2-0.20230823191329-dc02ac3a547c
yunion.io/x/structarg v0.0.0-20220312084958-9c6c79c7d1c6
)
require (
github.com/google/uuid v1.3.0
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656
yunion.io/x/jsonutils v0.0.0-20220106020632-953b71a4c3a8
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32
yunion.io/x/jsonutils v1.0.1-0.20230613121553-0f3b41e2ef19
)
require (

17
go.sum
View File

@@ -1148,11 +1148,11 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656 h1:0zlZD5uhZoIHgLVAWCz2aHaYk2ZrNsACCYD7R6EIBII=
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 h1:v7POYkQwo1XzOxBoIoRVr/k0V9Y5JyjpshlIFa9raug=
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
yunion.io/x/jsonutils v0.0.0-20220106020632-953b71a4c3a8 h1:yFJVMnUoolC8mlUxa+LMTObYmqJ2H7iyxGIaXxT1fOc=
yunion.io/x/jsonutils v0.0.0-20220106020632-953b71a4c3a8/go.mod h1:p0nyMqGA/apTxxyLIU/o1k4V7Vujl2O6ey30L594sYE=
yunion.io/x/jsonutils v1.0.1-0.20230613121553-0f3b41e2ef19 h1:mZh6vuo7oOiOtE5HF4667+XBNnn7uYpmGN5eIgCVMLk=
yunion.io/x/jsonutils v1.0.1-0.20230613121553-0f3b41e2ef19/go.mod h1:VK4Z93dgiKgAijcSqbMKmGaBMJuHulR16Hz4K015ZPo=
yunion.io/x/log v0.0.0-20190514041436-04ce53b17c6b/go.mod h1:+gauLs73omeJAPlsXcevLsJLKixV+sR/E7WSYTSx1fE=
yunion.io/x/log v0.0.0-20190629062853-9f6483a7103d/go.mod h1:LC6f/4FozL0iaAbnFt2eDX9jlsyo3WiOUPm03d7+U4U=
yunion.io/x/log v1.0.1-0.20230411060016-feb3f46ab361 h1:c5LyNdhbvBe/92pXs9jgXOU/S+RgYh/DHe538LpT/Mo=
@@ -1161,12 +1161,11 @@ yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900 h1:Hu/4ERvoWaN6aiFs4h4/yvVB
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900/go.mod h1:0vLkNEhlmA64HViPBAnSTUMrx5QP1CLsxXmxDKQ80tc=
yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/pkg v0.0.0-20190628082551-f4033ba2ea30/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/pkg v0.0.0-20200814072949-4f1b541857d6/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/pkg v1.0.1-0.20230420104238-bbd084afbdfe h1:pwjs6kOP3cenRN+Oc2zyJerAhBAn4owaLbzZyLx5/rA=
yunion.io/x/pkg v1.0.1-0.20230420104238-bbd084afbdfe/go.mod h1:ksCJVQ+DwKrJ5QBEoU8pzrDFfDaZVAFH/iJ6yQCYxJk=
yunion.io/x/pkg v1.0.1-0.20230711090507-0aafe0f0c9db h1:GyBvo/gYl2MY5Q0SZ6Nso8WJHPonmngOtcpVfyCE0yA=
yunion.io/x/pkg v1.0.1-0.20230711090507-0aafe0f0c9db/go.mod h1:ksCJVQ+DwKrJ5QBEoU8pzrDFfDaZVAFH/iJ6yQCYxJk=
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 v1.1.2-0.20230422192549-7a9668176f46 h1:M/Xv+Qu6/dSMyuvhgbs52/adr+O5k5NXtpF7czYVCJU=
yunion.io/x/sqlchemy v1.1.2-0.20230422192549-7a9668176f46/go.mod h1:xXVfJLIxxTRTnPEaVIIoRZXqWyO8+takIOYhc+zO5KE=
yunion.io/x/sqlchemy v1.1.2-0.20230823191329-dc02ac3a547c h1:9R2cTcmPBUno1P2YI321nztK1Jpu7QRBNbnHsI1uX1Q=
yunion.io/x/sqlchemy v1.1.2-0.20230823191329-dc02ac3a547c/go.mod h1:uuPVZEyEq3sWd5vf9VjGSy6lZzof22X87OEHw9sddJQ=
yunion.io/x/structarg v0.0.0-20220312084958-9c6c79c7d1c6 h1:WuWXhY3DvhdRTzWCJ/kwt3Ss6KIq7+KqJwb+esvNGwU=
yunion.io/x/structarg v0.0.0-20220312084958-9c6c79c7d1c6/go.mod h1:EP6NSv2C0zzqBDTKumv8hPWLb3XvgMZDHQRfyuOrQng=

View File

@@ -69,8 +69,8 @@ func TestAzureRuleSync(t *testing.T) {
},
Common: []cloudprovider.SecurityRule{},
InAdds: []cloudprovider.SecurityRule{
ruleWithName("", "in:allow tcp", 4094),
ruleWithName("", "in:allow udp", 4095),
ruleWithName("", "in:allow udp", 4094),
ruleWithName("", "in:allow tcp", 4095),
},
OutAdds: []cloudprovider.SecurityRule{},
InDels: []cloudprovider.SecurityRule{
@@ -92,15 +92,13 @@ func TestAzureRuleSync(t *testing.T) {
},
Common: []cloudprovider.SecurityRule{
ruleWithName("allow-icmp", "in:allow icmp", 400),
},
InAdds: []cloudprovider.SecurityRule{
ruleWithName("", "in:allow tcp", 398),
ruleWithName("", "in:allow udp", 399),
},
OutAdds: []cloudprovider.SecurityRule{},
InDels: []cloudprovider.SecurityRule{
ruleWithName("allow-tcp", "in:allow tcp", 300),
},
InAdds: []cloudprovider.SecurityRule{
ruleWithName("", "in:allow udp", 300),
},
OutAdds: []cloudprovider.SecurityRule{},
InDels: []cloudprovider.SecurityRule{},
OutDels: []cloudprovider.SecurityRule{},
},
{
@@ -113,14 +111,14 @@ func TestAzureRuleSync(t *testing.T) {
DestRules: []cloudprovider.SecurityRule{
ruleWithName("allow-tcp-22", "in:allow tcp 22", 300),
},
Common: []cloudprovider.SecurityRule{
ruleWithName("allow-tcp-22", "in:allow tcp 22", 300),
},
Common: []cloudprovider.SecurityRule{},
InAdds: []cloudprovider.SecurityRule{
ruleWithName("", "in:allow tcp 33", 299),
ruleWithName("", "in:allow tcp 22,33", 4095),
},
OutAdds: []cloudprovider.SecurityRule{},
InDels: []cloudprovider.SecurityRule{},
InDels: []cloudprovider.SecurityRule{
ruleWithName("allow-tcp-22", "in:allow tcp 22", 300),
},
OutDels: []cloudprovider.SecurityRule{},
},
{
@@ -141,17 +139,17 @@ func TestAzureRuleSync(t *testing.T) {
ruleWithName("in_allow_tcp_1050_4010", "in:allow tcp 1050", 4010),
},
Common: []cloudprovider.SecurityRule{
ruleWithName("in_allow_tcp_22_4013", "in:allow tcp 22", 4013),
ruleWithName("in_allow_udp_55_4014", "in:allow udp 55", 4014),
ruleWithName("in_allow_tcp_1002_4012", "in:allow tcp 1002", 4012),
ruleWithName("in_allow_tcp_1050_4010", "in:allow tcp 1050", 4010),
},
InAdds: []cloudprovider.SecurityRule{
ruleWithName("", "in:allow tcp 1011", 4011),
ruleWithName("", "in:allow tcp 22,1002,1011,1050", 4095),
},
OutAdds: []cloudprovider.SecurityRule{},
InDels: []cloudprovider.SecurityRule{
ruleWithName("in_allow_tcp_22_4013", "in:allow tcp 22", 4013),
ruleWithName("in_allow_tcp_1002_4012", "in:allow tcp 1002", 4012),
ruleWithName("in_allow_tcp_1010_4011", "in:allow tcp 1010", 4011),
ruleWithName("in_allow_tcp_1050_4010", "in:allow tcp 1050", 4010),
},
OutDels: []cloudprovider.SecurityRule{},
},
@@ -175,19 +173,19 @@ func TestAzureRuleSync(t *testing.T) {
ruleWithName("in_allow_tcp_1050_4010", "in:allow tcp 1050", 4010),
ruleWithName("in_allow_tcp_1055_4009", "in:allow tcp 1055", 4009),
},
Common: []cloudprovider.SecurityRule{
ruleWithName("in_allow_tcp_22_4013", "in:allow tcp 22", 4013),
ruleWithName("in_allow_udp_55_4014", "in:allow udp 55", 4014),
ruleWithName("in_allow_tcp_1002_4012", "in:allow tcp 1002", 4012),
ruleWithName("in_allow_tcp_1012_4011", "in:allow tcp 1012", 4011),
ruleWithName("in_allow_tcp_1050_4010", "in:allow tcp 1050", 4010),
},
Common: []cloudprovider.SecurityRule{},
InAdds: []cloudprovider.SecurityRule{
ruleWithName("", "in:allow icmp", 4009),
ruleWithName("", "in:allow udp 1055", 4008),
ruleWithName("", "in:allow icmp", 4095),
ruleWithName("", "in:allow tcp 22,1002,1012,1050", 4094),
ruleWithName("", "in:allow udp 55,1055", 4093),
},
OutAdds: []cloudprovider.SecurityRule{},
InDels: []cloudprovider.SecurityRule{
ruleWithName("in_allow_udp_55_4014", "in:allow udp 55", 4014),
ruleWithName("in_allow_tcp_22_4013", "in:allow tcp 22", 4013),
ruleWithName("in_allow_tcp_1002_4012", "in:allow tcp 1002", 4012),
ruleWithName("in_allow_tcp_1012_4011", "in:allow tcp 1012", 4011),
ruleWithName("in_allow_tcp_1050_4010", "in:allow tcp 1050", 4010),
ruleWithName("in_allow_tcp_1055_4009", "in:allow tcp 1055", 4009),
},
OutDels: []cloudprovider.SecurityRule{},

View File

@@ -63,11 +63,7 @@ func TestKvmRuleSync(t *testing.T) {
},
Common: []cloudprovider.SecurityRule{},
InAdds: []cloudprovider.SecurityRule{
ruleWithName("", "in:allow tcp 1521", 1),
ruleWithName("", "in:allow tcp 3389", 1),
ruleWithName("", "in:allow tcp 443", 1),
ruleWithName("", "in:allow tcp 6379", 1),
ruleWithName("", "in:allow tcp 80", 1),
ruleWithName("", "in:allow tcp 80,443,1521,3389,6379", 1),
},
OutAdds: []cloudprovider.SecurityRule{},
InDels: []cloudprovider.SecurityRule{

10
vendor/modules.txt vendored
View File

@@ -1432,13 +1432,13 @@ sigs.k8s.io/structured-merge-diff/v4/value
# sigs.k8s.io/yaml v1.2.0
## explicit; go 1.12
sigs.k8s.io/yaml
# yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656
# yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32
## explicit; go 1.12
yunion.io/x/executor/apis
yunion.io/x/executor/client
yunion.io/x/executor/server
# yunion.io/x/jsonutils v0.0.0-20220106020632-953b71a4c3a8
## explicit; go 1.12
# yunion.io/x/jsonutils v1.0.1-0.20230613121553-0f3b41e2ef19
## explicit; go 1.18
yunion.io/x/jsonutils
# yunion.io/x/log v1.0.1-0.20230411060016-feb3f46ab361
## explicit; go 1.12
@@ -1449,7 +1449,7 @@ yunion.io/x/log/hooks
yunion.io/x/ovsdb/cli_util
yunion.io/x/ovsdb/schema/ovn_nb
yunion.io/x/ovsdb/types
# yunion.io/x/pkg v1.0.1-0.20230420104238-bbd084afbdfe
# yunion.io/x/pkg v1.0.1-0.20230711090507-0aafe0f0c9db
## explicit; go 1.18
yunion.io/x/pkg/errors
yunion.io/x/pkg/gotypes
@@ -1486,7 +1486,7 @@ yunion.io/x/pkg/utils
# yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
## explicit; go 1.12
yunion.io/x/s3cli
# yunion.io/x/sqlchemy v1.1.2-0.20230422192549-7a9668176f46
# yunion.io/x/sqlchemy v1.1.2-0.20230823191329-dc02ac3a547c
## explicit; go 1.17
yunion.io/x/sqlchemy
yunion.io/x/sqlchemy/backends

201
vendor/yunion.io/x/executor/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@@ -16,7 +16,23 @@ import (
"yunion.io/x/executor/apis"
)
var exec *Executor
const (
defaultTimeoutSecs = 3
)
var (
exec *Executor
timeoutSeconds = defaultTimeoutSecs
)
func SetTimeoutSeconds(secs int) {
timeoutSeconds = secs
}
func GetTimeoutSeconds() int {
return timeoutSeconds
}
type Executor struct {
socketPath string
@@ -94,7 +110,7 @@ type Cmd struct {
func grcpDialWithUnixSocket(ctx context.Context, socketPath string) (*grpc.ClientConn, error) {
return grpc.DialContext(
ctx, socketPath,
grpc.WithInsecure(), grpc.WithBlock(), grpc.WithTimeout(time.Second*3),
grpc.WithInsecure(), grpc.WithBlock(), grpc.WithTimeout(time.Second*time.Duration(timeoutSeconds)),
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("unix", addr, timeout)
}),

9
vendor/yunion.io/x/jsonutils/Makefile generated vendored Normal file
View File

@@ -0,0 +1,9 @@
test:
go test -v ./...
GOPROXY ?= direct
mod:
GOPROXY=$(GOPROXY) GONOSUMDB=yunion.io/x \
go get -d $(patsubst %,%@master,$(shell GO111MODULE=on go mod edit -print | sed -n -e 's|.*\(yunion.io/x/[a-z].*\) v.*|\1|p'))
go mod tidy

79
vendor/yunion.io/x/jsonutils/json_pointer_trace.go generated vendored Normal file
View File

@@ -0,0 +1,79 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package jsonutils
import (
"fmt"
"strings"
)
type sJsonPointerNode struct {
pointer *sJSONPointer
inf interface{}
refcnt int
}
func (n *sJsonPointerNode) String() string {
return fmt.Sprintf("<%d>", n.pointer.nodeId)
}
type sJsonPointerTrace struct {
trace []*sJsonPointerNode
}
func newJsonPointerTrace() *sJsonPointerTrace {
return &sJsonPointerTrace{
trace: make([]*sJsonPointerNode, 0, 10),
}
}
func (t *sJsonPointerTrace) push(inf interface{}, ptr *sJSONPointer) *sJsonPointerNode {
node := &sJsonPointerNode{
pointer: ptr,
inf: inf,
refcnt: 1,
}
t.trace = append(t.trace, node)
// log.Debugf("push: %s", t.String())
return node
}
func (t *sJsonPointerTrace) find(inf interface{}) *sJsonPointerNode {
var ret *sJsonPointerNode
for i := range t.trace {
if t.trace[i].inf == inf {
ret = t.trace[i]
}
if ret != nil {
t.trace[i].refcnt++
}
}
return ret
}
func (t *sJsonPointerTrace) pop() {
if len(t.trace) > 0 && t.trace[len(t.trace)-1].refcnt == 1 {
t.trace = t.trace[0 : len(t.trace)-1]
}
// log.Debugf("pop: %s", t.String())
}
func (t *sJsonPointerTrace) String() string {
buf := &strings.Builder{}
for i := range t.trace {
buf.WriteString(t.trace[i].String())
}
return buf.String()
}

176
vendor/yunion.io/x/jsonutils/jsonpointer.go generated vendored Normal file
View File

@@ -0,0 +1,176 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package jsonutils
import (
"fmt"
"reflect"
"strings"
"time"
)
const (
jsonPointerKey = "___jnid_"
)
type sJSONPointer struct {
node JSONObject
nodeId int
}
var _ JSONObject = (*sJSONPointer)(nil)
func (s *sJsonMarshalSession) newJsonPointer(inf interface{}) *sJSONPointer {
s.nodeIndex++
jsonPtr := &sJSONPointer{
nodeId: s.nodeIndex,
}
s.nodeMap[s.nodeIndex] = s.objectTrace.push(inf, jsonPtr)
return jsonPtr
}
func (s *sJsonMarshalSession) setJsonObject(ptr *sJSONPointer, obj JSONObject) {
if _, ok := obj.(*JSONDict); ok {
ptr.node = obj
}
s.objectTrace.pop()
}
func (s *sJsonMarshalSession) setAllNodeId() {
for nodeId, jsonPtrNode := range s.nodeMap {
if jsonPtrNode.refcnt > 1 && jsonPtrNode.pointer.node != nil {
jsonPtrNode.pointer.node.(*JSONDict).setNodeId(nodeId)
}
}
}
func (ptr *sJSONPointer) String() string {
return fmt.Sprintf("<%d>", ptr.nodeId)
}
func (ptr *sJSONPointer) PrettyString() string {
return ptr.String()
}
func (ptr *sJSONPointer) buildString(sb *strings.Builder) {
sb.WriteString(ptr.String())
}
func (dict *JSONDict) setNodeId(nodeId int) {
dict.nodeId = nodeId
}
func (ptr *sJSONPointer) unmarshalValue(s *sJsonUnmarshalSession, val reflect.Value) error {
return s.setPointerValue(ptr.nodeId, val)
}
func (ptr *sJSONPointer) IsZero() bool {
if ptr.node != nil {
return ptr.node.IsZero()
}
return true
}
func (ptr *sJSONPointer) parse(s *sJsonParseSession, str []byte, offset int) (int, error) {
// null ops
return -1, nil
}
func (ptr *sJSONPointer) prettyString(level int) string {
return jsonPrettyString(ptr, level)
}
func (ptr *sJSONPointer) YAMLString() string {
return ptr.String()
}
func (ptr *sJSONPointer) QueryString() string {
return ""
}
func (ptr *sJSONPointer) _queryString(key string) string {
return ""
}
func (ptr *sJSONPointer) getNode() JSONObject {
if ptr.node != nil {
return ptr.node
}
return JSONNull
}
func (ptr *sJSONPointer) Contains(keys ...string) bool {
return ptr.getNode().Contains(keys...)
}
func (ptr *sJSONPointer) ContainsIgnoreCases(keys ...string) bool {
return ptr.getNode().ContainsIgnoreCases(keys...)
}
func (ptr *sJSONPointer) Get(keys ...string) (JSONObject, error) {
return ptr.getNode().Get(keys...)
}
func (ptr *sJSONPointer) GetIgnoreCases(keys ...string) (JSONObject, error) {
return ptr.getNode().GetIgnoreCases(keys...)
}
func (ptr *sJSONPointer) GetAt(i int, keys ...string) (JSONObject, error) {
return ptr.getNode().GetAt(i, keys...)
}
func (ptr *sJSONPointer) Int(keys ...string) (int64, error) {
return ptr.getNode().Int(keys...)
}
func (ptr *sJSONPointer) Float(keys ...string) (float64, error) {
return ptr.getNode().Float(keys...)
}
func (ptr *sJSONPointer) Bool(keys ...string) (bool, error) {
return ptr.getNode().Bool(keys...)
}
func (ptr *sJSONPointer) GetMap(keys ...string) (map[string]JSONObject, error) {
return ptr.getNode().GetMap(keys...)
}
func (ptr *sJSONPointer) GetArray(keys ...string) ([]JSONObject, error) {
return ptr.getNode().GetArray(keys...)
}
func (ptr *sJSONPointer) GetTime(keys ...string) (time.Time, error) {
return ptr.getNode().GetTime(keys...)
}
func (ptr *sJSONPointer) GetString(keys ...string) (string, error) {
return ptr.getNode().GetString(keys...)
}
func (ptr *sJSONPointer) Unmarshal(obj interface{}, keys ...string) error {
return ptr.getNode().Unmarshal(obj, keys...)
}
func (ptr *sJSONPointer) Equals(obj JSONObject) bool {
return ptr.getNode().Equals(obj)
}
func (ptr *sJSONPointer) Interface() interface{} {
return ptr.getNode().Interface()
}
func (ptr *sJSONPointer) isCompond() bool {
return ptr.getNode().isCompond()
}

View File

@@ -30,7 +30,7 @@ import (
type JSONObject interface {
gotypes.ISerializable
parse(str []byte, offset int) (int, error)
parse(s *sJsonParseSession, str []byte, offset int) (int, error)
writeSource
// String() string
@@ -53,7 +53,7 @@ type JSONObject interface {
GetString(keys ...string) (string, error)
Unmarshal(obj interface{}, keys ...string) error
Equals(obj JSONObject) bool
unmarshalValue(val reflect.Value) error
unmarshalValue(s *sJsonUnmarshalSession, val reflect.Value) error
// IsZero() bool
Interface() interface{}
isCompond() bool
@@ -71,6 +71,8 @@ var (
type JSONDict struct {
JSONValue
data sortedmap.SSortedMap
nodeId int
}
type JSONArray struct {
@@ -248,12 +250,25 @@ ret2:
return string(str[offset:i]), false, i, nil
}
func parseJSONValue(str []byte, offset int) (JSONObject, int, error) {
func (s *sJsonParseSession) parseJSONValue(str []byte, offset int) (JSONObject, int, error) {
val, quote, i, e := parseString(str, offset)
if e != nil {
return nil, i, errors.Wrap(e, "parseString")
} else if quote {
return &JSONString{data: val}, i, nil
} else if val[0] == '<' && val[len(val)-1] == '>' {
// Pointer <nnnn>
val = val[1 : len(val)-1]
ival, err := strconv.ParseInt(val, 10, 64)
if err != nil {
return nil, i, errors.Wrapf(errors.ErrInvalidStatus, "invalid node id %s", val)
}
nodeId := int(ival)
ptr := &sJSONPointer{
nodeId: nodeId,
}
s.saveReferer(nodeId, ptr)
return ptr, i, nil
} else {
lval := strings.ToLower(val)
if len(lval) == 0 || lval == "null" || lval == "none" {
@@ -362,7 +377,7 @@ func (this *JSONString) prettyString(level int) string {
return jsonPrettyString(this, level)
}
func (this *JSONValue) parse(str []byte, offset int) (int, error) {
func (this *JSONValue) parse(s *sJsonParseSession, str []byte, offset int) (int, error) {
return 0, nil
}
@@ -398,10 +413,11 @@ func (this *JSONBool) prettyString(level int) string {
return jsonPrettyString(this, level)
}
func parseDict(str []byte, offset int) (sortedmap.SSortedMap, int, error) {
func (s *sJsonParseSession) parseDict(str []byte, offset int) (sortedmap.SSortedMap, int, int, error) {
var nodeId int
smap := sortedmap.NewSortedMap()
if str[offset] != '{' {
return smap, offset, NewJSONError(str, offset, "{ not found")
return smap, offset, nodeId, NewJSONError(str, offset, "{ not found")
}
var i = offset + 1
var e error = nil
@@ -410,7 +426,7 @@ func parseDict(str []byte, offset int) (sortedmap.SSortedMap, int, error) {
for !stop && i < len(str) {
i = skipEmpty(str, i)
if i >= len(str) {
return smap, i, NewJSONError(str, i, "Truncated")
return smap, i, nodeId, NewJSONError(str, i, "Truncated")
}
if str[i] == '}' {
stop = true
@@ -419,41 +435,46 @@ func parseDict(str []byte, offset int) (sortedmap.SSortedMap, int, error) {
}
key, _, i, e = parseString(str, i)
if e != nil {
return smap, i, errors.Wrap(e, "parseString")
return smap, i, nodeId, errors.Wrap(e, "parseString")
}
if i >= len(str) {
return smap, i, NewJSONError(str, i, "Truncated")
return smap, i, nodeId, NewJSONError(str, i, "Truncated")
}
i = skipEmpty(str, i)
if i >= len(str) {
return smap, i, NewJSONError(str, i, "Truncated")
return smap, i, nodeId, NewJSONError(str, i, "Truncated")
}
if str[i] != ':' {
return smap, i, NewJSONError(str, i, ": not found")
return smap, i, nodeId, NewJSONError(str, i, ": not found")
}
i++
i = skipEmpty(str, i)
if i >= len(str) {
return smap, i, NewJSONError(str, i, "Truncated")
return smap, i, nodeId, NewJSONError(str, i, "Truncated")
}
var val JSONObject = nil
switch str[i] {
case '[':
val = &JSONArray{}
i, e = val.parse(str, i)
i, e = val.parse(s, str, i)
case '{':
val = &JSONDict{}
i, e = val.parse(str, i)
i, e = val.parse(s, str, i)
default:
val, i, e = parseJSONValue(str, i)
val, i, e = s.parseJSONValue(str, i)
}
if e != nil {
return smap, i, errors.Wrap(e, "parse misc")
return smap, i, nodeId, errors.Wrap(e, "parse misc")
}
if key == jsonPointerKey {
// node id
nodeId = int(val.(*JSONInt).data)
} else {
smap = sortedmap.Add(smap, key, val)
}
smap = sortedmap.Add(smap, key, val)
i = skipEmpty(str, i)
if i >= len(str) {
return smap, i, NewJSONError(str, i, "Truncated")
return smap, i, nodeId, NewJSONError(str, i, "Truncated")
}
switch str[i] {
case ',':
@@ -462,13 +483,13 @@ func parseDict(str []byte, offset int) (sortedmap.SSortedMap, int, error) {
i++
stop = true
default:
return smap, i, NewJSONError(str, i, "Unexpected char")
return smap, i, nodeId, NewJSONError(str, i, "Unexpected char")
}
}
return smap, i, nil
return smap, i, nodeId, nil
}
func parseArray(str []byte, offset int) ([]JSONObject, int, error) {
func (s *sJsonParseSession) parseArray(str []byte, offset int) ([]JSONObject, int, error) {
if str[offset] != '[' {
return nil, offset, NewJSONError(str, offset, "[ not found")
}
@@ -491,12 +512,12 @@ func parseArray(str []byte, offset int) ([]JSONObject, int, error) {
continue
case '[':
val = &JSONArray{}
i, e = val.parse(str, i)
i, e = val.parse(s, str, i)
case '{':
val = &JSONDict{}
i, e = val.parse(str, i)
i, e = val.parse(s, str, i)
default:
val, i, e = parseJSONValue(str, i)
val, i, e = s.parseJSONValue(str, i)
}
if e != nil {
return list, i, errors.Wrap(e, "parse misc")
@@ -522,10 +543,14 @@ func parseArray(str []byte, offset int) ([]JSONObject, int, error) {
return list, i, nil
}
func (this *JSONDict) parse(str []byte, offset int) (int, error) {
smap, i, e := parseDict(str, offset)
func (this *JSONDict) parse(s *sJsonParseSession, str []byte, offset int) (int, error) {
smap, i, nodeId, e := s.parseDict(str, offset)
if e == nil {
this.nodeId = nodeId
this.data = smap
if this.nodeId > 0 {
s.saveNode(nodeId, this)
}
return i, nil
}
return i, errors.Wrap(e, "parseDict")
@@ -580,8 +605,8 @@ func (this *JSONDict) prettyString(level int) string {
return buffer.String()
}
func (this *JSONArray) parse(str []byte, offset int) (int, error) {
val, i, e := parseArray(str, offset)
func (this *JSONArray) parse(s *sJsonParseSession, str []byte, offset int) (int, error) {
val, i, e := s.parseArray(str, offset)
if e == nil {
this.data = val
}
@@ -621,6 +646,7 @@ func ParseString(str string) (JSONObject, error) {
}
func Parse(str []byte) (JSONObject, error) {
s := newJsonParseSession()
var i = 0
i = skipEmpty(str, i)
var val JSONObject = nil
@@ -629,12 +655,12 @@ func Parse(str []byte) (JSONObject, error) {
switch str[i] {
case '{':
val = &JSONDict{}
i, e = val.parse(str, i)
i, e = val.parse(s, str, i)
case '[':
val = &JSONArray{}
i, e = val.parse(str, i)
i, e = val.parse(s, str, i)
default:
val, i, e = parseJSONValue(str, i)
val, i, e = s.parseJSONValue(str, i)
// return nil, NewJSONError(str, i, "Invalid JSON string")
}
if e != nil {

View File

@@ -24,6 +24,7 @@ Convert any object to JSONObject
import (
"fmt"
"reflect"
"sort"
"time"
"yunion.io/x/log"
@@ -33,7 +34,7 @@ import (
"yunion.io/x/pkg/util/timeutils"
)
func marshalSlice(val reflect.Value, info *reflectutils.SStructFieldInfo, omitEmpty bool) JSONObject {
func (s *sJsonMarshalSession) marshalSlice(val reflect.Value, info *reflectutils.SStructFieldInfo, omitEmpty bool) JSONObject {
if val.Kind() == reflect.Slice && val.IsNil() {
if !omitEmpty {
return JSONNull
@@ -46,7 +47,7 @@ func marshalSlice(val reflect.Value, info *reflectutils.SStructFieldInfo, omitEm
}
objs := make([]JSONObject, 0)
for i := 0; i < val.Len(); i += 1 {
val := marshalValue(val.Index(i), nil, omitEmpty)
val := s.marshalValue(val.Index(i), nil, omitEmpty)
if val != nil {
objs = append(objs, val)
}
@@ -59,7 +60,13 @@ func marshalSlice(val reflect.Value, info *reflectutils.SStructFieldInfo, omitEm
}
}
func marshalMap(val reflect.Value, info *reflectutils.SStructFieldInfo, omitEmpty bool) JSONObject {
type tMapKeys []reflect.Value
func (a tMapKeys) Len() int { return len(a) }
func (a tMapKeys) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a tMapKeys) Less(i, j int) bool { return a[i].String() < a[j].String() }
func (s *sJsonMarshalSession) marshalMap(val reflect.Value, info *reflectutils.SStructFieldInfo, omitEmpty bool) JSONObject {
if val.IsNil() {
if !omitEmpty {
return JSONNull
@@ -71,10 +78,12 @@ func marshalMap(val reflect.Value, info *reflectutils.SStructFieldInfo, omitEmpt
if len(keys) == 0 && info != nil && info.OmitEmpty && omitEmpty {
return nil
}
// sort keys
sort.Sort(tMapKeys(keys))
objPairs := make([]JSONPair, 0)
for i := 0; i < len(keys); i += 1 {
key := keys[i]
val := marshalValue(val.MapIndex(key), nil, omitEmpty)
val := s.marshalValue(val.MapIndex(key), nil, omitEmpty)
if val != nil {
objPairs = append(objPairs, JSONPair{key: fmt.Sprintf("%s", key), val: val})
}
@@ -87,8 +96,8 @@ func marshalMap(val reflect.Value, info *reflectutils.SStructFieldInfo, omitEmpt
}
}
func marshalStruct(val reflect.Value, info *reflectutils.SStructFieldInfo, omitEmpty bool) JSONObject {
objPairs := struct2JSONPairs(val, omitEmpty)
func (s *sJsonMarshalSession) marshalStruct(val reflect.Value, info *reflectutils.SStructFieldInfo, omitEmpty bool) JSONObject {
objPairs := s.struct2JSONPairs(val, omitEmpty)
if len(objPairs) == 0 && info != nil && info.OmitEmpty && omitEmpty {
return nil
}
@@ -109,7 +118,7 @@ func findValueByKey(pairs []JSONPair, key string) JSONObject {
return nil
}
func struct2JSONPairs(val reflect.Value, omitEmpty bool) []JSONPair {
func (s *sJsonMarshalSession) struct2JSONPairs(val reflect.Value, omitEmpty bool) []JSONPair {
fields := reflectutils.FetchStructFieldValueSet(val)
objPairs := make([]JSONPair, 0, len(fields))
depFields := make(map[string]string)
@@ -123,7 +132,7 @@ func struct2JSONPairs(val reflect.Value, omitEmpty bool) []JSONPair {
depFields[key] = deprecatedBy
continue
}
val := marshalValue(fields[i].Value, jsonInfo, omitEmpty)
val := s.marshalValue(fields[i].Value, jsonInfo, omitEmpty)
if val != nil {
objPair := JSONPair{key: key, val: val}
objPairs = append(objPairs, objPair)
@@ -242,15 +251,42 @@ func Marshal(obj interface{}) JSONObject {
if kind := val.Kind(); val.IsZero() && kind == reflect.Ptr {
return JSONNull
}
objValue := reflect.Indirect(val)
mval := marshalValue(objValue, nil, true)
s := newJsonMarshalSession()
mval := s.marshalValue(val, nil, true)
s.setAllNodeId()
if mval == nil {
return JSONNull
}
return mval
}
func marshalValue(objValue reflect.Value, info *reflectutils.SStructFieldInfo, omitEmpty bool) JSONObject {
func (s *sJsonMarshalSession) marshalValue(objValue reflect.Value, info *reflectutils.SStructFieldInfo, omitEmpty bool) JSONObject {
return tryStdMarshal(objValue, func(v reflect.Value) JSONObject {
return s.marshalValueWithObjectMap(v, info, omitEmpty)
})
}
func (s *sJsonMarshalSession) marshalValueWithObjectMap(objValue reflect.Value, info *reflectutils.SStructFieldInfo, omitEmpty bool) JSONObject {
var jsonPtr *sJSONPointer
if objValue.Kind() == reflect.Ptr {
inf := objValue.Interface()
if !gotypes.IsNil(inf) {
jsonPtrNode := s.objectTrace.find(inf)
if jsonPtrNode != nil {
// loop detected!
return jsonPtrNode.pointer
}
jsonPtr = s.newJsonPointer(inf)
}
}
jsonObj := s._marshalValue(objValue, info, omitEmpty)
if jsonPtr != nil {
s.setJsonObject(jsonPtr, jsonObj)
}
return jsonObj
}
func (s *sJsonMarshalSession) _marshalValue(objValue reflect.Value, info *reflectutils.SStructFieldInfo, omitEmpty bool) JSONObject {
switch objValue.Type() {
case JSONDictPtrType, JSONArrayPtrType, JSONBoolPtrType, JSONIntPtrType, JSONFloatPtrType, JSONStringPtrType, JSONObjectType:
if objValue.IsNil() {
@@ -337,15 +373,15 @@ func marshalValue(objValue reflect.Value, info *reflectutils.SStructFieldInfo, o
}
switch objValue.Kind() {
case reflect.Slice, reflect.Array:
return marshalSlice(objValue, info, omitEmpty)
return s.marshalSlice(objValue, info, omitEmpty)
case reflect.Struct:
if objValue.Type() == gotypes.TimeType {
return marshalTime(objValue.Interface().(time.Time), info, omitEmpty)
} else {
return marshalStruct(objValue, info, omitEmpty)
return s.marshalStruct(objValue, info, omitEmpty)
}
case reflect.Map:
return marshalMap(objValue, info, omitEmpty)
return s.marshalMap(objValue, info, omitEmpty)
case reflect.String:
strValue := objValue.Convert(gotypes.StringType)
return marshalString(strValue.Interface().(string), info, omitEmpty)
@@ -369,7 +405,7 @@ func marshalValue(objValue reflect.Value, info *reflectutils.SStructFieldInfo, o
return JSONNull
}
}
return marshalValue(objValue.Elem(), info, omitEmpty)
return s.marshalValue(objValue.Elem(), info, omitEmpty)
default:
log.Errorf("unsupport object %s %s", objValue.Type(), objValue.Interface())
return JSONNull
@@ -384,8 +420,9 @@ func MarshalAll(obj interface{}) JSONObject {
if kind := val.Kind(); val.IsZero() && kind == reflect.Ptr {
return JSONNull
}
objValue := reflect.Indirect(val)
mval := marshalValue(objValue, nil, false)
s := newJsonMarshalSession()
mval := s.marshalValue(val, nil, false)
s.setAllNodeId()
if mval == nil {
return JSONNull
}

29
vendor/yunion.io/x/jsonutils/marshal_session.go generated vendored Normal file
View File

@@ -0,0 +1,29 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package jsonutils
type sJsonMarshalSession struct {
nodeIndex int
objectTrace *sJsonPointerTrace
nodeMap map[int]*sJsonPointerNode
}
func newJsonMarshalSession() *sJsonMarshalSession {
return &sJsonMarshalSession{
nodeIndex: 0,
objectTrace: newJsonPointerTrace(),
nodeMap: make(map[int]*sJsonPointerNode),
}
}

59
vendor/yunion.io/x/jsonutils/parse_session.go generated vendored Normal file
View File

@@ -0,0 +1,59 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package jsonutils
import (
"fmt"
)
type sNodeReferer struct {
node JSONObject
pointers []*sJSONPointer
}
type sJsonParseSession struct {
objectMap map[int]*sNodeReferer
}
func newJsonParseSession() *sJsonParseSession {
return &sJsonParseSession{
objectMap: make(map[int]*sNodeReferer),
}
}
func (s *sJsonParseSession) saveReferer(nodeId int, ptr *sJSONPointer) {
if nr, ok := s.objectMap[nodeId]; ok {
nr.pointers = append(nr.pointers, ptr)
} else {
s.objectMap[nodeId] = &sNodeReferer{
pointers: []*sJSONPointer{ptr},
}
}
}
func (s *sJsonParseSession) saveNode(nodeId int, node JSONObject) {
if nr, ok := s.objectMap[nodeId]; ok {
if nr.node != nil {
panic(fmt.Sprintf("nodeId %d alreayd exists: %s != %s", nodeId, nr.node, node))
} else {
nr.node = node
}
} else {
s.objectMap[nodeId] = &sNodeReferer{
node: node,
pointers: nil,
}
}
}

123
vendor/yunion.io/x/jsonutils/std_json.go generated vendored Normal file
View File

@@ -0,0 +1,123 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package jsonutils
import (
"encoding/json"
"fmt"
"reflect"
"yunion.io/x/pkg/gotypes"
)
func tryStdUnmarshal(s *sJsonUnmarshalSession, jo JSONObject, v reflect.Value, unmarshalFunc func(s *sJsonUnmarshalSession, value reflect.Value) error) error {
u := IsImplementStdUnmarshaler(v)
if u != nil {
return u.UnmarshalJSON([]byte(jo.String()))
}
return unmarshalFunc(s, v)
}
func IsImplementStdUnmarshaler(v reflect.Value) json.Unmarshaler {
return indirectStdUnmarshaler(v)
}
func indirectStdUnmarshaler(v reflect.Value) json.Unmarshaler {
v0 := v
haveAddr := false
// If v is a named type and is addressable,
// start with its address, so that if the type has pointer methods,
// we find them
if v.Kind() != reflect.Ptr && v.Type().Name() != "" && v.CanAddr() {
haveAddr = true
v = v.Addr()
}
for {
// Load value from interface, but only if the result will be
// usefully addressable.
if v.Kind() == reflect.Interface && !v.IsNil() {
e := v.Elem()
if e.Kind() == reflect.Ptr && !e.IsNil() && e.Elem().Kind() == reflect.Ptr {
haveAddr = false
v = e
continue
}
}
if v.Kind() != reflect.Ptr {
break
}
// Prevent infinite loop if v is an interface pointing to its own address:
// var v interface{}
// v = &v
if v.Elem().Kind() == reflect.Interface && v.Elem().Elem() == v {
v = v.Elem()
break
}
if v.IsNil() {
v.Set(reflect.New(v.Type().Elem()))
}
if v.Type().NumMethod() > 0 && v.CanInterface() {
if u, ok := v.Interface().(json.Unmarshaler); ok {
return u
}
}
if haveAddr {
v = v0 // restore original value after round-trip Value.Addr().Elem()
haveAddr = false
} else {
v = v.Elem()
}
}
return nil
}
func IsImplementStdMarshaler(v reflect.Value) json.Marshaler {
return indirectStdMarshaler(v)
}
func indirectStdMarshaler(v reflect.Value) json.Marshaler {
if v.Kind() == reflect.Ptr && v.IsNil() {
return nil
}
if v.Type().NumMethod() > 0 && v.CanInterface() {
if u, ok := v.Interface().(json.Marshaler); ok {
return u
}
}
return nil
}
func tryStdMarshal(v reflect.Value, marshalFunc func(v reflect.Value) JSONObject) JSONObject {
if v.Type() != gotypes.TimeType {
m := IsImplementStdMarshaler(v)
if m != nil {
data, err := m.MarshalJSON()
if err != nil {
panic(fmt.Sprintf("MarshalJSON of %q error: %v", v.String(), err))
}
jo, err := Parse(data)
if err != nil {
panic(fmt.Sprintf("Parse data %q to json of %q error: %v", data, v.String(), err))
}
return jo
}
}
return marshalFunc(v)
}

View File

@@ -1,3 +1,17 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package jsonutils
import (

View File

@@ -50,6 +50,10 @@ func (this *JSONDict) Unmarshal(obj interface{}, keys ...string) error {
return jsonUnmarshal(this, obj, keys)
}
func (this *JSONString) Unmarshal(obj interface{}, keys ...string) error {
return jsonUnmarshal(this, obj, keys)
}
func jsonUnmarshal(jo JSONObject, o interface{}, keys []string) error {
if len(keys) > 0 {
var err error = nil
@@ -58,15 +62,16 @@ func jsonUnmarshal(jo JSONObject, o interface{}, keys []string) error {
return errors.Wrap(err, "Get")
}
}
s := newJsonUnmarshalSession()
value := reflect.ValueOf(o)
err := jo.unmarshalValue(reflect.Indirect(value))
err := jo.unmarshalValue(s, reflect.Indirect(value))
if err != nil {
return errors.Wrap(err, "jo.unmarshalValue")
}
return nil
}
func (this *JSONValue) unmarshalValue(val reflect.Value) error {
func (this *JSONValue) unmarshalValue(s *sJsonUnmarshalSession, val reflect.Value) error {
if val.CanSet() {
zeroVal := reflect.New(val.Type()).Elem()
val.Set(zeroVal)
@@ -74,7 +79,11 @@ func (this *JSONValue) unmarshalValue(val reflect.Value) error {
return nil
}
func (this *JSONInt) unmarshalValue(val reflect.Value) error {
func (this *JSONInt) unmarshalValue(s *sJsonUnmarshalSession, val reflect.Value) error {
return tryStdUnmarshal(s, this, val, this._unmarshalValue)
}
func (this *JSONInt) _unmarshalValue(s *sJsonUnmarshalSession, val reflect.Value) error {
switch val.Type() {
case JSONIntType:
json := val.Interface().(JSONInt)
@@ -127,7 +136,7 @@ func (this *JSONInt) unmarshalValue(val reflect.Value) error {
if val.IsNil() {
val.Set(reflect.New(val.Type().Elem()))
}
return this.unmarshalValue(val.Elem())
return this.unmarshalValue(s, val.Elem())
case reflect.Interface:
val.Set(reflect.ValueOf(this.data))
default:
@@ -136,7 +145,11 @@ func (this *JSONInt) unmarshalValue(val reflect.Value) error {
return nil
}
func (this *JSONBool) unmarshalValue(val reflect.Value) error {
func (this *JSONBool) unmarshalValue(s *sJsonUnmarshalSession, val reflect.Value) error {
return tryStdUnmarshal(s, this, val, this._unmarshalValue)
}
func (this *JSONBool) _unmarshalValue(s *sJsonUnmarshalSession, val reflect.Value) error {
switch val.Type() {
case JSONBoolType:
json := val.Interface().(JSONBool)
@@ -194,7 +207,7 @@ func (this *JSONBool) unmarshalValue(val reflect.Value) error {
if val.IsNil() {
val.Set(reflect.New(val.Type().Elem()))
}
return this.unmarshalValue(val.Elem())
return this.unmarshalValue(s, val.Elem())
case reflect.Interface:
val.Set(reflect.ValueOf(this.data))
default:
@@ -203,7 +216,11 @@ func (this *JSONBool) unmarshalValue(val reflect.Value) error {
return nil
}
func (this *JSONFloat) unmarshalValue(val reflect.Value) error {
func (this *JSONFloat) unmarshalValue(s *sJsonUnmarshalSession, val reflect.Value) error {
return tryStdUnmarshal(s, this, val, this._unmarshalValue)
}
func (this *JSONFloat) _unmarshalValue(s *sJsonUnmarshalSession, val reflect.Value) error {
switch val.Type() {
case JSONFloatType:
json := val.Interface().(JSONFloat)
@@ -270,7 +287,7 @@ func (this *JSONFloat) unmarshalValue(val reflect.Value) error {
if val.IsNil() {
val.Set(reflect.New(val.Type().Elem()))
}
return this.unmarshalValue(val.Elem())
return this.unmarshalValue(s, val.Elem())
case reflect.Interface:
val.Set(reflect.ValueOf(this.data))
default:
@@ -279,7 +296,14 @@ func (this *JSONFloat) unmarshalValue(val reflect.Value) error {
return nil
}
func (this *JSONString) unmarshalValue(val reflect.Value) error {
func (this *JSONString) unmarshalValue(s *sJsonUnmarshalSession, val reflect.Value) error {
if val.Type() == gotypes.TimeType {
return this._unmarshalValue(s, val)
}
return tryStdUnmarshal(s, this, val, this._unmarshalValue)
}
func (this *JSONString) _unmarshalValue(s *sJsonUnmarshalSession, val reflect.Value) error {
switch val.Type() {
case JSONStringType:
json := val.Interface().(JSONString)
@@ -371,7 +395,7 @@ func (this *JSONString) unmarshalValue(val reflect.Value) error {
if val.IsNil() {
val.Set(reflect.New(val.Type().Elem()))
}
return this.unmarshalValue(val.Elem())
return this.unmarshalValue(s, val.Elem())
case reflect.Interface:
val.Set(reflect.ValueOf(this.data))
case reflect.Slice:
@@ -382,14 +406,18 @@ func (this *JSONString) unmarshalValue(val reflect.Value) error {
} else if val.Len() != dataLen {
val.SetLen(dataLen)
}
return this.unmarshalValue(val.Index(0))
return this.unmarshalValue(s, val.Index(0))
default:
return errors.Wrapf(ErrTypeMismatch, "JSONString vs. %s", val.Type())
}
return nil
}
func (this *JSONArray) unmarshalValue(val reflect.Value) error {
func (this *JSONArray) unmarshalValue(s *sJsonUnmarshalSession, val reflect.Value) error {
return tryStdUnmarshal(s, this, val, this._unmarshalValue)
}
func (this *JSONArray) _unmarshalValue(s *sJsonUnmarshalSession, val reflect.Value) error {
switch val.Type() {
case JSONArrayType:
array := val.Interface().(JSONArray)
@@ -415,7 +443,7 @@ func (this *JSONArray) unmarshalValue(val reflect.Value) error {
if val.IsNil() {
val.Set(reflect.New(val.Type().Elem()))
}
return this.unmarshalValue(val.Elem())
return this.unmarshalValue(s, val.Elem())
}
return ErrTypeMismatch // fmt.Errorf("JSONArray type mismatch %s", val.Type())
case reflect.Interface:
@@ -435,7 +463,7 @@ func (this *JSONArray) unmarshalValue(val reflect.Value) error {
}
}
for i, json := range this.data {
err := json.unmarshalValue(val.Index(i))
err := json.unmarshalValue(s, val.Index(i))
if err != nil {
return errors.Wrap(err, "unmarshalValue")
}
@@ -446,7 +474,14 @@ func (this *JSONArray) unmarshalValue(val reflect.Value) error {
return nil
}
func (this *JSONDict) unmarshalValue(val reflect.Value) error {
func (this *JSONDict) unmarshalValue(s *sJsonUnmarshalSession, val reflect.Value) error {
if this.nodeId > 0 && val.CanAddr() {
s.saveNodeValue(this.nodeId, val.Addr())
}
return tryStdUnmarshal(s, this, val, this._unmarshalValue)
}
func (this *JSONDict) _unmarshalValue(s *sJsonUnmarshalSession, val reflect.Value) error {
switch val.Type() {
case JSONDictType:
dict := val.Interface().(JSONDict)
@@ -465,9 +500,9 @@ func (this *JSONDict) unmarshalValue(val reflect.Value) error {
val.SetString(this.String())
return nil
case reflect.Map:
return this.unmarshalMap(val)
return this.unmarshalMap(s, val)
case reflect.Struct:
return this.unmarshalStruct(val)
return this.unmarshalStruct(s, val)
case reflect.Interface:
if val.Type().Implements(gotypes.ISerializableType) {
objPtr, err := gotypes.NewSerializable(val.Type())
@@ -478,7 +513,7 @@ func (this *JSONDict) unmarshalValue(val reflect.Value) error {
val.Set(reflect.ValueOf(this.data)) // ???
return nil
}
err = this.unmarshalValue(reflect.ValueOf(objPtr))
err = this.unmarshalValue(s, reflect.ValueOf(objPtr))
if err != nil {
return errors.Wrap(err, "unmarshalValue")
}
@@ -502,7 +537,7 @@ func (this *JSONDict) unmarshalValue(val reflect.Value) error {
newVal := reflect.New(val.Type().Elem())
val.Set(newVal)
}
return this.unmarshalValue(val.Elem())
return this.unmarshalValue(s, val.Elem())
}
fallthrough
default:
@@ -511,7 +546,7 @@ func (this *JSONDict) unmarshalValue(val reflect.Value) error {
return nil
}
func (this *JSONDict) unmarshalMap(val reflect.Value) error {
func (this *JSONDict) unmarshalMap(s *sJsonUnmarshalSession, val reflect.Value) error {
if val.IsNil() {
mapVal := reflect.MakeMap(val.Type())
val.Set(mapVal)
@@ -530,7 +565,7 @@ func (this *JSONDict) unmarshalMap(val reflect.Value) error {
}
valVal := reflect.New(valType.Elem()).Elem()
err := v.unmarshalValue(valVal)
err := v.unmarshalValue(s, valVal)
if err != nil {
return errors.Wrap(err, "JSONDict.unmarshalMap")
}
@@ -539,7 +574,7 @@ func (this *JSONDict) unmarshalMap(val reflect.Value) error {
return nil
}
func setStructFieldAt(key string, v JSONObject, fieldValues reflectutils.SStructFieldValueSet, keyIndexMap map[string][]int, visited map[string]bool) error {
func setStructFieldAt(s *sJsonUnmarshalSession, key string, v JSONObject, fieldValues reflectutils.SStructFieldValueSet, keyIndexMap map[string][]int, visited map[string]bool) error {
if visited == nil {
visited = make(map[string]bool)
}
@@ -558,13 +593,16 @@ func setStructFieldAt(key string, v JSONObject, fieldValues reflectutils.SStruct
}
}
for _, index := range indexes {
err := v.unmarshalValue(fieldValues[index].Value)
if fieldValues[index].Parent != nil && fieldValues[index].Parent.Field.IsNil() {
fieldValues[index].Parent.Field.Set(fieldValues[index].Parent.Value)
}
err := v.unmarshalValue(s, fieldValues[index].Value)
if err != nil {
return errors.Wrap(err, "JSONDict.unmarshalStruct")
}
depInfo, ok := fieldValues[index].Info.Tags[TAG_DEPRECATED_BY]
if ok {
err := setStructFieldAt(depInfo, v, fieldValues, keyIndexMap, visited)
err := setStructFieldAt(s, depInfo, v, fieldValues, keyIndexMap, visited)
if err != nil {
return errors.Wrap(err, "setStructFieldAt")
}
@@ -573,14 +611,14 @@ func setStructFieldAt(key string, v JSONObject, fieldValues reflectutils.SStruct
return nil
}
func (this *JSONDict) unmarshalStruct(val reflect.Value) error {
fieldValues := reflectutils.FetchStructFieldValueSetForWrite(val)
func (this *JSONDict) unmarshalStruct(s *sJsonUnmarshalSession, val reflect.Value) error {
fieldValues := reflectutils.FetchStructFieldValueSet(val)
keyIndexMap := fieldValues.GetStructFieldIndexesMap()
errs := make([]error, 0)
for iter := sortedmap.NewIterator(this.data); iter.HasMore(); iter.Next() {
k, vinf := iter.Get()
v := vinf.(JSONObject)
err := setStructFieldAt(k, v, fieldValues, keyIndexMap, nil)
err := setStructFieldAt(s, k, v, fieldValues, keyIndexMap, nil)
if err != nil {
// store error, not interrupt the process
errs = append(errs, errors.Wrapf(err, "setStructFieldAt %s: %s", k, v))

67
vendor/yunion.io/x/jsonutils/unmarshal_session.go generated vendored Normal file
View File

@@ -0,0 +1,67 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package jsonutils
import (
"reflect"
)
type sJsonNodeValues struct {
nodeValue reflect.Value
nodeValueSet bool
targetValues []reflect.Value
}
type sJsonUnmarshalSession struct {
objectMap map[int]*sJsonNodeValues
}
func newJsonUnmarshalSession() *sJsonUnmarshalSession {
return &sJsonUnmarshalSession{
objectMap: make(map[int]*sJsonNodeValues),
}
}
func (s *sJsonUnmarshalSession) saveNodeValue(nodeId int, val reflect.Value) {
if nv, ok := s.objectMap[nodeId]; !ok {
s.objectMap[nodeId] = &sJsonNodeValues{
nodeValue: val,
nodeValueSet: true,
}
} else {
nv.nodeValue = val
nv.nodeValueSet = true
for i := range nv.targetValues {
nv.targetValues[i].Set(val)
}
nv.targetValues = nil
}
}
func (s *sJsonUnmarshalSession) setPointerValue(nodeId int, val reflect.Value) error {
if nv, ok := s.objectMap[nodeId]; ok && nv.nodeValueSet {
val.Set(nv.nodeValue)
} else if ok && !nv.nodeValueSet {
nv.targetValues = append(nv.targetValues, val)
} else {
s.objectMap[nodeId] = &sJsonNodeValues{
nodeValueSet: false,
targetValues: []reflect.Value{
val,
},
}
}
return nil
}

View File

@@ -1,6 +1,21 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package jsonutils
import (
"fmt"
"strings"
"yunion.io/x/pkg/sortedmap"
@@ -33,6 +48,12 @@ func (this *JSONBool) buildString(sb *strings.Builder) {
func (this *JSONDict) buildString(sb *strings.Builder) {
sb.WriteByte('{')
var idx = 0
if this.nodeId > 0 {
sb.WriteString(quoteString(jsonPointerKey))
sb.WriteByte(':')
sb.WriteString(fmt.Sprintf("%d", this.nodeId))
idx++
}
for iter := sortedmap.NewIterator(this.data); iter.HasMore(); iter.Next() {
k, vinf := iter.Get()
v := vinf.(JSONObject)

View File

@@ -43,7 +43,7 @@ func (jfc *SJointFilterClause) GetJointFilter(q *sqlchemy.SQuery) sqlchemy.ICond
}
func (jfc *SJointFilterClause) GetJointModelName() string {
return jfc.JointModel[:len(jfc.JointModel)-1]
return strings.TrimSuffix(jfc.JointModel, "s")
}
func condFunc(field sqlchemy.IQueryField, params []string, cond func(field sqlchemy.IQueryField, val string) sqlchemy.ICondition) sqlchemy.ICondition {

View File

@@ -101,10 +101,15 @@ func (srcs securityRuleCuts) cutOutProtocol(protocol string) securityRuleCuts {
return r
}
func (srcs securityRuleCuts) cutOutIPNet(n *net.IPNet) securityRuleCuts {
func (srcs securityRuleCuts) cutOutIPNet(protocol string, n *net.IPNet) securityRuleCuts {
r := securityRuleCuts{}
ar2 := netutils.NewIPV4AddrRangeFromIPNet(n)
for _, src := range srcs {
if src.r.Protocol != protocol && protocol != PROTO_ANY {
src_ := src
r = append(r, src_)
continue
}
sr := src.r
ar := netutils.NewIPV4AddrRangeFromIPNet(sr.IPNet)
left, subs := ar.Substract(ar2)
@@ -131,13 +136,18 @@ func (srcs securityRuleCuts) cutOutIPNet(n *net.IPNet) securityRuleCuts {
return r
}
func (srcs securityRuleCuts) cutOutPortRange(portStart, portEnd uint16) securityRuleCuts {
func (srcs securityRuleCuts) cutOutPortRange(protocol string, portStart, portEnd uint16) securityRuleCuts {
pr1 := &portRange{
start: portStart,
end: portEnd,
}
r := securityRuleCuts{}
for _, src := range srcs {
if src.r.Protocol != protocol {
src_ := src
r = append(r, src_)
continue
}
sr := src.r
if len(sr.Ports) > 0 {
ps := newPortsFromInts(sr.Ports...)
@@ -196,9 +206,14 @@ func (srcs securityRuleCuts) cutOutPortRange(portStart, portEnd uint16) security
return r
}
func (srcs securityRuleCuts) cutOutPorts(ps1 []uint16) securityRuleCuts {
func (srcs securityRuleCuts) cutOutPorts(protocol string, ps1 []uint16) securityRuleCuts {
r := securityRuleCuts{}
for _, src := range srcs {
if src.r.Protocol != protocol {
src_ := src
r = append(r, src_)
continue
}
sr := src.r
if len(sr.Ports) > 0 {
ps0 := newPortsFromInts(sr.Ports...)

View File

@@ -432,11 +432,11 @@ func (rule *SecurityRule) cutOut(r *SecurityRule) SecurityRuleSet {
srcs := securityRuleCuts{securityRuleCut{r: *rule}}
//a := srcs
srcs = srcs.cutOutProtocol(r.Protocol)
srcs = srcs.cutOutIPNet(r.IPNet)
srcs = srcs.cutOutIPNet(r.Protocol, r.IPNet)
if len(r.Ports) > 0 {
srcs = srcs.cutOutPorts([]uint16(newPortsFromInts(r.Ports...)))
srcs = srcs.cutOutPorts(r.Protocol, []uint16(newPortsFromInts(r.Ports...)))
} else if r.PortStart > 0 && r.PortEnd > 0 {
srcs = srcs.cutOutPortRange(uint16(r.PortStart), uint16(r.PortEnd))
srcs = srcs.cutOutPortRange(r.Protocol, uint16(r.PortStart), uint16(r.PortEnd))
} else {
srcs = srcs.cutOutPortsAll()
}

View File

@@ -84,6 +84,7 @@ func (srs SecurityRuleSet) equals(srs1 SecurityRuleSet) bool {
// - same direction
//
func (srs SecurityRuleSet) AllowList() SecurityRuleSet {
srs = srs.uniq()
r := SecurityRuleSet{}
wq := make(SecurityRuleSet, len(srs))
copy(wq, srs)
@@ -120,6 +121,19 @@ func (srs SecurityRuleSet) cutOutFirst() SecurityRuleSet {
return r
}
// remove duplicate rules
func (srs SecurityRuleSet) uniq() SecurityRuleSet {
for i := len(srs) - 1; i > 0; i-- {
sr0 := &srs[i-1]
sr1 := &srs[i]
if sr0.String() != sr1.String() {
continue
}
srs = append(srs[:i], srs[i+1:]...)
}
return srs
}
// collapse result of AllowList
//
// - same direction
@@ -181,11 +195,18 @@ func (srs SecurityRuleSet) collapse() SecurityRuleSet {
if !sr0.netEquals(sr1) {
continue
}
if len(sr0.Ports) > 0 && len(sr1.Ports) > 0 {
if (len(sr0.Ports) > 0 || (sr0.PortStart == sr0.PortEnd && sr0.PortStart > 0)) && (len(sr1.Ports) > 0 || (sr1.PortStart == sr1.PortEnd && sr1.PortStart > 0)) {
ps := newPortsFromInts(sr0.Ports...)
ps = append(ps, newPortsFromInts(sr1.Ports...)...)
if sr0.PortStart == sr0.PortEnd && sr0.PortStart > 0 {
ps = append(ps, uint16(sr0.PortStart))
}
if sr1.PortStart == sr1.PortEnd && sr1.PortStart > 0 {
ps = append(ps, uint16(sr1.PortStart))
}
ps = ps.dedup()
sr0.Ports = ps.IntSlice()
sr0.PortStart, sr0.PortEnd = -1, -1
srs1 = append(srs1[:i], srs1[i+1:]...)
} else if sr0.PortStart > 0 && sr1.PortStart > 0 && sr0.PortEnd > 0 && sr1.PortEnd > 0 {
if sr0.PortEnd == sr1.PortStart-1 {
@@ -200,6 +221,7 @@ func (srs SecurityRuleSet) collapse() SecurityRuleSet {
// save that contains, intersects
}
}
for i := range srs1 {
sr := &srs1[i]
if sr.PortStart <= 1 && sr.PortEnd >= 65535 {
@@ -250,6 +272,12 @@ func (srs SecurityRuleSet) collapse() SecurityRuleSet {
for _, srs := range needMerged {
result = append(result, srs.mergeNet()...)
}
result = result.uniq()
for i := range result {
sr := &result[i]
sr.Priority = 1
}
return result
}

View File

@@ -116,15 +116,14 @@ func DecodeMeta(str string) string {
}
func IsInStringArray(val string, array []string) bool {
for _, ele := range array {
if ele == val {
return true
}
}
return false
return IsInArray(val, array)
}
func InStringArray(val string, array []string) (ok bool, i int) {
return InArray2(val, array)
}
func InArray2[T int | uint | int8 | uint8 | int16 | uint16 | int32 | uint32 | int64 | uint64 | float32 | float64 | string](val T, array []T) (ok bool, i int) {
for i = range array {
if ok = array[i] == val; ok {
return
@@ -133,6 +132,15 @@ func InStringArray(val string, array []string) (ok bool, i int) {
return
}
func IsInArray[T int | uint | int8 | uint8 | int16 | uint16 | int32 | uint32 | int64 | uint64 | float32 | float64 | string](val T, array []T) bool {
for _, ele := range array {
if ele == val {
return true
}
}
return false
}
func InArray(v interface{}, in interface{}) (ok bool, i int) {
val := reflect.Indirect(reflect.ValueOf(in))
switch val.Kind() {

View File

@@ -258,6 +258,9 @@ func (click *SClickhouseBackend) GetColumnSpecByFieldType(table *sqlchemy.STable
}
col := NewFloatColumn(fieldname, "Float64", tagmap, isPointer)
return &col
case reflect.Map, reflect.Slice:
col := NewCompoundColumn(fieldname, tagmap, isPointer)
return &col
}
if fieldType.Implements(gotypes.ISerializableType) {
col := NewCompoundColumn(fieldname, tagmap, isPointer)

View File

@@ -213,6 +213,9 @@ func (mysql *SMySQLBackend) GetColumnSpecByFieldType(table *sqlchemy.STableSpec,
}
col := NewFloatColumn(fieldname, colType, tagmap, isPointer)
return &col
case reflect.Map, reflect.Slice:
col := NewCompoundColumn(fieldname, getTextSqlType(tagmap), tagmap, isPointer)
return &col
}
if fieldType.Implements(gotypes.ISerializableType) {
col := NewCompoundColumn(fieldname, getTextSqlType(tagmap), tagmap, isPointer)

View File

@@ -54,6 +54,7 @@ func parseIndexes(ts sqlchemy.ITableSpec, defStr string) []sqlchemy.STableIndex
for i := range matches {
tcs[i] = sqlchemy.NewTableIndex(
ts,
matches[i][2],
fetchColumns(matches[i][3]),
len(matches[i][1]) > 0,
)

View File

@@ -34,27 +34,27 @@ func (mysql *SMySQLBackend) CommitTableChangeSQL(ts sqlchemy.ITableSpec, changes
alters := make([]string, 0)
// first check if primary key is modifed
changePrimary := false
oldHasPrimary := false
// oldHasPrimary := false
for _, col := range changes.RemoveColumns {
if col.IsPrimary() {
changePrimary = true
oldHasPrimary = true
// oldHasPrimary = true
}
}
for _, cols := range changes.UpdatedColumns {
if cols.OldCol.IsPrimary() != cols.NewCol.IsPrimary() {
changePrimary = true
}
if cols.OldCol.IsPrimary() {
oldHasPrimary = true
}
// if cols.OldCol.IsPrimary() {
// oldHasPrimary = true
// }
}
for _, col := range changes.AddColumns {
if col.IsPrimary() {
changePrimary = true
}
}
if changePrimary && oldHasPrimary {
if changePrimary {
sql := fmt.Sprintf("DROP PRIMARY KEY")
alters = append(alters, sql)
}

View File

@@ -23,7 +23,7 @@ import (
)
const (
indexPattern = `\((?P<cols>` + "`" + `\w+` + "`" + `(,\s*` + "`" + `\w+` + "`" + `)*)\)`
indexPattern = `CREATE\s+INDEX\s+` + "`" + `(?P<name>\w+)` + "`" + `\s+ON\s+` + "`" + `(?P<tblname>\w+)` + "`" + `\s*\((?P<cols>` + "`" + `\w+` + "`" + `(,\s*` + "`" + `\w+` + "`" + `)*)\)`
)
var (
@@ -39,7 +39,7 @@ type sSqliteTableInfo struct {
func (ti *sSqliteTableInfo) parseTableIndex(ts sqlchemy.ITableSpec) (sqlchemy.STableIndex, error) {
matches := indexRegexp.FindAllStringSubmatch(ti.Sql, -1)
if len(matches) > 0 {
return sqlchemy.NewTableIndex(ts, sqlchemy.FetchColumns(matches[0][1]), false), nil
return sqlchemy.NewTableIndex(ts, matches[0][1], sqlchemy.FetchColumns(matches[0][3]), false), nil
}
return sqlchemy.STableIndex{}, errors.ErrNotFound
}

View File

@@ -170,6 +170,9 @@ func (sqlite *SSqliteBackend) GetColumnSpecByFieldType(table *sqlchemy.STableSpe
case reflect.Float32, reflect.Float64:
col := NewFloatColumn(fieldname, tagmap, isPointer)
return &col
case reflect.Map, reflect.Slice:
col := NewCompoundColumn(fieldname, tagmap, isPointer)
return &col
}
if fieldType.Implements(gotypes.ISerializableType) {
col := NewCompoundColumn(fieldname, tagmap, isPointer)

View File

@@ -19,7 +19,6 @@ import (
"strconv"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/pkg/gotypes"
"yunion.io/x/pkg/utils"
)
@@ -385,7 +384,6 @@ type SBaseCompoundColumn struct{}
func (c *SBaseCompoundColumn) ConvertFromString(str string) interface{} {
json, err := jsonutils.ParseString(str)
if err != nil {
log.Errorf("ParseString fail %s", err)
json = jsonutils.JSONNull
}
return json.String()

68
vendor/yunion.io/x/sqlchemy/delete_batch.go generated vendored Normal file
View File

@@ -0,0 +1,68 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package sqlchemy
import (
"fmt"
"reflect"
"strings"
"yunion.io/x/log"
)
func getSQLFilters(filter map[string]interface{}) ([]string, []interface{}) {
conds := make([]string, 0, len(filter))
params := make([]interface{}, 0, len(filter))
for k, v := range filter {
if reflect.TypeOf(v).Kind() == reflect.Slice || reflect.TypeOf(v).Kind() == reflect.Array {
value := reflect.ValueOf(v)
if value.Len() == 0 {
continue
}
arr := make([]string, value.Len())
for i := 0; i < value.Len(); i++ {
arr[i] = "?"
params = append(params, value.Index(i).Interface())
}
conds = append(conds, fmt.Sprintf("`%s` in (%s)", k, strings.Join(arr, ", ")))
} else {
conds = append(conds, fmt.Sprintf("`%s` = ?", k))
params = append(params, v)
}
}
return conds, params
}
func (ts *STableSpec) DeleteFrom(filters map[string]interface{}) error {
buf := strings.Builder{}
buf.WriteString("DELETE FROM `")
buf.WriteString(ts.Name())
buf.WriteString("`")
conds, params := getSQLFilters(filters)
if len(conds) > 0 {
buf.WriteString(" WHERE ")
buf.WriteString(strings.Join(conds, " AND "))
}
if DEBUG_SQLCHEMY {
log.Infof("Update: %s %s", buf.String(), params)
}
_, err := ts.Database().TxExec(buf.String(), params...)
return err
}

View File

@@ -73,7 +73,7 @@ func (ff *SFunctionFieldBase) Name() string {
// Label implementation of SFunctionFieldBase for IQueryField
func (ff *SFunctionFieldBase) Label(label string) IQueryField {
if len(label) > 0 && label != ff.alias {
if len(label) > 0 {
ff.alias = label
}
return ff

35
vendor/yunion.io/x/sqlchemy/index.go generated vendored
View File

@@ -21,18 +21,20 @@ import (
)
type STableIndex struct {
// name string
columns []string
name string
columns []string
isUnique bool
ts ITableSpec
}
func NewTableIndex(ts ITableSpec, cols []string, unique bool) STableIndex {
func NewTableIndex(ts ITableSpec, name string, cols []string, unique bool) STableIndex {
sort.Sort(TColumnNames(cols))
return STableIndex{
// name: name,
columns: cols,
name: name,
columns: cols,
isUnique: unique,
ts: ts,
}
@@ -56,14 +58,21 @@ func (cols TColumnNames) Less(i, j int) bool {
}
}
const IndexLimit int = 64
func (index *STableIndex) Name() string {
return fmt.Sprintf("ix_%s_%s", index.ts.Name(), strings.Join(index.columns, "_"))
if len(index.name) > 0 {
return index.name
}
name := fmt.Sprintf("ix_%s_%s", index.ts.Name(), strings.Join(index.columns, "_"))
if len(name) > IndexLimit {
name = name[:IndexLimit]
}
return name
}
func (index STableIndex) clone(ts ITableSpec) STableIndex {
cols := make([]string, len(index.columns))
copy(cols, index.columns)
return NewTableIndex(ts, cols, index.isUnique)
return NewTableIndex(ts, "", index.columns, index.isUnique)
}
func (index *STableIndex) IsIdentical(cols ...string) bool {
@@ -89,13 +98,17 @@ func (index *STableIndex) QuotedColumns() []string {
// AddIndex adds a SQL index over multiple columns for a Table
// param unique: indicates a unique index cols: name of columns
func (ts *STableSpec) AddIndex(unique bool, cols ...string) bool {
func (ts *STableSpec) addIndexWithName(name string, unique bool, cols ...string) bool {
for i := 0; i < len(ts._indexes); i++ {
if ts._indexes[i].IsIdentical(cols...) {
return false
}
}
idx := STableIndex{columns: cols, isUnique: unique, ts: ts}
idx := NewTableIndex(ts, name, cols, unique)
ts._indexes = append(ts._indexes, idx)
return true
}
func (ts *STableSpec) AddIndex(unique bool, cols ...string) bool {
return ts.addIndexWithName("", unique, cols...)
}

137
vendor/yunion.io/x/sqlchemy/insert_batch.go generated vendored Normal file
View File

@@ -0,0 +1,137 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package sqlchemy
import (
"bytes"
"fmt"
"reflect"
"strings"
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/gotypes"
"yunion.io/x/pkg/util/reflectutils"
"yunion.io/x/pkg/util/timeutils"
)
const (
sqlLineLimit = 100
)
func (t *STableSpec) InsertBatch(dataList []interface{}) error {
var sql string
var fieldCount int
{
buffer := new(bytes.Buffer)
buffer.WriteString("INSERT INTO `")
buffer.WriteString(t.Name())
buffer.WriteString("` (")
headers := make([]string, 0)
format := make([]string, 0)
for _, col := range t.Columns() {
if col.IsAutoIncrement() {
continue
}
name := col.Name()
headers = append(headers, fmt.Sprintf("`%s`", name))
if col.IsCreatedAt() || col.IsUpdatedAt() {
if t.Database().backend.SupportMixedInsertVariables() {
format = append(format, t.Database().backend.CurrentUTCTimeStampString())
} else {
format = append(format, "?")
fieldCount++
}
continue
}
format = append(format, "?")
fieldCount++
}
buffer.WriteString(strings.Join(headers, ","))
buffer.WriteString(") VALUES ")
buffer.WriteString("(")
buffer.WriteString(strings.Join(format, ","))
buffer.WriteString(")")
sql = buffer.String()
if DEBUG_SQLCHEMY {
log.Debugf("batchInsert SQL: %s", buffer.String())
}
}
batchParams := make([][]interface{}, 0)
now := timeutils.UtcNow()
errs := make([]error, 0)
for i := range dataList {
v := dataList[i]
var params []interface{}
modelValue := reflect.Indirect(reflect.ValueOf(v))
beforeInsert(modelValue)
dataFields := reflectutils.FetchStructFieldValueSet(modelValue)
for _, col := range t.Columns() {
if col.IsAutoIncrement() {
continue
}
if col.IsCreatedAt() || col.IsUpdatedAt() {
if !t.Database().backend.SupportMixedInsertVariables() {
params = append(params, now)
}
continue
}
ov, find := dataFields.GetInterface(col.Name())
if !find || gotypes.IsNil(ov) || col.IsZero(ov) {
// empty column
if col.IsSupportDefault() && (len(col.Default()) > 0 || col.IsString()) {
params = append(params, col.ConvertFromString(col.Default()))
} else {
params = append(params, nil)
}
} else {
params = append(params, col.ConvertFromValue(ov))
}
}
if len(params) != fieldCount {
log.Errorf("expect %d got %d(%#v)", fieldCount, len(params), params)
}
batchParams = append(batchParams, params)
if len(batchParams) >= sqlLineLimit || (i+1) == len(dataList) {
results, err := t.Database().TxBatchExec(sql, batchParams)
if err != nil {
return errors.Wrap(err, "TxBatchExec")
}
for _, result := range results {
if result.Error != nil {
errs = append(errs, result.Error)
}
}
if len(errs) != 0 {
return errors.NewAggregate(errs)
}
batchParams = make([][]interface{}, 0)
}
}
return nil
}

View File

@@ -22,7 +22,6 @@ import (
"time"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/gotypes"
"yunion.io/x/pkg/tristate"
@@ -72,9 +71,9 @@ func GetStringValue(dat interface{}) string {
serializable, ok := value.Interface().(gotypes.ISerializable)
if ok {
return serializable.String()
} else {
return jsonutils.Marshal(value.Interface()).String()
}
log.Errorf("cannot convert %v to string", value)
return ""
}
func setValueBySQLString(value reflect.Value, val string) error {
@@ -138,6 +137,9 @@ func setValueBySQLString(value reflect.Value, val string) error {
if err != nil {
return errors.Wrapf(err, "jsonutils.ParseString %s", val)
}
if jsonV == jsonutils.JSONNull {
return nil
}
jsonA, err := jsonV.GetArray()
if err != nil {
return errors.Wrap(err, "jsonV.GetArray")
@@ -159,9 +161,12 @@ func setValueBySQLString(value reflect.Value, val string) error {
if err != nil {
return errors.Wrapf(err, "jsonutils.ParseString %s", val)
}
if jsonV == jsonutils.JSONNull {
return nil
}
jsonM, err := jsonV.GetMap()
if err != nil {
return errors.Wrapf(err, "jsonV.GetMap")
return errors.Wrapf(err, "jsonV.GetMap val %s json %s", val, jsonV)
}
mapValue := reflect.MakeMap(value.Type())
value.Set(mapValue)
@@ -193,6 +198,9 @@ func setValueBySQLString(value reflect.Value, val string) error {
if err != nil {
return errors.Wrapf(err, "%s not a json string: %s", val, err)
}
if jsonV == jsonutils.JSONNull {
return nil
}
newVal := reflect.New(value.Type())
err = jsonV.Unmarshal(newVal.Interface())
if err != nil {

View File

@@ -353,7 +353,7 @@ func (c *STableField) Reference() string {
// Label implementation of STableField for IQueryField
func (c *STableField) Label(label string) IQueryField {
if len(label) > 0 && label != c.spec.Name() {
if len(label) > 0 {
c.alias = label
}
return c

View File

@@ -53,7 +53,7 @@ func (sqf *SUnionQueryField) Reference() string {
// Label implementation of SUnionQueryField for IQueryField
func (sqf *SUnionQueryField) Label(label string) IQueryField {
if len(label) > 0 && label != sqf.name {
if len(label) > 0 {
sqf.alias = label
}
return sqf

56
vendor/yunion.io/x/sqlchemy/update_batch.go generated vendored Normal file
View File

@@ -0,0 +1,56 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package sqlchemy
import (
"fmt"
"strings"
"yunion.io/x/log"
)
func (ts *STableSpec) UpdateBatch(data map[string]interface{}, filter map[string]interface{}) error {
if len(data) <= 0 {
return nil
}
params := make([]interface{}, 0, len(data))
setter := make([]string, 0, len(data))
for k, v := range data {
setter = append(setter, fmt.Sprintf("`%s` = ?", k))
params = append(params, v)
}
conds, condparams := getSQLFilters(filter)
params = append(params, condparams...)
buf := strings.Builder{}
buf.WriteString("UPDATE `")
buf.WriteString(ts.Name())
buf.WriteString("` SET ")
buf.WriteString(strings.Join(setter, ", "))
if len(conds) > 0 {
buf.WriteString(" WHERE ")
buf.WriteString(strings.Join(conds, " AND "))
}
if DEBUG_SQLCHEMY {
log.Infof("Update: %s %s", buf.String(), params)
}
_, err := ts.Database().Exec(buf.String(), params...)
return err
}