Compare commits
66 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50055c1045 | ||
|
|
cca97f5c51 | ||
|
|
1bfaf041ea | ||
|
|
927b5b6fd3 | ||
|
|
1afaa0bc8d | ||
|
|
7312a7aa94 | ||
|
|
fd18739b0a | ||
|
|
d92f56e7fe | ||
|
|
a1a7ec8c93 | ||
|
|
951fdf0927 | ||
|
|
7d3328f75b | ||
|
|
8db39a6b36 | ||
|
|
71681b1c5d | ||
|
|
6b2a015015 | ||
|
|
9e74baf37b | ||
|
|
b651d94bf5 | ||
|
|
b61433c5f8 | ||
|
|
c4d2191110 | ||
|
|
f6159c646c | ||
|
|
9cc7d54b64 | ||
|
|
05ce1d327b | ||
|
|
111df18204 | ||
|
|
bbcdf167b1 | ||
|
|
d62a44b1ac | ||
|
|
969bb2bcda | ||
|
|
6dcd3f2a98 | ||
|
|
7936dc85a9 | ||
|
|
94c4098de5 | ||
|
|
5b0aef8d4a | ||
|
|
4571b95e4a | ||
|
|
b9cba4c7df | ||
|
|
b46b5dc05f | ||
|
|
ef5630ba4a | ||
|
|
fe6c610d56 | ||
|
|
442dd195ca | ||
|
|
e9e4abff03 | ||
|
|
2a3fbd080e | ||
|
|
9d7f1a2702 | ||
|
|
57dcbce775 | ||
|
|
a71bf9ed79 | ||
|
|
725692ce94 | ||
|
|
ea15096dc3 | ||
|
|
a07dbb718f | ||
|
|
18381b76fb | ||
|
|
1d31245b4a | ||
|
|
f26bc337c9 | ||
|
|
05c2955211 | ||
|
|
f0ffa48390 | ||
|
|
a472b8a3bd | ||
|
|
cfa2717838 | ||
|
|
aece12854e | ||
|
|
02692029ee | ||
|
|
03da451d17 | ||
|
|
946a9f373c | ||
|
|
ff31d98f78 | ||
|
|
c49d64eaee | ||
|
|
68f390a73b | ||
|
|
66a748cc26 | ||
|
|
b0339266e1 | ||
|
|
ebdb181361 | ||
|
|
63f011c6c8 | ||
|
|
43fbd7a404 | ||
|
|
75192b6a6e | ||
|
|
d88ad9b3a1 | ||
|
|
b94fdf11cc | ||
|
|
2eb249ad0f |
@@ -6,3 +6,4 @@
|
|||||||
./build.sh linux mips64
|
./build.sh linux mips64
|
||||||
./build.sh linux mips64le
|
./build.sh linux mips64le
|
||||||
./build.sh darwin amd64
|
./build.sh darwin amd64
|
||||||
|
./build.sh darwin arm64
|
||||||
|
|||||||
13
go.mod
13
go.mod
@@ -13,15 +13,18 @@ require (
|
|||||||
github.com/go-ole/go-ole v1.2.4 // indirect
|
github.com/go-ole/go-ole v1.2.4 // indirect
|
||||||
github.com/go-sql-driver/mysql v1.5.0
|
github.com/go-sql-driver/mysql v1.5.0
|
||||||
github.com/go-yaml/yaml v2.1.0+incompatible
|
github.com/go-yaml/yaml v2.1.0+incompatible
|
||||||
github.com/golang/protobuf v1.4.2
|
github.com/golang/protobuf v1.5.2
|
||||||
github.com/iwind/TeaGo v0.0.0-20210411134150-ddf57e240c2f
|
github.com/iwind/TeaGo v0.0.0-20210411134150-ddf57e240c2f
|
||||||
github.com/lionsoul2014/ip2region v2.2.0-release+incompatible
|
github.com/lionsoul2014/ip2region v2.2.0-release+incompatible
|
||||||
github.com/mozillazg/go-pinyin v0.18.0
|
github.com/mozillazg/go-pinyin v0.18.0
|
||||||
github.com/pkg/sftp v1.12.0
|
github.com/pkg/sftp v1.12.0
|
||||||
github.com/shirou/gopsutil v2.20.9+incompatible
|
github.com/shirou/gopsutil v3.21.5+incompatible
|
||||||
|
github.com/tklauser/go-sysconf v0.3.6 // indirect
|
||||||
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a
|
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a
|
||||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299
|
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
|
||||||
google.golang.org/grpc v1.32.0
|
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22
|
||||||
google.golang.org/protobuf v1.25.0
|
google.golang.org/genproto v0.0.0-20210617175327-b9e0b3197ced // indirect
|
||||||
|
google.golang.org/grpc v1.38.0
|
||||||
|
google.golang.org/protobuf v1.26.0
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
47
go.sum
47
go.sum
@@ -68,6 +68,7 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
|
|||||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||||
github.com/cloudflare/cloudflare-go v0.13.2/go.mod h1:27kfc1apuifUmJhp069y0+hwlKDg4bd8LWlu7oKeZvM=
|
github.com/cloudflare/cloudflare-go v0.13.2/go.mod h1:27kfc1apuifUmJhp069y0+hwlKDg4bd8LWlu7oKeZvM=
|
||||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||||
|
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
||||||
github.com/cpu/goacmedns v0.0.3/go.mod h1:4MipLkI+qScwqtVxcNO6okBhbgRrr7/tKXUSgSL0teQ=
|
github.com/cpu/goacmedns v0.0.3/go.mod h1:4MipLkI+qScwqtVxcNO6okBhbgRrr7/tKXUSgSL0teQ=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
@@ -83,6 +84,7 @@ github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFP
|
|||||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||||
|
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||||
github.com/exoscale/egoscale v0.23.0/go.mod h1:hRo78jkjkCDKpivQdRBEpNYF5+cVpCJCPDg2/r45KaY=
|
github.com/exoscale/egoscale v0.23.0/go.mod h1:hRo78jkjkCDKpivQdRBEpNYF5+cVpCJCPDg2/r45KaY=
|
||||||
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
|
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
|
||||||
@@ -134,6 +136,9 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq
|
|||||||
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
||||||
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
|
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
|
||||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||||
|
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||||
|
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||||
|
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||||
@@ -143,6 +148,7 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
|
|||||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
|
github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
|
||||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
|
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
|
||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||||
@@ -153,6 +159,7 @@ github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hf
|
|||||||
github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
||||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
||||||
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
||||||
github.com/gophercloud/gophercloud v0.6.1-0.20191122030953-d8ac278c1c9d/go.mod h1:ozGNgr9KYOVATV5jsgHl/ceCDXGuguqOZAzoQ/2vcNM=
|
github.com/gophercloud/gophercloud v0.6.1-0.20191122030953-d8ac278c1c9d/go.mod h1:ozGNgr9KYOVATV5jsgHl/ceCDXGuguqOZAzoQ/2vcNM=
|
||||||
@@ -175,12 +182,6 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
|
|||||||
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||||
github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df/go.mod h1:QMZY7/J/KSQEhKWFeDesPjMj+wCHReeknARU3wqlyN4=
|
github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df/go.mod h1:QMZY7/J/KSQEhKWFeDesPjMj+wCHReeknARU3wqlyN4=
|
||||||
github.com/iwind/TeaGo v0.0.0-20200923021120-f5d76441fe9e/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
github.com/iwind/TeaGo v0.0.0-20200923021120-f5d76441fe9e/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
||||||
github.com/iwind/TeaGo v0.0.0-20210125103732-4d79fc3c3d0b h1:niQL2t//041GUaqDPM5D+ldyr0Ng2WKwZJHPRLQhQtk=
|
|
||||||
github.com/iwind/TeaGo v0.0.0-20210125103732-4d79fc3c3d0b/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
|
||||||
github.com/iwind/TeaGo v0.0.0-20210302120856-7588e79bdbe3 h1:k9K3HHMmkF7HYyIHz21AtmYH4Zdk/8OI98a8P0O8o1I=
|
|
||||||
github.com/iwind/TeaGo v0.0.0-20210302120856-7588e79bdbe3/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
|
||||||
github.com/iwind/TeaGo v0.0.0-20210325033016-3279bdaa087d h1:FQTYJmZeCMdwM0Bz+C4h31SDBt04ap6A4JOjm+FfYwk=
|
|
||||||
github.com/iwind/TeaGo v0.0.0-20210325033016-3279bdaa087d/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
|
||||||
github.com/iwind/TeaGo v0.0.0-20210411134150-ddf57e240c2f h1:r2O8PONj/KiuZjJHVHn7KlCePUIjNtgAmvLfgRafQ8o=
|
github.com/iwind/TeaGo v0.0.0-20210411134150-ddf57e240c2f h1:r2O8PONj/KiuZjJHVHn7KlCePUIjNtgAmvLfgRafQ8o=
|
||||||
github.com/iwind/TeaGo v0.0.0-20210411134150-ddf57e240c2f/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
github.com/iwind/TeaGo v0.0.0-20210411134150-ddf57e240c2f/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc=
|
||||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
||||||
@@ -289,6 +290,8 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
|
|||||||
github.com/sacloud/libsacloud v1.36.2/go.mod h1:P7YAOVmnIn3DKHqCZcUKYUXmSwGBm3yS7IBEjKVSrjg=
|
github.com/sacloud/libsacloud v1.36.2/go.mod h1:P7YAOVmnIn3DKHqCZcUKYUXmSwGBm3yS7IBEjKVSrjg=
|
||||||
github.com/shirou/gopsutil v2.20.9+incompatible h1:msXs2frUV+O/JLva9EDLpuJ84PrFsdCTCQex8PUdtkQ=
|
github.com/shirou/gopsutil v2.20.9+incompatible h1:msXs2frUV+O/JLva9EDLpuJ84PrFsdCTCQex8PUdtkQ=
|
||||||
github.com/shirou/gopsutil v2.20.9+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
github.com/shirou/gopsutil v2.20.9+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||||
|
github.com/shirou/gopsutil v3.21.5+incompatible h1:OloQyEerMi7JUrXiNzy8wQ5XN+baemxSl12QgIzt0jc=
|
||||||
|
github.com/shirou/gopsutil v3.21.5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||||
@@ -306,6 +309,10 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
|
|||||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/tklauser/go-sysconf v0.3.6 h1:oc1sJWvKkmvIxhDHeKWvZS4f6AW+YcoguSfRF2/Hmo4=
|
||||||
|
github.com/tklauser/go-sysconf v0.3.6/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITnppBXY/rYEFI=
|
||||||
|
github.com/tklauser/numcpus v0.2.2 h1:oyhllyrScuYI6g+h/zUvNXNp1wy7x8qQy3t/piefldA=
|
||||||
|
github.com/tklauser/numcpus v0.2.2/go.mod h1:x3qojaO3uyYt0i56EW/VUYs7uBvdl2fkfZFu0T9wgjM=
|
||||||
github.com/transip/gotransip/v6 v6.2.0/go.mod h1:pQZ36hWWRahCUXkFWlx9Hs711gLd8J4qdgLdRzmtY+g=
|
github.com/transip/gotransip/v6 v6.2.0/go.mod h1:pQZ36hWWRahCUXkFWlx9Hs711gLd8J4qdgLdRzmtY+g=
|
||||||
github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g=
|
github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g=
|
||||||
github.com/urfave/cli v1.22.4/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
github.com/urfave/cli v1.22.4/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||||
@@ -313,6 +320,7 @@ github.com/vultr/govultr v0.5.0/go.mod h1:wZZXZbYbqyY1n3AldoeYNZK4Wnmmoq6dNFkvd5
|
|||||||
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
|
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
|
||||||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
|
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
|
||||||
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
|
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
|
||||||
|
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||||
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
||||||
go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
||||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||||
@@ -356,6 +364,7 @@ golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHl
|
|||||||
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs=
|
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs=
|
||||||
golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
||||||
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
||||||
|
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
||||||
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
|
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
|
||||||
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
|
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
|
||||||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
||||||
@@ -363,6 +372,7 @@ golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
|
|||||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||||
golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
|
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
@@ -391,6 +401,9 @@ golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLL
|
|||||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||||
golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA=
|
golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA=
|
||||||
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||||
|
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||||
|
golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q=
|
||||||
|
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
@@ -403,6 +416,7 @@ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJ
|
|||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
|
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
|
||||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sys v0.0.0-20180622082034-63fc586f45fe/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20180622082034-63fc586f45fe/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
@@ -439,11 +453,23 @@ golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 h1:DYfZAGf2WMFjMxbgTjaC+2HC7NkNAQs+6Q8b9WEB/F4=
|
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 h1:DYfZAGf2WMFjMxbgTjaC+2HC7NkNAQs+6Q8b9WEB/F4=
|
||||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210316164454-77fc1eacc6aa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio=
|
||||||
|
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
|
||||||
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
@@ -482,10 +508,12 @@ golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapK
|
|||||||
golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||||
golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||||
golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw=
|
golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw=
|
||||||
|
golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
|
google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
|
||||||
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
|
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
|
||||||
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
|
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
|
||||||
@@ -523,6 +551,8 @@ google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfG
|
|||||||
google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY=
|
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY=
|
||||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||||
|
google.golang.org/genproto v0.0.0-20210617175327-b9e0b3197ced h1:c5geK1iMU3cDKtFrCVQIcjR3W+JOZMuhIyICMCTbtus=
|
||||||
|
google.golang.org/genproto v0.0.0-20210617175327-b9e0b3197ced/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24=
|
||||||
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
|
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
|
||||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||||
google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
google.golang.org/grpc v1.19.1/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||||
@@ -536,6 +566,8 @@ google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8
|
|||||||
google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||||
google.golang.org/grpc v1.32.0 h1:zWTV+LMdc3kaiJMSTOFz2UgSBgx8RNQoTGiZu3fR9S0=
|
google.golang.org/grpc v1.32.0 h1:zWTV+LMdc3kaiJMSTOFz2UgSBgx8RNQoTGiZu3fR9S0=
|
||||||
google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||||
|
google.golang.org/grpc v1.38.0 h1:/9BgsAsa5nWe26HqOlvlgJnqBuktYOLCgjCPqsa56W0=
|
||||||
|
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
|
||||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||||
@@ -546,6 +578,9 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
|
|||||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||||
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
|
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
|
||||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||||
|
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||||
|
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
|
||||||
|
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package acme
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients"
|
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients/dnstypes"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
"github.com/go-acme/lego/v4/challenge/dns01"
|
"github.com/go-acme/lego/v4/challenge/dns01"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -24,15 +25,15 @@ func (this *DNSProvider) Present(domain, token, keyAuth string) error {
|
|||||||
return errors.New("invalid fqdn value")
|
return errors.New("invalid fqdn value")
|
||||||
}
|
}
|
||||||
recordName := fqdn[:index]
|
recordName := fqdn[:index]
|
||||||
record, err := this.raw.QueryRecord(domain, recordName, dnsclients.RecordTypeTXT)
|
record, err := this.raw.QueryRecord(domain, recordName, dnstypes.RecordTypeTXT)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("query DNS record failed: " + err.Error())
|
return errors.New("query DNS record failed: " + err.Error())
|
||||||
}
|
}
|
||||||
if record == nil {
|
if record == nil {
|
||||||
err = this.raw.AddRecord(domain, &dnsclients.Record{
|
err = this.raw.AddRecord(domain, &dnstypes.Record{
|
||||||
Id: "",
|
Id: "",
|
||||||
Name: recordName,
|
Name: recordName,
|
||||||
Type: dnsclients.RecordTypeTXT,
|
Type: dnstypes.RecordTypeTXT,
|
||||||
Value: value,
|
Value: value,
|
||||||
Route: this.raw.DefaultRoute(),
|
Route: this.raw.DefaultRoute(),
|
||||||
})
|
})
|
||||||
@@ -40,9 +41,9 @@ func (this *DNSProvider) Present(domain, token, keyAuth string) error {
|
|||||||
return errors.New("create DNS record failed: " + err.Error())
|
return errors.New("create DNS record failed: " + err.Error())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = this.raw.UpdateRecord(domain, record, &dnsclients.Record{
|
err = this.raw.UpdateRecord(domain, record, &dnstypes.Record{
|
||||||
Name: recordName,
|
Name: recordName,
|
||||||
Type: dnsclients.RecordTypeTXT,
|
Type: dnstypes.RecordTypeTXT,
|
||||||
Value: value,
|
Value: value,
|
||||||
Route: this.raw.DefaultRoute(),
|
Route: this.raw.DefaultRoute(),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package teaconst
|
package teaconst
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "0.0.13"
|
Version = "0.2.3"
|
||||||
|
|
||||||
ProductName = "Edge API"
|
ProductName = "Edge API"
|
||||||
ProcessName = "edge-api"
|
ProcessName = "edge-api"
|
||||||
@@ -15,4 +15,12 @@ const (
|
|||||||
ErrServer = "服务器出了点小问题,请稍后重试"
|
ErrServer = "服务器出了点小问题,请稍后重试"
|
||||||
|
|
||||||
SystemdServiceName = "edge-api"
|
SystemdServiceName = "edge-api"
|
||||||
|
|
||||||
|
// 其他节点版本号,用来检测是否有需要升级的节点
|
||||||
|
|
||||||
|
NodeVersion = "0.2.3"
|
||||||
|
UserNodeVersion = "0.0.8"
|
||||||
|
AuthorityNodeVersion = "0.0.2"
|
||||||
|
MonitorNodeVersion = "0.0.2"
|
||||||
|
DNSNodeVersion = "0.0.1"
|
||||||
)
|
)
|
||||||
|
|||||||
7
internal/const/vars.go
Normal file
7
internal/const/vars.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||||
|
|
||||||
|
package teaconst
|
||||||
|
|
||||||
|
var (
|
||||||
|
IsPlus = false
|
||||||
|
)
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
@@ -29,10 +30,23 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成AccessToken
|
// GenerateAccessToken 生成AccessToken
|
||||||
func (this *APIAccessTokenDAO) GenerateAccessToken(tx *dbs.Tx, userId int64) (token string, expiresAt int64, err error) {
|
func (this *APIAccessTokenDAO) GenerateAccessToken(tx *dbs.Tx, adminId int64, userId int64) (token string, expiresAt int64, err error) {
|
||||||
|
if adminId <= 0 && userId <= 0 {
|
||||||
|
err = errors.New("either 'adminId' or 'userId' should not be zero")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if adminId > 0 {
|
||||||
|
userId = 0
|
||||||
|
}
|
||||||
|
if userId > 0 {
|
||||||
|
adminId = 0
|
||||||
|
}
|
||||||
|
|
||||||
// 查询以前的
|
// 查询以前的
|
||||||
accessToken, err := this.Query(tx).
|
accessToken, err := this.Query(tx).
|
||||||
|
Attr("adminId", adminId).
|
||||||
Attr("userId", userId).
|
Attr("userId", userId).
|
||||||
Find()
|
Find()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -48,6 +62,7 @@ func (this *APIAccessTokenDAO) GenerateAccessToken(tx *dbs.Tx, userId int64) (to
|
|||||||
op.Id = accessToken.(*APIAccessToken).Id
|
op.Id = accessToken.(*APIAccessToken).Id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
op.AdminId = adminId
|
||||||
op.UserId = userId
|
op.UserId = userId
|
||||||
op.Token = token
|
op.Token = token
|
||||||
op.CreatedAt = time.Now().Unix()
|
op.CreatedAt = time.Now().Unix()
|
||||||
@@ -56,7 +71,7 @@ func (this *APIAccessTokenDAO) GenerateAccessToken(tx *dbs.Tx, userId int64) (to
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找AccessToken
|
// FindAccessToken 查找AccessToken
|
||||||
func (this *APIAccessTokenDAO) FindAccessToken(tx *dbs.Tx, token string) (*APIAccessToken, error) {
|
func (this *APIAccessTokenDAO) FindAccessToken(tx *dbs.Tx, token string) (*APIAccessToken, error) {
|
||||||
one, err := this.Query(tx).
|
one, err := this.Query(tx).
|
||||||
Attr("token", token).
|
Attr("token", token).
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
// API访问令牌
|
// APIAccessToken API访问令牌
|
||||||
type APIAccessToken struct {
|
type APIAccessToken struct {
|
||||||
Id uint64 `field:"id"` // ID
|
Id uint64 `field:"id"` // ID
|
||||||
UserId uint32 `field:"userId"` // 用户ID
|
UserId uint32 `field:"userId"` // 用户ID
|
||||||
|
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||||
Token string `field:"token"` // 令牌
|
Token string `field:"token"` // 令牌
|
||||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||||
ExpiredAt uint64 `field:"expiredAt"` // 过期时间
|
ExpiredAt uint64 `field:"expiredAt"` // 过期时间
|
||||||
@@ -12,6 +13,7 @@ type APIAccessToken struct {
|
|||||||
type APIAccessTokenOperator struct {
|
type APIAccessTokenOperator struct {
|
||||||
Id interface{} // ID
|
Id interface{} // ID
|
||||||
UserId interface{} // 用户ID
|
UserId interface{} // 用户ID
|
||||||
|
AdminId interface{} // 管理员ID
|
||||||
Token interface{} // 令牌
|
Token interface{} // 令牌
|
||||||
CreatedAt interface{} // 创建时间
|
CreatedAt interface{} // 创建时间
|
||||||
ExpiredAt interface{} // 过期时间
|
ExpiredAt interface{} // 过期时间
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package models
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
@@ -38,7 +40,7 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启用条目
|
// EnableAPINode 启用条目
|
||||||
func (this *APINodeDAO) EnableAPINode(tx *dbs.Tx, id int64) error {
|
func (this *APINodeDAO) EnableAPINode(tx *dbs.Tx, id int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -47,7 +49,7 @@ func (this *APINodeDAO) EnableAPINode(tx *dbs.Tx, id int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 禁用条目
|
// DisableAPINode 禁用条目
|
||||||
func (this *APINodeDAO) DisableAPINode(tx *dbs.Tx, id int64) error {
|
func (this *APINodeDAO) DisableAPINode(tx *dbs.Tx, id int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -56,7 +58,7 @@ func (this *APINodeDAO) DisableAPINode(tx *dbs.Tx, id int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找启用中的条目
|
// FindEnabledAPINode 查找启用中的条目
|
||||||
func (this *APINodeDAO) FindEnabledAPINode(tx *dbs.Tx, id int64) (*APINode, error) {
|
func (this *APINodeDAO) FindEnabledAPINode(tx *dbs.Tx, id int64) (*APINode, error) {
|
||||||
result, err := this.Query(tx).
|
result, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -68,7 +70,7 @@ func (this *APINodeDAO) FindEnabledAPINode(tx *dbs.Tx, id int64) (*APINode, erro
|
|||||||
return result.(*APINode), err
|
return result.(*APINode), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据ID和Secret查找节点
|
// FindEnabledAPINodeWithUniqueIdAndSecret 根据ID和Secret查找节点
|
||||||
func (this *APINodeDAO) FindEnabledAPINodeWithUniqueIdAndSecret(tx *dbs.Tx, uniqueId string, secret string) (*APINode, error) {
|
func (this *APINodeDAO) FindEnabledAPINodeWithUniqueIdAndSecret(tx *dbs.Tx, uniqueId string, secret string) (*APINode, error) {
|
||||||
one, err := this.Query(tx).
|
one, err := this.Query(tx).
|
||||||
State(APINodeStateEnabled).
|
State(APINodeStateEnabled).
|
||||||
@@ -81,7 +83,7 @@ func (this *APINodeDAO) FindEnabledAPINodeWithUniqueIdAndSecret(tx *dbs.Tx, uniq
|
|||||||
return one.(*APINode), nil
|
return one.(*APINode), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据主键查找名称
|
// FindAPINodeName 根据主键查找名称
|
||||||
func (this *APINodeDAO) FindAPINodeName(tx *dbs.Tx, id int64) (string, error) {
|
func (this *APINodeDAO) FindAPINodeName(tx *dbs.Tx, id int64) (string, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -89,14 +91,14 @@ func (this *APINodeDAO) FindAPINodeName(tx *dbs.Tx, id int64) (string, error) {
|
|||||||
FindStringCol("")
|
FindStringCol("")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建API节点
|
// CreateAPINode 创建API节点
|
||||||
func (this *APINodeDAO) CreateAPINode(tx *dbs.Tx, name string, description string, httpJSON []byte, httpsJSON []byte, restIsOn bool, restHTTPJSON []byte, restHTTPSJSON []byte, accessAddrsJSON []byte, isOn bool) (nodeId int64, err error) {
|
func (this *APINodeDAO) CreateAPINode(tx *dbs.Tx, name string, description string, httpJSON []byte, httpsJSON []byte, restIsOn bool, restHTTPJSON []byte, restHTTPSJSON []byte, accessAddrsJSON []byte, isOn bool) (nodeId int64, err error) {
|
||||||
uniqueId, err := this.genUniqueId(tx)
|
uniqueId, err := this.genUniqueId(tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
secret := rands.String(32)
|
secret := rands.String(32)
|
||||||
err = NewApiTokenDAO().CreateAPIToken(tx, uniqueId, secret, NodeRoleAPI)
|
err = NewApiTokenDAO().CreateAPIToken(tx, uniqueId, secret, nodeconfigs.NodeRoleAPI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -134,7 +136,7 @@ func (this *APINodeDAO) CreateAPINode(tx *dbs.Tx, name string, description strin
|
|||||||
return types.Int64(op.Id), nil
|
return types.Int64(op.Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改API节点
|
// UpdateAPINode 修改API节点
|
||||||
func (this *APINodeDAO) UpdateAPINode(tx *dbs.Tx, nodeId int64, name string, description string, httpJSON []byte, httpsJSON []byte, restIsOn bool, restHTTPJSON []byte, restHTTPSJSON []byte, accessAddrsJSON []byte, isOn bool) error {
|
func (this *APINodeDAO) UpdateAPINode(tx *dbs.Tx, nodeId int64, name string, description string, httpJSON []byte, httpsJSON []byte, restIsOn bool, restHTTPJSON []byte, restHTTPSJSON []byte, accessAddrsJSON []byte, isOn bool) error {
|
||||||
if nodeId <= 0 {
|
if nodeId <= 0 {
|
||||||
return errors.New("invalid nodeId")
|
return errors.New("invalid nodeId")
|
||||||
@@ -177,7 +179,7 @@ func (this *APINodeDAO) UpdateAPINode(tx *dbs.Tx, nodeId int64, name string, des
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出所有可用API节点
|
// FindAllEnabledAPINodes 列出所有可用API节点
|
||||||
func (this *APINodeDAO) FindAllEnabledAPINodes(tx *dbs.Tx) (result []*APINode, err error) {
|
func (this *APINodeDAO) FindAllEnabledAPINodes(tx *dbs.Tx) (result []*APINode, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
Attr("clusterId", 0). // 非集群专用
|
Attr("clusterId", 0). // 非集群专用
|
||||||
@@ -189,7 +191,7 @@ func (this *APINodeDAO) FindAllEnabledAPINodes(tx *dbs.Tx) (result []*APINode, e
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出所有可用而且启用的API节点
|
// FindAllEnabledAndOnAPINodes 列出所有可用而且启用的API节点
|
||||||
func (this *APINodeDAO) FindAllEnabledAndOnAPINodes(tx *dbs.Tx) (result []*APINode, err error) {
|
func (this *APINodeDAO) FindAllEnabledAndOnAPINodes(tx *dbs.Tx) (result []*APINode, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
Attr("clusterId", 0). // 非集群专用
|
Attr("clusterId", 0). // 非集群专用
|
||||||
@@ -202,14 +204,14 @@ func (this *APINodeDAO) FindAllEnabledAndOnAPINodes(tx *dbs.Tx) (result []*APINo
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算API节点数量
|
// CountAllEnabledAPINodes 计算API节点数量
|
||||||
func (this *APINodeDAO) CountAllEnabledAPINodes(tx *dbs.Tx) (int64, error) {
|
func (this *APINodeDAO) CountAllEnabledAPINodes(tx *dbs.Tx) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
State(APINodeStateEnabled).
|
State(APINodeStateEnabled).
|
||||||
Count()
|
Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出单页的API节点
|
// ListEnabledAPINodes 列出单页的API节点
|
||||||
func (this *APINodeDAO) ListEnabledAPINodes(tx *dbs.Tx, offset int64, size int64) (result []*APINode, err error) {
|
func (this *APINodeDAO) ListEnabledAPINodes(tx *dbs.Tx, offset int64, size int64) (result []*APINode, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
Attr("clusterId", 0). // 非集群专用
|
Attr("clusterId", 0). // 非集群专用
|
||||||
@@ -223,7 +225,7 @@ func (this *APINodeDAO) ListEnabledAPINodes(tx *dbs.Tx, offset int64, size int64
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据主机名和端口获取ID
|
// FindEnabledAPINodeIdWithAddr 根据主机名和端口获取ID
|
||||||
func (this *APINodeDAO) FindEnabledAPINodeIdWithAddr(tx *dbs.Tx, protocol string, host string, port int) (int64, error) {
|
func (this *APINodeDAO) FindEnabledAPINodeIdWithAddr(tx *dbs.Tx, protocol string, host string, port int) (int64, error) {
|
||||||
addr := maps.Map{
|
addr := maps.Map{
|
||||||
"protocol": protocol,
|
"protocol": protocol,
|
||||||
@@ -250,7 +252,7 @@ func (this *APINodeDAO) FindEnabledAPINodeIdWithAddr(tx *dbs.Tx, protocol string
|
|||||||
return int64(one.(*APINode).Id), nil
|
return int64(one.(*APINode).Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置API节点状态
|
// UpdateAPINodeStatus 设置API节点状态
|
||||||
func (this *APINodeDAO) UpdateAPINodeStatus(tx *dbs.Tx, apiNodeId int64, statusJSON []byte) error {
|
func (this *APINodeDAO) UpdateAPINodeStatus(tx *dbs.Tx, apiNodeId int64, statusJSON []byte) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(apiNodeId).
|
Pk(apiNodeId).
|
||||||
@@ -275,3 +277,13 @@ func (this *APINodeDAO) genUniqueId(tx *dbs.Tx) (string, error) {
|
|||||||
return uniqueId, nil
|
return uniqueId, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CountAllLowerVersionNodes 计算所有节点中低于某个版本的节点数量
|
||||||
|
func (this *APINodeDAO) CountAllLowerVersionNodes(tx *dbs.Tx, version string) (int64, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
State(APINodeStateEnabled).
|
||||||
|
Where("status IS NOT NULL").
|
||||||
|
Where("(JSON_EXTRACT(status, '$.buildVersionCode') IS NULL OR JSON_EXTRACT(status, '$.buildVersionCode')<:version)").
|
||||||
|
Param("version", utils.VersionToLong(version)).
|
||||||
|
Count()
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
@@ -34,7 +35,7 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启用条目
|
// EnableApiToken 启用条目
|
||||||
func (this *ApiTokenDAO) EnableApiToken(tx *dbs.Tx, id uint32) (rowsAffected int64, err error) {
|
func (this *ApiTokenDAO) EnableApiToken(tx *dbs.Tx, id uint32) (rowsAffected int64, err error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -42,7 +43,7 @@ func (this *ApiTokenDAO) EnableApiToken(tx *dbs.Tx, id uint32) (rowsAffected int
|
|||||||
Update()
|
Update()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 禁用条目
|
// DisableApiToken 禁用条目
|
||||||
func (this *ApiTokenDAO) DisableApiToken(tx *dbs.Tx, id uint32) (rowsAffected int64, err error) {
|
func (this *ApiTokenDAO) DisableApiToken(tx *dbs.Tx, id uint32) (rowsAffected int64, err error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -50,7 +51,7 @@ func (this *ApiTokenDAO) DisableApiToken(tx *dbs.Tx, id uint32) (rowsAffected in
|
|||||||
Update()
|
Update()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找启用中的条目
|
// FindEnabledApiToken 查找启用中的条目
|
||||||
func (this *ApiTokenDAO) FindEnabledApiToken(tx *dbs.Tx, id uint32) (*ApiToken, error) {
|
func (this *ApiTokenDAO) FindEnabledApiToken(tx *dbs.Tx, id uint32) (*ApiToken, error) {
|
||||||
result, err := this.Query(tx).
|
result, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -62,7 +63,7 @@ func (this *ApiTokenDAO) FindEnabledApiToken(tx *dbs.Tx, id uint32) (*ApiToken,
|
|||||||
return result.(*ApiToken), err
|
return result.(*ApiToken), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取可缓存的节点Token信息
|
// FindEnabledTokenWithNodeCacheable 获取可缓存的节点Token信息
|
||||||
func (this *ApiTokenDAO) FindEnabledTokenWithNodeCacheable(tx *dbs.Tx, nodeId string) (*ApiToken, error) {
|
func (this *ApiTokenDAO) FindEnabledTokenWithNodeCacheable(tx *dbs.Tx, nodeId string) (*ApiToken, error) {
|
||||||
SharedCacheLocker.RLock()
|
SharedCacheLocker.RLock()
|
||||||
token, ok := apiTokenCacheMap[nodeId]
|
token, ok := apiTokenCacheMap[nodeId]
|
||||||
@@ -85,7 +86,7 @@ func (this *ApiTokenDAO) FindEnabledTokenWithNodeCacheable(tx *dbs.Tx, nodeId st
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取节点Token信息并可以缓存
|
// FindEnabledTokenWithNode 获取节点Token信息并可以缓存
|
||||||
func (this *ApiTokenDAO) FindEnabledTokenWithNode(tx *dbs.Tx, nodeId string) (*ApiToken, error) {
|
func (this *ApiTokenDAO) FindEnabledTokenWithNode(tx *dbs.Tx, nodeId string) (*ApiToken, error) {
|
||||||
one, err := this.Query(tx).
|
one, err := this.Query(tx).
|
||||||
Attr("nodeId", nodeId).
|
Attr("nodeId", nodeId).
|
||||||
@@ -97,7 +98,7 @@ func (this *ApiTokenDAO) FindEnabledTokenWithNode(tx *dbs.Tx, nodeId string) (*A
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据角色获取节点
|
// FindEnabledTokenWithRole 根据角色获取节点
|
||||||
func (this *ApiTokenDAO) FindEnabledTokenWithRole(tx *dbs.Tx, role string) (*ApiToken, error) {
|
func (this *ApiTokenDAO) FindEnabledTokenWithRole(tx *dbs.Tx, role string) (*ApiToken, error) {
|
||||||
one, err := this.Query(tx).
|
one, err := this.Query(tx).
|
||||||
Attr("role", role).
|
Attr("role", role).
|
||||||
@@ -109,8 +110,8 @@ func (this *ApiTokenDAO) FindEnabledTokenWithRole(tx *dbs.Tx, role string) (*Api
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存API Token
|
// CreateAPIToken 保存API Token
|
||||||
func (this *ApiTokenDAO) CreateAPIToken(tx *dbs.Tx, nodeId string, secret string, role NodeRole) error {
|
func (this *ApiTokenDAO) CreateAPIToken(tx *dbs.Tx, nodeId string, secret string, role nodeconfigs.NodeRole) error {
|
||||||
op := NewApiTokenOperator()
|
op := NewApiTokenOperator()
|
||||||
op.NodeId = nodeId
|
op.NodeId = nodeId
|
||||||
op.Secret = secret
|
op.Secret = secret
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ package authority
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,6 +28,9 @@ var SharedAuthorityKeyDAO *AuthorityKeyDAO
|
|||||||
func init() {
|
func init() {
|
||||||
dbs.OnReady(func() {
|
dbs.OnReady(func() {
|
||||||
SharedAuthorityKeyDAO = NewAuthorityKeyDAO()
|
SharedAuthorityKeyDAO = NewAuthorityKeyDAO()
|
||||||
|
|
||||||
|
// 初始化IsPlus值
|
||||||
|
_, _ = SharedAuthorityKeyDAO.IsPlus(nil)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +77,14 @@ func (this *AuthorityKeyDAO) ReadKey(tx *dbs.Tx) (key *AuthorityKey, err error)
|
|||||||
if one == nil {
|
if one == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
return one.(*AuthorityKey), nil
|
key = one.(*AuthorityKey)
|
||||||
|
|
||||||
|
// 顺便更新相关变量
|
||||||
|
if key.DayTo >= timeutil.Format("Y-m-d") {
|
||||||
|
teaconst.IsPlus = true
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResetKey 重置Key
|
// ResetKey 重置Key
|
||||||
@@ -81,3 +93,16 @@ func (this *AuthorityKeyDAO) ResetKey(tx *dbs.Tx) error {
|
|||||||
Delete()
|
Delete()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsPlus 判断是否为企业版
|
||||||
|
func (this *AuthorityKeyDAO) IsPlus(tx *dbs.Tx) (bool, error) {
|
||||||
|
key, err := this.ReadKey(tx)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if key == nil {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
teaconst.IsPlus = key.DayTo >= timeutil.Format("Y-m-d")
|
||||||
|
return teaconst.IsPlus, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,17 +7,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestAuthorityKeyDAO_UpdateValue(t *testing.T) {
|
func TestAuthorityKeyDAO_UpdateValue(t *testing.T) {
|
||||||
err := NewAuthorityKeyDAO().UpdateValue(nil, "12345678")
|
err := NewAuthorityKeyDAO().UpdateKey(nil, "12345678", "", "", "", []string{}, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
t.Logf("ok")
|
t.Log("ok")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAuthorityKeyDAO_ReadValue(t *testing.T) {
|
func TestAuthorityKeyDAO_ReadValue(t *testing.T) {
|
||||||
value, err := NewAuthorityKeyDAO().ReadValue(nil)
|
value, err := NewAuthorityKeyDAO().ReadKey(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
t.Logf(value)
|
t.Log(value)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package authority
|
|||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
@@ -112,7 +114,7 @@ func (this *AuthorityNodeDAO) CreateAuthorityNode(tx *dbs.Tx, name string, descr
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
secret := rands.String(32)
|
secret := rands.String(32)
|
||||||
err = models.NewApiTokenDAO().CreateAPIToken(tx, uniqueId, secret, models.NodeRoleAuthority)
|
err = models.NewApiTokenDAO().CreateAPIToken(tx, uniqueId, secret, nodeconfigs.NodeRoleAuthority)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -196,3 +198,13 @@ func (this *AuthorityNodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, statusJ
|
|||||||
Update()
|
Update()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CountAllLowerVersionNodes 计算所有节点中低于某个版本的节点数量
|
||||||
|
func (this *AuthorityNodeDAO) CountAllLowerVersionNodes(tx *dbs.Tx, version string) (int64, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
State(AuthorityNodeStateEnabled).
|
||||||
|
Where("status IS NOT NULL").
|
||||||
|
Where("(JSON_EXTRACT(status, '$.buildVersionCode') IS NULL OR JSON_EXTRACT(status, '$.buildVersionCode')<:version)").
|
||||||
|
Param("version", utils.VersionToLong(version)).
|
||||||
|
Count()
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package models
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
"github.com/iwind/TeaGo/lists"
|
"github.com/iwind/TeaGo/lists"
|
||||||
"github.com/iwind/TeaGo/logs"
|
"github.com/iwind/TeaGo/logs"
|
||||||
@@ -15,16 +16,29 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var accessLogDBMapping = map[int64]*dbs.DB{} // dbNodeId => DB
|
var accessLogDBMapping = map[int64]*dbs.DB{} // dbNodeId => DB
|
||||||
var accessLogDAOMapping = map[int64]*HTTPAccessLogDAOWrapper{} // dbNodeId => DAO
|
|
||||||
var accessLogLocker = &sync.RWMutex{}
|
var accessLogLocker = &sync.RWMutex{}
|
||||||
var accessLogTableMapping = map[string]bool{} // tableName_crc(dsn) => true
|
|
||||||
|
|
||||||
|
// HTTP服务访问
|
||||||
|
var httpAccessLogDAOMapping = map[int64]*HTTPAccessLogDAOWrapper{} // dbNodeId => DAO
|
||||||
|
var httpAccessLogTableMapping = map[string]bool{} // tableName_crc(dsn) => true
|
||||||
|
|
||||||
|
// DNS服务访问
|
||||||
|
var nsAccessLogDAOMapping = map[int64]*NSAccessLogDAOWrapper{} // dbNodeId => DAO
|
||||||
|
var nsAccessLogTableMapping = map[string]bool{} // tableName_crc(dsn) => true
|
||||||
|
|
||||||
|
// HTTPAccessLogDAOWrapper HTTP访问日志DAO
|
||||||
type HTTPAccessLogDAOWrapper struct {
|
type HTTPAccessLogDAOWrapper struct {
|
||||||
DAO *HTTPAccessLogDAO
|
DAO *HTTPAccessLogDAO
|
||||||
NodeId int64
|
NodeId int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NSAccessLogDAOWrapper NS访问日志DAO
|
||||||
|
type NSAccessLogDAOWrapper struct {
|
||||||
|
DAO *NSAccessLogDAO
|
||||||
|
NodeId int64
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
initializer := NewDBNodeInitializer()
|
initializer := NewDBNodeInitializer()
|
||||||
dbs.OnReadyDone(func() {
|
dbs.OnReadyDone(func() {
|
||||||
@@ -33,12 +47,26 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取获取DAO
|
// 获取获取DAO
|
||||||
func randomAccessLogDAO() (dao *HTTPAccessLogDAOWrapper) {
|
func randomHTTPAccessLogDAO() (dao *HTTPAccessLogDAOWrapper) {
|
||||||
accessLogLocker.RLock()
|
accessLogLocker.RLock()
|
||||||
if len(accessLogDAOMapping) == 0 {
|
if len(httpAccessLogDAOMapping) == 0 {
|
||||||
dao = nil
|
dao = nil
|
||||||
} else {
|
} else {
|
||||||
for _, d := range accessLogDAOMapping {
|
for _, d := range httpAccessLogDAOMapping {
|
||||||
|
dao = d
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
accessLogLocker.RUnlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func randomNSAccessLogDAO() (dao *NSAccessLogDAOWrapper) {
|
||||||
|
accessLogLocker.RLock()
|
||||||
|
if len(nsAccessLogDAOMapping) == 0 {
|
||||||
|
dao = nil
|
||||||
|
} else {
|
||||||
|
for _, d := range nsAccessLogDAOMapping {
|
||||||
dao = d
|
dao = d
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -48,7 +76,7 @@ func randomAccessLogDAO() (dao *HTTPAccessLogDAOWrapper) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 检查表格是否存在
|
// 检查表格是否存在
|
||||||
func findAccessLogTableName(db *dbs.DB, day string) (tableName string, ok bool, err error) {
|
func findHTTPAccessLogTableName(db *dbs.DB, day string) (tableName string, ok bool, err error) {
|
||||||
if !regexp.MustCompile(`^\d{8}$`).MatchString(day) {
|
if !regexp.MustCompile(`^\d{8}$`).MatchString(day) {
|
||||||
err = errors.New("invalid day '" + day + "', should be YYYYMMDD")
|
err = errors.New("invalid day '" + day + "', should be YYYYMMDD")
|
||||||
return
|
return
|
||||||
@@ -63,7 +91,36 @@ func findAccessLogTableName(db *dbs.DB, day string) (tableName string, ok bool,
|
|||||||
cacheKey := tableName + "_" + fmt.Sprintf("%d", crc32.ChecksumIEEE([]byte(config.Dsn)))
|
cacheKey := tableName + "_" + fmt.Sprintf("%d", crc32.ChecksumIEEE([]byte(config.Dsn)))
|
||||||
|
|
||||||
accessLogLocker.RLock()
|
accessLogLocker.RLock()
|
||||||
_, ok = accessLogTableMapping[cacheKey]
|
_, ok = httpAccessLogTableMapping[cacheKey]
|
||||||
|
accessLogLocker.RUnlock()
|
||||||
|
if ok {
|
||||||
|
return tableName, true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
tableNames, err := db.TableNames()
|
||||||
|
if err != nil {
|
||||||
|
return tableName, false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return tableName, lists.ContainsString(tableNames, tableName), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func findNSAccessLogTableName(db *dbs.DB, day string) (tableName string, ok bool, err error) {
|
||||||
|
if !regexp.MustCompile(`^\d{8}$`).MatchString(day) {
|
||||||
|
err = errors.New("invalid day '" + day + "', should be YYYYMMDD")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
config, err := db.Config()
|
||||||
|
if err != nil {
|
||||||
|
return "", false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
tableName = "edgeNSAccessLogs_" + day
|
||||||
|
cacheKey := tableName + "_" + fmt.Sprintf("%d", crc32.ChecksumIEEE([]byte(config.Dsn)))
|
||||||
|
|
||||||
|
accessLogLocker.RLock()
|
||||||
|
_, ok = nsAccessLogTableMapping[cacheKey]
|
||||||
accessLogLocker.RUnlock()
|
accessLogLocker.RUnlock()
|
||||||
if ok {
|
if ok {
|
||||||
return tableName, true, nil
|
return tableName, true, nil
|
||||||
@@ -78,7 +135,7 @@ func findAccessLogTableName(db *dbs.DB, day string) (tableName string, ok bool,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 根据日期获取表名
|
// 根据日期获取表名
|
||||||
func findAccessLogTable(db *dbs.DB, day string, force bool) (string, error) {
|
func findHTTPAccessLogTable(db *dbs.DB, day string, force bool) (string, error) {
|
||||||
config, err := db.Config()
|
config, err := db.Config()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@@ -89,7 +146,7 @@ func findAccessLogTable(db *dbs.DB, day string, force bool) (string, error) {
|
|||||||
|
|
||||||
if !force {
|
if !force {
|
||||||
accessLogLocker.RLock()
|
accessLogLocker.RLock()
|
||||||
_, ok := accessLogTableMapping[cacheKey]
|
_, ok := httpAccessLogTableMapping[cacheKey]
|
||||||
accessLogLocker.RUnlock()
|
accessLogLocker.RUnlock()
|
||||||
if ok {
|
if ok {
|
||||||
return tableName, nil
|
return tableName, nil
|
||||||
@@ -103,7 +160,7 @@ func findAccessLogTable(db *dbs.DB, day string, force bool) (string, error) {
|
|||||||
|
|
||||||
if lists.ContainsString(tableNames, tableName) {
|
if lists.ContainsString(tableNames, tableName) {
|
||||||
accessLogLocker.Lock()
|
accessLogLocker.Lock()
|
||||||
accessLogTableMapping[cacheKey] = true
|
httpAccessLogTableMapping[cacheKey] = true
|
||||||
accessLogLocker.Unlock()
|
accessLogLocker.Unlock()
|
||||||
return tableName, nil
|
return tableName, nil
|
||||||
}
|
}
|
||||||
@@ -115,13 +172,56 @@ func findAccessLogTable(db *dbs.DB, day string, force bool) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
accessLogLocker.Lock()
|
accessLogLocker.Lock()
|
||||||
accessLogTableMapping[cacheKey] = true
|
httpAccessLogTableMapping[cacheKey] = true
|
||||||
accessLogLocker.Unlock()
|
accessLogLocker.Unlock()
|
||||||
|
|
||||||
return tableName, nil
|
return tableName, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化数据库连接
|
func findNSAccessLogTable(db *dbs.DB, day string, force bool) (string, error) {
|
||||||
|
config, err := db.Config()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
tableName := "edgeNSAccessLogs_" + day
|
||||||
|
cacheKey := tableName + "_" + fmt.Sprintf("%d", crc32.ChecksumIEEE([]byte(config.Dsn)))
|
||||||
|
|
||||||
|
if !force {
|
||||||
|
accessLogLocker.RLock()
|
||||||
|
_, ok := nsAccessLogTableMapping[cacheKey]
|
||||||
|
accessLogLocker.RUnlock()
|
||||||
|
if ok {
|
||||||
|
return tableName, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tableNames, err := db.TableNames()
|
||||||
|
if err != nil {
|
||||||
|
return tableName, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if lists.ContainsString(tableNames, tableName) {
|
||||||
|
accessLogLocker.Lock()
|
||||||
|
nsAccessLogTableMapping[cacheKey] = true
|
||||||
|
accessLogLocker.Unlock()
|
||||||
|
return tableName, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建表格
|
||||||
|
_, err = db.Exec("CREATE TABLE `" + tableName + "` (\n `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `nodeId` int(11) unsigned DEFAULT '0' COMMENT '节点ID',\n `domainId` int(11) unsigned DEFAULT '0' COMMENT '域名ID',\n `recordId` int(11) unsigned DEFAULT '0' COMMENT '记录ID',\n `content` json DEFAULT NULL COMMENT '访问数据',\n `requestId` varchar(128) DEFAULT NULL COMMENT '请求ID',\n `createdAt` bigint(11) unsigned DEFAULT '0' COMMENT '创建时间',\n PRIMARY KEY (`id`),\n KEY `nodeId` (`nodeId`),\n KEY `domainId` (`domainId`),\n KEY `recordId` (`recordId`),\n KEY `requestId` (`requestId`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='域名服务访问日志';")
|
||||||
|
if err != nil {
|
||||||
|
return tableName, err
|
||||||
|
}
|
||||||
|
|
||||||
|
accessLogLocker.Lock()
|
||||||
|
nsAccessLogTableMapping[cacheKey] = true
|
||||||
|
accessLogLocker.Unlock()
|
||||||
|
|
||||||
|
return tableName, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DBNodeInitializer 初始化数据库连接
|
||||||
type DBNodeInitializer struct {
|
type DBNodeInitializer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +229,7 @@ func NewDBNodeInitializer() *DBNodeInitializer {
|
|||||||
return &DBNodeInitializer{}
|
return &DBNodeInitializer{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启动
|
// Start 启动
|
||||||
func (this *DBNodeInitializer) Start() {
|
func (this *DBNodeInitializer) Start() {
|
||||||
// 初始运行
|
// 初始运行
|
||||||
err := this.loop()
|
err := this.loop()
|
||||||
@@ -166,7 +266,8 @@ func (this *DBNodeInitializer) loop() error {
|
|||||||
if !lists.ContainsInt64(nodeIds, nodeId) {
|
if !lists.ContainsInt64(nodeIds, nodeId) {
|
||||||
closingDbs = append(closingDbs, db)
|
closingDbs = append(closingDbs, db)
|
||||||
delete(accessLogDBMapping, nodeId)
|
delete(accessLogDBMapping, nodeId)
|
||||||
delete(accessLogDAOMapping, nodeId)
|
delete(httpAccessLogDAOMapping, nodeId)
|
||||||
|
delete(nsAccessLogDAOMapping, nodeId)
|
||||||
logs.Println("[DB_NODE]close db node '" + strconv.FormatInt(nodeId, 10) + "'")
|
logs.Println("[DB_NODE]close db node '" + strconv.FormatInt(nodeId, 10) + "'")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -212,46 +313,94 @@ func (this *DBNodeInitializer) loop() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 检查表是否存在
|
// 检查表是否存在
|
||||||
tableName, err := findAccessLogTable(db, timeutil.Format("Ymd"), false)
|
// httpAccessLog
|
||||||
if err != nil {
|
{
|
||||||
if !strings.Contains(err.Error(), "1050") { // 非表格已存在错误
|
tableName, err := findHTTPAccessLogTable(db, timeutil.Format("Ymd"), false)
|
||||||
logs.Println("[DB_NODE]create first table in database node failed: " + err.Error())
|
if err != nil {
|
||||||
|
if !strings.Contains(err.Error(), "1050") { // 非表格已存在错误
|
||||||
|
logs.Println("[DB_NODE]create first table in database node failed: " + err.Error())
|
||||||
|
|
||||||
// 创建节点日志
|
// 创建节点日志
|
||||||
createLogErr := SharedNodeLogDAO.CreateLog(nil, NodeRoleDatabase, nodeId, "error", "ACCESS_LOG", "can not create access log table: "+err.Error(), time.Now().Unix())
|
createLogErr := SharedNodeLogDAO.CreateLog(nil, nodeconfigs.NodeRoleDatabase, nodeId, 0, "error", "ACCESS_LOG", "can not create access log table: "+err.Error(), time.Now().Unix())
|
||||||
if createLogErr != nil {
|
if createLogErr != nil {
|
||||||
logs.Println("[NODE_LOG]" + createLogErr.Error())
|
logs.Println("[NODE_LOG]" + createLogErr.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
err = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
continue
|
|
||||||
} else {
|
|
||||||
err = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
daoObject := dbs.DAOObject{
|
||||||
|
Instance: db,
|
||||||
|
DB: node.Name + "(id:" + strconv.Itoa(int(node.Id)) + ")",
|
||||||
|
Table: tableName,
|
||||||
|
PkName: "id",
|
||||||
|
Model: new(HTTPAccessLog),
|
||||||
|
}
|
||||||
|
err = daoObject.Init()
|
||||||
|
if err != nil {
|
||||||
|
logs.Println("[DB_NODE]initialize dao failed: " + err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
accessLogLocker.Lock()
|
||||||
|
accessLogDBMapping[nodeId] = db
|
||||||
|
dao := &HTTPAccessLogDAO{
|
||||||
|
DAOObject: daoObject,
|
||||||
|
}
|
||||||
|
httpAccessLogDAOMapping[nodeId] = &HTTPAccessLogDAOWrapper{
|
||||||
|
DAO: dao,
|
||||||
|
NodeId: nodeId,
|
||||||
|
}
|
||||||
|
accessLogLocker.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
daoObject := dbs.DAOObject{
|
|
||||||
Instance: db,
|
|
||||||
DB: node.Name + "(id:" + strconv.Itoa(int(node.Id)) + ")",
|
|
||||||
Table: tableName,
|
|
||||||
PkName: "id",
|
|
||||||
Model: new(HTTPAccessLog),
|
|
||||||
}
|
|
||||||
err = daoObject.Init()
|
|
||||||
if err != nil {
|
|
||||||
logs.Println("[DB_NODE]initialize dao failed: " + err.Error())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
accessLogLocker.Lock()
|
// nsAccessLog
|
||||||
accessLogDBMapping[nodeId] = db
|
{
|
||||||
dao := &HTTPAccessLogDAO{
|
tableName, err := findNSAccessLogTable(db, timeutil.Format("Ymd"), false)
|
||||||
DAOObject: daoObject,
|
if err != nil {
|
||||||
|
if !strings.Contains(err.Error(), "1050") { // 非表格已存在错误
|
||||||
|
logs.Println("[DB_NODE]create first table in database node failed: " + err.Error())
|
||||||
|
|
||||||
|
// 创建节点日志
|
||||||
|
createLogErr := SharedNodeLogDAO.CreateLog(nil, nodeconfigs.NodeRoleDatabase, nodeId, 0, "error", "ACCESS_LOG", "can not create access log table: "+err.Error(), time.Now().Unix())
|
||||||
|
if createLogErr != nil {
|
||||||
|
logs.Println("[NODE_LOG]" + createLogErr.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
daoObject := dbs.DAOObject{
|
||||||
|
Instance: db,
|
||||||
|
DB: node.Name + "(id:" + strconv.Itoa(int(node.Id)) + ")",
|
||||||
|
Table: tableName,
|
||||||
|
PkName: "id",
|
||||||
|
Model: new(NSAccessLog),
|
||||||
|
}
|
||||||
|
err = daoObject.Init()
|
||||||
|
if err != nil {
|
||||||
|
logs.Println("[DB_NODE]initialize dao failed: " + err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
accessLogLocker.Lock()
|
||||||
|
accessLogDBMapping[nodeId] = db
|
||||||
|
dao := &NSAccessLogDAO{
|
||||||
|
DAOObject: daoObject,
|
||||||
|
}
|
||||||
|
nsAccessLogDAOMapping[nodeId] = &NSAccessLogDAOWrapper{
|
||||||
|
DAO: dao,
|
||||||
|
NodeId: nodeId,
|
||||||
|
}
|
||||||
|
accessLogLocker.Unlock()
|
||||||
}
|
}
|
||||||
accessLogDAOMapping[nodeId] = &HTTPAccessLogDAOWrapper{
|
|
||||||
DAO: dao,
|
|
||||||
NodeId: nodeId,
|
|
||||||
}
|
|
||||||
accessLogLocker.Unlock()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ func TestDBNodeInitializer_loop(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
t.Log(len(accessLogDBMapping), len(accessLogDAOMapping))
|
t.Log(len(accessLogDBMapping), len(httpAccessLogDAOMapping))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFindAccessLogTable(t *testing.T) {
|
func TestFindAccessLogTable(t *testing.T) {
|
||||||
before := time.Now()
|
before := time.Now()
|
||||||
db := SharedHTTPAccessLogDAO.Instance
|
db := SharedHTTPAccessLogDAO.Instance
|
||||||
tableName, err := findAccessLogTable(db, "20201010", false)
|
tableName, err := findHTTPAccessLogTable(db, "20201010", false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ func TestFindAccessLogTable(t *testing.T) {
|
|||||||
t.Log(time.Since(before).Seconds()*1000, "ms")
|
t.Log(time.Since(before).Seconds()*1000, "ms")
|
||||||
|
|
||||||
before = time.Now()
|
before = time.Now()
|
||||||
tableName, err = findAccessLogTable(db, "20201010", false)
|
tableName, err = findHTTPAccessLogTable(db, "20201010", false)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -40,6 +40,6 @@ func BenchmarkFindAccessLogTable(b *testing.B) {
|
|||||||
|
|
||||||
runtime.GOMAXPROCS(1)
|
runtime.GOMAXPROCS(1)
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_, _ = findAccessLogTable(db, "20201010", false)
|
_, _ = findHTTPAccessLogTable(db, "20201010", false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package dns
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients"
|
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients/dnstypes"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
@@ -39,7 +39,7 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启用条目
|
// EnableDNSDomain 启用条目
|
||||||
func (this *DNSDomainDAO) EnableDNSDomain(tx *dbs.Tx, id int64) error {
|
func (this *DNSDomainDAO) EnableDNSDomain(tx *dbs.Tx, id int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -48,7 +48,7 @@ func (this *DNSDomainDAO) EnableDNSDomain(tx *dbs.Tx, id int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 禁用条目
|
// DisableDNSDomain 禁用条目
|
||||||
func (this *DNSDomainDAO) DisableDNSDomain(tx *dbs.Tx, id int64) error {
|
func (this *DNSDomainDAO) DisableDNSDomain(tx *dbs.Tx, id int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -57,7 +57,7 @@ func (this *DNSDomainDAO) DisableDNSDomain(tx *dbs.Tx, id int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找启用中的条目
|
// FindEnabledDNSDomain 查找启用中的条目
|
||||||
func (this *DNSDomainDAO) FindEnabledDNSDomain(tx *dbs.Tx, id int64) (*DNSDomain, error) {
|
func (this *DNSDomainDAO) FindEnabledDNSDomain(tx *dbs.Tx, id int64) (*DNSDomain, error) {
|
||||||
result, err := this.Query(tx).
|
result, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -69,7 +69,7 @@ func (this *DNSDomainDAO) FindEnabledDNSDomain(tx *dbs.Tx, id int64) (*DNSDomain
|
|||||||
return result.(*DNSDomain), err
|
return result.(*DNSDomain), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据主键查找名称
|
// FindDNSDomainName 根据主键查找名称
|
||||||
func (this *DNSDomainDAO) FindDNSDomainName(tx *dbs.Tx, id int64) (string, error) {
|
func (this *DNSDomainDAO) FindDNSDomainName(tx *dbs.Tx, id int64) (string, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -77,7 +77,7 @@ func (this *DNSDomainDAO) FindDNSDomainName(tx *dbs.Tx, id int64) (string, error
|
|||||||
FindStringCol("")
|
FindStringCol("")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建域名
|
// CreateDomain 创建域名
|
||||||
func (this *DNSDomainDAO) CreateDomain(tx *dbs.Tx, adminId int64, userId int64, providerId int64, name string) (int64, error) {
|
func (this *DNSDomainDAO) CreateDomain(tx *dbs.Tx, adminId int64, userId int64, providerId int64, name string) (int64, error) {
|
||||||
op := NewDNSDomainOperator()
|
op := NewDNSDomainOperator()
|
||||||
op.ProviderId = providerId
|
op.ProviderId = providerId
|
||||||
@@ -93,7 +93,7 @@ func (this *DNSDomainDAO) CreateDomain(tx *dbs.Tx, adminId int64, userId int64,
|
|||||||
return types.Int64(op.Id), nil
|
return types.Int64(op.Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改域名
|
// UpdateDomain 修改域名
|
||||||
func (this *DNSDomainDAO) UpdateDomain(tx *dbs.Tx, domainId int64, name string, isOn bool) error {
|
func (this *DNSDomainDAO) UpdateDomain(tx *dbs.Tx, domainId int64, name string, isOn bool) error {
|
||||||
if domainId <= 0 {
|
if domainId <= 0 {
|
||||||
return errors.New("invalid domainId")
|
return errors.New("invalid domainId")
|
||||||
@@ -109,7 +109,7 @@ func (this *DNSDomainDAO) UpdateDomain(tx *dbs.Tx, domainId int64, name string,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询一个服务商下面的所有域名
|
// FindAllEnabledDomainsWithProviderId 查询一个服务商下面的所有域名
|
||||||
func (this *DNSDomainDAO) FindAllEnabledDomainsWithProviderId(tx *dbs.Tx, providerId int64) (result []*DNSDomain, err error) {
|
func (this *DNSDomainDAO) FindAllEnabledDomainsWithProviderId(tx *dbs.Tx, providerId int64) (result []*DNSDomain, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(DNSDomainStateEnabled).
|
State(DNSDomainStateEnabled).
|
||||||
@@ -120,7 +120,7 @@ func (this *DNSDomainDAO) FindAllEnabledDomainsWithProviderId(tx *dbs.Tx, provid
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算某个服务商下的域名数量
|
// CountAllEnabledDomainsWithProviderId 计算某个服务商下的域名数量
|
||||||
func (this *DNSDomainDAO) CountAllEnabledDomainsWithProviderId(tx *dbs.Tx, providerId int64) (int64, error) {
|
func (this *DNSDomainDAO) CountAllEnabledDomainsWithProviderId(tx *dbs.Tx, providerId int64) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
State(DNSDomainStateEnabled).
|
State(DNSDomainStateEnabled).
|
||||||
@@ -128,7 +128,7 @@ func (this *DNSDomainDAO) CountAllEnabledDomainsWithProviderId(tx *dbs.Tx, provi
|
|||||||
Count()
|
Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新域名数据
|
// UpdateDomainData 更新域名数据
|
||||||
func (this *DNSDomainDAO) UpdateDomainData(tx *dbs.Tx, domainId int64, data string) error {
|
func (this *DNSDomainDAO) UpdateDomainData(tx *dbs.Tx, domainId int64, data string) error {
|
||||||
if domainId <= 0 {
|
if domainId <= 0 {
|
||||||
return errors.New("invalid domainId")
|
return errors.New("invalid domainId")
|
||||||
@@ -140,7 +140,7 @@ func (this *DNSDomainDAO) UpdateDomainData(tx *dbs.Tx, domainId int64, data stri
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新域名解析记录
|
// UpdateDomainRecords 更新域名解析记录
|
||||||
func (this *DNSDomainDAO) UpdateDomainRecords(tx *dbs.Tx, domainId int64, recordsJSON []byte) error {
|
func (this *DNSDomainDAO) UpdateDomainRecords(tx *dbs.Tx, domainId int64, recordsJSON []byte) error {
|
||||||
if domainId <= 0 {
|
if domainId <= 0 {
|
||||||
return errors.New("invalid domainId")
|
return errors.New("invalid domainId")
|
||||||
@@ -153,7 +153,7 @@ func (this *DNSDomainDAO) UpdateDomainRecords(tx *dbs.Tx, domainId int64, record
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新线路
|
// UpdateDomainRoutes 更新线路
|
||||||
func (this *DNSDomainDAO) UpdateDomainRoutes(tx *dbs.Tx, domainId int64, routesJSON []byte) error {
|
func (this *DNSDomainDAO) UpdateDomainRoutes(tx *dbs.Tx, domainId int64, routesJSON []byte) error {
|
||||||
if domainId <= 0 {
|
if domainId <= 0 {
|
||||||
return errors.New("invalid domainId")
|
return errors.New("invalid domainId")
|
||||||
@@ -166,8 +166,8 @@ func (this *DNSDomainDAO) UpdateDomainRoutes(tx *dbs.Tx, domainId int64, routesJ
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找域名线路
|
// FindDomainRoutes 查找域名线路
|
||||||
func (this *DNSDomainDAO) FindDomainRoutes(tx *dbs.Tx, domainId int64) ([]*dnsclients.Route, error) {
|
func (this *DNSDomainDAO) FindDomainRoutes(tx *dbs.Tx, domainId int64) ([]*dnstypes.Route, error) {
|
||||||
routes, err := this.Query(tx).
|
routes, err := this.Query(tx).
|
||||||
Pk(domainId).
|
Pk(domainId).
|
||||||
Result("routes").
|
Result("routes").
|
||||||
@@ -178,7 +178,7 @@ func (this *DNSDomainDAO) FindDomainRoutes(tx *dbs.Tx, domainId int64) ([]*dnscl
|
|||||||
if len(routes) == 0 || routes == "null" {
|
if len(routes) == 0 || routes == "null" {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
result := []*dnsclients.Route{}
|
result := []*dnstypes.Route{}
|
||||||
err = json.Unmarshal([]byte(routes), &result)
|
err = json.Unmarshal([]byte(routes), &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -186,7 +186,7 @@ func (this *DNSDomainDAO) FindDomainRoutes(tx *dbs.Tx, domainId int64) ([]*dnscl
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找线路名称
|
// FindDomainRouteName 查找线路名称
|
||||||
func (this *DNSDomainDAO) FindDomainRouteName(tx *dbs.Tx, domainId int64, routeCode string) (string, error) {
|
func (this *DNSDomainDAO) FindDomainRouteName(tx *dbs.Tx, domainId int64, routeCode string) (string, error) {
|
||||||
routes, err := this.FindDomainRoutes(tx, domainId)
|
routes, err := this.FindDomainRoutes(tx, domainId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -200,7 +200,7 @@ func (this *DNSDomainDAO) FindDomainRouteName(tx *dbs.Tx, domainId int64, routeC
|
|||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断是否有域名可选
|
// ExistAvailableDomains 判断是否有域名可选
|
||||||
func (this *DNSDomainDAO) ExistAvailableDomains(tx *dbs.Tx) (bool, error) {
|
func (this *DNSDomainDAO) ExistAvailableDomains(tx *dbs.Tx) (bool, error) {
|
||||||
subQuery, err := SharedDNSProviderDAO.Query(tx).
|
subQuery, err := SharedDNSProviderDAO.Query(tx).
|
||||||
Where("state=1"). // 这里要使用非变量
|
Where("state=1"). // 这里要使用非变量
|
||||||
@@ -216,7 +216,7 @@ func (this *DNSDomainDAO) ExistAvailableDomains(tx *dbs.Tx) (bool, error) {
|
|||||||
Exist()
|
Exist()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查域名解析记录是否存在
|
// ExistDomainRecord 检查域名解析记录是否存在
|
||||||
func (this *DNSDomainDAO) ExistDomainRecord(tx *dbs.Tx, domainId int64, recordName string, recordType string, recordRoute string, recordValue string) (bool, error) {
|
func (this *DNSDomainDAO) ExistDomainRecord(tx *dbs.Tx, domainId int64, recordName string, recordType string, recordRoute string, recordValue string) (bool, error) {
|
||||||
query := maps.Map{
|
query := maps.Map{
|
||||||
"name": recordName,
|
"name": recordName,
|
||||||
|
|||||||
@@ -2,15 +2,15 @@ package dns
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients"
|
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients/dnstypes"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 获取所有的线路
|
// DecodeRoutes 获取所有的线路
|
||||||
func (this *DNSDomain) DecodeRoutes() ([]*dnsclients.Route, error) {
|
func (this *DNSDomain) DecodeRoutes() ([]*dnstypes.Route, error) {
|
||||||
if len(this.Routes) == 0 || this.Routes == "null" {
|
if len(this.Routes) == 0 || this.Routes == "null" {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
result := []*dnsclients.Route{}
|
result := []*dnstypes.Route{}
|
||||||
err := json.Unmarshal([]byte(this.Routes), &result)
|
err := json.Unmarshal([]byte(this.Routes), &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -18,7 +18,7 @@ func (this *DNSDomain) DecodeRoutes() ([]*dnsclients.Route, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否包含某个线路
|
// ContainsRouteCode 检查是否包含某个线路
|
||||||
func (this *DNSDomain) ContainsRouteCode(route string) (bool, error) {
|
func (this *DNSDomain) ContainsRouteCode(route string) (bool, error) {
|
||||||
routes, err := this.DecodeRoutes()
|
routes, err := this.DecodeRoutes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -32,13 +32,13 @@ func (this *DNSDomain) ContainsRouteCode(route string) (bool, error) {
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取所有的记录
|
// DecodeRecords 获取所有的记录
|
||||||
func (this *DNSDomain) DecodeRecords() ([]*dnsclients.Record, error) {
|
func (this *DNSDomain) DecodeRecords() ([]*dnstypes.Record, error) {
|
||||||
records := this.Records
|
records := this.Records
|
||||||
if len(records) == 0 || records == "null" {
|
if len(records) == 0 || records == "null" {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
result := []*dnsclients.Record{}
|
result := []*dnstypes.Record{}
|
||||||
err := json.Unmarshal([]byte(records), &result)
|
err := json.Unmarshal([]byte(records), &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
func TestDNSTaskDAO_CreateDNSTask(t *testing.T) {
|
func TestDNSTaskDAO_CreateDNSTask(t *testing.T) {
|
||||||
dbs.NotifyReady()
|
dbs.NotifyReady()
|
||||||
err := SharedDNSTaskDAO.CreateDNSTask(nil, 1, 2, 3, "taskType")
|
err := SharedDNSTaskDAO.CreateDNSTask(nil, 1, 2, 3, 0, "taskType")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/iwind/TeaGo/logs"
|
"github.com/iwind/TeaGo/logs"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -41,9 +42,9 @@ func NewHTTPAccessLogDAO() *HTTPAccessLogDAO {
|
|||||||
}).(*HTTPAccessLogDAO)
|
}).(*HTTPAccessLogDAO)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建访问日志
|
// CreateHTTPAccessLogs 创建访问日志
|
||||||
func (this *HTTPAccessLogDAO) CreateHTTPAccessLogs(tx *dbs.Tx, accessLogs []*pb.HTTPAccessLog) error {
|
func (this *HTTPAccessLogDAO) CreateHTTPAccessLogs(tx *dbs.Tx, accessLogs []*pb.HTTPAccessLog) error {
|
||||||
dao := randomAccessLogDAO()
|
dao := randomHTTPAccessLogDAO()
|
||||||
if dao == nil {
|
if dao == nil {
|
||||||
dao = &HTTPAccessLogDAOWrapper{
|
dao = &HTTPAccessLogDAOWrapper{
|
||||||
DAO: SharedHTTPAccessLogDAO,
|
DAO: SharedHTTPAccessLogDAO,
|
||||||
@@ -53,7 +54,7 @@ func (this *HTTPAccessLogDAO) CreateHTTPAccessLogs(tx *dbs.Tx, accessLogs []*pb.
|
|||||||
return this.CreateHTTPAccessLogsWithDAO(tx, dao, accessLogs)
|
return this.CreateHTTPAccessLogsWithDAO(tx, dao, accessLogs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用特定的DAO创建访问日志
|
// CreateHTTPAccessLogsWithDAO 使用特定的DAO创建访问日志
|
||||||
func (this *HTTPAccessLogDAO) CreateHTTPAccessLogsWithDAO(tx *dbs.Tx, daoWrapper *HTTPAccessLogDAOWrapper, accessLogs []*pb.HTTPAccessLog) error {
|
func (this *HTTPAccessLogDAO) CreateHTTPAccessLogsWithDAO(tx *dbs.Tx, daoWrapper *HTTPAccessLogDAOWrapper, accessLogs []*pb.HTTPAccessLog) error {
|
||||||
if daoWrapper == nil {
|
if daoWrapper == nil {
|
||||||
return errors.New("dao should not be nil")
|
return errors.New("dao should not be nil")
|
||||||
@@ -68,7 +69,7 @@ func (this *HTTPAccessLogDAO) CreateHTTPAccessLogsWithDAO(tx *dbs.Tx, daoWrapper
|
|||||||
|
|
||||||
for _, accessLog := range accessLogs {
|
for _, accessLog := range accessLogs {
|
||||||
day := timeutil.Format("Ymd", time.Unix(accessLog.Timestamp, 0))
|
day := timeutil.Format("Ymd", time.Unix(accessLog.Timestamp, 0))
|
||||||
table, err := findAccessLogTable(dao.Instance, day, false)
|
table, err := findHTTPAccessLogTable(dao.Instance, day, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -97,7 +98,7 @@ func (this *HTTPAccessLogDAO) CreateHTTPAccessLogsWithDAO(tx *dbs.Tx, daoWrapper
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
// 是否为 Error 1146: Table 'xxx.xxx' doesn't exist 如果是,则创建表之后重试
|
// 是否为 Error 1146: Table 'xxx.xxx' doesn't exist 如果是,则创建表之后重试
|
||||||
if strings.Contains(err.Error(), "1146") {
|
if strings.Contains(err.Error(), "1146") {
|
||||||
table, err = findAccessLogTable(dao.Instance, day, true)
|
table, err = findHTTPAccessLogTable(dao.Instance, day, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -115,8 +116,8 @@ func (this *HTTPAccessLogDAO) CreateHTTPAccessLogsWithDAO(tx *dbs.Tx, daoWrapper
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 读取往前的 单页访问日志
|
// ListAccessLogs 读取往前的 单页访问日志
|
||||||
func (this *HTTPAccessLogDAO) ListAccessLogs(tx *dbs.Tx, lastRequestId string, size int64, day string, serverId int64, reverse bool, hasError bool, firewallPolicyId int64, firewallRuleGroupId int64, firewallRuleSetId int64, hasFirewallPolicy bool, userId int64) (result []*HTTPAccessLog, nextLastRequestId string, hasMore bool, err error) {
|
func (this *HTTPAccessLogDAO) ListAccessLogs(tx *dbs.Tx, lastRequestId string, size int64, day string, serverId int64, reverse bool, hasError bool, firewallPolicyId int64, firewallRuleGroupId int64, firewallRuleSetId int64, hasFirewallPolicy bool, userId int64, keyword string) (result []*HTTPAccessLog, nextLastRequestId string, hasMore bool, err error) {
|
||||||
if len(day) != 8 {
|
if len(day) != 8 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -126,18 +127,18 @@ func (this *HTTPAccessLogDAO) ListAccessLogs(tx *dbs.Tx, lastRequestId string, s
|
|||||||
size = 1000
|
size = 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
result, nextLastRequestId, err = this.listAccessLogs(tx, lastRequestId, size, day, serverId, reverse, hasError, firewallPolicyId, firewallRuleGroupId, firewallRuleSetId, hasFirewallPolicy, userId)
|
result, nextLastRequestId, err = this.listAccessLogs(tx, lastRequestId, size, day, serverId, reverse, hasError, firewallPolicyId, firewallRuleGroupId, firewallRuleSetId, hasFirewallPolicy, userId, keyword)
|
||||||
if err != nil || int64(len(result)) < size {
|
if err != nil || int64(len(result)) < size {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
moreResult, _, _ := this.listAccessLogs(tx, nextLastRequestId, 1, day, serverId, reverse, hasError, firewallPolicyId, firewallRuleGroupId, firewallRuleSetId, hasFirewallPolicy, userId)
|
moreResult, _, _ := this.listAccessLogs(tx, nextLastRequestId, 1, day, serverId, reverse, hasError, firewallPolicyId, firewallRuleGroupId, firewallRuleSetId, hasFirewallPolicy, userId, keyword)
|
||||||
hasMore = len(moreResult) > 0
|
hasMore = len(moreResult) > 0
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 读取往前的单页访问日志
|
// 读取往前的单页访问日志
|
||||||
func (this *HTTPAccessLogDAO) listAccessLogs(tx *dbs.Tx, lastRequestId string, size int64, day string, serverId int64, reverse bool, hasError bool, firewallPolicyId int64, firewallRuleGroupId int64, firewallRuleSetId int64, hasFirewallPolicy bool, userId int64) (result []*HTTPAccessLog, nextLastRequestId string, err error) {
|
func (this *HTTPAccessLogDAO) listAccessLogs(tx *dbs.Tx, lastRequestId string, size int64, day string, serverId int64, reverse bool, hasError bool, firewallPolicyId int64, firewallRuleGroupId int64, firewallRuleSetId int64, hasFirewallPolicy bool, userId int64, keyword string) (result []*HTTPAccessLog, nextLastRequestId string, err error) {
|
||||||
if size <= 0 {
|
if size <= 0 {
|
||||||
return nil, lastRequestId, nil
|
return nil, lastRequestId, nil
|
||||||
}
|
}
|
||||||
@@ -155,7 +156,7 @@ func (this *HTTPAccessLogDAO) listAccessLogs(tx *dbs.Tx, lastRequestId string, s
|
|||||||
|
|
||||||
accessLogLocker.RLock()
|
accessLogLocker.RLock()
|
||||||
daoList := []*HTTPAccessLogDAOWrapper{}
|
daoList := []*HTTPAccessLogDAOWrapper{}
|
||||||
for _, daoWrapper := range accessLogDAOMapping {
|
for _, daoWrapper := range httpAccessLogDAOMapping {
|
||||||
daoList = append(daoList, daoWrapper)
|
daoList = append(daoList, daoWrapper)
|
||||||
}
|
}
|
||||||
accessLogLocker.RUnlock()
|
accessLogLocker.RUnlock()
|
||||||
@@ -178,7 +179,7 @@ func (this *HTTPAccessLogDAO) listAccessLogs(tx *dbs.Tx, lastRequestId string, s
|
|||||||
|
|
||||||
dao := daoWrapper.DAO
|
dao := daoWrapper.DAO
|
||||||
|
|
||||||
tableName, exists, err := findAccessLogTableName(dao.Instance, day)
|
tableName, exists, err := findHTTPAccessLogTableName(dao.Instance, day)
|
||||||
if !exists {
|
if !exists {
|
||||||
// 表格不存在则跳过
|
// 表格不存在则跳过
|
||||||
return
|
return
|
||||||
@@ -213,6 +214,46 @@ func (this *HTTPAccessLogDAO) listAccessLogs(tx *dbs.Tx, lastRequestId string, s
|
|||||||
query.Where("firewallPolicyId>0")
|
query.Where("firewallPolicyId>0")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// keyword
|
||||||
|
if len(keyword) > 0 {
|
||||||
|
useOriginKeyword := false
|
||||||
|
|
||||||
|
where := "JSON_EXTRACT(content, '$.remoteAddr') LIKE :keyword OR JSON_EXTRACT(content, '$.requestURI') LIKE :keyword OR JSON_EXTRACT(content, '$.host') LIKE :keyword"
|
||||||
|
|
||||||
|
// 请求方法
|
||||||
|
if keyword == http.MethodGet ||
|
||||||
|
keyword == http.MethodPost ||
|
||||||
|
keyword == http.MethodHead ||
|
||||||
|
keyword == http.MethodConnect ||
|
||||||
|
keyword == http.MethodPut ||
|
||||||
|
keyword == http.MethodTrace ||
|
||||||
|
keyword == http.MethodOptions ||
|
||||||
|
keyword == http.MethodDelete ||
|
||||||
|
keyword == http.MethodPatch {
|
||||||
|
where += " OR JSON_EXTRACT(content, '$.requestMethod')=:originKeyword"
|
||||||
|
useOriginKeyword = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 响应状态码
|
||||||
|
if regexp.MustCompile(`^\d{3}$`).MatchString(keyword) {
|
||||||
|
where += " OR JSON_EXTRACT(content, '$.status')=:intKeyword"
|
||||||
|
query.Param("intKeyword", types.Int(keyword))
|
||||||
|
}
|
||||||
|
|
||||||
|
if regexp.MustCompile(`^\d{3}-\d{3}$`).MatchString(keyword) {
|
||||||
|
pieces := strings.Split(keyword, "-")
|
||||||
|
where += " OR JSON_EXTRACT(content, '$.status') BETWEEN :intKeyword1 AND :intKeyword2"
|
||||||
|
query.Param("intKeyword1", types.Int(pieces[0]))
|
||||||
|
query.Param("intKeyword2", types.Int(pieces[1]))
|
||||||
|
}
|
||||||
|
|
||||||
|
query.Where("("+where+")").
|
||||||
|
Param("keyword", "%"+keyword+"%")
|
||||||
|
if useOriginKeyword {
|
||||||
|
query.Param("originKeyword", keyword)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// offset
|
// offset
|
||||||
if len(lastRequestId) > 0 {
|
if len(lastRequestId) > 0 {
|
||||||
if !reverse {
|
if !reverse {
|
||||||
@@ -278,7 +319,7 @@ func (this *HTTPAccessLogDAO) listAccessLogs(tx *dbs.Tx, lastRequestId string, s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据请求ID获取访问日志
|
// FindAccessLogWithRequestId 根据请求ID获取访问日志
|
||||||
func (this *HTTPAccessLogDAO) FindAccessLogWithRequestId(tx *dbs.Tx, requestId string) (*HTTPAccessLog, error) {
|
func (this *HTTPAccessLogDAO) FindAccessLogWithRequestId(tx *dbs.Tx, requestId string) (*HTTPAccessLog, error) {
|
||||||
if !regexp.MustCompile(`^\d{30,}`).MatchString(requestId) {
|
if !regexp.MustCompile(`^\d{30,}`).MatchString(requestId) {
|
||||||
return nil, errors.New("invalid requestId")
|
return nil, errors.New("invalid requestId")
|
||||||
@@ -286,7 +327,7 @@ func (this *HTTPAccessLogDAO) FindAccessLogWithRequestId(tx *dbs.Tx, requestId s
|
|||||||
|
|
||||||
accessLogLocker.RLock()
|
accessLogLocker.RLock()
|
||||||
daoList := []*HTTPAccessLogDAOWrapper{}
|
daoList := []*HTTPAccessLogDAOWrapper{}
|
||||||
for _, daoWrapper := range accessLogDAOMapping {
|
for _, daoWrapper := range httpAccessLogDAOMapping {
|
||||||
daoList = append(daoList, daoWrapper)
|
daoList = append(daoList, daoWrapper)
|
||||||
}
|
}
|
||||||
accessLogLocker.RUnlock()
|
accessLogLocker.RUnlock()
|
||||||
@@ -309,7 +350,7 @@ func (this *HTTPAccessLogDAO) FindAccessLogWithRequestId(tx *dbs.Tx, requestId s
|
|||||||
|
|
||||||
dao := daoWrapper.DAO
|
dao := daoWrapper.DAO
|
||||||
|
|
||||||
tableName, exists, err := findAccessLogTableName(dao.Instance, day)
|
tableName, exists, err := findHTTPAccessLogTableName(dao.Instance, day)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logs.Println("[DB_NODE]" + err.Error())
|
logs.Println("[DB_NODE]" + err.Error())
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ func TestCreateHTTPAccessLogs(t *testing.T) {
|
|||||||
Status: 200,
|
Status: 200,
|
||||||
Timestamp: time.Now().Unix(),
|
Timestamp: time.Now().Unix(),
|
||||||
}
|
}
|
||||||
dao := randomAccessLogDAO()
|
dao := randomHTTPAccessLogDAO()
|
||||||
t.Log("dao:", dao)
|
t.Log("dao:", dao)
|
||||||
err = SharedHTTPAccessLogDAO.CreateHTTPAccessLogsWithDAO(tx, dao, []*pb.HTTPAccessLog{accessLog})
|
err = SharedHTTPAccessLogDAO.CreateHTTPAccessLogsWithDAO(tx, dao, []*pb.HTTPAccessLog{accessLog})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -41,7 +41,7 @@ func TestHTTPAccessLogDAO_ListAccessLogs(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
accessLogs, requestId, hasMore, err := SharedHTTPAccessLogDAO.ListAccessLogs(tx, "", 10, timeutil.Format("Ymd"), 0, false, false, 0, 0, 0, false, 0)
|
accessLogs, requestId, hasMore, err := SharedHTTPAccessLogDAO.ListAccessLogs(tx, "", 10, timeutil.Format("Ymd"), 0, false, false, 0, 0, 0, false, 0, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -68,7 +68,7 @@ func TestHTTPAccessLogDAO_ListAccessLogs_Page(t *testing.T) {
|
|||||||
times := 0 // 防止循环次数太多
|
times := 0 // 防止循环次数太多
|
||||||
for {
|
for {
|
||||||
before := time.Now()
|
before := time.Now()
|
||||||
accessLogs, requestId, hasMore, err := SharedHTTPAccessLogDAO.ListAccessLogs(tx, lastRequestId, 2, timeutil.Format("Ymd"), 0, false, false, 0, 0, 0, false, 0)
|
accessLogs, requestId, hasMore, err := SharedHTTPAccessLogDAO.ListAccessLogs(tx, lastRequestId, 2, timeutil.Format("Ymd"), 0, false, false, 0, 0, 0, false, 0, "")
|
||||||
cost := time.Since(before).Seconds()
|
cost := time.Since(before).Seconds()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -99,7 +99,7 @@ func TestHTTPAccessLogDAO_ListAccessLogs_Reverse(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
before := time.Now()
|
before := time.Now()
|
||||||
accessLogs, requestId, hasMore, err := SharedHTTPAccessLogDAO.ListAccessLogs(tx, "16023261176446590001000000000000003500000004", 2, timeutil.Format("Ymd"), 0, true, false, 0, 0, 0, false, 0)
|
accessLogs, requestId, hasMore, err := SharedHTTPAccessLogDAO.ListAccessLogs(tx, "16023261176446590001000000000000003500000004", 2, timeutil.Format("Ymd"), 0, true, false, 0, 0, 0, false, 0, "")
|
||||||
cost := time.Since(before).Seconds()
|
cost := time.Since(before).Seconds()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -124,7 +124,7 @@ func TestHTTPAccessLogDAO_ListAccessLogs_Page_NotExists(t *testing.T) {
|
|||||||
times := 0 // 防止循环次数太多
|
times := 0 // 防止循环次数太多
|
||||||
for {
|
for {
|
||||||
before := time.Now()
|
before := time.Now()
|
||||||
accessLogs, requestId, hasMore, err := SharedHTTPAccessLogDAO.ListAccessLogs(tx, lastRequestId, 2, timeutil.Format("Ymd", time.Now().AddDate(0, 0, 1)), 0, false, false, 0, 0, 0, false, 0)
|
accessLogs, requestId, hasMore, err := SharedHTTPAccessLogDAO.ListAccessLogs(tx, lastRequestId, 2, timeutil.Format("Ymd", time.Now().AddDate(0, 0, 1)), 0, false, false, 0, 0, 0, false, 0, "")
|
||||||
cost := time.Since(before).Seconds()
|
cost := time.Since(before).Seconds()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 转换成PB对象
|
// ToPB 转换成PB对象
|
||||||
func (this *HTTPAccessLog) ToPB() (*pb.HTTPAccessLog, error) {
|
func (this *HTTPAccessLog) ToPB() (*pb.HTTPAccessLog, error) {
|
||||||
p := &pb.HTTPAccessLog{}
|
p := &pb.HTTPAccessLog{}
|
||||||
err := json.Unmarshal([]byte(this.Content), p)
|
err := json.Unmarshal([]byte(this.Content), p)
|
||||||
|
|||||||
135
internal/db/models/http_auth_policy_dao.go
Normal file
135
internal/db/models/http_auth_policy_dao.go
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
"github.com/iwind/TeaGo/Tea"
|
||||||
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
HTTPAuthPolicyStateEnabled = 1 // 已启用
|
||||||
|
HTTPAuthPolicyStateDisabled = 0 // 已禁用
|
||||||
|
)
|
||||||
|
|
||||||
|
type HTTPAuthPolicyDAO dbs.DAO
|
||||||
|
|
||||||
|
func NewHTTPAuthPolicyDAO() *HTTPAuthPolicyDAO {
|
||||||
|
return dbs.NewDAO(&HTTPAuthPolicyDAO{
|
||||||
|
DAOObject: dbs.DAOObject{
|
||||||
|
DB: Tea.Env,
|
||||||
|
Table: "edgeHTTPAuthPolicies",
|
||||||
|
Model: new(HTTPAuthPolicy),
|
||||||
|
PkName: "id",
|
||||||
|
},
|
||||||
|
}).(*HTTPAuthPolicyDAO)
|
||||||
|
}
|
||||||
|
|
||||||
|
var SharedHTTPAuthPolicyDAO *HTTPAuthPolicyDAO
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
dbs.OnReady(func() {
|
||||||
|
SharedHTTPAuthPolicyDAO = NewHTTPAuthPolicyDAO()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// EnableHTTPAuthPolicy 启用条目
|
||||||
|
func (this *HTTPAuthPolicyDAO) EnableHTTPAuthPolicy(tx *dbs.Tx, id int64) error {
|
||||||
|
_, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Set("state", HTTPAuthPolicyStateEnabled).
|
||||||
|
Update()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DisableHTTPAuthPolicy 禁用条目
|
||||||
|
func (this *HTTPAuthPolicyDAO) DisableHTTPAuthPolicy(tx *dbs.Tx, id int64) error {
|
||||||
|
_, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Set("state", HTTPAuthPolicyStateDisabled).
|
||||||
|
Update()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindEnabledHTTPAuthPolicy 查找启用中的条目
|
||||||
|
func (this *HTTPAuthPolicyDAO) FindEnabledHTTPAuthPolicy(tx *dbs.Tx, id int64) (*HTTPAuthPolicy, error) {
|
||||||
|
result, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Attr("state", HTTPAuthPolicyStateEnabled).
|
||||||
|
Find()
|
||||||
|
if result == nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result.(*HTTPAuthPolicy), err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateHTTPAuthPolicy 创建策略
|
||||||
|
func (this *HTTPAuthPolicyDAO) CreateHTTPAuthPolicy(tx *dbs.Tx, name string, methodType string, paramsJSON []byte) (int64, error) {
|
||||||
|
op := NewHTTPAuthPolicyOperator()
|
||||||
|
op.Name = name
|
||||||
|
op.Type = methodType
|
||||||
|
op.Params = paramsJSON
|
||||||
|
op.IsOn = true
|
||||||
|
op.State = HTTPAuthPolicyStateEnabled
|
||||||
|
return this.SaveInt64(tx, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateHTTPAuthPolicy 修改策略
|
||||||
|
func (this *HTTPAuthPolicyDAO) UpdateHTTPAuthPolicy(tx *dbs.Tx, policyId int64, name string, paramsJSON []byte, isOn bool) error {
|
||||||
|
if policyId <= 0 {
|
||||||
|
return errors.New("invalid policyId")
|
||||||
|
}
|
||||||
|
op := NewHTTPAuthPolicyOperator()
|
||||||
|
op.Id = policyId
|
||||||
|
op.Name = name
|
||||||
|
op.Params = paramsJSON
|
||||||
|
op.IsOn = isOn
|
||||||
|
err := this.Save(tx, op)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return this.NotifyUpdate(tx, policyId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ComposePolicyConfig 组合配置
|
||||||
|
func (this *HTTPAuthPolicyDAO) ComposePolicyConfig(tx *dbs.Tx, policyId int64) (*serverconfigs.HTTPAuthPolicy, error) {
|
||||||
|
policy, err := this.FindEnabledHTTPAuthPolicy(tx, policyId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if policy == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
var config = &serverconfigs.HTTPAuthPolicy{
|
||||||
|
Id: int64(policy.Id),
|
||||||
|
Name: policy.Name,
|
||||||
|
IsOn: policy.IsOn == 1,
|
||||||
|
Type: policy.Type,
|
||||||
|
}
|
||||||
|
|
||||||
|
var params map[string]interface{}
|
||||||
|
if IsNotNull(policy.Params) {
|
||||||
|
err = json.Unmarshal([]byte(policy.Params), ¶ms)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.Params = params
|
||||||
|
}
|
||||||
|
config.Params = params
|
||||||
|
|
||||||
|
return config, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyUpdate 通知更改
|
||||||
|
func (this *HTTPAuthPolicyDAO) NotifyUpdate(tx *dbs.Tx, policyId int64) error {
|
||||||
|
webId, err := SharedHTTPWebDAO.FindEnabledWebIdWithHTTPAuthPolicyId(tx, policyId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if webId > 0 {
|
||||||
|
return SharedHTTPWebDAO.NotifyUpdate(tx, webId)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
6
internal/db/models/http_auth_policy_dao_test.go
Normal file
6
internal/db/models/http_auth_policy_dao_test.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
|
)
|
||||||
28
internal/db/models/http_auth_policy_model.go
Normal file
28
internal/db/models/http_auth_policy_model.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
// HTTPAuthPolicy HTTP认证策略
|
||||||
|
type HTTPAuthPolicy struct {
|
||||||
|
Id uint64 `field:"id"` // ID
|
||||||
|
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||||
|
UserId uint32 `field:"userId"` // 用户ID
|
||||||
|
IsOn uint8 `field:"isOn"` // 是否启用
|
||||||
|
Name string `field:"name"` // 名称
|
||||||
|
Type string `field:"type"` // 类型
|
||||||
|
Params string `field:"params"` // 参数
|
||||||
|
State uint8 `field:"state"` // 状态
|
||||||
|
}
|
||||||
|
|
||||||
|
type HTTPAuthPolicyOperator struct {
|
||||||
|
Id interface{} // ID
|
||||||
|
AdminId interface{} // 管理员ID
|
||||||
|
UserId interface{} // 用户ID
|
||||||
|
IsOn interface{} // 是否启用
|
||||||
|
Name interface{} // 名称
|
||||||
|
Type interface{} // 类型
|
||||||
|
Params interface{} // 参数
|
||||||
|
State interface{} // 状态
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHTTPAuthPolicyOperator() *HTTPAuthPolicyOperator {
|
||||||
|
return &HTTPAuthPolicyOperator{}
|
||||||
|
}
|
||||||
1
internal/db/models/http_auth_policy_model_ext.go
Normal file
1
internal/db/models/http_auth_policy_model_ext.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package models
|
||||||
@@ -37,12 +37,12 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化
|
// Init 初始化
|
||||||
func (this *HTTPCachePolicyDAO) Init() {
|
func (this *HTTPCachePolicyDAO) Init() {
|
||||||
_ = this.DAOObject.Init()
|
_ = this.DAOObject.Init()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启用条目
|
// EnableHTTPCachePolicy 启用条目
|
||||||
func (this *HTTPCachePolicyDAO) EnableHTTPCachePolicy(tx *dbs.Tx, id int64) error {
|
func (this *HTTPCachePolicyDAO) EnableHTTPCachePolicy(tx *dbs.Tx, id int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -51,7 +51,7 @@ func (this *HTTPCachePolicyDAO) EnableHTTPCachePolicy(tx *dbs.Tx, id int64) erro
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 禁用条目
|
// DisableHTTPCachePolicy 禁用条目
|
||||||
func (this *HTTPCachePolicyDAO) DisableHTTPCachePolicy(tx *dbs.Tx, policyId int64) error {
|
func (this *HTTPCachePolicyDAO) DisableHTTPCachePolicy(tx *dbs.Tx, policyId int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(policyId).
|
Pk(policyId).
|
||||||
@@ -63,7 +63,7 @@ func (this *HTTPCachePolicyDAO) DisableHTTPCachePolicy(tx *dbs.Tx, policyId int6
|
|||||||
return this.NotifyUpdate(tx, policyId)
|
return this.NotifyUpdate(tx, policyId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找启用中的条目
|
// FindEnabledHTTPCachePolicy 查找启用中的条目
|
||||||
func (this *HTTPCachePolicyDAO) FindEnabledHTTPCachePolicy(tx *dbs.Tx, id int64) (*HTTPCachePolicy, error) {
|
func (this *HTTPCachePolicyDAO) FindEnabledHTTPCachePolicy(tx *dbs.Tx, id int64) (*HTTPCachePolicy, error) {
|
||||||
result, err := this.Query(tx).
|
result, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -75,7 +75,7 @@ func (this *HTTPCachePolicyDAO) FindEnabledHTTPCachePolicy(tx *dbs.Tx, id int64)
|
|||||||
return result.(*HTTPCachePolicy), err
|
return result.(*HTTPCachePolicy), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据主键查找名称
|
// FindHTTPCachePolicyName 根据主键查找名称
|
||||||
func (this *HTTPCachePolicyDAO) FindHTTPCachePolicyName(tx *dbs.Tx, id int64) (string, error) {
|
func (this *HTTPCachePolicyDAO) FindHTTPCachePolicyName(tx *dbs.Tx, id int64) (string, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -83,7 +83,7 @@ func (this *HTTPCachePolicyDAO) FindHTTPCachePolicyName(tx *dbs.Tx, id int64) (s
|
|||||||
FindStringCol("")
|
FindStringCol("")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找所有可用的缓存策略
|
// FindAllEnabledCachePolicies 查找所有可用的缓存策略
|
||||||
func (this *HTTPCachePolicyDAO) FindAllEnabledCachePolicies(tx *dbs.Tx) (result []*HTTPCachePolicy, err error) {
|
func (this *HTTPCachePolicyDAO) FindAllEnabledCachePolicies(tx *dbs.Tx) (result []*HTTPCachePolicy, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(HTTPCachePolicyStateEnabled).
|
State(HTTPCachePolicyStateEnabled).
|
||||||
@@ -93,7 +93,7 @@ func (this *HTTPCachePolicyDAO) FindAllEnabledCachePolicies(tx *dbs.Tx) (result
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建缓存策略
|
// CreateCachePolicy 创建缓存策略
|
||||||
func (this *HTTPCachePolicyDAO) CreateCachePolicy(tx *dbs.Tx, isOn bool, name string, description string, capacityJSON []byte, maxKeys int64, maxSizeJSON []byte, storageType string, storageOptionsJSON []byte) (int64, error) {
|
func (this *HTTPCachePolicyDAO) CreateCachePolicy(tx *dbs.Tx, isOn bool, name string, description string, capacityJSON []byte, maxKeys int64, maxSizeJSON []byte, storageType string, storageOptionsJSON []byte) (int64, error) {
|
||||||
op := NewHTTPCachePolicyOperator()
|
op := NewHTTPCachePolicyOperator()
|
||||||
op.State = HTTPCachePolicyStateEnabled
|
op.State = HTTPCachePolicyStateEnabled
|
||||||
@@ -111,14 +111,51 @@ func (this *HTTPCachePolicyDAO) CreateCachePolicy(tx *dbs.Tx, isOn bool, name st
|
|||||||
if len(storageOptionsJSON) > 0 {
|
if len(storageOptionsJSON) > 0 {
|
||||||
op.Options = storageOptionsJSON
|
op.Options = storageOptionsJSON
|
||||||
}
|
}
|
||||||
err := this.Save(tx, op)
|
|
||||||
|
// 默认的缓存条件
|
||||||
|
cacheRef := &serverconfigs.HTTPCacheRef{
|
||||||
|
IsOn: true,
|
||||||
|
Key: "${scheme}://${host}${requestURI}",
|
||||||
|
Life: &shared.TimeDuration{Count: 2, Unit: shared.TimeDurationUnitHour},
|
||||||
|
Status: []int{200},
|
||||||
|
MaxSize: &shared.SizeCapacity{Count: 32, Unit: shared.SizeCapacityUnitMB},
|
||||||
|
SkipResponseSetCookie: true,
|
||||||
|
AllowChunkedEncoding: true,
|
||||||
|
Conds: &shared.HTTPRequestCondsConfig{
|
||||||
|
IsOn: true,
|
||||||
|
Connector: "or",
|
||||||
|
Groups: []*shared.HTTPRequestCondGroup{
|
||||||
|
{
|
||||||
|
IsOn: true,
|
||||||
|
Connector: "or",
|
||||||
|
Conds: []*shared.HTTPRequestCond{
|
||||||
|
{
|
||||||
|
Type: "url-extension",
|
||||||
|
IsRequest: true,
|
||||||
|
Param: "${requestPathExtension}",
|
||||||
|
Operator: shared.RequestCondOperatorIn,
|
||||||
|
Value: `[".html", ".js", ".css", ".gif", ".png", ".bmp", ".jpeg", ".jpg", ".webp", ".ico", ".pdf", ".ttf", ".eot", ".tiff", ".svg", ".svgz", ".eps", ".woff", ".otf", ".woff2", ".tif", ".csv", ".xls", ".xlsx", ".doc", ".docx", ".ppt", ".pptx", ".wav", ".mp3", ".mp4", ".ogg", ".mid", ".midi"]`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Description: "初始化规则",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
refsJSON, err := json.Marshal([]*serverconfigs.HTTPCacheRef{cacheRef})
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
op.Refs = refsJSON
|
||||||
|
|
||||||
|
err = this.Save(tx, op)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
return types.Int64(op.Id), nil
|
return types.Int64(op.Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改缓存策略
|
// UpdateCachePolicy 修改缓存策略
|
||||||
func (this *HTTPCachePolicyDAO) UpdateCachePolicy(tx *dbs.Tx, policyId int64, isOn bool, name string, description string, capacityJSON []byte, maxKeys int64, maxSizeJSON []byte, storageType string, storageOptionsJSON []byte) error {
|
func (this *HTTPCachePolicyDAO) UpdateCachePolicy(tx *dbs.Tx, policyId int64, isOn bool, name string, description string, capacityJSON []byte, maxKeys int64, maxSizeJSON []byte, storageType string, storageOptionsJSON []byte) error {
|
||||||
if policyId <= 0 {
|
if policyId <= 0 {
|
||||||
return errors.New("invalid policyId")
|
return errors.New("invalid policyId")
|
||||||
@@ -147,7 +184,7 @@ func (this *HTTPCachePolicyDAO) UpdateCachePolicy(tx *dbs.Tx, policyId int64, is
|
|||||||
return this.NotifyUpdate(tx, policyId)
|
return this.NotifyUpdate(tx, policyId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 组合配置
|
// ComposeCachePolicy 组合配置
|
||||||
func (this *HTTPCachePolicyDAO) ComposeCachePolicy(tx *dbs.Tx, policyId int64) (*serverconfigs.HTTPCachePolicy, error) {
|
func (this *HTTPCachePolicyDAO) ComposeCachePolicy(tx *dbs.Tx, policyId int64) (*serverconfigs.HTTPCachePolicy, error) {
|
||||||
policy, err := this.FindEnabledHTTPCachePolicy(tx, policyId)
|
policy, err := this.FindEnabledHTTPCachePolicy(tx, policyId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -196,20 +233,39 @@ func (this *HTTPCachePolicyDAO) ComposeCachePolicy(tx *dbs.Tx, policyId int64) (
|
|||||||
config.Options = m
|
config.Options = m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// refs
|
||||||
|
if IsNotNull(policy.Refs) {
|
||||||
|
refs := []*serverconfigs.HTTPCacheRef{}
|
||||||
|
err = json.Unmarshal([]byte(policy.Refs), &refs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.CacheRefs = refs
|
||||||
|
}
|
||||||
|
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算可用缓存策略数量
|
// CountAllEnabledHTTPCachePolicies 计算可用缓存策略数量
|
||||||
func (this *HTTPCachePolicyDAO) CountAllEnabledHTTPCachePolicies(tx *dbs.Tx) (int64, error) {
|
func (this *HTTPCachePolicyDAO) CountAllEnabledHTTPCachePolicies(tx *dbs.Tx, keyword string) (int64, error) {
|
||||||
return this.Query(tx).
|
query := this.Query(tx).
|
||||||
State(HTTPCachePolicyStateEnabled).
|
State(HTTPCachePolicyStateEnabled)
|
||||||
Count()
|
if len(keyword) > 0 {
|
||||||
|
query.Where("(name LIKE :keyword)").
|
||||||
|
Param("keyword", "%"+keyword+"%")
|
||||||
|
}
|
||||||
|
return query.Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出单页的缓存策略
|
// ListEnabledHTTPCachePolicies 列出单页的缓存策略
|
||||||
func (this *HTTPCachePolicyDAO) ListEnabledHTTPCachePolicies(tx *dbs.Tx, offset int64, size int64) ([]*serverconfigs.HTTPCachePolicy, error) {
|
func (this *HTTPCachePolicyDAO) ListEnabledHTTPCachePolicies(tx *dbs.Tx, keyword string, offset int64, size int64) ([]*serverconfigs.HTTPCachePolicy, error) {
|
||||||
ones, err := this.Query(tx).
|
query := this.Query(tx).
|
||||||
State(HTTPCachePolicyStateEnabled).
|
State(HTTPCachePolicyStateEnabled)
|
||||||
|
if len(keyword) > 0 {
|
||||||
|
query.Where("(name LIKE :keyword)").
|
||||||
|
Param("keyword", "%"+keyword+"%")
|
||||||
|
}
|
||||||
|
ones, err := query.
|
||||||
ResultPk().
|
ResultPk().
|
||||||
Offset(offset).
|
Offset(offset).
|
||||||
Limit(size).
|
Limit(size).
|
||||||
@@ -237,7 +293,22 @@ func (this *HTTPCachePolicyDAO) ListEnabledHTTPCachePolicies(tx *dbs.Tx, offset
|
|||||||
return cachePolicies, nil
|
return cachePolicies, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通知更新
|
// UpdatePolicyRefs 设置默认的缓存条件
|
||||||
|
func (this *HTTPCachePolicyDAO) UpdatePolicyRefs(tx *dbs.Tx, policyId int64, refsJSON []byte) error {
|
||||||
|
if len(refsJSON) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
err := this.Query(tx).
|
||||||
|
Pk(policyId).
|
||||||
|
Set("refs", refsJSON).
|
||||||
|
UpdateQuickly()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return this.NotifyUpdate(tx, policyId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyUpdate 通知更新
|
||||||
func (this *HTTPCachePolicyDAO) NotifyUpdate(tx *dbs.Tx, policyId int64) error {
|
func (this *HTTPCachePolicyDAO) NotifyUpdate(tx *dbs.Tx, policyId int64) error {
|
||||||
webIds, err := SharedHTTPWebDAO.FindAllWebIdsWithCachePolicyId(tx, policyId)
|
webIds, err := SharedHTTPWebDAO.FindAllWebIdsWithCachePolicyId(tx, policyId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
// HTTP缓存策略
|
// HTTPCachePolicy HTTP缓存策略
|
||||||
type HTTPCachePolicy struct {
|
type HTTPCachePolicy struct {
|
||||||
Id uint32 `field:"id"` // ID
|
Id uint32 `field:"id"` // ID
|
||||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||||
@@ -16,6 +16,7 @@ type HTTPCachePolicy struct {
|
|||||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||||
State uint8 `field:"state"` // 状态
|
State uint8 `field:"state"` // 状态
|
||||||
Description string `field:"description"` // 描述
|
Description string `field:"description"` // 描述
|
||||||
|
Refs string `field:"refs"` // 默认的缓存设置
|
||||||
}
|
}
|
||||||
|
|
||||||
type HTTPCachePolicyOperator struct {
|
type HTTPCachePolicyOperator struct {
|
||||||
@@ -33,6 +34,7 @@ type HTTPCachePolicyOperator struct {
|
|||||||
CreatedAt interface{} // 创建时间
|
CreatedAt interface{} // 创建时间
|
||||||
State interface{} // 状态
|
State interface{} // 状态
|
||||||
Description interface{} // 描述
|
Description interface{} // 描述
|
||||||
|
Refs interface{} // 默认的缓存设置
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHTTPCachePolicyOperator() *HTTPCachePolicyOperator {
|
func NewHTTPCachePolicyOperator() *HTTPCachePolicyOperator {
|
||||||
|
|||||||
201
internal/db/models/http_fastcgi_dao.go
Normal file
201
internal/db/models/http_fastcgi_dao.go
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
"github.com/iwind/TeaGo/Tea"
|
||||||
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
"github.com/iwind/TeaGo/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
HTTPFastcgiStateEnabled = 1 // 已启用
|
||||||
|
HTTPFastcgiStateDisabled = 0 // 已禁用
|
||||||
|
)
|
||||||
|
|
||||||
|
type HTTPFastcgiDAO dbs.DAO
|
||||||
|
|
||||||
|
func NewHTTPFastcgiDAO() *HTTPFastcgiDAO {
|
||||||
|
return dbs.NewDAO(&HTTPFastcgiDAO{
|
||||||
|
DAOObject: dbs.DAOObject{
|
||||||
|
DB: Tea.Env,
|
||||||
|
Table: "edgeHTTPFastcgis",
|
||||||
|
Model: new(HTTPFastcgi),
|
||||||
|
PkName: "id",
|
||||||
|
},
|
||||||
|
}).(*HTTPFastcgiDAO)
|
||||||
|
}
|
||||||
|
|
||||||
|
var SharedHTTPFastcgiDAO *HTTPFastcgiDAO
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
dbs.OnReady(func() {
|
||||||
|
SharedHTTPFastcgiDAO = NewHTTPFastcgiDAO()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// EnableHTTPFastcgi 启用条目
|
||||||
|
func (this *HTTPFastcgiDAO) EnableHTTPFastcgi(tx *dbs.Tx, id int64) error {
|
||||||
|
_, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Set("state", HTTPFastcgiStateEnabled).
|
||||||
|
Update()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DisableHTTPFastcgi 禁用条目
|
||||||
|
func (this *HTTPFastcgiDAO) DisableHTTPFastcgi(tx *dbs.Tx, id int64) error {
|
||||||
|
_, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Set("state", HTTPFastcgiStateDisabled).
|
||||||
|
Update()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindEnabledHTTPFastcgi 查找启用中的条目
|
||||||
|
func (this *HTTPFastcgiDAO) FindEnabledHTTPFastcgi(tx *dbs.Tx, id int64) (*HTTPFastcgi, error) {
|
||||||
|
result, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Attr("state", HTTPFastcgiStateEnabled).
|
||||||
|
Find()
|
||||||
|
if result == nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result.(*HTTPFastcgi), err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ComposeFastcgiConfig 组合配置
|
||||||
|
func (this *HTTPFastcgiDAO) ComposeFastcgiConfig(tx *dbs.Tx, fastcgiId int64) (*serverconfigs.HTTPFastcgiConfig, error) {
|
||||||
|
if fastcgiId <= 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
fastcgi, err := this.FindEnabledHTTPFastcgi(tx, fastcgiId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if fastcgi == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
config := &serverconfigs.HTTPFastcgiConfig{}
|
||||||
|
config.Id = int64(fastcgi.Id)
|
||||||
|
config.IsOn = fastcgi.IsOn == 1
|
||||||
|
config.Address = fastcgi.Address
|
||||||
|
|
||||||
|
if IsNotNull(fastcgi.Params) {
|
||||||
|
params := []*serverconfigs.HTTPFastcgiParam{}
|
||||||
|
err = json.Unmarshal([]byte(fastcgi.Params), ¶ms)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.Params = params
|
||||||
|
}
|
||||||
|
|
||||||
|
if IsNotNull(fastcgi.ReadTimeout) {
|
||||||
|
duration := &shared.TimeDuration{}
|
||||||
|
err = json.Unmarshal([]byte(fastcgi.ReadTimeout), duration)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.ReadTimeout = duration
|
||||||
|
}
|
||||||
|
|
||||||
|
if IsNotNull(fastcgi.ConnTimeout) {
|
||||||
|
duration := &shared.TimeDuration{}
|
||||||
|
err = json.Unmarshal([]byte(fastcgi.ConnTimeout), duration)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.ConnTimeout = duration
|
||||||
|
}
|
||||||
|
|
||||||
|
if fastcgi.PoolSize > 0 {
|
||||||
|
config.PoolSize = types.Int(fastcgi.PoolSize)
|
||||||
|
}
|
||||||
|
config.PathInfoPattern = fastcgi.PathInfoPattern
|
||||||
|
|
||||||
|
return config, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateFastcgi 创建Fastcgi
|
||||||
|
func (this *HTTPFastcgiDAO) CreateFastcgi(tx *dbs.Tx, adminId int64, userId int64, isOn bool, address string, paramsJSON []byte, readTimeoutJSON []byte, connTimeoutJSON []byte, poolSize int32, pathInfoPattern string) (int64, error) {
|
||||||
|
op := NewHTTPFastcgiOperator()
|
||||||
|
op.AdminId = adminId
|
||||||
|
op.UserId = userId
|
||||||
|
op.IsOn = isOn
|
||||||
|
op.Address = address
|
||||||
|
if len(paramsJSON) > 0 {
|
||||||
|
op.Params = paramsJSON
|
||||||
|
}
|
||||||
|
if len(readTimeoutJSON) > 0 {
|
||||||
|
op.ReadTimeout = readTimeoutJSON
|
||||||
|
}
|
||||||
|
if len(connTimeoutJSON) > 0 {
|
||||||
|
op.ConnTimeout = connTimeoutJSON
|
||||||
|
}
|
||||||
|
op.PoolSize = poolSize
|
||||||
|
op.PathInfoPattern = pathInfoPattern
|
||||||
|
|
||||||
|
op.State = HTTPFastcgiStateEnabled
|
||||||
|
return this.SaveInt64(tx, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateFastcgi 修改Fastcgi
|
||||||
|
func (this *HTTPFastcgiDAO) UpdateFastcgi(tx *dbs.Tx, fastcgiId int64, isOn bool, address string, paramsJSON []byte, readTimeoutJSON []byte, connTimeoutJSON []byte, poolSize int32, pathInfoPattern string) error {
|
||||||
|
if fastcgiId <= 0 {
|
||||||
|
return errors.New("invalid 'fastcgiId'")
|
||||||
|
}
|
||||||
|
op := NewHTTPFastcgiOperator()
|
||||||
|
op.Id = fastcgiId
|
||||||
|
op.IsOn = isOn
|
||||||
|
op.Address = address
|
||||||
|
if len(paramsJSON) > 0 {
|
||||||
|
op.Params = paramsJSON
|
||||||
|
}
|
||||||
|
if len(readTimeoutJSON) > 0 {
|
||||||
|
op.ReadTimeout = readTimeoutJSON
|
||||||
|
}
|
||||||
|
if len(connTimeoutJSON) > 0 {
|
||||||
|
op.ConnTimeout = connTimeoutJSON
|
||||||
|
}
|
||||||
|
op.PoolSize = poolSize
|
||||||
|
op.PathInfoPattern = pathInfoPattern
|
||||||
|
err := this.Save(tx, op)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return this.NotifyUpdate(tx, fastcgiId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CheckUserFastcgi 检查用户Fastcgi权限
|
||||||
|
func (this *HTTPFastcgiDAO) CheckUserFastcgi(tx *dbs.Tx, userId int64, fastcgiId int64) error {
|
||||||
|
if userId <= 0 || fastcgiId <= 0 {
|
||||||
|
return errors.New("permission error")
|
||||||
|
}
|
||||||
|
exists, err := this.Query(tx).
|
||||||
|
Pk(fastcgiId).
|
||||||
|
Attr("userId", userId).
|
||||||
|
State(HTTPFastcgiStateEnabled).
|
||||||
|
Exist()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !exists {
|
||||||
|
return errors.New("permission error")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyUpdate 通知更新
|
||||||
|
func (this *HTTPFastcgiDAO) NotifyUpdate(tx *dbs.Tx, fastcgiId int64) error {
|
||||||
|
webId, err := SharedHTTPWebDAO.FindEnabledWebIdWithFastcgiId(tx, fastcgiId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if webId > 0 {
|
||||||
|
return SharedHTTPWebDAO.NotifyUpdate(tx, webId)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
6
internal/db/models/http_fastcgi_dao_test.go
Normal file
6
internal/db/models/http_fastcgi_dao_test.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
|
)
|
||||||
34
internal/db/models/http_fastcgi_model.go
Normal file
34
internal/db/models/http_fastcgi_model.go
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
// HTTPFastcgi Fastcgi设置
|
||||||
|
type HTTPFastcgi struct {
|
||||||
|
Id uint64 `field:"id"` // ID
|
||||||
|
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||||
|
UserId uint32 `field:"userId"` // 用户ID
|
||||||
|
IsOn uint8 `field:"isOn"` // 是否启用
|
||||||
|
Address string `field:"address"` // 地址
|
||||||
|
Params string `field:"params"` // 参数
|
||||||
|
ReadTimeout string `field:"readTimeout"` // 读取超时
|
||||||
|
ConnTimeout string `field:"connTimeout"` // 连接超时
|
||||||
|
PoolSize uint32 `field:"poolSize"` // 连接池尺寸
|
||||||
|
PathInfoPattern string `field:"pathInfoPattern"` // PATH_INFO匹配
|
||||||
|
State uint8 `field:"state"` // 状态
|
||||||
|
}
|
||||||
|
|
||||||
|
type HTTPFastcgiOperator struct {
|
||||||
|
Id interface{} // ID
|
||||||
|
AdminId interface{} // 管理员ID
|
||||||
|
UserId interface{} // 用户ID
|
||||||
|
IsOn interface{} // 是否启用
|
||||||
|
Address interface{} // 地址
|
||||||
|
Params interface{} // 参数
|
||||||
|
ReadTimeout interface{} // 读取超时
|
||||||
|
ConnTimeout interface{} // 连接超时
|
||||||
|
PoolSize interface{} // 连接池尺寸
|
||||||
|
PathInfoPattern interface{} // PATH_INFO匹配
|
||||||
|
State interface{} // 状态
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHTTPFastcgiOperator() *HTTPFastcgiOperator {
|
||||||
|
return &HTTPFastcgiOperator{}
|
||||||
|
}
|
||||||
1
internal/db/models/http_fastcgi_model_ext.go
Normal file
1
internal/db/models/http_fastcgi_model_ext.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package models
|
||||||
@@ -37,12 +37,12 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化
|
// Init 初始化
|
||||||
func (this *HTTPFirewallPolicyDAO) Init() {
|
func (this *HTTPFirewallPolicyDAO) Init() {
|
||||||
_ = this.DAOObject.Init()
|
_ = this.DAOObject.Init()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启用条目
|
// EnableHTTPFirewallPolicy 启用条目
|
||||||
func (this *HTTPFirewallPolicyDAO) EnableHTTPFirewallPolicy(tx *dbs.Tx, id int64) error {
|
func (this *HTTPFirewallPolicyDAO) EnableHTTPFirewallPolicy(tx *dbs.Tx, id int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -51,7 +51,7 @@ func (this *HTTPFirewallPolicyDAO) EnableHTTPFirewallPolicy(tx *dbs.Tx, id int64
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 禁用条目
|
// DisableHTTPFirewallPolicy 禁用条目
|
||||||
func (this *HTTPFirewallPolicyDAO) DisableHTTPFirewallPolicy(tx *dbs.Tx, policyId int64) error {
|
func (this *HTTPFirewallPolicyDAO) DisableHTTPFirewallPolicy(tx *dbs.Tx, policyId int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(policyId).
|
Pk(policyId).
|
||||||
@@ -64,7 +64,7 @@ func (this *HTTPFirewallPolicyDAO) DisableHTTPFirewallPolicy(tx *dbs.Tx, policyI
|
|||||||
return this.NotifyUpdate(tx, policyId)
|
return this.NotifyUpdate(tx, policyId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找启用中的条目
|
// FindEnabledHTTPFirewallPolicy 查找启用中的条目
|
||||||
func (this *HTTPFirewallPolicyDAO) FindEnabledHTTPFirewallPolicy(tx *dbs.Tx, id int64) (*HTTPFirewallPolicy, error) {
|
func (this *HTTPFirewallPolicyDAO) FindEnabledHTTPFirewallPolicy(tx *dbs.Tx, id int64) (*HTTPFirewallPolicy, error) {
|
||||||
result, err := this.Query(tx).
|
result, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -76,7 +76,7 @@ func (this *HTTPFirewallPolicyDAO) FindEnabledHTTPFirewallPolicy(tx *dbs.Tx, id
|
|||||||
return result.(*HTTPFirewallPolicy), err
|
return result.(*HTTPFirewallPolicy), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据主键查找名称
|
// FindHTTPFirewallPolicyName 根据主键查找名称
|
||||||
func (this *HTTPFirewallPolicyDAO) FindHTTPFirewallPolicyName(tx *dbs.Tx, id int64) (string, error) {
|
func (this *HTTPFirewallPolicyDAO) FindHTTPFirewallPolicyName(tx *dbs.Tx, id int64) (string, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -84,7 +84,7 @@ func (this *HTTPFirewallPolicyDAO) FindHTTPFirewallPolicyName(tx *dbs.Tx, id int
|
|||||||
FindStringCol("")
|
FindStringCol("")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找所有可用策略
|
// FindAllEnabledFirewallPolicies 查找所有可用策略
|
||||||
func (this *HTTPFirewallPolicyDAO) FindAllEnabledFirewallPolicies(tx *dbs.Tx) (result []*HTTPFirewallPolicy, err error) {
|
func (this *HTTPFirewallPolicyDAO) FindAllEnabledFirewallPolicies(tx *dbs.Tx) (result []*HTTPFirewallPolicy, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(HTTPFirewallPolicyStateEnabled).
|
State(HTTPFirewallPolicyStateEnabled).
|
||||||
@@ -94,7 +94,7 @@ func (this *HTTPFirewallPolicyDAO) FindAllEnabledFirewallPolicies(tx *dbs.Tx) (r
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建策略
|
// CreateFirewallPolicy 创建策略
|
||||||
func (this *HTTPFirewallPolicyDAO) CreateFirewallPolicy(tx *dbs.Tx, userId int64, serverId int64, isOn bool, name string, description string, inboundJSON []byte, outboundJSON []byte) (int64, error) {
|
func (this *HTTPFirewallPolicyDAO) CreateFirewallPolicy(tx *dbs.Tx, userId int64, serverId int64, isOn bool, name string, description string, inboundJSON []byte, outboundJSON []byte) (int64, error) {
|
||||||
op := NewHTTPFirewallPolicyOperator()
|
op := NewHTTPFirewallPolicyOperator()
|
||||||
op.UserId = userId
|
op.UserId = userId
|
||||||
@@ -113,7 +113,7 @@ func (this *HTTPFirewallPolicyDAO) CreateFirewallPolicy(tx *dbs.Tx, userId int64
|
|||||||
return types.Int64(op.Id), err
|
return types.Int64(op.Id), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改策略的Inbound和Outbound
|
// UpdateFirewallPolicyInboundAndOutbound 修改策略的Inbound和Outbound
|
||||||
func (this *HTTPFirewallPolicyDAO) UpdateFirewallPolicyInboundAndOutbound(tx *dbs.Tx, policyId int64, inboundJSON []byte, outboundJSON []byte) error {
|
func (this *HTTPFirewallPolicyDAO) UpdateFirewallPolicyInboundAndOutbound(tx *dbs.Tx, policyId int64, inboundJSON []byte, outboundJSON []byte) error {
|
||||||
if policyId <= 0 {
|
if policyId <= 0 {
|
||||||
return errors.New("invalid policyId")
|
return errors.New("invalid policyId")
|
||||||
@@ -138,7 +138,7 @@ func (this *HTTPFirewallPolicyDAO) UpdateFirewallPolicyInboundAndOutbound(tx *db
|
|||||||
return this.NotifyUpdate(tx, policyId)
|
return this.NotifyUpdate(tx, policyId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改策略的Inbound
|
// UpdateFirewallPolicyInbound 修改策略的Inbound
|
||||||
func (this *HTTPFirewallPolicyDAO) UpdateFirewallPolicyInbound(tx *dbs.Tx, policyId int64, inboundJSON []byte) error {
|
func (this *HTTPFirewallPolicyDAO) UpdateFirewallPolicyInbound(tx *dbs.Tx, policyId int64, inboundJSON []byte) error {
|
||||||
if policyId <= 0 {
|
if policyId <= 0 {
|
||||||
return errors.New("invalid policyId")
|
return errors.New("invalid policyId")
|
||||||
@@ -158,7 +158,7 @@ func (this *HTTPFirewallPolicyDAO) UpdateFirewallPolicyInbound(tx *dbs.Tx, polic
|
|||||||
return this.NotifyUpdate(tx, policyId)
|
return this.NotifyUpdate(tx, policyId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改策略
|
// UpdateFirewallPolicy 修改策略
|
||||||
func (this *HTTPFirewallPolicyDAO) UpdateFirewallPolicy(tx *dbs.Tx, policyId int64, isOn bool, name string, description string, inboundJSON []byte, outboundJSON []byte, blockOptionsJSON []byte) error {
|
func (this *HTTPFirewallPolicyDAO) UpdateFirewallPolicy(tx *dbs.Tx, policyId int64, isOn bool, name string, description string, inboundJSON []byte, outboundJSON []byte, blockOptionsJSON []byte) error {
|
||||||
if policyId <= 0 {
|
if policyId <= 0 {
|
||||||
return errors.New("invalid policyId")
|
return errors.New("invalid policyId")
|
||||||
@@ -189,18 +189,28 @@ func (this *HTTPFirewallPolicyDAO) UpdateFirewallPolicy(tx *dbs.Tx, policyId int
|
|||||||
return this.NotifyUpdate(tx, policyId)
|
return this.NotifyUpdate(tx, policyId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算所有可用的策略数量
|
// CountAllEnabledFirewallPolicies 计算所有可用的策略数量
|
||||||
func (this *HTTPFirewallPolicyDAO) CountAllEnabledFirewallPolicies(tx *dbs.Tx) (int64, error) {
|
func (this *HTTPFirewallPolicyDAO) CountAllEnabledFirewallPolicies(tx *dbs.Tx, keyword string) (int64, error) {
|
||||||
return this.Query(tx).
|
query := this.Query(tx)
|
||||||
|
if len(keyword) > 0 {
|
||||||
|
query.Where("(name LIKE :keyword)").
|
||||||
|
Param("keyword", "%"+keyword+"%")
|
||||||
|
}
|
||||||
|
return query.
|
||||||
State(HTTPFirewallPolicyStateEnabled).
|
State(HTTPFirewallPolicyStateEnabled).
|
||||||
Attr("userId", 0).
|
Attr("userId", 0).
|
||||||
Attr("serverId", 0).
|
Attr("serverId", 0).
|
||||||
Count()
|
Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出单页的策略
|
// ListEnabledFirewallPolicies 列出单页的策略
|
||||||
func (this *HTTPFirewallPolicyDAO) ListEnabledFirewallPolicies(tx *dbs.Tx, offset int64, size int64) (result []*HTTPFirewallPolicy, err error) {
|
func (this *HTTPFirewallPolicyDAO) ListEnabledFirewallPolicies(tx *dbs.Tx, keyword string, offset int64, size int64) (result []*HTTPFirewallPolicy, err error) {
|
||||||
_, err = this.Query(tx).
|
query := this.Query(tx)
|
||||||
|
if len(keyword) > 0 {
|
||||||
|
query.Where("(name LIKE :keyword)").
|
||||||
|
Param("keyword", "%"+keyword+"%")
|
||||||
|
}
|
||||||
|
_, err = query.
|
||||||
State(HTTPFirewallPolicyStateEnabled).
|
State(HTTPFirewallPolicyStateEnabled).
|
||||||
Attr("userId", 0).
|
Attr("userId", 0).
|
||||||
Attr("serverId", 0).
|
Attr("serverId", 0).
|
||||||
@@ -212,7 +222,7 @@ func (this *HTTPFirewallPolicyDAO) ListEnabledFirewallPolicies(tx *dbs.Tx, offse
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 组合策略配置
|
// ComposeFirewallPolicy 组合策略配置
|
||||||
func (this *HTTPFirewallPolicyDAO) ComposeFirewallPolicy(tx *dbs.Tx, policyId int64) (*firewallconfigs.HTTPFirewallPolicy, error) {
|
func (this *HTTPFirewallPolicyDAO) ComposeFirewallPolicy(tx *dbs.Tx, policyId int64) (*firewallconfigs.HTTPFirewallPolicy, error) {
|
||||||
policy, err := this.FindEnabledHTTPFirewallPolicy(tx, policyId)
|
policy, err := this.FindEnabledHTTPFirewallPolicy(tx, policyId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -297,7 +307,7 @@ func (this *HTTPFirewallPolicyDAO) ComposeFirewallPolicy(tx *dbs.Tx, policyId in
|
|||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查用户防火墙策略
|
// CheckUserFirewallPolicy 检查用户防火墙策略
|
||||||
func (this *HTTPFirewallPolicyDAO) CheckUserFirewallPolicy(tx *dbs.Tx, userId int64, firewallPolicyId int64) error {
|
func (this *HTTPFirewallPolicyDAO) CheckUserFirewallPolicy(tx *dbs.Tx, userId int64, firewallPolicyId int64) error {
|
||||||
ok, err := this.Query(tx).
|
ok, err := this.Query(tx).
|
||||||
Pk(firewallPolicyId).
|
Pk(firewallPolicyId).
|
||||||
@@ -315,7 +325,7 @@ func (this *HTTPFirewallPolicyDAO) CheckUserFirewallPolicy(tx *dbs.Tx, userId in
|
|||||||
return ErrNotFound
|
return ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找包含某个IPList的所有策略
|
// FindEnabledFirewallPolicyIdsWithIPListId 查找包含某个IPList的所有策略
|
||||||
func (this *HTTPFirewallPolicyDAO) FindEnabledFirewallPolicyIdsWithIPListId(tx *dbs.Tx, ipListId int64) ([]int64, error) {
|
func (this *HTTPFirewallPolicyDAO) FindEnabledFirewallPolicyIdsWithIPListId(tx *dbs.Tx, ipListId int64) ([]int64, error) {
|
||||||
ones, err := this.Query(tx).
|
ones, err := this.Query(tx).
|
||||||
ResultPk().
|
ResultPk().
|
||||||
@@ -333,7 +343,7 @@ func (this *HTTPFirewallPolicyDAO) FindEnabledFirewallPolicyIdsWithIPListId(tx *
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找包含某个规则分组的策略ID
|
// FindEnabledFirewallPolicyIdWithRuleGroupId 查找包含某个规则分组的策略ID
|
||||||
func (this *HTTPFirewallPolicyDAO) FindEnabledFirewallPolicyIdWithRuleGroupId(tx *dbs.Tx, ruleGroupId int64) (int64, error) {
|
func (this *HTTPFirewallPolicyDAO) FindEnabledFirewallPolicyIdWithRuleGroupId(tx *dbs.Tx, ruleGroupId int64) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
ResultPk().
|
ResultPk().
|
||||||
@@ -343,7 +353,7 @@ func (this *HTTPFirewallPolicyDAO) FindEnabledFirewallPolicyIdWithRuleGroupId(tx
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置某个策略所属的服务ID
|
// UpdateFirewallPolicyServerId 设置某个策略所属的服务ID
|
||||||
func (this *HTTPFirewallPolicyDAO) UpdateFirewallPolicyServerId(tx *dbs.Tx, policyId int64, serverId int64) error {
|
func (this *HTTPFirewallPolicyDAO) UpdateFirewallPolicyServerId(tx *dbs.Tx, policyId int64, serverId int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(policyId).
|
Pk(policyId).
|
||||||
@@ -352,7 +362,7 @@ func (this *HTTPFirewallPolicyDAO) UpdateFirewallPolicyServerId(tx *dbs.Tx, poli
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通知更新
|
// NotifyUpdate 通知更新
|
||||||
func (this *HTTPFirewallPolicyDAO) NotifyUpdate(tx *dbs.Tx, policyId int64) error {
|
func (this *HTTPFirewallPolicyDAO) NotifyUpdate(tx *dbs.Tx, policyId int64) error {
|
||||||
webIds, err := SharedHTTPWebDAO.FindAllWebIdsWithHTTPFirewallPolicyId(tx, policyId)
|
webIds, err := SharedHTTPWebDAO.FindAllWebIdsWithHTTPFirewallPolicyId(tx, policyId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
@@ -36,12 +37,12 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化
|
// Init 初始化
|
||||||
func (this *HTTPLocationDAO) Init() {
|
func (this *HTTPLocationDAO) Init() {
|
||||||
_ = this.DAOObject.Init()
|
_ = this.DAOObject.Init()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启用条目
|
// EnableHTTPLocation 启用条目
|
||||||
func (this *HTTPLocationDAO) EnableHTTPLocation(tx *dbs.Tx, id int64) error {
|
func (this *HTTPLocationDAO) EnableHTTPLocation(tx *dbs.Tx, id int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -50,7 +51,7 @@ func (this *HTTPLocationDAO) EnableHTTPLocation(tx *dbs.Tx, id int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 禁用条目
|
// DisableHTTPLocation 禁用条目
|
||||||
func (this *HTTPLocationDAO) DisableHTTPLocation(tx *dbs.Tx, locationId int64) error {
|
func (this *HTTPLocationDAO) DisableHTTPLocation(tx *dbs.Tx, locationId int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(locationId).
|
Pk(locationId).
|
||||||
@@ -62,7 +63,7 @@ func (this *HTTPLocationDAO) DisableHTTPLocation(tx *dbs.Tx, locationId int64) e
|
|||||||
return this.NotifyUpdate(tx, locationId)
|
return this.NotifyUpdate(tx, locationId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找启用中的条目
|
// FindEnabledHTTPLocation 查找启用中的条目
|
||||||
func (this *HTTPLocationDAO) FindEnabledHTTPLocation(tx *dbs.Tx, id int64) (*HTTPLocation, error) {
|
func (this *HTTPLocationDAO) FindEnabledHTTPLocation(tx *dbs.Tx, id int64) (*HTTPLocation, error) {
|
||||||
result, err := this.Query(tx).
|
result, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -74,7 +75,7 @@ func (this *HTTPLocationDAO) FindEnabledHTTPLocation(tx *dbs.Tx, id int64) (*HTT
|
|||||||
return result.(*HTTPLocation), err
|
return result.(*HTTPLocation), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据主键查找名称
|
// FindHTTPLocationName 根据主键查找名称
|
||||||
func (this *HTTPLocationDAO) FindHTTPLocationName(tx *dbs.Tx, id int64) (string, error) {
|
func (this *HTTPLocationDAO) FindHTTPLocationName(tx *dbs.Tx, id int64) (string, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -82,8 +83,8 @@ func (this *HTTPLocationDAO) FindHTTPLocationName(tx *dbs.Tx, id int64) (string,
|
|||||||
FindStringCol("")
|
FindStringCol("")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建路径规则
|
// CreateLocation 创建路径规则
|
||||||
func (this *HTTPLocationDAO) CreateLocation(tx *dbs.Tx, parentId int64, name string, pattern string, description string, isBreak bool) (int64, error) {
|
func (this *HTTPLocationDAO) CreateLocation(tx *dbs.Tx, parentId int64, name string, pattern string, description string, isBreak bool, condsJSON []byte) (int64, error) {
|
||||||
op := NewHTTPLocationOperator()
|
op := NewHTTPLocationOperator()
|
||||||
op.IsOn = true
|
op.IsOn = true
|
||||||
op.State = HTTPLocationStateEnabled
|
op.State = HTTPLocationStateEnabled
|
||||||
@@ -92,6 +93,11 @@ func (this *HTTPLocationDAO) CreateLocation(tx *dbs.Tx, parentId int64, name str
|
|||||||
op.Pattern = pattern
|
op.Pattern = pattern
|
||||||
op.Description = description
|
op.Description = description
|
||||||
op.IsBreak = isBreak
|
op.IsBreak = isBreak
|
||||||
|
|
||||||
|
if len(condsJSON) > 0 {
|
||||||
|
op.Conds = condsJSON
|
||||||
|
}
|
||||||
|
|
||||||
err := this.Save(tx, op)
|
err := this.Save(tx, op)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
@@ -99,8 +105,8 @@ func (this *HTTPLocationDAO) CreateLocation(tx *dbs.Tx, parentId int64, name str
|
|||||||
return types.Int64(op.Id), nil
|
return types.Int64(op.Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改路径规则
|
// UpdateLocation 修改路径规则
|
||||||
func (this *HTTPLocationDAO) UpdateLocation(tx *dbs.Tx, locationId int64, name string, pattern string, description string, isOn bool, isBreak bool) error {
|
func (this *HTTPLocationDAO) UpdateLocation(tx *dbs.Tx, locationId int64, name string, pattern string, description string, isOn bool, isBreak bool, condsJSON []byte) error {
|
||||||
if locationId <= 0 {
|
if locationId <= 0 {
|
||||||
return errors.New("invalid locationId")
|
return errors.New("invalid locationId")
|
||||||
}
|
}
|
||||||
@@ -111,6 +117,11 @@ func (this *HTTPLocationDAO) UpdateLocation(tx *dbs.Tx, locationId int64, name s
|
|||||||
op.Description = description
|
op.Description = description
|
||||||
op.IsOn = isOn
|
op.IsOn = isOn
|
||||||
op.IsBreak = isBreak
|
op.IsBreak = isBreak
|
||||||
|
|
||||||
|
if len(condsJSON) > 0 {
|
||||||
|
op.Conds = condsJSON
|
||||||
|
}
|
||||||
|
|
||||||
err := this.Save(tx, op)
|
err := this.Save(tx, op)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -118,7 +129,7 @@ func (this *HTTPLocationDAO) UpdateLocation(tx *dbs.Tx, locationId int64, name s
|
|||||||
return this.NotifyUpdate(tx, locationId)
|
return this.NotifyUpdate(tx, locationId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 组合配置
|
// ComposeLocationConfig 组合配置
|
||||||
func (this *HTTPLocationDAO) ComposeLocationConfig(tx *dbs.Tx, locationId int64) (*serverconfigs.HTTPLocationConfig, error) {
|
func (this *HTTPLocationDAO) ComposeLocationConfig(tx *dbs.Tx, locationId int64) (*serverconfigs.HTTPLocationConfig, error) {
|
||||||
location, err := this.FindEnabledHTTPLocation(tx, locationId)
|
location, err := this.FindEnabledHTTPLocation(tx, locationId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -163,10 +174,20 @@ func (this *HTTPLocationDAO) ComposeLocationConfig(tx *dbs.Tx, locationId int64)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// conds
|
||||||
|
if len(location.Conds) > 0 {
|
||||||
|
conds := &shared.HTTPRequestCondsConfig{}
|
||||||
|
err = json.Unmarshal([]byte(location.Conds), conds)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.Conds = conds
|
||||||
|
}
|
||||||
|
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找反向代理设置
|
// FindLocationReverseProxy 查找反向代理设置
|
||||||
func (this *HTTPLocationDAO) FindLocationReverseProxy(tx *dbs.Tx, locationId int64) (*serverconfigs.ReverseProxyRef, error) {
|
func (this *HTTPLocationDAO) FindLocationReverseProxy(tx *dbs.Tx, locationId int64) (*serverconfigs.ReverseProxyRef, error) {
|
||||||
refString, err := this.Query(tx).
|
refString, err := this.Query(tx).
|
||||||
Pk(locationId).
|
Pk(locationId).
|
||||||
@@ -186,7 +207,7 @@ func (this *HTTPLocationDAO) FindLocationReverseProxy(tx *dbs.Tx, locationId int
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更改反向代理设置
|
// UpdateLocationReverseProxy 更改反向代理设置
|
||||||
func (this *HTTPLocationDAO) UpdateLocationReverseProxy(tx *dbs.Tx, locationId int64, reverseProxyJSON []byte) error {
|
func (this *HTTPLocationDAO) UpdateLocationReverseProxy(tx *dbs.Tx, locationId int64, reverseProxyJSON []byte) error {
|
||||||
if locationId <= 0 {
|
if locationId <= 0 {
|
||||||
return errors.New("invalid locationId")
|
return errors.New("invalid locationId")
|
||||||
@@ -201,7 +222,7 @@ func (this *HTTPLocationDAO) UpdateLocationReverseProxy(tx *dbs.Tx, locationId i
|
|||||||
return this.NotifyUpdate(tx, locationId)
|
return this.NotifyUpdate(tx, locationId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找WebId
|
// FindLocationWebId 查找WebId
|
||||||
func (this *HTTPLocationDAO) FindLocationWebId(tx *dbs.Tx, locationId int64) (int64, error) {
|
func (this *HTTPLocationDAO) FindLocationWebId(tx *dbs.Tx, locationId int64) (int64, error) {
|
||||||
webId, err := this.Query(tx).
|
webId, err := this.Query(tx).
|
||||||
Pk(locationId).
|
Pk(locationId).
|
||||||
@@ -210,7 +231,7 @@ func (this *HTTPLocationDAO) FindLocationWebId(tx *dbs.Tx, locationId int64) (in
|
|||||||
return int64(webId), err
|
return int64(webId), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更改Web设置
|
// UpdateLocationWeb 更改Web设置
|
||||||
func (this *HTTPLocationDAO) UpdateLocationWeb(tx *dbs.Tx, locationId int64, webId int64) error {
|
func (this *HTTPLocationDAO) UpdateLocationWeb(tx *dbs.Tx, locationId int64, webId int64) error {
|
||||||
if locationId <= 0 {
|
if locationId <= 0 {
|
||||||
return errors.New("invalid locationId")
|
return errors.New("invalid locationId")
|
||||||
@@ -225,7 +246,7 @@ func (this *HTTPLocationDAO) UpdateLocationWeb(tx *dbs.Tx, locationId int64, web
|
|||||||
return this.NotifyUpdate(tx, locationId)
|
return this.NotifyUpdate(tx, locationId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 转换引用为配置
|
// ConvertLocationRefs 转换引用为配置
|
||||||
func (this *HTTPLocationDAO) ConvertLocationRefs(tx *dbs.Tx, refs []*serverconfigs.HTTPLocationRef) (locations []*serverconfigs.HTTPLocationConfig, err error) {
|
func (this *HTTPLocationDAO) ConvertLocationRefs(tx *dbs.Tx, refs []*serverconfigs.HTTPLocationRef) (locations []*serverconfigs.HTTPLocationConfig, err error) {
|
||||||
for _, ref := range refs {
|
for _, ref := range refs {
|
||||||
config, err := this.ComposeLocationConfig(tx, ref.LocationId)
|
config, err := this.ComposeLocationConfig(tx, ref.LocationId)
|
||||||
@@ -243,7 +264,7 @@ func (this *HTTPLocationDAO) ConvertLocationRefs(tx *dbs.Tx, refs []*serverconfi
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据WebId查找LocationId
|
// FindEnabledLocationIdWithWebId 根据WebId查找LocationId
|
||||||
func (this *HTTPLocationDAO) FindEnabledLocationIdWithWebId(tx *dbs.Tx, webId int64) (locationId int64, err error) {
|
func (this *HTTPLocationDAO) FindEnabledLocationIdWithWebId(tx *dbs.Tx, webId int64) (locationId int64, err error) {
|
||||||
if webId <= 0 {
|
if webId <= 0 {
|
||||||
return
|
return
|
||||||
@@ -254,7 +275,7 @@ func (this *HTTPLocationDAO) FindEnabledLocationIdWithWebId(tx *dbs.Tx, webId in
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通知更新
|
// NotifyUpdate 通知更新
|
||||||
func (this *HTTPLocationDAO) NotifyUpdate(tx *dbs.Tx, locationId int64) error {
|
func (this *HTTPLocationDAO) NotifyUpdate(tx *dbs.Tx, locationId int64) error {
|
||||||
webId, err := SharedHTTPWebDAO.FindEnabledWebIdWithLocationId(tx, locationId)
|
webId, err := SharedHTTPWebDAO.FindEnabledWebIdWithLocationId(tx, locationId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
@@ -35,12 +37,12 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化
|
// Init 初始化
|
||||||
func (this *HTTPRewriteRuleDAO) Init() {
|
func (this *HTTPRewriteRuleDAO) Init() {
|
||||||
_ = this.DAOObject.Init()
|
_ = this.DAOObject.Init()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启用条目
|
// EnableHTTPRewriteRule 启用条目
|
||||||
func (this *HTTPRewriteRuleDAO) EnableHTTPRewriteRule(tx *dbs.Tx, id int64) error {
|
func (this *HTTPRewriteRuleDAO) EnableHTTPRewriteRule(tx *dbs.Tx, id int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -49,7 +51,7 @@ func (this *HTTPRewriteRuleDAO) EnableHTTPRewriteRule(tx *dbs.Tx, id int64) erro
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 禁用条目
|
// DisableHTTPRewriteRule 禁用条目
|
||||||
func (this *HTTPRewriteRuleDAO) DisableHTTPRewriteRule(tx *dbs.Tx, rewriteRuleId int64) error {
|
func (this *HTTPRewriteRuleDAO) DisableHTTPRewriteRule(tx *dbs.Tx, rewriteRuleId int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(rewriteRuleId).
|
Pk(rewriteRuleId).
|
||||||
@@ -61,7 +63,7 @@ func (this *HTTPRewriteRuleDAO) DisableHTTPRewriteRule(tx *dbs.Tx, rewriteRuleId
|
|||||||
return this.NotifyUpdate(tx, rewriteRuleId)
|
return this.NotifyUpdate(tx, rewriteRuleId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找启用中的条目
|
// FindEnabledHTTPRewriteRule 查找启用中的条目
|
||||||
func (this *HTTPRewriteRuleDAO) FindEnabledHTTPRewriteRule(tx *dbs.Tx, id int64) (*HTTPRewriteRule, error) {
|
func (this *HTTPRewriteRuleDAO) FindEnabledHTTPRewriteRule(tx *dbs.Tx, id int64) (*HTTPRewriteRule, error) {
|
||||||
result, err := this.Query(tx).
|
result, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -73,7 +75,7 @@ func (this *HTTPRewriteRuleDAO) FindEnabledHTTPRewriteRule(tx *dbs.Tx, id int64)
|
|||||||
return result.(*HTTPRewriteRule), err
|
return result.(*HTTPRewriteRule), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构造配置
|
// ComposeRewriteRule 构造配置
|
||||||
func (this *HTTPRewriteRuleDAO) ComposeRewriteRule(tx *dbs.Tx, rewriteRuleId int64) (*serverconfigs.HTTPRewriteRule, error) {
|
func (this *HTTPRewriteRuleDAO) ComposeRewriteRule(tx *dbs.Tx, rewriteRuleId int64) (*serverconfigs.HTTPRewriteRule, error) {
|
||||||
rule, err := this.FindEnabledHTTPRewriteRule(tx, rewriteRuleId)
|
rule, err := this.FindEnabledHTTPRewriteRule(tx, rewriteRuleId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -93,11 +95,21 @@ func (this *HTTPRewriteRuleDAO) ComposeRewriteRule(tx *dbs.Tx, rewriteRuleId int
|
|||||||
config.ProxyHost = rule.ProxyHost
|
config.ProxyHost = rule.ProxyHost
|
||||||
config.IsBreak = rule.IsBreak == 1
|
config.IsBreak = rule.IsBreak == 1
|
||||||
config.WithQuery = rule.WithQuery == 1
|
config.WithQuery = rule.WithQuery == 1
|
||||||
|
|
||||||
|
// conds
|
||||||
|
if len(rule.Conds) > 0 {
|
||||||
|
conds := &shared.HTTPRequestCondsConfig{}
|
||||||
|
err = json.Unmarshal([]byte(rule.Conds), conds)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.Conds = conds
|
||||||
|
}
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建规则
|
// CreateRewriteRule 创建规则
|
||||||
func (this *HTTPRewriteRuleDAO) CreateRewriteRule(tx *dbs.Tx, pattern string, replace string, mode string, redirectStatus int, isBreak bool, proxyHost string, withQuery bool, isOn bool) (int64, error) {
|
func (this *HTTPRewriteRuleDAO) CreateRewriteRule(tx *dbs.Tx, pattern string, replace string, mode string, redirectStatus int, isBreak bool, proxyHost string, withQuery bool, isOn bool, condsJSON []byte) (int64, error) {
|
||||||
op := NewHTTPRewriteRuleOperator()
|
op := NewHTTPRewriteRuleOperator()
|
||||||
op.State = HTTPRewriteRuleStateEnabled
|
op.State = HTTPRewriteRuleStateEnabled
|
||||||
op.IsOn = isOn
|
op.IsOn = isOn
|
||||||
@@ -109,12 +121,17 @@ func (this *HTTPRewriteRuleDAO) CreateRewriteRule(tx *dbs.Tx, pattern string, re
|
|||||||
op.IsBreak = isBreak
|
op.IsBreak = isBreak
|
||||||
op.WithQuery = withQuery
|
op.WithQuery = withQuery
|
||||||
op.ProxyHost = proxyHost
|
op.ProxyHost = proxyHost
|
||||||
|
|
||||||
|
if len(condsJSON) > 0 {
|
||||||
|
op.Conds = condsJSON
|
||||||
|
}
|
||||||
|
|
||||||
err := this.Save(tx, op)
|
err := this.Save(tx, op)
|
||||||
return types.Int64(op.Id), err
|
return types.Int64(op.Id), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改规则
|
// UpdateRewriteRule 修改规则
|
||||||
func (this *HTTPRewriteRuleDAO) UpdateRewriteRule(tx *dbs.Tx, rewriteRuleId int64, pattern string, replace string, mode string, redirectStatus int, isBreak bool, proxyHost string, withQuery bool, isOn bool) error {
|
func (this *HTTPRewriteRuleDAO) UpdateRewriteRule(tx *dbs.Tx, rewriteRuleId int64, pattern string, replace string, mode string, redirectStatus int, isBreak bool, proxyHost string, withQuery bool, isOn bool, condsJSON []byte) error {
|
||||||
if rewriteRuleId <= 0 {
|
if rewriteRuleId <= 0 {
|
||||||
return errors.New("invalid rewriteRuleId")
|
return errors.New("invalid rewriteRuleId")
|
||||||
}
|
}
|
||||||
@@ -128,6 +145,11 @@ func (this *HTTPRewriteRuleDAO) UpdateRewriteRule(tx *dbs.Tx, rewriteRuleId int6
|
|||||||
op.IsBreak = isBreak
|
op.IsBreak = isBreak
|
||||||
op.WithQuery = withQuery
|
op.WithQuery = withQuery
|
||||||
op.ProxyHost = proxyHost
|
op.ProxyHost = proxyHost
|
||||||
|
|
||||||
|
if len(condsJSON) > 0 {
|
||||||
|
op.Conds = condsJSON
|
||||||
|
}
|
||||||
|
|
||||||
err := this.Save(tx, op)
|
err := this.Save(tx, op)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -135,7 +157,7 @@ func (this *HTTPRewriteRuleDAO) UpdateRewriteRule(tx *dbs.Tx, rewriteRuleId int6
|
|||||||
return this.NotifyUpdate(tx, rewriteRuleId)
|
return this.NotifyUpdate(tx, rewriteRuleId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通知更新
|
// NotifyUpdate 通知更新
|
||||||
func (this *HTTPRewriteRuleDAO) NotifyUpdate(tx *dbs.Tx, rewriteRuleId int64) error {
|
func (this *HTTPRewriteRuleDAO) NotifyUpdate(tx *dbs.Tx, rewriteRuleId int64) error {
|
||||||
webId, err := SharedHTTPWebDAO.FindEnabledWebIdWithRewriteRuleId(tx, rewriteRuleId)
|
webId, err := SharedHTTPWebDAO.FindEnabledWebIdWithRewriteRuleId(tx, rewriteRuleId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func (this *HTTPWebDAO) Init() {
|
|||||||
_ = this.DAOObject.Init()
|
_ = this.DAOObject.Init()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启用条目
|
// EnableHTTPWeb 启用条目
|
||||||
func (this *HTTPWebDAO) EnableHTTPWeb(tx *dbs.Tx, id int64) error {
|
func (this *HTTPWebDAO) EnableHTTPWeb(tx *dbs.Tx, id int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -53,7 +53,7 @@ func (this *HTTPWebDAO) EnableHTTPWeb(tx *dbs.Tx, id int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 禁用条目
|
// DisableHTTPWeb 禁用条目
|
||||||
func (this *HTTPWebDAO) DisableHTTPWeb(tx *dbs.Tx, id int64) error {
|
func (this *HTTPWebDAO) DisableHTTPWeb(tx *dbs.Tx, id int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -62,7 +62,7 @@ func (this *HTTPWebDAO) DisableHTTPWeb(tx *dbs.Tx, id int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找启用中的条目
|
// FindEnabledHTTPWeb 查找启用中的条目
|
||||||
func (this *HTTPWebDAO) FindEnabledHTTPWeb(tx *dbs.Tx, id int64) (*HTTPWeb, error) {
|
func (this *HTTPWebDAO) FindEnabledHTTPWeb(tx *dbs.Tx, id int64) (*HTTPWeb, error) {
|
||||||
result, err := this.Query(tx).
|
result, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -74,7 +74,7 @@ func (this *HTTPWebDAO) FindEnabledHTTPWeb(tx *dbs.Tx, id int64) (*HTTPWeb, erro
|
|||||||
return result.(*HTTPWeb), err
|
return result.(*HTTPWeb), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 组合配置
|
// ComposeWebConfig 组合配置
|
||||||
func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64) (*serverconfigs.HTTPWebConfig, error) {
|
func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64) (*serverconfigs.HTTPWebConfig, error) {
|
||||||
web, err := SharedHTTPWebDAO.FindEnabledHTTPWeb(tx, webId)
|
web, err := SharedHTTPWebDAO.FindEnabledHTTPWeb(tx, webId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -323,10 +323,55 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64) (*serverconfig
|
|||||||
config.HostRedirects = redirects
|
config.HostRedirects = redirects
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fastcgi
|
||||||
|
if IsNotNull(web.Fastcgi) {
|
||||||
|
ref := &serverconfigs.HTTPFastcgiRef{}
|
||||||
|
err = json.Unmarshal([]byte(web.Fastcgi), ref)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.FastcgiRef = ref
|
||||||
|
|
||||||
|
if len(ref.FastcgiIds) > 0 {
|
||||||
|
list := []*serverconfigs.HTTPFastcgiConfig{}
|
||||||
|
for _, fastcgiId := range ref.FastcgiIds {
|
||||||
|
fastcgiConfig, err := SharedHTTPFastcgiDAO.ComposeFastcgiConfig(tx, fastcgiId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if fastcgiConfig != nil {
|
||||||
|
list = append(list, fastcgiConfig)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
config.FastcgiList = list
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 认证
|
||||||
|
if IsNotNull(web.Auth) {
|
||||||
|
authConfig := &serverconfigs.HTTPAuthConfig{}
|
||||||
|
err = json.Unmarshal([]byte(web.Auth), authConfig)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var newRefs []*serverconfigs.HTTPAuthPolicyRef
|
||||||
|
for _, ref := range authConfig.PolicyRefs {
|
||||||
|
policyConfig, err := SharedHTTPAuthPolicyDAO.ComposePolicyConfig(tx, ref.AuthPolicyId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if policyConfig != nil {
|
||||||
|
ref.AuthPolicy = policyConfig
|
||||||
|
newRefs = append(newRefs, ref)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
config.Auth = authConfig
|
||||||
|
}
|
||||||
|
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建Web配置
|
// CreateWeb 创建Web配置
|
||||||
func (this *HTTPWebDAO) CreateWeb(tx *dbs.Tx, adminId int64, userId int64, rootJSON []byte) (int64, error) {
|
func (this *HTTPWebDAO) CreateWeb(tx *dbs.Tx, adminId int64, userId int64, rootJSON []byte) (int64, error) {
|
||||||
op := NewHTTPWebOperator()
|
op := NewHTTPWebOperator()
|
||||||
op.State = HTTPWebStateEnabled
|
op.State = HTTPWebStateEnabled
|
||||||
@@ -342,7 +387,7 @@ func (this *HTTPWebDAO) CreateWeb(tx *dbs.Tx, adminId int64, userId int64, rootJ
|
|||||||
return types.Int64(op.Id), nil
|
return types.Int64(op.Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改Web配置
|
// UpdateWeb 修改Web配置
|
||||||
func (this *HTTPWebDAO) UpdateWeb(tx *dbs.Tx, webId int64, rootJSON []byte) error {
|
func (this *HTTPWebDAO) UpdateWeb(tx *dbs.Tx, webId int64, rootJSON []byte) error {
|
||||||
if webId <= 0 {
|
if webId <= 0 {
|
||||||
return errors.New("invalid webId")
|
return errors.New("invalid webId")
|
||||||
@@ -358,7 +403,7 @@ func (this *HTTPWebDAO) UpdateWeb(tx *dbs.Tx, webId int64, rootJSON []byte) erro
|
|||||||
return this.NotifyUpdate(tx, webId)
|
return this.NotifyUpdate(tx, webId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改Gzip配置
|
// UpdateWebGzip 修改Gzip配置
|
||||||
func (this *HTTPWebDAO) UpdateWebGzip(tx *dbs.Tx, webId int64, gzipJSON []byte) error {
|
func (this *HTTPWebDAO) UpdateWebGzip(tx *dbs.Tx, webId int64, gzipJSON []byte) error {
|
||||||
if webId <= 0 {
|
if webId <= 0 {
|
||||||
return errors.New("invalid webId")
|
return errors.New("invalid webId")
|
||||||
@@ -374,7 +419,7 @@ func (this *HTTPWebDAO) UpdateWebGzip(tx *dbs.Tx, webId int64, gzipJSON []byte)
|
|||||||
return this.NotifyUpdate(tx, webId)
|
return this.NotifyUpdate(tx, webId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改字符编码
|
// UpdateWebCharset 修改字符编码
|
||||||
func (this *HTTPWebDAO) UpdateWebCharset(tx *dbs.Tx, webId int64, charsetJSON []byte) error {
|
func (this *HTTPWebDAO) UpdateWebCharset(tx *dbs.Tx, webId int64, charsetJSON []byte) error {
|
||||||
if webId <= 0 {
|
if webId <= 0 {
|
||||||
return errors.New("invalid webId")
|
return errors.New("invalid webId")
|
||||||
@@ -390,7 +435,7 @@ func (this *HTTPWebDAO) UpdateWebCharset(tx *dbs.Tx, webId int64, charsetJSON []
|
|||||||
return this.NotifyUpdate(tx, webId)
|
return this.NotifyUpdate(tx, webId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更改请求Header策略
|
// UpdateWebRequestHeaderPolicy 更改请求Header策略
|
||||||
func (this *HTTPWebDAO) UpdateWebRequestHeaderPolicy(tx *dbs.Tx, webId int64, headerPolicyJSON []byte) error {
|
func (this *HTTPWebDAO) UpdateWebRequestHeaderPolicy(tx *dbs.Tx, webId int64, headerPolicyJSON []byte) error {
|
||||||
if webId <= 0 {
|
if webId <= 0 {
|
||||||
return errors.New("invalid webId")
|
return errors.New("invalid webId")
|
||||||
@@ -406,7 +451,7 @@ func (this *HTTPWebDAO) UpdateWebRequestHeaderPolicy(tx *dbs.Tx, webId int64, he
|
|||||||
return this.NotifyUpdate(tx, webId)
|
return this.NotifyUpdate(tx, webId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更改响应Header策略
|
// UpdateWebResponseHeaderPolicy 更改响应Header策略
|
||||||
func (this *HTTPWebDAO) UpdateWebResponseHeaderPolicy(tx *dbs.Tx, webId int64, headerPolicyJSON []byte) error {
|
func (this *HTTPWebDAO) UpdateWebResponseHeaderPolicy(tx *dbs.Tx, webId int64, headerPolicyJSON []byte) error {
|
||||||
if webId <= 0 {
|
if webId <= 0 {
|
||||||
return errors.New("invalid webId")
|
return errors.New("invalid webId")
|
||||||
@@ -422,7 +467,7 @@ func (this *HTTPWebDAO) UpdateWebResponseHeaderPolicy(tx *dbs.Tx, webId int64, h
|
|||||||
return this.NotifyUpdate(tx, webId)
|
return this.NotifyUpdate(tx, webId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更改特殊页面配置
|
// UpdateWebPages 更改特殊页面配置
|
||||||
func (this *HTTPWebDAO) UpdateWebPages(tx *dbs.Tx, webId int64, pagesJSON []byte) error {
|
func (this *HTTPWebDAO) UpdateWebPages(tx *dbs.Tx, webId int64, pagesJSON []byte) error {
|
||||||
if webId <= 0 {
|
if webId <= 0 {
|
||||||
return errors.New("invalid webId")
|
return errors.New("invalid webId")
|
||||||
@@ -438,7 +483,7 @@ func (this *HTTPWebDAO) UpdateWebPages(tx *dbs.Tx, webId int64, pagesJSON []byte
|
|||||||
return this.NotifyUpdate(tx, webId)
|
return this.NotifyUpdate(tx, webId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更改Shutdown配置
|
// UpdateWebShutdown 更改Shutdown配置
|
||||||
func (this *HTTPWebDAO) UpdateWebShutdown(tx *dbs.Tx, webId int64, shutdownJSON []byte) error {
|
func (this *HTTPWebDAO) UpdateWebShutdown(tx *dbs.Tx, webId int64, shutdownJSON []byte) error {
|
||||||
if webId <= 0 {
|
if webId <= 0 {
|
||||||
return errors.New("invalid webId")
|
return errors.New("invalid webId")
|
||||||
@@ -454,7 +499,7 @@ func (this *HTTPWebDAO) UpdateWebShutdown(tx *dbs.Tx, webId int64, shutdownJSON
|
|||||||
return this.NotifyUpdate(tx, webId)
|
return this.NotifyUpdate(tx, webId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更改访问日志策略
|
// UpdateWebAccessLogConfig 更改访问日志策略
|
||||||
func (this *HTTPWebDAO) UpdateWebAccessLogConfig(tx *dbs.Tx, webId int64, accessLogJSON []byte) error {
|
func (this *HTTPWebDAO) UpdateWebAccessLogConfig(tx *dbs.Tx, webId int64, accessLogJSON []byte) error {
|
||||||
if webId <= 0 {
|
if webId <= 0 {
|
||||||
return errors.New("invalid webId")
|
return errors.New("invalid webId")
|
||||||
@@ -470,7 +515,7 @@ func (this *HTTPWebDAO) UpdateWebAccessLogConfig(tx *dbs.Tx, webId int64, access
|
|||||||
return this.NotifyUpdate(tx, webId)
|
return this.NotifyUpdate(tx, webId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更改统计配置
|
// UpdateWebStat 更改统计配置
|
||||||
func (this *HTTPWebDAO) UpdateWebStat(tx *dbs.Tx, webId int64, statJSON []byte) error {
|
func (this *HTTPWebDAO) UpdateWebStat(tx *dbs.Tx, webId int64, statJSON []byte) error {
|
||||||
if webId <= 0 {
|
if webId <= 0 {
|
||||||
return errors.New("invalid webId")
|
return errors.New("invalid webId")
|
||||||
@@ -486,7 +531,7 @@ func (this *HTTPWebDAO) UpdateWebStat(tx *dbs.Tx, webId int64, statJSON []byte)
|
|||||||
return this.NotifyUpdate(tx, webId)
|
return this.NotifyUpdate(tx, webId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更改缓存配置
|
// UpdateWebCache 更改缓存配置
|
||||||
func (this *HTTPWebDAO) UpdateWebCache(tx *dbs.Tx, webId int64, cacheJSON []byte) error {
|
func (this *HTTPWebDAO) UpdateWebCache(tx *dbs.Tx, webId int64, cacheJSON []byte) error {
|
||||||
if webId <= 0 {
|
if webId <= 0 {
|
||||||
return errors.New("invalid webId")
|
return errors.New("invalid webId")
|
||||||
@@ -502,7 +547,7 @@ func (this *HTTPWebDAO) UpdateWebCache(tx *dbs.Tx, webId int64, cacheJSON []byte
|
|||||||
return this.NotifyUpdate(tx, webId)
|
return this.NotifyUpdate(tx, webId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更改防火墙配置
|
// UpdateWebFirewall 更改防火墙配置
|
||||||
func (this *HTTPWebDAO) UpdateWebFirewall(tx *dbs.Tx, webId int64, firewallJSON []byte) error {
|
func (this *HTTPWebDAO) UpdateWebFirewall(tx *dbs.Tx, webId int64, firewallJSON []byte) error {
|
||||||
if webId <= 0 {
|
if webId <= 0 {
|
||||||
return errors.New("invalid webId")
|
return errors.New("invalid webId")
|
||||||
@@ -518,7 +563,7 @@ func (this *HTTPWebDAO) UpdateWebFirewall(tx *dbs.Tx, webId int64, firewallJSON
|
|||||||
return this.NotifyUpdate(tx, webId)
|
return this.NotifyUpdate(tx, webId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更改路径规则配置
|
// UpdateWebLocations 更改路径规则配置
|
||||||
func (this *HTTPWebDAO) UpdateWebLocations(tx *dbs.Tx, webId int64, locationsJSON []byte) error {
|
func (this *HTTPWebDAO) UpdateWebLocations(tx *dbs.Tx, webId int64, locationsJSON []byte) error {
|
||||||
if webId <= 0 {
|
if webId <= 0 {
|
||||||
return errors.New("invalid webId")
|
return errors.New("invalid webId")
|
||||||
@@ -534,7 +579,7 @@ func (this *HTTPWebDAO) UpdateWebLocations(tx *dbs.Tx, webId int64, locationsJSO
|
|||||||
return this.NotifyUpdate(tx, webId)
|
return this.NotifyUpdate(tx, webId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更改跳转到HTTPS设置
|
// UpdateWebRedirectToHTTPS 更改跳转到HTTPS设置
|
||||||
func (this *HTTPWebDAO) UpdateWebRedirectToHTTPS(tx *dbs.Tx, webId int64, redirectToHTTPSJSON []byte) error {
|
func (this *HTTPWebDAO) UpdateWebRedirectToHTTPS(tx *dbs.Tx, webId int64, redirectToHTTPSJSON []byte) error {
|
||||||
if webId <= 0 {
|
if webId <= 0 {
|
||||||
return errors.New("invalid webId")
|
return errors.New("invalid webId")
|
||||||
@@ -550,7 +595,7 @@ func (this *HTTPWebDAO) UpdateWebRedirectToHTTPS(tx *dbs.Tx, webId int64, redire
|
|||||||
return this.NotifyUpdate(tx, webId)
|
return this.NotifyUpdate(tx, webId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改Websocket设置
|
// UpdateWebsocket 修改Websocket设置
|
||||||
func (this *HTTPWebDAO) UpdateWebsocket(tx *dbs.Tx, webId int64, websocketJSON []byte) error {
|
func (this *HTTPWebDAO) UpdateWebsocket(tx *dbs.Tx, webId int64, websocketJSON []byte) error {
|
||||||
if webId <= 0 {
|
if webId <= 0 {
|
||||||
return errors.New("invalid webId")
|
return errors.New("invalid webId")
|
||||||
@@ -566,7 +611,23 @@ func (this *HTTPWebDAO) UpdateWebsocket(tx *dbs.Tx, webId int64, websocketJSON [
|
|||||||
return this.NotifyUpdate(tx, webId)
|
return this.NotifyUpdate(tx, webId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改重写规则设置
|
// UpdateWebFastcgi 修改Fastcgi设置
|
||||||
|
func (this *HTTPWebDAO) UpdateWebFastcgi(tx *dbs.Tx, webId int64, fastcgiJSON []byte) error {
|
||||||
|
if webId <= 0 {
|
||||||
|
return errors.New("invalid webId")
|
||||||
|
}
|
||||||
|
op := NewHTTPWebOperator()
|
||||||
|
op.Id = webId
|
||||||
|
op.Fastcgi = JSONBytes(fastcgiJSON)
|
||||||
|
err := this.Save(tx, op)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.NotifyUpdate(tx, webId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateWebRewriteRules 修改重写规则设置
|
||||||
func (this *HTTPWebDAO) UpdateWebRewriteRules(tx *dbs.Tx, webId int64, rewriteRulesJSON []byte) error {
|
func (this *HTTPWebDAO) UpdateWebRewriteRules(tx *dbs.Tx, webId int64, rewriteRulesJSON []byte) error {
|
||||||
if webId <= 0 {
|
if webId <= 0 {
|
||||||
return errors.New("invalid webId")
|
return errors.New("invalid webId")
|
||||||
@@ -582,7 +643,23 @@ func (this *HTTPWebDAO) UpdateWebRewriteRules(tx *dbs.Tx, webId int64, rewriteRu
|
|||||||
return this.NotifyUpdate(tx, webId)
|
return this.NotifyUpdate(tx, webId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据缓存策略ID查找所有的WebId
|
// UpdateWebAuth 修改认证信息
|
||||||
|
func (this *HTTPWebDAO) UpdateWebAuth(tx *dbs.Tx, webId int64, authJSON []byte) error {
|
||||||
|
if webId <= 0 {
|
||||||
|
return errors.New("invalid webId")
|
||||||
|
}
|
||||||
|
op := NewHTTPWebOperator()
|
||||||
|
op.Id = webId
|
||||||
|
op.Auth = JSONBytes(authJSON)
|
||||||
|
err := this.Save(tx, op)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.NotifyUpdate(tx, webId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindAllWebIdsWithCachePolicyId 根据缓存策略ID查找所有的WebId
|
||||||
func (this *HTTPWebDAO) FindAllWebIdsWithCachePolicyId(tx *dbs.Tx, cachePolicyId int64) ([]int64, error) {
|
func (this *HTTPWebDAO) FindAllWebIdsWithCachePolicyId(tx *dbs.Tx, cachePolicyId int64) ([]int64, error) {
|
||||||
ones, err := this.Query(tx).
|
ones, err := this.Query(tx).
|
||||||
State(HTTPWebStateEnabled).
|
State(HTTPWebStateEnabled).
|
||||||
@@ -626,7 +703,7 @@ func (this *HTTPWebDAO) FindAllWebIdsWithCachePolicyId(tx *dbs.Tx, cachePolicyId
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据防火墙策略ID查找所有的WebId
|
// FindAllWebIdsWithHTTPFirewallPolicyId 根据防火墙策略ID查找所有的WebId
|
||||||
func (this *HTTPWebDAO) FindAllWebIdsWithHTTPFirewallPolicyId(tx *dbs.Tx, firewallPolicyId int64) ([]int64, error) {
|
func (this *HTTPWebDAO) FindAllWebIdsWithHTTPFirewallPolicyId(tx *dbs.Tx, firewallPolicyId int64) ([]int64, error) {
|
||||||
ones, err := this.Query(tx).
|
ones, err := this.Query(tx).
|
||||||
State(HTTPWebStateEnabled).
|
State(HTTPWebStateEnabled).
|
||||||
@@ -673,7 +750,7 @@ func (this *HTTPWebDAO) FindAllWebIdsWithHTTPFirewallPolicyId(tx *dbs.Tx, firewa
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找包含某个Location的Web
|
// FindEnabledWebIdWithLocationId 查找包含某个Location的Web
|
||||||
func (this *HTTPWebDAO) FindEnabledWebIdWithLocationId(tx *dbs.Tx, locationId int64) (webId int64, err error) {
|
func (this *HTTPWebDAO) FindEnabledWebIdWithLocationId(tx *dbs.Tx, locationId int64) (webId int64, err error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
State(HTTPWebStateEnabled).
|
State(HTTPWebStateEnabled).
|
||||||
@@ -683,7 +760,7 @@ func (this *HTTPWebDAO) FindEnabledWebIdWithLocationId(tx *dbs.Tx, locationId in
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找包含某个重写规则的Web
|
// FindEnabledWebIdWithRewriteRuleId 查找包含某个重写规则的Web
|
||||||
func (this *HTTPWebDAO) FindEnabledWebIdWithRewriteRuleId(tx *dbs.Tx, rewriteRuleId int64) (webId int64, err error) {
|
func (this *HTTPWebDAO) FindEnabledWebIdWithRewriteRuleId(tx *dbs.Tx, rewriteRuleId int64) (webId int64, err error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
State(HTTPWebStateEnabled).
|
State(HTTPWebStateEnabled).
|
||||||
@@ -693,7 +770,7 @@ func (this *HTTPWebDAO) FindEnabledWebIdWithRewriteRuleId(tx *dbs.Tx, rewriteRul
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找包含某个页面的Web
|
// FindEnabledWebIdWithPageId 查找包含某个页面的Web
|
||||||
func (this *HTTPWebDAO) FindEnabledWebIdWithPageId(tx *dbs.Tx, pageId int64) (webId int64, err error) {
|
func (this *HTTPWebDAO) FindEnabledWebIdWithPageId(tx *dbs.Tx, pageId int64) (webId int64, err error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
State(HTTPWebStateEnabled).
|
State(HTTPWebStateEnabled).
|
||||||
@@ -703,7 +780,7 @@ func (this *HTTPWebDAO) FindEnabledWebIdWithPageId(tx *dbs.Tx, pageId int64) (we
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找包含某个Header的Web
|
// FindEnabledWebIdWithHeaderPolicyId 查找包含某个Header的Web
|
||||||
func (this *HTTPWebDAO) FindEnabledWebIdWithHeaderPolicyId(tx *dbs.Tx, headerPolicyId int64) (webId int64, err error) {
|
func (this *HTTPWebDAO) FindEnabledWebIdWithHeaderPolicyId(tx *dbs.Tx, headerPolicyId int64) (webId int64, err error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
State(HTTPWebStateEnabled).
|
State(HTTPWebStateEnabled).
|
||||||
@@ -713,7 +790,7 @@ func (this *HTTPWebDAO) FindEnabledWebIdWithHeaderPolicyId(tx *dbs.Tx, headerPol
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找包含某个Gzip配置的Web
|
// FindEnabledWebIdWithGzipId 查找包含某个Gzip配置的Web
|
||||||
func (this *HTTPWebDAO) FindEnabledWebIdWithGzipId(tx *dbs.Tx, gzipId int64) (webId int64, err error) {
|
func (this *HTTPWebDAO) FindEnabledWebIdWithGzipId(tx *dbs.Tx, gzipId int64) (webId int64, err error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
State(HTTPWebStateEnabled).
|
State(HTTPWebStateEnabled).
|
||||||
@@ -723,7 +800,7 @@ func (this *HTTPWebDAO) FindEnabledWebIdWithGzipId(tx *dbs.Tx, gzipId int64) (we
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找包含某个Websocket配置的Web
|
// FindEnabledWebIdWithWebsocketId 查找包含某个Websocket配置的Web
|
||||||
func (this *HTTPWebDAO) FindEnabledWebIdWithWebsocketId(tx *dbs.Tx, websocketId int64) (webId int64, err error) {
|
func (this *HTTPWebDAO) FindEnabledWebIdWithWebsocketId(tx *dbs.Tx, websocketId int64) (webId int64, err error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
State(HTTPWebStateEnabled).
|
State(HTTPWebStateEnabled).
|
||||||
@@ -733,7 +810,27 @@ func (this *HTTPWebDAO) FindEnabledWebIdWithWebsocketId(tx *dbs.Tx, websocketId
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找使用此Web的Server
|
// FindEnabledWebIdWithFastcgiId 查找包含某个Fastcgi配置的Web
|
||||||
|
func (this *HTTPWebDAO) FindEnabledWebIdWithFastcgiId(tx *dbs.Tx, fastcgiId int64) (webId int64, err error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
State(HTTPWebStateEnabled).
|
||||||
|
ResultPk().
|
||||||
|
Where("JSON_CONTAINS(fastcgi, :jsonQuery)").
|
||||||
|
Param("jsonQuery", maps.Map{"fastcgiIds": fastcgiId}.AsJSON()).
|
||||||
|
FindInt64Col(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindEnabledWebIdWithHTTPAuthPolicyId 查找包含某个认证策略的Web
|
||||||
|
func (this *HTTPWebDAO) FindEnabledWebIdWithHTTPAuthPolicyId(tx *dbs.Tx, httpAuthPolicyId int64) (webId int64, err error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
State(HTTPWebStateEnabled).
|
||||||
|
ResultPk().
|
||||||
|
Where("JSON_CONTAINS(auth, :jsonQuery, '$.policyRefs')").
|
||||||
|
Param("jsonQuery", maps.Map{"authPolicyId": httpAuthPolicyId}.AsJSON()).
|
||||||
|
FindInt64Col(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindWebServerId 查找使用此Web的Server
|
||||||
func (this *HTTPWebDAO) FindWebServerId(tx *dbs.Tx, webId int64) (serverId int64, err error) {
|
func (this *HTTPWebDAO) FindWebServerId(tx *dbs.Tx, webId int64) (serverId int64, err error) {
|
||||||
if webId <= 0 {
|
if webId <= 0 {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
@@ -766,7 +863,7 @@ func (this *HTTPWebDAO) FindWebServerId(tx *dbs.Tx, webId int64) (serverId int64
|
|||||||
return this.FindWebServerId(tx, webId)
|
return this.FindWebServerId(tx, webId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查用户权限
|
// CheckUserWeb 检查用户权限
|
||||||
func (this *HTTPWebDAO) CheckUserWeb(tx *dbs.Tx, userId int64, webId int64) error {
|
func (this *HTTPWebDAO) CheckUserWeb(tx *dbs.Tx, userId int64, webId int64) error {
|
||||||
serverId, err := this.FindWebServerId(tx, webId)
|
serverId, err := this.FindWebServerId(tx, webId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -778,7 +875,7 @@ func (this *HTTPWebDAO) CheckUserWeb(tx *dbs.Tx, userId int64, webId int64) erro
|
|||||||
return SharedServerDAO.CheckUserServer(tx, userId, serverId)
|
return SharedServerDAO.CheckUserServer(tx, userId, serverId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置主机跳转
|
// UpdateWebHostRedirects 设置主机跳转
|
||||||
func (this *HTTPWebDAO) UpdateWebHostRedirects(tx *dbs.Tx, webId int64, hostRedirects []*serverconfigs.HTTPHostRedirectConfig) error {
|
func (this *HTTPWebDAO) UpdateWebHostRedirects(tx *dbs.Tx, webId int64, hostRedirects []*serverconfigs.HTTPHostRedirectConfig) error {
|
||||||
if webId <= 0 {
|
if webId <= 0 {
|
||||||
return errors.New("invalid ")
|
return errors.New("invalid ")
|
||||||
@@ -801,7 +898,7 @@ func (this *HTTPWebDAO) UpdateWebHostRedirects(tx *dbs.Tx, webId int64, hostRedi
|
|||||||
return this.NotifyUpdate(tx, webId)
|
return this.NotifyUpdate(tx, webId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找主机跳转
|
// FindWebHostRedirects 查找主机跳转
|
||||||
func (this *HTTPWebDAO) FindWebHostRedirects(tx *dbs.Tx, webId int64) ([]byte, error) {
|
func (this *HTTPWebDAO) FindWebHostRedirects(tx *dbs.Tx, webId int64) ([]byte, error) {
|
||||||
col, err := this.Query(tx).
|
col, err := this.Query(tx).
|
||||||
Pk(webId).
|
Pk(webId).
|
||||||
@@ -813,7 +910,7 @@ func (this *HTTPWebDAO) FindWebHostRedirects(tx *dbs.Tx, webId int64) ([]byte, e
|
|||||||
return []byte(col), nil
|
return []byte(col), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通知更新
|
// NotifyUpdate 通知更新
|
||||||
func (this *HTTPWebDAO) NotifyUpdate(tx *dbs.Tx, webId int64) error {
|
func (this *HTTPWebDAO) NotifyUpdate(tx *dbs.Tx, webId int64) error {
|
||||||
serverId, err := this.FindWebServerId(tx, webId)
|
serverId, err := this.FindWebServerId(tx, webId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
// HTTP Web
|
// HTTPWeb HTTP Web
|
||||||
type HTTPWeb struct {
|
type HTTPWeb struct {
|
||||||
Id uint32 `field:"id"` // ID
|
Id uint32 `field:"id"` // ID
|
||||||
IsOn uint8 `field:"isOn"` // 是否启用
|
IsOn uint8 `field:"isOn"` // 是否启用
|
||||||
@@ -27,6 +27,8 @@ type HTTPWeb struct {
|
|||||||
Websocket string `field:"websocket"` // Websocket设置
|
Websocket string `field:"websocket"` // Websocket设置
|
||||||
RewriteRules string `field:"rewriteRules"` // 重写规则配置
|
RewriteRules string `field:"rewriteRules"` // 重写规则配置
|
||||||
HostRedirects string `field:"hostRedirects"` // 域名跳转
|
HostRedirects string `field:"hostRedirects"` // 域名跳转
|
||||||
|
Fastcgi string `field:"fastcgi"` // Fastcgi配置
|
||||||
|
Auth string `field:"auth"` // 认证策略配置
|
||||||
}
|
}
|
||||||
|
|
||||||
type HTTPWebOperator struct {
|
type HTTPWebOperator struct {
|
||||||
@@ -55,6 +57,8 @@ type HTTPWebOperator struct {
|
|||||||
Websocket interface{} // Websocket设置
|
Websocket interface{} // Websocket设置
|
||||||
RewriteRules interface{} // 重写规则配置
|
RewriteRules interface{} // 重写规则配置
|
||||||
HostRedirects interface{} // 域名跳转
|
HostRedirects interface{} // 域名跳转
|
||||||
|
Fastcgi interface{} // Fastcgi配置
|
||||||
|
Auth interface{} // 认证策略配置
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHTTPWebOperator() *HTTPWebOperator {
|
func NewHTTPWebOperator() *HTTPWebOperator {
|
||||||
|
|||||||
51
internal/db/models/latest_item_dao.go
Normal file
51
internal/db/models/latest_item_dao.go
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
"github.com/iwind/TeaGo/Tea"
|
||||||
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LatestItemType = string
|
||||||
|
|
||||||
|
const (
|
||||||
|
LatestItemTypeCluster LatestItemType = "cluster"
|
||||||
|
LatestItemTypeServer LatestItemType = "server"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LatestItemDAO dbs.DAO
|
||||||
|
|
||||||
|
func NewLatestItemDAO() *LatestItemDAO {
|
||||||
|
return dbs.NewDAO(&LatestItemDAO{
|
||||||
|
DAOObject: dbs.DAOObject{
|
||||||
|
DB: Tea.Env,
|
||||||
|
Table: "edgeLatestItems",
|
||||||
|
Model: new(LatestItem),
|
||||||
|
PkName: "id",
|
||||||
|
},
|
||||||
|
}).(*LatestItemDAO)
|
||||||
|
}
|
||||||
|
|
||||||
|
var SharedLatestItemDAO *LatestItemDAO
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
dbs.OnReady(func() {
|
||||||
|
SharedLatestItemDAO = NewLatestItemDAO()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IncreaseItemCount 增加数量
|
||||||
|
func (this *LatestItemDAO) IncreaseItemCount(tx *dbs.Tx, itemType LatestItemType, itemId int64) error {
|
||||||
|
return this.Query(tx).
|
||||||
|
InsertOrUpdateQuickly(maps.Map{
|
||||||
|
"itemType": itemType,
|
||||||
|
"itemId": itemId,
|
||||||
|
"count": 1,
|
||||||
|
"updatedAt": time.Now().Unix(),
|
||||||
|
}, maps.Map{
|
||||||
|
"count": dbs.SQL("count+1"),
|
||||||
|
"updatedAt": time.Now().Unix(),
|
||||||
|
})
|
||||||
|
}
|
||||||
6
internal/db/models/latest_item_dao_test.go
Normal file
6
internal/db/models/latest_item_dao_test.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
|
)
|
||||||
22
internal/db/models/latest_item_model.go
Normal file
22
internal/db/models/latest_item_model.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
// LatestItem 最近的条目统计
|
||||||
|
type LatestItem struct {
|
||||||
|
Id uint64 `field:"id"` // ID
|
||||||
|
ItemType string `field:"itemType"` // Item类型
|
||||||
|
ItemId uint64 `field:"itemId"` // itemID
|
||||||
|
Count uint64 `field:"count"` // 数量
|
||||||
|
UpdatedAt uint64 `field:"updatedAt"` // 更新时间
|
||||||
|
}
|
||||||
|
|
||||||
|
type LatestItemOperator struct {
|
||||||
|
Id interface{} // ID
|
||||||
|
ItemType interface{} // Item类型
|
||||||
|
ItemId interface{} // itemID
|
||||||
|
Count interface{} // 数量
|
||||||
|
UpdatedAt interface{} // 更新时间
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLatestItemOperator() *LatestItemOperator {
|
||||||
|
return &LatestItemOperator{}
|
||||||
|
}
|
||||||
1
internal/db/models/latest_item_model_ext.go
Normal file
1
internal/db/models/latest_item_model_ext.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package models
|
||||||
@@ -37,6 +37,7 @@ const (
|
|||||||
MessageTypeLogCapacityOverflow MessageType = "LogCapacityOverflow" // 日志超出最大限制
|
MessageTypeLogCapacityOverflow MessageType = "LogCapacityOverflow" // 日志超出最大限制
|
||||||
MessageTypeServerNamesAuditingSuccess MessageType = "ServerNamesAuditingSuccess" // 服务域名审核成功
|
MessageTypeServerNamesAuditingSuccess MessageType = "ServerNamesAuditingSuccess" // 服务域名审核成功
|
||||||
MessageTypeServerNamesAuditingFailed MessageType = "ServerNamesAuditingFailed" // 服务域名审核失败
|
MessageTypeServerNamesAuditingFailed MessageType = "ServerNamesAuditingFailed" // 服务域名审核失败
|
||||||
|
MessageTypeThresholdSatisfied MessageType = "ThresholdSatisfied" // 满足阈值
|
||||||
)
|
)
|
||||||
|
|
||||||
type MessageDAO dbs.DAO
|
type MessageDAO dbs.DAO
|
||||||
@@ -112,7 +113,20 @@ func (this *MessageDAO) CreateClusterMessage(tx *dbs.Tx, clusterId int64, messag
|
|||||||
|
|
||||||
// CreateNodeMessage 创建节点消息
|
// CreateNodeMessage 创建节点消息
|
||||||
func (this *MessageDAO) CreateNodeMessage(tx *dbs.Tx, clusterId int64, nodeId int64, messageType MessageType, level string, subject string, body string, paramsJSON []byte) error {
|
func (this *MessageDAO) CreateNodeMessage(tx *dbs.Tx, clusterId int64, nodeId int64, messageType MessageType, level string, subject string, body string, paramsJSON []byte) error {
|
||||||
_, err := this.createMessage(tx, clusterId, nodeId, messageType, level, subject, body, paramsJSON)
|
// 检查N分钟内是否已经发送过
|
||||||
|
hash := this.calHash(subject, body, paramsJSON)
|
||||||
|
exists, err := this.Query(tx).
|
||||||
|
Attr("hash", hash).
|
||||||
|
Gt("createdAt", time.Now().Unix()-10*60). // 10分钟
|
||||||
|
Exist()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if exists {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = this.createMessage(tx, clusterId, nodeId, messageType, level, subject, body, paramsJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -144,11 +158,6 @@ func (this *MessageDAO) CreateNodeMessage(tx *dbs.Tx, clusterId int64, nodeId in
|
|||||||
|
|
||||||
// CreateMessage 创建普通消息
|
// CreateMessage 创建普通消息
|
||||||
func (this *MessageDAO) CreateMessage(tx *dbs.Tx, adminId int64, userId int64, messageType MessageType, level string, subject string, body string, paramsJSON []byte) error {
|
func (this *MessageDAO) CreateMessage(tx *dbs.Tx, adminId int64, userId int64, messageType MessageType, level string, subject string, body string, paramsJSON []byte) error {
|
||||||
h := md5.New()
|
|
||||||
h.Write([]byte(body))
|
|
||||||
h.Write(paramsJSON)
|
|
||||||
hash := fmt.Sprintf("%x", h.Sum(nil))
|
|
||||||
|
|
||||||
op := NewMessageOperator()
|
op := NewMessageOperator()
|
||||||
op.AdminId = adminId
|
op.AdminId = adminId
|
||||||
op.UserId = userId
|
op.UserId = userId
|
||||||
@@ -169,7 +178,7 @@ func (this *MessageDAO) CreateMessage(tx *dbs.Tx, adminId int64, userId int64, m
|
|||||||
op.State = MessageStateEnabled
|
op.State = MessageStateEnabled
|
||||||
op.IsRead = false
|
op.IsRead = false
|
||||||
op.Day = timeutil.Format("Ymd")
|
op.Day = timeutil.Format("Ymd")
|
||||||
op.Hash = hash
|
op.Hash = this.calHash(subject, body, paramsJSON)
|
||||||
err := this.Save(tx, op)
|
err := this.Save(tx, op)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -278,11 +287,6 @@ func (this *MessageDAO) CheckMessageUser(tx *dbs.Tx, messageId int64, adminId in
|
|||||||
|
|
||||||
// 创建消息
|
// 创建消息
|
||||||
func (this *MessageDAO) createMessage(tx *dbs.Tx, clusterId int64, nodeId int64, messageType MessageType, level string, subject string, body string, paramsJSON []byte) (int64, error) {
|
func (this *MessageDAO) createMessage(tx *dbs.Tx, clusterId int64, nodeId int64, messageType MessageType, level string, subject string, body string, paramsJSON []byte) (int64, error) {
|
||||||
h := md5.New()
|
|
||||||
h.Write([]byte(body))
|
|
||||||
h.Write(paramsJSON)
|
|
||||||
hash := fmt.Sprintf("%x", h.Sum(nil))
|
|
||||||
|
|
||||||
// TODO 检查同样的消息最近是否发送过
|
// TODO 检查同样的消息最近是否发送过
|
||||||
|
|
||||||
// 创建新消息
|
// 创建新消息
|
||||||
@@ -309,7 +313,7 @@ func (this *MessageDAO) createMessage(tx *dbs.Tx, clusterId int64, nodeId int64,
|
|||||||
op.State = MessageStateEnabled
|
op.State = MessageStateEnabled
|
||||||
op.CreatedAt = time.Now().Unix()
|
op.CreatedAt = time.Now().Unix()
|
||||||
op.Day = timeutil.Format("Ymd")
|
op.Day = timeutil.Format("Ymd")
|
||||||
op.Hash = hash
|
op.Hash = this.calHash(subject, body, paramsJSON)
|
||||||
|
|
||||||
err := this.Save(tx, op)
|
err := this.Save(tx, op)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -317,3 +321,12 @@ func (this *MessageDAO) createMessage(tx *dbs.Tx, clusterId int64, nodeId int64,
|
|||||||
}
|
}
|
||||||
return types.Int64(op.Id), nil
|
return types.Int64(op.Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 计算Hash
|
||||||
|
func (this *MessageDAO) calHash(subject string, body string, paramsJSON []byte) string {
|
||||||
|
h := md5.New()
|
||||||
|
h.Write([]byte(subject))
|
||||||
|
h.Write([]byte(body))
|
||||||
|
h.Write(paramsJSON)
|
||||||
|
return fmt.Sprintf("%x", h.Sum(nil))
|
||||||
|
}
|
||||||
|
|||||||
@@ -97,8 +97,8 @@ func (this *MessageReceiverDAO) CreateReceiver(tx *dbs.Tx, target MessageTaskTar
|
|||||||
return this.SaveInt64(tx, op)
|
return this.SaveInt64(tx, op)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindAllReceivers 查询接收人
|
// FindAllEnabledReceivers 查询接收人
|
||||||
func (this *MessageReceiverDAO) FindAllReceivers(tx *dbs.Tx, target MessageTaskTarget, messageType string) (result []*MessageReceiver, err error) {
|
func (this *MessageReceiverDAO) FindAllEnabledReceivers(tx *dbs.Tx, target MessageTaskTarget, messageType string) (result []*MessageReceiver, err error) {
|
||||||
query := this.Query(tx)
|
query := this.Query(tx)
|
||||||
if len(messageType) > 0 {
|
if len(messageType) > 0 {
|
||||||
query.Attr("type", []string{"*", messageType}) // *表示所有的
|
query.Attr("type", []string{"*", messageType}) // *表示所有的
|
||||||
@@ -113,3 +113,17 @@ func (this *MessageReceiverDAO) FindAllReceivers(tx *dbs.Tx, target MessageTaskT
|
|||||||
FindAll()
|
FindAll()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CountAllEnabledReceivers 计算接收人数量
|
||||||
|
func (this *MessageReceiverDAO) CountAllEnabledReceivers(tx *dbs.Tx, target MessageTaskTarget, messageType string) (int64, error) {
|
||||||
|
query := this.Query(tx)
|
||||||
|
if len(messageType) > 0 {
|
||||||
|
query.Attr("type", []string{"*", messageType}) // *表示所有的
|
||||||
|
}
|
||||||
|
return query.
|
||||||
|
Attr("clusterId", target.ClusterId).
|
||||||
|
Attr("nodeId", target.NodeId).
|
||||||
|
Attr("serverId", target.ServerId).
|
||||||
|
State(MessageReceiverStateEnabled).
|
||||||
|
Count()
|
||||||
|
}
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ func (this *MessageTaskDAO) UpdateMessageTaskStatus(tx *dbs.Tx, taskId int64, st
|
|||||||
|
|
||||||
// CreateMessageTasks 从集群、节点或者服务中创建任务
|
// CreateMessageTasks 从集群、节点或者服务中创建任务
|
||||||
func (this *MessageTaskDAO) CreateMessageTasks(tx *dbs.Tx, target MessageTaskTarget, messageType MessageType, subject string, body string) error {
|
func (this *MessageTaskDAO) CreateMessageTasks(tx *dbs.Tx, target MessageTaskTarget, messageType MessageType, subject string, body string) error {
|
||||||
receivers, err := SharedMessageReceiverDAO.FindAllReceivers(tx, target, messageType)
|
receivers, err := SharedMessageReceiverDAO.FindAllEnabledReceivers(tx, target, messageType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package models
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
@@ -111,7 +113,7 @@ func (this *MonitorNodeDAO) CreateMonitorNode(tx *dbs.Tx, name string, descripti
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
secret := rands.String(32)
|
secret := rands.String(32)
|
||||||
err = NewApiTokenDAO().CreateAPIToken(tx, uniqueId, secret, NodeRoleMonitor)
|
err = NewApiTokenDAO().CreateAPIToken(tx, uniqueId, secret, nodeconfigs.NodeRoleMonitor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -195,3 +197,13 @@ func (this *MonitorNodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, statusJSO
|
|||||||
Update()
|
Update()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CountAllLowerVersionNodes 计算所有节点中低于某个版本的节点数量
|
||||||
|
func (this *MonitorNodeDAO) CountAllLowerVersionNodes(tx *dbs.Tx, version string) (int64, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
State(MonitorNodeStateEnabled).
|
||||||
|
Where("status IS NOT NULL").
|
||||||
|
Where("(JSON_EXTRACT(status, '$.buildVersionCode') IS NULL OR JSON_EXTRACT(status, '$.buildVersionCode')<:version)").
|
||||||
|
Param("version", utils.VersionToLong(version)).
|
||||||
|
Count()
|
||||||
|
}
|
||||||
|
|||||||
145
internal/db/models/nameservers/ns_cluster_dao.go
Normal file
145
internal/db/models/nameservers/ns_cluster_dao.go
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
package nameservers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
"github.com/iwind/TeaGo/Tea"
|
||||||
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
NSClusterStateEnabled = 1 // 已启用
|
||||||
|
NSClusterStateDisabled = 0 // 已禁用
|
||||||
|
)
|
||||||
|
|
||||||
|
type NSClusterDAO dbs.DAO
|
||||||
|
|
||||||
|
func NewNSClusterDAO() *NSClusterDAO {
|
||||||
|
return dbs.NewDAO(&NSClusterDAO{
|
||||||
|
DAOObject: dbs.DAOObject{
|
||||||
|
DB: Tea.Env,
|
||||||
|
Table: "edgeNSClusters",
|
||||||
|
Model: new(NSCluster),
|
||||||
|
PkName: "id",
|
||||||
|
},
|
||||||
|
}).(*NSClusterDAO)
|
||||||
|
}
|
||||||
|
|
||||||
|
var SharedNSClusterDAO *NSClusterDAO
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
dbs.OnReady(func() {
|
||||||
|
SharedNSClusterDAO = NewNSClusterDAO()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// EnableNSCluster 启用条目
|
||||||
|
func (this *NSClusterDAO) EnableNSCluster(tx *dbs.Tx, id int64) error {
|
||||||
|
_, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Set("state", NSClusterStateEnabled).
|
||||||
|
Update()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DisableNSCluster 禁用条目
|
||||||
|
func (this *NSClusterDAO) DisableNSCluster(tx *dbs.Tx, id int64) error {
|
||||||
|
_, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Set("state", NSClusterStateDisabled).
|
||||||
|
Update()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindEnabledNSCluster 查找启用中的条目
|
||||||
|
func (this *NSClusterDAO) FindEnabledNSCluster(tx *dbs.Tx, id int64) (*NSCluster, error) {
|
||||||
|
result, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Attr("state", NSClusterStateEnabled).
|
||||||
|
Find()
|
||||||
|
if result == nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result.(*NSCluster), err
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindEnabledNSClusterName 查找启用中的条目名称
|
||||||
|
func (this *NSClusterDAO) FindEnabledNSClusterName(tx *dbs.Tx, id int64) (string, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
State(NSClusterStateEnabled).
|
||||||
|
Result("name").
|
||||||
|
FindStringCol("")
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateCluster 创建集群
|
||||||
|
func (this *NSClusterDAO) CreateCluster(tx *dbs.Tx, name string, accessLogRefJSON []byte) (int64, error) {
|
||||||
|
op := NewNSClusterOperator()
|
||||||
|
op.Name = name
|
||||||
|
|
||||||
|
if len(accessLogRefJSON) > 0 {
|
||||||
|
op.AccessLog = accessLogRefJSON
|
||||||
|
}
|
||||||
|
|
||||||
|
op.IsOn = true
|
||||||
|
op.State = NSClusterStateEnabled
|
||||||
|
return this.SaveInt64(tx, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateCluster 修改集群
|
||||||
|
func (this *NSClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name string, isOn bool) error {
|
||||||
|
if clusterId <= 0 {
|
||||||
|
return errors.New("invalid clusterId")
|
||||||
|
}
|
||||||
|
op := NewNSClusterOperator()
|
||||||
|
op.Id = clusterId
|
||||||
|
op.Name = name
|
||||||
|
op.IsOn = isOn
|
||||||
|
return this.Save(tx, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountAllEnabledClusters 计算可用集群数量
|
||||||
|
func (this *NSClusterDAO) CountAllEnabledClusters(tx *dbs.Tx) (int64, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
State(NSClusterStateEnabled).
|
||||||
|
Count()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListEnabledClusters 列出单页集群
|
||||||
|
func (this *NSClusterDAO) ListEnabledClusters(tx *dbs.Tx, offset int64, size int64) (result []*NSCluster, err error) {
|
||||||
|
_, err = this.Query(tx).
|
||||||
|
State(NSClusterStateEnabled).
|
||||||
|
Offset(offset).
|
||||||
|
Limit(size).
|
||||||
|
DescPk().
|
||||||
|
Slice(&result).
|
||||||
|
FindAll()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindAllEnabledClusters 列出所有集群
|
||||||
|
func (this *NSClusterDAO) FindAllEnabledClusters(tx *dbs.Tx) (result []*NSCluster, err error) {
|
||||||
|
_, err = this.Query(tx).
|
||||||
|
State(NSClusterStateEnabled).
|
||||||
|
DescPk().
|
||||||
|
Slice(&result).
|
||||||
|
FindAll()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateClusterAccessLog 设置访问日志
|
||||||
|
func (this *NSClusterDAO) UpdateClusterAccessLog(tx *dbs.Tx, clusterId int64, accessLogJSON []byte) error {
|
||||||
|
return this.Query(tx).
|
||||||
|
Pk(clusterId).
|
||||||
|
Set("accessLog", accessLogJSON).
|
||||||
|
UpdateQuickly()
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindClusterAccessLog 读取访问日志配置
|
||||||
|
func (this *NSClusterDAO) FindClusterAccessLog(tx *dbs.Tx, clusterId int64) ([]byte, error) {
|
||||||
|
accessLog, err := this.Query(tx).
|
||||||
|
Pk(clusterId).
|
||||||
|
Result("accessLog").
|
||||||
|
FindStringCol("")
|
||||||
|
return []byte(accessLog), err
|
||||||
|
}
|
||||||
6
internal/db/models/nameservers/ns_cluster_dao_test.go
Normal file
6
internal/db/models/nameservers/ns_cluster_dao_test.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package nameservers
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
|
)
|
||||||
24
internal/db/models/nameservers/ns_cluster_model.go
Normal file
24
internal/db/models/nameservers/ns_cluster_model.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package nameservers
|
||||||
|
|
||||||
|
// NSCluster 域名服务器集群
|
||||||
|
type NSCluster struct {
|
||||||
|
Id uint32 `field:"id"` // ID
|
||||||
|
IsOn uint8 `field:"isOn"` // 是否启用
|
||||||
|
Name string `field:"name"` // 集群名
|
||||||
|
InstallDir string `field:"installDir"` // 安装目录
|
||||||
|
State uint8 `field:"state"` // 状态
|
||||||
|
AccessLog string `field:"accessLog"` // 访问日志配置
|
||||||
|
}
|
||||||
|
|
||||||
|
type NSClusterOperator struct {
|
||||||
|
Id interface{} // ID
|
||||||
|
IsOn interface{} // 是否启用
|
||||||
|
Name interface{} // 集群名
|
||||||
|
InstallDir interface{} // 安装目录
|
||||||
|
State interface{} // 状态
|
||||||
|
AccessLog interface{} // 访问日志配置
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewNSClusterOperator() *NSClusterOperator {
|
||||||
|
return &NSClusterOperator{}
|
||||||
|
}
|
||||||
1
internal/db/models/nameservers/ns_cluster_model_ext.go
Normal file
1
internal/db/models/nameservers/ns_cluster_model_ext.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package nameservers
|
||||||
196
internal/db/models/nameservers/ns_domain_dao.go
Normal file
196
internal/db/models/nameservers/ns_domain_dao.go
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
package nameservers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
"github.com/iwind/TeaGo/Tea"
|
||||||
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
NSDomainStateEnabled = 1 // 已启用
|
||||||
|
NSDomainStateDisabled = 0 // 已禁用
|
||||||
|
)
|
||||||
|
|
||||||
|
type NSDomainDAO dbs.DAO
|
||||||
|
|
||||||
|
func NewNSDomainDAO() *NSDomainDAO {
|
||||||
|
return dbs.NewDAO(&NSDomainDAO{
|
||||||
|
DAOObject: dbs.DAOObject{
|
||||||
|
DB: Tea.Env,
|
||||||
|
Table: "edgeNSDomains",
|
||||||
|
Model: new(NSDomain),
|
||||||
|
PkName: "id",
|
||||||
|
},
|
||||||
|
}).(*NSDomainDAO)
|
||||||
|
}
|
||||||
|
|
||||||
|
var SharedNSDomainDAO *NSDomainDAO
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
dbs.OnReady(func() {
|
||||||
|
SharedNSDomainDAO = NewNSDomainDAO()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// EnableNSDomain 启用条目
|
||||||
|
func (this *NSDomainDAO) EnableNSDomain(tx *dbs.Tx, id int64) error {
|
||||||
|
_, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Set("state", NSDomainStateEnabled).
|
||||||
|
Update()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DisableNSDomain 禁用条目
|
||||||
|
func (this *NSDomainDAO) DisableNSDomain(tx *dbs.Tx, domainId int64) error {
|
||||||
|
version, err := this.IncreaseVersion(tx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = this.Query(tx).
|
||||||
|
Pk(domainId).
|
||||||
|
Set("state", NSDomainStateDisabled).
|
||||||
|
Set("version", version).
|
||||||
|
Update()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindEnabledNSDomain 查找启用中的条目
|
||||||
|
func (this *NSDomainDAO) FindEnabledNSDomain(tx *dbs.Tx, id int64) (*NSDomain, error) {
|
||||||
|
result, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Attr("state", NSDomainStateEnabled).
|
||||||
|
Find()
|
||||||
|
if result == nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result.(*NSDomain), err
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindNSDomainName 根据主键查找名称
|
||||||
|
func (this *NSDomainDAO) FindNSDomainName(tx *dbs.Tx, id int64) (string, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Result("name").
|
||||||
|
FindStringCol("")
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateDomain 创建域名
|
||||||
|
func (this *NSDomainDAO) CreateDomain(tx *dbs.Tx, clusterId int64, userId int64, name string) (int64, error) {
|
||||||
|
version, err := this.IncreaseVersion(tx)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
op := NewNSDomainOperator()
|
||||||
|
op.ClusterId = clusterId
|
||||||
|
op.UserId = userId
|
||||||
|
op.Name = name
|
||||||
|
op.Version = version
|
||||||
|
op.IsOn = true
|
||||||
|
op.State = NSDomainStateEnabled
|
||||||
|
return this.SaveInt64(tx, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateDomain 修改域名
|
||||||
|
func (this *NSDomainDAO) UpdateDomain(tx *dbs.Tx, domainId int64, clusterId int64, userId int64, isOn bool) error {
|
||||||
|
if domainId <= 0 {
|
||||||
|
return errors.New("invalid domainId")
|
||||||
|
}
|
||||||
|
|
||||||
|
version, err := this.IncreaseVersion(tx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
op := NewNSDomainOperator()
|
||||||
|
op.Id = domainId
|
||||||
|
op.ClusterId = clusterId
|
||||||
|
op.UserId = userId
|
||||||
|
op.IsOn = isOn
|
||||||
|
op.Version = version
|
||||||
|
return this.Save(tx, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountAllEnabledDomains 计算域名数量
|
||||||
|
func (this *NSDomainDAO) CountAllEnabledDomains(tx *dbs.Tx, clusterId int64, userId int64, keyword string) (int64, error) {
|
||||||
|
query := this.Query(tx)
|
||||||
|
if clusterId > 0 {
|
||||||
|
query.Attr("clusterId", clusterId)
|
||||||
|
} else {
|
||||||
|
query.Where("clusterId IN (SELECT id FROM " + SharedNSClusterDAO.Table + " WHERE state=1)")
|
||||||
|
}
|
||||||
|
if userId > 0 {
|
||||||
|
query.Attr("userId", userId)
|
||||||
|
} else {
|
||||||
|
query.Where("(userId=0 OR userId IN (SELECT id FROM " + models.SharedUserDAO.Table + " WHERE state=1))")
|
||||||
|
}
|
||||||
|
if len(keyword) > 0 {
|
||||||
|
query.Where("(name LIKE :keyword)").
|
||||||
|
Param("keyword", "%"+keyword+"%")
|
||||||
|
}
|
||||||
|
|
||||||
|
return query.
|
||||||
|
State(NSDomainStateEnabled).
|
||||||
|
Count()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListEnabledDomains 列出单页域名
|
||||||
|
func (this *NSDomainDAO) ListEnabledDomains(tx *dbs.Tx, clusterId int64, userId int64, keyword string, offset int64, size int64) (result []*NSDomain, err error) {
|
||||||
|
query := this.Query(tx)
|
||||||
|
if clusterId > 0 {
|
||||||
|
query.Attr("clusterId", clusterId)
|
||||||
|
} else {
|
||||||
|
query.Where("clusterId IN (SELECT id FROM " + SharedNSClusterDAO.Table + " WHERE state=1)")
|
||||||
|
}
|
||||||
|
if userId > 0 {
|
||||||
|
query.Attr("userId", userId)
|
||||||
|
} else {
|
||||||
|
query.Where("(userId=0 OR userId IN (SELECT id FROM " + models.SharedUserDAO.Table + " WHERE state=1))")
|
||||||
|
}
|
||||||
|
if len(keyword) > 0 {
|
||||||
|
query.Where("(name LIKE :keyword)").
|
||||||
|
Param("keyword", "%"+keyword+"%")
|
||||||
|
}
|
||||||
|
_, err = query.
|
||||||
|
State(NSDomainStateEnabled).
|
||||||
|
DescPk().
|
||||||
|
Offset(offset).
|
||||||
|
Limit(size).
|
||||||
|
Slice(&result).
|
||||||
|
FindAll()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// IncreaseVersion 增加版本
|
||||||
|
func (this *NSDomainDAO) IncreaseVersion(tx *dbs.Tx) (int64, error) {
|
||||||
|
return models.SharedSysLockerDAO.Increase(tx, "NS_DOMAIN_VERSION", 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListDomainsAfterVersion 列出某个版本后的域名
|
||||||
|
func (this *NSDomainDAO) ListDomainsAfterVersion(tx *dbs.Tx, version int64, size int64) (result []*NSDomain, err error) {
|
||||||
|
if size <= 0 {
|
||||||
|
size = 10000
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = this.Query(tx).
|
||||||
|
Gte("version", version).
|
||||||
|
Limit(size).
|
||||||
|
Asc("version").
|
||||||
|
Slice(&result).
|
||||||
|
FindAll()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindDomainIdWithName 根据名称查找域名
|
||||||
|
func (this *NSDomainDAO) FindDomainIdWithName(tx *dbs.Tx, clusterId int64, name string) (int64, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
Attr("clusterId", clusterId).
|
||||||
|
Attr("name", name).
|
||||||
|
State(NSDomainStateEnabled).
|
||||||
|
ResultPk().
|
||||||
|
FindInt64Col(0)
|
||||||
|
}
|
||||||
6
internal/db/models/nameservers/ns_domain_dao_test.go
Normal file
6
internal/db/models/nameservers/ns_domain_dao_test.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package nameservers
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
|
)
|
||||||
28
internal/db/models/nameservers/ns_domain_model.go
Normal file
28
internal/db/models/nameservers/ns_domain_model.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package nameservers
|
||||||
|
|
||||||
|
// NSDomain DNS域名
|
||||||
|
type NSDomain struct {
|
||||||
|
Id uint32 `field:"id"` // ID
|
||||||
|
ClusterId uint32 `field:"clusterId"` // 集群ID
|
||||||
|
UserId uint32 `field:"userId"` // 用户ID
|
||||||
|
IsOn uint8 `field:"isOn"` // 是否启用
|
||||||
|
Name string `field:"name"` // 域名
|
||||||
|
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||||
|
Version uint64 `field:"version"` // 版本
|
||||||
|
State uint8 `field:"state"` // 状态
|
||||||
|
}
|
||||||
|
|
||||||
|
type NSDomainOperator struct {
|
||||||
|
Id interface{} // ID
|
||||||
|
ClusterId interface{} // 集群ID
|
||||||
|
UserId interface{} // 用户ID
|
||||||
|
IsOn interface{} // 是否启用
|
||||||
|
Name interface{} // 域名
|
||||||
|
CreatedAt interface{} // 创建时间
|
||||||
|
Version interface{} // 版本
|
||||||
|
State interface{} // 状态
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewNSDomainOperator() *NSDomainOperator {
|
||||||
|
return &NSDomainOperator{}
|
||||||
|
}
|
||||||
1
internal/db/models/nameservers/ns_domain_model_ext.go
Normal file
1
internal/db/models/nameservers/ns_domain_model_ext.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package nameservers
|
||||||
392
internal/db/models/nameservers/ns_node_dao.go
Normal file
392
internal/db/models/nameservers/ns_node_dao.go
Normal file
@@ -0,0 +1,392 @@
|
|||||||
|
package nameservers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
"github.com/iwind/TeaGo/Tea"
|
||||||
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
"github.com/iwind/TeaGo/rands"
|
||||||
|
"github.com/iwind/TeaGo/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
NSNodeStateEnabled = 1 // 已启用
|
||||||
|
NSNodeStateDisabled = 0 // 已禁用
|
||||||
|
)
|
||||||
|
|
||||||
|
type NSNodeDAO dbs.DAO
|
||||||
|
|
||||||
|
func NewNSNodeDAO() *NSNodeDAO {
|
||||||
|
return dbs.NewDAO(&NSNodeDAO{
|
||||||
|
DAOObject: dbs.DAOObject{
|
||||||
|
DB: Tea.Env,
|
||||||
|
Table: "edgeNSNodes",
|
||||||
|
Model: new(NSNode),
|
||||||
|
PkName: "id",
|
||||||
|
},
|
||||||
|
}).(*NSNodeDAO)
|
||||||
|
}
|
||||||
|
|
||||||
|
var SharedNSNodeDAO *NSNodeDAO
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
dbs.OnReady(func() {
|
||||||
|
SharedNSNodeDAO = NewNSNodeDAO()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// EnableNSNode 启用条目
|
||||||
|
func (this *NSNodeDAO) EnableNSNode(tx *dbs.Tx, id int64) error {
|
||||||
|
_, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Set("state", NSNodeStateEnabled).
|
||||||
|
Update()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DisableNSNode 禁用条目
|
||||||
|
func (this *NSNodeDAO) DisableNSNode(tx *dbs.Tx, id int64) error {
|
||||||
|
_, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Set("state", NSNodeStateDisabled).
|
||||||
|
Update()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return this.NotifyUpdate(tx, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindEnabledNSNode 查找启用中的条目
|
||||||
|
func (this *NSNodeDAO) FindEnabledNSNode(tx *dbs.Tx, id int64) (*NSNode, error) {
|
||||||
|
result, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Attr("state", NSNodeStateEnabled).
|
||||||
|
Find()
|
||||||
|
if result == nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result.(*NSNode), err
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindAllEnabledNodesWithClusterId 查找一个集群下的所有节点
|
||||||
|
func (this *NSNodeDAO) FindAllEnabledNodesWithClusterId(tx *dbs.Tx, clusterId int64) (result []*NSNode, err error) {
|
||||||
|
_, err = this.Query(tx).
|
||||||
|
Attr("clusterId", clusterId).
|
||||||
|
State(NSNodeStateEnabled).
|
||||||
|
DescPk().
|
||||||
|
Slice(&result).
|
||||||
|
FindAll()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountAllEnabledNodes 所有集群的可用的节点数量
|
||||||
|
func (this *NSNodeDAO) CountAllEnabledNodes(tx *dbs.Tx) (int64, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
State(NSNodeStateEnabled).
|
||||||
|
Where("clusterId IN (SELECT id FROM " + SharedNSClusterDAO.Table + " WHERE state=1)").
|
||||||
|
Count()
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountAllEnabledNodesMatch 计算满足条件的节点数量
|
||||||
|
func (this *NSNodeDAO) CountAllEnabledNodesMatch(tx *dbs.Tx, clusterId int64, installState configutils.BoolState, activeState configutils.BoolState, keyword string) (int64, error) {
|
||||||
|
query := this.Query(tx)
|
||||||
|
if clusterId > 0 {
|
||||||
|
query.Attr("clusterId", clusterId)
|
||||||
|
}
|
||||||
|
// 安装状态
|
||||||
|
switch installState {
|
||||||
|
case configutils.BoolStateAll:
|
||||||
|
// 所有
|
||||||
|
case configutils.BoolStateYes:
|
||||||
|
query.Attr("isInstalled", 1)
|
||||||
|
case configutils.BoolStateNo:
|
||||||
|
query.Attr("isInstalled", 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 在线状态
|
||||||
|
switch activeState {
|
||||||
|
case configutils.BoolStateAll:
|
||||||
|
// 所有
|
||||||
|
case configutils.BoolStateYes:
|
||||||
|
query.Where("JSON_EXTRACT(status, '$.isActive') AND UNIX_TIMESTAMP()-JSON_EXTRACT(status, '$.updatedAt')<=60")
|
||||||
|
case configutils.BoolStateNo:
|
||||||
|
query.Where("(status IS NULL OR NOT JSON_EXTRACT(status, '$.isActive') OR UNIX_TIMESTAMP()-JSON_EXTRACT(status, '$.updatedAt')>60)")
|
||||||
|
}
|
||||||
|
if len(keyword) > 0 {
|
||||||
|
query.Where("(name LIKE :keyword)").
|
||||||
|
Param("keyword", "%"+keyword+"%")
|
||||||
|
}
|
||||||
|
|
||||||
|
return query.
|
||||||
|
State(NSNodeStateEnabled).
|
||||||
|
Count()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListAllEnabledNodesMatch 列出单页匹配的节点
|
||||||
|
func (this *NSNodeDAO) ListAllEnabledNodesMatch(tx *dbs.Tx, clusterId int64, installState configutils.BoolState, activeState configutils.BoolState, keyword string, offset int64, size int64) (result []*NSNode, err error) {
|
||||||
|
query := this.Query(tx)
|
||||||
|
|
||||||
|
// 安装状态
|
||||||
|
switch installState {
|
||||||
|
case configutils.BoolStateAll:
|
||||||
|
// 所有
|
||||||
|
case configutils.BoolStateYes:
|
||||||
|
query.Attr("isInstalled", 1)
|
||||||
|
case configutils.BoolStateNo:
|
||||||
|
query.Attr("isInstalled", 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 在线状态
|
||||||
|
switch activeState {
|
||||||
|
case configutils.BoolStateAll:
|
||||||
|
// 所有
|
||||||
|
case configutils.BoolStateYes:
|
||||||
|
query.Where("JSON_EXTRACT(status, '$.isActive') AND UNIX_TIMESTAMP()-JSON_EXTRACT(status, '$.updatedAt')<=60")
|
||||||
|
case configutils.BoolStateNo:
|
||||||
|
query.Where("(status IS NULL OR NOT JSON_EXTRACT(status, '$.isActive') OR UNIX_TIMESTAMP()-JSON_EXTRACT(status, '$.updatedAt')>60)")
|
||||||
|
}
|
||||||
|
|
||||||
|
if clusterId > 0 {
|
||||||
|
query.Attr("clusterId", clusterId)
|
||||||
|
}
|
||||||
|
if len(keyword) > 0 {
|
||||||
|
query.Where("(name LIKE :keyword)").
|
||||||
|
Param("keyword", "%"+keyword+"%")
|
||||||
|
}
|
||||||
|
_, err = query.
|
||||||
|
State(NSNodeStateEnabled).
|
||||||
|
Offset(offset).
|
||||||
|
Limit(size).
|
||||||
|
Slice(&result).
|
||||||
|
DescPk().
|
||||||
|
FindAll()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountAllLowerVersionNodesWithClusterId 计算单个集群中所有低于某个版本的节点数量
|
||||||
|
func (this *NSNodeDAO) CountAllLowerVersionNodesWithClusterId(tx *dbs.Tx, clusterId int64, os string, arch string, version string) (int64, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
State(NSNodeStateEnabled).
|
||||||
|
Attr("clusterId", clusterId).
|
||||||
|
Where("status IS NOT NULL").
|
||||||
|
Where("JSON_EXTRACT(status, '$.os')=:os").
|
||||||
|
Where("JSON_EXTRACT(status, '$.arch')=:arch").
|
||||||
|
Where("(JSON_EXTRACT(status, '$.buildVersionCode') IS NULL OR JSON_EXTRACT(status, '$.buildVersionCode')<:version)").
|
||||||
|
Param("os", os).
|
||||||
|
Param("arch", arch).
|
||||||
|
Param("version", utils.VersionToLong(version)).
|
||||||
|
Count()
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateNode 创建节点
|
||||||
|
func (this *NSNodeDAO) CreateNode(tx *dbs.Tx, adminId int64, name string, clusterId int64) (nodeId int64, err error) {
|
||||||
|
uniqueId, err := this.GenUniqueId(tx)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
secret := rands.String(32)
|
||||||
|
|
||||||
|
// 保存API Token
|
||||||
|
err = models.SharedApiTokenDAO.CreateAPIToken(tx, uniqueId, secret, nodeconfigs.NodeRoleDNS)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
op := NewNSNodeOperator()
|
||||||
|
op.AdminId = adminId
|
||||||
|
op.Name = name
|
||||||
|
op.UniqueId = uniqueId
|
||||||
|
op.Secret = secret
|
||||||
|
op.ClusterId = clusterId
|
||||||
|
op.IsOn = 1
|
||||||
|
op.State = NSNodeStateEnabled
|
||||||
|
err = this.Save(tx, op)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 通知节点更新
|
||||||
|
nodeId = types.Int64(op.Id)
|
||||||
|
err = this.NotifyUpdate(tx, nodeId)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 通知DNS更新
|
||||||
|
err = this.NotifyDNSUpdate(tx, nodeId)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodeId, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateNode 修改节点
|
||||||
|
func (this *NSNodeDAO) UpdateNode(tx *dbs.Tx, nodeId int64, name string, clusterId int64, isOn bool) error {
|
||||||
|
if nodeId <= 0 {
|
||||||
|
return errors.New("invalid nodeId")
|
||||||
|
}
|
||||||
|
op := NewNSNodeOperator()
|
||||||
|
op.Id = nodeId
|
||||||
|
op.Name = name
|
||||||
|
op.ClusterId = clusterId
|
||||||
|
op.IsOn = isOn
|
||||||
|
err := this.Save(tx, op)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = this.NotifyUpdate(tx, nodeId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.NotifyDNSUpdate(tx, nodeId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindEnabledNodeIdWithUniqueId 根据唯一ID获取节点ID
|
||||||
|
func (this *NSNodeDAO) FindEnabledNodeIdWithUniqueId(tx *dbs.Tx, uniqueId string) (int64, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
Attr("uniqueId", uniqueId).
|
||||||
|
Attr("state", NSNodeStateEnabled).
|
||||||
|
ResultPk().
|
||||||
|
FindInt64Col(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindNodeInstallStatus 查询节点的安装状态
|
||||||
|
func (this *NSNodeDAO) FindNodeInstallStatus(tx *dbs.Tx, nodeId int64) (*models.NodeInstallStatus, error) {
|
||||||
|
node, err := this.Query(tx).
|
||||||
|
Pk(nodeId).
|
||||||
|
Result("installStatus", "isInstalled").
|
||||||
|
Find()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if node == nil {
|
||||||
|
return nil, errors.New("not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
installStatus := node.(*NSNode).InstallStatus
|
||||||
|
isInstalled := node.(*NSNode).IsInstalled == 1
|
||||||
|
if len(installStatus) == 0 {
|
||||||
|
return models.NewNodeInstallStatus(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
status := &models.NodeInstallStatus{}
|
||||||
|
err = json.Unmarshal([]byte(installStatus), status)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if isInstalled {
|
||||||
|
status.IsFinished = true
|
||||||
|
status.IsOk = true
|
||||||
|
}
|
||||||
|
return status, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenUniqueId 生成唯一ID
|
||||||
|
func (this *NSNodeDAO) GenUniqueId(tx *dbs.Tx) (string, error) {
|
||||||
|
for {
|
||||||
|
uniqueId := rands.HexString(32)
|
||||||
|
ok, err := this.Query(tx).
|
||||||
|
Attr("uniqueId", uniqueId).
|
||||||
|
Exist()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return uniqueId, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateNodeIsInstalled 设置节点安装状态
|
||||||
|
func (this *NSNodeDAO) UpdateNodeIsInstalled(tx *dbs.Tx, nodeId int64, isInstalled bool) error {
|
||||||
|
_, err := this.Query(tx).
|
||||||
|
Pk(nodeId).
|
||||||
|
Set("isInstalled", isInstalled).
|
||||||
|
Set("installStatus", "null"). // 重置安装状态
|
||||||
|
Update()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateNodeStatus 更改节点状态
|
||||||
|
func (this NSNodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, statusJSON []byte) error {
|
||||||
|
if statusJSON == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
_, err := this.Query(tx).
|
||||||
|
Pk(nodeId).
|
||||||
|
Set("status", string(statusJSON)).
|
||||||
|
Update()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountAllLowerVersionNodes 计算所有节点中低于某个版本的节点数量
|
||||||
|
func (this *NSNodeDAO) CountAllLowerVersionNodes(tx *dbs.Tx, version string) (int64, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
State(NSNodeStateEnabled).
|
||||||
|
Where("status IS NOT NULL").
|
||||||
|
Where("(JSON_EXTRACT(status, '$.buildVersionCode') IS NULL OR JSON_EXTRACT(status, '$.buildVersionCode')<:version)").
|
||||||
|
Param("version", utils.VersionToLong(version)).
|
||||||
|
Count()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ComposeNodeConfig 组合节点配置
|
||||||
|
func (this *NSNodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64) (*dnsconfigs.NSNodeConfig, error) {
|
||||||
|
if nodeId <= 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
node, err := this.FindEnabledNSNode(tx, nodeId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if node == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
cluster, err := SharedNSClusterDAO.FindEnabledNSCluster(tx, int64(node.ClusterId))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if cluster == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
config := &dnsconfigs.NSNodeConfig{
|
||||||
|
Id: int64(node.Id),
|
||||||
|
ClusterId: int64(node.ClusterId),
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(cluster.AccessLog) > 0 {
|
||||||
|
ref := &dnsconfigs.AccessLogRef{}
|
||||||
|
err = json.Unmarshal([]byte(cluster.AccessLog), ref)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.AccessLogRef = ref
|
||||||
|
}
|
||||||
|
|
||||||
|
return config, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyUpdate 通知更新
|
||||||
|
func (this *NSNodeDAO) NotifyUpdate(tx *dbs.Tx, nodeId int64) error {
|
||||||
|
// TODO 先什么都不做
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyDNSUpdate 通知DNS更新
|
||||||
|
func (this *NSNodeDAO) NotifyDNSUpdate(tx *dbs.Tx, nodeId int64) error {
|
||||||
|
// TODO 先什么都不做
|
||||||
|
return nil
|
||||||
|
}
|
||||||
6
internal/db/models/nameservers/ns_node_dao_test.go
Normal file
6
internal/db/models/nameservers/ns_node_dao_test.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package nameservers
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
|
)
|
||||||
38
internal/db/models/nameservers/ns_node_model.go
Normal file
38
internal/db/models/nameservers/ns_node_model.go
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package nameservers
|
||||||
|
|
||||||
|
// NSNode 域名服务器节点
|
||||||
|
type NSNode struct {
|
||||||
|
Id uint32 `field:"id"` // ID
|
||||||
|
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||||
|
ClusterId uint32 `field:"clusterId"` // 集群ID
|
||||||
|
Name string `field:"name"` // 节点名称
|
||||||
|
IsOn uint8 `field:"isOn"` // 是否启用
|
||||||
|
Status string `field:"status"` // 运行状态
|
||||||
|
UniqueId string `field:"uniqueId"` // 节点ID
|
||||||
|
Secret string `field:"secret"` // 密钥
|
||||||
|
IsUp uint8 `field:"isUp"` // 是否运行
|
||||||
|
IsInstalled uint8 `field:"isInstalled"` // 是否已安装
|
||||||
|
InstallStatus string `field:"installStatus"` // 安装状态
|
||||||
|
InstallDir string `field:"installDir"` // 安装目录
|
||||||
|
State uint8 `field:"state"` // 状态
|
||||||
|
}
|
||||||
|
|
||||||
|
type NSNodeOperator struct {
|
||||||
|
Id interface{} // ID
|
||||||
|
AdminId interface{} // 管理员ID
|
||||||
|
ClusterId interface{} // 集群ID
|
||||||
|
Name interface{} // 节点名称
|
||||||
|
IsOn interface{} // 是否启用
|
||||||
|
Status interface{} // 运行状态
|
||||||
|
UniqueId interface{} // 节点ID
|
||||||
|
Secret interface{} // 密钥
|
||||||
|
IsUp interface{} // 是否运行
|
||||||
|
IsInstalled interface{} // 是否已安装
|
||||||
|
InstallStatus interface{} // 安装状态
|
||||||
|
InstallDir interface{} // 安装目录
|
||||||
|
State interface{} // 状态
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewNSNodeOperator() *NSNodeOperator {
|
||||||
|
return &NSNodeOperator{}
|
||||||
|
}
|
||||||
42
internal/db/models/nameservers/ns_node_model_ext.go
Normal file
42
internal/db/models/nameservers/ns_node_model_ext.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package nameservers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DecodeInstallStatus 安装状态
|
||||||
|
func (this *NSNode) DecodeInstallStatus() (*models.NodeInstallStatus, error) {
|
||||||
|
if len(this.InstallStatus) == 0 || this.InstallStatus == "null" {
|
||||||
|
return models.NewNodeInstallStatus(), nil
|
||||||
|
}
|
||||||
|
status := &models.NodeInstallStatus{}
|
||||||
|
err := json.Unmarshal([]byte(this.InstallStatus), status)
|
||||||
|
if err != nil {
|
||||||
|
return models.NewNodeInstallStatus(), err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果N秒钟没有更新状态,则认为不在运行
|
||||||
|
if status.IsRunning && status.UpdatedAt < time.Now().Unix()-10 {
|
||||||
|
status.IsRunning = false
|
||||||
|
status.IsFinished = true
|
||||||
|
status.Error = "timeout"
|
||||||
|
}
|
||||||
|
|
||||||
|
return status, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecodeStatus 节点状态
|
||||||
|
func (this *NSNode) DecodeStatus() (*nodeconfigs.NodeStatus, error) {
|
||||||
|
if len(this.Status) == 0 || this.Status == "null" {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
status := &nodeconfigs.NodeStatus{}
|
||||||
|
err := json.Unmarshal([]byte(this.Status), status)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return status, nil
|
||||||
|
}
|
||||||
220
internal/db/models/nameservers/ns_record_dao.go
Normal file
220
internal/db/models/nameservers/ns_record_dao.go
Normal file
@@ -0,0 +1,220 @@
|
|||||||
|
package nameservers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
"github.com/iwind/TeaGo/Tea"
|
||||||
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
NSRecordStateEnabled = 1 // 已启用
|
||||||
|
NSRecordStateDisabled = 0 // 已禁用
|
||||||
|
)
|
||||||
|
|
||||||
|
type NSRecordDAO dbs.DAO
|
||||||
|
|
||||||
|
func NewNSRecordDAO() *NSRecordDAO {
|
||||||
|
return dbs.NewDAO(&NSRecordDAO{
|
||||||
|
DAOObject: dbs.DAOObject{
|
||||||
|
DB: Tea.Env,
|
||||||
|
Table: "edgeNSRecords",
|
||||||
|
Model: new(NSRecord),
|
||||||
|
PkName: "id",
|
||||||
|
},
|
||||||
|
}).(*NSRecordDAO)
|
||||||
|
}
|
||||||
|
|
||||||
|
var SharedNSRecordDAO *NSRecordDAO
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
dbs.OnReady(func() {
|
||||||
|
SharedNSRecordDAO = NewNSRecordDAO()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// EnableNSRecord 启用条目
|
||||||
|
func (this *NSRecordDAO) EnableNSRecord(tx *dbs.Tx, id uint64) error {
|
||||||
|
_, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Set("state", NSRecordStateEnabled).
|
||||||
|
Update()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DisableNSRecord 禁用条目
|
||||||
|
func (this *NSRecordDAO) DisableNSRecord(tx *dbs.Tx, id int64) error {
|
||||||
|
version, err := this.IncreaseVersion(tx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Set("state", NSRecordStateDisabled).
|
||||||
|
Set("version", version).
|
||||||
|
Update()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindEnabledNSRecord 查找启用中的条目
|
||||||
|
func (this *NSRecordDAO) FindEnabledNSRecord(tx *dbs.Tx, id int64) (*NSRecord, error) {
|
||||||
|
result, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Attr("state", NSRecordStateEnabled).
|
||||||
|
Find()
|
||||||
|
if result == nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result.(*NSRecord), err
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindNSRecordName 根据主键查找名称
|
||||||
|
func (this *NSRecordDAO) FindNSRecordName(tx *dbs.Tx, id int64) (string, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Result("name").
|
||||||
|
FindStringCol("")
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateRecord 创建记录
|
||||||
|
func (this *NSRecordDAO) CreateRecord(tx *dbs.Tx, domainId int64, description string, name string, dnsType dnsconfigs.RecordType, value string, ttl int32, routeIds []int64) (int64, error) {
|
||||||
|
version, err := this.IncreaseVersion(tx)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
op := NewNSRecordOperator()
|
||||||
|
op.DomainId = domainId
|
||||||
|
op.Description = description
|
||||||
|
op.Name = name
|
||||||
|
op.Type = dnsType
|
||||||
|
op.Value = value
|
||||||
|
op.Ttl = ttl
|
||||||
|
|
||||||
|
if len(routeIds) == 0 {
|
||||||
|
op.RouteIds = "[]"
|
||||||
|
} else {
|
||||||
|
routeIds, err := json.Marshal(routeIds)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
op.RouteIds = routeIds
|
||||||
|
}
|
||||||
|
|
||||||
|
op.IsOn = true
|
||||||
|
op.State = NSRecordStateEnabled
|
||||||
|
op.Version = version
|
||||||
|
return this.SaveInt64(tx, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *NSRecordDAO) UpdateRecord(tx *dbs.Tx, recordId int64, description string, name string, dnsType dnsconfigs.RecordType, value string, ttl int32, routeIds []int64) error {
|
||||||
|
if recordId <= 0 {
|
||||||
|
return errors.New("invalid recordId")
|
||||||
|
}
|
||||||
|
|
||||||
|
version, err := this.IncreaseVersion(tx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
op := NewNSRecordOperator()
|
||||||
|
op.Id = recordId
|
||||||
|
op.Description = description
|
||||||
|
op.Name = name
|
||||||
|
op.Type = dnsType
|
||||||
|
op.Value = value
|
||||||
|
op.Ttl = ttl
|
||||||
|
|
||||||
|
if len(routeIds) == 0 {
|
||||||
|
op.RouteIds = "[]"
|
||||||
|
} else {
|
||||||
|
routeIds, err := json.Marshal(routeIds)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
op.RouteIds = routeIds
|
||||||
|
}
|
||||||
|
|
||||||
|
op.Version = version
|
||||||
|
|
||||||
|
return this.Save(tx, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *NSRecordDAO) CountAllEnabledRecords(tx *dbs.Tx, domainId int64, dnsType dnsconfigs.RecordType, keyword string, routeId int64) (int64, error) {
|
||||||
|
query := this.Query(tx).
|
||||||
|
Attr("domainId", domainId).
|
||||||
|
State(NSRecordStateEnabled)
|
||||||
|
if len(dnsType) > 0 {
|
||||||
|
query.Attr("type", dnsType)
|
||||||
|
}
|
||||||
|
if len(keyword) > 0 {
|
||||||
|
query.Where("(name LIKE :keyword OR value LIKE :keyword OR description LIKE :keyword)").
|
||||||
|
Param("keyword", "%"+keyword+"%")
|
||||||
|
}
|
||||||
|
if routeId > 0 {
|
||||||
|
query.JSONContains("routeIds", strconv.FormatInt(routeId, 10))
|
||||||
|
}
|
||||||
|
return query.Count()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *NSRecordDAO) ListEnabledRecords(tx *dbs.Tx, domainId int64, dnsType dnsconfigs.RecordType, keyword string, routeId int64, offset int64, size int64) (result []*NSRecord, err error) {
|
||||||
|
query := this.Query(tx).
|
||||||
|
Attr("domainId", domainId).
|
||||||
|
State(NSRecordStateEnabled)
|
||||||
|
if len(dnsType) > 0 {
|
||||||
|
query.Attr("type", dnsType)
|
||||||
|
}
|
||||||
|
if len(keyword) > 0 {
|
||||||
|
query.Where("(name LIKE :keyword OR value LIKE :keyword OR description LIKE :keyword)").
|
||||||
|
Param("keyword", "%"+keyword+"%")
|
||||||
|
}
|
||||||
|
if routeId > 0 {
|
||||||
|
query.JSONContains("routeIds", strconv.FormatInt(routeId, 10))
|
||||||
|
}
|
||||||
|
_, err = query.
|
||||||
|
DescPk().
|
||||||
|
Offset(offset).
|
||||||
|
Limit(size).
|
||||||
|
Slice(&result).
|
||||||
|
FindAll()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// IncreaseVersion 增加版本
|
||||||
|
func (this *NSRecordDAO) IncreaseVersion(tx *dbs.Tx) (int64, error) {
|
||||||
|
return models.SharedSysLockerDAO.Increase(tx, "NS_RECORD_VERSION", 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRecordsAfterVersion 列出某个版本后的记录
|
||||||
|
func (this *NSRecordDAO) ListRecordsAfterVersion(tx *dbs.Tx, version int64, size int64) (result []*NSRecord, err error) {
|
||||||
|
if size <= 0 {
|
||||||
|
size = 10000
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = this.Query(tx).
|
||||||
|
Gte("version", version).
|
||||||
|
Limit(size).
|
||||||
|
Asc("version").
|
||||||
|
Slice(&result).
|
||||||
|
FindAll()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindEnabledRecordWithName 查询单条记录
|
||||||
|
func (this *NSRecordDAO) FindEnabledRecordWithName(tx *dbs.Tx, domainId int64, recordName string, recordType dnsconfigs.RecordType) (*NSRecord, error) {
|
||||||
|
record, err := this.Query(tx).
|
||||||
|
State(NSRecordStateEnabled).
|
||||||
|
Attr("domainId", domainId).
|
||||||
|
Attr("name", recordName).
|
||||||
|
Attr("type", recordType).
|
||||||
|
Find()
|
||||||
|
if record == nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return record.(*NSRecord), nil
|
||||||
|
}
|
||||||
6
internal/db/models/nameservers/ns_record_dao_test.go
Normal file
6
internal/db/models/nameservers/ns_record_dao_test.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package nameservers
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
|
)
|
||||||
38
internal/db/models/nameservers/ns_record_model.go
Normal file
38
internal/db/models/nameservers/ns_record_model.go
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package nameservers
|
||||||
|
|
||||||
|
// NSRecord DNS记录
|
||||||
|
type NSRecord struct {
|
||||||
|
Id uint64 `field:"id"` // ID
|
||||||
|
DomainId uint32 `field:"domainId"` // 域名ID
|
||||||
|
IsOn uint8 `field:"isOn"` // 是否启用
|
||||||
|
Description string `field:"description"` // 备注
|
||||||
|
Name string `field:"name"` // 记录名
|
||||||
|
Type string `field:"type"` // 类型
|
||||||
|
Value string `field:"value"` // 值
|
||||||
|
Ttl uint32 `field:"ttl"` // TTL(秒)
|
||||||
|
Weight uint32 `field:"weight"` // 权重
|
||||||
|
RouteIds string `field:"routeIds"` // 线路
|
||||||
|
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||||
|
Version uint64 `field:"version"` //
|
||||||
|
State uint8 `field:"state"` // 状态
|
||||||
|
}
|
||||||
|
|
||||||
|
type NSRecordOperator struct {
|
||||||
|
Id interface{} // ID
|
||||||
|
DomainId interface{} // 域名ID
|
||||||
|
IsOn interface{} // 是否启用
|
||||||
|
Description interface{} // 备注
|
||||||
|
Name interface{} // 记录名
|
||||||
|
Type interface{} // 类型
|
||||||
|
Value interface{} // 值
|
||||||
|
Ttl interface{} // TTL(秒)
|
||||||
|
Weight interface{} // 权重
|
||||||
|
RouteIds interface{} // 线路
|
||||||
|
CreatedAt interface{} // 创建时间
|
||||||
|
Version interface{} //
|
||||||
|
State interface{} // 状态
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewNSRecordOperator() *NSRecordOperator {
|
||||||
|
return &NSRecordOperator{}
|
||||||
|
}
|
||||||
11
internal/db/models/nameservers/ns_record_model_ext.go
Normal file
11
internal/db/models/nameservers/ns_record_model_ext.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package nameservers
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
|
func (this *NSRecord) DecodeRouteIds() []int64 {
|
||||||
|
routeIds := []int64{}
|
||||||
|
if len(this.RouteIds) > 0 {
|
||||||
|
_ = json.Unmarshal([]byte(this.RouteIds), &routeIds)
|
||||||
|
}
|
||||||
|
return routeIds
|
||||||
|
}
|
||||||
192
internal/db/models/nameservers/ns_route_dao.go
Normal file
192
internal/db/models/nameservers/ns_route_dao.go
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
package nameservers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
"github.com/iwind/TeaGo/Tea"
|
||||||
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
NSRouteStateEnabled = 1 // 已启用
|
||||||
|
NSRouteStateDisabled = 0 // 已禁用
|
||||||
|
)
|
||||||
|
|
||||||
|
type NSRouteDAO dbs.DAO
|
||||||
|
|
||||||
|
func NewNSRouteDAO() *NSRouteDAO {
|
||||||
|
return dbs.NewDAO(&NSRouteDAO{
|
||||||
|
DAOObject: dbs.DAOObject{
|
||||||
|
DB: Tea.Env,
|
||||||
|
Table: "edgeNSRoutes",
|
||||||
|
Model: new(NSRoute),
|
||||||
|
PkName: "id",
|
||||||
|
},
|
||||||
|
}).(*NSRouteDAO)
|
||||||
|
}
|
||||||
|
|
||||||
|
var SharedNSRouteDAO *NSRouteDAO
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
dbs.OnReady(func() {
|
||||||
|
SharedNSRouteDAO = NewNSRouteDAO()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// EnableNSRoute 启用条目
|
||||||
|
func (this *NSRouteDAO) EnableNSRoute(tx *dbs.Tx, id int64) error {
|
||||||
|
_, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Set("state", NSRouteStateEnabled).
|
||||||
|
Update()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DisableNSRoute 禁用条目
|
||||||
|
func (this *NSRouteDAO) DisableNSRoute(tx *dbs.Tx, routeId int64) error {
|
||||||
|
version, err := this.IncreaseVersion(tx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = this.Query(tx).
|
||||||
|
Pk(routeId).
|
||||||
|
Set("state", NSRouteStateDisabled).
|
||||||
|
Set("version", version).
|
||||||
|
Update()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindEnabledNSRoute 查找启用中的条目
|
||||||
|
func (this *NSRouteDAO) FindEnabledNSRoute(tx *dbs.Tx, id int64) (*NSRoute, error) {
|
||||||
|
result, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Attr("state", NSRouteStateEnabled).
|
||||||
|
Find()
|
||||||
|
if result == nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result.(*NSRoute), err
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindNSRouteName 根据主键查找名称
|
||||||
|
func (this *NSRouteDAO) FindNSRouteName(tx *dbs.Tx, id int64) (string, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Result("name").
|
||||||
|
FindStringCol("")
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateRoute 创建线路
|
||||||
|
func (this *NSRouteDAO) CreateRoute(tx *dbs.Tx, clusterId int64, domainId int64, userId int64, name string, rangesJSON []byte) (int64, error) {
|
||||||
|
version, err := this.IncreaseVersion(tx)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
op := NewNSRouteOperator()
|
||||||
|
op.ClusterId = clusterId
|
||||||
|
op.DomainId = domainId
|
||||||
|
op.UserId = userId
|
||||||
|
op.Name = name
|
||||||
|
if len(rangesJSON) > 0 {
|
||||||
|
op.Ranges = rangesJSON
|
||||||
|
} else {
|
||||||
|
op.Ranges = "[]"
|
||||||
|
}
|
||||||
|
op.IsOn = true
|
||||||
|
op.State = NSRouteStateEnabled
|
||||||
|
op.Version = version
|
||||||
|
return this.SaveInt64(tx, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateRoute 修改线路
|
||||||
|
func (this *NSRouteDAO) UpdateRoute(tx *dbs.Tx, routeId int64, name string, rangesJSON []byte) error {
|
||||||
|
if routeId <= 0 {
|
||||||
|
return errors.New("invalid routeId")
|
||||||
|
}
|
||||||
|
|
||||||
|
version, err := this.IncreaseVersion(tx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
op := NewNSRouteOperator()
|
||||||
|
op.Id = routeId
|
||||||
|
op.Name = name
|
||||||
|
if len(rangesJSON) > 0 {
|
||||||
|
op.Ranges = rangesJSON
|
||||||
|
} else {
|
||||||
|
op.Ranges = "[]"
|
||||||
|
}
|
||||||
|
|
||||||
|
op.Version = version
|
||||||
|
|
||||||
|
return this.Save(tx, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateRouteOrders 修改线路排序
|
||||||
|
func (this *NSRouteDAO) UpdateRouteOrders(tx *dbs.Tx, routeIds []int64) error {
|
||||||
|
version, err := this.IncreaseVersion(tx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
order := len(routeIds)
|
||||||
|
for _, routeId := range routeIds {
|
||||||
|
_, err = this.Query(tx).
|
||||||
|
Pk(routeId).
|
||||||
|
Set("order", order).
|
||||||
|
Set("version", version).
|
||||||
|
Update()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
order--
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindAllEnabledRoutes 列出所有线路
|
||||||
|
func (this *NSRouteDAO) FindAllEnabledRoutes(tx *dbs.Tx, clusterId int64, domainId int64, userId int64) (result []*NSRoute, err error) {
|
||||||
|
query := this.Query(tx).
|
||||||
|
State(NSRouteStateEnabled).
|
||||||
|
Slice(&result).
|
||||||
|
Desc("order").
|
||||||
|
DescPk()
|
||||||
|
if clusterId > 0 {
|
||||||
|
query.Attr("clusterId", clusterId)
|
||||||
|
} else {
|
||||||
|
// 不查询所有集群的线路
|
||||||
|
query.Attr("clusterId", 0)
|
||||||
|
}
|
||||||
|
if domainId > 0 {
|
||||||
|
query.Attr("domainId", domainId)
|
||||||
|
}
|
||||||
|
if userId > 0 {
|
||||||
|
query.Attr("userId", userId)
|
||||||
|
}
|
||||||
|
_, err = query.FindAll()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// IncreaseVersion 增加版本
|
||||||
|
func (this *NSRouteDAO) IncreaseVersion(tx *dbs.Tx) (int64, error) {
|
||||||
|
return models.SharedSysLockerDAO.Increase(tx, "NS_ROUTE_VERSION", 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRoutesAfterVersion 列出某个版本后的域名
|
||||||
|
func (this *NSRouteDAO) ListRoutesAfterVersion(tx *dbs.Tx, version int64, size int64) (result []*NSRoute, err error) {
|
||||||
|
if size <= 0 {
|
||||||
|
size = 10000
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = this.Query(tx).
|
||||||
|
Gte("version", version).
|
||||||
|
Limit(size).
|
||||||
|
Asc("version").
|
||||||
|
Slice(&result).
|
||||||
|
FindAll()
|
||||||
|
return
|
||||||
|
}
|
||||||
6
internal/db/models/nameservers/ns_route_dao_test.go
Normal file
6
internal/db/models/nameservers/ns_route_dao_test.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package nameservers
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
|
)
|
||||||
32
internal/db/models/nameservers/ns_route_model.go
Normal file
32
internal/db/models/nameservers/ns_route_model.go
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package nameservers
|
||||||
|
|
||||||
|
// NSRoute DNS线路
|
||||||
|
type NSRoute struct {
|
||||||
|
Id uint32 `field:"id"` // ID
|
||||||
|
IsOn uint8 `field:"isOn"` // 是否启用
|
||||||
|
ClusterId uint32 `field:"clusterId"` // 集群ID
|
||||||
|
DomainId uint32 `field:"domainId"` // 域名ID
|
||||||
|
UserId uint32 `field:"userId"` // 用户ID
|
||||||
|
Name string `field:"name"` // 名称
|
||||||
|
Ranges string `field:"ranges"` // 范围
|
||||||
|
Order uint32 `field:"order"` // 排序
|
||||||
|
Version uint64 `field:"version"` // 版本号
|
||||||
|
State uint8 `field:"state"` // 状态
|
||||||
|
}
|
||||||
|
|
||||||
|
type NSRouteOperator struct {
|
||||||
|
Id interface{} // ID
|
||||||
|
IsOn interface{} // 是否启用
|
||||||
|
ClusterId interface{} // 集群ID
|
||||||
|
DomainId interface{} // 域名ID
|
||||||
|
UserId interface{} // 用户ID
|
||||||
|
Name interface{} // 名称
|
||||||
|
Ranges interface{} // 范围
|
||||||
|
Order interface{} // 排序
|
||||||
|
Version interface{} // 版本号
|
||||||
|
State interface{} // 状态
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewNSRouteOperator() *NSRouteOperator {
|
||||||
|
return &NSRouteOperator{}
|
||||||
|
}
|
||||||
1
internal/db/models/nameservers/ns_route_model_ext.go
Normal file
1
internal/db/models/nameservers/ns_route_model_ext.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package nameservers
|
||||||
@@ -44,7 +44,7 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启用条目
|
// EnableNodeCluster 启用条目
|
||||||
func (this *NodeClusterDAO) EnableNodeCluster(tx *dbs.Tx, id int64) error {
|
func (this *NodeClusterDAO) EnableNodeCluster(tx *dbs.Tx, id int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -53,7 +53,7 @@ func (this *NodeClusterDAO) EnableNodeCluster(tx *dbs.Tx, id int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 禁用条目
|
// DisableNodeCluster 禁用条目
|
||||||
func (this *NodeClusterDAO) DisableNodeCluster(tx *dbs.Tx, id int64) error {
|
func (this *NodeClusterDAO) DisableNodeCluster(tx *dbs.Tx, id int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -62,7 +62,7 @@ func (this *NodeClusterDAO) DisableNodeCluster(tx *dbs.Tx, id int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找集群
|
// FindEnabledNodeCluster 查找集群
|
||||||
func (this *NodeClusterDAO) FindEnabledNodeCluster(tx *dbs.Tx, id int64) (*NodeCluster, error) {
|
func (this *NodeClusterDAO) FindEnabledNodeCluster(tx *dbs.Tx, id int64) (*NodeCluster, error) {
|
||||||
result, err := this.Query(tx).
|
result, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -74,7 +74,7 @@ func (this *NodeClusterDAO) FindEnabledNodeCluster(tx *dbs.Tx, id int64) (*NodeC
|
|||||||
return result.(*NodeCluster), err
|
return result.(*NodeCluster), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据UniqueId获取ID
|
// FindEnabledClusterIdWithUniqueId 根据UniqueId获取ID
|
||||||
// TODO 增加缓存
|
// TODO 增加缓存
|
||||||
func (this *NodeClusterDAO) FindEnabledClusterIdWithUniqueId(tx *dbs.Tx, uniqueId string) (int64, error) {
|
func (this *NodeClusterDAO) FindEnabledClusterIdWithUniqueId(tx *dbs.Tx, uniqueId string) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
@@ -84,7 +84,7 @@ func (this *NodeClusterDAO) FindEnabledClusterIdWithUniqueId(tx *dbs.Tx, uniqueI
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据主键查找名称
|
// FindNodeClusterName 根据主键查找名称
|
||||||
func (this *NodeClusterDAO) FindNodeClusterName(tx *dbs.Tx, id int64) (string, error) {
|
func (this *NodeClusterDAO) FindNodeClusterName(tx *dbs.Tx, id int64) (string, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -92,7 +92,7 @@ func (this *NodeClusterDAO) FindNodeClusterName(tx *dbs.Tx, id int64) (string, e
|
|||||||
FindStringCol("")
|
FindStringCol("")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找所有可用的集群
|
// FindAllEnableClusters 查找所有可用的集群
|
||||||
func (this *NodeClusterDAO) FindAllEnableClusters(tx *dbs.Tx) (result []*NodeCluster, err error) {
|
func (this *NodeClusterDAO) FindAllEnableClusters(tx *dbs.Tx) (result []*NodeCluster, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(NodeClusterStateEnabled).
|
State(NodeClusterStateEnabled).
|
||||||
@@ -103,7 +103,7 @@ func (this *NodeClusterDAO) FindAllEnableClusters(tx *dbs.Tx) (result []*NodeClu
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找所有可用的集群Ids
|
// FindAllEnableClusterIds 查找所有可用的集群Ids
|
||||||
func (this *NodeClusterDAO) FindAllEnableClusterIds(tx *dbs.Tx) (result []int64, err error) {
|
func (this *NodeClusterDAO) FindAllEnableClusterIds(tx *dbs.Tx) (result []int64, err error) {
|
||||||
ones, err := this.Query(tx).
|
ones, err := this.Query(tx).
|
||||||
State(NodeClusterStateEnabled).
|
State(NodeClusterStateEnabled).
|
||||||
@@ -118,7 +118,7 @@ func (this *NodeClusterDAO) FindAllEnableClusterIds(tx *dbs.Tx) (result []int64,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建集群
|
// CreateCluster 创建集群
|
||||||
func (this *NodeClusterDAO) CreateCluster(tx *dbs.Tx, adminId int64, name string, grantId int64, installDir string, dnsDomainId int64, dnsName string, cachePolicyId int64, httpFirewallPolicyId int64, systemServices map[string]maps.Map) (clusterId int64, err error) {
|
func (this *NodeClusterDAO) CreateCluster(tx *dbs.Tx, adminId int64, name string, grantId int64, installDir string, dnsDomainId int64, dnsName string, cachePolicyId int64, httpFirewallPolicyId int64, systemServices map[string]maps.Map) (clusterId int64, err error) {
|
||||||
uniqueId, err := this.GenUniqueId(tx)
|
uniqueId, err := this.GenUniqueId(tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -126,7 +126,7 @@ func (this *NodeClusterDAO) CreateCluster(tx *dbs.Tx, adminId int64, name string
|
|||||||
}
|
}
|
||||||
|
|
||||||
secret := rands.String(32)
|
secret := rands.String(32)
|
||||||
err = SharedApiTokenDAO.CreateAPIToken(tx, uniqueId, secret, NodeRoleCluster)
|
err = SharedApiTokenDAO.CreateAPIToken(tx, uniqueId, secret, nodeconfigs.NodeRoleCluster)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
@@ -176,7 +176,7 @@ func (this *NodeClusterDAO) CreateCluster(tx *dbs.Tx, adminId int64, name string
|
|||||||
return types.Int64(op.Id), nil
|
return types.Int64(op.Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改集群
|
// UpdateCluster 修改集群
|
||||||
func (this *NodeClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name string, grantId int64, installDir string) error {
|
func (this *NodeClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name string, grantId int64, installDir string) error {
|
||||||
if clusterId <= 0 {
|
if clusterId <= 0 {
|
||||||
return errors.New("invalid clusterId")
|
return errors.New("invalid clusterId")
|
||||||
@@ -190,7 +190,7 @@ func (this *NodeClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name stri
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算所有集群数量
|
// CountAllEnabledClusters 计算所有集群数量
|
||||||
func (this *NodeClusterDAO) CountAllEnabledClusters(tx *dbs.Tx, keyword string) (int64, error) {
|
func (this *NodeClusterDAO) CountAllEnabledClusters(tx *dbs.Tx, keyword string) (int64, error) {
|
||||||
query := this.Query(tx).
|
query := this.Query(tx).
|
||||||
State(NodeClusterStateEnabled)
|
State(NodeClusterStateEnabled)
|
||||||
@@ -201,7 +201,7 @@ func (this *NodeClusterDAO) CountAllEnabledClusters(tx *dbs.Tx, keyword string)
|
|||||||
return query.Count()
|
return query.Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出单页集群
|
// ListEnabledClusters 列出单页集群
|
||||||
func (this *NodeClusterDAO) ListEnabledClusters(tx *dbs.Tx, keyword string, offset, size int64) (result []*NodeCluster, err error) {
|
func (this *NodeClusterDAO) ListEnabledClusters(tx *dbs.Tx, keyword string, offset, size int64) (result []*NodeCluster, err error) {
|
||||||
query := this.Query(tx).
|
query := this.Query(tx).
|
||||||
State(NodeClusterStateEnabled)
|
State(NodeClusterStateEnabled)
|
||||||
@@ -218,7 +218,7 @@ func (this *NodeClusterDAO) ListEnabledClusters(tx *dbs.Tx, keyword string, offs
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找所有API节点地址
|
// FindAllAPINodeAddrsWithCluster 查找所有API节点地址
|
||||||
func (this *NodeClusterDAO) FindAllAPINodeAddrsWithCluster(tx *dbs.Tx, clusterId int64) (result []string, err error) {
|
func (this *NodeClusterDAO) FindAllAPINodeAddrsWithCluster(tx *dbs.Tx, clusterId int64) (result []string, err error) {
|
||||||
one, err := this.Query(tx).
|
one, err := this.Query(tx).
|
||||||
Pk(clusterId).
|
Pk(clusterId).
|
||||||
@@ -274,7 +274,7 @@ func (this *NodeClusterDAO) FindAllAPINodeAddrsWithCluster(tx *dbs.Tx, clusterId
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找健康检查设置
|
// FindClusterHealthCheckConfig 查找健康检查设置
|
||||||
func (this *NodeClusterDAO) FindClusterHealthCheckConfig(tx *dbs.Tx, clusterId int64) (*serverconfigs.HealthCheckConfig, error) {
|
func (this *NodeClusterDAO) FindClusterHealthCheckConfig(tx *dbs.Tx, clusterId int64) (*serverconfigs.HealthCheckConfig, error) {
|
||||||
col, err := this.Query(tx).
|
col, err := this.Query(tx).
|
||||||
Pk(clusterId).
|
Pk(clusterId).
|
||||||
@@ -295,7 +295,7 @@ func (this *NodeClusterDAO) FindClusterHealthCheckConfig(tx *dbs.Tx, clusterId i
|
|||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改健康检查设置
|
// UpdateClusterHealthCheck 修改健康检查设置
|
||||||
func (this *NodeClusterDAO) UpdateClusterHealthCheck(tx *dbs.Tx, clusterId int64, healthCheckJSON []byte) error {
|
func (this *NodeClusterDAO) UpdateClusterHealthCheck(tx *dbs.Tx, clusterId int64, healthCheckJSON []byte) error {
|
||||||
if clusterId <= 0 {
|
if clusterId <= 0 {
|
||||||
return errors.New("invalid clusterId '" + strconv.FormatInt(clusterId, 10) + "'")
|
return errors.New("invalid clusterId '" + strconv.FormatInt(clusterId, 10) + "'")
|
||||||
@@ -310,7 +310,7 @@ func (this *NodeClusterDAO) UpdateClusterHealthCheck(tx *dbs.Tx, clusterId int64
|
|||||||
return this.NotifyUpdate(tx, clusterId)
|
return this.NotifyUpdate(tx, clusterId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算使用某个认证的集群数量
|
// CountAllEnabledClustersWithGrantId 计算使用某个认证的集群数量
|
||||||
func (this *NodeClusterDAO) CountAllEnabledClustersWithGrantId(tx *dbs.Tx, grantId int64) (int64, error) {
|
func (this *NodeClusterDAO) CountAllEnabledClustersWithGrantId(tx *dbs.Tx, grantId int64) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
State(NodeClusterStateEnabled).
|
State(NodeClusterStateEnabled).
|
||||||
@@ -318,7 +318,7 @@ func (this *NodeClusterDAO) CountAllEnabledClustersWithGrantId(tx *dbs.Tx, grant
|
|||||||
Count()
|
Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取使用某个认证的所有集群
|
// FindAllEnabledClustersWithGrantId 获取使用某个认证的所有集群
|
||||||
func (this *NodeClusterDAO) FindAllEnabledClustersWithGrantId(tx *dbs.Tx, grantId int64) (result []*NodeCluster, err error) {
|
func (this *NodeClusterDAO) FindAllEnabledClustersWithGrantId(tx *dbs.Tx, grantId int64) (result []*NodeCluster, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(NodeClusterStateEnabled).
|
State(NodeClusterStateEnabled).
|
||||||
@@ -329,7 +329,7 @@ func (this *NodeClusterDAO) FindAllEnabledClustersWithGrantId(tx *dbs.Tx, grantI
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算使用某个DNS服务商的集群数量
|
// CountAllEnabledClustersWithDNSProviderId 计算使用某个DNS服务商的集群数量
|
||||||
func (this *NodeClusterDAO) CountAllEnabledClustersWithDNSProviderId(tx *dbs.Tx, dnsProviderId int64) (int64, error) {
|
func (this *NodeClusterDAO) CountAllEnabledClustersWithDNSProviderId(tx *dbs.Tx, dnsProviderId int64) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
State(NodeClusterStateEnabled).
|
State(NodeClusterStateEnabled).
|
||||||
@@ -338,7 +338,7 @@ func (this *NodeClusterDAO) CountAllEnabledClustersWithDNSProviderId(tx *dbs.Tx,
|
|||||||
Count()
|
Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取所有使用某个DNS服务商的集群
|
// FindAllEnabledClustersWithDNSProviderId 获取所有使用某个DNS服务商的集群
|
||||||
func (this *NodeClusterDAO) FindAllEnabledClustersWithDNSProviderId(tx *dbs.Tx, dnsProviderId int64) (result []*NodeCluster, err error) {
|
func (this *NodeClusterDAO) FindAllEnabledClustersWithDNSProviderId(tx *dbs.Tx, dnsProviderId int64) (result []*NodeCluster, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(NodeClusterStateEnabled).
|
State(NodeClusterStateEnabled).
|
||||||
@@ -350,7 +350,7 @@ func (this *NodeClusterDAO) FindAllEnabledClustersWithDNSProviderId(tx *dbs.Tx,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算使用某个DNS域名的集群数量
|
// CountAllEnabledClustersWithDNSDomainId 计算使用某个DNS域名的集群数量
|
||||||
func (this *NodeClusterDAO) CountAllEnabledClustersWithDNSDomainId(tx *dbs.Tx, dnsDomainId int64) (int64, error) {
|
func (this *NodeClusterDAO) CountAllEnabledClustersWithDNSDomainId(tx *dbs.Tx, dnsDomainId int64) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
State(NodeClusterStateEnabled).
|
State(NodeClusterStateEnabled).
|
||||||
@@ -358,7 +358,7 @@ func (this *NodeClusterDAO) CountAllEnabledClustersWithDNSDomainId(tx *dbs.Tx, d
|
|||||||
Count()
|
Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询使用某个DNS域名的集群ID列表
|
// FindAllEnabledClusterIdsWithDNSDomainId 查询使用某个DNS域名的集群ID列表
|
||||||
func (this *NodeClusterDAO) FindAllEnabledClusterIdsWithDNSDomainId(tx *dbs.Tx, dnsDomainId int64) ([]int64, error) {
|
func (this *NodeClusterDAO) FindAllEnabledClusterIdsWithDNSDomainId(tx *dbs.Tx, dnsDomainId int64) ([]int64, error) {
|
||||||
ones, err := this.Query(tx).
|
ones, err := this.Query(tx).
|
||||||
State(NodeClusterStateEnabled).
|
State(NodeClusterStateEnabled).
|
||||||
@@ -375,7 +375,7 @@ func (this *NodeClusterDAO) FindAllEnabledClusterIdsWithDNSDomainId(tx *dbs.Tx,
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询使用某个DNS域名的所有集群域名
|
// FindAllEnabledClustersWithDNSDomainId 查询使用某个DNS域名的所有集群域名
|
||||||
func (this *NodeClusterDAO) FindAllEnabledClustersWithDNSDomainId(tx *dbs.Tx, dnsDomainId int64) (result []*NodeCluster, err error) {
|
func (this *NodeClusterDAO) FindAllEnabledClustersWithDNSDomainId(tx *dbs.Tx, dnsDomainId int64) (result []*NodeCluster, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(NodeClusterStateEnabled).
|
State(NodeClusterStateEnabled).
|
||||||
@@ -386,7 +386,7 @@ func (this *NodeClusterDAO) FindAllEnabledClustersWithDNSDomainId(tx *dbs.Tx, dn
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询已经设置了域名的集群
|
// FindAllEnabledClustersHaveDNSDomain 查询已经设置了域名的集群
|
||||||
func (this *NodeClusterDAO) FindAllEnabledClustersHaveDNSDomain(tx *dbs.Tx) (result []*NodeCluster, err error) {
|
func (this *NodeClusterDAO) FindAllEnabledClustersHaveDNSDomain(tx *dbs.Tx) (result []*NodeCluster, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(NodeClusterStateEnabled).
|
State(NodeClusterStateEnabled).
|
||||||
@@ -397,7 +397,7 @@ func (this *NodeClusterDAO) FindAllEnabledClustersHaveDNSDomain(tx *dbs.Tx) (res
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找集群的认证ID
|
// FindClusterGrantId 查找集群的认证ID
|
||||||
func (this *NodeClusterDAO) FindClusterGrantId(tx *dbs.Tx, clusterId int64) (int64, error) {
|
func (this *NodeClusterDAO) FindClusterGrantId(tx *dbs.Tx, clusterId int64) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(clusterId).
|
Pk(clusterId).
|
||||||
@@ -405,7 +405,7 @@ func (this *NodeClusterDAO) FindClusterGrantId(tx *dbs.Tx, clusterId int64) (int
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找DNS信息
|
// FindClusterDNSInfo 查找DNS信息
|
||||||
func (this *NodeClusterDAO) FindClusterDNSInfo(tx *dbs.Tx, clusterId int64) (*NodeCluster, error) {
|
func (this *NodeClusterDAO) FindClusterDNSInfo(tx *dbs.Tx, clusterId int64) (*NodeCluster, error) {
|
||||||
one, err := this.Query(tx).
|
one, err := this.Query(tx).
|
||||||
Pk(clusterId).
|
Pk(clusterId).
|
||||||
@@ -420,7 +420,7 @@ func (this *NodeClusterDAO) FindClusterDNSInfo(tx *dbs.Tx, clusterId int64) (*No
|
|||||||
return one.(*NodeCluster), nil
|
return one.(*NodeCluster), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查某个子域名是否可用
|
// ExistClusterDNSName 检查某个子域名是否可用
|
||||||
func (this *NodeClusterDAO) ExistClusterDNSName(tx *dbs.Tx, dnsName string, excludeClusterId int64) (bool, error) {
|
func (this *NodeClusterDAO) ExistClusterDNSName(tx *dbs.Tx, dnsName string, excludeClusterId int64) (bool, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Attr("dnsName", dnsName).
|
Attr("dnsName", dnsName).
|
||||||
@@ -430,7 +430,7 @@ func (this *NodeClusterDAO) ExistClusterDNSName(tx *dbs.Tx, dnsName string, excl
|
|||||||
Exist()
|
Exist()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改集群DNS相关信息
|
// UpdateClusterDNS 修改集群DNS相关信息
|
||||||
func (this *NodeClusterDAO) UpdateClusterDNS(tx *dbs.Tx, clusterId int64, dnsName string, dnsDomainId int64, nodesAutoSync bool, serversAutoSync bool) error {
|
func (this *NodeClusterDAO) UpdateClusterDNS(tx *dbs.Tx, clusterId int64, dnsName string, dnsDomainId int64, nodesAutoSync bool, serversAutoSync bool) error {
|
||||||
if clusterId <= 0 {
|
if clusterId <= 0 {
|
||||||
return errors.New("invalid clusterId")
|
return errors.New("invalid clusterId")
|
||||||
@@ -461,7 +461,7 @@ func (this *NodeClusterDAO) UpdateClusterDNS(tx *dbs.Tx, clusterId int64, dnsNam
|
|||||||
return this.NotifyDNSUpdate(tx, clusterId)
|
return this.NotifyDNSUpdate(tx, clusterId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查集群的DNS问题
|
// CheckClusterDNS 检查集群的DNS问题
|
||||||
func (this *NodeClusterDAO) CheckClusterDNS(tx *dbs.Tx, cluster *NodeCluster) (issues []*pb.DNSIssue, err error) {
|
func (this *NodeClusterDAO) CheckClusterDNS(tx *dbs.Tx, cluster *NodeCluster) (issues []*pb.DNSIssue, err error) {
|
||||||
clusterId := int64(cluster.Id)
|
clusterId := int64(cluster.Id)
|
||||||
domainId := int64(cluster.DnsDomainId)
|
domainId := int64(cluster.DnsDomainId)
|
||||||
@@ -549,7 +549,7 @@ func (this *NodeClusterDAO) CheckClusterDNS(tx *dbs.Tx, cluster *NodeCluster) (i
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 检查IP地址
|
// 检查IP地址
|
||||||
ipAddr, err := SharedNodeIPAddressDAO.FindFirstNodeAccessIPAddress(tx, nodeId)
|
ipAddr, err := SharedNodeIPAddressDAO.FindFirstNodeAccessIPAddress(tx, nodeId, nodeconfigs.NodeRoleNode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -573,7 +573,7 @@ func (this *NodeClusterDAO) CheckClusterDNS(tx *dbs.Tx, cluster *NodeCluster) (i
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找集群所属管理员
|
// FindClusterAdminId 查找集群所属管理员
|
||||||
func (this *NodeClusterDAO) FindClusterAdminId(tx *dbs.Tx, clusterId int64) (int64, error) {
|
func (this *NodeClusterDAO) FindClusterAdminId(tx *dbs.Tx, clusterId int64) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(clusterId).
|
Pk(clusterId).
|
||||||
@@ -581,7 +581,7 @@ func (this *NodeClusterDAO) FindClusterAdminId(tx *dbs.Tx, clusterId int64) (int
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找集群的TOA设置
|
// FindClusterTOAConfig 查找集群的TOA设置
|
||||||
func (this *NodeClusterDAO) FindClusterTOAConfig(tx *dbs.Tx, clusterId int64) (*nodeconfigs.TOAConfig, error) {
|
func (this *NodeClusterDAO) FindClusterTOAConfig(tx *dbs.Tx, clusterId int64) (*nodeconfigs.TOAConfig, error) {
|
||||||
toa, err := this.Query(tx).
|
toa, err := this.Query(tx).
|
||||||
Pk(clusterId).
|
Pk(clusterId).
|
||||||
@@ -602,7 +602,7 @@ func (this *NodeClusterDAO) FindClusterTOAConfig(tx *dbs.Tx, clusterId int64) (*
|
|||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改集群的TOA设置
|
// UpdateClusterTOA 修改集群的TOA设置
|
||||||
func (this *NodeClusterDAO) UpdateClusterTOA(tx *dbs.Tx, clusterId int64, toaJSON []byte) error {
|
func (this *NodeClusterDAO) UpdateClusterTOA(tx *dbs.Tx, clusterId int64, toaJSON []byte) error {
|
||||||
if clusterId <= 0 {
|
if clusterId <= 0 {
|
||||||
return errors.New("invalid clusterId")
|
return errors.New("invalid clusterId")
|
||||||
@@ -617,7 +617,7 @@ func (this *NodeClusterDAO) UpdateClusterTOA(tx *dbs.Tx, clusterId int64, toaJSO
|
|||||||
return this.NotifyUpdate(tx, clusterId)
|
return this.NotifyUpdate(tx, clusterId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算使用某个缓存策略的集群数量
|
// CountAllEnabledNodeClustersWithHTTPCachePolicyId 计算使用某个缓存策略的集群数量
|
||||||
func (this *NodeClusterDAO) CountAllEnabledNodeClustersWithHTTPCachePolicyId(tx *dbs.Tx, httpCachePolicyId int64) (int64, error) {
|
func (this *NodeClusterDAO) CountAllEnabledNodeClustersWithHTTPCachePolicyId(tx *dbs.Tx, httpCachePolicyId int64) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
State(NodeClusterStateEnabled).
|
State(NodeClusterStateEnabled).
|
||||||
@@ -625,7 +625,7 @@ func (this *NodeClusterDAO) CountAllEnabledNodeClustersWithHTTPCachePolicyId(tx
|
|||||||
Count()
|
Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找使用缓存策略的所有集群
|
// FindAllEnabledNodeClustersWithHTTPCachePolicyId 查找使用缓存策略的所有集群
|
||||||
func (this *NodeClusterDAO) FindAllEnabledNodeClustersWithHTTPCachePolicyId(tx *dbs.Tx, httpCachePolicyId int64) (result []*NodeCluster, err error) {
|
func (this *NodeClusterDAO) FindAllEnabledNodeClustersWithHTTPCachePolicyId(tx *dbs.Tx, httpCachePolicyId int64) (result []*NodeCluster, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(NodeClusterStateEnabled).
|
State(NodeClusterStateEnabled).
|
||||||
@@ -636,7 +636,7 @@ func (this *NodeClusterDAO) FindAllEnabledNodeClustersWithHTTPCachePolicyId(tx *
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算使用某个WAF策略的集群数量
|
// CountAllEnabledNodeClustersWithHTTPFirewallPolicyId 计算使用某个WAF策略的集群数量
|
||||||
func (this *NodeClusterDAO) CountAllEnabledNodeClustersWithHTTPFirewallPolicyId(tx *dbs.Tx, httpFirewallPolicyId int64) (int64, error) {
|
func (this *NodeClusterDAO) CountAllEnabledNodeClustersWithHTTPFirewallPolicyId(tx *dbs.Tx, httpFirewallPolicyId int64) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
State(NodeClusterStateEnabled).
|
State(NodeClusterStateEnabled).
|
||||||
@@ -644,7 +644,7 @@ func (this *NodeClusterDAO) CountAllEnabledNodeClustersWithHTTPFirewallPolicyId(
|
|||||||
Count()
|
Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找使用WAF策略的所有集群
|
// FindAllEnabledNodeClustersWithHTTPFirewallPolicyId 查找使用WAF策略的所有集群
|
||||||
func (this *NodeClusterDAO) FindAllEnabledNodeClustersWithHTTPFirewallPolicyId(tx *dbs.Tx, httpFirewallPolicyId int64) (result []*NodeCluster, err error) {
|
func (this *NodeClusterDAO) FindAllEnabledNodeClustersWithHTTPFirewallPolicyId(tx *dbs.Tx, httpFirewallPolicyId int64) (result []*NodeCluster, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(NodeClusterStateEnabled).
|
State(NodeClusterStateEnabled).
|
||||||
@@ -655,7 +655,7 @@ func (this *NodeClusterDAO) FindAllEnabledNodeClustersWithHTTPFirewallPolicyId(t
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找使用WAF策略的所有集群Ids
|
// FindAllEnabledNodeClusterIdsWithHTTPFirewallPolicyId 查找使用WAF策略的所有集群Ids
|
||||||
func (this *NodeClusterDAO) FindAllEnabledNodeClusterIdsWithHTTPFirewallPolicyId(tx *dbs.Tx, httpFirewallPolicyId int64) (result []int64, err error) {
|
func (this *NodeClusterDAO) FindAllEnabledNodeClusterIdsWithHTTPFirewallPolicyId(tx *dbs.Tx, httpFirewallPolicyId int64) (result []int64, err error) {
|
||||||
ones, err := this.Query(tx).
|
ones, err := this.Query(tx).
|
||||||
State(NodeClusterStateEnabled).
|
State(NodeClusterStateEnabled).
|
||||||
@@ -668,7 +668,7 @@ func (this *NodeClusterDAO) FindAllEnabledNodeClusterIdsWithHTTPFirewallPolicyId
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找使用缓存策略的所有集群Ids
|
// FindAllEnabledNodeClusterIdsWithCachePolicyId 查找使用缓存策略的所有集群Ids
|
||||||
func (this *NodeClusterDAO) FindAllEnabledNodeClusterIdsWithCachePolicyId(tx *dbs.Tx, cachePolicyId int64) (result []int64, err error) {
|
func (this *NodeClusterDAO) FindAllEnabledNodeClusterIdsWithCachePolicyId(tx *dbs.Tx, cachePolicyId int64) (result []int64, err error) {
|
||||||
ones, err := this.Query(tx).
|
ones, err := this.Query(tx).
|
||||||
State(NodeClusterStateEnabled).
|
State(NodeClusterStateEnabled).
|
||||||
@@ -681,7 +681,7 @@ func (this *NodeClusterDAO) FindAllEnabledNodeClusterIdsWithCachePolicyId(tx *db
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取集群的WAF策略ID
|
// FindClusterHTTPFirewallPolicyId 获取集群的WAF策略ID
|
||||||
func (this *NodeClusterDAO) FindClusterHTTPFirewallPolicyId(tx *dbs.Tx, clusterId int64) (int64, error) {
|
func (this *NodeClusterDAO) FindClusterHTTPFirewallPolicyId(tx *dbs.Tx, clusterId int64) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(clusterId).
|
Pk(clusterId).
|
||||||
@@ -689,7 +689,7 @@ func (this *NodeClusterDAO) FindClusterHTTPFirewallPolicyId(tx *dbs.Tx, clusterI
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置集群的缓存策略
|
// UpdateNodeClusterHTTPCachePolicyId 设置集群的缓存策略
|
||||||
func (this *NodeClusterDAO) UpdateNodeClusterHTTPCachePolicyId(tx *dbs.Tx, clusterId int64, httpCachePolicyId int64) error {
|
func (this *NodeClusterDAO) UpdateNodeClusterHTTPCachePolicyId(tx *dbs.Tx, clusterId int64, httpCachePolicyId int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(clusterId).
|
Pk(clusterId).
|
||||||
@@ -701,7 +701,7 @@ func (this *NodeClusterDAO) UpdateNodeClusterHTTPCachePolicyId(tx *dbs.Tx, clust
|
|||||||
return this.NotifyUpdate(tx, clusterId)
|
return this.NotifyUpdate(tx, clusterId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取集群的缓存策略ID
|
// FindClusterHTTPCachePolicyId 获取集群的缓存策略ID
|
||||||
func (this *NodeClusterDAO) FindClusterHTTPCachePolicyId(tx *dbs.Tx, clusterId int64) (int64, error) {
|
func (this *NodeClusterDAO) FindClusterHTTPCachePolicyId(tx *dbs.Tx, clusterId int64) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(clusterId).
|
Pk(clusterId).
|
||||||
@@ -709,7 +709,7 @@ func (this *NodeClusterDAO) FindClusterHTTPCachePolicyId(tx *dbs.Tx, clusterId i
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置集群的WAF策略
|
// UpdateNodeClusterHTTPFirewallPolicyId 设置集群的WAF策略
|
||||||
func (this *NodeClusterDAO) UpdateNodeClusterHTTPFirewallPolicyId(tx *dbs.Tx, clusterId int64, httpFirewallPolicyId int64) error {
|
func (this *NodeClusterDAO) UpdateNodeClusterHTTPFirewallPolicyId(tx *dbs.Tx, clusterId int64, httpFirewallPolicyId int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(clusterId).
|
Pk(clusterId).
|
||||||
@@ -721,7 +721,7 @@ func (this *NodeClusterDAO) UpdateNodeClusterHTTPFirewallPolicyId(tx *dbs.Tx, cl
|
|||||||
return this.NotifyUpdate(tx, clusterId)
|
return this.NotifyUpdate(tx, clusterId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改集群的系统服务设置
|
// UpdateNodeClusterSystemService 修改集群的系统服务设置
|
||||||
func (this *NodeClusterDAO) UpdateNodeClusterSystemService(tx *dbs.Tx, clusterId int64, serviceType nodeconfigs.SystemServiceType, params maps.Map) error {
|
func (this *NodeClusterDAO) UpdateNodeClusterSystemService(tx *dbs.Tx, clusterId int64, serviceType nodeconfigs.SystemServiceType, params maps.Map) error {
|
||||||
if clusterId <= 0 {
|
if clusterId <= 0 {
|
||||||
return errors.New("invalid clusterId")
|
return errors.New("invalid clusterId")
|
||||||
@@ -760,7 +760,7 @@ func (this *NodeClusterDAO) UpdateNodeClusterSystemService(tx *dbs.Tx, clusterId
|
|||||||
return this.NotifyUpdate(tx, clusterId)
|
return this.NotifyUpdate(tx, clusterId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找集群的系统服务设置
|
// FindNodeClusterSystemServiceParams 查找集群的系统服务设置
|
||||||
func (this *NodeClusterDAO) FindNodeClusterSystemServiceParams(tx *dbs.Tx, clusterId int64, serviceType nodeconfigs.SystemServiceType) (params maps.Map, err error) {
|
func (this *NodeClusterDAO) FindNodeClusterSystemServiceParams(tx *dbs.Tx, clusterId int64, serviceType nodeconfigs.SystemServiceType) (params maps.Map, err error) {
|
||||||
if clusterId <= 0 {
|
if clusterId <= 0 {
|
||||||
return nil, errors.New("invalid clusterId")
|
return nil, errors.New("invalid clusterId")
|
||||||
@@ -782,7 +782,7 @@ func (this *NodeClusterDAO) FindNodeClusterSystemServiceParams(tx *dbs.Tx, clust
|
|||||||
return servicesMap[serviceType], nil
|
return servicesMap[serviceType], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找集群的所有服务设置
|
// FindNodeClusterSystemServices 查找集群的所有服务设置
|
||||||
func (this *NodeClusterDAO) FindNodeClusterSystemServices(tx *dbs.Tx, clusterId int64) (services map[string]maps.Map, err error) {
|
func (this *NodeClusterDAO) FindNodeClusterSystemServices(tx *dbs.Tx, clusterId int64) (services map[string]maps.Map, err error) {
|
||||||
if clusterId <= 0 {
|
if clusterId <= 0 {
|
||||||
return nil, errors.New("invalid clusterId")
|
return nil, errors.New("invalid clusterId")
|
||||||
@@ -804,7 +804,7 @@ func (this *NodeClusterDAO) FindNodeClusterSystemServices(tx *dbs.Tx, clusterId
|
|||||||
return servicesMap, nil
|
return servicesMap, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成唯一ID
|
// GenUniqueId 生成唯一ID
|
||||||
func (this *NodeClusterDAO) GenUniqueId(tx *dbs.Tx) (string, error) {
|
func (this *NodeClusterDAO) GenUniqueId(tx *dbs.Tx) (string, error) {
|
||||||
for {
|
for {
|
||||||
uniqueId := rands.HexString(32)
|
uniqueId := rands.HexString(32)
|
||||||
@@ -821,12 +821,28 @@ func (this *NodeClusterDAO) GenUniqueId(tx *dbs.Tx) (string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通知更新
|
// FindLatestNodeClusters 查询最近访问的集群
|
||||||
|
func (this *NodeClusterDAO) FindLatestNodeClusters(tx *dbs.Tx, size int64) (result []*NodeCluster, err error) {
|
||||||
|
itemTable := SharedLatestItemDAO.Table
|
||||||
|
itemType := LatestItemTypeCluster
|
||||||
|
_, err = this.Query(tx).
|
||||||
|
Result(this.Table+".id", this.Table+".name").
|
||||||
|
Join(SharedLatestItemDAO, dbs.QueryJoinRight, this.Table+".id="+itemTable+".itemId AND "+itemTable+".itemType='"+itemType+"'").
|
||||||
|
Asc("CEIL((UNIX_TIMESTAMP() - " + itemTable + ".updatedAt) / (7 * 86400))"). // 优先一个星期以内的
|
||||||
|
Desc(itemTable + ".count").
|
||||||
|
State(NodeClusterStateEnabled).
|
||||||
|
Limit(size).
|
||||||
|
Slice(&result).
|
||||||
|
FindAll()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyUpdate 通知更新
|
||||||
func (this *NodeClusterDAO) NotifyUpdate(tx *dbs.Tx, clusterId int64) error {
|
func (this *NodeClusterDAO) NotifyUpdate(tx *dbs.Tx, clusterId int64) error {
|
||||||
return SharedNodeTaskDAO.CreateClusterTask(tx, clusterId, NodeTaskTypeConfigChanged)
|
return SharedNodeTaskDAO.CreateClusterTask(tx, clusterId, NodeTaskTypeConfigChanged)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通知DNS更新
|
// NotifyDNSUpdate 通知DNS更新
|
||||||
// TODO 更新新的DNS解析记录的同时,需要删除老的DNS解析记录
|
// TODO 更新新的DNS解析记录的同时,需要删除老的DNS解析记录
|
||||||
func (this *NodeClusterDAO) NotifyDNSUpdate(tx *dbs.Tx, clusterId int64) error {
|
func (this *NodeClusterDAO) NotifyDNSUpdate(tx *dbs.Tx, clusterId int64) error {
|
||||||
err := dns.SharedDNSTaskDAO.CreateClusterTask(tx, clusterId, dns.DNSTaskTypeClusterChange)
|
err := dns.SharedDNSTaskDAO.CreateClusterTask(tx, clusterId, dns.DNSTaskTypeClusterChange)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
@@ -124,7 +125,7 @@ func (this *NodeDAO) CreateNode(tx *dbs.Tx, adminId int64, name string, clusterI
|
|||||||
secret := rands.String(32)
|
secret := rands.String(32)
|
||||||
|
|
||||||
// 保存API Token
|
// 保存API Token
|
||||||
err = SharedApiTokenDAO.CreateAPIToken(tx, uniqueId, secret, NodeRoleNode)
|
err = SharedApiTokenDAO.CreateAPIToken(tx, uniqueId, secret, nodeconfigs.NodeRoleNode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -161,7 +162,7 @@ func (this *NodeDAO) CreateNode(tx *dbs.Tx, adminId int64, name string, clusterI
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateNode 修改节点
|
// UpdateNode 修改节点
|
||||||
func (this *NodeDAO) UpdateNode(tx *dbs.Tx, nodeId int64, name string, clusterId int64, groupId int64, regionId int64, maxCPU int32, isOn bool) error {
|
func (this *NodeDAO) UpdateNode(tx *dbs.Tx, nodeId int64, name string, clusterId int64, groupId int64, regionId int64, maxCPU int32, isOn bool, maxCacheDiskCapacityJSON []byte, maxCacheMemoryCapacityJSON []byte) error {
|
||||||
if nodeId <= 0 {
|
if nodeId <= 0 {
|
||||||
return errors.New("invalid nodeId")
|
return errors.New("invalid nodeId")
|
||||||
}
|
}
|
||||||
@@ -174,6 +175,12 @@ func (this *NodeDAO) UpdateNode(tx *dbs.Tx, nodeId int64, name string, clusterId
|
|||||||
op.LatestVersion = dbs.SQL("latestVersion+1")
|
op.LatestVersion = dbs.SQL("latestVersion+1")
|
||||||
op.MaxCPU = maxCPU
|
op.MaxCPU = maxCPU
|
||||||
op.IsOn = isOn
|
op.IsOn = isOn
|
||||||
|
if len(maxCacheDiskCapacityJSON) > 0 {
|
||||||
|
op.MaxCacheDiskCapacity = maxCacheDiskCapacityJSON
|
||||||
|
}
|
||||||
|
if len(maxCacheMemoryCapacityJSON) > 0 {
|
||||||
|
op.MaxCacheMemoryCapacity = maxCacheMemoryCapacityJSON
|
||||||
|
}
|
||||||
err := this.Save(tx, op)
|
err := this.Save(tx, op)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -395,6 +402,27 @@ func (this *NodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, statusJSON []byt
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FindNodeStatus 获取节点状态
|
||||||
|
func (this *NodeDAO) FindNodeStatus(tx *dbs.Tx, nodeId int64) (*nodeconfigs.NodeStatus, error) {
|
||||||
|
statusJSONString, err := this.Query(tx).
|
||||||
|
Pk(nodeId).
|
||||||
|
Result("status").
|
||||||
|
FindStringCol("")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(statusJSONString) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
status := &nodeconfigs.NodeStatus{}
|
||||||
|
err = json.Unmarshal([]byte(statusJSONString), status)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return status, nil
|
||||||
|
}
|
||||||
|
|
||||||
// UpdateNodeIsActive 更改节点在线状态
|
// UpdateNodeIsActive 更改节点在线状态
|
||||||
func (this *NodeDAO) UpdateNodeIsActive(tx *dbs.Tx, nodeId int64, isActive bool) error {
|
func (this *NodeDAO) UpdateNodeIsActive(tx *dbs.Tx, nodeId int64, isActive bool) error {
|
||||||
b := "true"
|
b := "true"
|
||||||
@@ -558,6 +586,29 @@ func (this *NodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64) (*nodeconfigs.N
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 缓存最大容量设置
|
||||||
|
if len(node.MaxCacheDiskCapacity) > 0 {
|
||||||
|
capacity := &shared.SizeCapacity{}
|
||||||
|
err = json.Unmarshal([]byte(node.MaxCacheDiskCapacity), capacity)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if capacity.Count > 0 {
|
||||||
|
config.MaxCacheDiskCapacity = capacity
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(node.MaxCacheMemoryCapacity) > 0 {
|
||||||
|
capacity := &shared.SizeCapacity{}
|
||||||
|
err = json.Unmarshal([]byte(node.MaxCacheMemoryCapacity), capacity)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if capacity.Count > 0 {
|
||||||
|
config.MaxCacheMemoryCapacity = capacity
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TOA
|
// TOA
|
||||||
toaConfig, err := SharedNodeClusterDAO.FindClusterTOAConfig(tx, clusterId)
|
toaConfig, err := SharedNodeClusterDAO.FindClusterTOAConfig(tx, clusterId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -692,7 +743,7 @@ func (this *NodeDAO) FindAllNotInstalledNodesWithClusterId(tx *dbs.Tx, clusterId
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// CountAllLowerVersionNodesWithClusterId 计算所有低于某个版本的节点数量
|
// CountAllLowerVersionNodesWithClusterId 计算单个集群中所有低于某个版本的节点数量
|
||||||
func (this *NodeDAO) CountAllLowerVersionNodesWithClusterId(tx *dbs.Tx, clusterId int64, os string, arch string, version string) (int64, error) {
|
func (this *NodeDAO) CountAllLowerVersionNodesWithClusterId(tx *dbs.Tx, clusterId int64, os string, arch string, version string) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
State(NodeStateEnabled).
|
State(NodeStateEnabled).
|
||||||
@@ -707,7 +758,7 @@ func (this *NodeDAO) CountAllLowerVersionNodesWithClusterId(tx *dbs.Tx, clusterI
|
|||||||
Count()
|
Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindAllLowerVersionNodesWithClusterId 查找所有低于某个版本的节点
|
// FindAllLowerVersionNodesWithClusterId 查找单个集群中所有低于某个版本的节点
|
||||||
func (this *NodeDAO) FindAllLowerVersionNodesWithClusterId(tx *dbs.Tx, clusterId int64, os string, arch string, version string) (result []*Node, err error) {
|
func (this *NodeDAO) FindAllLowerVersionNodesWithClusterId(tx *dbs.Tx, clusterId int64, os string, arch string, version string) (result []*Node, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(NodeStateEnabled).
|
State(NodeStateEnabled).
|
||||||
@@ -725,6 +776,17 @@ func (this *NodeDAO) FindAllLowerVersionNodesWithClusterId(tx *dbs.Tx, clusterId
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CountAllLowerVersionNodes 计算所有集群中低于某个版本的节点数量
|
||||||
|
func (this *NodeDAO) CountAllLowerVersionNodes(tx *dbs.Tx, version string) (int64, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
State(NodeStateEnabled).
|
||||||
|
Where("clusterId IN (SELECT id FROM "+SharedNodeClusterDAO.Table+" WHERE state=1)").
|
||||||
|
Where("status IS NOT NULL").
|
||||||
|
Where("(JSON_EXTRACT(status, '$.buildVersionCode') IS NULL OR JSON_EXTRACT(status, '$.buildVersionCode')<:version)").
|
||||||
|
Param("version", utils.VersionToLong(version)).
|
||||||
|
Count()
|
||||||
|
}
|
||||||
|
|
||||||
// CountAllEnabledNodesWithGroupId 查找某个节点分组下的所有节点数量
|
// CountAllEnabledNodesWithGroupId 查找某个节点分组下的所有节点数量
|
||||||
func (this *NodeDAO) CountAllEnabledNodesWithGroupId(tx *dbs.Tx, groupId int64) (int64, error) {
|
func (this *NodeDAO) CountAllEnabledNodesWithGroupId(tx *dbs.Tx, groupId int64) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启用条目
|
// EnableNodeGrant 启用条目
|
||||||
func (this *NodeGrantDAO) EnableNodeGrant(tx *dbs.Tx, id uint32) (rowsAffected int64, err error) {
|
func (this *NodeGrantDAO) EnableNodeGrant(tx *dbs.Tx, id uint32) (rowsAffected int64, err error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -42,7 +42,7 @@ func (this *NodeGrantDAO) EnableNodeGrant(tx *dbs.Tx, id uint32) (rowsAffected i
|
|||||||
Update()
|
Update()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 禁用条目
|
// DisableNodeGrant 禁用条目
|
||||||
func (this *NodeGrantDAO) DisableNodeGrant(tx *dbs.Tx, id int64) (err error) {
|
func (this *NodeGrantDAO) DisableNodeGrant(tx *dbs.Tx, id int64) (err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -51,7 +51,7 @@ func (this *NodeGrantDAO) DisableNodeGrant(tx *dbs.Tx, id int64) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找启用中的条目
|
// FindEnabledNodeGrant 查找启用中的条目
|
||||||
func (this *NodeGrantDAO) FindEnabledNodeGrant(tx *dbs.Tx, id int64) (*NodeGrant, error) {
|
func (this *NodeGrantDAO) FindEnabledNodeGrant(tx *dbs.Tx, id int64) (*NodeGrant, error) {
|
||||||
result, err := this.Query(tx).
|
result, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -63,7 +63,7 @@ func (this *NodeGrantDAO) FindEnabledNodeGrant(tx *dbs.Tx, id int64) (*NodeGrant
|
|||||||
return result.(*NodeGrant), err
|
return result.(*NodeGrant), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据主键查找名称
|
// FindNodeGrantName 根据主键查找名称
|
||||||
func (this *NodeGrantDAO) FindNodeGrantName(tx *dbs.Tx, id uint32) (string, error) {
|
func (this *NodeGrantDAO) FindNodeGrantName(tx *dbs.Tx, id uint32) (string, error) {
|
||||||
name, err := this.Query(tx).
|
name, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -72,7 +72,7 @@ func (this *NodeGrantDAO) FindNodeGrantName(tx *dbs.Tx, id uint32) (string, erro
|
|||||||
return name.(string), err
|
return name.(string), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建认证信息
|
// CreateGrant 创建认证信息
|
||||||
func (this *NodeGrantDAO) CreateGrant(tx *dbs.Tx, adminId int64, name string, method string, username string, password string, privateKey string, description string, nodeId int64) (grantId int64, err error) {
|
func (this *NodeGrantDAO) CreateGrant(tx *dbs.Tx, adminId int64, name string, method string, username string, password string, privateKey string, description string, nodeId int64) (grantId int64, err error) {
|
||||||
op := NewNodeGrantOperator()
|
op := NewNodeGrantOperator()
|
||||||
op.AdminId = adminId
|
op.AdminId = adminId
|
||||||
@@ -94,7 +94,7 @@ func (this *NodeGrantDAO) CreateGrant(tx *dbs.Tx, adminId int64, name string, me
|
|||||||
return types.Int64(op.Id), err
|
return types.Int64(op.Id), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改认证信息
|
// UpdateGrant 修改认证信息
|
||||||
func (this *NodeGrantDAO) UpdateGrant(tx *dbs.Tx, grantId int64, name string, method string, username string, password string, privateKey string, description string, nodeId int64) error {
|
func (this *NodeGrantDAO) UpdateGrant(tx *dbs.Tx, grantId int64, name string, method string, username string, password string, privateKey string, description string, nodeId int64) error {
|
||||||
if grantId <= 0 {
|
if grantId <= 0 {
|
||||||
return errors.New("invalid grantId")
|
return errors.New("invalid grantId")
|
||||||
@@ -119,17 +119,26 @@ func (this *NodeGrantDAO) UpdateGrant(tx *dbs.Tx, grantId int64, name string, me
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算所有认证信息数量
|
// CountAllEnabledGrants 计算所有认证信息数量
|
||||||
func (this *NodeGrantDAO) CountAllEnabledGrants(tx *dbs.Tx) (int64, error) {
|
func (this *NodeGrantDAO) CountAllEnabledGrants(tx *dbs.Tx, keyword string) (int64, error) {
|
||||||
return this.Query(tx).
|
query := this.Query(tx).
|
||||||
State(NodeGrantStateEnabled).
|
State(NodeGrantStateEnabled)
|
||||||
Count()
|
if len(keyword) > 0 {
|
||||||
|
query.Where("(name LIKE :keyword OR username LIKE :keyword OR description LIKE :keyword)").
|
||||||
|
Param("keyword", "%"+keyword+"%")
|
||||||
|
}
|
||||||
|
return query.Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出单页的认证信息
|
// ListEnabledGrants 列出单页的认证信息
|
||||||
func (this *NodeGrantDAO) ListEnabledGrants(tx *dbs.Tx, offset int64, size int64) (result []*NodeGrant, err error) {
|
func (this *NodeGrantDAO) ListEnabledGrants(tx *dbs.Tx, keyword string, offset int64, size int64) (result []*NodeGrant, err error) {
|
||||||
_, err = this.Query(tx).
|
query := this.Query(tx).
|
||||||
State(NodeGrantStateEnabled).
|
State(NodeGrantStateEnabled)
|
||||||
|
if len(keyword) > 0 {
|
||||||
|
query.Where("(name LIKE :keyword OR username LIKE :keyword OR description LIKE :keyword)").
|
||||||
|
Param("keyword", "%"+keyword+"%")
|
||||||
|
}
|
||||||
|
_, err = query.
|
||||||
Offset(offset).
|
Offset(offset).
|
||||||
Size(size).
|
Size(size).
|
||||||
DescPk().
|
DescPk().
|
||||||
@@ -138,7 +147,7 @@ func (this *NodeGrantDAO) ListEnabledGrants(tx *dbs.Tx, offset int64, size int64
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出所有的认证信息
|
// FindAllEnabledGrants 列出所有的认证信息
|
||||||
func (this *NodeGrantDAO) FindAllEnabledGrants(tx *dbs.Tx) (result []*NodeGrant, err error) {
|
func (this *NodeGrantDAO) FindAllEnabledGrants(tx *dbs.Tx) (result []*NodeGrant, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(NodeGrantStateEnabled).
|
State(NodeGrantStateEnabled).
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package models
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
@@ -34,7 +35,7 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启用条目
|
// EnableAddress 启用条目
|
||||||
func (this *NodeIPAddressDAO) EnableAddress(tx *dbs.Tx, id int64) (err error) {
|
func (this *NodeIPAddressDAO) EnableAddress(tx *dbs.Tx, id int64) (err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -43,7 +44,7 @@ func (this *NodeIPAddressDAO) EnableAddress(tx *dbs.Tx, id int64) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 禁用IP地址
|
// DisableAddress 禁用IP地址
|
||||||
func (this *NodeIPAddressDAO) DisableAddress(tx *dbs.Tx, id int64) (err error) {
|
func (this *NodeIPAddressDAO) DisableAddress(tx *dbs.Tx, id int64) (err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -52,11 +53,14 @@ func (this *NodeIPAddressDAO) DisableAddress(tx *dbs.Tx, id int64) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 禁用节点的所有的IP地址
|
// DisableAllAddressesWithNodeId 禁用节点的所有的IP地址
|
||||||
func (this *NodeIPAddressDAO) DisableAllAddressesWithNodeId(tx *dbs.Tx, nodeId int64) error {
|
func (this *NodeIPAddressDAO) DisableAllAddressesWithNodeId(tx *dbs.Tx, nodeId int64, role nodeconfigs.NodeRole) error {
|
||||||
if nodeId <= 0 {
|
if nodeId <= 0 {
|
||||||
return errors.New("invalid nodeId")
|
return errors.New("invalid nodeId")
|
||||||
}
|
}
|
||||||
|
if len(role) == 0 {
|
||||||
|
role = nodeconfigs.NodeRoleNode
|
||||||
|
}
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Attr("nodeId", nodeId).
|
Attr("nodeId", nodeId).
|
||||||
Set("state", NodeIPAddressStateDisabled).
|
Set("state", NodeIPAddressStateDisabled).
|
||||||
@@ -64,7 +68,7 @@ func (this *NodeIPAddressDAO) DisableAllAddressesWithNodeId(tx *dbs.Tx, nodeId i
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找启用中的IP地址
|
// FindEnabledAddress 查找启用中的IP地址
|
||||||
func (this *NodeIPAddressDAO) FindEnabledAddress(tx *dbs.Tx, id int64) (*NodeIPAddress, error) {
|
func (this *NodeIPAddressDAO) FindEnabledAddress(tx *dbs.Tx, id int64) (*NodeIPAddress, error) {
|
||||||
result, err := this.Query(tx).
|
result, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -76,7 +80,7 @@ func (this *NodeIPAddressDAO) FindEnabledAddress(tx *dbs.Tx, id int64) (*NodeIPA
|
|||||||
return result.(*NodeIPAddress), err
|
return result.(*NodeIPAddress), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据主键查找名称
|
// FindAddressName 根据主键查找名称
|
||||||
func (this *NodeIPAddressDAO) FindAddressName(tx *dbs.Tx, id int64) (string, error) {
|
func (this *NodeIPAddressDAO) FindAddressName(tx *dbs.Tx, id int64) (string, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -84,10 +88,15 @@ func (this *NodeIPAddressDAO) FindAddressName(tx *dbs.Tx, id int64) (string, err
|
|||||||
FindStringCol("")
|
FindStringCol("")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建IP地址
|
// CreateAddress 创建IP地址
|
||||||
func (this *NodeIPAddressDAO) CreateAddress(tx *dbs.Tx, nodeId int64, name string, ip string, canAccess bool) (addressId int64, err error) {
|
func (this *NodeIPAddressDAO) CreateAddress(tx *dbs.Tx, nodeId int64, role nodeconfigs.NodeRole, name string, ip string, canAccess bool) (addressId int64, err error) {
|
||||||
|
if len(role) == 0 {
|
||||||
|
role = nodeconfigs.NodeRoleNode
|
||||||
|
}
|
||||||
|
|
||||||
op := NewNodeIPAddressOperator()
|
op := NewNodeIPAddressOperator()
|
||||||
op.NodeId = nodeId
|
op.NodeId = nodeId
|
||||||
|
op.Role = role
|
||||||
op.Name = name
|
op.Name = name
|
||||||
op.Ip = ip
|
op.Ip = ip
|
||||||
op.CanAccess = canAccess
|
op.CanAccess = canAccess
|
||||||
@@ -105,7 +114,7 @@ func (this *NodeIPAddressDAO) CreateAddress(tx *dbs.Tx, nodeId int64, name strin
|
|||||||
return types.Int64(op.Id), nil
|
return types.Int64(op.Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改IP地址
|
// UpdateAddress 修改IP地址
|
||||||
func (this *NodeIPAddressDAO) UpdateAddress(tx *dbs.Tx, addressId int64, name string, ip string, canAccess bool) (err error) {
|
func (this *NodeIPAddressDAO) UpdateAddress(tx *dbs.Tx, addressId int64, name string, ip string, canAccess bool) (err error) {
|
||||||
if addressId <= 0 {
|
if addressId <= 0 {
|
||||||
return errors.New("invalid addressId")
|
return errors.New("invalid addressId")
|
||||||
@@ -121,7 +130,7 @@ func (this *NodeIPAddressDAO) UpdateAddress(tx *dbs.Tx, addressId int64, name st
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改IP地址中的IP
|
// UpdateAddressIP 修改IP地址中的IP
|
||||||
func (this *NodeIPAddressDAO) UpdateAddressIP(tx *dbs.Tx, addressId int64, ip string) error {
|
func (this *NodeIPAddressDAO) UpdateAddressIP(tx *dbs.Tx, addressId int64, ip string) error {
|
||||||
if addressId <= 0 {
|
if addressId <= 0 {
|
||||||
return errors.New("invalid addressId")
|
return errors.New("invalid addressId")
|
||||||
@@ -133,7 +142,7 @@ func (this *NodeIPAddressDAO) UpdateAddressIP(tx *dbs.Tx, addressId int64, ip st
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改IP地址所属节点
|
// UpdateAddressNodeId 修改IP地址所属节点
|
||||||
func (this *NodeIPAddressDAO) UpdateAddressNodeId(tx *dbs.Tx, addressId int64, nodeId int64) error {
|
func (this *NodeIPAddressDAO) UpdateAddressNodeId(tx *dbs.Tx, addressId int64, nodeId int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(addressId).
|
Pk(addressId).
|
||||||
@@ -151,10 +160,14 @@ func (this *NodeIPAddressDAO) UpdateAddressNodeId(tx *dbs.Tx, addressId int64, n
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找节点的所有的IP地址
|
// FindAllEnabledAddressesWithNode 查找节点的所有的IP地址
|
||||||
func (this *NodeIPAddressDAO) FindAllEnabledAddressesWithNode(tx *dbs.Tx, nodeId int64) (result []*NodeIPAddress, err error) {
|
func (this *NodeIPAddressDAO) FindAllEnabledAddressesWithNode(tx *dbs.Tx, nodeId int64, role nodeconfigs.NodeRole) (result []*NodeIPAddress, err error) {
|
||||||
|
if len(role) == 0 {
|
||||||
|
role = nodeconfigs.NodeRoleNode
|
||||||
|
}
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
Attr("nodeId", nodeId).
|
Attr("nodeId", nodeId).
|
||||||
|
Attr("role", role).
|
||||||
State(NodeIPAddressStateEnabled).
|
State(NodeIPAddressStateEnabled).
|
||||||
Desc("order").
|
Desc("order").
|
||||||
AscPk().
|
AscPk().
|
||||||
@@ -163,10 +176,14 @@ func (this *NodeIPAddressDAO) FindAllEnabledAddressesWithNode(tx *dbs.Tx, nodeId
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找节点的第一个可访问的IP地址
|
// FindFirstNodeAccessIPAddress 查找节点的第一个可访问的IP地址
|
||||||
func (this *NodeIPAddressDAO) FindFirstNodeAccessIPAddress(tx *dbs.Tx, nodeId int64) (string, error) {
|
func (this *NodeIPAddressDAO) FindFirstNodeAccessIPAddress(tx *dbs.Tx, nodeId int64, role nodeconfigs.NodeRole) (string, error) {
|
||||||
|
if len(role) == 0 {
|
||||||
|
role = nodeconfigs.NodeRoleNode
|
||||||
|
}
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Attr("nodeId", nodeId).
|
Attr("nodeId", nodeId).
|
||||||
|
Attr("role", role).
|
||||||
State(NodeIPAddressStateEnabled).
|
State(NodeIPAddressStateEnabled).
|
||||||
Attr("canAccess", true).
|
Attr("canAccess", true).
|
||||||
Desc("order").
|
Desc("order").
|
||||||
@@ -175,10 +192,14 @@ func (this *NodeIPAddressDAO) FindFirstNodeAccessIPAddress(tx *dbs.Tx, nodeId in
|
|||||||
FindStringCol("")
|
FindStringCol("")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找节点的第一个可访问的IP地址ID
|
// FindFirstNodeAccessIPAddressId 查找节点的第一个可访问的IP地址ID
|
||||||
func (this *NodeIPAddressDAO) FindFirstNodeAccessIPAddressId(tx *dbs.Tx, nodeId int64) (int64, error) {
|
func (this *NodeIPAddressDAO) FindFirstNodeAccessIPAddressId(tx *dbs.Tx, nodeId int64, role nodeconfigs.NodeRole) (int64, error) {
|
||||||
|
if len(role) == 0 {
|
||||||
|
role = nodeconfigs.NodeRoleNode
|
||||||
|
}
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Attr("nodeId", nodeId).
|
Attr("nodeId", nodeId).
|
||||||
|
Attr("role", role).
|
||||||
State(NodeIPAddressStateEnabled).
|
State(NodeIPAddressStateEnabled).
|
||||||
Attr("canAccess", true).
|
Attr("canAccess", true).
|
||||||
Desc("order").
|
Desc("order").
|
||||||
@@ -187,8 +208,11 @@ func (this *NodeIPAddressDAO) FindFirstNodeAccessIPAddressId(tx *dbs.Tx, nodeId
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找节点所有的可访问的IP地址
|
// FindNodeAccessIPAddresses 查找节点所有的可访问的IP地址
|
||||||
func (this *NodeIPAddressDAO) FindNodeAccessIPAddresses(tx *dbs.Tx, nodeId int64) (result []*NodeIPAddress, err error) {
|
func (this *NodeIPAddressDAO) FindNodeAccessIPAddresses(tx *dbs.Tx, nodeId int64, role nodeconfigs.NodeRole) (result []*NodeIPAddress, err error) {
|
||||||
|
if len(role) == 0 {
|
||||||
|
role = nodeconfigs.NodeRoleNode
|
||||||
|
}
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
Attr("nodeId", nodeId).
|
Attr("nodeId", nodeId).
|
||||||
State(NodeIPAddressStateEnabled).
|
State(NodeIPAddressStateEnabled).
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
// 节点IP地址
|
// NodeIPAddress 节点IP地址
|
||||||
type NodeIPAddress struct {
|
type NodeIPAddress struct {
|
||||||
Id uint32 `field:"id"` // ID
|
Id uint32 `field:"id"` // ID
|
||||||
NodeId uint32 `field:"nodeId"` // 节点ID
|
NodeId uint32 `field:"nodeId"` // 节点ID
|
||||||
|
Role string `field:"role"` // 节点角色
|
||||||
Name string `field:"name"` // 名称
|
Name string `field:"name"` // 名称
|
||||||
Ip string `field:"ip"` // IP地址
|
Ip string `field:"ip"` // IP地址
|
||||||
Description string `field:"description"` // 描述
|
Description string `field:"description"` // 描述
|
||||||
@@ -15,6 +16,7 @@ type NodeIPAddress struct {
|
|||||||
type NodeIPAddressOperator struct {
|
type NodeIPAddressOperator struct {
|
||||||
Id interface{} // ID
|
Id interface{} // ID
|
||||||
NodeId interface{} // 节点ID
|
NodeId interface{} // 节点ID
|
||||||
|
Role interface{} // 节点角色
|
||||||
Name interface{} // 名称
|
Name interface{} // 名称
|
||||||
Ip interface{} // IP地址
|
Ip interface{} // IP地址
|
||||||
Description interface{} // 描述
|
Description interface{} // 描述
|
||||||
|
|||||||
@@ -2,18 +2,20 @@ package models
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
stringutil "github.com/iwind/TeaGo/utils/string"
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NodeLogDAO dbs.DAO
|
type NodeLogDAO dbs.DAO
|
||||||
|
|
||||||
const ()
|
|
||||||
|
|
||||||
func NewNodeLogDAO() *NodeLogDAO {
|
func NewNodeLogDAO() *NodeLogDAO {
|
||||||
return dbs.NewDAO(&NodeLogDAO{
|
return dbs.NewDAO(&NodeLogDAO{
|
||||||
DAOObject: dbs.DAOObject{
|
DAOObject: dbs.DAOObject{
|
||||||
@@ -33,21 +35,45 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建日志
|
// CreateLog 创建日志
|
||||||
func (this *NodeLogDAO) CreateLog(tx *dbs.Tx, nodeRole NodeRole, nodeId int64, level string, tag string, description string, createdAt int64) error {
|
func (this *NodeLogDAO) CreateLog(tx *dbs.Tx, nodeRole nodeconfigs.NodeRole, nodeId int64, serverId int64, level string, tag string, description string, createdAt int64) error {
|
||||||
|
hash := stringutil.Md5(nodeRole + "@" + strconv.FormatInt(nodeId, 10) + "@" + strconv.FormatInt(serverId, 10) + "@" + level + "@" + tag + "@" + description)
|
||||||
|
|
||||||
|
// 检查是否在重复最后一条,避免重复创建
|
||||||
|
lastLog, err := this.Query(tx).
|
||||||
|
Result("id", "hash", "createdAt").
|
||||||
|
DescPk().
|
||||||
|
Find()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if lastLog != nil {
|
||||||
|
nodeLog := lastLog.(*NodeLog)
|
||||||
|
if nodeLog.Hash == hash && time.Now().Unix()-int64(nodeLog.CreatedAt) < 1800 {
|
||||||
|
err = this.Query(tx).
|
||||||
|
Pk(nodeLog.Id).
|
||||||
|
Set("count", dbs.SQL("count+1")).
|
||||||
|
UpdateQuickly()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
op := NewNodeLogOperator()
|
op := NewNodeLogOperator()
|
||||||
op.Role = nodeRole
|
op.Role = nodeRole
|
||||||
op.NodeId = nodeId
|
op.NodeId = nodeId
|
||||||
|
op.ServerId = serverId
|
||||||
op.Level = level
|
op.Level = level
|
||||||
op.Tag = tag
|
op.Tag = tag
|
||||||
op.Description = description
|
op.Description = description
|
||||||
op.CreatedAt = createdAt
|
op.CreatedAt = createdAt
|
||||||
op.Day = timeutil.FormatTime("Ymd", createdAt)
|
op.Day = timeutil.FormatTime("Ymd", createdAt)
|
||||||
err := this.Save(tx, op)
|
op.Hash = hash
|
||||||
|
op.Count = 1
|
||||||
|
err = this.Save(tx, op)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清除超出一定日期的日志
|
// DeleteExpiredLogs 清除超出一定日期的日志
|
||||||
func (this *NodeLogDAO) DeleteExpiredLogs(tx *dbs.Tx, days int) error {
|
func (this *NodeLogDAO) DeleteExpiredLogs(tx *dbs.Tx, days int) error {
|
||||||
if days <= 0 {
|
if days <= 0 {
|
||||||
return errors.New("invalid days '" + strconv.Itoa(days) + "'")
|
return errors.New("invalid days '" + strconv.Itoa(days) + "'")
|
||||||
@@ -61,19 +87,93 @@ func (this *NodeLogDAO) DeleteExpiredLogs(tx *dbs.Tx, days int) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算节点数量
|
// CountNodeLogs 计算节点日志数量
|
||||||
func (this *NodeLogDAO) CountNodeLogs(tx *dbs.Tx, role string, nodeId int64) (int64, error) {
|
func (this *NodeLogDAO) CountNodeLogs(tx *dbs.Tx, role string, nodeId int64, serverId int64, dayFrom string, dayTo string, keyword string, level string) (int64, error) {
|
||||||
return this.Query(tx).
|
query := this.Query(tx).
|
||||||
Attr("nodeId", nodeId).
|
Attr("role", role)
|
||||||
Attr("role", role).
|
if nodeId > 0 {
|
||||||
Count()
|
query.Attr("nodeId", nodeId)
|
||||||
|
} else {
|
||||||
|
switch role {
|
||||||
|
case nodeconfigs.NodeRoleNode:
|
||||||
|
query.Where("nodeId IN (SELECT id FROM " + SharedNodeDAO.Table + " WHERE state=1)")
|
||||||
|
case nodeconfigs.NodeRoleDNS:
|
||||||
|
query.Where("nodeId IN (SELECT id FROM edgeNSNodes WHERE state=1)") // 没有用 SharedNSNodeDAO() 因为有包循环引用的问题
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if serverId > 0 {
|
||||||
|
query.Attr("serverId", serverId)
|
||||||
|
}
|
||||||
|
if len(dayFrom) > 0 {
|
||||||
|
dayFrom = strings.ReplaceAll(dayFrom, "-", "")
|
||||||
|
query.Gte("day", dayFrom)
|
||||||
|
}
|
||||||
|
if len(dayTo) > 0 {
|
||||||
|
dayTo = strings.ReplaceAll(dayTo, "-", "")
|
||||||
|
query.Lte("day", dayTo)
|
||||||
|
}
|
||||||
|
if len(keyword) > 0 {
|
||||||
|
query.Where("(tag LIKE :keyword OR description LIKE :keyword)").
|
||||||
|
Param("keyword", "%"+keyword+"%")
|
||||||
|
}
|
||||||
|
if len(level) > 0 {
|
||||||
|
query.Attr("level", level)
|
||||||
|
}
|
||||||
|
|
||||||
|
return query.Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出单页日志
|
// ListNodeLogs 列出单页日志
|
||||||
func (this *NodeLogDAO) ListNodeLogs(tx *dbs.Tx, role string, nodeId int64, offset int64, size int64) (result []*NodeLog, err error) {
|
func (this *NodeLogDAO) ListNodeLogs(tx *dbs.Tx,
|
||||||
_, err = this.Query(tx).
|
role string,
|
||||||
Attr("nodeId", nodeId).
|
nodeId int64,
|
||||||
Attr("role", role).
|
serverId int64,
|
||||||
|
allServers bool,
|
||||||
|
dayFrom string,
|
||||||
|
dayTo string,
|
||||||
|
keyword string,
|
||||||
|
level string,
|
||||||
|
fixedState configutils.BoolState,
|
||||||
|
offset int64,
|
||||||
|
size int64) (result []*NodeLog, err error) {
|
||||||
|
query := this.Query(tx).
|
||||||
|
Attr("role", role)
|
||||||
|
if nodeId > 0 {
|
||||||
|
query.Attr("nodeId", nodeId)
|
||||||
|
} else {
|
||||||
|
switch role {
|
||||||
|
case nodeconfigs.NodeRoleNode:
|
||||||
|
query.Where("nodeId IN (SELECT id FROM " + SharedNodeDAO.Table + " WHERE state=1)")
|
||||||
|
case nodeconfigs.NodeRoleDNS:
|
||||||
|
query.Where("nodeId IN (SELECT id FROM edgeNSNodes WHERE state=1)") // 没有用 SharedNSNodeDAO() 因为有包循环引用的问题
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if serverId > 0 {
|
||||||
|
query.Attr("serverId", serverId)
|
||||||
|
} else if allServers {
|
||||||
|
query.Where("serverId>0")
|
||||||
|
}
|
||||||
|
if fixedState == configutils.BoolStateYes {
|
||||||
|
query.Attr("isFixed", 1)
|
||||||
|
} else if fixedState == configutils.BoolStateNo {
|
||||||
|
query.Attr("isFixed", 0)
|
||||||
|
}
|
||||||
|
if len(dayFrom) > 0 {
|
||||||
|
dayFrom = strings.ReplaceAll(dayFrom, "-", "")
|
||||||
|
query.Gte("day", dayFrom)
|
||||||
|
}
|
||||||
|
if len(dayTo) > 0 {
|
||||||
|
dayTo = strings.ReplaceAll(dayTo, "-", "")
|
||||||
|
query.Lte("day", dayTo)
|
||||||
|
}
|
||||||
|
if len(keyword) > 0 {
|
||||||
|
query.Where("(tag LIKE :keyword OR description LIKE :keyword)").
|
||||||
|
Param("keyword", "%"+keyword+"%")
|
||||||
|
}
|
||||||
|
if len(level) > 0 {
|
||||||
|
query.Attr("level", level)
|
||||||
|
}
|
||||||
|
_, err = query.
|
||||||
Offset(offset).
|
Offset(offset).
|
||||||
Limit(size).
|
Limit(size).
|
||||||
Slice(&result).
|
Slice(&result).
|
||||||
@@ -81,3 +181,33 @@ func (this *NodeLogDAO) ListNodeLogs(tx *dbs.Tx, role string, nodeId int64, offs
|
|||||||
FindAll()
|
FindAll()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateNodeLogFixed 设置节点日志为已修复
|
||||||
|
func (this *NodeLogDAO) UpdateNodeLogFixed(tx *dbs.Tx, logId int64) error {
|
||||||
|
if logId <= 0 {
|
||||||
|
return errors.New("invalid logId")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 我们把相同内容的日志都置为已修复
|
||||||
|
hash, err := this.Query(tx).
|
||||||
|
Pk(logId).
|
||||||
|
Result("hash").
|
||||||
|
FindStringCol("")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(hash) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
err = this.Query(tx).
|
||||||
|
Attr("hash", hash).
|
||||||
|
Attr("isFixed", false).
|
||||||
|
Set("isFixed", true).
|
||||||
|
UpdateQuickly()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
// 节点日志
|
// NodeLog 节点日志
|
||||||
type NodeLog struct {
|
type NodeLog struct {
|
||||||
Id uint64 `field:"id"` // ID
|
Id uint64 `field:"id"` // ID
|
||||||
Role string `field:"role"` // 节点角色
|
Role string `field:"role"` // 节点角色
|
||||||
@@ -10,6 +10,10 @@ type NodeLog struct {
|
|||||||
Level string `field:"level"` // 级别
|
Level string `field:"level"` // 级别
|
||||||
NodeId uint32 `field:"nodeId"` // 节点ID
|
NodeId uint32 `field:"nodeId"` // 节点ID
|
||||||
Day string `field:"day"` // 日期
|
Day string `field:"day"` // 日期
|
||||||
|
ServerId uint32 `field:"serverId"` // 服务ID
|
||||||
|
Hash string `field:"hash"` // 信息内容Hash
|
||||||
|
Count uint32 `field:"count"` // 重复次数
|
||||||
|
IsFixed uint8 `field:"isFixed"` // 是否已处理
|
||||||
}
|
}
|
||||||
|
|
||||||
type NodeLogOperator struct {
|
type NodeLogOperator struct {
|
||||||
@@ -21,6 +25,10 @@ type NodeLogOperator struct {
|
|||||||
Level interface{} // 级别
|
Level interface{} // 级别
|
||||||
NodeId interface{} // 节点ID
|
NodeId interface{} // 节点ID
|
||||||
Day interface{} // 日期
|
Day interface{} // 日期
|
||||||
|
ServerId interface{} // 服务ID
|
||||||
|
Hash interface{} // 信息内容Hash
|
||||||
|
Count interface{} // 重复次数
|
||||||
|
IsFixed interface{} // 是否已处理
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNodeLogOperator() *NodeLogOperator {
|
func NewNodeLogOperator() *NodeLogOperator {
|
||||||
|
|||||||
@@ -1,62 +1,66 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
// 节点
|
// Node 节点
|
||||||
type Node struct {
|
type Node struct {
|
||||||
Id uint32 `field:"id"` // ID
|
Id uint32 `field:"id"` // ID
|
||||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||||
UserId uint32 `field:"userId"` // 用户ID
|
UserId uint32 `field:"userId"` // 用户ID
|
||||||
IsOn uint8 `field:"isOn"` // 是否启用
|
IsOn uint8 `field:"isOn"` // 是否启用
|
||||||
IsUp uint8 `field:"isUp"` // 是否在线
|
IsUp uint8 `field:"isUp"` // 是否在线
|
||||||
CountUp uint32 `field:"countUp"` // 连续在线次数
|
CountUp uint32 `field:"countUp"` // 连续在线次数
|
||||||
CountDown uint32 `field:"countDown"` // 连续下线次数
|
CountDown uint32 `field:"countDown"` // 连续下线次数
|
||||||
IsActive uint8 `field:"isActive"` // 是否活跃
|
IsActive uint8 `field:"isActive"` // 是否活跃
|
||||||
UniqueId string `field:"uniqueId"` // 节点ID
|
UniqueId string `field:"uniqueId"` // 节点ID
|
||||||
Secret string `field:"secret"` // 密钥
|
Secret string `field:"secret"` // 密钥
|
||||||
Name string `field:"name"` // 节点名
|
Name string `field:"name"` // 节点名
|
||||||
Code string `field:"code"` // 代号
|
Code string `field:"code"` // 代号
|
||||||
ClusterId uint32 `field:"clusterId"` // 集群ID
|
ClusterId uint32 `field:"clusterId"` // 集群ID
|
||||||
RegionId uint32 `field:"regionId"` // 区域ID
|
RegionId uint32 `field:"regionId"` // 区域ID
|
||||||
GroupId uint32 `field:"groupId"` // 分组ID
|
GroupId uint32 `field:"groupId"` // 分组ID
|
||||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||||
Status string `field:"status"` // 最新的状态
|
Status string `field:"status"` // 最新的状态
|
||||||
Version uint32 `field:"version"` // 当前版本号
|
Version uint32 `field:"version"` // 当前版本号
|
||||||
LatestVersion uint32 `field:"latestVersion"` // 最后版本号
|
LatestVersion uint32 `field:"latestVersion"` // 最后版本号
|
||||||
InstallDir string `field:"installDir"` // 安装目录
|
InstallDir string `field:"installDir"` // 安装目录
|
||||||
IsInstalled uint8 `field:"isInstalled"` // 是否已安装
|
IsInstalled uint8 `field:"isInstalled"` // 是否已安装
|
||||||
InstallStatus string `field:"installStatus"` // 安装状态
|
InstallStatus string `field:"installStatus"` // 安装状态
|
||||||
State uint8 `field:"state"` // 状态
|
State uint8 `field:"state"` // 状态
|
||||||
ConnectedAPINodes string `field:"connectedAPINodes"` // 当前连接的API节点
|
ConnectedAPINodes string `field:"connectedAPINodes"` // 当前连接的API节点
|
||||||
MaxCPU uint32 `field:"maxCPU"` // 可以使用的最多CPU
|
MaxCPU uint32 `field:"maxCPU"` // 可以使用的最多CPU
|
||||||
DnsRoutes string `field:"dnsRoutes"` // DNS线路设置
|
DnsRoutes string `field:"dnsRoutes"` // DNS线路设置
|
||||||
|
MaxCacheDiskCapacity string `field:"maxCacheDiskCapacity"` // 硬盘缓存容量
|
||||||
|
MaxCacheMemoryCapacity string `field:"maxCacheMemoryCapacity"` // 内存缓存容量
|
||||||
}
|
}
|
||||||
|
|
||||||
type NodeOperator struct {
|
type NodeOperator struct {
|
||||||
Id interface{} // ID
|
Id interface{} // ID
|
||||||
AdminId interface{} // 管理员ID
|
AdminId interface{} // 管理员ID
|
||||||
UserId interface{} // 用户ID
|
UserId interface{} // 用户ID
|
||||||
IsOn interface{} // 是否启用
|
IsOn interface{} // 是否启用
|
||||||
IsUp interface{} // 是否在线
|
IsUp interface{} // 是否在线
|
||||||
CountUp interface{} // 连续在线次数
|
CountUp interface{} // 连续在线次数
|
||||||
CountDown interface{} // 连续下线次数
|
CountDown interface{} // 连续下线次数
|
||||||
IsActive interface{} // 是否活跃
|
IsActive interface{} // 是否活跃
|
||||||
UniqueId interface{} // 节点ID
|
UniqueId interface{} // 节点ID
|
||||||
Secret interface{} // 密钥
|
Secret interface{} // 密钥
|
||||||
Name interface{} // 节点名
|
Name interface{} // 节点名
|
||||||
Code interface{} // 代号
|
Code interface{} // 代号
|
||||||
ClusterId interface{} // 集群ID
|
ClusterId interface{} // 集群ID
|
||||||
RegionId interface{} // 区域ID
|
RegionId interface{} // 区域ID
|
||||||
GroupId interface{} // 分组ID
|
GroupId interface{} // 分组ID
|
||||||
CreatedAt interface{} // 创建时间
|
CreatedAt interface{} // 创建时间
|
||||||
Status interface{} // 最新的状态
|
Status interface{} // 最新的状态
|
||||||
Version interface{} // 当前版本号
|
Version interface{} // 当前版本号
|
||||||
LatestVersion interface{} // 最后版本号
|
LatestVersion interface{} // 最后版本号
|
||||||
InstallDir interface{} // 安装目录
|
InstallDir interface{} // 安装目录
|
||||||
IsInstalled interface{} // 是否已安装
|
IsInstalled interface{} // 是否已安装
|
||||||
InstallStatus interface{} // 安装状态
|
InstallStatus interface{} // 安装状态
|
||||||
State interface{} // 状态
|
State interface{} // 状态
|
||||||
ConnectedAPINodes interface{} // 当前连接的API节点
|
ConnectedAPINodes interface{} // 当前连接的API节点
|
||||||
MaxCPU interface{} // 可以使用的最多CPU
|
MaxCPU interface{} // 可以使用的最多CPU
|
||||||
DnsRoutes interface{} // DNS线路设置
|
DnsRoutes interface{} // DNS线路设置
|
||||||
|
MaxCacheDiskCapacity interface{} // 硬盘缓存容量
|
||||||
|
MaxCacheMemoryCapacity interface{} // 内存缓存容量
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNodeOperator() *NodeOperator {
|
func NewNodeOperator() *NodeOperator {
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
package models
|
|
||||||
|
|
||||||
type NodeRole = string
|
|
||||||
|
|
||||||
const (
|
|
||||||
NodeRoleAdmin NodeRole = "admin"
|
|
||||||
NodeRoleUser NodeRole = "user"
|
|
||||||
NodeRoleProvider NodeRole = "provider"
|
|
||||||
NodeRoleAPI NodeRole = "api"
|
|
||||||
NodeRoleDatabase NodeRole = "database"
|
|
||||||
NodeRoleLog NodeRole = "log"
|
|
||||||
NodeRoleDNS NodeRole = "dns"
|
|
||||||
NodeRoleMonitor NodeRole = "monitor"
|
|
||||||
NodeRoleNode NodeRole = "node"
|
|
||||||
NodeRoleCluster NodeRole = "cluster"
|
|
||||||
NodeRoleAuthority NodeRole = "authority"
|
|
||||||
)
|
|
||||||
@@ -13,8 +13,9 @@ import (
|
|||||||
type NodeTaskType = string
|
type NodeTaskType = string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
NodeTaskTypeConfigChanged NodeTaskType = "configChanged"
|
NodeTaskTypeConfigChanged NodeTaskType = "configChanged"
|
||||||
NodeTaskTypeIPItemChanged NodeTaskType = "ipItemChanged"
|
NodeTaskTypeIPItemChanged NodeTaskType = "ipItemChanged"
|
||||||
|
NodeTaskTypeNodeVersionChanged NodeTaskType = "nodeVersionChanged"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NodeTaskDAO dbs.DAO
|
type NodeTaskDAO dbs.DAO
|
||||||
|
|||||||
271
internal/db/models/node_threshold_dao.go
Normal file
271
internal/db/models/node_threshold_dao.go
Normal file
@@ -0,0 +1,271 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
"github.com/iwind/TeaGo/Tea"
|
||||||
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
"github.com/iwind/TeaGo/types"
|
||||||
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
NodeThresholdStateEnabled = 1 // 已启用
|
||||||
|
NodeThresholdStateDisabled = 0 // 已禁用
|
||||||
|
)
|
||||||
|
|
||||||
|
type NodeThresholdDAO dbs.DAO
|
||||||
|
|
||||||
|
func NewNodeThresholdDAO() *NodeThresholdDAO {
|
||||||
|
return dbs.NewDAO(&NodeThresholdDAO{
|
||||||
|
DAOObject: dbs.DAOObject{
|
||||||
|
DB: Tea.Env,
|
||||||
|
Table: "edgeNodeThresholds",
|
||||||
|
Model: new(NodeThreshold),
|
||||||
|
PkName: "id",
|
||||||
|
},
|
||||||
|
}).(*NodeThresholdDAO)
|
||||||
|
}
|
||||||
|
|
||||||
|
var SharedNodeThresholdDAO *NodeThresholdDAO
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
dbs.OnReady(func() {
|
||||||
|
SharedNodeThresholdDAO = NewNodeThresholdDAO()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// EnableNodeThreshold 启用条目
|
||||||
|
func (this *NodeThresholdDAO) EnableNodeThreshold(tx *dbs.Tx, id int64) error {
|
||||||
|
_, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Set("state", NodeThresholdStateEnabled).
|
||||||
|
Update()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DisableNodeThreshold 禁用条目
|
||||||
|
func (this *NodeThresholdDAO) DisableNodeThreshold(tx *dbs.Tx, id int64) error {
|
||||||
|
_, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Set("state", NodeThresholdStateDisabled).
|
||||||
|
Update()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindEnabledNodeThreshold 查找启用中的条目
|
||||||
|
func (this *NodeThresholdDAO) FindEnabledNodeThreshold(tx *dbs.Tx, id int64) (*NodeThreshold, error) {
|
||||||
|
result, err := this.Query(tx).
|
||||||
|
Pk(id).
|
||||||
|
Attr("state", NodeThresholdStateEnabled).
|
||||||
|
Find()
|
||||||
|
if result == nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result.(*NodeThreshold), err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateThreshold 创建阈值
|
||||||
|
func (this *NodeThresholdDAO) CreateThreshold(tx *dbs.Tx, role string, clusterId int64, nodeId int64, item nodeconfigs.NodeValueItem, param string, operator nodeconfigs.NodeValueOperator, valueJSON []byte, message string, sumMethod nodeconfigs.NodeValueSumMethod, duration int32, durationUnit nodeconfigs.NodeValueDurationUnit, notifyDuration int32) (int64, error) {
|
||||||
|
op := NewNodeThresholdOperator()
|
||||||
|
op.Role = role
|
||||||
|
op.ClusterId = clusterId
|
||||||
|
op.NodeId = nodeId
|
||||||
|
op.Item = item
|
||||||
|
op.Param = param
|
||||||
|
op.Operator = operator
|
||||||
|
op.Value = valueJSON
|
||||||
|
op.Message = message
|
||||||
|
op.SumMethod = sumMethod
|
||||||
|
op.Duration = duration
|
||||||
|
op.DurationUnit = durationUnit
|
||||||
|
op.NotifyDuration = notifyDuration
|
||||||
|
op.IsOn = true
|
||||||
|
op.State = NodeThresholdStateEnabled
|
||||||
|
return this.SaveInt64(tx, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateThreshold 修改阈值
|
||||||
|
func (this *NodeThresholdDAO) UpdateThreshold(tx *dbs.Tx, thresholdId int64, item nodeconfigs.NodeValueItem, param string, operator nodeconfigs.NodeValueOperator, valueJSON []byte, message string, sumMethod nodeconfigs.NodeValueSumMethod, duration int32, durationUnit nodeconfigs.NodeValueDurationUnit, notifyDuration int32, isOn bool) error {
|
||||||
|
if thresholdId <= 0 {
|
||||||
|
return errors.New("invalid thresholdId")
|
||||||
|
}
|
||||||
|
op := NewNodeThresholdOperator()
|
||||||
|
op.Id = thresholdId
|
||||||
|
op.Item = item
|
||||||
|
op.Param = param
|
||||||
|
op.Operator = operator
|
||||||
|
op.Value = valueJSON
|
||||||
|
op.Message = message
|
||||||
|
op.SumMethod = sumMethod
|
||||||
|
op.Duration = duration
|
||||||
|
op.DurationUnit = durationUnit
|
||||||
|
op.NotifyDuration = notifyDuration
|
||||||
|
op.IsOn = isOn
|
||||||
|
return this.Save(tx, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindAllEnabledThresholds 列出所有阈值
|
||||||
|
func (this *NodeThresholdDAO) FindAllEnabledThresholds(tx *dbs.Tx, role string, clusterId int64, nodeId int64) (result []*NodeThreshold, err error) {
|
||||||
|
if clusterId <= 0 && nodeId <= 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
query := this.Query(tx)
|
||||||
|
if clusterId > 0 {
|
||||||
|
query.Attr("clusterId", clusterId)
|
||||||
|
}
|
||||||
|
if nodeId > 0 {
|
||||||
|
query.Attr("nodeId", nodeId)
|
||||||
|
}
|
||||||
|
query.State(NodeThresholdStateEnabled)
|
||||||
|
query.Slice(&result)
|
||||||
|
_, err = query.
|
||||||
|
Attr("role", role).
|
||||||
|
Asc("IF(nodeId>0, 1, 0)").
|
||||||
|
Desc("order").
|
||||||
|
AscPk().
|
||||||
|
FindAll()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindAllEnabledAndOnClusterThresholds 查询集群专属的阈值设置
|
||||||
|
func (this *NodeThresholdDAO) FindAllEnabledAndOnClusterThresholds(tx *dbs.Tx, role string, clusterId int64, item string) (result []*NodeThreshold, err error) {
|
||||||
|
if clusterId <= 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = this.Query(tx).
|
||||||
|
Attr("role", role).
|
||||||
|
Attr("clusterId", clusterId).
|
||||||
|
Attr("nodeId", 0).
|
||||||
|
Attr("item", item).
|
||||||
|
Attr("isOn", true).
|
||||||
|
State(NodeThresholdStateEnabled).
|
||||||
|
Desc("order").
|
||||||
|
AscPk().
|
||||||
|
Slice(&result).
|
||||||
|
FindAll()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindAllEnabledAndOnNodeThresholds 查询节点专属的阈值设置
|
||||||
|
func (this *NodeThresholdDAO) FindAllEnabledAndOnNodeThresholds(tx *dbs.Tx, role string, nodeId int64, item string) (result []*NodeThreshold, err error) {
|
||||||
|
if nodeId <= 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = this.Query(tx).
|
||||||
|
Attr("role", role).
|
||||||
|
Attr("nodeId", nodeId).
|
||||||
|
Attr("item", item).
|
||||||
|
Attr("isOn", true).
|
||||||
|
State(NodeThresholdStateEnabled).
|
||||||
|
Desc("order").
|
||||||
|
AscPk().
|
||||||
|
Slice(&result).
|
||||||
|
FindAll()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountAllEnabledThresholds 计算阈值的数量
|
||||||
|
func (this *NodeThresholdDAO) CountAllEnabledThresholds(tx *dbs.Tx, clusterId int64, nodeId int64) (int64, error) {
|
||||||
|
if clusterId <= 0 && nodeId <= 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
query := this.Query(tx)
|
||||||
|
if clusterId > 0 {
|
||||||
|
query.Attr("clusterId", clusterId)
|
||||||
|
}
|
||||||
|
if nodeId > 0 {
|
||||||
|
query.Attr("nodeId", nodeId)
|
||||||
|
}
|
||||||
|
query.State(NodeThresholdStateEnabled)
|
||||||
|
return query.Count()
|
||||||
|
}
|
||||||
|
|
||||||
|
// FireNodeThreshold 触发相关阈值设置
|
||||||
|
func (this *NodeThresholdDAO) FireNodeThreshold(tx *dbs.Tx, role string, nodeId int64, item string) error {
|
||||||
|
clusterId, err := SharedNodeDAO.FindNodeClusterId(tx, nodeId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if clusterId == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 集群相关阈值
|
||||||
|
var thresholds []*NodeThreshold
|
||||||
|
{
|
||||||
|
clusterThresholds, err := this.FindAllEnabledAndOnClusterThresholds(tx, role, clusterId, item)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
thresholds = append(thresholds, clusterThresholds...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 节点相关阈值
|
||||||
|
{
|
||||||
|
nodeThresholds, err := this.FindAllEnabledAndOnNodeThresholds(tx, role, nodeId, item)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
thresholds = append(thresholds, nodeThresholds...)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(thresholds) > 0 {
|
||||||
|
for _, threshold := range thresholds {
|
||||||
|
if len(threshold.Param) == 0 || threshold.Duration <= 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
paramValue, err := SharedNodeValueDAO.SumValues(tx, role, nodeId, item, threshold.Param, threshold.SumMethod, types.Int32(threshold.Duration), threshold.DurationUnit)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
originValue := nodeconfigs.UnmarshalNodeValue([]byte(threshold.Value))
|
||||||
|
thresholdValue := types.Float64(originValue)
|
||||||
|
isMatched := nodeconfigs.CompareNodeValue(threshold.Operator, paramValue, thresholdValue)
|
||||||
|
if isMatched {
|
||||||
|
// TODO 执行其他动作
|
||||||
|
|
||||||
|
// 是否已经通知过
|
||||||
|
if threshold.NotifyDuration > 0 && threshold.NotifiedAt > 0 && time.Now().Unix()-int64(threshold.NotifiedAt) < int64(threshold.NotifyDuration*60) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建消息
|
||||||
|
nodeName, err := SharedNodeDAO.FindNodeName(tx, nodeId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
itemName := nodeconfigs.FindNodeValueItemName(threshold.Item)
|
||||||
|
paramName := nodeconfigs.FindNodeValueItemParamName(threshold.Item, threshold.Param)
|
||||||
|
operatorName := nodeconfigs.FindNodeValueOperatorName(threshold.Operator)
|
||||||
|
|
||||||
|
subject := "节点 \"" + nodeName + "\" " + itemName + " 达到阈值"
|
||||||
|
body := "节点 \"" + nodeName + "\" " + itemName + " 达到阈值\n阈值设置:" + paramName + " " + operatorName + " " + originValue + "\n当前值:" + fmt.Sprintf("%.2f", paramValue) + "\n触发时间:" + timeutil.Format("Y-m-d H:i:s")
|
||||||
|
if len(threshold.Message) > 0 {
|
||||||
|
body = threshold.Message
|
||||||
|
body = strings.Replace(body, "${item.name}", itemName, -1)
|
||||||
|
body = strings.Replace(body, "${value}", fmt.Sprintf("%.2f", paramValue), -1)
|
||||||
|
}
|
||||||
|
err = SharedMessageDAO.CreateNodeMessage(tx, clusterId, nodeId, MessageTypeThresholdSatisfied, MessageLevelWarning, subject, body, maps.Map{}.AsJSON())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置通知时间
|
||||||
|
_, err = this.Query(tx).
|
||||||
|
Pk(threshold.Id).
|
||||||
|
Set("notifiedAt", time.Now().Unix()).
|
||||||
|
Update()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
6
internal/db/models/node_threshold_dao_test.go
Normal file
6
internal/db/models/node_threshold_dao_test.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
|
)
|
||||||
46
internal/db/models/node_threshold_model.go
Normal file
46
internal/db/models/node_threshold_model.go
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
// NodeThreshold 集群阈值设置
|
||||||
|
type NodeThreshold struct {
|
||||||
|
Id uint64 `field:"id"` // ID
|
||||||
|
Role string `field:"role"` // 节点角色
|
||||||
|
ClusterId uint32 `field:"clusterId"` // 集群ID
|
||||||
|
NodeId uint32 `field:"nodeId"` // 节点ID
|
||||||
|
IsOn uint8 `field:"isOn"` // 是否启用
|
||||||
|
Item string `field:"item"` // 监控项
|
||||||
|
Param string `field:"param"` // 参数
|
||||||
|
Operator string `field:"operator"` // 操作符
|
||||||
|
Value string `field:"value"` // 对比值
|
||||||
|
Message string `field:"message"` // 消息内容
|
||||||
|
NotifyDuration uint32 `field:"notifyDuration"` // 通知间隔
|
||||||
|
NotifiedAt uint32 `field:"notifiedAt"` // 上次通知时间
|
||||||
|
Duration uint32 `field:"duration"` // 时间段
|
||||||
|
DurationUnit string `field:"durationUnit"` // 时间段单位
|
||||||
|
SumMethod string `field:"sumMethod"` // 聚合方法
|
||||||
|
Order uint32 `field:"order"` // 排序
|
||||||
|
State uint8 `field:"state"` // 状态
|
||||||
|
}
|
||||||
|
|
||||||
|
type NodeThresholdOperator struct {
|
||||||
|
Id interface{} // ID
|
||||||
|
Role interface{} // 节点角色
|
||||||
|
ClusterId interface{} // 集群ID
|
||||||
|
NodeId interface{} // 节点ID
|
||||||
|
IsOn interface{} // 是否启用
|
||||||
|
Item interface{} // 监控项
|
||||||
|
Param interface{} // 参数
|
||||||
|
Operator interface{} // 操作符
|
||||||
|
Value interface{} // 对比值
|
||||||
|
Message interface{} // 消息内容
|
||||||
|
NotifyDuration interface{} // 通知间隔
|
||||||
|
NotifiedAt interface{} // 上次通知时间
|
||||||
|
Duration interface{} // 时间段
|
||||||
|
DurationUnit interface{} // 时间段单位
|
||||||
|
SumMethod interface{} // 聚合方法
|
||||||
|
Order interface{} // 排序
|
||||||
|
State interface{} // 状态
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewNodeThresholdOperator() *NodeThresholdOperator {
|
||||||
|
return &NodeThresholdOperator{}
|
||||||
|
}
|
||||||
1
internal/db/models/node_threshold_model_ext.go
Normal file
1
internal/db/models/node_threshold_model_ext.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package models
|
||||||
120
internal/db/models/node_value_dao.go
Normal file
120
internal/db/models/node_value_dao.go
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
"github.com/iwind/TeaGo/Tea"
|
||||||
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type NodeValueDAO dbs.DAO
|
||||||
|
|
||||||
|
func NewNodeValueDAO() *NodeValueDAO {
|
||||||
|
return dbs.NewDAO(&NodeValueDAO{
|
||||||
|
DAOObject: dbs.DAOObject{
|
||||||
|
DB: Tea.Env,
|
||||||
|
Table: "edgeNodeValues",
|
||||||
|
Model: new(NodeValue),
|
||||||
|
PkName: "id",
|
||||||
|
},
|
||||||
|
}).(*NodeValueDAO)
|
||||||
|
}
|
||||||
|
|
||||||
|
var SharedNodeValueDAO *NodeValueDAO
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
dbs.OnReady(func() {
|
||||||
|
SharedNodeValueDAO = NewNodeValueDAO()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateValue 创建值
|
||||||
|
func (this *NodeValueDAO) CreateValue(tx *dbs.Tx, role nodeconfigs.NodeRole, nodeId int64, item string, valueJSON []byte, createdAt int64) error {
|
||||||
|
day := timeutil.FormatTime("Ymd", createdAt)
|
||||||
|
hour := timeutil.FormatTime("YmdH", createdAt)
|
||||||
|
minute := timeutil.FormatTime("YmdHi", createdAt)
|
||||||
|
|
||||||
|
return this.Query(tx).
|
||||||
|
InsertOrUpdateQuickly(maps.Map{
|
||||||
|
"role": role,
|
||||||
|
"nodeId": nodeId,
|
||||||
|
"item": item,
|
||||||
|
"value": valueJSON,
|
||||||
|
"createdAt": createdAt,
|
||||||
|
"day": day,
|
||||||
|
"hour": hour,
|
||||||
|
"minute": minute,
|
||||||
|
}, maps.Map{
|
||||||
|
"value": valueJSON,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteExpiredValues 清除数据
|
||||||
|
func (this *NodeValueDAO) DeleteExpiredValues(tx *dbs.Tx) error {
|
||||||
|
// 删除N天之前的所有数据
|
||||||
|
expiredDays := 100
|
||||||
|
day := timeutil.Format("Ymd", time.Now().AddDate(0, 0, -expiredDays))
|
||||||
|
_, err := this.Query(tx).
|
||||||
|
Where("day<:day").
|
||||||
|
Param("day", day).
|
||||||
|
Delete()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListValues 列出最近的的数据
|
||||||
|
func (this *NodeValueDAO) ListValues(tx *dbs.Tx, role string, nodeId int64, item string, timeRange nodeconfigs.NodeValueRange) (result []*NodeValue, err error) {
|
||||||
|
query := this.Query(tx).
|
||||||
|
Attr("role", role).
|
||||||
|
Attr("nodeId", nodeId).
|
||||||
|
Attr("item", item)
|
||||||
|
|
||||||
|
switch timeRange {
|
||||||
|
// TODO 支持更多的时间范围
|
||||||
|
case nodeconfigs.NodeValueRangeMinute:
|
||||||
|
fromMinute := timeutil.FormatTime("YmdHi", time.Now().Unix()-3600) // 一个小时之前的
|
||||||
|
query.Gte("minute", fromMinute)
|
||||||
|
default:
|
||||||
|
err = errors.New("invalid 'range' value: '" + timeRange + "'")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = query.Slice(&result).
|
||||||
|
FindAll()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// SumValues 计算某项参数值
|
||||||
|
func (this *NodeValueDAO) SumValues(tx *dbs.Tx, role string, nodeId int64, item string, param string, method nodeconfigs.NodeValueSumMethod, duration int32, durationUnit nodeconfigs.NodeValueDurationUnit) (float64, error) {
|
||||||
|
if duration <= 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
query := this.Query(tx).
|
||||||
|
Attr("role", role).
|
||||||
|
Attr("nodeId", nodeId).
|
||||||
|
Attr("item", item)
|
||||||
|
switch method {
|
||||||
|
case nodeconfigs.NodeValueSumMethodAvg:
|
||||||
|
query.Result("AVG(JSON_EXTRACT(value, '$." + param + "'))")
|
||||||
|
case nodeconfigs.NodeValueSumMethodSum:
|
||||||
|
query.Result("SUM(JSON_EXTRACT(value, '$." + param + "'))")
|
||||||
|
default:
|
||||||
|
query.Result("AVG(JSON_EXTRACT(value, '$." + param + "'))")
|
||||||
|
}
|
||||||
|
switch durationUnit {
|
||||||
|
case nodeconfigs.NodeValueDurationUnitMinute:
|
||||||
|
fromMinute := timeutil.FormatTime("YmdHi", time.Now().Unix()-int64(duration * 60))
|
||||||
|
query.Gte("minute", fromMinute)
|
||||||
|
default:
|
||||||
|
fromMinute := timeutil.FormatTime("YmdHi", time.Now().Unix()-int64(duration * 60))
|
||||||
|
query.Gte("minute", fromMinute)
|
||||||
|
}
|
||||||
|
return query.FindFloat64Col(0)
|
||||||
|
}
|
||||||
22
internal/db/models/node_value_dao_test.go
Normal file
22
internal/db/models/node_value_dao_test.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNodeValueDAO_CreateValue(t *testing.T) {
|
||||||
|
dao := NewNodeValueDAO()
|
||||||
|
m := maps.Map{
|
||||||
|
"hello": "world12344",
|
||||||
|
}
|
||||||
|
err := dao.CreateValue(nil, nodeconfigs.NodeRoleNode, 1, "test", m.AsJSON(), time.Now().Unix())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Log("ok")
|
||||||
|
}
|
||||||
30
internal/db/models/node_value_model.go
Normal file
30
internal/db/models/node_value_model.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
// NodeValue 节点监控数据
|
||||||
|
type NodeValue struct {
|
||||||
|
Id uint64 `field:"id"` // ID
|
||||||
|
NodeId uint32 `field:"nodeId"` // 节点ID
|
||||||
|
Role string `field:"role"` // 节点角色
|
||||||
|
Item string `field:"item"` // 监控项
|
||||||
|
Value string `field:"value"` // 数据
|
||||||
|
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||||
|
Day string `field:"day"` // 日期
|
||||||
|
Hour string `field:"hour"` // 小时
|
||||||
|
Minute string `field:"minute"` // 分钟
|
||||||
|
}
|
||||||
|
|
||||||
|
type NodeValueOperator struct {
|
||||||
|
Id interface{} // ID
|
||||||
|
NodeId interface{} // 节点ID
|
||||||
|
Role interface{} // 节点角色
|
||||||
|
Item interface{} // 监控项
|
||||||
|
Value interface{} // 数据
|
||||||
|
CreatedAt interface{} // 创建时间
|
||||||
|
Day interface{} // 日期
|
||||||
|
Hour interface{} // 小时
|
||||||
|
Minute interface{} // 分钟
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewNodeValueOperator() *NodeValueOperator {
|
||||||
|
return &NodeValueOperator{}
|
||||||
|
}
|
||||||
1
internal/db/models/node_value_model_ext.go
Normal file
1
internal/db/models/node_value_model_ext.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package models
|
||||||
@@ -5,6 +5,7 @@ const (
|
|||||||
LevelInfo = "info"
|
LevelInfo = "info"
|
||||||
LevelWarning = "warning"
|
LevelWarning = "warning"
|
||||||
LevelError = "error"
|
LevelError = "error"
|
||||||
|
LevelSuccess = "success"
|
||||||
|
|
||||||
LogTypeAdmin = "admin"
|
LogTypeAdmin = "admin"
|
||||||
LogTypeUser = "user"
|
LogTypeUser = "user"
|
||||||
|
|||||||
315
internal/db/models/ns_access_log_dao.go
Normal file
315
internal/db/models/ns_access_log_dao.go
Normal file
@@ -0,0 +1,315 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/configs"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
"github.com/iwind/TeaGo/Tea"
|
||||||
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
"github.com/iwind/TeaGo/lists"
|
||||||
|
"github.com/iwind/TeaGo/logs"
|
||||||
|
"github.com/iwind/TeaGo/types"
|
||||||
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
|
"regexp"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type NSAccessLogDAO dbs.DAO
|
||||||
|
|
||||||
|
func NewNSAccessLogDAO() *NSAccessLogDAO {
|
||||||
|
return dbs.NewDAO(&NSAccessLogDAO{
|
||||||
|
DAOObject: dbs.DAOObject{
|
||||||
|
DB: Tea.Env,
|
||||||
|
Table: "edgeNSAccessLogs",
|
||||||
|
Model: new(NSAccessLog),
|
||||||
|
PkName: "id",
|
||||||
|
},
|
||||||
|
}).(*NSAccessLogDAO)
|
||||||
|
}
|
||||||
|
|
||||||
|
var SharedNSAccessLogDAO *NSAccessLogDAO
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
dbs.OnReady(func() {
|
||||||
|
SharedNSAccessLogDAO = NewNSAccessLogDAO()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateNSAccessLogs 创建访问日志
|
||||||
|
func (this *NSAccessLogDAO) CreateNSAccessLogs(tx *dbs.Tx, accessLogs []*pb.NSAccessLog) error {
|
||||||
|
dao := randomNSAccessLogDAO()
|
||||||
|
if dao == nil {
|
||||||
|
dao = &NSAccessLogDAOWrapper{
|
||||||
|
DAO: SharedNSAccessLogDAO,
|
||||||
|
NodeId: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.CreateNSAccessLogsWithDAO(tx, dao, accessLogs)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateNSAccessLogsWithDAO 使用特定的DAO创建访问日志
|
||||||
|
func (this *NSAccessLogDAO) CreateNSAccessLogsWithDAO(tx *dbs.Tx, daoWrapper *NSAccessLogDAOWrapper, accessLogs []*pb.NSAccessLog) error {
|
||||||
|
if daoWrapper == nil {
|
||||||
|
return errors.New("dao should not be nil")
|
||||||
|
}
|
||||||
|
if len(accessLogs) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
dao := daoWrapper.DAO
|
||||||
|
|
||||||
|
// TODO 改成事务批量提交,以加快速度
|
||||||
|
|
||||||
|
for _, accessLog := range accessLogs {
|
||||||
|
day := timeutil.Format("Ymd", time.Unix(accessLog.Timestamp, 0))
|
||||||
|
table, err := findNSAccessLogTable(dao.Instance, day, false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fields := map[string]interface{}{}
|
||||||
|
fields["nodeId"] = accessLog.NsNodeId
|
||||||
|
fields["domainId"] = accessLog.NsDomainId
|
||||||
|
fields["recordId"] = accessLog.NsRecordId
|
||||||
|
fields["createdAt"] = accessLog.Timestamp
|
||||||
|
fields["requestId"] = accessLog.RequestId + strconv.FormatInt(time.Now().UnixNano(), 10) + configs.PaddingId
|
||||||
|
|
||||||
|
content, err := json.Marshal(accessLog)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fields["content"] = content
|
||||||
|
|
||||||
|
_, err = dao.Query(tx).
|
||||||
|
Table(table).
|
||||||
|
Sets(fields).
|
||||||
|
Insert()
|
||||||
|
if err != nil {
|
||||||
|
// 是否为 Error 1146: Table 'xxx.xxx' doesn't exist 如果是,则创建表之后重试
|
||||||
|
if strings.Contains(err.Error(), "1146") {
|
||||||
|
table, err = findNSAccessLogTable(dao.Instance, day, true)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = dao.Query(tx).
|
||||||
|
Table(table).
|
||||||
|
Sets(fields).
|
||||||
|
Insert()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListAccessLogs 读取往前的 单页访问日志
|
||||||
|
func (this *NSAccessLogDAO) ListAccessLogs(tx *dbs.Tx, lastRequestId string, size int64, day string, nodeId int64, domainId int64, recordId int64, keyword string, reverse bool) (result []*NSAccessLog, nextLastRequestId string, hasMore bool, err error) {
|
||||||
|
if len(day) != 8 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 限制能查询的最大条数,防止占用内存过多
|
||||||
|
if size > 1000 {
|
||||||
|
size = 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
result, nextLastRequestId, err = this.listAccessLogs(tx, lastRequestId, size, day, nodeId, domainId, recordId, keyword, reverse)
|
||||||
|
if err != nil || int64(len(result)) < size {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
moreResult, _, _ := this.listAccessLogs(tx, nextLastRequestId, 1, day, nodeId, domainId, recordId, keyword, reverse)
|
||||||
|
hasMore = len(moreResult) > 0
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取往前的单页访问日志
|
||||||
|
func (this *NSAccessLogDAO) listAccessLogs(tx *dbs.Tx, lastRequestId string, size int64, day string, nodeId int64, domainId int64, recordId int64, keyword string, reverse bool) (result []*NSAccessLog, nextLastRequestId string, err error) {
|
||||||
|
if size <= 0 {
|
||||||
|
return nil, lastRequestId, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
accessLogLocker.RLock()
|
||||||
|
daoList := []*NSAccessLogDAOWrapper{}
|
||||||
|
for _, daoWrapper := range nsAccessLogDAOMapping {
|
||||||
|
daoList = append(daoList, daoWrapper)
|
||||||
|
}
|
||||||
|
accessLogLocker.RUnlock()
|
||||||
|
|
||||||
|
if len(daoList) == 0 {
|
||||||
|
daoList = []*NSAccessLogDAOWrapper{{
|
||||||
|
DAO: SharedNSAccessLogDAO,
|
||||||
|
NodeId: 0,
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
locker := sync.Mutex{}
|
||||||
|
|
||||||
|
count := len(daoList)
|
||||||
|
wg := &sync.WaitGroup{}
|
||||||
|
wg.Add(count)
|
||||||
|
for _, daoWrapper := range daoList {
|
||||||
|
go func(daoWrapper *NSAccessLogDAOWrapper) {
|
||||||
|
defer wg.Done()
|
||||||
|
|
||||||
|
dao := daoWrapper.DAO
|
||||||
|
|
||||||
|
tableName, exists, err := findNSAccessLogTableName(dao.Instance, day)
|
||||||
|
if !exists {
|
||||||
|
// 表格不存在则跳过
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
logs.Println("[DB_NODE]" + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
query := dao.Query(tx)
|
||||||
|
|
||||||
|
// 条件
|
||||||
|
if nodeId > 0 {
|
||||||
|
query.Attr("nodeId", nodeId)
|
||||||
|
}
|
||||||
|
if domainId > 0 {
|
||||||
|
query.Attr("domainId", domainId)
|
||||||
|
}
|
||||||
|
if recordId > 0 {
|
||||||
|
query.Attr("recordId", recordId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// offset
|
||||||
|
if len(lastRequestId) > 0 {
|
||||||
|
if !reverse {
|
||||||
|
query.Where("requestId<:requestId").
|
||||||
|
Param("requestId", lastRequestId)
|
||||||
|
} else {
|
||||||
|
query.Where("requestId>:requestId").
|
||||||
|
Param("requestId", lastRequestId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// keyword
|
||||||
|
if len(keyword) > 0 {
|
||||||
|
query.Where("(JSON_EXTRACT(content, '$.remoteAddr') LIKE :keyword OR JSON_EXTRACT(content, '$.questionName') LIKE :keyword OR JSON_EXTRACT(content, '$.recordValue') LIKE :keyword)").
|
||||||
|
Param("keyword", "%"+keyword+"%")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reverse {
|
||||||
|
query.Desc("requestId")
|
||||||
|
} else {
|
||||||
|
query.Asc("requestId")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开始查询
|
||||||
|
ones, err := query.
|
||||||
|
Table(tableName).
|
||||||
|
Limit(size).
|
||||||
|
FindAll()
|
||||||
|
if err != nil {
|
||||||
|
logs.Println("[DB_NODE]" + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
locker.Lock()
|
||||||
|
for _, one := range ones {
|
||||||
|
accessLog := one.(*NSAccessLog)
|
||||||
|
result = append(result, accessLog)
|
||||||
|
}
|
||||||
|
locker.Unlock()
|
||||||
|
}(daoWrapper)
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
if len(result) == 0 {
|
||||||
|
return nil, lastRequestId, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按照requestId排序
|
||||||
|
sort.Slice(result, func(i, j int) bool {
|
||||||
|
if !reverse {
|
||||||
|
return result[i].RequestId > result[j].RequestId
|
||||||
|
} else {
|
||||||
|
return result[i].RequestId < result[j].RequestId
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if int64(len(result)) > size {
|
||||||
|
result = result[:size]
|
||||||
|
}
|
||||||
|
|
||||||
|
requestId := result[len(result)-1].RequestId
|
||||||
|
if reverse {
|
||||||
|
lists.Reverse(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reverse {
|
||||||
|
return result, requestId, nil
|
||||||
|
} else {
|
||||||
|
return result, requestId, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindAccessLogWithRequestId 根据请求ID获取访问日志
|
||||||
|
func (this *NSAccessLogDAO) FindAccessLogWithRequestId(tx *dbs.Tx, requestId string) (*NSAccessLog, error) {
|
||||||
|
if !regexp.MustCompile(`^\d{30,}`).MatchString(requestId) {
|
||||||
|
return nil, errors.New("invalid requestId")
|
||||||
|
}
|
||||||
|
|
||||||
|
accessLogLocker.RLock()
|
||||||
|
daoList := []*NSAccessLogDAOWrapper{}
|
||||||
|
for _, daoWrapper := range nsAccessLogDAOMapping {
|
||||||
|
daoList = append(daoList, daoWrapper)
|
||||||
|
}
|
||||||
|
accessLogLocker.RUnlock()
|
||||||
|
|
||||||
|
if len(daoList) == 0 {
|
||||||
|
daoList = []*NSAccessLogDAOWrapper{{
|
||||||
|
DAO: SharedNSAccessLogDAO,
|
||||||
|
NodeId: 0,
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
count := len(daoList)
|
||||||
|
wg := &sync.WaitGroup{}
|
||||||
|
wg.Add(count)
|
||||||
|
var result *NSAccessLog = nil
|
||||||
|
day := timeutil.FormatTime("Ymd", types.Int64(requestId[:10]))
|
||||||
|
for _, daoWrapper := range daoList {
|
||||||
|
go func(daoWrapper *NSAccessLogDAOWrapper) {
|
||||||
|
defer wg.Done()
|
||||||
|
|
||||||
|
dao := daoWrapper.DAO
|
||||||
|
|
||||||
|
tableName, exists, err := findNSAccessLogTableName(dao.Instance, day)
|
||||||
|
if err != nil {
|
||||||
|
logs.Println("[DB_NODE]" + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !exists {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
one, err := dao.Query(tx).
|
||||||
|
Table(tableName).
|
||||||
|
Attr("requestId", requestId).
|
||||||
|
Find()
|
||||||
|
if err != nil {
|
||||||
|
logs.Println("[DB_NODE]" + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if one != nil {
|
||||||
|
result = one.(*NSAccessLog)
|
||||||
|
}
|
||||||
|
}(daoWrapper)
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
6
internal/db/models/ns_access_log_dao_test.go
Normal file
6
internal/db/models/ns_access_log_dao_test.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
|
)
|
||||||
26
internal/db/models/ns_access_log_model.go
Normal file
26
internal/db/models/ns_access_log_model.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
// NSAccessLog 域名服务访问日志
|
||||||
|
type NSAccessLog struct {
|
||||||
|
Id uint64 `field:"id"` // ID
|
||||||
|
NodeId uint32 `field:"nodeId"` // 节点ID
|
||||||
|
DomainId uint32 `field:"domainId"` // 域名ID
|
||||||
|
RecordId uint32 `field:"recordId"` // 记录ID
|
||||||
|
Content string `field:"content"` // 访问数据
|
||||||
|
RequestId string `field:"requestId"` // 请求ID
|
||||||
|
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||||
|
}
|
||||||
|
|
||||||
|
type NSAccessLogOperator struct {
|
||||||
|
Id interface{} // ID
|
||||||
|
NodeId interface{} // 节点ID
|
||||||
|
DomainId interface{} // 域名ID
|
||||||
|
RecordId interface{} // 记录ID
|
||||||
|
Content interface{} // 访问数据
|
||||||
|
RequestId interface{} // 请求ID
|
||||||
|
CreatedAt interface{} // 创建时间
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewNSAccessLogOperator() *NSAccessLogOperator {
|
||||||
|
return &NSAccessLogOperator{}
|
||||||
|
}
|
||||||
17
internal/db/models/ns_access_log_model_ext.go
Normal file
17
internal/db/models/ns_access_log_model_ext.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ToPB 转换成PB对象
|
||||||
|
func (this *NSAccessLog) ToPB() (*pb.NSAccessLog, error) {
|
||||||
|
p := &pb.NSAccessLog{}
|
||||||
|
err := json.Unmarshal([]byte(this.Content), p)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
p.RequestId = this.RequestId
|
||||||
|
return p, nil
|
||||||
|
}
|
||||||
@@ -38,12 +38,12 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化
|
// Init 初始化
|
||||||
func (this *ReverseProxyDAO) Init() {
|
func (this *ReverseProxyDAO) Init() {
|
||||||
_ = this.DAOObject.Init()
|
_ = this.DAOObject.Init()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启用条目
|
// EnableReverseProxy 启用条目
|
||||||
func (this *ReverseProxyDAO) EnableReverseProxy(tx *dbs.Tx, id int64) error {
|
func (this *ReverseProxyDAO) EnableReverseProxy(tx *dbs.Tx, id int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -55,7 +55,7 @@ func (this *ReverseProxyDAO) EnableReverseProxy(tx *dbs.Tx, id int64) error {
|
|||||||
return this.NotifyUpdate(tx, id)
|
return this.NotifyUpdate(tx, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 禁用条目
|
// DisableReverseProxy 禁用条目
|
||||||
func (this *ReverseProxyDAO) DisableReverseProxy(tx *dbs.Tx, id int64) error {
|
func (this *ReverseProxyDAO) DisableReverseProxy(tx *dbs.Tx, id int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -67,7 +67,7 @@ func (this *ReverseProxyDAO) DisableReverseProxy(tx *dbs.Tx, id int64) error {
|
|||||||
return this.NotifyUpdate(tx, id)
|
return this.NotifyUpdate(tx, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找启用中的条目
|
// FindEnabledReverseProxy 查找启用中的条目
|
||||||
func (this *ReverseProxyDAO) FindEnabledReverseProxy(tx *dbs.Tx, id int64) (*ReverseProxy, error) {
|
func (this *ReverseProxyDAO) FindEnabledReverseProxy(tx *dbs.Tx, id int64) (*ReverseProxy, error) {
|
||||||
result, err := this.Query(tx).
|
result, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -79,7 +79,7 @@ func (this *ReverseProxyDAO) FindEnabledReverseProxy(tx *dbs.Tx, id int64) (*Rev
|
|||||||
return result.(*ReverseProxy), err
|
return result.(*ReverseProxy), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据iD组合配置
|
// ComposeReverseProxyConfig 根据ID组合配置
|
||||||
func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyId int64) (*serverconfigs.ReverseProxyConfig, error) {
|
func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyId int64) (*serverconfigs.ReverseProxyConfig, error) {
|
||||||
reverseProxy, err := this.FindEnabledReverseProxy(tx, reverseProxyId)
|
reverseProxy, err := this.FindEnabledReverseProxy(tx, reverseProxyId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -184,13 +184,14 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
|
|||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建反向代理
|
// CreateReverseProxy 创建反向代理
|
||||||
func (this *ReverseProxyDAO) CreateReverseProxy(tx *dbs.Tx, adminId int64, userId int64, schedulingJSON []byte, primaryOriginsJSON []byte, backupOriginsJSON []byte) (int64, error) {
|
func (this *ReverseProxyDAO) CreateReverseProxy(tx *dbs.Tx, adminId int64, userId int64, schedulingJSON []byte, primaryOriginsJSON []byte, backupOriginsJSON []byte) (int64, error) {
|
||||||
op := NewReverseProxyOperator()
|
op := NewReverseProxyOperator()
|
||||||
op.IsOn = true
|
op.IsOn = true
|
||||||
op.State = ReverseProxyStateEnabled
|
op.State = ReverseProxyStateEnabled
|
||||||
op.AdminId = adminId
|
op.AdminId = adminId
|
||||||
op.UserId = userId
|
op.UserId = userId
|
||||||
|
op.RequestHostType = serverconfigs.RequestHostTypeProxyServer
|
||||||
|
|
||||||
defaultHeaders := []string{"X-Real-IP", "X-Forwarded-For", "X-Forwarded-By", "X-Forwarded-Host", "X-Forwarded-Proto"}
|
defaultHeaders := []string{"X-Real-IP", "X-Forwarded-For", "X-Forwarded-By", "X-Forwarded-Host", "X-Forwarded-Proto"}
|
||||||
defaultHeadersJSON, err := json.Marshal(defaultHeaders)
|
defaultHeadersJSON, err := json.Marshal(defaultHeaders)
|
||||||
@@ -216,7 +217,7 @@ func (this *ReverseProxyDAO) CreateReverseProxy(tx *dbs.Tx, adminId int64, userI
|
|||||||
return types.Int64(op.Id), nil
|
return types.Int64(op.Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改反向代理调度算法
|
// UpdateReverseProxyScheduling 修改反向代理调度算法
|
||||||
func (this *ReverseProxyDAO) UpdateReverseProxyScheduling(tx *dbs.Tx, reverseProxyId int64, schedulingJSON []byte) error {
|
func (this *ReverseProxyDAO) UpdateReverseProxyScheduling(tx *dbs.Tx, reverseProxyId int64, schedulingJSON []byte) error {
|
||||||
if reverseProxyId <= 0 {
|
if reverseProxyId <= 0 {
|
||||||
return errors.New("invalid reverseProxyId")
|
return errors.New("invalid reverseProxyId")
|
||||||
@@ -235,7 +236,7 @@ func (this *ReverseProxyDAO) UpdateReverseProxyScheduling(tx *dbs.Tx, reversePro
|
|||||||
return this.NotifyUpdate(tx, reverseProxyId)
|
return this.NotifyUpdate(tx, reverseProxyId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改主要源站
|
// UpdateReverseProxyPrimaryOrigins 修改主要源站
|
||||||
func (this *ReverseProxyDAO) UpdateReverseProxyPrimaryOrigins(tx *dbs.Tx, reverseProxyId int64, origins []byte) error {
|
func (this *ReverseProxyDAO) UpdateReverseProxyPrimaryOrigins(tx *dbs.Tx, reverseProxyId int64, origins []byte) error {
|
||||||
if reverseProxyId <= 0 {
|
if reverseProxyId <= 0 {
|
||||||
return errors.New("invalid reverseProxyId")
|
return errors.New("invalid reverseProxyId")
|
||||||
@@ -254,7 +255,7 @@ func (this *ReverseProxyDAO) UpdateReverseProxyPrimaryOrigins(tx *dbs.Tx, revers
|
|||||||
return this.NotifyUpdate(tx, reverseProxyId)
|
return this.NotifyUpdate(tx, reverseProxyId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改备用源站
|
// UpdateReverseProxyBackupOrigins 修改备用源站
|
||||||
func (this *ReverseProxyDAO) UpdateReverseProxyBackupOrigins(tx *dbs.Tx, reverseProxyId int64, origins []byte) error {
|
func (this *ReverseProxyDAO) UpdateReverseProxyBackupOrigins(tx *dbs.Tx, reverseProxyId int64, origins []byte) error {
|
||||||
if reverseProxyId <= 0 {
|
if reverseProxyId <= 0 {
|
||||||
return errors.New("invalid reverseProxyId")
|
return errors.New("invalid reverseProxyId")
|
||||||
@@ -273,7 +274,7 @@ func (this *ReverseProxyDAO) UpdateReverseProxyBackupOrigins(tx *dbs.Tx, reverse
|
|||||||
return this.NotifyUpdate(tx, reverseProxyId)
|
return this.NotifyUpdate(tx, reverseProxyId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改是否启用
|
// UpdateReverseProxy 修改是否启用
|
||||||
func (this *ReverseProxyDAO) UpdateReverseProxy(tx *dbs.Tx, reverseProxyId int64, requestHostType int8, requestHost string, requestURI string, stripPrefix string, autoFlush bool, addHeaders []string, connTimeout *shared.TimeDuration, readTimeout *shared.TimeDuration, idleTimeout *shared.TimeDuration, maxConns int32, maxIdleConns int32) error {
|
func (this *ReverseProxyDAO) UpdateReverseProxy(tx *dbs.Tx, reverseProxyId int64, requestHostType int8, requestHost string, requestURI string, stripPrefix string, autoFlush bool, addHeaders []string, connTimeout *shared.TimeDuration, readTimeout *shared.TimeDuration, idleTimeout *shared.TimeDuration, maxConns int32, maxIdleConns int32) error {
|
||||||
if reverseProxyId <= 0 {
|
if reverseProxyId <= 0 {
|
||||||
return errors.New("invalid reverseProxyId")
|
return errors.New("invalid reverseProxyId")
|
||||||
@@ -340,7 +341,7 @@ func (this *ReverseProxyDAO) UpdateReverseProxy(tx *dbs.Tx, reverseProxyId int64
|
|||||||
return this.NotifyUpdate(tx, reverseProxyId)
|
return this.NotifyUpdate(tx, reverseProxyId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找包含某个源站的反向代理ID
|
// FindReverseProxyContainsOriginId 查找包含某个源站的反向代理ID
|
||||||
func (this *ReverseProxyDAO) FindReverseProxyContainsOriginId(tx *dbs.Tx, originId int64) (int64, error) {
|
func (this *ReverseProxyDAO) FindReverseProxyContainsOriginId(tx *dbs.Tx, originId int64) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
ResultPk().
|
ResultPk().
|
||||||
@@ -351,7 +352,31 @@ func (this *ReverseProxyDAO) FindReverseProxyContainsOriginId(tx *dbs.Tx, origin
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通知更新
|
// CheckUserReverseProxy 检查用户权限
|
||||||
|
func (this *ReverseProxyDAO) CheckUserReverseProxy(tx *dbs.Tx, userId int64, reverseProxyId int64) error {
|
||||||
|
exists, err := this.Query(tx).
|
||||||
|
Pk(reverseProxyId).
|
||||||
|
Attr("userId", userId).
|
||||||
|
Exist()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if exists {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查server是否为用户的
|
||||||
|
serverId, err := SharedServerDAO.FindEnabledServerIdWithReverseProxyId(tx, reverseProxyId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if serverId == 0 {
|
||||||
|
return ErrNotFound
|
||||||
|
}
|
||||||
|
return SharedServerDAO.CheckUserServer(tx, userId, serverId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyUpdate 通知更新
|
||||||
func (this *ReverseProxyDAO) NotifyUpdate(tx *dbs.Tx, reverseProxyId int64) error {
|
func (this *ReverseProxyDAO) NotifyUpdate(tx *dbs.Tx, reverseProxyId int64) error {
|
||||||
serverId, err := SharedServerDAO.FindEnabledServerIdWithReverseProxyId(tx, reverseProxyId)
|
serverId, err := SharedServerDAO.FindEnabledServerIdWithReverseProxyId(tx, reverseProxyId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServerDailyStatDAO dbs.DAO
|
type ServerDailyStatDAO dbs.DAO
|
||||||
@@ -30,24 +31,33 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 提交数据
|
// SaveStats 提交数据
|
||||||
func (this *ServerDailyStatDAO) SaveStats(tx *dbs.Tx, stats []*pb.ServerDailyStat) error {
|
func (this *ServerDailyStatDAO) SaveStats(tx *dbs.Tx, stats []*pb.ServerDailyStat) error {
|
||||||
for _, stat := range stats {
|
for _, stat := range stats {
|
||||||
day := timeutil.FormatTime("Ymd", stat.CreatedAt)
|
day := timeutil.FormatTime("Ymd", stat.CreatedAt)
|
||||||
timeFrom := timeutil.FormatTime("His", stat.CreatedAt)
|
timeFrom := timeutil.FormatTime("His", stat.CreatedAt)
|
||||||
timeTo := timeutil.FormatTime("His", stat.CreatedAt+5*60) // 5分钟
|
timeTo := timeutil.FormatTime("His", stat.CreatedAt+5*60-1) // 5分钟
|
||||||
|
|
||||||
_, _, err := this.Query(tx).
|
_, _, err := this.Query(tx).
|
||||||
Param("bytes", stat.Bytes).
|
Param("bytes", stat.Bytes).
|
||||||
|
Param("cachedBytes", stat.CachedBytes).
|
||||||
|
Param("countRequests", stat.CountRequests).
|
||||||
|
Param("countCachedRequests", stat.CountCachedRequests).
|
||||||
InsertOrUpdate(maps.Map{
|
InsertOrUpdate(maps.Map{
|
||||||
"serverId": stat.ServerId,
|
"serverId": stat.ServerId,
|
||||||
"regionId": stat.RegionId,
|
"regionId": stat.RegionId,
|
||||||
"bytes": dbs.SQL("bytes+:bytes"),
|
"bytes": dbs.SQL("bytes+:bytes"),
|
||||||
"day": day,
|
"cachedBytes": dbs.SQL("cachedBytes+:cachedBytes"),
|
||||||
"timeFrom": timeFrom,
|
"countRequests": dbs.SQL("countRequests+:countRequests"),
|
||||||
"timeTo": timeTo,
|
"countCachedRequests": dbs.SQL("countCachedRequests+:countCachedRequests"),
|
||||||
|
"day": day,
|
||||||
|
"timeFrom": timeFrom,
|
||||||
|
"timeTo": timeTo,
|
||||||
}, maps.Map{
|
}, maps.Map{
|
||||||
"bytes": dbs.SQL("bytes+:bytes"),
|
"bytes": dbs.SQL("bytes+:bytes"),
|
||||||
|
"cachedBytes": dbs.SQL("cachedBytes+:cachedBytes"),
|
||||||
|
"countRequests": dbs.SQL("countRequests+:countRequests"),
|
||||||
|
"countCachedRequests": dbs.SQL("countCachedRequests+:countCachedRequests"),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -56,7 +66,7 @@ func (this *ServerDailyStatDAO) SaveStats(tx *dbs.Tx, stats []*pb.ServerDailySta
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据用户计算某月合计
|
// SumUserMonthly 根据用户计算某月合计
|
||||||
// month 格式为YYYYMM
|
// month 格式为YYYYMM
|
||||||
func (this *ServerDailyStatDAO) SumUserMonthly(tx *dbs.Tx, userId int64, regionId int64, month string) (int64, error) {
|
func (this *ServerDailyStatDAO) SumUserMonthly(tx *dbs.Tx, userId int64, regionId int64, month string) (int64, error) {
|
||||||
query := this.Query(tx)
|
query := this.Query(tx)
|
||||||
@@ -69,7 +79,7 @@ func (this *ServerDailyStatDAO) SumUserMonthly(tx *dbs.Tx, userId int64, regionI
|
|||||||
SumInt64("bytes", 0)
|
SumInt64("bytes", 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取某月带宽峰值
|
// SumUserMonthlyPeek 获取某月带宽峰值
|
||||||
// month 格式为YYYYMM
|
// month 格式为YYYYMM
|
||||||
func (this *ServerDailyStatDAO) SumUserMonthlyPeek(tx *dbs.Tx, userId int64, regionId int64, month string) (int64, error) {
|
func (this *ServerDailyStatDAO) SumUserMonthlyPeek(tx *dbs.Tx, userId int64, regionId int64, month string) (int64, error) {
|
||||||
query := this.Query(tx)
|
query := this.Query(tx)
|
||||||
@@ -86,7 +96,7 @@ func (this *ServerDailyStatDAO) SumUserMonthlyPeek(tx *dbs.Tx, userId int64, reg
|
|||||||
return int64(max), nil
|
return int64(max), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取某天流量总和
|
// SumUserDaily 获取某天流量总和
|
||||||
// day 格式为YYYYMMDD
|
// day 格式为YYYYMMDD
|
||||||
func (this *ServerDailyStatDAO) SumUserDaily(tx *dbs.Tx, userId int64, regionId int64, day string) (int64, error) {
|
func (this *ServerDailyStatDAO) SumUserDaily(tx *dbs.Tx, userId int64, regionId int64, day string) (int64, error) {
|
||||||
query := this.Query(tx)
|
query := this.Query(tx)
|
||||||
@@ -100,7 +110,7 @@ func (this *ServerDailyStatDAO) SumUserDaily(tx *dbs.Tx, userId int64, regionId
|
|||||||
SumInt64("bytes", 0)
|
SumInt64("bytes", 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取某天带宽峰值
|
// SumUserDailyPeek 获取某天带宽峰值
|
||||||
// day 格式为YYYYMMDD
|
// day 格式为YYYYMMDD
|
||||||
func (this *ServerDailyStatDAO) SumUserDailyPeek(tx *dbs.Tx, userId int64, regionId int64, day string) (int64, error) {
|
func (this *ServerDailyStatDAO) SumUserDailyPeek(tx *dbs.Tx, userId int64, regionId int64, day string) (int64, error) {
|
||||||
query := this.Query(tx)
|
query := this.Query(tx)
|
||||||
@@ -117,3 +127,93 @@ func (this *ServerDailyStatDAO) SumUserDailyPeek(tx *dbs.Tx, userId int64, regio
|
|||||||
}
|
}
|
||||||
return int64(max), nil
|
return int64(max), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SumMinutelyStat 获取某个分钟内的流量
|
||||||
|
// minute 格式为YYYYMMDDHHMM,并且已经格式化成每5分钟一个值
|
||||||
|
func (this *ServerDailyStatDAO) SumMinutelyStat(tx *dbs.Tx, serverId int64, minute string) (stat *pb.ServerDailyStat, err error) {
|
||||||
|
stat = &pb.ServerDailyStat{}
|
||||||
|
|
||||||
|
if !regexp.MustCompile(`^\d{12}$`).MatchString(minute) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
one, _, err := this.Query(tx).
|
||||||
|
Result("SUM(bytes) AS bytes, SUM(cachedBytes) AS cachedBytes, SUM(countRequests) AS countRequests, SUM(countCachedRequests) AS countCachedRequests").
|
||||||
|
Attr("serverId", serverId).
|
||||||
|
Attr("day", minute[:8]).
|
||||||
|
Attr("timeFrom", minute[8:]+"00").
|
||||||
|
FindOne()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if one == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
stat.Bytes = one.GetInt64("bytes")
|
||||||
|
stat.CachedBytes = one.GetInt64("cachedBytes")
|
||||||
|
stat.CountRequests = one.GetInt64("countRequests")
|
||||||
|
stat.CountCachedRequests = one.GetInt64("countCachedRequests")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// SumHourlyStat 获取某个小时内的流量
|
||||||
|
// hour 格式为YYYYMMDDHH
|
||||||
|
func (this *ServerDailyStatDAO) SumHourlyStat(tx *dbs.Tx, serverId int64, hour string) (stat *pb.ServerDailyStat, err error) {
|
||||||
|
stat = &pb.ServerDailyStat{}
|
||||||
|
|
||||||
|
if !regexp.MustCompile(`^\d{10}$`).MatchString(hour) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
one, _, err := this.Query(tx).
|
||||||
|
Result("SUM(bytes) AS bytes, SUM(cachedBytes) AS cachedBytes, SUM(countRequests) AS countRequests, SUM(countCachedRequests) AS countCachedRequests").
|
||||||
|
Attr("serverId", serverId).
|
||||||
|
Attr("day", hour[:8]).
|
||||||
|
Gte("timeFrom", hour[8:]+"0000").
|
||||||
|
Lte("timeTo", hour[8:]+"5959").
|
||||||
|
FindOne()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if one == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
stat.Bytes = one.GetInt64("bytes")
|
||||||
|
stat.CachedBytes = one.GetInt64("cachedBytes")
|
||||||
|
stat.CountRequests = one.GetInt64("countRequests")
|
||||||
|
stat.CountCachedRequests = one.GetInt64("countCachedRequests")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// SumDailyStat 获取某天内的流量
|
||||||
|
// day 格式为YYYYMMDD
|
||||||
|
func (this *ServerDailyStatDAO) SumDailyStat(tx *dbs.Tx, serverId int64, day string) (stat *pb.ServerDailyStat, err error) {
|
||||||
|
stat = &pb.ServerDailyStat{}
|
||||||
|
|
||||||
|
if !regexp.MustCompile(`^\d{8}$`).MatchString(day) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
one, _, err := this.Query(tx).
|
||||||
|
Result("SUM(bytes) AS bytes, SUM(cachedBytes) AS cachedBytes, SUM(countRequests) AS countRequests, SUM(countCachedRequests) AS countCachedRequests").
|
||||||
|
Attr("serverId", serverId).
|
||||||
|
Attr("day", day).
|
||||||
|
FindOne()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if one == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
stat.Bytes = one.GetInt64("bytes")
|
||||||
|
stat.CachedBytes = one.GetInt64("cachedBytes")
|
||||||
|
stat.CountRequests = one.GetInt64("countRequests")
|
||||||
|
stat.CountCachedRequests = one.GetInt64("countCachedRequests")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
"github.com/iwind/TeaGo/logs"
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@@ -51,3 +52,25 @@ func TestServerDailyStatDAO_SumUserMonthly(t *testing.T) {
|
|||||||
}
|
}
|
||||||
t.Log("bytes:", bytes)
|
t.Log("bytes:", bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestServerDailyStatDAO_SumHourlyRequests(t *testing.T) {
|
||||||
|
dbs.NotifyReady()
|
||||||
|
var tx *dbs.Tx
|
||||||
|
|
||||||
|
stat, err := NewServerDailyStatDAO().SumHourlyStat(tx, 23, timeutil.Format("YmdH"))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
logs.PrintAsJSON(stat, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestServerDailyStatDAO_SumMinutelyRequests(t *testing.T) {
|
||||||
|
dbs.NotifyReady()
|
||||||
|
var tx *dbs.Tx
|
||||||
|
|
||||||
|
stat, err := NewServerDailyStatDAO().SumMinutelyStat(tx, 23, timeutil.Format("Ymd") + "1435")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
logs.PrintAsJSON(stat, t)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,26 +1,32 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
// 计费流量统计
|
// ServerDailyStat 计费流量统计
|
||||||
type ServerDailyStat struct {
|
type ServerDailyStat struct {
|
||||||
Id uint64 `field:"id"` // ID
|
Id uint64 `field:"id"` // ID
|
||||||
ServerId uint32 `field:"serverId"` // 服务ID
|
ServerId uint32 `field:"serverId"` // 服务ID
|
||||||
RegionId uint32 `field:"regionId"` // 区域ID
|
RegionId uint32 `field:"regionId"` // 区域ID
|
||||||
Bytes uint64 `field:"bytes"` // 流量
|
Bytes uint64 `field:"bytes"` // 流量
|
||||||
Day string `field:"day"` // 日期YYYYMMDD
|
CachedBytes uint64 `field:"cachedBytes"` // 缓存的流量
|
||||||
TimeFrom string `field:"timeFrom"` // 开始时间HHMMSS
|
CountRequests uint64 `field:"countRequests"` // 请求数
|
||||||
TimeTo string `field:"timeTo"` // 结束时间
|
CountCachedRequests uint64 `field:"countCachedRequests"` // 缓存的请求数
|
||||||
IsCharged uint8 `field:"isCharged"` // 是否已计算费用
|
Day string `field:"day"` // 日期YYYYMMDD
|
||||||
|
TimeFrom string `field:"timeFrom"` // 开始时间HHMMSS
|
||||||
|
TimeTo string `field:"timeTo"` // 结束时间
|
||||||
|
IsCharged uint8 `field:"isCharged"` // 是否已计算费用
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServerDailyStatOperator struct {
|
type ServerDailyStatOperator struct {
|
||||||
Id interface{} // ID
|
Id interface{} // ID
|
||||||
ServerId interface{} // 服务ID
|
ServerId interface{} // 服务ID
|
||||||
RegionId interface{} // 区域ID
|
RegionId interface{} // 区域ID
|
||||||
Bytes interface{} // 流量
|
Bytes interface{} // 流量
|
||||||
Day interface{} // 日期YYYYMMDD
|
CachedBytes interface{} // 缓存的流量
|
||||||
TimeFrom interface{} // 开始时间HHMMSS
|
CountRequests interface{} // 请求数
|
||||||
TimeTo interface{} // 结束时间
|
CountCachedRequests interface{} // 缓存的请求数
|
||||||
IsCharged interface{} // 是否已计算费用
|
Day interface{} // 日期YYYYMMDD
|
||||||
|
TimeFrom interface{} // 开始时间HHMMSS
|
||||||
|
TimeTo interface{} // 结束时间
|
||||||
|
IsCharged interface{} // 是否已计算费用
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServerDailyStatOperator() *ServerDailyStatOperator {
|
func NewServerDailyStatOperator() *ServerDailyStatOperator {
|
||||||
|
|||||||
@@ -49,14 +49,14 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化
|
// Init 初始化
|
||||||
func (this *ServerDAO) Init() {
|
func (this *ServerDAO) Init() {
|
||||||
this.DAOObject.Init()
|
this.DAOObject.Init()
|
||||||
|
|
||||||
// 这里不处理增删改事件,是为了避免Server修改本身的时候,也要触发别的Server变更
|
// 这里不处理增删改事件,是为了避免Server修改本身的时候,也要触发别的Server变更
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启用条目
|
// EnableServer 启用条目
|
||||||
func (this *ServerDAO) EnableServer(tx *dbs.Tx, id uint32) (rowsAffected int64, err error) {
|
func (this *ServerDAO) EnableServer(tx *dbs.Tx, id uint32) (rowsAffected int64, err error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -64,7 +64,7 @@ func (this *ServerDAO) EnableServer(tx *dbs.Tx, id uint32) (rowsAffected int64,
|
|||||||
Update()
|
Update()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 禁用条目
|
// DisableServer 禁用条目
|
||||||
func (this *ServerDAO) DisableServer(tx *dbs.Tx, serverId int64) (err error) {
|
func (this *ServerDAO) DisableServer(tx *dbs.Tx, serverId int64) (err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
Pk(serverId).
|
Pk(serverId).
|
||||||
@@ -85,7 +85,7 @@ func (this *ServerDAO) DisableServer(tx *dbs.Tx, serverId int64) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找启用中的服务
|
// FindEnabledServer 查找启用中的服务
|
||||||
func (this *ServerDAO) FindEnabledServer(tx *dbs.Tx, serverId int64) (*Server, error) {
|
func (this *ServerDAO) FindEnabledServer(tx *dbs.Tx, serverId int64) (*Server, error) {
|
||||||
result, err := this.Query(tx).
|
result, err := this.Query(tx).
|
||||||
Pk(serverId).
|
Pk(serverId).
|
||||||
@@ -97,7 +97,7 @@ func (this *ServerDAO) FindEnabledServer(tx *dbs.Tx, serverId int64) (*Server, e
|
|||||||
return result.(*Server), err
|
return result.(*Server), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找服务名称
|
// FindEnabledServerName 查找服务名称
|
||||||
func (this *ServerDAO) FindEnabledServerName(tx *dbs.Tx, serverId int64) (string, error) {
|
func (this *ServerDAO) FindEnabledServerName(tx *dbs.Tx, serverId int64) (string, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(serverId).
|
Pk(serverId).
|
||||||
@@ -106,7 +106,7 @@ func (this *ServerDAO) FindEnabledServerName(tx *dbs.Tx, serverId int64) (string
|
|||||||
FindStringCol("")
|
FindStringCol("")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找服务基本信息
|
// FindEnabledServerBasic 查找服务基本信息
|
||||||
func (this *ServerDAO) FindEnabledServerBasic(tx *dbs.Tx, serverId int64) (*Server, error) {
|
func (this *ServerDAO) FindEnabledServerBasic(tx *dbs.Tx, serverId int64) (*Server, error) {
|
||||||
result, err := this.Query(tx).
|
result, err := this.Query(tx).
|
||||||
Pk(serverId).
|
Pk(serverId).
|
||||||
@@ -119,7 +119,7 @@ func (this *ServerDAO) FindEnabledServerBasic(tx *dbs.Tx, serverId int64) (*Serv
|
|||||||
return result.(*Server), err
|
return result.(*Server), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找服务类型
|
// FindEnabledServerType 查找服务类型
|
||||||
func (this *ServerDAO) FindEnabledServerType(tx *dbs.Tx, serverId int64) (string, error) {
|
func (this *ServerDAO) FindEnabledServerType(tx *dbs.Tx, serverId int64) (string, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(serverId).
|
Pk(serverId).
|
||||||
@@ -127,7 +127,7 @@ func (this *ServerDAO) FindEnabledServerType(tx *dbs.Tx, serverId int64) (string
|
|||||||
FindStringCol("")
|
FindStringCol("")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建服务
|
// CreateServer 创建服务
|
||||||
func (this *ServerDAO) CreateServer(tx *dbs.Tx,
|
func (this *ServerDAO) CreateServer(tx *dbs.Tx,
|
||||||
adminId int64,
|
adminId int64,
|
||||||
userId int64,
|
userId int64,
|
||||||
@@ -236,7 +236,7 @@ func (this *ServerDAO) CreateServer(tx *dbs.Tx,
|
|||||||
return serverId, nil
|
return serverId, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改服务基本信息
|
// UpdateServerBasic 修改服务基本信息
|
||||||
func (this *ServerDAO) UpdateServerBasic(tx *dbs.Tx, serverId int64, name string, description string, clusterId int64, isOn bool, groupIds []int64) error {
|
func (this *ServerDAO) UpdateServerBasic(tx *dbs.Tx, serverId int64, name string, description string, clusterId int64, isOn bool, groupIds []int64) error {
|
||||||
if serverId <= 0 {
|
if serverId <= 0 {
|
||||||
return errors.New("serverId should not be smaller than 0")
|
return errors.New("serverId should not be smaller than 0")
|
||||||
@@ -273,7 +273,7 @@ func (this *ServerDAO) UpdateServerBasic(tx *dbs.Tx, serverId int64, name string
|
|||||||
return this.NotifyDNSUpdate(tx, serverId)
|
return this.NotifyDNSUpdate(tx, serverId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置用户相关的基本信息
|
// UpdateUserServerBasic 设置用户相关的基本信息
|
||||||
func (this *ServerDAO) UpdateUserServerBasic(tx *dbs.Tx, serverId int64, name string) error {
|
func (this *ServerDAO) UpdateUserServerBasic(tx *dbs.Tx, serverId int64, name string) error {
|
||||||
if serverId <= 0 {
|
if serverId <= 0 {
|
||||||
return errors.New("serverId should not be smaller than 0")
|
return errors.New("serverId should not be smaller than 0")
|
||||||
@@ -290,7 +290,7 @@ func (this *ServerDAO) UpdateUserServerBasic(tx *dbs.Tx, serverId int64, name st
|
|||||||
return this.NotifyUpdate(tx, serverId)
|
return this.NotifyUpdate(tx, serverId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修复服务是否启用
|
// UpdateServerIsOn 修复服务是否启用
|
||||||
func (this *ServerDAO) UpdateServerIsOn(tx *dbs.Tx, serverId int64, isOn bool) error {
|
func (this *ServerDAO) UpdateServerIsOn(tx *dbs.Tx, serverId int64, isOn bool) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(serverId).
|
Pk(serverId).
|
||||||
@@ -308,7 +308,7 @@ func (this *ServerDAO) UpdateServerIsOn(tx *dbs.Tx, serverId int64, isOn bool) e
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改服务配置
|
// UpdateServerConfig 修改服务配置
|
||||||
func (this *ServerDAO) UpdateServerConfig(tx *dbs.Tx, serverId int64, configJSON []byte, updateMd5 bool) (isChanged bool, err error) {
|
func (this *ServerDAO) UpdateServerConfig(tx *dbs.Tx, serverId int64, configJSON []byte, updateMd5 bool) (isChanged bool, err error) {
|
||||||
if serverId <= 0 {
|
if serverId <= 0 {
|
||||||
return false, errors.New("serverId should not be smaller than 0")
|
return false, errors.New("serverId should not be smaller than 0")
|
||||||
@@ -351,7 +351,7 @@ func (this *ServerDAO) UpdateServerConfig(tx *dbs.Tx, serverId int64, configJSON
|
|||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改HTTP配置
|
// UpdateServerHTTP 修改HTTP配置
|
||||||
func (this *ServerDAO) UpdateServerHTTP(tx *dbs.Tx, serverId int64, config []byte) error {
|
func (this *ServerDAO) UpdateServerHTTP(tx *dbs.Tx, serverId int64, config []byte) error {
|
||||||
if serverId <= 0 {
|
if serverId <= 0 {
|
||||||
return errors.New("serverId should not be smaller than 0")
|
return errors.New("serverId should not be smaller than 0")
|
||||||
@@ -370,7 +370,7 @@ func (this *ServerDAO) UpdateServerHTTP(tx *dbs.Tx, serverId int64, config []byt
|
|||||||
return this.NotifyUpdate(tx, serverId)
|
return this.NotifyUpdate(tx, serverId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改HTTPS配置
|
// UpdateServerHTTPS 修改HTTPS配置
|
||||||
func (this *ServerDAO) UpdateServerHTTPS(tx *dbs.Tx, serverId int64, httpsJSON []byte) error {
|
func (this *ServerDAO) UpdateServerHTTPS(tx *dbs.Tx, serverId int64, httpsJSON []byte) error {
|
||||||
if serverId <= 0 {
|
if serverId <= 0 {
|
||||||
return errors.New("serverId should not be smaller than 0")
|
return errors.New("serverId should not be smaller than 0")
|
||||||
@@ -389,7 +389,7 @@ func (this *ServerDAO) UpdateServerHTTPS(tx *dbs.Tx, serverId int64, httpsJSON [
|
|||||||
return this.NotifyUpdate(tx, serverId)
|
return this.NotifyUpdate(tx, serverId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改TCP配置
|
// UpdateServerTCP 修改TCP配置
|
||||||
func (this *ServerDAO) UpdateServerTCP(tx *dbs.Tx, serverId int64, config []byte) error {
|
func (this *ServerDAO) UpdateServerTCP(tx *dbs.Tx, serverId int64, config []byte) error {
|
||||||
if serverId <= 0 {
|
if serverId <= 0 {
|
||||||
return errors.New("serverId should not be smaller than 0")
|
return errors.New("serverId should not be smaller than 0")
|
||||||
@@ -408,7 +408,7 @@ func (this *ServerDAO) UpdateServerTCP(tx *dbs.Tx, serverId int64, config []byte
|
|||||||
return this.NotifyUpdate(tx, serverId)
|
return this.NotifyUpdate(tx, serverId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改TLS配置
|
// UpdateServerTLS 修改TLS配置
|
||||||
func (this *ServerDAO) UpdateServerTLS(tx *dbs.Tx, serverId int64, config []byte) error {
|
func (this *ServerDAO) UpdateServerTLS(tx *dbs.Tx, serverId int64, config []byte) error {
|
||||||
if serverId <= 0 {
|
if serverId <= 0 {
|
||||||
return errors.New("serverId should not be smaller than 0")
|
return errors.New("serverId should not be smaller than 0")
|
||||||
@@ -427,7 +427,7 @@ func (this *ServerDAO) UpdateServerTLS(tx *dbs.Tx, serverId int64, config []byte
|
|||||||
return this.NotifyUpdate(tx, serverId)
|
return this.NotifyUpdate(tx, serverId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改Unix配置
|
// UpdateServerUnix 修改Unix配置
|
||||||
func (this *ServerDAO) UpdateServerUnix(tx *dbs.Tx, serverId int64, config []byte) error {
|
func (this *ServerDAO) UpdateServerUnix(tx *dbs.Tx, serverId int64, config []byte) error {
|
||||||
if serverId <= 0 {
|
if serverId <= 0 {
|
||||||
return errors.New("serverId should not be smaller than 0")
|
return errors.New("serverId should not be smaller than 0")
|
||||||
@@ -446,7 +446,7 @@ func (this *ServerDAO) UpdateServerUnix(tx *dbs.Tx, serverId int64, config []byt
|
|||||||
return this.NotifyUpdate(tx, serverId)
|
return this.NotifyUpdate(tx, serverId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改UDP配置
|
// UpdateServerUDP 修改UDP配置
|
||||||
func (this *ServerDAO) UpdateServerUDP(tx *dbs.Tx, serverId int64, config []byte) error {
|
func (this *ServerDAO) UpdateServerUDP(tx *dbs.Tx, serverId int64, config []byte) error {
|
||||||
if serverId <= 0 {
|
if serverId <= 0 {
|
||||||
return errors.New("serverId should not be smaller than 0")
|
return errors.New("serverId should not be smaller than 0")
|
||||||
@@ -465,7 +465,7 @@ func (this *ServerDAO) UpdateServerUDP(tx *dbs.Tx, serverId int64, config []byte
|
|||||||
return this.NotifyUpdate(tx, serverId)
|
return this.NotifyUpdate(tx, serverId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改Web配置
|
// UpdateServerWeb 修改Web配置
|
||||||
func (this *ServerDAO) UpdateServerWeb(tx *dbs.Tx, serverId int64, webId int64) error {
|
func (this *ServerDAO) UpdateServerWeb(tx *dbs.Tx, serverId int64, webId int64) error {
|
||||||
if serverId <= 0 {
|
if serverId <= 0 {
|
||||||
return errors.New("serverId should not be smaller than 0")
|
return errors.New("serverId should not be smaller than 0")
|
||||||
@@ -480,7 +480,7 @@ func (this *ServerDAO) UpdateServerWeb(tx *dbs.Tx, serverId int64, webId int64)
|
|||||||
return this.NotifyUpdate(tx, serverId)
|
return this.NotifyUpdate(tx, serverId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化Web配置
|
// InitServerWeb 初始化Web配置
|
||||||
func (this *ServerDAO) InitServerWeb(tx *dbs.Tx, serverId int64) (int64, error) {
|
func (this *ServerDAO) InitServerWeb(tx *dbs.Tx, serverId int64) (int64, error) {
|
||||||
if serverId <= 0 {
|
if serverId <= 0 {
|
||||||
return 0, errors.New("serverId should not be smaller than 0")
|
return 0, errors.New("serverId should not be smaller than 0")
|
||||||
@@ -512,7 +512,7 @@ func (this *ServerDAO) InitServerWeb(tx *dbs.Tx, serverId int64) (int64, error)
|
|||||||
return webId, nil
|
return webId, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找ServerNames配置
|
// FindServerServerNames 查找ServerNames配置
|
||||||
func (this *ServerDAO) FindServerServerNames(tx *dbs.Tx, serverId int64) (serverNamesJSON []byte, isAuditing bool, auditingServerNamesJSON []byte, auditingResultJSON []byte, err error) {
|
func (this *ServerDAO) FindServerServerNames(tx *dbs.Tx, serverId int64) (serverNamesJSON []byte, isAuditing bool, auditingServerNamesJSON []byte, auditingResultJSON []byte, err error) {
|
||||||
if serverId <= 0 {
|
if serverId <= 0 {
|
||||||
return
|
return
|
||||||
@@ -531,7 +531,7 @@ func (this *ServerDAO) FindServerServerNames(tx *dbs.Tx, serverId int64) (server
|
|||||||
return []byte(server.ServerNames), server.IsAuditing == 1, []byte(server.AuditingServerNames), []byte(server.AuditingResult), nil
|
return []byte(server.ServerNames), server.IsAuditing == 1, []byte(server.AuditingServerNames), []byte(server.AuditingResult), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改ServerNames配置
|
// UpdateServerNames 修改ServerNames配置
|
||||||
func (this *ServerDAO) UpdateServerNames(tx *dbs.Tx, serverId int64, serverNames []byte) error {
|
func (this *ServerDAO) UpdateServerNames(tx *dbs.Tx, serverId int64, serverNames []byte) error {
|
||||||
if serverId <= 0 {
|
if serverId <= 0 {
|
||||||
return errors.New("serverId should not be smaller than 0")
|
return errors.New("serverId should not be smaller than 0")
|
||||||
@@ -551,7 +551,7 @@ func (this *ServerDAO) UpdateServerNames(tx *dbs.Tx, serverId int64, serverNames
|
|||||||
return this.NotifyUpdate(tx, serverId)
|
return this.NotifyUpdate(tx, serverId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改域名审核
|
// UpdateAuditingServerNames 修改域名审核
|
||||||
func (this *ServerDAO) UpdateAuditingServerNames(tx *dbs.Tx, serverId int64, isAuditing bool, auditingServerNamesJSON []byte) error {
|
func (this *ServerDAO) UpdateAuditingServerNames(tx *dbs.Tx, serverId int64, isAuditing bool, auditingServerNamesJSON []byte) error {
|
||||||
if serverId <= 0 {
|
if serverId <= 0 {
|
||||||
return errors.New("serverId should not be smaller than 0")
|
return errors.New("serverId should not be smaller than 0")
|
||||||
@@ -573,7 +573,7 @@ func (this *ServerDAO) UpdateAuditingServerNames(tx *dbs.Tx, serverId int64, isA
|
|||||||
return this.NotifyUpdate(tx, serverId)
|
return this.NotifyUpdate(tx, serverId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改域名审核结果
|
// UpdateServerAuditing 修改域名审核结果
|
||||||
func (this *ServerDAO) UpdateServerAuditing(tx *dbs.Tx, serverId int64, result *pb.ServerNameAuditingResult) error {
|
func (this *ServerDAO) UpdateServerAuditing(tx *dbs.Tx, serverId int64, result *pb.ServerNameAuditingResult) error {
|
||||||
if serverId <= 0 {
|
if serverId <= 0 {
|
||||||
return errors.New("invalid serverId")
|
return errors.New("invalid serverId")
|
||||||
@@ -608,7 +608,7 @@ func (this *ServerDAO) UpdateServerAuditing(tx *dbs.Tx, serverId int64, result *
|
|||||||
return this.NotifyDNSUpdate(tx, serverId)
|
return this.NotifyDNSUpdate(tx, serverId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改反向代理配置
|
// UpdateServerReverseProxy 修改反向代理配置
|
||||||
func (this *ServerDAO) UpdateServerReverseProxy(tx *dbs.Tx, serverId int64, config []byte) error {
|
func (this *ServerDAO) UpdateServerReverseProxy(tx *dbs.Tx, serverId int64, config []byte) error {
|
||||||
if serverId <= 0 {
|
if serverId <= 0 {
|
||||||
return errors.New("serverId should not be smaller than 0")
|
return errors.New("serverId should not be smaller than 0")
|
||||||
@@ -624,14 +624,14 @@ func (this *ServerDAO) UpdateServerReverseProxy(tx *dbs.Tx, serverId int64, conf
|
|||||||
return this.NotifyUpdate(tx, serverId)
|
return this.NotifyUpdate(tx, serverId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算所有可用服务数量
|
// CountAllEnabledServers 计算所有可用服务数量
|
||||||
func (this *ServerDAO) CountAllEnabledServers(tx *dbs.Tx) (int64, error) {
|
func (this *ServerDAO) CountAllEnabledServers(tx *dbs.Tx) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
State(ServerStateEnabled).
|
State(ServerStateEnabled).
|
||||||
Count()
|
Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算所有可用服务数量
|
// CountAllEnabledServersMatch 计算所有可用服务数量
|
||||||
func (this *ServerDAO) CountAllEnabledServersMatch(tx *dbs.Tx, groupId int64, keyword string, userId int64, clusterId int64, auditingFlag configutils.BoolState, protocolFamily string) (int64, error) {
|
func (this *ServerDAO) CountAllEnabledServersMatch(tx *dbs.Tx, groupId int64, keyword string, userId int64, clusterId int64, auditingFlag configutils.BoolState, protocolFamily string) (int64, error) {
|
||||||
query := this.Query(tx).
|
query := this.Query(tx).
|
||||||
State(ServerStateEnabled)
|
State(ServerStateEnabled)
|
||||||
@@ -660,7 +660,7 @@ func (this *ServerDAO) CountAllEnabledServersMatch(tx *dbs.Tx, groupId int64, ke
|
|||||||
return query.Count()
|
return query.Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出单页的服务
|
// ListEnabledServersMatch 列出单页的服务
|
||||||
func (this *ServerDAO) ListEnabledServersMatch(tx *dbs.Tx, offset int64, size int64, groupId int64, keyword string, userId int64, clusterId int64, auditingFlag int32, protocolFamily string) (result []*Server, err error) {
|
func (this *ServerDAO) ListEnabledServersMatch(tx *dbs.Tx, offset int64, size int64, groupId int64, keyword string, userId int64, clusterId int64, auditingFlag int32, protocolFamily string) (result []*Server, err error) {
|
||||||
query := this.Query(tx).
|
query := this.Query(tx).
|
||||||
State(ServerStateEnabled).
|
State(ServerStateEnabled).
|
||||||
@@ -696,7 +696,7 @@ func (this *ServerDAO) ListEnabledServersMatch(tx *dbs.Tx, offset int64, size in
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取节点中的所有服务
|
// FindAllEnabledServersWithNode 获取节点中的所有服务
|
||||||
func (this *ServerDAO) FindAllEnabledServersWithNode(tx *dbs.Tx, nodeId int64) (result []*Server, err error) {
|
func (this *ServerDAO) FindAllEnabledServersWithNode(tx *dbs.Tx, nodeId int64) (result []*Server, err error) {
|
||||||
// 节点所在集群
|
// 节点所在集群
|
||||||
clusterId, err := SharedNodeDAO.FindNodeClusterId(tx, nodeId)
|
clusterId, err := SharedNodeDAO.FindNodeClusterId(tx, nodeId)
|
||||||
@@ -716,7 +716,7 @@ func (this *ServerDAO) FindAllEnabledServersWithNode(tx *dbs.Tx, nodeId int64) (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取所有的服务ID
|
// FindAllEnabledServerIds 获取所有的服务ID
|
||||||
func (this *ServerDAO) FindAllEnabledServerIds(tx *dbs.Tx) (serverIds []int64, err error) {
|
func (this *ServerDAO) FindAllEnabledServerIds(tx *dbs.Tx) (serverIds []int64, err error) {
|
||||||
ones, err := this.Query(tx).
|
ones, err := this.Query(tx).
|
||||||
State(ServerStateEnabled).
|
State(ServerStateEnabled).
|
||||||
@@ -729,7 +729,7 @@ func (this *ServerDAO) FindAllEnabledServerIds(tx *dbs.Tx) (serverIds []int64, e
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取某个用户的所有的服务ID
|
// FindAllEnabledServerIdsWithUserId 获取某个用户的所有的服务ID
|
||||||
func (this *ServerDAO) FindAllEnabledServerIdsWithUserId(tx *dbs.Tx, userId int64) (serverIds []int64, err error) {
|
func (this *ServerDAO) FindAllEnabledServerIdsWithUserId(tx *dbs.Tx, userId int64) (serverIds []int64, err error) {
|
||||||
ones, err := this.Query(tx).
|
ones, err := this.Query(tx).
|
||||||
State(ServerStateEnabled).
|
State(ServerStateEnabled).
|
||||||
@@ -743,7 +743,7 @@ func (this *ServerDAO) FindAllEnabledServerIdsWithUserId(tx *dbs.Tx, userId int6
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找服务的搜索条件
|
// FindServerNodeFilters 查找服务的搜索条件
|
||||||
func (this *ServerDAO) FindServerNodeFilters(tx *dbs.Tx, serverId int64) (isOk bool, clusterId int64, err error) {
|
func (this *ServerDAO) FindServerNodeFilters(tx *dbs.Tx, serverId int64) (isOk bool, clusterId int64, err error) {
|
||||||
one, err := this.Query(tx).
|
one, err := this.Query(tx).
|
||||||
Pk(serverId).
|
Pk(serverId).
|
||||||
@@ -760,7 +760,7 @@ func (this *ServerDAO) FindServerNodeFilters(tx *dbs.Tx, serverId int64) (isOk b
|
|||||||
return true, int64(server.ClusterId), nil
|
return true, int64(server.ClusterId), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构造服务的Config
|
// ComposeServerConfig 构造服务的Config
|
||||||
func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, serverId int64) (*serverconfigs.ServerConfig, error) {
|
func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, serverId int64) (*serverconfigs.ServerConfig, error) {
|
||||||
server, err := this.FindEnabledServer(tx, serverId)
|
server, err := this.FindEnabledServer(tx, serverId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -921,7 +921,7 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, serverId int64) (*serverc
|
|||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新服务的Config配置
|
// RenewServerConfig 更新服务的Config配置
|
||||||
func (this *ServerDAO) RenewServerConfig(tx *dbs.Tx, serverId int64, updateMd5 bool) (isChanged bool, err error) {
|
func (this *ServerDAO) RenewServerConfig(tx *dbs.Tx, serverId int64, updateMd5 bool) (isChanged bool, err error) {
|
||||||
serverConfig, err := this.ComposeServerConfig(tx, serverId)
|
serverConfig, err := this.ComposeServerConfig(tx, serverId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -934,7 +934,7 @@ func (this *ServerDAO) RenewServerConfig(tx *dbs.Tx, serverId int64, updateMd5 b
|
|||||||
return this.UpdateServerConfig(tx, serverId, data, updateMd5)
|
return this.UpdateServerConfig(tx, serverId, data, updateMd5)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据条件获取反向代理配置
|
// FindReverseProxyRef 根据条件获取反向代理配置
|
||||||
func (this *ServerDAO) FindReverseProxyRef(tx *dbs.Tx, serverId int64) (*serverconfigs.ReverseProxyRef, error) {
|
func (this *ServerDAO) FindReverseProxyRef(tx *dbs.Tx, serverId int64) (*serverconfigs.ReverseProxyRef, error) {
|
||||||
reverseProxy, err := this.Query(tx).
|
reverseProxy, err := this.Query(tx).
|
||||||
Pk(serverId).
|
Pk(serverId).
|
||||||
@@ -951,7 +951,7 @@ func (this *ServerDAO) FindReverseProxyRef(tx *dbs.Tx, serverId int64) (*serverc
|
|||||||
return config, err
|
return config, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找Server对应的WebId
|
// FindServerWebId 查找Server对应的WebId
|
||||||
func (this *ServerDAO) FindServerWebId(tx *dbs.Tx, serverId int64) (int64, error) {
|
func (this *ServerDAO) FindServerWebId(tx *dbs.Tx, serverId int64) (int64, error) {
|
||||||
webId, err := this.Query(tx).
|
webId, err := this.Query(tx).
|
||||||
Pk(serverId).
|
Pk(serverId).
|
||||||
@@ -963,7 +963,7 @@ func (this *ServerDAO) FindServerWebId(tx *dbs.Tx, serverId int64) (int64, error
|
|||||||
return int64(webId), nil
|
return int64(webId), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算使用SSL策略的所有服务数量
|
// CountAllEnabledServersWithSSLPolicyIds 计算使用SSL策略的所有服务数量
|
||||||
func (this *ServerDAO) CountAllEnabledServersWithSSLPolicyIds(tx *dbs.Tx, sslPolicyIds []int64) (count int64, err error) {
|
func (this *ServerDAO) CountAllEnabledServersWithSSLPolicyIds(tx *dbs.Tx, sslPolicyIds []int64) (count int64, err error) {
|
||||||
if len(sslPolicyIds) == 0 {
|
if len(sslPolicyIds) == 0 {
|
||||||
return
|
return
|
||||||
@@ -979,7 +979,7 @@ func (this *ServerDAO) CountAllEnabledServersWithSSLPolicyIds(tx *dbs.Tx, sslPol
|
|||||||
Count()
|
Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找使用某个SSL策略的所有服务
|
// FindAllEnabledServersWithSSLPolicyIds 查找使用某个SSL策略的所有服务
|
||||||
func (this *ServerDAO) FindAllEnabledServersWithSSLPolicyIds(tx *dbs.Tx, sslPolicyIds []int64) (result []*Server, err error) {
|
func (this *ServerDAO) FindAllEnabledServersWithSSLPolicyIds(tx *dbs.Tx, sslPolicyIds []int64) (result []*Server, err error) {
|
||||||
if len(sslPolicyIds) == 0 {
|
if len(sslPolicyIds) == 0 {
|
||||||
return
|
return
|
||||||
@@ -999,7 +999,7 @@ func (this *ServerDAO) FindAllEnabledServersWithSSLPolicyIds(tx *dbs.Tx, sslPoli
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找使用某个SSL策略的所有服务Id
|
// FindAllEnabledServerIdsWithSSLPolicyIds 查找使用某个SSL策略的所有服务Id
|
||||||
func (this *ServerDAO) FindAllEnabledServerIdsWithSSLPolicyIds(tx *dbs.Tx, sslPolicyIds []int64) (result []int64, err error) {
|
func (this *ServerDAO) FindAllEnabledServerIdsWithSSLPolicyIds(tx *dbs.Tx, sslPolicyIds []int64) (result []int64, err error) {
|
||||||
if len(sslPolicyIds) == 0 {
|
if len(sslPolicyIds) == 0 {
|
||||||
return
|
return
|
||||||
@@ -1025,7 +1025,7 @@ func (this *ServerDAO) FindAllEnabledServerIdsWithSSLPolicyIds(tx *dbs.Tx, sslPo
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算使用某个缓存策略的所有服务数量
|
// CountEnabledServersWithWebIds 计算使用某个缓存策略的所有服务数量
|
||||||
func (this *ServerDAO) CountEnabledServersWithWebIds(tx *dbs.Tx, webIds []int64) (count int64, err error) {
|
func (this *ServerDAO) CountEnabledServersWithWebIds(tx *dbs.Tx, webIds []int64) (count int64, err error) {
|
||||||
if len(webIds) == 0 {
|
if len(webIds) == 0 {
|
||||||
return
|
return
|
||||||
@@ -1037,7 +1037,7 @@ func (this *ServerDAO) CountEnabledServersWithWebIds(tx *dbs.Tx, webIds []int64)
|
|||||||
Count()
|
Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找使用某个缓存策略的所有服务
|
// FindAllEnabledServersWithWebIds 查找使用某个缓存策略的所有服务
|
||||||
func (this *ServerDAO) FindAllEnabledServersWithWebIds(tx *dbs.Tx, webIds []int64) (result []*Server, err error) {
|
func (this *ServerDAO) FindAllEnabledServersWithWebIds(tx *dbs.Tx, webIds []int64) (result []*Server, err error) {
|
||||||
if len(webIds) == 0 {
|
if len(webIds) == 0 {
|
||||||
return
|
return
|
||||||
@@ -1052,7 +1052,7 @@ func (this *ServerDAO) FindAllEnabledServersWithWebIds(tx *dbs.Tx, webIds []int6
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算使用某个集群的所有服务数量
|
// CountAllEnabledServersWithNodeClusterId 计算使用某个集群的所有服务数量
|
||||||
func (this *ServerDAO) CountAllEnabledServersWithNodeClusterId(tx *dbs.Tx, clusterId int64) (int64, error) {
|
func (this *ServerDAO) CountAllEnabledServersWithNodeClusterId(tx *dbs.Tx, clusterId int64) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
State(ServerStateEnabled).
|
State(ServerStateEnabled).
|
||||||
@@ -1060,7 +1060,7 @@ func (this *ServerDAO) CountAllEnabledServersWithNodeClusterId(tx *dbs.Tx, clust
|
|||||||
Count()
|
Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算使用某个分组的服务数量
|
// CountAllEnabledServersWithGroupId 计算使用某个分组的服务数量
|
||||||
func (this *ServerDAO) CountAllEnabledServersWithGroupId(tx *dbs.Tx, groupId int64) (int64, error) {
|
func (this *ServerDAO) CountAllEnabledServersWithGroupId(tx *dbs.Tx, groupId int64) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
State(ServerStateEnabled).
|
State(ServerStateEnabled).
|
||||||
@@ -1069,7 +1069,7 @@ func (this *ServerDAO) CountAllEnabledServersWithGroupId(tx *dbs.Tx, groupId int
|
|||||||
Count()
|
Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询使用某个DNS域名的所有服务域名
|
// FindAllServerDNSNamesWithDNSDomainId 查询使用某个DNS域名的所有服务域名
|
||||||
func (this *ServerDAO) FindAllServerDNSNamesWithDNSDomainId(tx *dbs.Tx, dnsDomainId int64) ([]string, error) {
|
func (this *ServerDAO) FindAllServerDNSNamesWithDNSDomainId(tx *dbs.Tx, dnsDomainId int64) ([]string, error) {
|
||||||
clusterIds, err := SharedNodeClusterDAO.FindAllEnabledClusterIdsWithDNSDomainId(tx, dnsDomainId)
|
clusterIds, err := SharedNodeClusterDAO.FindAllEnabledClusterIdsWithDNSDomainId(tx, dnsDomainId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1099,7 +1099,7 @@ func (this *ServerDAO) FindAllServerDNSNamesWithDNSDomainId(tx *dbs.Tx, dnsDomai
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取某个集群下的服务DNS信息
|
// FindAllServersDNSWithClusterId 获取某个集群下的服务DNS信息
|
||||||
func (this *ServerDAO) FindAllServersDNSWithClusterId(tx *dbs.Tx, clusterId int64) (result []*Server, err error) {
|
func (this *ServerDAO) FindAllServersDNSWithClusterId(tx *dbs.Tx, clusterId int64) (result []*Server, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(ServerStateEnabled).
|
State(ServerStateEnabled).
|
||||||
@@ -1113,7 +1113,7 @@ func (this *ServerDAO) FindAllServersDNSWithClusterId(tx *dbs.Tx, clusterId int6
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重新生成子域名
|
// GenerateServerDNSName 重新生成子域名
|
||||||
func (this *ServerDAO) GenerateServerDNSName(tx *dbs.Tx, serverId int64) (string, error) {
|
func (this *ServerDAO) GenerateServerDNSName(tx *dbs.Tx, serverId int64) (string, error) {
|
||||||
if serverId <= 0 {
|
if serverId <= 0 {
|
||||||
return "", errors.New("invalid serverId")
|
return "", errors.New("invalid serverId")
|
||||||
@@ -1143,7 +1143,7 @@ func (this *ServerDAO) GenerateServerDNSName(tx *dbs.Tx, serverId int64) (string
|
|||||||
return dnsName, nil
|
return dnsName, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询当前服务的集群ID
|
// FindServerClusterId 查询当前服务的集群ID
|
||||||
func (this *ServerDAO) FindServerClusterId(tx *dbs.Tx, serverId int64) (int64, error) {
|
func (this *ServerDAO) FindServerClusterId(tx *dbs.Tx, serverId int64) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(serverId).
|
Pk(serverId).
|
||||||
@@ -1151,7 +1151,7 @@ func (this *ServerDAO) FindServerClusterId(tx *dbs.Tx, serverId int64) (int64, e
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询服务的DNS名称
|
// FindServerDNSName 查询服务的DNS名称
|
||||||
func (this *ServerDAO) FindServerDNSName(tx *dbs.Tx, serverId int64) (string, error) {
|
func (this *ServerDAO) FindServerDNSName(tx *dbs.Tx, serverId int64) (string, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(serverId).
|
Pk(serverId).
|
||||||
@@ -1159,7 +1159,7 @@ func (this *ServerDAO) FindServerDNSName(tx *dbs.Tx, serverId int64) (string, er
|
|||||||
FindStringCol("")
|
FindStringCol("")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询服务的DNS相关信息,并且不关注状态
|
// FindStatelessServerDNS 查询服务的DNS相关信息,并且不关注状态
|
||||||
func (this *ServerDAO) FindStatelessServerDNS(tx *dbs.Tx, serverId int64) (*Server, error) {
|
func (this *ServerDAO) FindStatelessServerDNS(tx *dbs.Tx, serverId int64) (*Server, error) {
|
||||||
one, err := this.Query(tx).
|
one, err := this.Query(tx).
|
||||||
Pk(serverId).
|
Pk(serverId).
|
||||||
@@ -1171,7 +1171,7 @@ func (this *ServerDAO) FindStatelessServerDNS(tx *dbs.Tx, serverId int64) (*Serv
|
|||||||
return one.(*Server), nil
|
return one.(*Server), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取当前服务的管理员ID和用户ID
|
// FindServerAdminIdAndUserId 获取当前服务的管理员ID和用户ID
|
||||||
func (this *ServerDAO) FindServerAdminIdAndUserId(tx *dbs.Tx, serverId int64) (adminId int64, userId int64, err error) {
|
func (this *ServerDAO) FindServerAdminIdAndUserId(tx *dbs.Tx, serverId int64) (adminId int64, userId int64, err error) {
|
||||||
one, err := this.Query(tx).
|
one, err := this.Query(tx).
|
||||||
Pk(serverId).
|
Pk(serverId).
|
||||||
@@ -1186,7 +1186,7 @@ func (this *ServerDAO) FindServerAdminIdAndUserId(tx *dbs.Tx, serverId int64) (a
|
|||||||
return int64(one.(*Server).AdminId), int64(one.(*Server).UserId), nil
|
return int64(one.(*Server).AdminId), int64(one.(*Server).UserId), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查用户服务
|
// CheckUserServer 检查用户服务
|
||||||
func (this *ServerDAO) CheckUserServer(tx *dbs.Tx, userId int64, serverId int64) error {
|
func (this *ServerDAO) CheckUserServer(tx *dbs.Tx, userId int64, serverId int64) error {
|
||||||
if serverId <= 0 || userId <= 0 {
|
if serverId <= 0 || userId <= 0 {
|
||||||
return ErrNotFound
|
return ErrNotFound
|
||||||
@@ -1204,20 +1204,11 @@ func (this *ServerDAO) CheckUserServer(tx *dbs.Tx, userId int64, serverId int64)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置一个用户下的所有服务的所属集群
|
// UpdateUserServersClusterId 设置一个用户下的所有服务的所属集群
|
||||||
func (this *ServerDAO) UpdateUserServersClusterId(tx *dbs.Tx, userId int64, clusterId int64) error {
|
func (this *ServerDAO) UpdateUserServersClusterId(tx *dbs.Tx, userId int64, oldClusterId, newClusterId int64) error {
|
||||||
// 之前的cluster
|
_, err := this.Query(tx).
|
||||||
oldClusterId, err := SharedUserDAO.FindUserClusterId(tx, userId)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if oldClusterId == clusterId {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = this.Query(tx).
|
|
||||||
Attr("userId", userId).
|
Attr("userId", userId).
|
||||||
Set("clusterId", clusterId).
|
Set("clusterId", newClusterId).
|
||||||
Update()
|
Update()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -1232,14 +1223,22 @@ func (this *ServerDAO) UpdateUserServersClusterId(tx *dbs.Tx, userId int64, clus
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
err = dns.SharedDNSTaskDAO.CreateClusterTask(tx, oldClusterId, dns.DNSTaskTypeClusterChange)
|
||||||
|
|
||||||
if clusterId > 0 {
|
|
||||||
err = SharedNodeTaskDAO.CreateClusterTask(tx, clusterId, NodeTaskTypeConfigChanged)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = SharedNodeTaskDAO.CreateClusterTask(tx, clusterId, NodeTaskTypeIPItemChanged)
|
}
|
||||||
|
|
||||||
|
if newClusterId > 0 {
|
||||||
|
err = SharedNodeTaskDAO.CreateClusterTask(tx, newClusterId, NodeTaskTypeConfigChanged)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = SharedNodeTaskDAO.CreateClusterTask(tx, newClusterId, NodeTaskTypeIPItemChanged)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = dns.SharedDNSTaskDAO.CreateClusterTask(tx, newClusterId, dns.DNSTaskTypeClusterChange)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -1248,7 +1247,7 @@ func (this *ServerDAO) UpdateUserServersClusterId(tx *dbs.Tx, userId int64, clus
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找用户的所有的服务
|
// FindAllEnabledServersWithUserId 查找用户的所有的服务
|
||||||
func (this *ServerDAO) FindAllEnabledServersWithUserId(tx *dbs.Tx, userId int64) (result []*Server, err error) {
|
func (this *ServerDAO) FindAllEnabledServersWithUserId(tx *dbs.Tx, userId int64) (result []*Server, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(ServerStateEnabled).
|
State(ServerStateEnabled).
|
||||||
@@ -1259,7 +1258,7 @@ func (this *ServerDAO) FindAllEnabledServersWithUserId(tx *dbs.Tx, userId int64)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据WebId查找ServerId
|
// FindEnabledServerIdWithWebId 根据WebId查找ServerId
|
||||||
func (this *ServerDAO) FindEnabledServerIdWithWebId(tx *dbs.Tx, webId int64) (serverId int64, err error) {
|
func (this *ServerDAO) FindEnabledServerIdWithWebId(tx *dbs.Tx, webId int64) (serverId int64, err error) {
|
||||||
if webId <= 0 {
|
if webId <= 0 {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
@@ -1271,7 +1270,7 @@ func (this *ServerDAO) FindEnabledServerIdWithWebId(tx *dbs.Tx, webId int64) (se
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找包含某个反向代理的Server
|
// FindEnabledServerIdWithReverseProxyId 查找包含某个反向代理的Server
|
||||||
func (this *ServerDAO) FindEnabledServerIdWithReverseProxyId(tx *dbs.Tx, reverseProxyId int64) (serverId int64, err error) {
|
func (this *ServerDAO) FindEnabledServerIdWithReverseProxyId(tx *dbs.Tx, reverseProxyId int64) (serverId int64, err error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
State(ServerStateEnabled).
|
State(ServerStateEnabled).
|
||||||
@@ -1281,7 +1280,7 @@ func (this *ServerDAO) FindEnabledServerIdWithReverseProxyId(tx *dbs.Tx, reverse
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查端口是否被使用
|
// CheckPortIsUsing 检查端口是否被使用
|
||||||
func (this *ServerDAO) CheckPortIsUsing(tx *dbs.Tx, clusterId int64, port int, excludeServerId int64, excludeProtocol string) (bool, error) {
|
func (this *ServerDAO) CheckPortIsUsing(tx *dbs.Tx, clusterId int64, port int, excludeServerId int64, excludeProtocol string) (bool, error) {
|
||||||
listen := maps.Map{
|
listen := maps.Map{
|
||||||
"portRange": strconv.Itoa(port),
|
"portRange": strconv.Itoa(port),
|
||||||
@@ -1321,7 +1320,7 @@ func (this *ServerDAO) CheckPortIsUsing(tx *dbs.Tx, clusterId int64, port int, e
|
|||||||
Exist()
|
Exist()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查ServerName是否已存在
|
// ExistServerNameInCluster 检查ServerName是否已存在
|
||||||
func (this *ServerDAO) ExistServerNameInCluster(tx *dbs.Tx, clusterId int64, serverName string, excludeServerId int64) (bool, error) {
|
func (this *ServerDAO) ExistServerNameInCluster(tx *dbs.Tx, clusterId int64, serverName string, excludeServerId int64) (bool, error) {
|
||||||
query := this.Query(tx).
|
query := this.Query(tx).
|
||||||
Attr("clusterId", clusterId).
|
Attr("clusterId", clusterId).
|
||||||
@@ -1335,7 +1334,7 @@ func (this *ServerDAO) ExistServerNameInCluster(tx *dbs.Tx, clusterId int64, ser
|
|||||||
return query.Exist()
|
return query.Exist()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成DNS Name
|
// GenDNSName 生成DNS Name
|
||||||
func (this *ServerDAO) GenDNSName(tx *dbs.Tx) (string, error) {
|
func (this *ServerDAO) GenDNSName(tx *dbs.Tx) (string, error) {
|
||||||
for {
|
for {
|
||||||
dnsName := rands.HexString(8)
|
dnsName := rands.HexString(8)
|
||||||
@@ -1351,7 +1350,23 @@ func (this *ServerDAO) GenDNSName(tx *dbs.Tx) (string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 同步集群
|
// FindLatestServers 查询最近访问的服务
|
||||||
|
func (this *ServerDAO) FindLatestServers(tx *dbs.Tx, size int64) (result []*Server, err error) {
|
||||||
|
itemTable := SharedLatestItemDAO.Table
|
||||||
|
itemType := LatestItemTypeServer
|
||||||
|
_, err = this.Query(tx).
|
||||||
|
Result(this.Table+".id", this.Table+".name").
|
||||||
|
Join(SharedLatestItemDAO, dbs.QueryJoinRight, this.Table+".id="+itemTable+".itemId AND "+itemTable+".itemType='"+itemType+"'").
|
||||||
|
Asc("CEIL((UNIX_TIMESTAMP() - " + itemTable + ".updatedAt) / (7 * 86400))"). // 优先一个星期以内的
|
||||||
|
Desc(itemTable + ".count").
|
||||||
|
State(NodeClusterStateEnabled).
|
||||||
|
Limit(size).
|
||||||
|
Slice(&result).
|
||||||
|
FindAll()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotifyUpdate 同步集群
|
||||||
func (this *ServerDAO) NotifyUpdate(tx *dbs.Tx, serverId int64) error {
|
func (this *ServerDAO) NotifyUpdate(tx *dbs.Tx, serverId int64) error {
|
||||||
// 更新配置
|
// 更新配置
|
||||||
_, err := this.RenewServerConfig(tx, serverId, true)
|
_, err := this.RenewServerConfig(tx, serverId, true)
|
||||||
@@ -1370,7 +1385,7 @@ func (this *ServerDAO) NotifyUpdate(tx *dbs.Tx, serverId int64) error {
|
|||||||
return SharedNodeTaskDAO.CreateClusterTask(tx, clusterId, NodeTaskTypeConfigChanged)
|
return SharedNodeTaskDAO.CreateClusterTask(tx, clusterId, NodeTaskTypeConfigChanged)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通知DNS更新
|
// NotifyDNSUpdate 通知DNS更新
|
||||||
func (this *ServerDAO) NotifyDNSUpdate(tx *dbs.Tx, serverId int64) error {
|
func (this *ServerDAO) NotifyDNSUpdate(tx *dbs.Tx, serverId int64) error {
|
||||||
clusterId, err := this.Query(tx).
|
clusterId, err := this.Query(tx).
|
||||||
Pk(serverId).
|
Pk(serverId).
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
"github.com/iwind/TeaGo/rands"
|
"github.com/iwind/TeaGo/rands"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -34,7 +35,7 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启用条目
|
// EnableUserAccessKey 启用条目
|
||||||
func (this *UserAccessKeyDAO) EnableUserAccessKey(tx *dbs.Tx, id int64) error {
|
func (this *UserAccessKeyDAO) EnableUserAccessKey(tx *dbs.Tx, id int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -43,7 +44,7 @@ func (this *UserAccessKeyDAO) EnableUserAccessKey(tx *dbs.Tx, id int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 禁用条目
|
// DisableUserAccessKey 禁用条目
|
||||||
func (this *UserAccessKeyDAO) DisableUserAccessKey(tx *dbs.Tx, id int64) error {
|
func (this *UserAccessKeyDAO) DisableUserAccessKey(tx *dbs.Tx, id int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -52,7 +53,7 @@ func (this *UserAccessKeyDAO) DisableUserAccessKey(tx *dbs.Tx, id int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找启用中的条目
|
// FindEnabledUserAccessKey 查找启用中的条目
|
||||||
func (this *UserAccessKeyDAO) FindEnabledUserAccessKey(tx *dbs.Tx, id int64) (*UserAccessKey, error) {
|
func (this *UserAccessKeyDAO) FindEnabledUserAccessKey(tx *dbs.Tx, id int64) (*UserAccessKey, error) {
|
||||||
result, err := this.Query(tx).
|
result, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -64,12 +65,13 @@ func (this *UserAccessKeyDAO) FindEnabledUserAccessKey(tx *dbs.Tx, id int64) (*U
|
|||||||
return result.(*UserAccessKey), err
|
return result.(*UserAccessKey), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建Key
|
// CreateAccessKey 创建Key
|
||||||
func (this *UserAccessKeyDAO) CreateAccessKey(tx *dbs.Tx, userId int64, description string) (int64, error) {
|
func (this *UserAccessKeyDAO) CreateAccessKey(tx *dbs.Tx, adminId int64, userId int64, description string) (int64, error) {
|
||||||
if userId <= 0 {
|
if adminId <= 0 && userId <= 0 {
|
||||||
return 0, errors.New("invalid userId")
|
return 0, errors.New("invalid adminId or userId")
|
||||||
}
|
}
|
||||||
op := NewUserAccessKeyOperator()
|
op := NewUserAccessKeyOperator()
|
||||||
|
op.AdminId = adminId
|
||||||
op.UserId = userId
|
op.UserId = userId
|
||||||
op.Description = description
|
op.Description = description
|
||||||
op.UniqueId = rands.String(16)
|
op.UniqueId = rands.String(16)
|
||||||
@@ -79,9 +81,11 @@ func (this *UserAccessKeyDAO) CreateAccessKey(tx *dbs.Tx, userId int64, descript
|
|||||||
return this.SaveInt64(tx, op)
|
return this.SaveInt64(tx, op)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找用户所有的Key
|
// FindAllEnabledAccessKeys 查找用户所有的Key
|
||||||
func (this *UserAccessKeyDAO) FindAllEnabledAccessKeys(tx *dbs.Tx, userId int64) (result []*UserAccessKey, err error) {
|
func (this *UserAccessKeyDAO) FindAllEnabledAccessKeys(tx *dbs.Tx, adminId int64, userId int64) (result []*UserAccessKey, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
|
Attr("adminId", adminId).
|
||||||
|
Attr("userId", userId).
|
||||||
State(UserAccessKeyStateEnabled).
|
State(UserAccessKeyStateEnabled).
|
||||||
DescPk().
|
DescPk().
|
||||||
Slice(&result).
|
Slice(&result).
|
||||||
@@ -89,16 +93,17 @@ func (this *UserAccessKeyDAO) FindAllEnabledAccessKeys(tx *dbs.Tx, userId int64)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查用户的AccessKey
|
// CheckUserAccessKey 检查用户的AccessKey
|
||||||
func (this *UserAccessKeyDAO) CheckUserAccessKey(tx *dbs.Tx, userId int64, accessKeyId int64) (bool, error) {
|
func (this *UserAccessKeyDAO) CheckUserAccessKey(tx *dbs.Tx, adminId int64, userId int64, accessKeyId int64) (bool, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(accessKeyId).
|
Pk(accessKeyId).
|
||||||
State(UserAccessKeyStateEnabled).
|
State(UserAccessKeyStateEnabled).
|
||||||
|
Attr("adminId", adminId).
|
||||||
Attr("userId", userId).
|
Attr("userId", userId).
|
||||||
Exist()
|
Exist()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置是否启用
|
// UpdateAccessKeyIsOn 设置是否启用
|
||||||
func (this *UserAccessKeyDAO) UpdateAccessKeyIsOn(tx *dbs.Tx, accessKeyId int64, isOn bool) error {
|
func (this *UserAccessKeyDAO) UpdateAccessKeyIsOn(tx *dbs.Tx, accessKeyId int64, isOn bool) error {
|
||||||
if accessKeyId <= 0 {
|
if accessKeyId <= 0 {
|
||||||
return errors.New("invalid accessKeyId")
|
return errors.New("invalid accessKeyId")
|
||||||
@@ -110,7 +115,7 @@ func (this *UserAccessKeyDAO) UpdateAccessKeyIsOn(tx *dbs.Tx, accessKeyId int64,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据UniqueId查找AccessKey
|
// FindAccessKeyWithUniqueId 根据UniqueId查找AccessKey
|
||||||
func (this *UserAccessKeyDAO) FindAccessKeyWithUniqueId(tx *dbs.Tx, uniqueId string) (*UserAccessKey, error) {
|
func (this *UserAccessKeyDAO) FindAccessKeyWithUniqueId(tx *dbs.Tx, uniqueId string) (*UserAccessKey, error) {
|
||||||
one, err := this.Query(tx).
|
one, err := this.Query(tx).
|
||||||
Attr("uniqueId", uniqueId).
|
Attr("uniqueId", uniqueId).
|
||||||
@@ -123,3 +128,20 @@ func (this *UserAccessKeyDAO) FindAccessKeyWithUniqueId(tx *dbs.Tx, uniqueId str
|
|||||||
|
|
||||||
return one.(*UserAccessKey), nil
|
return one.(*UserAccessKey), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateAccessKeyAccessedAt 更新AccessKey访问时间
|
||||||
|
func (this *UserAccessKeyDAO) UpdateAccessKeyAccessedAt(tx *dbs.Tx, accessKeyId int64) error {
|
||||||
|
return this.Query(tx).
|
||||||
|
Pk(accessKeyId).
|
||||||
|
Set("accessedAt", time.Now().Unix()).
|
||||||
|
UpdateQuickly()
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountAllEnabledAccessKeys 计算可用AccessKey数量
|
||||||
|
func (this *UserAccessKeyDAO) CountAllEnabledAccessKeys(tx *dbs.Tx, adminId int64, userId int64) (int64, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
Attr("adminId", adminId).
|
||||||
|
Attr("userId", userId).
|
||||||
|
State(UserAccessKeyStateEnabled).
|
||||||
|
Count()
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,25 +1,29 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
// AccessKey
|
// UserAccessKey AccessKey
|
||||||
type UserAccessKey struct {
|
type UserAccessKey struct {
|
||||||
Id uint32 `field:"id"` // ID
|
Id uint32 `field:"id"` // ID
|
||||||
|
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||||
UserId uint32 `field:"userId"` // 用户ID
|
UserId uint32 `field:"userId"` // 用户ID
|
||||||
SubUserId uint32 `field:"subUserId"` // 子用户ID
|
SubUserId uint32 `field:"subUserId"` // 子用户ID
|
||||||
IsOn uint8 `field:"isOn"` // 是否启用
|
IsOn uint8 `field:"isOn"` // 是否启用
|
||||||
UniqueId string `field:"uniqueId"` // 唯一的Key
|
UniqueId string `field:"uniqueId"` // 唯一的Key
|
||||||
Secret string `field:"secret"` // 密钥
|
Secret string `field:"secret"` // 密钥
|
||||||
Description string `field:"description"` // 备注
|
Description string `field:"description"` // 备注
|
||||||
|
AccessedAt uint64 `field:"accessedAt"` // 最近一次访问时间
|
||||||
State uint8 `field:"state"` // 状态
|
State uint8 `field:"state"` // 状态
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserAccessKeyOperator struct {
|
type UserAccessKeyOperator struct {
|
||||||
Id interface{} // ID
|
Id interface{} // ID
|
||||||
|
AdminId interface{} // 管理员ID
|
||||||
UserId interface{} // 用户ID
|
UserId interface{} // 用户ID
|
||||||
SubUserId interface{} // 子用户ID
|
SubUserId interface{} // 子用户ID
|
||||||
IsOn interface{} // 是否启用
|
IsOn interface{} // 是否启用
|
||||||
UniqueId interface{} // 唯一的Key
|
UniqueId interface{} // 唯一的Key
|
||||||
Secret interface{} // 密钥
|
Secret interface{} // 密钥
|
||||||
Description interface{} // 备注
|
Description interface{} // 备注
|
||||||
|
AccessedAt interface{} // 最近一次访问时间
|
||||||
State interface{} // 状态
|
State interface{} // 状态
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启用条目
|
// EnableUser 启用条目
|
||||||
func (this *UserDAO) EnableUser(tx *dbs.Tx, id int64) (rowsAffected int64, err error) {
|
func (this *UserDAO) EnableUser(tx *dbs.Tx, id int64) (rowsAffected int64, err error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -44,7 +44,7 @@ func (this *UserDAO) EnableUser(tx *dbs.Tx, id int64) (rowsAffected int64, err e
|
|||||||
Update()
|
Update()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 禁用条目
|
// DisableUser 禁用条目
|
||||||
func (this *UserDAO) DisableUser(tx *dbs.Tx, id int64) (rowsAffected int64, err error) {
|
func (this *UserDAO) DisableUser(tx *dbs.Tx, id int64) (rowsAffected int64, err error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -52,7 +52,7 @@ func (this *UserDAO) DisableUser(tx *dbs.Tx, id int64) (rowsAffected int64, err
|
|||||||
Update()
|
Update()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找启用中的条目
|
// FindEnabledUser 查找启用中的条目
|
||||||
func (this *UserDAO) FindEnabledUser(tx *dbs.Tx, id int64) (*User, error) {
|
func (this *UserDAO) FindEnabledUser(tx *dbs.Tx, id int64) (*User, error) {
|
||||||
result, err := this.Query(tx).
|
result, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -64,7 +64,7 @@ func (this *UserDAO) FindEnabledUser(tx *dbs.Tx, id int64) (*User, error) {
|
|||||||
return result.(*User), err
|
return result.(*User), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找用户基本信息
|
// FindEnabledBasicUser 查找用户基本信息
|
||||||
func (this *UserDAO) FindEnabledBasicUser(tx *dbs.Tx, id int64) (*User, error) {
|
func (this *UserDAO) FindEnabledBasicUser(tx *dbs.Tx, id int64) (*User, error) {
|
||||||
result, err := this.Query(tx).
|
result, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -77,7 +77,7 @@ func (this *UserDAO) FindEnabledBasicUser(tx *dbs.Tx, id int64) (*User, error) {
|
|||||||
return result.(*User), err
|
return result.(*User), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取管理员名称
|
// FindUserFullname 获取管理员名称
|
||||||
func (this *UserDAO) FindUserFullname(tx *dbs.Tx, userId int64) (string, error) {
|
func (this *UserDAO) FindUserFullname(tx *dbs.Tx, userId int64) (string, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(userId).
|
Pk(userId).
|
||||||
@@ -85,7 +85,7 @@ func (this *UserDAO) FindUserFullname(tx *dbs.Tx, userId int64) (string, error)
|
|||||||
FindStringCol("")
|
FindStringCol("")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建用户
|
// CreateUser 创建用户
|
||||||
func (this *UserDAO) CreateUser(tx *dbs.Tx, username string, password string, fullname string, mobile string, tel string, email string, remark string, source string, clusterId int64) (int64, error) {
|
func (this *UserDAO) CreateUser(tx *dbs.Tx, username string, password string, fullname string, mobile string, tel string, email string, remark string, source string, clusterId int64) (int64, error) {
|
||||||
op := NewUserOperator()
|
op := NewUserOperator()
|
||||||
op.Username = username
|
op.Username = username
|
||||||
@@ -107,8 +107,8 @@ func (this *UserDAO) CreateUser(tx *dbs.Tx, username string, password string, fu
|
|||||||
return types.Int64(op.Id), nil
|
return types.Int64(op.Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改用户
|
// UpdateUser 修改用户
|
||||||
func (this *UserDAO) UpdateUser(tx *dbs.Tx, userId int64, username string, password string, fullname string, mobile string, tel string, email string, remark string, isOn bool, clusterId int64) error {
|
func (this *UserDAO) UpdateUser(tx *dbs.Tx, userId int64, username string, password string, fullname string, mobile string, tel string, email string, remark string, isOn bool, nodeClusterId int64) error {
|
||||||
if userId <= 0 {
|
if userId <= 0 {
|
||||||
return errors.New("invalid userId")
|
return errors.New("invalid userId")
|
||||||
}
|
}
|
||||||
@@ -123,13 +123,13 @@ func (this *UserDAO) UpdateUser(tx *dbs.Tx, userId int64, username string, passw
|
|||||||
op.Tel = tel
|
op.Tel = tel
|
||||||
op.Email = email
|
op.Email = email
|
||||||
op.Remark = remark
|
op.Remark = remark
|
||||||
|
op.ClusterId = nodeClusterId
|
||||||
op.IsOn = isOn
|
op.IsOn = isOn
|
||||||
op.ClusterId = clusterId
|
|
||||||
err := this.Save(tx, op)
|
err := this.Save(tx, op)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改用户基本信息
|
// UpdateUserInfo 修改用户基本信息
|
||||||
func (this *UserDAO) UpdateUserInfo(tx *dbs.Tx, userId int64, fullname string) error {
|
func (this *UserDAO) UpdateUserInfo(tx *dbs.Tx, userId int64, fullname string) error {
|
||||||
if userId <= 0 {
|
if userId <= 0 {
|
||||||
return errors.New("invalid userId")
|
return errors.New("invalid userId")
|
||||||
@@ -140,7 +140,7 @@ func (this *UserDAO) UpdateUserInfo(tx *dbs.Tx, userId int64, fullname string) e
|
|||||||
return this.Save(tx, op)
|
return this.Save(tx, op)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改用户登录信息
|
// UpdateUserLogin 修改用户登录信息
|
||||||
func (this *UserDAO) UpdateUserLogin(tx *dbs.Tx, userId int64, username string, password string) error {
|
func (this *UserDAO) UpdateUserLogin(tx *dbs.Tx, userId int64, username string, password string) error {
|
||||||
if userId <= 0 {
|
if userId <= 0 {
|
||||||
return errors.New("invalid userId")
|
return errors.New("invalid userId")
|
||||||
@@ -155,7 +155,7 @@ func (this *UserDAO) UpdateUserLogin(tx *dbs.Tx, userId int64, username string,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算用户数量
|
// CountAllEnabledUsers 计算用户数量
|
||||||
func (this *UserDAO) CountAllEnabledUsers(tx *dbs.Tx, keyword string) (int64, error) {
|
func (this *UserDAO) CountAllEnabledUsers(tx *dbs.Tx, keyword string) (int64, error) {
|
||||||
query := this.Query(tx)
|
query := this.Query(tx)
|
||||||
query.State(UserStateEnabled)
|
query.State(UserStateEnabled)
|
||||||
@@ -166,8 +166,8 @@ func (this *UserDAO) CountAllEnabledUsers(tx *dbs.Tx, keyword string) (int64, er
|
|||||||
return query.Count()
|
return query.Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出单页用户
|
// ListEnabledUsers 列出单页用户
|
||||||
func (this *UserDAO) ListEnabledUsers(tx *dbs.Tx, keyword string) (result []*User, err error) {
|
func (this *UserDAO) ListEnabledUsers(tx *dbs.Tx, keyword string, offset int64, size int64) (result []*User, err error) {
|
||||||
query := this.Query(tx)
|
query := this.Query(tx)
|
||||||
query.State(UserStateEnabled)
|
query.State(UserStateEnabled)
|
||||||
if len(keyword) > 0 {
|
if len(keyword) > 0 {
|
||||||
@@ -176,12 +176,14 @@ func (this *UserDAO) ListEnabledUsers(tx *dbs.Tx, keyword string) (result []*Use
|
|||||||
}
|
}
|
||||||
_, err = query.
|
_, err = query.
|
||||||
DescPk().
|
DescPk().
|
||||||
|
Offset(offset).
|
||||||
|
Limit(size).
|
||||||
Slice(&result).
|
Slice(&result).
|
||||||
FindAll()
|
FindAll()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查用户名是否存在
|
// ExistUser 检查用户名是否存在
|
||||||
func (this *UserDAO) ExistUser(tx *dbs.Tx, userId int64, username string) (bool, error) {
|
func (this *UserDAO) ExistUser(tx *dbs.Tx, userId int64, username string) (bool, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
State(UserStateEnabled).
|
State(UserStateEnabled).
|
||||||
@@ -190,7 +192,7 @@ func (this *UserDAO) ExistUser(tx *dbs.Tx, userId int64, username string) (bool,
|
|||||||
Exist()
|
Exist()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出单页的用户ID
|
// ListEnabledUserIds 列出单页的用户ID
|
||||||
func (this *UserDAO) ListEnabledUserIds(tx *dbs.Tx, offset, size int64) ([]int64, error) {
|
func (this *UserDAO) ListEnabledUserIds(tx *dbs.Tx, offset, size int64) ([]int64, error) {
|
||||||
ones, _, err := this.Query(tx).
|
ones, _, err := this.Query(tx).
|
||||||
ResultPk().
|
ResultPk().
|
||||||
@@ -209,7 +211,7 @@ func (this *UserDAO) ListEnabledUserIds(tx *dbs.Tx, offset, size int64) ([]int64
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查用户名、密码
|
// CheckUserPassword 检查用户名、密码
|
||||||
func (this *UserDAO) CheckUserPassword(tx *dbs.Tx, username string, encryptedPassword string) (int64, error) {
|
func (this *UserDAO) CheckUserPassword(tx *dbs.Tx, username string, encryptedPassword string) (int64, error) {
|
||||||
if len(username) == 0 || len(encryptedPassword) == 0 {
|
if len(username) == 0 || len(encryptedPassword) == 0 {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
@@ -223,7 +225,7 @@ func (this *UserDAO) CheckUserPassword(tx *dbs.Tx, username string, encryptedPas
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找用户所在集群
|
// FindUserClusterId 查找用户所在集群
|
||||||
func (this *UserDAO) FindUserClusterId(tx *dbs.Tx, userId int64) (int64, error) {
|
func (this *UserDAO) FindUserClusterId(tx *dbs.Tx, userId int64) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(userId).
|
Pk(userId).
|
||||||
@@ -231,7 +233,7 @@ func (this *UserDAO) FindUserClusterId(tx *dbs.Tx, userId int64) (int64, error)
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新用户Features
|
// UpdateUserFeatures 更新用户Features
|
||||||
func (this *UserDAO) UpdateUserFeatures(tx *dbs.Tx, userId int64, featuresJSON []byte) error {
|
func (this *UserDAO) UpdateUserFeatures(tx *dbs.Tx, userId int64, featuresJSON []byte) error {
|
||||||
if userId <= 0 {
|
if userId <= 0 {
|
||||||
return errors.New("invalid userId")
|
return errors.New("invalid userId")
|
||||||
@@ -249,7 +251,7 @@ func (this *UserDAO) UpdateUserFeatures(tx *dbs.Tx, userId int64, featuresJSON [
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找用户Features
|
// FindUserFeatures 查找用户Features
|
||||||
func (this *UserDAO) FindUserFeatures(tx *dbs.Tx, userId int64) ([]*UserFeature, error) {
|
func (this *UserDAO) FindUserFeatures(tx *dbs.Tx, userId int64) ([]*UserFeature, error) {
|
||||||
featuresJSON, err := this.Query(tx).
|
featuresJSON, err := this.Query(tx).
|
||||||
Pk(userId).
|
Pk(userId).
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package models
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
@@ -38,7 +40,7 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启用条目
|
// EnableUserNode 启用条目
|
||||||
func (this *UserNodeDAO) EnableUserNode(tx *dbs.Tx, id uint32) error {
|
func (this *UserNodeDAO) EnableUserNode(tx *dbs.Tx, id uint32) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -47,7 +49,7 @@ func (this *UserNodeDAO) EnableUserNode(tx *dbs.Tx, id uint32) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 禁用条目
|
// DisableUserNode 禁用条目
|
||||||
func (this *UserNodeDAO) DisableUserNode(tx *dbs.Tx, id int64) error {
|
func (this *UserNodeDAO) DisableUserNode(tx *dbs.Tx, id int64) error {
|
||||||
_, err := this.Query(tx).
|
_, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -56,7 +58,7 @@ func (this *UserNodeDAO) DisableUserNode(tx *dbs.Tx, id int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查找启用中的条目
|
// FindEnabledUserNode 查找启用中的条目
|
||||||
func (this *UserNodeDAO) FindEnabledUserNode(tx *dbs.Tx, id int64) (*UserNode, error) {
|
func (this *UserNodeDAO) FindEnabledUserNode(tx *dbs.Tx, id int64) (*UserNode, error) {
|
||||||
result, err := this.Query(tx).
|
result, err := this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -68,7 +70,7 @@ func (this *UserNodeDAO) FindEnabledUserNode(tx *dbs.Tx, id int64) (*UserNode, e
|
|||||||
return result.(*UserNode), err
|
return result.(*UserNode), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据主键查找名称
|
// FindUserNodeName 根据主键查找名称
|
||||||
func (this *UserNodeDAO) FindUserNodeName(tx *dbs.Tx, id int64) (string, error) {
|
func (this *UserNodeDAO) FindUserNodeName(tx *dbs.Tx, id int64) (string, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Pk(id).
|
Pk(id).
|
||||||
@@ -76,7 +78,7 @@ func (this *UserNodeDAO) FindUserNodeName(tx *dbs.Tx, id int64) (string, error)
|
|||||||
FindStringCol("")
|
FindStringCol("")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出所有可用用户节点
|
// FindAllEnabledUserNodes 列出所有可用用户节点
|
||||||
func (this *UserNodeDAO) FindAllEnabledUserNodes(tx *dbs.Tx) (result []*UserNode, err error) {
|
func (this *UserNodeDAO) FindAllEnabledUserNodes(tx *dbs.Tx) (result []*UserNode, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(UserNodeStateEnabled).
|
State(UserNodeStateEnabled).
|
||||||
@@ -87,14 +89,14 @@ func (this *UserNodeDAO) FindAllEnabledUserNodes(tx *dbs.Tx) (result []*UserNode
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算用户节点数量
|
// CountAllEnabledUserNodes 计算用户节点数量
|
||||||
func (this *UserNodeDAO) CountAllEnabledUserNodes(tx *dbs.Tx) (int64, error) {
|
func (this *UserNodeDAO) CountAllEnabledUserNodes(tx *dbs.Tx) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
State(UserNodeStateEnabled).
|
State(UserNodeStateEnabled).
|
||||||
Count()
|
Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出单页的用户节点
|
// ListEnabledUserNodes 列出单页的用户节点
|
||||||
func (this *UserNodeDAO) ListEnabledUserNodes(tx *dbs.Tx, offset int64, size int64) (result []*UserNode, err error) {
|
func (this *UserNodeDAO) ListEnabledUserNodes(tx *dbs.Tx, offset int64, size int64) (result []*UserNode, err error) {
|
||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(UserNodeStateEnabled).
|
State(UserNodeStateEnabled).
|
||||||
@@ -107,7 +109,7 @@ func (this *UserNodeDAO) ListEnabledUserNodes(tx *dbs.Tx, offset int64, size int
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据主机名和端口获取ID
|
// FindEnabledUserNodeIdWithAddr 根据主机名和端口获取ID
|
||||||
func (this *UserNodeDAO) FindEnabledUserNodeIdWithAddr(tx *dbs.Tx, protocol string, host string, port int) (int64, error) {
|
func (this *UserNodeDAO) FindEnabledUserNodeIdWithAddr(tx *dbs.Tx, protocol string, host string, port int) (int64, error) {
|
||||||
addr := maps.Map{
|
addr := maps.Map{
|
||||||
"protocol": protocol,
|
"protocol": protocol,
|
||||||
@@ -134,14 +136,14 @@ func (this *UserNodeDAO) FindEnabledUserNodeIdWithAddr(tx *dbs.Tx, protocol stri
|
|||||||
return int64(one.(*UserNode).Id), nil
|
return int64(one.(*UserNode).Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建用户节点
|
// CreateUserNode 创建用户节点
|
||||||
func (this *UserNodeDAO) CreateUserNode(tx *dbs.Tx, name string, description string, httpJSON []byte, httpsJSON []byte, accessAddrsJSON []byte, isOn bool) (nodeId int64, err error) {
|
func (this *UserNodeDAO) CreateUserNode(tx *dbs.Tx, name string, description string, httpJSON []byte, httpsJSON []byte, accessAddrsJSON []byte, isOn bool) (nodeId int64, err error) {
|
||||||
uniqueId, err := this.GenUniqueId(tx)
|
uniqueId, err := this.GenUniqueId(tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
secret := rands.String(32)
|
secret := rands.String(32)
|
||||||
err = NewApiTokenDAO().CreateAPIToken(tx, uniqueId, secret, NodeRoleUser)
|
err = NewApiTokenDAO().CreateAPIToken(tx, uniqueId, secret, nodeconfigs.NodeRoleUser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -172,7 +174,7 @@ func (this *UserNodeDAO) CreateUserNode(tx *dbs.Tx, name string, description str
|
|||||||
return types.Int64(op.Id), nil
|
return types.Int64(op.Id), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改用户节点
|
// UpdateUserNode 修改用户节点
|
||||||
func (this *UserNodeDAO) UpdateUserNode(tx *dbs.Tx, nodeId int64, name string, description string, httpJSON []byte, httpsJSON []byte, accessAddrsJSON []byte, isOn bool) error {
|
func (this *UserNodeDAO) UpdateUserNode(tx *dbs.Tx, nodeId int64, name string, description string, httpJSON []byte, httpsJSON []byte, accessAddrsJSON []byte, isOn bool) error {
|
||||||
if nodeId <= 0 {
|
if nodeId <= 0 {
|
||||||
return errors.New("invalid nodeId")
|
return errors.New("invalid nodeId")
|
||||||
@@ -204,7 +206,7 @@ func (this *UserNodeDAO) UpdateUserNode(tx *dbs.Tx, nodeId int64, name string, d
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据唯一ID获取节点信息
|
// FindEnabledUserNodeWithUniqueId 根据唯一ID获取节点信息
|
||||||
func (this *UserNodeDAO) FindEnabledUserNodeWithUniqueId(tx *dbs.Tx, uniqueId string) (*UserNode, error) {
|
func (this *UserNodeDAO) FindEnabledUserNodeWithUniqueId(tx *dbs.Tx, uniqueId string) (*UserNode, error) {
|
||||||
result, err := this.Query(tx).
|
result, err := this.Query(tx).
|
||||||
Attr("uniqueId", uniqueId).
|
Attr("uniqueId", uniqueId).
|
||||||
@@ -216,7 +218,7 @@ func (this *UserNodeDAO) FindEnabledUserNodeWithUniqueId(tx *dbs.Tx, uniqueId st
|
|||||||
return result.(*UserNode), err
|
return result.(*UserNode), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据唯一ID获取节点ID
|
// FindEnabledUserNodeIdWithUniqueId 根据唯一ID获取节点ID
|
||||||
func (this *UserNodeDAO) FindEnabledUserNodeIdWithUniqueId(tx *dbs.Tx, uniqueId string) (int64, error) {
|
func (this *UserNodeDAO) FindEnabledUserNodeIdWithUniqueId(tx *dbs.Tx, uniqueId string) (int64, error) {
|
||||||
return this.Query(tx).
|
return this.Query(tx).
|
||||||
Attr("uniqueId", uniqueId).
|
Attr("uniqueId", uniqueId).
|
||||||
@@ -225,7 +227,7 @@ func (this *UserNodeDAO) FindEnabledUserNodeIdWithUniqueId(tx *dbs.Tx, uniqueId
|
|||||||
FindInt64Col(0)
|
FindInt64Col(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成唯一ID
|
// GenUniqueId 生成唯一ID
|
||||||
func (this *UserNodeDAO) GenUniqueId(tx *dbs.Tx) (string, error) {
|
func (this *UserNodeDAO) GenUniqueId(tx *dbs.Tx) (string, error) {
|
||||||
for {
|
for {
|
||||||
uniqueId := rands.HexString(32)
|
uniqueId := rands.HexString(32)
|
||||||
@@ -242,7 +244,7 @@ func (this *UserNodeDAO) GenUniqueId(tx *dbs.Tx) (string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更改节点状态
|
// UpdateNodeStatus 更改节点状态
|
||||||
func (this *UserNodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, statusJSON []byte) error {
|
func (this *UserNodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, statusJSON []byte) error {
|
||||||
if len(statusJSON) == 0 {
|
if len(statusJSON) == 0 {
|
||||||
return nil
|
return nil
|
||||||
@@ -253,3 +255,13 @@ func (this *UserNodeDAO) UpdateNodeStatus(tx *dbs.Tx, nodeId int64, statusJSON [
|
|||||||
Update()
|
Update()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CountAllLowerVersionNodes 计算所有节点中低于某个版本的节点数量
|
||||||
|
func (this *UserNodeDAO) CountAllLowerVersionNodes(tx *dbs.Tx, version string) (int64, error) {
|
||||||
|
return this.Query(tx).
|
||||||
|
State(UserNodeStateEnabled).
|
||||||
|
Where("status IS NOT NULL").
|
||||||
|
Where("(JSON_EXTRACT(status, '$.buildVersionCode') IS NULL OR JSON_EXTRACT(status, '$.buildVersionCode')<:version)").
|
||||||
|
Param("version", utils.VersionToLong(version)).
|
||||||
|
Count()
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
package dnsclients
|
package dnstypes
|
||||||
|
|
||||||
type RecordType = string
|
type RecordType = string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
RecordTypeA RecordType = "A"
|
RecordTypeA RecordType = "A"
|
||||||
RecordTypeCName RecordType = "CNAME"
|
RecordTypeAAAA RecordType = "AAAA"
|
||||||
|
RecordTypeCNAME RecordType = "CNAME"
|
||||||
RecordTypeTXT RecordType = "TXT"
|
RecordTypeTXT RecordType = "TXT"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package dnsclients
|
package dnstypes
|
||||||
|
|
||||||
// Route 线路描述
|
// Route 线路描述
|
||||||
type Route struct {
|
type Route struct {
|
||||||
@@ -2,6 +2,7 @@ package dnsclients
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients/dnstypes"
|
||||||
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
|
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
|
||||||
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses"
|
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses"
|
||||||
"github.com/aliyun/alibaba-cloud-sdk-go/services/alidns"
|
"github.com/aliyun/alibaba-cloud-sdk-go/services/alidns"
|
||||||
@@ -31,7 +32,7 @@ func (this *AliDNSProvider) Auth(params maps.Map) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetRecords 获取域名列表
|
// GetRecords 获取域名列表
|
||||||
func (this *AliDNSProvider) GetRecords(domain string) (records []*Record, err error) {
|
func (this *AliDNSProvider) GetRecords(domain string) (records []*dnstypes.Record, err error) {
|
||||||
pageNumber := 1
|
pageNumber := 1
|
||||||
size := 100
|
size := 100
|
||||||
|
|
||||||
@@ -48,11 +49,11 @@ func (this *AliDNSProvider) GetRecords(domain string) (records []*Record, err er
|
|||||||
}
|
}
|
||||||
for _, record := range resp.DomainRecords.Record {
|
for _, record := range resp.DomainRecords.Record {
|
||||||
// 修正Record
|
// 修正Record
|
||||||
if record.Type == RecordTypeCName && !strings.HasSuffix(record.Value, ".") {
|
if record.Type == dnstypes.RecordTypeCNAME && !strings.HasSuffix(record.Value, ".") {
|
||||||
record.Value += "."
|
record.Value += "."
|
||||||
}
|
}
|
||||||
|
|
||||||
records = append(records, &Record{
|
records = append(records, &dnstypes.Record{
|
||||||
Id: record.RecordId,
|
Id: record.RecordId,
|
||||||
Name: record.RR,
|
Name: record.RR,
|
||||||
Type: record.Type,
|
Type: record.Type,
|
||||||
@@ -71,7 +72,7 @@ func (this *AliDNSProvider) GetRecords(domain string) (records []*Record, err er
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetRoutes 读取域名支持的线路数据
|
// GetRoutes 读取域名支持的线路数据
|
||||||
func (this *AliDNSProvider) GetRoutes(domain string) (routes []*Route, err error) {
|
func (this *AliDNSProvider) GetRoutes(domain string) (routes []*dnstypes.Route, err error) {
|
||||||
req := alidns.CreateDescribeSupportLinesRequest()
|
req := alidns.CreateDescribeSupportLinesRequest()
|
||||||
req.DomainName = domain
|
req.DomainName = domain
|
||||||
|
|
||||||
@@ -81,7 +82,7 @@ func (this *AliDNSProvider) GetRoutes(domain string) (routes []*Route, err error
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, line := range resp.RecordLines.RecordLine {
|
for _, line := range resp.RecordLines.RecordLine {
|
||||||
routes = append(routes, &Route{
|
routes = append(routes, &dnstypes.Route{
|
||||||
Name: line.LineName,
|
Name: line.LineName,
|
||||||
Code: line.LineCode,
|
Code: line.LineCode,
|
||||||
})
|
})
|
||||||
@@ -90,7 +91,7 @@ func (this *AliDNSProvider) GetRoutes(domain string) (routes []*Route, err error
|
|||||||
}
|
}
|
||||||
|
|
||||||
// QueryRecord 查询单个记录
|
// QueryRecord 查询单个记录
|
||||||
func (this *AliDNSProvider) QueryRecord(domain string, name string, recordType RecordType) (*Record, error) {
|
func (this *AliDNSProvider) QueryRecord(domain string, name string, recordType dnstypes.RecordType) (*dnstypes.Record, error) {
|
||||||
records, err := this.GetRecords(domain)
|
records, err := this.GetRecords(domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -104,7 +105,7 @@ func (this *AliDNSProvider) QueryRecord(domain string, name string, recordType R
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddRecord 设置记录
|
// AddRecord 设置记录
|
||||||
func (this *AliDNSProvider) AddRecord(domain string, newRecord *Record) error {
|
func (this *AliDNSProvider) AddRecord(domain string, newRecord *dnstypes.Record) error {
|
||||||
req := alidns.CreateAddDomainRecordRequest()
|
req := alidns.CreateAddDomainRecordRequest()
|
||||||
req.RR = newRecord.Name
|
req.RR = newRecord.Name
|
||||||
req.Type = newRecord.Type
|
req.Type = newRecord.Type
|
||||||
@@ -125,7 +126,7 @@ func (this *AliDNSProvider) AddRecord(domain string, newRecord *Record) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateRecord 修改记录
|
// UpdateRecord 修改记录
|
||||||
func (this *AliDNSProvider) UpdateRecord(domain string, record *Record, newRecord *Record) error {
|
func (this *AliDNSProvider) UpdateRecord(domain string, record *dnstypes.Record, newRecord *dnstypes.Record) error {
|
||||||
req := alidns.CreateUpdateDomainRecordRequest()
|
req := alidns.CreateUpdateDomainRecordRequest()
|
||||||
req.RecordId = record.Id
|
req.RecordId = record.Id
|
||||||
req.RR = newRecord.Name
|
req.RR = newRecord.Name
|
||||||
@@ -139,7 +140,7 @@ func (this *AliDNSProvider) UpdateRecord(domain string, record *Record, newRecor
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteRecord 删除记录
|
// DeleteRecord 删除记录
|
||||||
func (this *AliDNSProvider) DeleteRecord(domain string, record *Record) error {
|
func (this *AliDNSProvider) DeleteRecord(domain string, record *dnstypes.Record) error {
|
||||||
req := alidns.CreateDeleteDomainRecordRequest()
|
req := alidns.CreateDeleteDomainRecordRequest()
|
||||||
req.RecordId = record.Id
|
req.RecordId = record.Id
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package dnsclients
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients/dnstypes"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
_ "github.com/iwind/TeaGo/bootstrap"
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
@@ -29,7 +30,7 @@ func TestAliDNSProvider_DeleteRecord(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = provider.DeleteRecord("meloy.cn", &Record{
|
err = provider.DeleteRecord("meloy.cn", &dnstypes.Record{
|
||||||
Id: "20746603318032384",
|
Id: "20746603318032384",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -57,10 +58,10 @@ func TestAliDNSProvider_AddRecord(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = provider.AddRecord("meloy.cn", &Record{
|
err = provider.AddRecord("meloy.cn", &dnstypes.Record{
|
||||||
Id: "",
|
Id: "",
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Type: RecordTypeA,
|
Type: dnstypes.RecordTypeA,
|
||||||
Value: "192.168.1.100",
|
Value: "192.168.1.100",
|
||||||
Route: "unicom",
|
Route: "unicom",
|
||||||
})
|
})
|
||||||
@@ -76,10 +77,10 @@ func TestAliDNSProvider_UpdateRecord(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = provider.UpdateRecord("meloy.cn", &Record{Id: "20746664455255040"}, &Record{
|
err = provider.UpdateRecord("meloy.cn", &dnstypes.Record{Id: "20746664455255040"}, &dnstypes.Record{
|
||||||
Id: "",
|
Id: "",
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Type: RecordTypeA,
|
Type: dnstypes.RecordTypeA,
|
||||||
Value: "192.168.1.101",
|
Value: "192.168.1.101",
|
||||||
Route: "unicom",
|
Route: "unicom",
|
||||||
})
|
})
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user