mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 02:11:09 +00:00
update vendor dependencies for glusterfs removal code
Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
This commit is contained in:
parent
c2a7bfd6b4
commit
d2f11fe7f9
21
LICENSES/vendor/github.com/go-ozzo/ozzo-validation/LICENSE
generated
vendored
21
LICENSES/vendor/github.com/go-ozzo/ozzo-validation/LICENSE
generated
vendored
@ -1,21 +0,0 @@
|
||||
= vendor/github.com/go-ozzo/ozzo-validation licensed under: =
|
||||
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2016, Qiang Xue
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
= vendor/github.com/go-ozzo/ozzo-validation/LICENSE da12d993f2ce14947ad6eec35520b081
|
11
LICENSES/vendor/github.com/heketi/heketi/LICENSE
generated
vendored
11
LICENSES/vendor/github.com/heketi/heketi/LICENSE
generated
vendored
@ -1,11 +0,0 @@
|
||||
= vendor/github.com/heketi/heketi licensed under: =
|
||||
|
||||
Heketi code is released under various licenses:
|
||||
|
||||
The REST API client code (in go and python) is released
|
||||
under a dual license of Apache 2.0 or LGPLv3+.
|
||||
|
||||
The other parts of heketi (server, cli, tests, ...) are released
|
||||
under a dual license of LGPLv3+ or GPLv2.
|
||||
|
||||
= vendor/github.com/heketi/heketi/LICENSE a58e72c3bda574189508cb90d56fa19f
|
20
go.mod
20
go.mod
@ -45,7 +45,6 @@ require (
|
||||
github.com/google/go-cmp v0.5.8
|
||||
github.com/google/gofuzz v1.1.0
|
||||
github.com/google/uuid v1.1.2
|
||||
github.com/heketi/heketi v10.3.0+incompatible
|
||||
github.com/ishidawataru/sctp v0.0.0-20190723014705-7c296d48a2b5
|
||||
github.com/libopenstorage/openstorage v1.0.0
|
||||
github.com/lithammer/dedent v1.1.0
|
||||
@ -145,9 +144,7 @@ require (
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
|
||||
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220418222510-f25a4f6275ed // indirect
|
||||
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
|
||||
github.com/auth0/go-jwt-middleware v1.0.1 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/boltdb/bolt v1.3.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
github.com/chai2010/gettext-go v1.0.2 // indirect
|
||||
github.com/checkpoint-restore/go-criu/v5 v5.3.0 // indirect
|
||||
@ -171,7 +168,6 @@ require (
|
||||
github.com/go-openapi/jsonpointer v0.19.5 // indirect
|
||||
github.com/go-openapi/jsonreference v0.19.5 // indirect
|
||||
github.com/go-openapi/swag v0.19.14 // indirect
|
||||
github.com/go-ozzo/ozzo-validation v3.5.0+incompatible // indirect
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
|
||||
github.com/gofrs/uuid v4.0.0+incompatible // indirect
|
||||
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
|
||||
@ -180,13 +176,11 @@ require (
|
||||
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
|
||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
|
||||
github.com/googleapis/gax-go/v2 v2.1.1 // indirect
|
||||
github.com/gorilla/mux v1.8.0 // indirect
|
||||
github.com/gorilla/websocket v1.4.2 // indirect
|
||||
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
|
||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
|
||||
github.com/heketi/tests v0.0.0-20151005000721-f3775cbcefd6 // indirect
|
||||
github.com/imdario/mergo v0.3.6 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
||||
@ -195,7 +189,6 @@ require (
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/karrick/godirwalk v1.16.1 // indirect
|
||||
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
|
||||
github.com/lpabon/godbc v0.1.1 // indirect
|
||||
github.com/mailru/easyjson v0.7.6 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
|
||||
github.com/mindprince/gonvml v0.0.0-20190828220739-9ebdce4bb989 // indirect
|
||||
@ -225,7 +218,6 @@ require (
|
||||
github.com/stretchr/objx v0.2.0 // indirect
|
||||
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
|
||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 // indirect
|
||||
github.com/urfave/negroni v1.0.0 // indirect
|
||||
github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae // indirect
|
||||
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
|
||||
github.com/xlab/treeprint v1.1.0 // indirect
|
||||
@ -292,13 +284,11 @@ replace (
|
||||
github.com/armon/circbuf => github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e
|
||||
github.com/armon/go-socks5 => github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
|
||||
github.com/asaskevich/govalidator => github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a
|
||||
github.com/auth0/go-jwt-middleware => github.com/auth0/go-jwt-middleware v1.0.1
|
||||
github.com/aws/aws-sdk-go => github.com/aws/aws-sdk-go v1.38.49
|
||||
github.com/benbjohnson/clock => github.com/benbjohnson/clock v1.1.0
|
||||
github.com/beorn7/perks => github.com/beorn7/perks v1.0.1
|
||||
github.com/blang/semver => github.com/blang/semver v3.5.1+incompatible
|
||||
github.com/blang/semver/v4 => github.com/blang/semver/v4 v4.0.0
|
||||
github.com/boltdb/bolt => github.com/boltdb/bolt v1.3.1
|
||||
github.com/census-instrumentation/opencensus-proto => github.com/census-instrumentation/opencensus-proto v0.2.1
|
||||
github.com/certifi/gocertifi => github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054
|
||||
github.com/cespare/xxhash/v2 => github.com/cespare/xxhash/v2 v2.1.2
|
||||
@ -367,7 +357,6 @@ replace (
|
||||
github.com/go-openapi/jsonpointer => github.com/go-openapi/jsonpointer v0.19.5
|
||||
github.com/go-openapi/jsonreference => github.com/go-openapi/jsonreference v0.19.5
|
||||
github.com/go-openapi/swag => github.com/go-openapi/swag v0.19.14
|
||||
github.com/go-ozzo/ozzo-validation => github.com/go-ozzo/ozzo-validation v3.5.0+incompatible
|
||||
github.com/go-stack/stack => github.com/go-stack/stack v1.8.0
|
||||
github.com/go-task/slim-sprig => github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0
|
||||
github.com/godbus/dbus/v5 => github.com/godbus/dbus/v5 v5.0.6
|
||||
@ -396,15 +385,11 @@ replace (
|
||||
github.com/google/shlex => github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
|
||||
github.com/google/uuid => github.com/google/uuid v1.1.2
|
||||
github.com/googleapis/gax-go/v2 => github.com/googleapis/gax-go/v2 v2.1.1
|
||||
github.com/gopherjs/gopherjs => github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00
|
||||
github.com/gorilla/mux => github.com/gorilla/mux v1.8.0
|
||||
github.com/gorilla/websocket => github.com/gorilla/websocket v1.4.2
|
||||
github.com/gregjones/httpcache => github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7
|
||||
github.com/grpc-ecosystem/go-grpc-middleware => github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
|
||||
github.com/grpc-ecosystem/go-grpc-prometheus => github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
|
||||
github.com/grpc-ecosystem/grpc-gateway => github.com/grpc-ecosystem/grpc-gateway v1.16.0
|
||||
github.com/heketi/heketi => github.com/heketi/heketi v10.3.0+incompatible
|
||||
github.com/heketi/tests => github.com/heketi/tests v0.0.0-20151005000721-f3775cbcefd6
|
||||
github.com/ianlancetaylor/demangle => github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639
|
||||
github.com/imdario/mergo => github.com/imdario/mergo v0.3.6
|
||||
github.com/inconshreveable/mousetrap => github.com/inconshreveable/mousetrap v1.0.0
|
||||
@ -415,7 +400,6 @@ replace (
|
||||
github.com/josharian/intern => github.com/josharian/intern v1.0.0
|
||||
github.com/jpillora/backoff => github.com/jpillora/backoff v1.0.0
|
||||
github.com/json-iterator/go => github.com/json-iterator/go v1.1.12
|
||||
github.com/jtolds/gls => github.com/jtolds/gls v4.20.0+incompatible
|
||||
github.com/julienschmidt/httprouter => github.com/julienschmidt/httprouter v1.3.0
|
||||
github.com/jung-kurt/gofpdf => github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5
|
||||
github.com/karrick/godirwalk => github.com/karrick/godirwalk v1.16.1
|
||||
@ -428,7 +412,6 @@ replace (
|
||||
github.com/libopenstorage/openstorage => github.com/libopenstorage/openstorage v1.0.0
|
||||
github.com/liggitt/tabwriter => github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de
|
||||
github.com/lithammer/dedent => github.com/lithammer/dedent v1.1.0
|
||||
github.com/lpabon/godbc => github.com/lpabon/godbc v0.1.1
|
||||
github.com/mailru/easyjson => github.com/mailru/easyjson v0.7.6
|
||||
github.com/mattn/go-runewidth => github.com/mattn/go-runewidth v0.0.7
|
||||
github.com/matttproud/golang_protobuf_extensions => github.com/matttproud/golang_protobuf_extensions v1.0.1
|
||||
@ -479,8 +462,6 @@ replace (
|
||||
github.com/seccomp/libseccomp-golang => github.com/seccomp/libseccomp-golang v0.9.2-0.20220502022130-f33da4d89646
|
||||
github.com/sergi/go-diff => github.com/sergi/go-diff v1.1.0
|
||||
github.com/sirupsen/logrus => github.com/sirupsen/logrus v1.8.1
|
||||
github.com/smartystreets/assertions => github.com/smartystreets/assertions v1.1.0
|
||||
github.com/smartystreets/goconvey => github.com/smartystreets/goconvey v1.6.4
|
||||
github.com/soheilhy/cmux => github.com/soheilhy/cmux v0.1.5
|
||||
github.com/spf13/afero => github.com/spf13/afero v1.6.0
|
||||
github.com/spf13/cobra => github.com/spf13/cobra v1.4.0
|
||||
@ -491,7 +472,6 @@ replace (
|
||||
github.com/syndtr/gocapability => github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635
|
||||
github.com/tmc/grpc-websocket-proxy => github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802
|
||||
github.com/urfave/cli => github.com/urfave/cli v1.22.2
|
||||
github.com/urfave/negroni => github.com/urfave/negroni v1.0.0
|
||||
github.com/vishvananda/netlink => github.com/vishvananda/netlink v1.1.0
|
||||
github.com/vishvananda/netns => github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae
|
||||
github.com/vmware/govmomi => github.com/vmware/govmomi v0.20.3
|
||||
|
20
go.sum
20
go.sum
@ -57,8 +57,6 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
|
||||
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA=
|
||||
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
|
||||
github.com/auth0/go-jwt-middleware v1.0.1 h1:/fsQ4vRr4zod1wKReUH+0A3ySRjGiT9G34kypO/EKwI=
|
||||
github.com/auth0/go-jwt-middleware v1.0.1/go.mod h1:YSeUX3z6+TF2H+7padiEqNJ73Zy9vXW72U//IgN0BIM=
|
||||
github.com/aws/aws-sdk-go v1.38.49 h1:E31vxjCe6a5I+mJLmUGaZobiWmg9KdWaud9IfceYeYQ=
|
||||
github.com/aws/aws-sdk-go v1.38.49/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
|
||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||
@ -69,8 +67,6 @@ github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdn
|
||||
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
|
||||
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
|
||||
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
|
||||
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
|
||||
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054 h1:uH66TXeswKn5PW5zdZ39xEwfS9an067BirqA+P4QaLI=
|
||||
github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA=
|
||||
@ -184,8 +180,6 @@ github.com/go-openapi/jsonreference v0.19.5 h1:1WJP/wi4OjB4iV8KVbH73rQaoialJrqv8
|
||||
github.com/go-openapi/jsonreference v0.19.5/go.mod h1:RdybgQwPxbL4UEjuAruzK1x3nE69AqPYEJeo/TWfEeg=
|
||||
github.com/go-openapi/swag v0.19.14 h1:gm3vOOXfiuw5i9p5N9xJvfjvuofpyvLA9Wr6QfK5Fng=
|
||||
github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
|
||||
github.com/go-ozzo/ozzo-validation v3.5.0+incompatible h1:sUy/in/P6askYr16XJgTKq/0SZhiWsdg4WZGaLsGQkM=
|
||||
github.com/go-ozzo/ozzo-validation v3.5.0+incompatible/go.mod h1:gsEKFIVnabGBt6mXmxK0MoFy+cZoTJY6mu5Ll3LVLBU=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I=
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
||||
@ -233,9 +227,6 @@ github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/googleapis/gax-go/v2 v2.1.1 h1:dp3bWCh+PPO1zjRRiCSczJav13sBvG4UhNyVTa1KqdU=
|
||||
github.com/googleapis/gax-go/v2 v2.1.1/go.mod h1:hddJymUZASv3XPyGkUpKj8pPO47Rmb0eJc8R6ouapiM=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
||||
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 h1:pdN6V1QBWetyv/0+wjACpqVH+eVULgEjkurDLq3goeM=
|
||||
@ -246,10 +237,6 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92Bcuy
|
||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
|
||||
github.com/heketi/heketi v10.3.0+incompatible h1:X4DBFPzcyWZWhia32d94UhDECQJHH0M5kpRb1gxxUHk=
|
||||
github.com/heketi/heketi v10.3.0+incompatible/go.mod h1:bB9ly3RchcQqsQ9CpyaQwvva7RS5ytVoSoholZQON6o=
|
||||
github.com/heketi/tests v0.0.0-20151005000721-f3775cbcefd6 h1:oJ/NLadJn5HoxvonA6VxG31lg0d6XOURNA09BTtM4fY=
|
||||
github.com/heketi/tests v0.0.0-20151005000721-f3775cbcefd6/go.mod h1:xGMAM8JLi7UkZt1i4FQeQy0R2T8GLUwQhOP5M1gBhy4=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28=
|
||||
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
||||
@ -268,7 +255,6 @@ github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFF
|
||||
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
|
||||
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
|
||||
github.com/karrick/godirwalk v1.16.1 h1:DynhcF+bztK8gooS0+NDJFrdNZjJ3gzVzC545UNA9iw=
|
||||
@ -287,8 +273,6 @@ github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhn
|
||||
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE=
|
||||
github.com/lithammer/dedent v1.1.0 h1:VNzHMVCBNG1j0fh3OrsFRkVUwStdDArbgBWoPAffktY=
|
||||
github.com/lithammer/dedent v1.1.0/go.mod h1:jrXYCQtgg0nJiN+StA2KgR7w6CiQNv9Fd/Z9BP0jIOc=
|
||||
github.com/lpabon/godbc v0.1.1 h1:ilqjArN1UOENJJdM34I2YHKmF/B0gGq4VLoSGy9iAao=
|
||||
github.com/lpabon/godbc v0.1.1/go.mod h1:Jo9QV0cf3U6jZABgiJ2skINAXb9j8m51r07g4KI92ZA=
|
||||
github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA=
|
||||
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||
@ -377,8 +361,6 @@ github.com/seccomp/libseccomp-golang v0.9.2-0.20220502022130-f33da4d89646/go.mod
|
||||
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
||||
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/smartystreets/assertions v1.1.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
|
||||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/soheilhy/cmux v0.1.5 h1:jjzc5WVemNEDTLwv9tlmemhC73tI08BNOIGwBOo10Js=
|
||||
github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0=
|
||||
github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY=
|
||||
@ -398,8 +380,6 @@ github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG
|
||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 h1:uruHq4dN7GR16kFc5fp3d1RIYzJW5onx8Ybykw2YQFA=
|
||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||
github.com/urfave/negroni v1.0.0 h1:kIimOitoypq34K7TG7DUaJ9kq/N4Ofuwi1sjz0KipXc=
|
||||
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
|
||||
github.com/vishvananda/netlink v1.1.0 h1:1iyaYNBLmP6L0220aDnYQpo1QEV4t4hJ+xEEhhJH8j0=
|
||||
github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
|
||||
github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae h1:4hwBBUfQCFe3Cym0ZtKyq7L16eZUtYKs+BaHDN6mAns=
|
||||
|
25
vendor/github.com/go-ozzo/ozzo-validation/.gitignore
generated
vendored
25
vendor/github.com/go-ozzo/ozzo-validation/.gitignore
generated
vendored
@ -1,25 +0,0 @@
|
||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
*.prof
|
||||
.DS_Store
|
16
vendor/github.com/go-ozzo/ozzo-validation/.travis.yml
generated
vendored
16
vendor/github.com/go-ozzo/ozzo-validation/.travis.yml
generated
vendored
@ -1,16 +0,0 @@
|
||||
language: go
|
||||
|
||||
go:
|
||||
- 1.8
|
||||
- 1.9
|
||||
- tip
|
||||
|
||||
install:
|
||||
- go get golang.org/x/tools/cmd/cover
|
||||
- go get github.com/mattn/goveralls
|
||||
- go list -f '{{range .Imports}}{{.}} {{end}}' ./... | xargs go get -v
|
||||
- go list -f '{{range .TestImports}}{{.}} {{end}}' ./... | xargs go get -v
|
||||
|
||||
script:
|
||||
- go test -v -covermode=count -coverprofile=coverage.out
|
||||
- $HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci
|
17
vendor/github.com/go-ozzo/ozzo-validation/LICENSE
generated
vendored
17
vendor/github.com/go-ozzo/ozzo-validation/LICENSE
generated
vendored
@ -1,17 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2016, Qiang Xue
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
534
vendor/github.com/go-ozzo/ozzo-validation/README.md
generated
vendored
534
vendor/github.com/go-ozzo/ozzo-validation/README.md
generated
vendored
@ -1,534 +0,0 @@
|
||||
# ozzo-validation
|
||||
|
||||
[](http://godoc.org/github.com/go-ozzo/ozzo-validation)
|
||||
[](https://travis-ci.org/go-ozzo/ozzo-validation)
|
||||
[](https://coveralls.io/github/go-ozzo/ozzo-validation?branch=master)
|
||||
[](https://goreportcard.com/report/github.com/go-ozzo/ozzo-validation)
|
||||
|
||||
## Description
|
||||
|
||||
ozzo-validation is a Go package that provides configurable and extensible data validation capabilities.
|
||||
It has the following features:
|
||||
|
||||
* use normal programming constructs rather than error-prone struct tags to specify how data should be validated.
|
||||
* can validate data of different types, e.g., structs, strings, byte slices, slices, maps, arrays.
|
||||
* can validate custom data types as long as they implement the `Validatable` interface.
|
||||
* can validate data types that implement the `sql.Valuer` interface (e.g. `sql.NullString`).
|
||||
* customizable and well-formatted validation errors.
|
||||
* provide a rich set of validation rules right out of box.
|
||||
* extremely easy to create and use custom validation rules.
|
||||
|
||||
|
||||
## Requirements
|
||||
|
||||
Go 1.8 or above.
|
||||
|
||||
|
||||
## Getting Started
|
||||
|
||||
The ozzo-validation package mainly includes a set of validation rules and two validation methods. You use
|
||||
validation rules to describe how a value should be considered valid, and you call either `validation.Validate()`
|
||||
or `validation.ValidateStruct()` to validate the value.
|
||||
|
||||
|
||||
### Installation
|
||||
|
||||
Run the following command to install the package:
|
||||
|
||||
```
|
||||
go get github.com/go-ozzo/ozzo-validation
|
||||
go get github.com/go-ozzo/ozzo-validation/is
|
||||
```
|
||||
|
||||
### Validating a Simple Value
|
||||
|
||||
For a simple value, such as a string or an integer, you may use `validation.Validate()` to validate it. For example,
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-ozzo/ozzo-validation"
|
||||
"github.com/go-ozzo/ozzo-validation/is"
|
||||
)
|
||||
|
||||
func main() {
|
||||
data := "example"
|
||||
err := validation.Validate(data,
|
||||
validation.Required, // not empty
|
||||
validation.Length(5, 100), // length between 5 and 100
|
||||
is.URL, // is a valid URL
|
||||
)
|
||||
fmt.Println(err)
|
||||
// Output:
|
||||
// must be a valid URL
|
||||
}
|
||||
```
|
||||
|
||||
The method `validation.Validate()` will run through the rules in the order that they are listed. If a rule fails
|
||||
the validation, the method will return the corresponding error and skip the rest of the rules. The method will
|
||||
return nil if the value passes all validation rules.
|
||||
|
||||
|
||||
### Validating a Struct
|
||||
|
||||
For a struct value, you usually want to check if its fields are valid. For example, in a RESTful application, you
|
||||
may unmarshal the request payload into a struct and then validate the struct fields. If one or multiple fields
|
||||
are invalid, you may want to get an error describing which fields are invalid. You can use `validation.ValidateStruct()`
|
||||
to achieve this purpose. A single struct can have rules for multiple fields, and a field can be associated with multiple
|
||||
rules. For example,
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"github.com/go-ozzo/ozzo-validation"
|
||||
"github.com/go-ozzo/ozzo-validation/is"
|
||||
)
|
||||
|
||||
type Address struct {
|
||||
Street string
|
||||
City string
|
||||
State string
|
||||
Zip string
|
||||
}
|
||||
|
||||
func (a Address) Validate() error {
|
||||
return validation.ValidateStruct(&a,
|
||||
// Street cannot be empty, and the length must between 5 and 50
|
||||
validation.Field(&a.Street, validation.Required, validation.Length(5, 50)),
|
||||
// City cannot be empty, and the length must between 5 and 50
|
||||
validation.Field(&a.City, validation.Required, validation.Length(5, 50)),
|
||||
// State cannot be empty, and must be a string consisting of two letters in upper case
|
||||
validation.Field(&a.State, validation.Required, validation.Match(regexp.MustCompile("^[A-Z]{2}$"))),
|
||||
// State cannot be empty, and must be a string consisting of five digits
|
||||
validation.Field(&a.Zip, validation.Required, validation.Match(regexp.MustCompile("^[0-9]{5}$"))),
|
||||
)
|
||||
}
|
||||
|
||||
func main() {
|
||||
a := Address{
|
||||
Street: "123",
|
||||
City: "Unknown",
|
||||
State: "Virginia",
|
||||
Zip: "12345",
|
||||
}
|
||||
|
||||
err := a.Validate()
|
||||
fmt.Println(err)
|
||||
// Output:
|
||||
// Street: the length must be between 5 and 50; State: must be in a valid format.
|
||||
}
|
||||
```
|
||||
|
||||
Note that when calling `validation.ValidateStruct` to validate a struct, you should pass to the method a pointer
|
||||
to the struct instead of the struct itself. Similarly, when calling `validation.Field` to specify the rules
|
||||
for a struct field, you should use a pointer to the struct field.
|
||||
|
||||
When the struct validation is performed, the fields are validated in the order they are specified in `ValidateStruct`.
|
||||
And when each field is validated, its rules are also evaluated in the order they are associated with the field.
|
||||
If a rule fails, an error is recorded for that field, and the validation will continue with the next field.
|
||||
|
||||
|
||||
### Validation Errors
|
||||
|
||||
The `validation.ValidateStruct` method returns validation errors found in struct fields in terms of `validation.Errors`
|
||||
which is a map of fields and their corresponding errors. Nil is returned if validation passes.
|
||||
|
||||
By default, `validation.Errors` uses the struct tags named `json` to determine what names should be used to
|
||||
represent the invalid fields. The type also implements the `json.Marshaler` interface so that it can be marshaled
|
||||
into a proper JSON object. For example,
|
||||
|
||||
```go
|
||||
type Address struct {
|
||||
Street string `json:"street"`
|
||||
City string `json:"city"`
|
||||
State string `json:"state"`
|
||||
Zip string `json:"zip"`
|
||||
}
|
||||
|
||||
// ...perform validation here...
|
||||
|
||||
err := a.Validate()
|
||||
b, _ := json.Marshal(err)
|
||||
fmt.Println(string(b))
|
||||
// Output:
|
||||
// {"street":"the length must be between 5 and 50","state":"must be in a valid format"}
|
||||
```
|
||||
|
||||
You may modify `validation.ErrorTag` to use a different struct tag name.
|
||||
|
||||
If you do not like the magic that `ValidateStruct` determines error keys based on struct field names or corresponding
|
||||
tag values, you may use the following alternative approach:
|
||||
|
||||
```go
|
||||
c := Customer{
|
||||
Name: "Qiang Xue",
|
||||
Email: "q",
|
||||
Address: Address{
|
||||
State: "Virginia",
|
||||
},
|
||||
}
|
||||
|
||||
err := validation.Errors{
|
||||
"name": validation.Validate(c.Name, validation.Required, validation.Length(5, 20)),
|
||||
"email": validation.Validate(c.Name, validation.Required, is.Email),
|
||||
"zip": validation.Validate(c.Address.Zip, validation.Required, validation.Match(regexp.MustCompile("^[0-9]{5}$"))),
|
||||
}.Filter()
|
||||
fmt.Println(err)
|
||||
// Output:
|
||||
// email: must be a valid email address; zip: cannot be blank.
|
||||
```
|
||||
|
||||
In the above example, we build a `validation.Errors` by a list of names and the corresponding validation results.
|
||||
At the end we call `Errors.Filter()` to remove from `Errors` all nils which correspond to those successful validation
|
||||
results. The method will return nil if `Errors` is empty.
|
||||
|
||||
The above approach is very flexible as it allows you to freely build up your validation error structure. You can use
|
||||
it to validate both struct and non-struct values. Compared to using `ValidateStruct` to validate a struct,
|
||||
it has the drawback that you have to redundantly specify the error keys while `ValidateStruct` can automatically
|
||||
find them out.
|
||||
|
||||
|
||||
### Internal Errors
|
||||
|
||||
Internal errors are different from validation errors in that internal errors are caused by malfunctioning code (e.g.
|
||||
a validator making a remote call to validate some data when the remote service is down) rather
|
||||
than the data being validated. When an internal error happens during data validation, you may allow the user to resubmit
|
||||
the same data to perform validation again, hoping the program resumes functioning. On the other hand, if data validation
|
||||
fails due to data error, the user should generally not resubmit the same data again.
|
||||
|
||||
To differentiate internal errors from validation errors, when an internal error occurs in a validator, wrap it
|
||||
into `validation.InternalError` by calling `validation.NewInternalError()`. The user of the validator can then check
|
||||
if a returned error is an internal error or not. For example,
|
||||
|
||||
```go
|
||||
if err := a.Validate(); err != nil {
|
||||
if e, ok := err.(validation.InternalError); ok {
|
||||
// an internal error happened
|
||||
fmt.Println(e.InternalError())
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## Validatable Types
|
||||
|
||||
A type is validatable if it implements the `validation.Validatable` interface.
|
||||
|
||||
When `validation.Validate` is used to validate a validatable value, if it does not find any error with the
|
||||
given validation rules, it will further call the value's `Validate()` method.
|
||||
|
||||
Similarly, when `validation.ValidateStruct` is validating a struct field whose type is validatable, it will call
|
||||
the field's `Validate` method after it passes the listed rules.
|
||||
|
||||
In the following example, the `Address` field of `Customer` is validatable because `Address` implements
|
||||
`validation.Validatable`. Therefore, when validating a `Customer` struct with `validation.ValidateStruct`,
|
||||
validation will "dive" into the `Address` field.
|
||||
|
||||
```go
|
||||
type Customer struct {
|
||||
Name string
|
||||
Gender string
|
||||
Email string
|
||||
Address Address
|
||||
}
|
||||
|
||||
func (c Customer) Validate() error {
|
||||
return validation.ValidateStruct(&c,
|
||||
// Name cannot be empty, and the length must be between 5 and 20.
|
||||
validation.Field(&c.Name, validation.Required, validation.Length(5, 20)),
|
||||
// Gender is optional, and should be either "Female" or "Male".
|
||||
validation.Field(&c.Gender, validation.In("Female", "Male")),
|
||||
// Email cannot be empty and should be in a valid email format.
|
||||
validation.Field(&c.Email, validation.Required, is.Email),
|
||||
// Validate Address using its own validation rules
|
||||
validation.Field(&c.Address),
|
||||
)
|
||||
}
|
||||
|
||||
c := Customer{
|
||||
Name: "Qiang Xue",
|
||||
Email: "q",
|
||||
Address: Address{
|
||||
Street: "123 Main Street",
|
||||
City: "Unknown",
|
||||
State: "Virginia",
|
||||
Zip: "12345",
|
||||
},
|
||||
}
|
||||
|
||||
err := c.Validate()
|
||||
fmt.Println(err)
|
||||
// Output:
|
||||
// Address: (State: must be in a valid format.); Email: must be a valid email address.
|
||||
```
|
||||
|
||||
Sometimes, you may want to skip the invocation of a type's `Validate` method. To do so, simply associate
|
||||
a `validation.Skip` rule with the value being validated.
|
||||
|
||||
|
||||
### Maps/Slices/Arrays of Validatables
|
||||
|
||||
When validating a map, slice, or array, whose element type implements the `validation.Validatable` interface,
|
||||
the `validation.Validate` method will call the `Validate` method of every non-nil element.
|
||||
The validation errors of the elements will be returned as `validation.Errors` which maps the keys of the
|
||||
invalid elements to their corresponding validation errors. For example,
|
||||
|
||||
```go
|
||||
addresses := []Address{
|
||||
Address{State: "MD", Zip: "12345"},
|
||||
Address{Street: "123 Main St", City: "Vienna", State: "VA", Zip: "12345"},
|
||||
Address{City: "Unknown", State: "NC", Zip: "123"},
|
||||
}
|
||||
err := validation.Validate(addresses)
|
||||
fmt.Println(err)
|
||||
// Output:
|
||||
// 0: (City: cannot be blank; Street: cannot be blank.); 2: (Street: cannot be blank; Zip: must be in a valid format.).
|
||||
```
|
||||
|
||||
When using `validation.ValidateStruct` to validate a struct, the above validation procedure also applies to those struct
|
||||
fields which are map/slices/arrays of validatables.
|
||||
|
||||
|
||||
### Pointers
|
||||
|
||||
When a value being validated is a pointer, most validation rules will validate the actual value pointed to by the pointer.
|
||||
If the pointer is nil, these rules will skip the validation.
|
||||
|
||||
An exception is the `validation.Required` and `validation.NotNil` rules. When a pointer is nil, they
|
||||
will report a validation error.
|
||||
|
||||
|
||||
### Types Implementing `sql.Valuer`
|
||||
|
||||
If a data type implements the `sql.Valuer` interface (e.g. `sql.NullString`), the built-in validation rules will handle
|
||||
it properly. In particular, when a rule is validating such data, it will call the `Value()` method and validate
|
||||
the returned value instead.
|
||||
|
||||
|
||||
### Required vs. Not Nil
|
||||
|
||||
When validating input values, there are two different scenarios about checking if input values are provided or not.
|
||||
|
||||
In the first scenario, an input value is considered missing if it is not entered or it is entered as a zero value
|
||||
(e.g. an empty string, a zero integer). You can use the `validation.Required` rule in this case.
|
||||
|
||||
In the second scenario, an input value is considered missing only if it is not entered. A pointer field is usually
|
||||
used in this case so that you can detect if a value is entered or not by checking if the pointer is nil or not.
|
||||
You can use the `validation.NotNil` rule to ensure a value is entered (even if it is a zero value).
|
||||
|
||||
|
||||
### Embedded Structs
|
||||
|
||||
The `validation.ValidateStruct` method will properly validate a struct that contains embedded structs. In particular,
|
||||
the fields of an embedded struct are treated as if they belong directly to the containing struct. For example,
|
||||
|
||||
```go
|
||||
type Employee struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func ()
|
||||
|
||||
type Manager struct {
|
||||
Employee
|
||||
Level int
|
||||
}
|
||||
|
||||
m := Manager{}
|
||||
err := validation.ValidateStruct(&m,
|
||||
validation.Field(&m.Name, validation.Required),
|
||||
validation.Field(&m.Level, validation.Required),
|
||||
)
|
||||
fmt.Println(err)
|
||||
// Output:
|
||||
// Level: cannot be blank; Name: cannot be blank.
|
||||
```
|
||||
|
||||
In the above code, we use `&m.Name` to specify the validation of the `Name` field of the embedded struct `Employee`.
|
||||
And the validation error uses `Name` as the key for the error associated with the `Name` field as if `Name` a field
|
||||
directly belonging to `Manager`.
|
||||
|
||||
If `Employee` implements the `validation.Validatable` interface, we can also use the following code to validate
|
||||
`Manager`, which generates the same validation result:
|
||||
|
||||
```go
|
||||
func (e Employee) Validate() error {
|
||||
return validation.ValidateStruct(&e,
|
||||
validation.Field(&e.Name, validation.Required),
|
||||
)
|
||||
}
|
||||
|
||||
err := validation.ValidateStruct(&m,
|
||||
validation.Field(&m.Employee),
|
||||
validation.Field(&m.Level, validation.Required),
|
||||
)
|
||||
fmt.Println(err)
|
||||
// Output:
|
||||
// Level: cannot be blank; Name: cannot be blank.
|
||||
```
|
||||
|
||||
|
||||
## Built-in Validation Rules
|
||||
|
||||
The following rules are provided in the `validation` package:
|
||||
|
||||
* `In(...interface{})`: checks if a value can be found in the given list of values.
|
||||
* `Length(min, max int)`: checks if the length of a value is within the specified range.
|
||||
This rule should only be used for validating strings, slices, maps, and arrays.
|
||||
* `RuneLength(min, max int)`: checks if the length of a string is within the specified range.
|
||||
This rule is similar as `Length` except that when the value being validated is a string, it checks
|
||||
its rune length instead of byte length.
|
||||
* `Min(min interface{})` and `Max(max interface{})`: checks if a value is within the specified range.
|
||||
These two rules should only be used for validating int, uint, float and time.Time types.
|
||||
* `Match(*regexp.Regexp)`: checks if a value matches the specified regular expression.
|
||||
This rule should only be used for strings and byte slices.
|
||||
* `Date(layout string)`: checks if a string value is a date whose format is specified by the layout.
|
||||
By calling `Min()` and/or `Max()`, you can check additionally if the date is within the specified range.
|
||||
* `Required`: checks if a value is not empty (neither nil nor zero).
|
||||
* `NotNil`: checks if a pointer value is not nil. Non-pointer values are considered valid.
|
||||
* `NilOrNotEmpty`: checks if a value is a nil pointer or a non-empty value. This differs from `Required` in that it treats a nil pointer as valid.
|
||||
* `Skip`: this is a special rule used to indicate that all rules following it should be skipped (including the nested ones).
|
||||
* `MultipleOf`: checks if the value is a multiple of the specified range.
|
||||
|
||||
The `is` sub-package provides a list of commonly used string validation rules that can be used to check if the format
|
||||
of a value satisfies certain requirements. Note that these rules only handle strings and byte slices and if a string
|
||||
or byte slice is empty, it is considered valid. You may use a `Required` rule to ensure a value is not empty.
|
||||
Below is the whole list of the rules provided by the `is` package:
|
||||
|
||||
* `Email`: validates if a string is an email or not
|
||||
* `URL`: validates if a string is a valid URL
|
||||
* `RequestURL`: validates if a string is a valid request URL
|
||||
* `RequestURI`: validates if a string is a valid request URI
|
||||
* `Alpha`: validates if a string contains English letters only (a-zA-Z)
|
||||
* `Digit`: validates if a string contains digits only (0-9)
|
||||
* `Alphanumeric`: validates if a string contains English letters and digits only (a-zA-Z0-9)
|
||||
* `UTFLetter`: validates if a string contains unicode letters only
|
||||
* `UTFDigit`: validates if a string contains unicode decimal digits only
|
||||
* `UTFLetterNumeric`: validates if a string contains unicode letters and numbers only
|
||||
* `UTFNumeric`: validates if a string contains unicode number characters (category N) only
|
||||
* `LowerCase`: validates if a string contains lower case unicode letters only
|
||||
* `UpperCase`: validates if a string contains upper case unicode letters only
|
||||
* `Hexadecimal`: validates if a string is a valid hexadecimal number
|
||||
* `HexColor`: validates if a string is a valid hexadecimal color code
|
||||
* `RGBColor`: validates if a string is a valid RGB color in the form of rgb(R, G, B)
|
||||
* `Int`: validates if a string is a valid integer number
|
||||
* `Float`: validates if a string is a floating point number
|
||||
* `UUIDv3`: validates if a string is a valid version 3 UUID
|
||||
* `UUIDv4`: validates if a string is a valid version 4 UUID
|
||||
* `UUIDv5`: validates if a string is a valid version 5 UUID
|
||||
* `UUID`: validates if a string is a valid UUID
|
||||
* `CreditCard`: validates if a string is a valid credit card number
|
||||
* `ISBN10`: validates if a string is an ISBN version 10
|
||||
* `ISBN13`: validates if a string is an ISBN version 13
|
||||
* `ISBN`: validates if a string is an ISBN (either version 10 or 13)
|
||||
* `JSON`: validates if a string is in valid JSON format
|
||||
* `ASCII`: validates if a string contains ASCII characters only
|
||||
* `PrintableASCII`: validates if a string contains printable ASCII characters only
|
||||
* `Multibyte`: validates if a string contains multibyte characters
|
||||
* `FullWidth`: validates if a string contains full-width characters
|
||||
* `HalfWidth`: validates if a string contains half-width characters
|
||||
* `VariableWidth`: validates if a string contains both full-width and half-width characters
|
||||
* `Base64`: validates if a string is encoded in Base64
|
||||
* `DataURI`: validates if a string is a valid base64-encoded data URI
|
||||
* `E164`: validates if a string is a valid E164 phone number (+19251232233)
|
||||
* `CountryCode2`: validates if a string is a valid ISO3166 Alpha 2 country code
|
||||
* `CountryCode3`: validates if a string is a valid ISO3166 Alpha 3 country code
|
||||
* `DialString`: validates if a string is a valid dial string that can be passed to Dial()
|
||||
* `MAC`: validates if a string is a MAC address
|
||||
* `IP`: validates if a string is a valid IP address (either version 4 or 6)
|
||||
* `IPv4`: validates if a string is a valid version 4 IP address
|
||||
* `IPv6`: validates if a string is a valid version 6 IP address
|
||||
* `Subdomain`: validates if a string is valid subdomain
|
||||
* `Domain`: validates if a string is valid domain
|
||||
* `DNSName`: validates if a string is valid DNS name
|
||||
* `Host`: validates if a string is a valid IP (both v4 and v6) or a valid DNS name
|
||||
* `Port`: validates if a string is a valid port number
|
||||
* `MongoID`: validates if a string is a valid Mongo ID
|
||||
* `Latitude`: validates if a string is a valid latitude
|
||||
* `Longitude`: validates if a string is a valid longitude
|
||||
* `SSN`: validates if a string is a social security number (SSN)
|
||||
* `Semver`: validates if a string is a valid semantic version
|
||||
|
||||
### Customizing Error Messages
|
||||
|
||||
All built-in validation rules allow you to customize error messages. To do so, simply call the `Error()` method
|
||||
of the rules. For example,
|
||||
|
||||
```go
|
||||
data := "2123"
|
||||
err := validation.Validate(data,
|
||||
validation.Required.Error("is required"),
|
||||
validation.Match(regexp.MustCompile("^[0-9]{5}$")).Error("must be a string with five digits"),
|
||||
)
|
||||
fmt.Println(err)
|
||||
// Output:
|
||||
// must be a string with five digits
|
||||
```
|
||||
|
||||
|
||||
## Creating Custom Rules
|
||||
|
||||
Creating a custom rule is as simple as implementing the `validation.Rule` interface. The interface contains a single
|
||||
method as shown below, which should validate the value and return the validation error, if any:
|
||||
|
||||
```go
|
||||
// Validate validates a value and returns an error if validation fails.
|
||||
Validate(value interface{}) error
|
||||
```
|
||||
|
||||
If you already have a function with the same signature as shown above, you can call `validation.By()` to turn
|
||||
it into a validation rule. For example,
|
||||
|
||||
```go
|
||||
func checkAbc(value interface{}) error {
|
||||
s, _ := value.(string)
|
||||
if s != "abc" {
|
||||
return errors.New("must be abc")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
err := validation.Validate("xyz", validation.By(checkAbc))
|
||||
fmt.Println(err)
|
||||
// Output: must be abc
|
||||
```
|
||||
|
||||
|
||||
### Rule Groups
|
||||
|
||||
When a combination of several rules are used in multiple places, you may use the following trick to create a
|
||||
rule group so that your code is more maintainable.
|
||||
|
||||
```go
|
||||
var NameRule = []validation.Rule{
|
||||
validation.Required,
|
||||
validation.Length(5, 20),
|
||||
}
|
||||
|
||||
type User struct {
|
||||
FirstName string
|
||||
LastName string
|
||||
}
|
||||
|
||||
func (u User) Validate() error {
|
||||
return validation.ValidateStruct(&u,
|
||||
validation.Field(&u.FirstName, NameRule...),
|
||||
validation.Field(&u.LastName, NameRule...),
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
In the above example, we create a rule group `NameRule` which consists of two validation rules. We then use this rule
|
||||
group to validate both `FirstName` and `LastName`.
|
||||
|
||||
|
||||
## Credits
|
||||
|
||||
The `is` sub-package wraps the excellent validators provided by the [govalidator](https://github.com/asaskevich/govalidator) package.
|
46
vendor/github.com/go-ozzo/ozzo-validation/UPGRADE.md
generated
vendored
46
vendor/github.com/go-ozzo/ozzo-validation/UPGRADE.md
generated
vendored
@ -1,46 +0,0 @@
|
||||
# Upgrade Instructions
|
||||
|
||||
## Upgrade from 2.x to 3.x
|
||||
|
||||
* Instead of using `StructRules` to define struct validation rules, use `ValidateStruct()` to declare and perform
|
||||
struct validation. The following code snippet shows how to modify your code:
|
||||
```go
|
||||
// 2.x usage
|
||||
err := validation.StructRules{}.
|
||||
Add("Street", validation.Required, validation.Length(5, 50)).
|
||||
Add("City", validation.Required, validation.Length(5, 50)).
|
||||
Add("State", validation.Required, validation.Match(regexp.MustCompile("^[A-Z]{2}$"))).
|
||||
Add("Zip", validation.Required, validation.Match(regexp.MustCompile("^[0-9]{5}$"))).
|
||||
Validate(a)
|
||||
|
||||
// 3.x usage
|
||||
err := validation.ValidateStruct(&a,
|
||||
validation.Field(&a.Street, validation.Required, validation.Length(5, 50)),
|
||||
validation.Field(&a.City, validation.Required, validation.Length(5, 50)),
|
||||
validation.Field(&a.State, validation.Required, validation.Match(regexp.MustCompile("^[A-Z]{2}$"))),
|
||||
validation.Field(&a.Zip, validation.Required, validation.Match(regexp.MustCompile("^[0-9]{5}$"))),
|
||||
)
|
||||
```
|
||||
|
||||
* Instead of using `Rules` to declare a rule list and use it to validate a value, call `Validate()` with the rules directly.
|
||||
```go
|
||||
data := "example"
|
||||
|
||||
// 2.x usage
|
||||
rules := validation.Rules{
|
||||
validation.Required,
|
||||
validation.Length(5, 100),
|
||||
is.URL,
|
||||
}
|
||||
err := rules.Validate(data)
|
||||
|
||||
// 3.x usage
|
||||
err := validation.Validate(data,
|
||||
validation.Required,
|
||||
validation.Length(5, 100),
|
||||
is.URL,
|
||||
)
|
||||
```
|
||||
|
||||
* The default struct tags used for determining error keys is changed from `validation` to `json`. You may modify
|
||||
`validation.ErrorTag` to change it back.
|
84
vendor/github.com/go-ozzo/ozzo-validation/date.go
generated
vendored
84
vendor/github.com/go-ozzo/ozzo-validation/date.go
generated
vendored
@ -1,84 +0,0 @@
|
||||
// Copyright 2016 Qiang Xue. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package validation
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
type DateRule struct {
|
||||
layout string
|
||||
min, max time.Time
|
||||
message string
|
||||
rangeMessage string
|
||||
}
|
||||
|
||||
// Date returns a validation rule that checks if a string value is in a format that can be parsed into a date.
|
||||
// The format of the date should be specified as the layout parameter which accepts the same value as that for time.Parse.
|
||||
// For example,
|
||||
// validation.Date(time.ANSIC)
|
||||
// validation.Date("02 Jan 06 15:04 MST")
|
||||
// validation.Date("2006-01-02")
|
||||
//
|
||||
// By calling Min() and/or Max(), you can let the Date rule to check if a parsed date value is within
|
||||
// the specified date range.
|
||||
//
|
||||
// An empty value is considered valid. Use the Required rule to make sure a value is not empty.
|
||||
func Date(layout string) *DateRule {
|
||||
return &DateRule{
|
||||
layout: layout,
|
||||
message: "must be a valid date",
|
||||
rangeMessage: "the data is out of range",
|
||||
}
|
||||
}
|
||||
|
||||
// Error sets the error message that is used when the value being validated is not a valid date.
|
||||
func (r *DateRule) Error(message string) *DateRule {
|
||||
r.message = message
|
||||
return r
|
||||
}
|
||||
|
||||
// RangeError sets the error message that is used when the value being validated is out of the specified Min/Max date range.
|
||||
func (r *DateRule) RangeError(message string) *DateRule {
|
||||
r.rangeMessage = message
|
||||
return r
|
||||
}
|
||||
|
||||
// Min sets the minimum date range. A zero value means skipping the minimum range validation.
|
||||
func (r *DateRule) Min(min time.Time) *DateRule {
|
||||
r.min = min
|
||||
return r
|
||||
}
|
||||
|
||||
// Max sets the maximum date range. A zero value means skipping the maximum range validation.
|
||||
func (r *DateRule) Max(max time.Time) *DateRule {
|
||||
r.max = max
|
||||
return r
|
||||
}
|
||||
|
||||
// Validate checks if the given value is a valid date.
|
||||
func (r *DateRule) Validate(value interface{}) error {
|
||||
value, isNil := Indirect(value)
|
||||
if isNil || IsEmpty(value) {
|
||||
return nil
|
||||
}
|
||||
|
||||
str, err := EnsureString(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
date, err := time.Parse(r.layout, str)
|
||||
if err != nil {
|
||||
return errors.New(r.message)
|
||||
}
|
||||
|
||||
if !r.min.IsZero() && r.min.After(date) || !r.max.IsZero() && date.After(r.max) {
|
||||
return errors.New(r.rangeMessage)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
89
vendor/github.com/go-ozzo/ozzo-validation/error.go
generated
vendored
89
vendor/github.com/go-ozzo/ozzo-validation/error.go
generated
vendored
@ -1,89 +0,0 @@
|
||||
// Copyright 2016 Qiang Xue. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package validation
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
)
|
||||
|
||||
type (
|
||||
// Errors represents the validation errors that are indexed by struct field names, map or slice keys.
|
||||
Errors map[string]error
|
||||
|
||||
// InternalError represents an error that should NOT be treated as a validation error.
|
||||
InternalError interface {
|
||||
error
|
||||
InternalError() error
|
||||
}
|
||||
|
||||
internalError struct {
|
||||
error
|
||||
}
|
||||
)
|
||||
|
||||
// NewInternalError wraps a given error into an InternalError.
|
||||
func NewInternalError(err error) InternalError {
|
||||
return &internalError{error: err}
|
||||
}
|
||||
|
||||
// InternalError returns the actual error that it wraps around.
|
||||
func (e *internalError) InternalError() error {
|
||||
return e.error
|
||||
}
|
||||
|
||||
// Error returns the error string of Errors.
|
||||
func (es Errors) Error() string {
|
||||
if len(es) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
keys := []string{}
|
||||
for key := range es {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
s := ""
|
||||
for i, key := range keys {
|
||||
if i > 0 {
|
||||
s += "; "
|
||||
}
|
||||
if errs, ok := es[key].(Errors); ok {
|
||||
s += fmt.Sprintf("%v: (%v)", key, errs)
|
||||
} else {
|
||||
s += fmt.Sprintf("%v: %v", key, es[key].Error())
|
||||
}
|
||||
}
|
||||
return s + "."
|
||||
}
|
||||
|
||||
// MarshalJSON converts the Errors into a valid JSON.
|
||||
func (es Errors) MarshalJSON() ([]byte, error) {
|
||||
errs := map[string]interface{}{}
|
||||
for key, err := range es {
|
||||
if ms, ok := err.(json.Marshaler); ok {
|
||||
errs[key] = ms
|
||||
} else {
|
||||
errs[key] = err.Error()
|
||||
}
|
||||
}
|
||||
return json.Marshal(errs)
|
||||
}
|
||||
|
||||
// Filter removes all nils from Errors and returns back the updated Errors as an error.
|
||||
// If the length of Errors becomes 0, it will return nil.
|
||||
func (es Errors) Filter() error {
|
||||
for key, value := range es {
|
||||
if value == nil {
|
||||
delete(es, key)
|
||||
}
|
||||
}
|
||||
if len(es) == 0 {
|
||||
return nil
|
||||
}
|
||||
return es
|
||||
}
|
43
vendor/github.com/go-ozzo/ozzo-validation/in.go
generated
vendored
43
vendor/github.com/go-ozzo/ozzo-validation/in.go
generated
vendored
@ -1,43 +0,0 @@
|
||||
// Copyright 2016 Qiang Xue. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package validation
|
||||
|
||||
import "errors"
|
||||
|
||||
// In returns a validation rule that checks if a value can be found in the given list of values.
|
||||
// Note that the value being checked and the possible range of values must be of the same type.
|
||||
// An empty value is considered valid. Use the Required rule to make sure a value is not empty.
|
||||
func In(values ...interface{}) *InRule {
|
||||
return &InRule{
|
||||
elements: values,
|
||||
message: "must be a valid value",
|
||||
}
|
||||
}
|
||||
|
||||
type InRule struct {
|
||||
elements []interface{}
|
||||
message string
|
||||
}
|
||||
|
||||
// Validate checks if the given value is valid or not.
|
||||
func (r *InRule) Validate(value interface{}) error {
|
||||
value, isNil := Indirect(value)
|
||||
if isNil || IsEmpty(value) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, e := range r.elements {
|
||||
if e == value {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return errors.New(r.message)
|
||||
}
|
||||
|
||||
// Error sets the error message for the rule.
|
||||
func (r *InRule) Error(message string) *InRule {
|
||||
r.message = message
|
||||
return r
|
||||
}
|
171
vendor/github.com/go-ozzo/ozzo-validation/is/rules.go
generated
vendored
171
vendor/github.com/go-ozzo/ozzo-validation/is/rules.go
generated
vendored
@ -1,171 +0,0 @@
|
||||
// Copyright 2016 Qiang Xue. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package is provides a list of commonly used string validation rules.
|
||||
package is
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"unicode"
|
||||
|
||||
"github.com/asaskevich/govalidator"
|
||||
"github.com/go-ozzo/ozzo-validation"
|
||||
)
|
||||
|
||||
var (
|
||||
// Email validates if a string is an email or not.
|
||||
Email = validation.NewStringRule(govalidator.IsEmail, "must be a valid email address")
|
||||
// URL validates if a string is a valid URL
|
||||
URL = validation.NewStringRule(govalidator.IsURL, "must be a valid URL")
|
||||
// RequestURL validates if a string is a valid request URL
|
||||
RequestURL = validation.NewStringRule(govalidator.IsRequestURL, "must be a valid request URL")
|
||||
// RequestURI validates if a string is a valid request URI
|
||||
RequestURI = validation.NewStringRule(govalidator.IsRequestURI, "must be a valid request URI")
|
||||
// Alpha validates if a string contains English letters only (a-zA-Z)
|
||||
Alpha = validation.NewStringRule(govalidator.IsAlpha, "must contain English letters only")
|
||||
// Digit validates if a string contains digits only (0-9)
|
||||
Digit = validation.NewStringRule(isDigit, "must contain digits only")
|
||||
// Alphanumeric validates if a string contains English letters and digits only (a-zA-Z0-9)
|
||||
Alphanumeric = validation.NewStringRule(govalidator.IsAlphanumeric, "must contain English letters and digits only")
|
||||
// UTFLetter validates if a string contains unicode letters only
|
||||
UTFLetter = validation.NewStringRule(govalidator.IsUTFLetter, "must contain unicode letter characters only")
|
||||
// UTFDigit validates if a string contains unicode decimal digits only
|
||||
UTFDigit = validation.NewStringRule(govalidator.IsUTFDigit, "must contain unicode decimal digits only")
|
||||
// UTFLetterNumeric validates if a string contains unicode letters and numbers only
|
||||
UTFLetterNumeric = validation.NewStringRule(govalidator.IsUTFLetterNumeric, "must contain unicode letters and numbers only")
|
||||
// UTFNumeric validates if a string contains unicode number characters (category N) only
|
||||
UTFNumeric = validation.NewStringRule(isUTFNumeric, "must contain unicode number characters only")
|
||||
// LowerCase validates if a string contains lower case unicode letters only
|
||||
LowerCase = validation.NewStringRule(govalidator.IsLowerCase, "must be in lower case")
|
||||
// UpperCase validates if a string contains upper case unicode letters only
|
||||
UpperCase = validation.NewStringRule(govalidator.IsUpperCase, "must be in upper case")
|
||||
// Hexadecimal validates if a string is a valid hexadecimal number
|
||||
Hexadecimal = validation.NewStringRule(govalidator.IsHexadecimal, "must be a valid hexadecimal number")
|
||||
// HexColor validates if a string is a valid hexadecimal color code
|
||||
HexColor = validation.NewStringRule(govalidator.IsHexcolor, "must be a valid hexadecimal color code")
|
||||
// RGBColor validates if a string is a valid RGB color in the form of rgb(R, G, B)
|
||||
RGBColor = validation.NewStringRule(govalidator.IsRGBcolor, "must be a valid RGB color code")
|
||||
// Int validates if a string is a valid integer number
|
||||
Int = validation.NewStringRule(govalidator.IsInt, "must be an integer number")
|
||||
// Float validates if a string is a floating point number
|
||||
Float = validation.NewStringRule(govalidator.IsFloat, "must be a floating point number")
|
||||
// UUIDv3 validates if a string is a valid version 3 UUID
|
||||
UUIDv3 = validation.NewStringRule(govalidator.IsUUIDv3, "must be a valid UUID v3")
|
||||
// UUIDv4 validates if a string is a valid version 4 UUID
|
||||
UUIDv4 = validation.NewStringRule(govalidator.IsUUIDv4, "must be a valid UUID v4")
|
||||
// UUIDv5 validates if a string is a valid version 5 UUID
|
||||
UUIDv5 = validation.NewStringRule(govalidator.IsUUIDv5, "must be a valid UUID v5")
|
||||
// UUID validates if a string is a valid UUID
|
||||
UUID = validation.NewStringRule(govalidator.IsUUID, "must be a valid UUID")
|
||||
// CreditCard validates if a string is a valid credit card number
|
||||
CreditCard = validation.NewStringRule(govalidator.IsCreditCard, "must be a valid credit card number")
|
||||
// ISBN10 validates if a string is an ISBN version 10
|
||||
ISBN10 = validation.NewStringRule(govalidator.IsISBN10, "must be a valid ISBN-10")
|
||||
// ISBN13 validates if a string is an ISBN version 13
|
||||
ISBN13 = validation.NewStringRule(govalidator.IsISBN13, "must be a valid ISBN-13")
|
||||
// ISBN validates if a string is an ISBN (either version 10 or 13)
|
||||
ISBN = validation.NewStringRule(isISBN, "must be a valid ISBN")
|
||||
// JSON validates if a string is in valid JSON format
|
||||
JSON = validation.NewStringRule(govalidator.IsJSON, "must be in valid JSON format")
|
||||
// ASCII validates if a string contains ASCII characters only
|
||||
ASCII = validation.NewStringRule(govalidator.IsASCII, "must contain ASCII characters only")
|
||||
// PrintableASCII validates if a string contains printable ASCII characters only
|
||||
PrintableASCII = validation.NewStringRule(govalidator.IsPrintableASCII, "must contain printable ASCII characters only")
|
||||
// Multibyte validates if a string contains multibyte characters
|
||||
Multibyte = validation.NewStringRule(govalidator.IsMultibyte, "must contain multibyte characters")
|
||||
// FullWidth validates if a string contains full-width characters
|
||||
FullWidth = validation.NewStringRule(govalidator.IsFullWidth, "must contain full-width characters")
|
||||
// HalfWidth validates if a string contains half-width characters
|
||||
HalfWidth = validation.NewStringRule(govalidator.IsHalfWidth, "must contain half-width characters")
|
||||
// VariableWidth validates if a string contains both full-width and half-width characters
|
||||
VariableWidth = validation.NewStringRule(govalidator.IsVariableWidth, "must contain both full-width and half-width characters")
|
||||
// Base64 validates if a string is encoded in Base64
|
||||
Base64 = validation.NewStringRule(govalidator.IsBase64, "must be encoded in Base64")
|
||||
// DataURI validates if a string is a valid base64-encoded data URI
|
||||
DataURI = validation.NewStringRule(govalidator.IsDataURI, "must be a Base64-encoded data URI")
|
||||
// E164 validates if a string is a valid ISO3166 Alpha 2 country code
|
||||
E164 = validation.NewStringRule(isE164Number, "must be a valid E164 number")
|
||||
// CountryCode2 validates if a string is a valid ISO3166 Alpha 2 country code
|
||||
CountryCode2 = validation.NewStringRule(govalidator.IsISO3166Alpha2, "must be a valid two-letter country code")
|
||||
// CountryCode3 validates if a string is a valid ISO3166 Alpha 3 country code
|
||||
CountryCode3 = validation.NewStringRule(govalidator.IsISO3166Alpha3, "must be a valid three-letter country code")
|
||||
// DialString validates if a string is a valid dial string that can be passed to Dial()
|
||||
DialString = validation.NewStringRule(govalidator.IsDialString, "must be a valid dial string")
|
||||
// MAC validates if a string is a MAC address
|
||||
MAC = validation.NewStringRule(govalidator.IsMAC, "must be a valid MAC address")
|
||||
// IP validates if a string is a valid IP address (either version 4 or 6)
|
||||
IP = validation.NewStringRule(govalidator.IsIP, "must be a valid IP address")
|
||||
// IPv4 validates if a string is a valid version 4 IP address
|
||||
IPv4 = validation.NewStringRule(govalidator.IsIPv4, "must be a valid IPv4 address")
|
||||
// IPv6 validates if a string is a valid version 6 IP address
|
||||
IPv6 = validation.NewStringRule(govalidator.IsIPv6, "must be a valid IPv6 address")
|
||||
// Subdomain validates if a string is valid subdomain
|
||||
Subdomain = validation.NewStringRule(isSubdomain, "must be a valid subdomain")
|
||||
// Domain validates if a string is valid domain
|
||||
Domain = validation.NewStringRule(isDomain, "must be a valid domain")
|
||||
// DNSName validates if a string is valid DNS name
|
||||
DNSName = validation.NewStringRule(govalidator.IsDNSName, "must be a valid DNS name")
|
||||
// Host validates if a string is a valid IP (both v4 and v6) or a valid DNS name
|
||||
Host = validation.NewStringRule(govalidator.IsHost, "must be a valid IP address or DNS name")
|
||||
// Port validates if a string is a valid port number
|
||||
Port = validation.NewStringRule(govalidator.IsPort, "must be a valid port number")
|
||||
// MongoID validates if a string is a valid Mongo ID
|
||||
MongoID = validation.NewStringRule(govalidator.IsMongoID, "must be a valid hex-encoded MongoDB ObjectId")
|
||||
// Latitude validates if a string is a valid latitude
|
||||
Latitude = validation.NewStringRule(govalidator.IsLatitude, "must be a valid latitude")
|
||||
// Longitude validates if a string is a valid longitude
|
||||
Longitude = validation.NewStringRule(govalidator.IsLongitude, "must be a valid longitude")
|
||||
// SSN validates if a string is a social security number (SSN)
|
||||
SSN = validation.NewStringRule(govalidator.IsSSN, "must be a valid social security number")
|
||||
// Semver validates if a string is a valid semantic version
|
||||
Semver = validation.NewStringRule(govalidator.IsSemver, "must be a valid semantic version")
|
||||
)
|
||||
|
||||
var (
|
||||
reDigit = regexp.MustCompile("^[0-9]+$")
|
||||
// Subdomain regex source: https://stackoverflow.com/a/7933253
|
||||
reSubdomain = regexp.MustCompile(`^[A-Za-z0-9](?:[A-Za-z0-9\-]{0,61}[A-Za-z0-9])?$`)
|
||||
)
|
||||
|
||||
func isISBN(value string) bool {
|
||||
return govalidator.IsISBN(value, 10) || govalidator.IsISBN(value, 13)
|
||||
}
|
||||
|
||||
func isDigit(value string) bool {
|
||||
return reDigit.MatchString(value)
|
||||
}
|
||||
|
||||
func isE164Number(value string) bool {
|
||||
// E164 regex source: https://stackoverflow.com/a/23299989
|
||||
reE164 := regexp.MustCompile(`^\+?[1-9]\d{1,14}$`)
|
||||
return reE164.MatchString(value)
|
||||
}
|
||||
|
||||
func isSubdomain(value string) bool {
|
||||
// Subdomain regex source: https://stackoverflow.com/a/7933253
|
||||
reSubdomain := regexp.MustCompile(`^[A-Za-z0-9](?:[A-Za-z0-9\-]{0,61}[A-Za-z0-9])?$`)
|
||||
return reSubdomain.MatchString(value)
|
||||
}
|
||||
|
||||
func isDomain(value string) bool {
|
||||
if len(value) > 255 {
|
||||
return false
|
||||
}
|
||||
|
||||
// Domain regex source: https://stackoverflow.com/a/7933253
|
||||
// Slightly modified: Removed 255 max length validation since Go regex does not
|
||||
// support lookarounds. More info: https://stackoverflow.com/a/38935027
|
||||
reDomain := regexp.MustCompile(`^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+(?:[a-z]{1,63}| xn--[a-z0-9]{1,59})$`)
|
||||
|
||||
return reDomain.MatchString(value)
|
||||
}
|
||||
|
||||
func isUTFNumeric(value string) bool {
|
||||
for _, c := range value {
|
||||
if unicode.IsNumber(c) == false {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
81
vendor/github.com/go-ozzo/ozzo-validation/length.go
generated
vendored
81
vendor/github.com/go-ozzo/ozzo-validation/length.go
generated
vendored
@ -1,81 +0,0 @@
|
||||
// Copyright 2016 Qiang Xue. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package validation
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// Length returns a validation rule that checks if a value's length is within the specified range.
|
||||
// If max is 0, it means there is no upper bound for the length.
|
||||
// This rule should only be used for validating strings, slices, maps, and arrays.
|
||||
// An empty value is considered valid. Use the Required rule to make sure a value is not empty.
|
||||
func Length(min, max int) *LengthRule {
|
||||
message := "the value must be empty"
|
||||
if min == 0 && max > 0 {
|
||||
message = fmt.Sprintf("the length must be no more than %v", max)
|
||||
} else if min > 0 && max == 0 {
|
||||
message = fmt.Sprintf("the length must be no less than %v", min)
|
||||
} else if min > 0 && max > 0 {
|
||||
if min == max {
|
||||
message = fmt.Sprintf("the length must be exactly %v", min)
|
||||
} else {
|
||||
message = fmt.Sprintf("the length must be between %v and %v", min, max)
|
||||
}
|
||||
}
|
||||
return &LengthRule{
|
||||
min: min,
|
||||
max: max,
|
||||
message: message,
|
||||
}
|
||||
}
|
||||
|
||||
// RuneLength returns a validation rule that checks if a string's rune length is within the specified range.
|
||||
// If max is 0, it means there is no upper bound for the length.
|
||||
// This rule should only be used for validating strings, slices, maps, and arrays.
|
||||
// An empty value is considered valid. Use the Required rule to make sure a value is not empty.
|
||||
// If the value being validated is not a string, the rule works the same as Length.
|
||||
func RuneLength(min, max int) *LengthRule {
|
||||
r := Length(min, max)
|
||||
r.rune = true
|
||||
return r
|
||||
}
|
||||
|
||||
type LengthRule struct {
|
||||
min, max int
|
||||
message string
|
||||
rune bool
|
||||
}
|
||||
|
||||
// Validate checks if the given value is valid or not.
|
||||
func (v *LengthRule) Validate(value interface{}) error {
|
||||
value, isNil := Indirect(value)
|
||||
if isNil || IsEmpty(value) {
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
l int
|
||||
err error
|
||||
)
|
||||
if s, ok := value.(string); ok && v.rune {
|
||||
l = utf8.RuneCountInString(s)
|
||||
} else if l, err = LengthOfValue(value); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if v.min > 0 && l < v.min || v.max > 0 && l > v.max {
|
||||
return errors.New(v.message)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Error sets the error message for the rule.
|
||||
func (v *LengthRule) Error(message string) *LengthRule {
|
||||
v.message = message
|
||||
return v
|
||||
}
|
47
vendor/github.com/go-ozzo/ozzo-validation/match.go
generated
vendored
47
vendor/github.com/go-ozzo/ozzo-validation/match.go
generated
vendored
@ -1,47 +0,0 @@
|
||||
// Copyright 2016 Qiang Xue. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package validation
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
// Match returns a validation rule that checks if a value matches the specified regular expression.
|
||||
// This rule should only be used for validating strings and byte slices, or a validation error will be reported.
|
||||
// An empty value is considered valid. Use the Required rule to make sure a value is not empty.
|
||||
func Match(re *regexp.Regexp) *MatchRule {
|
||||
return &MatchRule{
|
||||
re: re,
|
||||
message: "must be in a valid format",
|
||||
}
|
||||
}
|
||||
|
||||
type MatchRule struct {
|
||||
re *regexp.Regexp
|
||||
message string
|
||||
}
|
||||
|
||||
// Validate checks if the given value is valid or not.
|
||||
func (v *MatchRule) Validate(value interface{}) error {
|
||||
value, isNil := Indirect(value)
|
||||
if isNil {
|
||||
return nil
|
||||
}
|
||||
|
||||
isString, str, isBytes, bs := StringOrBytes(value)
|
||||
if isString && (str == "" || v.re.MatchString(str)) {
|
||||
return nil
|
||||
} else if isBytes && (len(bs) == 0 || v.re.Match(bs)) {
|
||||
return nil
|
||||
}
|
||||
return errors.New(v.message)
|
||||
}
|
||||
|
||||
// Error sets the error message for the rule.
|
||||
func (v *MatchRule) Error(message string) *MatchRule {
|
||||
v.message = message
|
||||
return v
|
||||
}
|
177
vendor/github.com/go-ozzo/ozzo-validation/minmax.go
generated
vendored
177
vendor/github.com/go-ozzo/ozzo-validation/minmax.go
generated
vendored
@ -1,177 +0,0 @@
|
||||
// Copyright 2016 Qiang Xue. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package validation
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ThresholdRule struct {
|
||||
threshold interface{}
|
||||
operator int
|
||||
message string
|
||||
}
|
||||
|
||||
const (
|
||||
greaterThan = iota
|
||||
greaterEqualThan
|
||||
lessThan
|
||||
lessEqualThan
|
||||
)
|
||||
|
||||
// Min is a validation rule that checks if a value is greater or equal than the specified value.
|
||||
// By calling Exclusive, the rule will check if the value is strictly greater than the specified value.
|
||||
// Note that the value being checked and the threshold value must be of the same type.
|
||||
// Only int, uint, float and time.Time types are supported.
|
||||
// An empty value is considered valid. Please use the Required rule to make sure a value is not empty.
|
||||
func Min(min interface{}) *ThresholdRule {
|
||||
return &ThresholdRule{
|
||||
threshold: min,
|
||||
operator: greaterEqualThan,
|
||||
message: fmt.Sprintf("must be no less than %v", min),
|
||||
}
|
||||
}
|
||||
|
||||
// Max is a validation rule that checks if a value is less or equal than the specified value.
|
||||
// By calling Exclusive, the rule will check if the value is strictly less than the specified value.
|
||||
// Note that the value being checked and the threshold value must be of the same type.
|
||||
// Only int, uint, float and time.Time types are supported.
|
||||
// An empty value is considered valid. Please use the Required rule to make sure a value is not empty.
|
||||
func Max(max interface{}) *ThresholdRule {
|
||||
return &ThresholdRule{
|
||||
threshold: max,
|
||||
operator: lessEqualThan,
|
||||
message: fmt.Sprintf("must be no greater than %v", max),
|
||||
}
|
||||
}
|
||||
|
||||
// Exclusive sets the comparison to exclude the boundary value.
|
||||
func (r *ThresholdRule) Exclusive() *ThresholdRule {
|
||||
if r.operator == greaterEqualThan {
|
||||
r.operator = greaterThan
|
||||
r.message = fmt.Sprintf("must be greater than %v", r.threshold)
|
||||
} else if r.operator == lessEqualThan {
|
||||
r.operator = lessThan
|
||||
r.message = fmt.Sprintf("must be less than %v", r.threshold)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// Validate checks if the given value is valid or not.
|
||||
func (r *ThresholdRule) Validate(value interface{}) error {
|
||||
value, isNil := Indirect(value)
|
||||
if isNil || IsEmpty(value) {
|
||||
return nil
|
||||
}
|
||||
|
||||
rv := reflect.ValueOf(r.threshold)
|
||||
switch rv.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
v, err := ToInt(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.compareInt(rv.Int(), v) {
|
||||
return nil
|
||||
}
|
||||
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
v, err := ToUint(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.compareUint(rv.Uint(), v) {
|
||||
return nil
|
||||
}
|
||||
|
||||
case reflect.Float32, reflect.Float64:
|
||||
v, err := ToFloat(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.compareFloat(rv.Float(), v) {
|
||||
return nil
|
||||
}
|
||||
|
||||
case reflect.Struct:
|
||||
t, ok := r.threshold.(time.Time)
|
||||
if !ok {
|
||||
return fmt.Errorf("type not supported: %v", rv.Type())
|
||||
}
|
||||
v, ok := value.(time.Time)
|
||||
if !ok {
|
||||
return fmt.Errorf("cannot convert %v to time.Time", reflect.TypeOf(value))
|
||||
}
|
||||
if v.IsZero() || r.compareTime(t, v) {
|
||||
return nil
|
||||
}
|
||||
|
||||
default:
|
||||
return fmt.Errorf("type not supported: %v", rv.Type())
|
||||
}
|
||||
|
||||
return errors.New(r.message)
|
||||
}
|
||||
|
||||
// Error sets the error message for the rule.
|
||||
func (r *ThresholdRule) Error(message string) *ThresholdRule {
|
||||
r.message = message
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *ThresholdRule) compareInt(threshold, value int64) bool {
|
||||
switch r.operator {
|
||||
case greaterThan:
|
||||
return value > threshold
|
||||
case greaterEqualThan:
|
||||
return value >= threshold
|
||||
case lessThan:
|
||||
return value < threshold
|
||||
default:
|
||||
return value <= threshold
|
||||
}
|
||||
}
|
||||
|
||||
func (r *ThresholdRule) compareUint(threshold, value uint64) bool {
|
||||
switch r.operator {
|
||||
case greaterThan:
|
||||
return value > threshold
|
||||
case greaterEqualThan:
|
||||
return value >= threshold
|
||||
case lessThan:
|
||||
return value < threshold
|
||||
default:
|
||||
return value <= threshold
|
||||
}
|
||||
}
|
||||
|
||||
func (r *ThresholdRule) compareFloat(threshold, value float64) bool {
|
||||
switch r.operator {
|
||||
case greaterThan:
|
||||
return value > threshold
|
||||
case greaterEqualThan:
|
||||
return value >= threshold
|
||||
case lessThan:
|
||||
return value < threshold
|
||||
default:
|
||||
return value <= threshold
|
||||
}
|
||||
}
|
||||
|
||||
func (r *ThresholdRule) compareTime(threshold, value time.Time) bool {
|
||||
switch r.operator {
|
||||
case greaterThan:
|
||||
return value.After(threshold)
|
||||
case greaterEqualThan:
|
||||
return value.After(threshold) || value.Equal(threshold)
|
||||
case lessThan:
|
||||
return value.Before(threshold)
|
||||
default:
|
||||
return value.Before(threshold) || value.Equal(threshold)
|
||||
}
|
||||
}
|
55
vendor/github.com/go-ozzo/ozzo-validation/multipleof.go
generated
vendored
55
vendor/github.com/go-ozzo/ozzo-validation/multipleof.go
generated
vendored
@ -1,55 +0,0 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func MultipleOf(threshold interface{}) *multipleOfRule {
|
||||
return &multipleOfRule{
|
||||
threshold,
|
||||
fmt.Sprintf("must be multiple of %v", threshold),
|
||||
}
|
||||
}
|
||||
|
||||
type multipleOfRule struct {
|
||||
threshold interface{}
|
||||
message string
|
||||
}
|
||||
|
||||
// Error sets the error message for the rule.
|
||||
func (r *multipleOfRule) Error(message string) *multipleOfRule {
|
||||
r.message = message
|
||||
return r
|
||||
}
|
||||
|
||||
|
||||
func (r *multipleOfRule) Validate(value interface{}) error {
|
||||
|
||||
rv := reflect.ValueOf(r.threshold)
|
||||
switch rv.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
v, err := ToInt(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if v%rv.Int() == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
v, err := ToUint(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if v%rv.Uint() == 0 {
|
||||
return nil
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("type not supported: %v", rv.Type())
|
||||
}
|
||||
|
||||
return errors.New(r.message)
|
||||
}
|
45
vendor/github.com/go-ozzo/ozzo-validation/not_in.go
generated
vendored
45
vendor/github.com/go-ozzo/ozzo-validation/not_in.go
generated
vendored
@ -1,45 +0,0 @@
|
||||
// Copyright 2018 Qiang Xue, Google LLC. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package validation
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
// NotIn returns a validation rule that checks if a value os absent from, the given list of values.
|
||||
// Note that the value being checked and the possible range of values must be of the same type.
|
||||
// An empty value is considered valid. Use the Required rule to make sure a value is not empty.
|
||||
func NotIn(values ...interface{}) *NotInRule {
|
||||
return &NotInRule{
|
||||
elements: values,
|
||||
message: "must not be in list",
|
||||
}
|
||||
}
|
||||
|
||||
type NotInRule struct {
|
||||
elements []interface{}
|
||||
message string
|
||||
}
|
||||
|
||||
// Validate checks if the given value is valid or not.
|
||||
func (r *NotInRule) Validate(value interface{}) error {
|
||||
value, isNil := Indirect(value)
|
||||
if isNil || IsEmpty(value) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, e := range r.elements {
|
||||
if e == value {
|
||||
return errors.New(r.message)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Error sets the error message for the rule.
|
||||
func (r *NotInRule) Error(message string) *NotInRule {
|
||||
r.message = message
|
||||
return r
|
||||
}
|
32
vendor/github.com/go-ozzo/ozzo-validation/not_nil.go
generated
vendored
32
vendor/github.com/go-ozzo/ozzo-validation/not_nil.go
generated
vendored
@ -1,32 +0,0 @@
|
||||
// Copyright 2016 Qiang Xue. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package validation
|
||||
|
||||
import "errors"
|
||||
|
||||
// NotNil is a validation rule that checks if a value is not nil.
|
||||
// NotNil only handles types including interface, pointer, slice, and map.
|
||||
// All other types are considered valid.
|
||||
var NotNil = ¬NilRule{message: "is required"}
|
||||
|
||||
type notNilRule struct {
|
||||
message string
|
||||
}
|
||||
|
||||
// Validate checks if the given value is valid or not.
|
||||
func (r *notNilRule) Validate(value interface{}) error {
|
||||
_, isNil := Indirect(value)
|
||||
if isNil {
|
||||
return errors.New(r.message)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Error sets the error message for the rule.
|
||||
func (r *notNilRule) Error(message string) *notNilRule {
|
||||
return ¬NilRule{
|
||||
message: message,
|
||||
}
|
||||
}
|
42
vendor/github.com/go-ozzo/ozzo-validation/required.go
generated
vendored
42
vendor/github.com/go-ozzo/ozzo-validation/required.go
generated
vendored
@ -1,42 +0,0 @@
|
||||
// Copyright 2016 Qiang Xue. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package validation
|
||||
|
||||
import "errors"
|
||||
|
||||
// Required is a validation rule that checks if a value is not empty.
|
||||
// A value is considered not empty if
|
||||
// - integer, float: not zero
|
||||
// - bool: true
|
||||
// - string, array, slice, map: len() > 0
|
||||
// - interface, pointer: not nil and the referenced value is not empty
|
||||
// - any other types
|
||||
var Required = &requiredRule{message: "cannot be blank", skipNil: false}
|
||||
|
||||
// NilOrNotEmpty checks if a value is a nil pointer or a value that is not empty.
|
||||
// NilOrNotEmpty differs from Required in that it treats a nil pointer as valid.
|
||||
var NilOrNotEmpty = &requiredRule{message: "cannot be blank", skipNil: true}
|
||||
|
||||
type requiredRule struct {
|
||||
message string
|
||||
skipNil bool
|
||||
}
|
||||
|
||||
// Validate checks if the given value is valid or not.
|
||||
func (v *requiredRule) Validate(value interface{}) error {
|
||||
value, isNil := Indirect(value)
|
||||
if v.skipNil && !isNil && IsEmpty(value) || !v.skipNil && (isNil || IsEmpty(value)) {
|
||||
return errors.New(v.message)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Error sets the error message for the rule.
|
||||
func (v *requiredRule) Error(message string) *requiredRule {
|
||||
return &requiredRule{
|
||||
message: message,
|
||||
skipNil: v.skipNil,
|
||||
}
|
||||
}
|
48
vendor/github.com/go-ozzo/ozzo-validation/string.go
generated
vendored
48
vendor/github.com/go-ozzo/ozzo-validation/string.go
generated
vendored
@ -1,48 +0,0 @@
|
||||
// Copyright 2016 Qiang Xue. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package validation
|
||||
|
||||
import "errors"
|
||||
|
||||
type stringValidator func(string) bool
|
||||
|
||||
// StringRule is a rule that checks a string variable using a specified stringValidator.
|
||||
type StringRule struct {
|
||||
validate stringValidator
|
||||
message string
|
||||
}
|
||||
|
||||
// NewStringRule creates a new validation rule using a function that takes a string value and returns a bool.
|
||||
// The rule returned will use the function to check if a given string or byte slice is valid or not.
|
||||
// An empty value is considered to be valid. Please use the Required rule to make sure a value is not empty.
|
||||
func NewStringRule(validator stringValidator, message string) *StringRule {
|
||||
return &StringRule{
|
||||
validate: validator,
|
||||
message: message,
|
||||
}
|
||||
}
|
||||
|
||||
// Error sets the error message for the rule.
|
||||
func (v *StringRule) Error(message string) *StringRule {
|
||||
return NewStringRule(v.validate, message)
|
||||
}
|
||||
|
||||
// Validate checks if the given value is valid or not.
|
||||
func (v *StringRule) Validate(value interface{}) error {
|
||||
value, isNil := Indirect(value)
|
||||
if isNil || IsEmpty(value) {
|
||||
return nil
|
||||
}
|
||||
|
||||
str, err := EnsureString(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if v.validate(str) {
|
||||
return nil
|
||||
}
|
||||
return errors.New(v.message)
|
||||
}
|
154
vendor/github.com/go-ozzo/ozzo-validation/struct.go
generated
vendored
154
vendor/github.com/go-ozzo/ozzo-validation/struct.go
generated
vendored
@ -1,154 +0,0 @@
|
||||
// Copyright 2016 Qiang Xue. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package validation
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrStructPointer is the error that a struct being validated is not specified as a pointer.
|
||||
ErrStructPointer = errors.New("only a pointer to a struct can be validated")
|
||||
)
|
||||
|
||||
type (
|
||||
// ErrFieldPointer is the error that a field is not specified as a pointer.
|
||||
ErrFieldPointer int
|
||||
|
||||
// ErrFieldNotFound is the error that a field cannot be found in the struct.
|
||||
ErrFieldNotFound int
|
||||
|
||||
// FieldRules represents a rule set associated with a struct field.
|
||||
FieldRules struct {
|
||||
fieldPtr interface{}
|
||||
rules []Rule
|
||||
}
|
||||
)
|
||||
|
||||
// Error returns the error string of ErrFieldPointer.
|
||||
func (e ErrFieldPointer) Error() string {
|
||||
return fmt.Sprintf("field #%v must be specified as a pointer", int(e))
|
||||
}
|
||||
|
||||
// Error returns the error string of ErrFieldNotFound.
|
||||
func (e ErrFieldNotFound) Error() string {
|
||||
return fmt.Sprintf("field #%v cannot be found in the struct", int(e))
|
||||
}
|
||||
|
||||
// ValidateStruct validates a struct by checking the specified struct fields against the corresponding validation rules.
|
||||
// Note that the struct being validated must be specified as a pointer to it. If the pointer is nil, it is considered valid.
|
||||
// Use Field() to specify struct fields that need to be validated. Each Field() call specifies a single field which
|
||||
// should be specified as a pointer to the field. A field can be associated with multiple rules.
|
||||
// For example,
|
||||
//
|
||||
// value := struct {
|
||||
// Name string
|
||||
// Value string
|
||||
// }{"name", "demo"}
|
||||
// err := validation.ValidateStruct(&value,
|
||||
// validation.Field(&a.Name, validation.Required),
|
||||
// validation.Field(&a.Value, validation.Required, validation.Length(5, 10)),
|
||||
// )
|
||||
// fmt.Println(err)
|
||||
// // Value: the length must be between 5 and 10.
|
||||
//
|
||||
// An error will be returned if validation fails.
|
||||
func ValidateStruct(structPtr interface{}, fields ...*FieldRules) error {
|
||||
value := reflect.ValueOf(structPtr)
|
||||
if value.Kind() != reflect.Ptr || !value.IsNil() && value.Elem().Kind() != reflect.Struct {
|
||||
// must be a pointer to a struct
|
||||
return NewInternalError(ErrStructPointer)
|
||||
}
|
||||
if value.IsNil() {
|
||||
// treat a nil struct pointer as valid
|
||||
return nil
|
||||
}
|
||||
value = value.Elem()
|
||||
|
||||
errs := Errors{}
|
||||
|
||||
for i, fr := range fields {
|
||||
fv := reflect.ValueOf(fr.fieldPtr)
|
||||
if fv.Kind() != reflect.Ptr {
|
||||
return NewInternalError(ErrFieldPointer(i))
|
||||
}
|
||||
ft := findStructField(value, fv)
|
||||
if ft == nil {
|
||||
return NewInternalError(ErrFieldNotFound(i))
|
||||
}
|
||||
if err := Validate(fv.Elem().Interface(), fr.rules...); err != nil {
|
||||
if ie, ok := err.(InternalError); ok && ie.InternalError() != nil {
|
||||
return err
|
||||
}
|
||||
if ft.Anonymous {
|
||||
// merge errors from anonymous struct field
|
||||
if es, ok := err.(Errors); ok {
|
||||
for name, value := range es {
|
||||
errs[name] = value
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
errs[getErrorFieldName(ft)] = err
|
||||
}
|
||||
}
|
||||
|
||||
if len(errs) > 0 {
|
||||
return errs
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Field specifies a struct field and the corresponding validation rules.
|
||||
// The struct field must be specified as a pointer to it.
|
||||
func Field(fieldPtr interface{}, rules ...Rule) *FieldRules {
|
||||
return &FieldRules{
|
||||
fieldPtr: fieldPtr,
|
||||
rules: rules,
|
||||
}
|
||||
}
|
||||
|
||||
// findStructField looks for a field in the given struct.
|
||||
// The field being looked for should be a pointer to the actual struct field.
|
||||
// If found, the field info will be returned. Otherwise, nil will be returned.
|
||||
func findStructField(structValue reflect.Value, fieldValue reflect.Value) *reflect.StructField {
|
||||
ptr := fieldValue.Pointer()
|
||||
for i := structValue.NumField() - 1; i >= 0; i-- {
|
||||
sf := structValue.Type().Field(i)
|
||||
if ptr == structValue.Field(i).UnsafeAddr() {
|
||||
// do additional type comparison because it's possible that the address of
|
||||
// an embedded struct is the same as the first field of the embedded struct
|
||||
if sf.Type == fieldValue.Elem().Type() {
|
||||
return &sf
|
||||
}
|
||||
}
|
||||
if sf.Anonymous {
|
||||
// delve into anonymous struct to look for the field
|
||||
fi := structValue.Field(i)
|
||||
if sf.Type.Kind() == reflect.Ptr {
|
||||
fi = fi.Elem()
|
||||
}
|
||||
if fi.Kind() == reflect.Struct {
|
||||
if f := findStructField(fi, fieldValue); f != nil {
|
||||
return f
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// getErrorFieldName returns the name that should be used to represent the validation error of a struct field.
|
||||
func getErrorFieldName(f *reflect.StructField) string {
|
||||
if tag := f.Tag.Get(ErrorTag); tag != "" {
|
||||
if cps := strings.SplitN(tag, ",", 2); cps[0] != "" {
|
||||
return cps[0]
|
||||
}
|
||||
}
|
||||
return f.Name
|
||||
}
|
163
vendor/github.com/go-ozzo/ozzo-validation/util.go
generated
vendored
163
vendor/github.com/go-ozzo/ozzo-validation/util.go
generated
vendored
@ -1,163 +0,0 @@
|
||||
// Copyright 2016 Qiang Xue. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package validation
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
bytesType = reflect.TypeOf([]byte(nil))
|
||||
valuerType = reflect.TypeOf((*driver.Valuer)(nil)).Elem()
|
||||
)
|
||||
|
||||
// EnsureString ensures the given value is a string.
|
||||
// If the value is a byte slice, it will be typecast into a string.
|
||||
// An error is returned otherwise.
|
||||
func EnsureString(value interface{}) (string, error) {
|
||||
v := reflect.ValueOf(value)
|
||||
if v.Kind() == reflect.String {
|
||||
return v.String(), nil
|
||||
}
|
||||
if v.Type() == bytesType {
|
||||
return string(v.Interface().([]byte)), nil
|
||||
}
|
||||
return "", errors.New("must be either a string or byte slice")
|
||||
}
|
||||
|
||||
// StringOrBytes typecasts a value into a string or byte slice.
|
||||
// Boolean flags are returned to indicate if the typecasting succeeds or not.
|
||||
func StringOrBytes(value interface{}) (isString bool, str string, isBytes bool, bs []byte) {
|
||||
v := reflect.ValueOf(value)
|
||||
if v.Kind() == reflect.String {
|
||||
str = v.String()
|
||||
isString = true
|
||||
} else if v.Kind() == reflect.Slice && v.Type() == bytesType {
|
||||
bs = v.Interface().([]byte)
|
||||
isBytes = true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// LengthOfValue returns the length of a value that is a string, slice, map, or array.
|
||||
// An error is returned for all other types.
|
||||
func LengthOfValue(value interface{}) (int, error) {
|
||||
v := reflect.ValueOf(value)
|
||||
switch v.Kind() {
|
||||
case reflect.String, reflect.Slice, reflect.Map, reflect.Array:
|
||||
return v.Len(), nil
|
||||
}
|
||||
return 0, fmt.Errorf("cannot get the length of %v", v.Kind())
|
||||
}
|
||||
|
||||
// ToInt converts the given value to an int64.
|
||||
// An error is returned for all incompatible types.
|
||||
func ToInt(value interface{}) (int64, error) {
|
||||
v := reflect.ValueOf(value)
|
||||
switch v.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return v.Int(), nil
|
||||
}
|
||||
return 0, fmt.Errorf("cannot convert %v to int64", v.Kind())
|
||||
}
|
||||
|
||||
// ToUint converts the given value to an uint64.
|
||||
// An error is returned for all incompatible types.
|
||||
func ToUint(value interface{}) (uint64, error) {
|
||||
v := reflect.ValueOf(value)
|
||||
switch v.Kind() {
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
return v.Uint(), nil
|
||||
}
|
||||
return 0, fmt.Errorf("cannot convert %v to uint64", v.Kind())
|
||||
}
|
||||
|
||||
// ToFloat converts the given value to a float64.
|
||||
// An error is returned for all incompatible types.
|
||||
func ToFloat(value interface{}) (float64, error) {
|
||||
v := reflect.ValueOf(value)
|
||||
switch v.Kind() {
|
||||
case reflect.Float32, reflect.Float64:
|
||||
return v.Float(), nil
|
||||
}
|
||||
return 0, fmt.Errorf("cannot convert %v to float64", v.Kind())
|
||||
}
|
||||
|
||||
// IsEmpty checks if a value is empty or not.
|
||||
// A value is considered empty if
|
||||
// - integer, float: zero
|
||||
// - bool: false
|
||||
// - string, array: len() == 0
|
||||
// - slice, map: nil or len() == 0
|
||||
// - interface, pointer: nil or the referenced value is empty
|
||||
func IsEmpty(value interface{}) bool {
|
||||
v := reflect.ValueOf(value)
|
||||
switch v.Kind() {
|
||||
case reflect.String, reflect.Array, reflect.Map, reflect.Slice:
|
||||
return v.Len() == 0
|
||||
case reflect.Bool:
|
||||
return !v.Bool()
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return v.Int() == 0
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
return v.Uint() == 0
|
||||
case reflect.Float32, reflect.Float64:
|
||||
return v.Float() == 0
|
||||
case reflect.Invalid:
|
||||
return true
|
||||
case reflect.Interface, reflect.Ptr:
|
||||
if v.IsNil() {
|
||||
return true
|
||||
}
|
||||
return IsEmpty(v.Elem().Interface())
|
||||
case reflect.Struct:
|
||||
v, ok := value.(time.Time)
|
||||
if ok && v.IsZero() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// Indirect returns the value that the given interface or pointer references to.
|
||||
// If the value implements driver.Valuer, it will deal with the value returned by
|
||||
// the Value() method instead. A boolean value is also returned to indicate if
|
||||
// the value is nil or not (only applicable to interface, pointer, map, and slice).
|
||||
// If the value is neither an interface nor a pointer, it will be returned back.
|
||||
func Indirect(value interface{}) (interface{}, bool) {
|
||||
rv := reflect.ValueOf(value)
|
||||
kind := rv.Kind()
|
||||
switch kind {
|
||||
case reflect.Invalid:
|
||||
return nil, true
|
||||
case reflect.Ptr, reflect.Interface:
|
||||
if rv.IsNil() {
|
||||
return nil, true
|
||||
}
|
||||
return Indirect(rv.Elem().Interface())
|
||||
case reflect.Slice, reflect.Map, reflect.Func, reflect.Chan:
|
||||
if rv.IsNil() {
|
||||
return nil, true
|
||||
}
|
||||
}
|
||||
|
||||
if rv.Type().Implements(valuerType) {
|
||||
return indirectValuer(value.(driver.Valuer))
|
||||
}
|
||||
|
||||
return value, false
|
||||
}
|
||||
|
||||
func indirectValuer(valuer driver.Valuer) (interface{}, bool) {
|
||||
if value, err := valuer.Value(); value != nil && err == nil {
|
||||
return Indirect(value)
|
||||
}
|
||||
return nil, true
|
||||
}
|
133
vendor/github.com/go-ozzo/ozzo-validation/validation.go
generated
vendored
133
vendor/github.com/go-ozzo/ozzo-validation/validation.go
generated
vendored
@ -1,133 +0,0 @@
|
||||
// Copyright 2016 Qiang Xue. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package validation provides configurable and extensible rules for validating data of various types.
|
||||
package validation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type (
|
||||
// Validatable is the interface indicating the type implementing it supports data validation.
|
||||
Validatable interface {
|
||||
// Validate validates the data and returns an error if validation fails.
|
||||
Validate() error
|
||||
}
|
||||
|
||||
// Rule represents a validation rule.
|
||||
Rule interface {
|
||||
// Validate validates a value and returns a value if validation fails.
|
||||
Validate(value interface{}) error
|
||||
}
|
||||
|
||||
// RuleFunc represents a validator function.
|
||||
// You may wrap it as a Rule by calling By().
|
||||
RuleFunc func(value interface{}) error
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrorTag is the struct tag name used to customize the error field name for a struct field.
|
||||
ErrorTag = "json"
|
||||
|
||||
// Skip is a special validation rule that indicates all rules following it should be skipped.
|
||||
Skip = &skipRule{}
|
||||
|
||||
validatableType = reflect.TypeOf((*Validatable)(nil)).Elem()
|
||||
)
|
||||
|
||||
// Validate validates the given value and returns the validation error, if any.
|
||||
//
|
||||
// Validate performs validation using the following steps:
|
||||
// - validate the value against the rules passed in as parameters
|
||||
// - if the value is a map and the map values implement `Validatable`, call `Validate` of every map value
|
||||
// - if the value is a slice or array whose values implement `Validatable`, call `Validate` of every element
|
||||
func Validate(value interface{}, rules ...Rule) error {
|
||||
for _, rule := range rules {
|
||||
if _, ok := rule.(*skipRule); ok {
|
||||
return nil
|
||||
}
|
||||
if err := rule.Validate(value); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
rv := reflect.ValueOf(value)
|
||||
if (rv.Kind() == reflect.Ptr || rv.Kind() == reflect.Interface) && rv.IsNil() {
|
||||
return nil
|
||||
}
|
||||
|
||||
if v, ok := value.(Validatable); ok {
|
||||
return v.Validate()
|
||||
}
|
||||
|
||||
switch rv.Kind() {
|
||||
case reflect.Map:
|
||||
if rv.Type().Elem().Implements(validatableType) {
|
||||
return validateMap(rv)
|
||||
}
|
||||
case reflect.Slice, reflect.Array:
|
||||
if rv.Type().Elem().Implements(validatableType) {
|
||||
return validateSlice(rv)
|
||||
}
|
||||
case reflect.Ptr, reflect.Interface:
|
||||
return Validate(rv.Elem().Interface())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// validateMap validates a map of validatable elements
|
||||
func validateMap(rv reflect.Value) error {
|
||||
errs := Errors{}
|
||||
for _, key := range rv.MapKeys() {
|
||||
if mv := rv.MapIndex(key).Interface(); mv != nil {
|
||||
if err := mv.(Validatable).Validate(); err != nil {
|
||||
errs[fmt.Sprintf("%v", key.Interface())] = err
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(errs) > 0 {
|
||||
return errs
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// validateMap validates a slice/array of validatable elements
|
||||
func validateSlice(rv reflect.Value) error {
|
||||
errs := Errors{}
|
||||
l := rv.Len()
|
||||
for i := 0; i < l; i++ {
|
||||
if ev := rv.Index(i).Interface(); ev != nil {
|
||||
if err := ev.(Validatable).Validate(); err != nil {
|
||||
errs[strconv.Itoa(i)] = err
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(errs) > 0 {
|
||||
return errs
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type skipRule struct{}
|
||||
|
||||
func (r *skipRule) Validate(interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type inlineRule struct {
|
||||
f RuleFunc
|
||||
}
|
||||
|
||||
func (r *inlineRule) Validate(value interface{}) error {
|
||||
return r.f(value)
|
||||
}
|
||||
|
||||
// By wraps a RuleFunc into a Rule.
|
||||
func By(f RuleFunc) Rule {
|
||||
return &inlineRule{f}
|
||||
}
|
9
vendor/github.com/heketi/heketi/AUTHORS
generated
vendored
9
vendor/github.com/heketi/heketi/AUTHORS
generated
vendored
@ -1,9 +0,0 @@
|
||||
lpabon@redhat.com
|
||||
campbellalex11@gmail.com
|
||||
sid@sidcarter.com
|
||||
hchiramm@redhat.com
|
||||
mliyazud@redhat.com
|
||||
nerawat@redhat.com
|
||||
obnox@redhat.com
|
||||
obnox@samba.org
|
||||
lpabon@gmail.com
|
339
vendor/github.com/heketi/heketi/COPYING-GPLV2
generated
vendored
339
vendor/github.com/heketi/heketi/COPYING-GPLV2
generated
vendored
@ -1,339 +0,0 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
165
vendor/github.com/heketi/heketi/COPYING-LGPLV3
generated
vendored
165
vendor/github.com/heketi/heketi/COPYING-LGPLV3
generated
vendored
@ -1,165 +0,0 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
7
vendor/github.com/heketi/heketi/LICENSE
generated
vendored
7
vendor/github.com/heketi/heketi/LICENSE
generated
vendored
@ -1,7 +0,0 @@
|
||||
Heketi code is released under various licenses:
|
||||
|
||||
The REST API client code (in go and python) is released
|
||||
under a dual license of Apache 2.0 or LGPLv3+.
|
||||
|
||||
The other parts of heketi (server, cli, tests, ...) are released
|
||||
under a dual license of LGPLv3+ or GPLv2.
|
201
vendor/github.com/heketi/heketi/LICENSE-APACHE2
generated
vendored
201
vendor/github.com/heketi/heketi/LICENSE-APACHE2
generated
vendored
@ -1,201 +0,0 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
78
vendor/github.com/heketi/heketi/client/api/go-client/admin.go
generated
vendored
78
vendor/github.com/heketi/heketi/client/api/go-client/admin.go
generated
vendored
@ -1,78 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2018 The heketi Authors
|
||||
//
|
||||
// This file is licensed to you under your choice of the GNU Lesser
|
||||
// General Public License, version 3 or any later version (LGPLv3 or
|
||||
// later), as published by the Free Software Foundation,
|
||||
// or under the Apache License, Version 2.0 <LICENSE-APACHE2 or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0>.
|
||||
//
|
||||
// You may not use this file except in compliance with those terms.
|
||||
//
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/heketi/heketi/pkg/glusterfs/api"
|
||||
"github.com/heketi/heketi/pkg/utils"
|
||||
)
|
||||
|
||||
func (c *Client) AdminStatusGet() (*api.AdminStatus, error) {
|
||||
req, err := http.NewRequest("GET", c.host+"/admin", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var as api.AdminStatus
|
||||
err = utils.GetJsonFromResponse(r, &as)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &as, nil
|
||||
}
|
||||
|
||||
func (c *Client) AdminStatusSet(request *api.AdminStatus) error {
|
||||
// Marshal request to JSON
|
||||
buffer, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", c.host+"/admin", bytes.NewBuffer(buffer))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.StatusCode == http.StatusOK || r.StatusCode == http.StatusNoContent {
|
||||
return nil
|
||||
}
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
49
vendor/github.com/heketi/heketi/client/api/go-client/backup.go
generated
vendored
49
vendor/github.com/heketi/heketi/client/api/go-client/backup.go
generated
vendored
@ -1,49 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2016 The heketi Authors
|
||||
//
|
||||
// This file is licensed to you under your choice of the GNU Lesser
|
||||
// General Public License, version 3 or any later version (LGPLv3 or
|
||||
// later), as published by the Free Software Foundation,
|
||||
// or under the Apache License, Version 2.0 <LICENSE-APACHE2 or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0>.
|
||||
//
|
||||
// You may not use this file except in compliance with those terms.
|
||||
//
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/heketi/heketi/pkg/utils"
|
||||
)
|
||||
|
||||
func (c *Client) BackupDb(w io.Writer) error {
|
||||
// Create a request
|
||||
req, err := http.NewRequest("GET", c.host+"/backup/db", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Read data from response
|
||||
_, err = io.Copy(w, r.Body)
|
||||
|
||||
return err
|
||||
}
|
212
vendor/github.com/heketi/heketi/client/api/go-client/block_volume.go
generated
vendored
212
vendor/github.com/heketi/heketi/client/api/go-client/block_volume.go
generated
vendored
@ -1,212 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2015 The heketi Authors
|
||||
//
|
||||
// This file is licensed to you under your choice of the GNU Lesser
|
||||
// General Public License, version 3 or any later version (LGPLv3 or
|
||||
// later), as published by the Free Software Foundation,
|
||||
// or under the Apache License, Version 2.0 <LICENSE-APACHE2 or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0>.
|
||||
//
|
||||
// You may not use this file except in compliance with those terms.
|
||||
//
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/heketi/heketi/pkg/glusterfs/api"
|
||||
"github.com/heketi/heketi/pkg/utils"
|
||||
)
|
||||
|
||||
func (c *Client) BlockVolumeCreate(request *api.BlockVolumeCreateRequest) (
|
||||
*api.BlockVolumeInfoResponse, error) {
|
||||
|
||||
buffer, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST",
|
||||
c.host+"/blockvolumes",
|
||||
bytes.NewBuffer(buffer))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusAccepted {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
r, err = c.pollResponse(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
var blockvolume api.BlockVolumeInfoResponse
|
||||
err = utils.GetJsonFromResponse(r, &blockvolume)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &blockvolume, nil
|
||||
|
||||
}
|
||||
|
||||
func (c *Client) BlockVolumeList() (*api.BlockVolumeListResponse, error) {
|
||||
req, err := http.NewRequest("GET", c.host+"/blockvolumes", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
var blockvolumes api.BlockVolumeListResponse
|
||||
err = utils.GetJsonFromResponse(r, &blockvolumes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &blockvolumes, nil
|
||||
}
|
||||
|
||||
func (c *Client) BlockVolumeInfo(id string) (*api.BlockVolumeInfoResponse, error) {
|
||||
req, err := http.NewRequest("GET", c.host+"/blockvolumes/"+id, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
var blockvolume api.BlockVolumeInfoResponse
|
||||
err = utils.GetJsonFromResponse(r, &blockvolume)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &blockvolume, nil
|
||||
}
|
||||
|
||||
func (c *Client) BlockVolumeDelete(id string) error {
|
||||
req, err := http.NewRequest("DELETE", c.host+"/blockvolumes/"+id, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusAccepted {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
r, err = c.pollResponse(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.StatusCode != http.StatusNoContent {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) BlockVolumeExpand(id string, request *api.BlockVolumeExpandRequest) (
|
||||
*api.BlockVolumeInfoResponse, error) {
|
||||
|
||||
// Marshal request to JSON
|
||||
buffer, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create a request
|
||||
req, err := http.NewRequest("POST",
|
||||
c.host+"/blockvolumes/"+id+"/expand",
|
||||
bytes.NewBuffer(buffer))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusAccepted {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Wait for response
|
||||
r, err = c.pollResponse(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Read JSON response
|
||||
var blockvolume api.BlockVolumeInfoResponse
|
||||
err = utils.GetJsonFromResponse(r, &blockvolume)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &blockvolume, nil
|
||||
}
|
72
vendor/github.com/heketi/heketi/client/api/go-client/brick.go
generated
vendored
72
vendor/github.com/heketi/heketi/client/api/go-client/brick.go
generated
vendored
@ -1,72 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2019 The heketi Authors
|
||||
//
|
||||
// This file is licensed to you under your choice of the GNU Lesser
|
||||
// General Public License, version 3 or any later version (LGPLv3 or
|
||||
// later), as published by the Free Software Foundation,
|
||||
// or under the Apache License, Version 2.0 <LICENSE-APACHE2 or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0>.
|
||||
//
|
||||
// You may not use this file except in compliance with those terms.
|
||||
//
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/heketi/heketi/pkg/glusterfs/api"
|
||||
"github.com/heketi/heketi/pkg/utils"
|
||||
)
|
||||
|
||||
// BrickEvict requests that Heketi evict the given brick from the
|
||||
// underlying gluster volume, automatically replacing it with a new brick.
|
||||
//
|
||||
// NOTE: options is currently empty but reserved for future extensions
|
||||
// to the api.
|
||||
func (c *Client) BrickEvict(id string, request *api.BrickEvictOptions) error {
|
||||
var buf io.Reader
|
||||
if request != nil {
|
||||
b, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
buf = bytes.NewBuffer(b)
|
||||
}
|
||||
|
||||
// Create a request
|
||||
req, err := http.NewRequest("POST", c.host+"/bricks/to-evict/"+id, buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusAccepted {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Wait for response
|
||||
r, err = c.pollResponse(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.StatusCode != http.StatusNoContent {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
392
vendor/github.com/heketi/heketi/client/api/go-client/client.go
generated
vendored
392
vendor/github.com/heketi/heketi/client/api/go-client/client.go
generated
vendored
@ -1,392 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2015 The heketi Authors
|
||||
//
|
||||
// This file is licensed to you under your choice of the GNU Lesser
|
||||
// General Public License, version 3 or any later version (LGPLv3 or
|
||||
// later), as published by the Free Software Foundation,
|
||||
// or under the Apache License, Version 2.0 <LICENSE-APACHE2 or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0>.
|
||||
//
|
||||
// You may not use this file except in compliance with those terms.
|
||||
//
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
jwt "github.com/form3tech-oss/jwt-go"
|
||||
"github.com/heketi/heketi/pkg/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
MAX_CONCURRENT_REQUESTS = 32
|
||||
RETRY_COUNT = 6
|
||||
|
||||
// default delay values
|
||||
MIN_DELAY = 10
|
||||
MAX_DELAY = 30
|
||||
POLL_DELAY = 400 // milliseconds
|
||||
)
|
||||
|
||||
type ClientTLSOptions struct {
|
||||
// directly borrow the field names from crypto/tls
|
||||
InsecureSkipVerify bool
|
||||
// one or more cert file paths (best for self-signed certs)
|
||||
VerifyCerts []string
|
||||
}
|
||||
|
||||
// Client configuration options
|
||||
type ClientOptions struct {
|
||||
RetryEnabled bool
|
||||
RetryCount int
|
||||
// control waits between retries (seconds)
|
||||
RetryMinDelay, RetryMaxDelay int
|
||||
// control wait time while polling for responses (milliseconds)
|
||||
PollDelay int
|
||||
}
|
||||
|
||||
// Client object
|
||||
type Client struct {
|
||||
host string
|
||||
key string
|
||||
user string
|
||||
throttle chan bool
|
||||
|
||||
// configuration for TLS support
|
||||
tlsClientConfig *tls.Config
|
||||
|
||||
// general behavioral options
|
||||
opts ClientOptions
|
||||
|
||||
// allow plugging in custom do wrappers
|
||||
do func(*http.Request) (*http.Response, error)
|
||||
|
||||
// allow plugging in custom http client fetcher
|
||||
getClient ClientFunc
|
||||
}
|
||||
|
||||
var defaultClientOptions = ClientOptions{
|
||||
RetryEnabled: true,
|
||||
RetryCount: RETRY_COUNT,
|
||||
RetryMinDelay: MIN_DELAY,
|
||||
RetryMaxDelay: MAX_DELAY,
|
||||
PollDelay: POLL_DELAY,
|
||||
}
|
||||
|
||||
// DefaultClientOptions returns a ClientOptions type with all the fields
|
||||
// initialized to the default values used internally by the new-client
|
||||
// functions.
|
||||
func DefaultClientOptions() ClientOptions {
|
||||
return defaultClientOptions
|
||||
}
|
||||
|
||||
// NewClient creates a new client to access a Heketi server
|
||||
func NewClient(host, user, key string) *Client {
|
||||
return NewClientWithOptions(host, user, key, defaultClientOptions)
|
||||
}
|
||||
|
||||
// NewClientWithOptions creates a new client to access a Heketi server
|
||||
// with a user specified suite of options.
|
||||
func NewClientWithOptions(host, user, key string, opts ClientOptions) *Client {
|
||||
c := &Client{}
|
||||
|
||||
c.key = key
|
||||
c.host = host
|
||||
c.user = user
|
||||
c.opts = opts
|
||||
// Maximum concurrent requests
|
||||
c.throttle = make(chan bool, MAX_CONCURRENT_REQUESTS)
|
||||
if opts.RetryEnabled {
|
||||
c.do = c.retryOperationDo
|
||||
} else {
|
||||
c.do = c.doBasic
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func NewClientTLS(host, user, key string, tlsOpts *ClientTLSOptions) (*Client, error) {
|
||||
c := NewClient(host, user, key)
|
||||
if err := c.SetTLSOptions(tlsOpts); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// Create a client to access a Heketi server without authentication enabled
|
||||
func NewClientNoAuth(host string) *Client {
|
||||
return NewClient(host, "", "")
|
||||
}
|
||||
|
||||
// SetTLSOptions configures an existing heketi client for
|
||||
// TLS support based on the ClientTLSOptions.
|
||||
func (c *Client) SetTLSOptions(o *ClientTLSOptions) error {
|
||||
if o == nil {
|
||||
c.tlsClientConfig = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
tlsConfig := &tls.Config{}
|
||||
tlsConfig.InsecureSkipVerify = o.InsecureSkipVerify
|
||||
if len(o.VerifyCerts) > 0 {
|
||||
tlsConfig.RootCAs = x509.NewCertPool()
|
||||
for _, path := range o.VerifyCerts {
|
||||
pem, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read cert file %v: %v",
|
||||
path, err)
|
||||
}
|
||||
if ok := tlsConfig.RootCAs.AppendCertsFromPEM(pem); !ok {
|
||||
return fmt.Errorf("failed to load PEM encoded cert from %s",
|
||||
path)
|
||||
}
|
||||
}
|
||||
}
|
||||
c.tlsClientConfig = tlsConfig
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) SetClientFunc(f ClientFunc) {
|
||||
c.getClient = f
|
||||
}
|
||||
|
||||
// Simple Hello test to check if the server is up
|
||||
func (c *Client) Hello() error {
|
||||
// Create request
|
||||
req, err := http.NewRequest("GET", c.host+"/hello", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Get info
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doBasic performs the core http transaction.
|
||||
// Make sure we do not run out of fds by throttling the requests
|
||||
func (c *Client) doBasic(req *http.Request) (*http.Response, error) {
|
||||
c.throttle <- true
|
||||
defer func() {
|
||||
<-c.throttle
|
||||
}()
|
||||
|
||||
getClient := c.getClient
|
||||
if getClient == nil {
|
||||
getClient = HeketiHttpClient
|
||||
}
|
||||
httpClient, err := getClient(c.tlsClientConfig, c.checkRedirect)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return httpClient.Do(req)
|
||||
}
|
||||
|
||||
// This function is called by the http package if it detects that it needs to
|
||||
// be redirected. This happens when the server returns a 303 HTTP Status.
|
||||
// Here we create a new token before it makes the next request.
|
||||
func (c *Client) checkRedirect(req *http.Request, via []*http.Request) error {
|
||||
return c.setToken(req)
|
||||
}
|
||||
|
||||
func (c *Client) pollResponse(r *http.Response) (*http.Response, error) {
|
||||
return c.waitForResponseWithTimer(
|
||||
r, time.Millisecond*time.Duration(c.opts.PollDelay))
|
||||
}
|
||||
|
||||
// Wait for the job to finish, waiting waitTime on every loop
|
||||
func (c *Client) waitForResponseWithTimer(r *http.Response,
|
||||
waitTime time.Duration) (*http.Response, error) {
|
||||
|
||||
// Get temp resource
|
||||
location, err := r.Location()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for {
|
||||
// Create request
|
||||
req, err := http.NewRequest("GET", location.String(), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Wait for response
|
||||
r, err = c.doBasic(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Check if the request is pending
|
||||
if r.Header.Get("X-Pending") == "true" {
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
if r != nil {
|
||||
//Read Response Body
|
||||
ioutil.ReadAll(r.Body)
|
||||
r.Body.Close()
|
||||
}
|
||||
time.Sleep(waitTime)
|
||||
} else {
|
||||
return r, nil
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Create JSON Web Token
|
||||
func (c *Client) setToken(r *http.Request) error {
|
||||
|
||||
// Create qsh hash
|
||||
qshstring := r.Method + "&" + r.URL.Path
|
||||
hash := sha256.New()
|
||||
hash.Write([]byte(qshstring))
|
||||
|
||||
// Create Token
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
|
||||
// Set issuer
|
||||
"iss": c.user,
|
||||
|
||||
// Set issued at time
|
||||
"iat": time.Now().Unix(),
|
||||
|
||||
// Set expiration
|
||||
"exp": time.Now().Add(time.Minute * 5).Unix(),
|
||||
|
||||
// Set qsh
|
||||
"qsh": hex.EncodeToString(hash.Sum(nil)),
|
||||
})
|
||||
|
||||
// Sign the token
|
||||
signedtoken, err := token.SignedString([]byte(c.key))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Save it in the header
|
||||
r.Header.Set("Authorization", "bearer "+signedtoken)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// retryOperationDo performs the http request and internally
|
||||
// handles http 429 codes up to the number of retries specified
|
||||
// by the Client.
|
||||
func (c *Client) retryOperationDo(req *http.Request) (*http.Response, error) {
|
||||
var (
|
||||
requestBody []byte
|
||||
err error
|
||||
)
|
||||
if req.Body != nil {
|
||||
requestBody, err = ioutil.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Send request
|
||||
var r *http.Response
|
||||
for i := 0; i <= c.opts.RetryCount; i++ {
|
||||
req.Body = ioutil.NopCloser(bytes.NewReader(requestBody))
|
||||
r, err = c.doBasic(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch r.StatusCode {
|
||||
case http.StatusTooManyRequests:
|
||||
if r != nil {
|
||||
//Read Response Body
|
||||
// I don't like discarding error here, but I cant
|
||||
// think of something better atm
|
||||
b, _ := ioutil.ReadAll(r.Body)
|
||||
r.Body.Close()
|
||||
r.Body = ioutil.NopCloser(bytes.NewReader(b))
|
||||
}
|
||||
//sleep before continue
|
||||
time.Sleep(c.opts.retryDelay(r))
|
||||
continue
|
||||
|
||||
default:
|
||||
return r, err
|
||||
|
||||
}
|
||||
}
|
||||
return r, err
|
||||
}
|
||||
|
||||
// retryDelay returns a duration for which a retry should wait
|
||||
// (after failure) before continuing.
|
||||
func (c *ClientOptions) retryDelay(r *http.Response) time.Duration {
|
||||
var (
|
||||
min = c.RetryMinDelay
|
||||
max = c.RetryMaxDelay
|
||||
)
|
||||
if ra := r.Header.Get("Retry-After"); ra != "" {
|
||||
// TODO: support http date
|
||||
if i, err := strconv.Atoi(ra); err == nil {
|
||||
s := rand.Intn(min) + i
|
||||
return time.Second * time.Duration(s)
|
||||
}
|
||||
}
|
||||
s := rand.Intn(max-min) + min
|
||||
return time.Second * time.Duration(s)
|
||||
}
|
||||
|
||||
// CheckRedirectFunc is an alias for the somewhat complex function signature
|
||||
// of the CheckRedirect function of the http.Client.
|
||||
type CheckRedirectFunc func(*http.Request, []*http.Request) error
|
||||
|
||||
// ClientFunc is an alias for the function signature needed to create custom
|
||||
// http clients.
|
||||
type ClientFunc func(*tls.Config, CheckRedirectFunc) (HttpPerformer, error)
|
||||
|
||||
// HttpPerformer is an interface that the heketi api client needs from the http
|
||||
// client.
|
||||
type HttpPerformer interface {
|
||||
Do(req *http.Request) (*http.Response, error)
|
||||
}
|
||||
|
||||
// HeketiHttpClient constructs a new http client for use by the heketi
|
||||
// api client, using the traditional heketi approach.
|
||||
func HeketiHttpClient(tlsConfig *tls.Config, checkRedirect CheckRedirectFunc) (HttpPerformer, error) {
|
||||
httpClient := &http.Client{}
|
||||
if tlsConfig != nil {
|
||||
httpClient.Transport = &http.Transport{
|
||||
TLSClientConfig: tlsConfig,
|
||||
}
|
||||
}
|
||||
httpClient.CheckRedirect = checkRedirect
|
||||
return httpClient, nil
|
||||
}
|
192
vendor/github.com/heketi/heketi/client/api/go-client/cluster.go
generated
vendored
192
vendor/github.com/heketi/heketi/client/api/go-client/cluster.go
generated
vendored
@ -1,192 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2015 The heketi Authors
|
||||
//
|
||||
// This file is licensed to you under your choice of the GNU Lesser
|
||||
// General Public License, version 3 or any later version (LGPLv3 or
|
||||
// later), as published by the Free Software Foundation,
|
||||
// or under the Apache License, Version 2.0 <LICENSE-APACHE2 or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0>.
|
||||
//
|
||||
// You may not use this file except in compliance with those terms.
|
||||
//
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/heketi/heketi/pkg/glusterfs/api"
|
||||
"github.com/heketi/heketi/pkg/utils"
|
||||
)
|
||||
|
||||
func (c *Client) ClusterCreate(request *api.ClusterCreateRequest) (*api.ClusterInfoResponse, error) {
|
||||
|
||||
buffer, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create a request
|
||||
req, err := http.NewRequest("POST", c.host+"/clusters",
|
||||
bytes.NewBuffer(buffer))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusCreated {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Read JSON response
|
||||
var cluster api.ClusterInfoResponse
|
||||
err = utils.GetJsonFromResponse(r, &cluster)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &cluster, nil
|
||||
}
|
||||
|
||||
func (c *Client) ClusterSetFlags(id string, request *api.ClusterSetFlagsRequest) error {
|
||||
|
||||
buffer, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create a request
|
||||
req, err := http.NewRequest("POST", c.host+"/clusters/"+id+"/flags",
|
||||
bytes.NewBuffer(buffer))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) ClusterInfo(id string) (*api.ClusterInfoResponse, error) {
|
||||
|
||||
// Create request
|
||||
req, err := http.NewRequest("GET", c.host+"/clusters/"+id, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Get info
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Read JSON response
|
||||
var cluster api.ClusterInfoResponse
|
||||
err = utils.GetJsonFromResponse(r, &cluster)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &cluster, nil
|
||||
}
|
||||
|
||||
func (c *Client) ClusterList() (*api.ClusterListResponse, error) {
|
||||
|
||||
// Create request
|
||||
req, err := http.NewRequest("GET", c.host+"/clusters", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Get info
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Read JSON response
|
||||
var clusters api.ClusterListResponse
|
||||
err = utils.GetJsonFromResponse(r, &clusters)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &clusters, nil
|
||||
}
|
||||
|
||||
func (c *Client) ClusterDelete(id string) error {
|
||||
|
||||
// Create DELETE request
|
||||
req, err := http.NewRequest("DELETE", c.host+"/clusters/"+id, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
84
vendor/github.com/heketi/heketi/client/api/go-client/db.go
generated
vendored
84
vendor/github.com/heketi/heketi/client/api/go-client/db.go
generated
vendored
@ -1,84 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2018 The heketi Authors
|
||||
//
|
||||
// This file is licensed to you under your choice of the GNU Lesser
|
||||
// General Public License, version 3 or any later version (LGPLv3 or
|
||||
// later), as published by the Free Software Foundation,
|
||||
// or under the Apache License, Version 2.0 <LICENSE-APACHE2 or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0>.
|
||||
//
|
||||
// You may not use this file except in compliance with those terms.
|
||||
//
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/heketi/heketi/pkg/utils"
|
||||
)
|
||||
|
||||
// DbDump provides a JSON representation of current state of DB
|
||||
func (c *Client) DbDump() (string, error) {
|
||||
req, err := http.NewRequest("GET", c.host+"/db/dump", nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return "", utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
respBytes, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
respJSON := string(respBytes)
|
||||
return respJSON, nil
|
||||
}
|
||||
|
||||
// DbCheck provides a JSON summary of the DB check operation
|
||||
func (c *Client) DbCheck() (string, error) {
|
||||
req, err := http.NewRequest("GET", c.host+"/db/check", nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return "", utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
respBytes, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
respJSON := string(respBytes)
|
||||
return respJSON, nil
|
||||
}
|
263
vendor/github.com/heketi/heketi/client/api/go-client/device.go
generated
vendored
263
vendor/github.com/heketi/heketi/client/api/go-client/device.go
generated
vendored
@ -1,263 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2015 The heketi Authors
|
||||
//
|
||||
// This file is licensed to you under your choice of the GNU Lesser
|
||||
// General Public License, version 3 or any later version (LGPLv3 or
|
||||
// later), as published by the Free Software Foundation,
|
||||
// or under the Apache License, Version 2.0 <LICENSE-APACHE2 or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0>.
|
||||
//
|
||||
// You may not use this file except in compliance with those terms.
|
||||
//
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/heketi/heketi/pkg/glusterfs/api"
|
||||
"github.com/heketi/heketi/pkg/utils"
|
||||
)
|
||||
|
||||
func (c *Client) DeviceAdd(request *api.DeviceAddRequest) error {
|
||||
// Marshal request to JSON
|
||||
buffer, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create a request
|
||||
req, err := http.NewRequest("POST", c.host+"/devices", bytes.NewBuffer(buffer))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusAccepted {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Wait for response
|
||||
r, err = c.pollResponse(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.StatusCode != http.StatusNoContent {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) DeviceInfo(id string) (*api.DeviceInfoResponse, error) {
|
||||
|
||||
// Create request
|
||||
req, err := http.NewRequest("GET", c.host+"/devices/"+id, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Get info
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Read JSON response
|
||||
var device api.DeviceInfoResponse
|
||||
err = utils.GetJsonFromResponse(r, &device)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &device, nil
|
||||
}
|
||||
|
||||
func (c *Client) DeviceDelete(id string) error {
|
||||
return c.DeviceDeleteWithOptions(id, nil)
|
||||
}
|
||||
|
||||
func (c *Client) DeviceDeleteWithOptions(
|
||||
id string, request *api.DeviceDeleteOptions) error {
|
||||
|
||||
var buf io.Reader
|
||||
if request != nil {
|
||||
b, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
buf = bytes.NewBuffer(b)
|
||||
}
|
||||
|
||||
// Create a request
|
||||
req, err := http.NewRequest("DELETE", c.host+"/devices/"+id, buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusAccepted {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Wait for response
|
||||
r, err = c.pollResponse(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.StatusCode != http.StatusNoContent {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) DeviceState(id string,
|
||||
request *api.StateRequest) error {
|
||||
|
||||
// Marshal request to JSON
|
||||
buffer, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create a request
|
||||
req, err := http.NewRequest("POST",
|
||||
c.host+"/devices/"+id+"/state",
|
||||
bytes.NewBuffer(buffer))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Get info
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusAccepted {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Wait for response
|
||||
r, err = c.pollResponse(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.StatusCode != http.StatusNoContent {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) DeviceResync(id string) error {
|
||||
|
||||
// Create a request
|
||||
req, err := http.NewRequest("GET", c.host+"/devices/"+id+"/resync", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusAccepted {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Wait for response
|
||||
r, err = c.pollResponse(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.StatusCode != http.StatusNoContent {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) DeviceSetTags(id string, request *api.TagsChangeRequest) error {
|
||||
buffer, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST",
|
||||
c.host+"/devices/"+id+"/tags",
|
||||
bytes.NewBuffer(buffer))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Get info
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
return nil
|
||||
}
|
78
vendor/github.com/heketi/heketi/client/api/go-client/logging.go
generated
vendored
78
vendor/github.com/heketi/heketi/client/api/go-client/logging.go
generated
vendored
@ -1,78 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2018 The heketi Authors
|
||||
//
|
||||
// This file is licensed to you under your choice of the GNU Lesser
|
||||
// General Public License, version 3 or any later version (LGPLv3 or
|
||||
// later), as published by the Free Software Foundation,
|
||||
// or under the Apache License, Version 2.0 <LICENSE-APACHE2 or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0>.
|
||||
//
|
||||
// You may not use this file except in compliance with those terms.
|
||||
//
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/heketi/heketi/pkg/glusterfs/api"
|
||||
"github.com/heketi/heketi/pkg/utils"
|
||||
)
|
||||
|
||||
func (c *Client) LogLevelGet() (*api.LogLevelInfo, error) {
|
||||
req, err := http.NewRequest("GET", c.host+"/internal/logging", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var lli api.LogLevelInfo
|
||||
err = utils.GetJsonFromResponse(r, &lli)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &lli, nil
|
||||
}
|
||||
|
||||
func (c *Client) LogLevelSet(request *api.LogLevelInfo) error {
|
||||
// Marshal request to JSON
|
||||
buffer, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", c.host+"/internal/logging", bytes.NewBuffer(buffer))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
return nil
|
||||
}
|
218
vendor/github.com/heketi/heketi/client/api/go-client/node.go
generated
vendored
218
vendor/github.com/heketi/heketi/client/api/go-client/node.go
generated
vendored
@ -1,218 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2015 The heketi Authors
|
||||
//
|
||||
// This file is licensed to you under your choice of the GNU Lesser
|
||||
// General Public License, version 3 or any later version (LGPLv3 or
|
||||
// later), as published by the Free Software Foundation,
|
||||
// or under the Apache License, Version 2.0 <LICENSE-APACHE2 or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0>.
|
||||
//
|
||||
// You may not use this file except in compliance with those terms.
|
||||
//
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/heketi/heketi/pkg/glusterfs/api"
|
||||
"github.com/heketi/heketi/pkg/utils"
|
||||
)
|
||||
|
||||
func (c *Client) NodeAdd(request *api.NodeAddRequest) (*api.NodeInfoResponse, error) {
|
||||
|
||||
// Marshal request to JSON
|
||||
buffer, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create a request
|
||||
req, err := http.NewRequest("POST", c.host+"/nodes", bytes.NewBuffer(buffer))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusAccepted {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Wait for response
|
||||
r, err = c.pollResponse(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Read JSON response
|
||||
var node api.NodeInfoResponse
|
||||
err = utils.GetJsonFromResponse(r, &node)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &node, nil
|
||||
}
|
||||
|
||||
func (c *Client) NodeInfo(id string) (*api.NodeInfoResponse, error) {
|
||||
|
||||
// Create request
|
||||
req, err := http.NewRequest("GET", c.host+"/nodes/"+id, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Get info
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Read JSON response
|
||||
var node api.NodeInfoResponse
|
||||
err = utils.GetJsonFromResponse(r, &node)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &node, nil
|
||||
}
|
||||
|
||||
func (c *Client) NodeDelete(id string) error {
|
||||
|
||||
// Create a request
|
||||
req, err := http.NewRequest("DELETE", c.host+"/nodes/"+id, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusAccepted {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Wait for response
|
||||
r, err = c.pollResponse(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.StatusCode != http.StatusNoContent {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) NodeState(id string, request *api.StateRequest) error {
|
||||
// Marshal request to JSON
|
||||
buffer, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create a request
|
||||
req, err := http.NewRequest("POST",
|
||||
c.host+"/nodes/"+id+"/state",
|
||||
bytes.NewBuffer(buffer))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Get info
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusAccepted {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Wait for response
|
||||
r, err = c.pollResponse(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.StatusCode != http.StatusNoContent {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) NodeSetTags(id string, request *api.TagsChangeRequest) error {
|
||||
buffer, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST",
|
||||
c.host+"/nodes/"+id+"/tags",
|
||||
bytes.NewBuffer(buffer))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Get info
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
return nil
|
||||
}
|
161
vendor/github.com/heketi/heketi/client/api/go-client/operations.go
generated
vendored
161
vendor/github.com/heketi/heketi/client/api/go-client/operations.go
generated
vendored
@ -1,161 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2018 The heketi Authors
|
||||
//
|
||||
// This file is licensed to you under your choice of the GNU Lesser
|
||||
// General Public License, version 3 or any later version (LGPLv3 or
|
||||
// later), as published by the Free Software Foundation,
|
||||
// or under the Apache License, Version 2.0 <LICENSE-APACHE2 or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0>.
|
||||
//
|
||||
// You may not use this file except in compliance with those terms.
|
||||
//
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/heketi/heketi/pkg/glusterfs/api"
|
||||
"github.com/heketi/heketi/pkg/utils"
|
||||
)
|
||||
|
||||
func (c *Client) OperationsInfo() (*api.OperationsInfo, error) {
|
||||
req, err := http.NewRequest("GET", c.host+"/operations", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
var oi api.OperationsInfo
|
||||
err = utils.GetJsonFromResponse(r, &oi)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &oi, nil
|
||||
}
|
||||
|
||||
func (c *Client) PendingOperationList() (*api.PendingOperationListResponse, error) {
|
||||
req, err := http.NewRequest("GET", c.host+"/operations/pending", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
var ol api.PendingOperationListResponse
|
||||
err = utils.GetJsonFromResponse(r, &ol)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ol, nil
|
||||
}
|
||||
|
||||
func (c *Client) PendingOperationDetails(
|
||||
id string) (*api.PendingOperationDetails, error) {
|
||||
|
||||
req, err := http.NewRequest("GET", c.host+"/operations/pending/"+id, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
var pd api.PendingOperationDetails
|
||||
err = utils.GetJsonFromResponse(r, &pd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pd, nil
|
||||
}
|
||||
|
||||
func (c *Client) PendingOperationCleanUp(
|
||||
request *api.PendingOperationsCleanRequest) error {
|
||||
|
||||
buffer, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST",
|
||||
c.host+"/operations/pending/cleanup",
|
||||
bytes.NewBuffer(buffer))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
switch r.StatusCode {
|
||||
case http.StatusAccepted: // expected
|
||||
case http.StatusOK:
|
||||
return nil
|
||||
default:
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// NOTE: I (jjm) wanted this to truly async at first. But in
|
||||
// order to not deviate from the current model too much
|
||||
// AND that the rest async framework in heketi needs to be
|
||||
// polled in order to remove things from its map, the traditional
|
||||
// poll server after request behavior is retained here.
|
||||
r, err = c.pollResponse(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.StatusCode != http.StatusNoContent {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
return nil
|
||||
}
|
52
vendor/github.com/heketi/heketi/client/api/go-client/state.go
generated
vendored
52
vendor/github.com/heketi/heketi/client/api/go-client/state.go
generated
vendored
@ -1,52 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2018 The heketi Authors
|
||||
//
|
||||
// This file is licensed to you under your choice of the GNU Lesser
|
||||
// General Public License, version 3 or any later version (LGPLv3 or
|
||||
// later), as published by the Free Software Foundation,
|
||||
// or under the Apache License, Version 2.0 <LICENSE-APACHE2 or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0>.
|
||||
//
|
||||
// You may not use this file except in compliance with those terms.
|
||||
//
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/heketi/heketi/pkg/utils"
|
||||
)
|
||||
|
||||
// StateExamineGluster provides a comparision of DB and Gluster
|
||||
func (c *Client) StateExamineGluster() (string, error) {
|
||||
req, err := http.NewRequest("GET", c.host+"/internal/state/examine/gluster", nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return "", utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
respBytes, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
respJSON := string(respBytes)
|
||||
return respJSON, nil
|
||||
}
|
66
vendor/github.com/heketi/heketi/client/api/go-client/topology.go
generated
vendored
66
vendor/github.com/heketi/heketi/client/api/go-client/topology.go
generated
vendored
@ -1,66 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2015 The heketi Authors
|
||||
//
|
||||
// This file is licensed to you under your choice of the GNU Lesser
|
||||
// General Public License, version 3 or any later version (LGPLv3 or
|
||||
// later), as published by the Free Software Foundation,
|
||||
// or under the Apache License, Version 2.0 <LICENSE-APACHE2 or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0>.
|
||||
//
|
||||
// You may not use this file except in compliance with those terms.
|
||||
//
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"github.com/heketi/heketi/pkg/glusterfs/api"
|
||||
)
|
||||
|
||||
func (c *Client) TopologyInfo() (*api.TopologyInfoResponse, error) {
|
||||
topo := &api.TopologyInfoResponse{
|
||||
ClusterList: make([]api.Cluster, 0),
|
||||
}
|
||||
clusterlist, err := c.ClusterList()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, cluster := range clusterlist.Clusters {
|
||||
clusteri, err := c.ClusterInfo(cluster)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cluster := api.Cluster{
|
||||
Id: clusteri.Id,
|
||||
Volumes: make([]api.VolumeInfoResponse, 0),
|
||||
Nodes: make([]api.NodeInfoResponse, 0),
|
||||
ClusterFlags: api.ClusterFlags{
|
||||
Block: clusteri.Block,
|
||||
File: clusteri.File,
|
||||
},
|
||||
}
|
||||
cluster.Id = clusteri.Id
|
||||
|
||||
// Iterate over the volume list in the cluster
|
||||
for _, volumes := range clusteri.Volumes {
|
||||
volumesi, err := c.VolumeInfo(volumes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if volumesi.Cluster == cluster.Id {
|
||||
cluster.Volumes = append(cluster.Volumes, *volumesi)
|
||||
}
|
||||
}
|
||||
|
||||
// Iterate over the nodes in the cluster
|
||||
for _, node := range clusteri.Nodes {
|
||||
nodei, err := c.NodeInfo(string(node))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cluster.Nodes = append(cluster.Nodes, *nodei)
|
||||
}
|
||||
topo.ClusterList = append(topo.ClusterList, cluster)
|
||||
}
|
||||
return topo, nil
|
||||
|
||||
}
|
337
vendor/github.com/heketi/heketi/client/api/go-client/volume.go
generated
vendored
337
vendor/github.com/heketi/heketi/client/api/go-client/volume.go
generated
vendored
@ -1,337 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2015 The heketi Authors
|
||||
//
|
||||
// This file is licensed to you under your choice of the GNU Lesser
|
||||
// General Public License, version 3 or any later version (LGPLv3 or
|
||||
// later), as published by the Free Software Foundation,
|
||||
// or under the Apache License, Version 2.0 <LICENSE-APACHE2 or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0>.
|
||||
//
|
||||
// You may not use this file except in compliance with those terms.
|
||||
//
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/heketi/heketi/pkg/glusterfs/api"
|
||||
"github.com/heketi/heketi/pkg/utils"
|
||||
)
|
||||
|
||||
func (c *Client) VolumeCreate(request *api.VolumeCreateRequest) (
|
||||
*api.VolumeInfoResponse, error) {
|
||||
|
||||
// Marshal request to JSON
|
||||
buffer, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create a request
|
||||
req, err := http.NewRequest("POST",
|
||||
c.host+"/volumes",
|
||||
bytes.NewBuffer(buffer))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusAccepted {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Wait for response
|
||||
r, err = c.pollResponse(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Read JSON response
|
||||
var volume api.VolumeInfoResponse
|
||||
err = utils.GetJsonFromResponse(r, &volume)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &volume, nil
|
||||
|
||||
}
|
||||
|
||||
func (c *Client) VolumeSetBlockRestriction(id string, request *api.VolumeBlockRestrictionRequest) (
|
||||
*api.VolumeInfoResponse, error) {
|
||||
|
||||
// Marshal request to JSON
|
||||
buffer, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create a request
|
||||
req, err := http.NewRequest("POST",
|
||||
c.host+"/volumes/"+id+"/block-restriction",
|
||||
bytes.NewBuffer(buffer))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusAccepted {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Wait for response
|
||||
r, err = c.pollResponse(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Read JSON response
|
||||
var volume api.VolumeInfoResponse
|
||||
err = utils.GetJsonFromResponse(r, &volume)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &volume, nil
|
||||
|
||||
}
|
||||
|
||||
func (c *Client) VolumeExpand(id string, request *api.VolumeExpandRequest) (
|
||||
*api.VolumeInfoResponse, error) {
|
||||
|
||||
// Marshal request to JSON
|
||||
buffer, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create a request
|
||||
req, err := http.NewRequest("POST",
|
||||
c.host+"/volumes/"+id+"/expand",
|
||||
bytes.NewBuffer(buffer))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusAccepted {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Wait for response
|
||||
r, err = c.pollResponse(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Read JSON response
|
||||
var volume api.VolumeInfoResponse
|
||||
err = utils.GetJsonFromResponse(r, &volume)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &volume, nil
|
||||
|
||||
}
|
||||
|
||||
func (c *Client) VolumeList() (*api.VolumeListResponse, error) {
|
||||
|
||||
// Create request
|
||||
req, err := http.NewRequest("GET", c.host+"/volumes", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Get info
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Read JSON response
|
||||
var volumes api.VolumeListResponse
|
||||
err = utils.GetJsonFromResponse(r, &volumes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &volumes, nil
|
||||
}
|
||||
|
||||
func (c *Client) VolumeInfo(id string) (*api.VolumeInfoResponse, error) {
|
||||
|
||||
// Create request
|
||||
req, err := http.NewRequest("GET", c.host+"/volumes/"+id, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Get info
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Read JSON response
|
||||
var volume api.VolumeInfoResponse
|
||||
err = utils.GetJsonFromResponse(r, &volume)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &volume, nil
|
||||
}
|
||||
|
||||
func (c *Client) VolumeDelete(id string) error {
|
||||
|
||||
// Create a request
|
||||
req, err := http.NewRequest("DELETE", c.host+"/volumes/"+id, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusAccepted {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Wait for response
|
||||
r, err = c.pollResponse(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r.StatusCode != http.StatusNoContent {
|
||||
return utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) VolumeClone(id string, request *api.VolumeCloneRequest) (*api.VolumeInfoResponse, error) {
|
||||
// Marshal request to JSON
|
||||
buffer, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create a request
|
||||
req, err := http.NewRequest("POST", c.host+"/volumes/"+id+"/clone", bytes.NewBuffer(buffer))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
// Set token
|
||||
err = c.setToken(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Send request
|
||||
r, err := c.do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != http.StatusAccepted {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Wait for response
|
||||
r, err = c.pollResponse(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.StatusCode != http.StatusOK {
|
||||
return nil, utils.GetErrorFromResponse(r)
|
||||
}
|
||||
|
||||
// Read JSON response
|
||||
var volume api.VolumeInfoResponse
|
||||
err = utils.GetJsonFromResponse(r, &volume)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &volume, nil
|
||||
}
|
728
vendor/github.com/heketi/heketi/pkg/glusterfs/api/types.go
generated
vendored
728
vendor/github.com/heketi/heketi/pkg/glusterfs/api/types.go
generated
vendored
@ -1,728 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2016 The heketi Authors
|
||||
//
|
||||
// This file is licensed to you under your choice of the GNU Lesser
|
||||
// General Public License, version 3 or any later version (LGPLv3 or
|
||||
// later), as published by the Free Software Foundation,
|
||||
// or under the Apache License, Version 2.0 <LICENSE-APACHE2 or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0>.
|
||||
//
|
||||
// You may not use this file except in compliance with those terms.
|
||||
//
|
||||
|
||||
//
|
||||
// Please see https://github.com/heketi/heketi/wiki/API
|
||||
// for documentation
|
||||
//
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
|
||||
validation "github.com/go-ozzo/ozzo-validation"
|
||||
"github.com/go-ozzo/ozzo-validation/is"
|
||||
)
|
||||
|
||||
var (
|
||||
// Restricting the deviceName to much smaller subset of Unix Path
|
||||
// as unix path takes almost everything except NULL
|
||||
deviceNameRe = regexp.MustCompile("^/[a-zA-Z0-9_.:/-]+$")
|
||||
|
||||
// Volume name constraints decided by looking at
|
||||
// "cli_validate_volname" function in cli-cmd-parser.c of gluster code
|
||||
volumeNameRe = regexp.MustCompile("^[a-zA-Z0-9_-]+$")
|
||||
|
||||
blockVolNameRe = regexp.MustCompile("^[a-zA-Z0-9_-]+$")
|
||||
|
||||
tagNameRe = regexp.MustCompile("^[a-zA-Z0-9_.-]+$")
|
||||
)
|
||||
|
||||
// ValidateUUID is written this way because heketi UUID does not
|
||||
// conform to neither UUID v4 nor v5.
|
||||
func ValidateUUID(value interface{}) error {
|
||||
s, _ := value.(string)
|
||||
err := validation.Validate(s, validation.RuneLength(32, 32), is.Hexadecimal)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v is not a valid UUID", s)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// State
|
||||
type EntryState string
|
||||
|
||||
const (
|
||||
EntryStateUnknown EntryState = ""
|
||||
EntryStateOnline EntryState = "online"
|
||||
EntryStateOffline EntryState = "offline"
|
||||
EntryStateFailed EntryState = "failed"
|
||||
)
|
||||
|
||||
func ValidateEntryState(value interface{}) error {
|
||||
s, _ := value.(EntryState)
|
||||
err := validation.Validate(s, validation.Required, validation.In(EntryStateOnline, EntryStateOffline, EntryStateFailed))
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v is not valid state", s)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type DurabilityType string
|
||||
|
||||
const (
|
||||
DurabilityReplicate DurabilityType = "replicate"
|
||||
DurabilityDistributeOnly DurabilityType = "none"
|
||||
DurabilityEC DurabilityType = "disperse"
|
||||
)
|
||||
|
||||
func ValidateDurabilityType(value interface{}) error {
|
||||
s, _ := value.(DurabilityType)
|
||||
err := validation.Validate(s, validation.Required, validation.In(DurabilityReplicate, DurabilityDistributeOnly, DurabilityEC))
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v is not a valid durability type", s)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type HealInfoCheck string
|
||||
|
||||
const (
|
||||
HealCheckUnknown HealInfoCheck = ""
|
||||
HealCheckEnable HealInfoCheck = "enable"
|
||||
HealCheckDisable HealInfoCheck = "disable"
|
||||
)
|
||||
|
||||
func ValidateHealCheck(value interface{}) error {
|
||||
h, _ := value.(HealInfoCheck)
|
||||
err := validation.Validate(h, validation.In(HealCheckUnknown, HealCheckEnable, HealCheckDisable))
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v is not valid heal info check", h)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Common
|
||||
type StateRequest struct {
|
||||
State EntryState `json:"state"`
|
||||
HealCheck HealInfoCheck `json:"healcheck"`
|
||||
}
|
||||
|
||||
func (statereq StateRequest) Validate() error {
|
||||
if err := validation.ValidateStruct(&statereq,
|
||||
validation.Field(&statereq.HealCheck, validation.By(ValidateHealCheck))); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return validation.ValidateStruct(&statereq,
|
||||
validation.Field(&statereq.State, validation.Required, validation.By(ValidateEntryState)),
|
||||
)
|
||||
}
|
||||
|
||||
// Storage values in KB
|
||||
type StorageSize struct {
|
||||
Total uint64 `json:"total"`
|
||||
Free uint64 `json:"free"`
|
||||
Used uint64 `json:"used"`
|
||||
}
|
||||
|
||||
type HostAddresses struct {
|
||||
Manage sort.StringSlice `json:"manage"`
|
||||
Storage sort.StringSlice `json:"storage"`
|
||||
}
|
||||
|
||||
func ValidateManagementHostname(value interface{}) error {
|
||||
s, _ := value.(sort.StringSlice)
|
||||
for _, fqdn := range s {
|
||||
err := validation.Validate(fqdn, validation.Required, is.Host)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v is not a valid manage hostname", s)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ValidateStorageHostname(value interface{}) error {
|
||||
s, _ := value.(sort.StringSlice)
|
||||
for _, ip := range s {
|
||||
err := validation.Validate(ip, validation.Required, is.Host)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v is not a valid storage hostname", s)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (hostadd HostAddresses) Validate() error {
|
||||
return validation.ValidateStruct(&hostadd,
|
||||
validation.Field(&hostadd.Manage, validation.Required, validation.By(ValidateManagementHostname)),
|
||||
validation.Field(&hostadd.Storage, validation.Required, validation.By(ValidateStorageHostname)),
|
||||
)
|
||||
}
|
||||
|
||||
// Brick
|
||||
type BrickInfo struct {
|
||||
Id string `json:"id"`
|
||||
Path string `json:"path"`
|
||||
DeviceId string `json:"device"`
|
||||
NodeId string `json:"node"`
|
||||
VolumeId string `json:"volume"`
|
||||
|
||||
// Size in KB
|
||||
Size uint64 `json:"size"`
|
||||
}
|
||||
|
||||
// Device
|
||||
type Device struct {
|
||||
Name string `json:"name"`
|
||||
Tags map[string]string `json:"tags,omitempty"`
|
||||
}
|
||||
|
||||
func (dev Device) Validate() error {
|
||||
return validation.ValidateStruct(&dev,
|
||||
validation.Field(&dev.Name, validation.Required, validation.Match(deviceNameRe)),
|
||||
validation.Field(&dev.Tags, validation.By(ValidateTags)),
|
||||
)
|
||||
}
|
||||
|
||||
type DeviceAddRequest struct {
|
||||
Device
|
||||
NodeId string `json:"node"`
|
||||
DestroyData bool `json:"destroydata,omitempty"`
|
||||
}
|
||||
|
||||
func (devAddReq DeviceAddRequest) Validate() error {
|
||||
return validation.ValidateStruct(&devAddReq,
|
||||
validation.Field(&devAddReq.Device, validation.Required),
|
||||
validation.Field(&devAddReq.NodeId, validation.Required, validation.By(ValidateUUID)),
|
||||
validation.Field(&devAddReq.DestroyData, validation.In(true, false)),
|
||||
)
|
||||
}
|
||||
|
||||
type DeviceInfo struct {
|
||||
Device
|
||||
Storage StorageSize `json:"storage"`
|
||||
Id string `json:"id"`
|
||||
Paths []string `json:"paths,omitempty"`
|
||||
PvUUID string `json:"pv_uuid,omitempty"`
|
||||
}
|
||||
|
||||
type DeviceInfoResponse struct {
|
||||
DeviceInfo
|
||||
State EntryState `json:"state"`
|
||||
Bricks []BrickInfo `json:"bricks"`
|
||||
}
|
||||
|
||||
// Node
|
||||
type NodeAddRequest struct {
|
||||
Zone int `json:"zone"`
|
||||
Hostnames HostAddresses `json:"hostnames"`
|
||||
ClusterId string `json:"cluster"`
|
||||
Tags map[string]string `json:"tags,omitempty"`
|
||||
}
|
||||
|
||||
func (req NodeAddRequest) Validate() error {
|
||||
return validation.ValidateStruct(&req,
|
||||
validation.Field(&req.Zone, validation.Required, validation.Min(1)),
|
||||
validation.Field(&req.Hostnames, validation.Required),
|
||||
validation.Field(&req.ClusterId, validation.Required, validation.By(ValidateUUID)),
|
||||
validation.Field(&req.Tags, validation.By(ValidateTags)),
|
||||
)
|
||||
}
|
||||
|
||||
type NodeInfo struct {
|
||||
NodeAddRequest
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
type NodeInfoResponse struct {
|
||||
NodeInfo
|
||||
State EntryState `json:"state"`
|
||||
DevicesInfo []DeviceInfoResponse `json:"devices"`
|
||||
}
|
||||
|
||||
// Cluster
|
||||
|
||||
type ClusterFlags struct {
|
||||
Block bool `json:"block"`
|
||||
File bool `json:"file"`
|
||||
}
|
||||
|
||||
type Cluster struct {
|
||||
Volumes []VolumeInfoResponse `json:"volumes"`
|
||||
//currently BlockVolumes will be used only for metrics
|
||||
BlockVolumes []BlockVolumeInfoResponse `json:"blockvolumes,omitempty"`
|
||||
Nodes []NodeInfoResponse `json:"nodes"`
|
||||
Id string `json:"id"`
|
||||
ClusterFlags
|
||||
}
|
||||
|
||||
type TopologyInfoResponse struct {
|
||||
ClusterList []Cluster `json:"clusters"`
|
||||
}
|
||||
|
||||
type ClusterCreateRequest struct {
|
||||
ClusterFlags
|
||||
}
|
||||
|
||||
type ClusterSetFlagsRequest struct {
|
||||
ClusterFlags
|
||||
}
|
||||
|
||||
type ClusterInfoResponse struct {
|
||||
Id string `json:"id"`
|
||||
Nodes sort.StringSlice `json:"nodes"`
|
||||
Volumes sort.StringSlice `json:"volumes"`
|
||||
ClusterFlags
|
||||
BlockVolumes sort.StringSlice `json:"blockvolumes"`
|
||||
}
|
||||
|
||||
type ClusterListResponse struct {
|
||||
Clusters []string `json:"clusters"`
|
||||
}
|
||||
|
||||
// Durabilities
|
||||
type ReplicaDurability struct {
|
||||
Replica int `json:"replica,omitempty"`
|
||||
}
|
||||
|
||||
type DisperseDurability struct {
|
||||
Data int `json:"data,omitempty"`
|
||||
Redundancy int `json:"redundancy,omitempty"`
|
||||
}
|
||||
|
||||
// Volume
|
||||
type VolumeDurabilityInfo struct {
|
||||
Type DurabilityType `json:"type,omitempty"`
|
||||
Replicate ReplicaDurability `json:"replicate,omitempty"`
|
||||
Disperse DisperseDurability `json:"disperse,omitempty"`
|
||||
}
|
||||
|
||||
type VolumeCreateRequest struct {
|
||||
// Size in GiB
|
||||
Size int `json:"size"`
|
||||
Clusters []string `json:"clusters,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Durability VolumeDurabilityInfo `json:"durability,omitempty"`
|
||||
Gid int64 `json:"gid,omitempty"`
|
||||
GlusterVolumeOptions []string `json:"glustervolumeoptions,omitempty"`
|
||||
Block bool `json:"block,omitempty"`
|
||||
Snapshot struct {
|
||||
Enable bool `json:"enable"`
|
||||
Factor float32 `json:"factor"`
|
||||
} `json:"snapshot"`
|
||||
}
|
||||
|
||||
func (volCreateRequest VolumeCreateRequest) Validate() error {
|
||||
return validation.ValidateStruct(&volCreateRequest,
|
||||
validation.Field(&volCreateRequest.Size, validation.Required, validation.Min(1)),
|
||||
validation.Field(&volCreateRequest.Clusters, validation.By(ValidateUUID)),
|
||||
validation.Field(&volCreateRequest.Name, validation.Match(volumeNameRe)),
|
||||
validation.Field(&volCreateRequest.Durability, validation.Skip),
|
||||
validation.Field(&volCreateRequest.Gid, validation.Skip),
|
||||
validation.Field(&volCreateRequest.GlusterVolumeOptions, validation.Skip),
|
||||
validation.Field(&volCreateRequest.Block, validation.In(true, false)),
|
||||
// This is possibly a bug in validation lib, ignore next two lines for now
|
||||
// validation.Field(&volCreateRequest.Snapshot.Enable, validation.In(true, false)),
|
||||
// validation.Field(&volCreateRequest.Snapshot.Factor, validation.Min(1.0)),
|
||||
)
|
||||
}
|
||||
|
||||
type BlockRestriction string
|
||||
|
||||
const (
|
||||
Unrestricted BlockRestriction = ""
|
||||
Locked BlockRestriction = "locked"
|
||||
LockedByUpdate BlockRestriction = "locked-by-update"
|
||||
)
|
||||
|
||||
func (br BlockRestriction) String() string {
|
||||
switch br {
|
||||
case Unrestricted:
|
||||
return "(none)"
|
||||
case Locked:
|
||||
return "locked"
|
||||
case LockedByUpdate:
|
||||
return "locked-by-update"
|
||||
default:
|
||||
return "unknown"
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
type VolumeInfo struct {
|
||||
VolumeCreateRequest
|
||||
Id string `json:"id"`
|
||||
Cluster string `json:"cluster"`
|
||||
Mount struct {
|
||||
GlusterFS struct {
|
||||
Hosts []string `json:"hosts"`
|
||||
MountPoint string `json:"device"`
|
||||
Options map[string]string `json:"options"`
|
||||
} `json:"glusterfs"`
|
||||
} `json:"mount"`
|
||||
BlockInfo struct {
|
||||
FreeSize int `json:"freesize,omitempty"`
|
||||
ReservedSize int `json:"reservedsize,omitempty"`
|
||||
BlockVolumes sort.StringSlice `json:"blockvolume,omitempty"`
|
||||
Restriction BlockRestriction `json:"restriction,omitempty"`
|
||||
} `json:"blockinfo,omitempty"`
|
||||
}
|
||||
|
||||
type VolumeInfoResponse struct {
|
||||
VolumeInfo
|
||||
Bricks []BrickInfo `json:"bricks"`
|
||||
}
|
||||
|
||||
type VolumeListResponse struct {
|
||||
Volumes []string `json:"volumes"`
|
||||
}
|
||||
|
||||
type VolumeExpandRequest struct {
|
||||
Size int `json:"expand_size"`
|
||||
}
|
||||
|
||||
func (volExpandReq VolumeExpandRequest) Validate() error {
|
||||
return validation.ValidateStruct(&volExpandReq,
|
||||
validation.Field(&volExpandReq.Size, validation.Required, validation.Min(1)),
|
||||
)
|
||||
}
|
||||
|
||||
type VolumeCloneRequest struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
func (vcr VolumeCloneRequest) Validate() error {
|
||||
return validation.ValidateStruct(&vcr,
|
||||
validation.Field(&vcr.Name, validation.Match(volumeNameRe)),
|
||||
)
|
||||
}
|
||||
|
||||
type VolumeBlockRestrictionRequest struct {
|
||||
Restriction BlockRestriction `json:"restriction"`
|
||||
}
|
||||
|
||||
func (vbrr VolumeBlockRestrictionRequest) Validate() error {
|
||||
return validation.ValidateStruct(&vbrr,
|
||||
validation.Field(&vbrr.Restriction,
|
||||
validation.In(Unrestricted, Locked)))
|
||||
}
|
||||
|
||||
// BlockVolume
|
||||
|
||||
type BlockVolumeCreateRequest struct {
|
||||
// Size in GiB
|
||||
Size int `json:"size"`
|
||||
Clusters []string `json:"clusters,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Hacount int `json:"hacount,omitempty"`
|
||||
Auth bool `json:"auth,omitempty"`
|
||||
}
|
||||
|
||||
func (blockVolCreateReq BlockVolumeCreateRequest) Validate() error {
|
||||
return validation.ValidateStruct(&blockVolCreateReq,
|
||||
validation.Field(&blockVolCreateReq.Size, validation.Required, validation.Min(1)),
|
||||
validation.Field(&blockVolCreateReq.Clusters, validation.By(ValidateUUID)),
|
||||
validation.Field(&blockVolCreateReq.Name, validation.Match(blockVolNameRe)),
|
||||
validation.Field(&blockVolCreateReq.Hacount, validation.Min(1)),
|
||||
validation.Field(&blockVolCreateReq.Auth, validation.Skip),
|
||||
)
|
||||
}
|
||||
|
||||
type BlockVolumeInfo struct {
|
||||
BlockVolumeCreateRequest
|
||||
Id string `json:"id"`
|
||||
BlockVolume struct {
|
||||
Hosts []string `json:"hosts"`
|
||||
Iqn string `json:"iqn"`
|
||||
Lun int `json:"lun"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
/*
|
||||
Options map[string]string `json:"options"` // needed?...
|
||||
*/
|
||||
} `json:"blockvolume"`
|
||||
Cluster string `json:"cluster,omitempty"`
|
||||
BlockHostingVolume string `json:"blockhostingvolume,omitempty"`
|
||||
UsableSize int `json:"usablesize,omitempty"`
|
||||
}
|
||||
|
||||
type BlockVolumeInfoResponse struct {
|
||||
BlockVolumeInfo
|
||||
}
|
||||
|
||||
type BlockVolumeListResponse struct {
|
||||
BlockVolumes []string `json:"blockvolumes"`
|
||||
}
|
||||
|
||||
type BlockVolumeExpandRequest struct {
|
||||
Size int `json:"new_size"`
|
||||
}
|
||||
|
||||
func (blockVolExpandReq BlockVolumeExpandRequest) Validate() error {
|
||||
return validation.ValidateStruct(&blockVolExpandReq,
|
||||
validation.Field(&blockVolExpandReq.Size, validation.Required, validation.Min(1)),
|
||||
)
|
||||
}
|
||||
|
||||
type LogLevelInfo struct {
|
||||
// should contain one or more logger to log-level-name mapping
|
||||
LogLevel map[string]string `json:"loglevel"`
|
||||
}
|
||||
|
||||
type TagsChangeType string
|
||||
|
||||
const (
|
||||
UnknownTagsChangeType TagsChangeType = ""
|
||||
SetTags TagsChangeType = "set"
|
||||
UpdateTags TagsChangeType = "update"
|
||||
DeleteTags TagsChangeType = "delete"
|
||||
)
|
||||
|
||||
// Common tag post body
|
||||
type TagsChangeRequest struct {
|
||||
Tags map[string]string `json:"tags"`
|
||||
Change TagsChangeType `json:"change_type"`
|
||||
}
|
||||
|
||||
func (tcr TagsChangeRequest) Validate() error {
|
||||
return validation.ValidateStruct(&tcr,
|
||||
validation.Field(&tcr.Tags, validation.By(ValidateTags)),
|
||||
validation.Field(&tcr.Change,
|
||||
validation.Required,
|
||||
validation.In(SetTags, UpdateTags, DeleteTags)))
|
||||
}
|
||||
|
||||
func ValidateTags(v interface{}) error {
|
||||
t, ok := v.(map[string]string)
|
||||
if !ok {
|
||||
return fmt.Errorf("tags must be a map of strings to strings")
|
||||
}
|
||||
if len(t) > 32 {
|
||||
return fmt.Errorf("too many tags specified (%v), up to %v supported",
|
||||
len(t), 32)
|
||||
}
|
||||
for k, v := range t {
|
||||
if len(k) == 0 {
|
||||
return fmt.Errorf("tag names may not be empty")
|
||||
}
|
||||
if err := validation.Validate(k, validation.RuneLength(1, 32)); err != nil {
|
||||
return fmt.Errorf("tag name %v: %v", k, err)
|
||||
}
|
||||
if err := validation.Validate(v, validation.RuneLength(0, 64)); err != nil {
|
||||
return fmt.Errorf("value of tag %v: %v", k, err)
|
||||
}
|
||||
if !tagNameRe.MatchString(k) {
|
||||
return fmt.Errorf("invalid characters in tag name %+v", k)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Constructors
|
||||
|
||||
func NewVolumeInfoResponse() *VolumeInfoResponse {
|
||||
|
||||
info := &VolumeInfoResponse{}
|
||||
info.Mount.GlusterFS.Options = make(map[string]string)
|
||||
info.Bricks = make([]BrickInfo, 0)
|
||||
|
||||
return info
|
||||
}
|
||||
|
||||
// String functions
|
||||
func (v *VolumeInfoResponse) String() string {
|
||||
s := fmt.Sprintf("Name: %v\n"+
|
||||
"Size: %v\n"+
|
||||
"Volume Id: %v\n"+
|
||||
"Cluster Id: %v\n"+
|
||||
"Mount: %v\n"+
|
||||
"Mount Options: backup-volfile-servers=%v\n"+
|
||||
"Block: %v\n"+
|
||||
"Free Size: %v\n"+
|
||||
"Reserved Size: %v\n"+
|
||||
"Block Hosting Restriction: %v\n"+
|
||||
"Block Volumes: %v\n"+
|
||||
"Durability Type: %v\n",
|
||||
v.Name,
|
||||
v.Size,
|
||||
v.Id,
|
||||
v.Cluster,
|
||||
v.Mount.GlusterFS.MountPoint,
|
||||
v.Mount.GlusterFS.Options["backup-volfile-servers"],
|
||||
v.Block,
|
||||
v.BlockInfo.FreeSize,
|
||||
v.BlockInfo.ReservedSize,
|
||||
v.BlockInfo.Restriction,
|
||||
v.BlockInfo.BlockVolumes,
|
||||
v.Durability.Type)
|
||||
|
||||
switch v.Durability.Type {
|
||||
case DurabilityEC:
|
||||
s += fmt.Sprintf("Disperse Data: %v\n"+
|
||||
"Disperse Redundancy: %v\n",
|
||||
v.Durability.Disperse.Data,
|
||||
v.Durability.Disperse.Redundancy)
|
||||
case DurabilityReplicate:
|
||||
s += fmt.Sprintf("Distributed+Replica: %v\n",
|
||||
v.Durability.Replicate.Replica)
|
||||
}
|
||||
|
||||
if v.Snapshot.Enable {
|
||||
s += fmt.Sprintf("Snapshot Factor: %.2f\n",
|
||||
v.Snapshot.Factor)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func NewBlockVolumeInfoResponse() *BlockVolumeInfoResponse {
|
||||
|
||||
info := &BlockVolumeInfoResponse{}
|
||||
// Nothing to Construct now maybe for future
|
||||
|
||||
return info
|
||||
}
|
||||
|
||||
// String functions
|
||||
func (v *BlockVolumeInfoResponse) String() string {
|
||||
s := fmt.Sprintf("Name: %v\n"+
|
||||
"Size: %v\n"+
|
||||
"UsableSize: %v\n"+
|
||||
"Volume Id: %v\n"+
|
||||
"Cluster Id: %v\n"+
|
||||
"Hosts: %v\n"+
|
||||
"IQN: %v\n"+
|
||||
"LUN: %v\n"+
|
||||
"Hacount: %v\n"+
|
||||
"Username: %v\n"+
|
||||
"Password: %v\n"+
|
||||
"Block Hosting Volume: %v\n",
|
||||
v.Name,
|
||||
v.Size,
|
||||
v.UsableSize,
|
||||
v.Id,
|
||||
v.Cluster,
|
||||
v.BlockVolume.Hosts,
|
||||
v.BlockVolume.Iqn,
|
||||
v.BlockVolume.Lun,
|
||||
v.Hacount,
|
||||
v.BlockVolume.Username,
|
||||
v.BlockVolume.Password,
|
||||
v.BlockHostingVolume)
|
||||
|
||||
/*
|
||||
s += "\nBricks:\n"
|
||||
for _, b := range v.Bricks {
|
||||
s += fmt.Sprintf("Id: %v\n"+
|
||||
"Path: %v\n"+
|
||||
"Size (GiB): %v\n"+
|
||||
"Node: %v\n"+
|
||||
"Device: %v\n\n",
|
||||
b.Id,
|
||||
b.Path,
|
||||
b.Size/(1024*1024),
|
||||
b.NodeId,
|
||||
b.DeviceId)
|
||||
}
|
||||
*/
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
type OperationsInfo struct {
|
||||
Total uint64 `json:"total"`
|
||||
InFlight uint64 `json:"in_flight"`
|
||||
// state based counts:
|
||||
Stale uint64 `json:"stale"`
|
||||
Failed uint64 `json:"failed"`
|
||||
New uint64 `json:"new"`
|
||||
}
|
||||
|
||||
type AdminState string
|
||||
|
||||
const (
|
||||
AdminStateNormal AdminState = "normal"
|
||||
AdminStateReadOnly AdminState = "read-only"
|
||||
AdminStateLocal AdminState = "local-client"
|
||||
)
|
||||
|
||||
type AdminStatus struct {
|
||||
State AdminState `json:"state"`
|
||||
}
|
||||
|
||||
func (as AdminStatus) Validate() error {
|
||||
return validation.ValidateStruct(&as,
|
||||
validation.Field(&as.State,
|
||||
validation.Required,
|
||||
validation.In(AdminStateNormal, AdminStateReadOnly, AdminStateLocal)))
|
||||
}
|
||||
|
||||
// DeviceDeleteOptions is used to specify additional behavior for device
|
||||
// deletes.
|
||||
type DeviceDeleteOptions struct {
|
||||
// force heketi to forget about a device, possibly
|
||||
// orphaning metadata on the node
|
||||
ForceForget bool `json:"forceforget"`
|
||||
}
|
||||
|
||||
// PendingOperationInfo contains metadata to summarize a pending
|
||||
// operation.
|
||||
type PendingOperationInfo struct {
|
||||
Id string `json:"id"`
|
||||
TypeName string `json:"type_name"`
|
||||
Status string `json:"status"`
|
||||
SubStatus string `json:"sub_status"`
|
||||
// TODO label, timestamp?
|
||||
}
|
||||
|
||||
type PendingChangeInfo struct {
|
||||
Id string `json:"id"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
type PendingOperationDetails struct {
|
||||
PendingOperationInfo
|
||||
Changes []PendingChangeInfo `json:"changes"`
|
||||
}
|
||||
|
||||
type PendingOperationListResponse struct {
|
||||
PendingOperations []PendingOperationInfo `json:"pendingoperations"`
|
||||
}
|
||||
|
||||
type PendingOperationsCleanRequest struct {
|
||||
Operations []string `json:"operations,omitempty"`
|
||||
}
|
||||
|
||||
func (pocr PendingOperationsCleanRequest) Validate() error {
|
||||
return validation.ValidateStruct(&pocr,
|
||||
validation.Field(&pocr.Operations, validation.By(ValidateIds)),
|
||||
)
|
||||
}
|
||||
|
||||
func ValidateIds(v interface{}) error {
|
||||
ids, ok := v.([]string)
|
||||
if !ok {
|
||||
return fmt.Errorf("must be a list of strings")
|
||||
}
|
||||
if len(ids) > 32 {
|
||||
return fmt.Errorf("too many ids specified (%v), up to %v supported",
|
||||
len(ids), 32)
|
||||
}
|
||||
for _, id := range ids {
|
||||
if err := ValidateUUID(id); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// reserving a type for future options for brick evict
|
||||
type BrickEvictOptions struct {
|
||||
HealCheck HealInfoCheck `json:"healcheck"`
|
||||
}
|
||||
|
||||
func (brickops BrickEvictOptions) Validate() error {
|
||||
return validation.ValidateStruct(&brickops,
|
||||
validation.Field(&brickops.HealCheck, validation.By(ValidateHealCheck)))
|
||||
}
|
62
vendor/github.com/heketi/heketi/pkg/utils/bodystring.go
generated
vendored
62
vendor/github.com/heketi/heketi/pkg/utils/bodystring.go
generated
vendored
@ -1,62 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2015 The heketi Authors
|
||||
//
|
||||
// This file is licensed to you under your choice of the GNU Lesser
|
||||
// General Public License, version 3 or any later version (LGPLv3 or
|
||||
// later), as published by the Free Software Foundation,
|
||||
// or under the Apache License, Version 2.0 <LICENSE-APACHE2 or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0>.
|
||||
//
|
||||
// You may not use this file except in compliance with those terms.
|
||||
//
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
errMax = int64(4096)
|
||||
strMax = int64(8192)
|
||||
)
|
||||
|
||||
// Return the body from a response as a string
|
||||
func GetStringFromResponse(r *http.Response) (string, error) {
|
||||
// If the content length is not set, limit reading to 8K worth of data.
|
||||
return getResponse(r, strMax)
|
||||
}
|
||||
|
||||
func getResponse(r *http.Response, max int64) (string, error) {
|
||||
if r.ContentLength >= 0 {
|
||||
max = r.ContentLength
|
||||
}
|
||||
body, err := ioutil.ReadAll(io.LimitReader(r.Body, max))
|
||||
defer r.Body.Close()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(body), nil
|
||||
}
|
||||
|
||||
// Return the body from a response as an error
|
||||
func GetErrorFromResponse(r *http.Response) error {
|
||||
// If the content length is not set, limit reading to 4K worth of data.
|
||||
// It is probably way more than needed because an error that long is
|
||||
// very unusual. Plus it will only cut it off rather than show nothing.
|
||||
s, err := getResponse(r, errMax)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s = strings.TrimSpace(s)
|
||||
if len(s) == 0 {
|
||||
return fmt.Errorf("server did not provide a message (status %v: %v)", r.StatusCode, http.StatusText(r.StatusCode))
|
||||
}
|
||||
return errors.New(s)
|
||||
}
|
46
vendor/github.com/heketi/heketi/pkg/utils/jsonutils.go
generated
vendored
46
vendor/github.com/heketi/heketi/pkg/utils/jsonutils.go
generated
vendored
@ -1,46 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2015 The heketi Authors
|
||||
//
|
||||
// This file is licensed to you under your choice of the GNU Lesser
|
||||
// General Public License, version 3 or any later version (LGPLv3 or
|
||||
// later), as published by the Free Software Foundation,
|
||||
// or under the Apache License, Version 2.0 <LICENSE-APACHE2 or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0>.
|
||||
//
|
||||
// You may not use this file except in compliance with those terms.
|
||||
//
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func jsonFromBody(r io.Reader, v interface{}) error {
|
||||
|
||||
// Check body
|
||||
body, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := json.Unmarshal(body, v); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Unmarshal JSON from request
|
||||
func GetJsonFromRequest(r *http.Request, v interface{}) error {
|
||||
defer r.Body.Close()
|
||||
return jsonFromBody(r.Body, v)
|
||||
}
|
||||
|
||||
// Unmarshal JSON from response
|
||||
func GetJsonFromResponse(r *http.Response, v interface{}) error {
|
||||
defer r.Body.Close()
|
||||
return jsonFromBody(r.Body, v)
|
||||
}
|
71
vendor/github.com/heketi/heketi/pkg/utils/statusgroup.go
generated
vendored
71
vendor/github.com/heketi/heketi/pkg/utils/statusgroup.go
generated
vendored
@ -1,71 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2015 The heketi Authors
|
||||
//
|
||||
// This file is licensed to you under your choice of the GNU Lesser
|
||||
// General Public License, version 3 or any later version (LGPLv3 or
|
||||
// later), as published by the Free Software Foundation,
|
||||
// or under the Apache License, Version 2.0 <LICENSE-APACHE2 or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0>.
|
||||
//
|
||||
// You may not use this file except in compliance with those terms.
|
||||
//
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
type StatusGroup struct {
|
||||
wg sync.WaitGroup
|
||||
results chan error
|
||||
err error
|
||||
}
|
||||
|
||||
// Create a new goroutine error status collector
|
||||
func NewStatusGroup() *StatusGroup {
|
||||
s := &StatusGroup{}
|
||||
s.results = make(chan error, 1)
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// Adds to the number of goroutines it should wait
|
||||
func (s *StatusGroup) Add(delta int) {
|
||||
s.wg.Add(delta)
|
||||
}
|
||||
|
||||
// Removes the number of pending goroutines by one
|
||||
func (s *StatusGroup) Done() {
|
||||
s.wg.Done()
|
||||
}
|
||||
|
||||
// Goroutine can return an error back to caller
|
||||
func (s *StatusGroup) Err(err error) {
|
||||
s.results <- err
|
||||
}
|
||||
|
||||
// Returns an error if any of the spawned goroutines
|
||||
// return an error. Only the last error is saved.
|
||||
// This function must be called last after the last
|
||||
// s.Register() function
|
||||
func (s *StatusGroup) Result() error {
|
||||
|
||||
// This goroutine will wait until all
|
||||
// other privously spawned goroutines finish.
|
||||
// Once they finish, it will close the channel
|
||||
go func() {
|
||||
s.wg.Wait()
|
||||
close(s.results)
|
||||
}()
|
||||
|
||||
// Read from the channel until close
|
||||
for err := range s.results {
|
||||
// Only save the last one
|
||||
if err != nil {
|
||||
s.err = err
|
||||
}
|
||||
}
|
||||
|
||||
return s.err
|
||||
}
|
33
vendor/modules.txt
vendored
33
vendor/modules.txt
vendored
@ -111,8 +111,6 @@ github.com/armon/go-socks5
|
||||
# github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a => github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a
|
||||
## explicit
|
||||
github.com/asaskevich/govalidator
|
||||
# github.com/auth0/go-jwt-middleware v1.0.1 => github.com/auth0/go-jwt-middleware v1.0.1
|
||||
## explicit; go 1.14
|
||||
# github.com/aws/aws-sdk-go v1.38.49 => github.com/aws/aws-sdk-go v1.38.49
|
||||
## explicit; go 1.11
|
||||
github.com/aws/aws-sdk-go/aws
|
||||
@ -168,8 +166,6 @@ github.com/beorn7/perks/quantile
|
||||
# github.com/blang/semver/v4 v4.0.0 => github.com/blang/semver/v4 v4.0.0
|
||||
## explicit; go 1.14
|
||||
github.com/blang/semver/v4
|
||||
# github.com/boltdb/bolt v1.3.1 => github.com/boltdb/bolt v1.3.1
|
||||
## explicit
|
||||
# github.com/cespare/xxhash/v2 v2.1.2 => github.com/cespare/xxhash/v2 v2.1.2
|
||||
## explicit; go 1.11
|
||||
github.com/cespare/xxhash/v2
|
||||
@ -294,10 +290,6 @@ github.com/go-openapi/jsonreference
|
||||
# github.com/go-openapi/swag v0.19.14 => github.com/go-openapi/swag v0.19.14
|
||||
## explicit; go 1.11
|
||||
github.com/go-openapi/swag
|
||||
# github.com/go-ozzo/ozzo-validation v3.5.0+incompatible => github.com/go-ozzo/ozzo-validation v3.5.0+incompatible
|
||||
## explicit
|
||||
github.com/go-ozzo/ozzo-validation
|
||||
github.com/go-ozzo/ozzo-validation/is
|
||||
# github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 => github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0
|
||||
## explicit; go 1.13
|
||||
github.com/go-task/slim-sprig
|
||||
@ -463,8 +455,6 @@ github.com/google/uuid
|
||||
github.com/googleapis/gax-go/v2
|
||||
github.com/googleapis/gax-go/v2/apierror
|
||||
github.com/googleapis/gax-go/v2/apierror/internal/proto
|
||||
# github.com/gorilla/mux v1.8.0 => github.com/gorilla/mux v1.8.0
|
||||
## explicit; go 1.12
|
||||
# github.com/gorilla/websocket v1.4.2 => github.com/gorilla/websocket v1.4.2
|
||||
## explicit; go 1.12
|
||||
github.com/gorilla/websocket
|
||||
@ -482,13 +472,6 @@ github.com/grpc-ecosystem/go-grpc-prometheus
|
||||
github.com/grpc-ecosystem/grpc-gateway/internal
|
||||
github.com/grpc-ecosystem/grpc-gateway/runtime
|
||||
github.com/grpc-ecosystem/grpc-gateway/utilities
|
||||
# github.com/heketi/heketi v10.3.0+incompatible => github.com/heketi/heketi v10.3.0+incompatible
|
||||
## explicit
|
||||
github.com/heketi/heketi/client/api/go-client
|
||||
github.com/heketi/heketi/pkg/glusterfs/api
|
||||
github.com/heketi/heketi/pkg/utils
|
||||
# github.com/heketi/tests v0.0.0-20151005000721-f3775cbcefd6 => github.com/heketi/tests v0.0.0-20151005000721-f3775cbcefd6
|
||||
## explicit
|
||||
# github.com/imdario/mergo v0.3.6 => github.com/imdario/mergo v0.3.6
|
||||
## explicit
|
||||
github.com/imdario/mergo
|
||||
@ -528,8 +511,6 @@ github.com/liggitt/tabwriter
|
||||
# github.com/lithammer/dedent v1.1.0 => github.com/lithammer/dedent v1.1.0
|
||||
## explicit
|
||||
github.com/lithammer/dedent
|
||||
# github.com/lpabon/godbc v0.1.1 => github.com/lpabon/godbc v0.1.1
|
||||
## explicit
|
||||
# github.com/mailru/easyjson v0.7.6 => github.com/mailru/easyjson v0.7.6
|
||||
## explicit; go 1.12
|
||||
github.com/mailru/easyjson/buffer
|
||||
@ -744,8 +725,6 @@ github.com/syndtr/gocapability/capability
|
||||
# github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 => github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802
|
||||
## explicit
|
||||
github.com/tmc/grpc-websocket-proxy/wsproxy
|
||||
# github.com/urfave/negroni v1.0.0 => github.com/urfave/negroni v1.0.0
|
||||
## explicit
|
||||
# github.com/vishvananda/netlink v1.1.0 => github.com/vishvananda/netlink v1.1.0
|
||||
## explicit; go 1.12
|
||||
github.com/vishvananda/netlink
|
||||
@ -2556,13 +2535,11 @@ sigs.k8s.io/yaml
|
||||
# github.com/armon/circbuf => github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e
|
||||
# github.com/armon/go-socks5 => github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
|
||||
# github.com/asaskevich/govalidator => github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a
|
||||
# github.com/auth0/go-jwt-middleware => github.com/auth0/go-jwt-middleware v1.0.1
|
||||
# github.com/aws/aws-sdk-go => github.com/aws/aws-sdk-go v1.38.49
|
||||
# github.com/benbjohnson/clock => github.com/benbjohnson/clock v1.1.0
|
||||
# github.com/beorn7/perks => github.com/beorn7/perks v1.0.1
|
||||
# github.com/blang/semver => github.com/blang/semver v3.5.1+incompatible
|
||||
# github.com/blang/semver/v4 => github.com/blang/semver/v4 v4.0.0
|
||||
# github.com/boltdb/bolt => github.com/boltdb/bolt v1.3.1
|
||||
# github.com/census-instrumentation/opencensus-proto => github.com/census-instrumentation/opencensus-proto v0.2.1
|
||||
# github.com/certifi/gocertifi => github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054
|
||||
# github.com/cespare/xxhash/v2 => github.com/cespare/xxhash/v2 v2.1.2
|
||||
@ -2631,7 +2608,6 @@ sigs.k8s.io/yaml
|
||||
# github.com/go-openapi/jsonpointer => github.com/go-openapi/jsonpointer v0.19.5
|
||||
# github.com/go-openapi/jsonreference => github.com/go-openapi/jsonreference v0.19.5
|
||||
# github.com/go-openapi/swag => github.com/go-openapi/swag v0.19.14
|
||||
# github.com/go-ozzo/ozzo-validation => github.com/go-ozzo/ozzo-validation v3.5.0+incompatible
|
||||
# github.com/go-stack/stack => github.com/go-stack/stack v1.8.0
|
||||
# github.com/go-task/slim-sprig => github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0
|
||||
# github.com/godbus/dbus/v5 => github.com/godbus/dbus/v5 v5.0.6
|
||||
@ -2660,15 +2636,11 @@ sigs.k8s.io/yaml
|
||||
# github.com/google/shlex => github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
|
||||
# github.com/google/uuid => github.com/google/uuid v1.1.2
|
||||
# github.com/googleapis/gax-go/v2 => github.com/googleapis/gax-go/v2 v2.1.1
|
||||
# github.com/gopherjs/gopherjs => github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00
|
||||
# github.com/gorilla/mux => github.com/gorilla/mux v1.8.0
|
||||
# github.com/gorilla/websocket => github.com/gorilla/websocket v1.4.2
|
||||
# github.com/gregjones/httpcache => github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7
|
||||
# github.com/grpc-ecosystem/go-grpc-middleware => github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
|
||||
# github.com/grpc-ecosystem/go-grpc-prometheus => github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
|
||||
# github.com/grpc-ecosystem/grpc-gateway => github.com/grpc-ecosystem/grpc-gateway v1.16.0
|
||||
# github.com/heketi/heketi => github.com/heketi/heketi v10.3.0+incompatible
|
||||
# github.com/heketi/tests => github.com/heketi/tests v0.0.0-20151005000721-f3775cbcefd6
|
||||
# github.com/ianlancetaylor/demangle => github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639
|
||||
# github.com/imdario/mergo => github.com/imdario/mergo v0.3.6
|
||||
# github.com/inconshreveable/mousetrap => github.com/inconshreveable/mousetrap v1.0.0
|
||||
@ -2679,7 +2651,6 @@ sigs.k8s.io/yaml
|
||||
# github.com/josharian/intern => github.com/josharian/intern v1.0.0
|
||||
# github.com/jpillora/backoff => github.com/jpillora/backoff v1.0.0
|
||||
# github.com/json-iterator/go => github.com/json-iterator/go v1.1.12
|
||||
# github.com/jtolds/gls => github.com/jtolds/gls v4.20.0+incompatible
|
||||
# github.com/julienschmidt/httprouter => github.com/julienschmidt/httprouter v1.3.0
|
||||
# github.com/jung-kurt/gofpdf => github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5
|
||||
# github.com/karrick/godirwalk => github.com/karrick/godirwalk v1.16.1
|
||||
@ -2692,7 +2663,6 @@ sigs.k8s.io/yaml
|
||||
# github.com/libopenstorage/openstorage => github.com/libopenstorage/openstorage v1.0.0
|
||||
# github.com/liggitt/tabwriter => github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de
|
||||
# github.com/lithammer/dedent => github.com/lithammer/dedent v1.1.0
|
||||
# github.com/lpabon/godbc => github.com/lpabon/godbc v0.1.1
|
||||
# github.com/mailru/easyjson => github.com/mailru/easyjson v0.7.6
|
||||
# github.com/mattn/go-runewidth => github.com/mattn/go-runewidth v0.0.7
|
||||
# github.com/matttproud/golang_protobuf_extensions => github.com/matttproud/golang_protobuf_extensions v1.0.1
|
||||
@ -2743,8 +2713,6 @@ sigs.k8s.io/yaml
|
||||
# github.com/seccomp/libseccomp-golang => github.com/seccomp/libseccomp-golang v0.9.2-0.20220502022130-f33da4d89646
|
||||
# github.com/sergi/go-diff => github.com/sergi/go-diff v1.1.0
|
||||
# github.com/sirupsen/logrus => github.com/sirupsen/logrus v1.8.1
|
||||
# github.com/smartystreets/assertions => github.com/smartystreets/assertions v1.1.0
|
||||
# github.com/smartystreets/goconvey => github.com/smartystreets/goconvey v1.6.4
|
||||
# github.com/soheilhy/cmux => github.com/soheilhy/cmux v0.1.5
|
||||
# github.com/spf13/afero => github.com/spf13/afero v1.6.0
|
||||
# github.com/spf13/cobra => github.com/spf13/cobra v1.4.0
|
||||
@ -2755,7 +2723,6 @@ sigs.k8s.io/yaml
|
||||
# github.com/syndtr/gocapability => github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635
|
||||
# github.com/tmc/grpc-websocket-proxy => github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802
|
||||
# github.com/urfave/cli => github.com/urfave/cli v1.22.2
|
||||
# github.com/urfave/negroni => github.com/urfave/negroni v1.0.0
|
||||
# github.com/vishvananda/netlink => github.com/vishvananda/netlink v1.1.0
|
||||
# github.com/vishvananda/netns => github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae
|
||||
# github.com/vmware/govmomi => github.com/vmware/govmomi v0.20.3
|
||||
|
Loading…
Reference in New Issue
Block a user