Update mcs to latest minio and mc (#69)
updates code to be compatible with: - github.com/minio/mc v0.0.0-20200415193718-68b638f2f96c - github.com/minio/minio v0.0.0-20200415191640-bde0f444dbab Note: admin_config api is patched temporarily now to return the target configuration as a raw string due to the changes done on minio.
This commit is contained in:
9
go.mod
9
go.mod
@@ -13,11 +13,10 @@ require (
|
||||
github.com/go-openapi/validate v0.19.7
|
||||
github.com/jessevdk/go-flags v1.4.0
|
||||
github.com/minio/cli v1.22.0
|
||||
github.com/minio/m3/mcs v0.0.0-20200402043742-b25a986a7344 // indirect
|
||||
github.com/minio/mc v0.0.0-20200403024131-4d36c1f8b856
|
||||
github.com/minio/minio v0.0.0-20200327214830-6f992134a25f
|
||||
github.com/minio/minio-go/v6 v6.0.51-0.20200401083717-eadbcae2a0e6
|
||||
github.com/minio/mc v0.0.0-20200415193718-68b638f2f96c
|
||||
github.com/minio/minio v0.0.0-20200415191640-bde0f444dbab
|
||||
github.com/minio/minio-go/v6 v6.0.53
|
||||
github.com/stretchr/testify v1.5.1
|
||||
github.com/unrolled/secure v1.0.7
|
||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a
|
||||
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e
|
||||
)
|
||||
|
||||
47
go.sum
47
go.sum
@@ -55,6 +55,7 @@ github.com/cheggaaa/pb v1.0.28/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXH
|
||||
github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag=
|
||||
github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/codegangsta/negroni v1.0.0 h1:+aYywywx4bnKXWvoWtRfJ91vC59NbEhEY03sZjQhbVY=
|
||||
github.com/codegangsta/negroni v1.0.0/go.mod h1:v0y3T5G7Y1UlFfyxFn/QLRU4a2EuNau2iZY63YTKWo0=
|
||||
github.com/coredns/coredns v1.4.0 h1:RubBkYmkByUqZWWkjRHvNLnUHgkRVqAWgSMmRFvpE1A=
|
||||
github.com/coredns/coredns v1.4.0/go.mod h1:zASH/MVDgR6XZTbxvOnsZfffS+31vg6Ackf/wo1+AM0=
|
||||
@@ -104,8 +105,6 @@ github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 h1:Mn26/9ZMNWSw9C9ER
|
||||
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32/go.mod h1:GIjDIg/heH5DOkXY3YJ/wNhfHsQHoXGjl8G8amsYQ1I=
|
||||
github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
|
||||
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
|
||||
github.com/go-bindata/go-bindata v3.1.2+incompatible h1:5vjJMVhowQdPzjE1LdxyFF7YFTXg5IgGVW4gBr5IbvE=
|
||||
github.com/go-bindata/go-bindata v3.1.2+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo=
|
||||
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
github.com/go-ldap/ldap v3.0.2+incompatible/go.mod h1:qfd9rJvER9Q0/D/Sqn1DfHRoBp40uXYvFoEVrNEPqRc=
|
||||
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
||||
@@ -341,8 +340,7 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kurin/blazer v0.5.4-0.20190613185654-cf2f27cc0be3 h1:1sl2HmNtqGnDuydLgCJwZIpDLGqZOdwOkcY8WtUl8Cw=
|
||||
github.com/kurin/blazer v0.5.4-0.20190613185654-cf2f27cc0be3/go.mod h1:4FCXMUWo9DllR2Do4TtBd377ezyAJ51vB5uTBjt0pGU=
|
||||
github.com/kurin/blazer v0.5.4-0.20200327014341-8f90a40f8af7/go.mod h1:4FCXMUWo9DllR2Do4TtBd377ezyAJ51vB5uTBjt0pGU=
|
||||
github.com/lib/pq v1.1.1 h1:sJZmqHoEaY7f+NPP8pgLB/WxulyR3fewgCM2qaSlBb4=
|
||||
github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/mailru/easyjson v0.0.0-20180730094502-03f2033d19d5/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
@@ -386,22 +384,13 @@ github.com/minio/highwayhash v1.0.0 h1:iMSDhgUILCr0TNm8LWlSjF8N0ZIj2qbO8WHp6Q/J2
|
||||
github.com/minio/highwayhash v1.0.0/go.mod h1:xQboMTeM9nY9v/LlAOxFctujiv5+Aq2hR5dxBpaMbdc=
|
||||
github.com/minio/lsync v1.0.1 h1:AVvILxA976xc27hstd1oR+X9PQG0sPSom1MNb1ImfUs=
|
||||
github.com/minio/lsync v1.0.1/go.mod h1:tCFzfo0dlvdGl70IT4IAK/5Wtgb0/BrTmo/jE8pArKA=
|
||||
github.com/minio/m3 v0.0.2 h1:F2Oc0hPOLAAHYCjIcnSuKyeZVUbIO5ZSMzGV5Yeh3vU=
|
||||
github.com/minio/m3/mcs v0.0.0-20200402043742-b25a986a7344 h1:IVYJFRNkDTsJlbGRmg6UN447DYCj3xnuHQOSoWWm1O4=
|
||||
github.com/minio/m3/mcs v0.0.0-20200402043742-b25a986a7344/go.mod h1:uYD9TwIIxviKlQrrItSGxUSqGGQDm3hgkfrwr4sqeF4=
|
||||
github.com/minio/mc v0.0.0-20200401220942-e05f02d9f459/go.mod h1:GWohdY5tXSiMnBCofmDRK5yRCihQH2FKNM0eh+UsY5Y=
|
||||
github.com/minio/mc v0.0.0-20200403024131-4d36c1f8b856 h1:4uIc5fw4tVr5glh2Mc8GFuiY04pTGEhmihPxJPUvCoU=
|
||||
github.com/minio/mc v0.0.0-20200403024131-4d36c1f8b856/go.mod h1:IDy4dA4aFY6zFFNkYgdUztl0jcYuev/Ubg3NadoaMKc=
|
||||
github.com/minio/mcs v0.0.2 h1:3kdVL2oSa7u53cNRArDK4Ujiajjb56SK+Xb1/12Lu4Y=
|
||||
github.com/minio/minio v0.0.0-20200327214830-6f992134a25f h1:RoOBi0vhXkZqe2b6RTROOsVJUwMqLMoet9r7eL01euo=
|
||||
github.com/minio/minio v0.0.0-20200327214830-6f992134a25f/go.mod h1:BzbIyKUJPp+4f03i2XF7+GsijXnxMakUe5x+lm2WNc8=
|
||||
github.com/minio/minio-go/v6 v6.0.45/go.mod h1:qD0lajrGW49lKZLtXKtCB4X/qkMf0a5tBvN2PaZg7Gg=
|
||||
github.com/minio/minio-go/v6 v6.0.51-0.20200319192131-097caa7760c7 h1:WQmYVUDRGdcEWhJeb42/Fn1IO7SBLem173DTE4+jp/E=
|
||||
github.com/minio/minio-go/v6 v6.0.51-0.20200319192131-097caa7760c7/go.mod h1:qD0lajrGW49lKZLtXKtCB4X/qkMf0a5tBvN2PaZg7Gg=
|
||||
github.com/minio/minio-go/v6 v6.0.51-0.20200401083717-eadbcae2a0e6 h1:7JhqKjmt1Tv6co7eP/40/xtDLrzzWu1UwUNwQzSvcb0=
|
||||
github.com/minio/minio-go/v6 v6.0.51-0.20200401083717-eadbcae2a0e6/go.mod h1:qD0lajrGW49lKZLtXKtCB4X/qkMf0a5tBvN2PaZg7Gg=
|
||||
github.com/minio/parquet-go v0.0.0-20200125064549-a1e49702e174 h1:WYFHZIJ5LTWd4C3CW26jguaBLLDdX7l1/Xa3QSKGkIc=
|
||||
github.com/minio/parquet-go v0.0.0-20200125064549-a1e49702e174/go.mod h1:PXYM9yI2l0YPmxHUXe6mFTmkQcyaVasDshAPTbGpDoo=
|
||||
github.com/minio/mc v0.0.0-20200415193718-68b638f2f96c h1:JLr0fYpCleodj9nGB5hfsJU2zPdnNQKqa2bYsIvPhVw=
|
||||
github.com/minio/mc v0.0.0-20200415193718-68b638f2f96c/go.mod h1:l9PuOY62zT7AQJqopDjfo/T22AIBJSb2yXPVZf4RlhM=
|
||||
github.com/minio/minio v0.0.0-20200415191640-bde0f444dbab h1:9hlqghJl3e3HorXa6ADWsz6ECq790t4iQs07VD9JctM=
|
||||
github.com/minio/minio v0.0.0-20200415191640-bde0f444dbab/go.mod h1:v8oQPMMaTkjDwp5cOz1WCElA4Ik+X+0y4On+VMk0fis=
|
||||
github.com/minio/minio-go/v6 v6.0.53 h1:8jzpwiOzZ5Iz7/goFWqNZRICbyWYShbb5rARjrnSCNI=
|
||||
github.com/minio/minio-go/v6 v6.0.53/go.mod h1:DIvC/IApeHX8q1BAMVCXSXwpmrmM+I+iBvhvztQorfI=
|
||||
github.com/minio/parquet-go v0.0.0-20200414234858-838cfa8aae61/go.mod h1:4trzEJ7N1nBTd5Tt7OCZT5SEin+WiAXpdJ/WgPkESA8=
|
||||
github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU=
|
||||
github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM=
|
||||
github.com/minio/simdjson-go v0.1.5-0.20200303142138-b17fe061ea37 h1:pDeao6M5AEd8hwTtGmE0pVKomlL56JFRa5SiXDZAuJE=
|
||||
@@ -516,8 +505,8 @@ github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx
|
||||
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
|
||||
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/skyrings/skyring-common v0.0.0-20160929130248-d1c0bb1cbd5e h1:jrZSSgPUDtBeJbGXqgGUeupQH8I+ZvGXfhpIahye2Bc=
|
||||
github.com/skyrings/skyring-common v0.0.0-20160929130248-d1c0bb1cbd5e/go.mod h1:d8hQseuYt4rJoOo21lFzYJdhMjmDqLY++ayArbgYjWI=
|
||||
github.com/sirupsen/logrus v1.5.0 h1:1N5EYkVAPEywqZRJd7cwnRtCb6xJx7NH3T3WUTF980Q=
|
||||
github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/assertions v0.0.0-20190401211740-f487f9de1cd3 h1:hBSHahWMEgzwRyS6dRpxY0XyjZsHyQ61s084wo5PJe0=
|
||||
github.com/smartystreets/assertions v0.0.0-20190401211740-f487f9de1cd3/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
@@ -624,11 +613,9 @@ golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR
|
||||
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0=
|
||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k=
|
||||
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190402181905-9f3314589c9a h1:tImsplftrFpALCYumobsd0K86vlAs/eXGFms2txfJfA=
|
||||
@@ -659,8 +646,8 @@ golang.org/x/sys v0.0.0-20190523142557-0e01d883c5c5/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200320181252-af34d8274f85 h1:fD99hd4ciR6T3oPhr2EkmuKe9oHixHx9Hj/hND89j3g=
|
||||
golang.org/x/sys v0.0.0-20200320181252-af34d8274f85/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.1-0.20181227161524-e6919f6577db/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
@@ -721,8 +708,8 @@ gopkg.in/h2non/filetype.v1 v1.0.5/go.mod h1:M0yem4rwSX5lLVrkEuRRp2/NinFMD5vgJ4Dl
|
||||
gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/ini.v1 v1.48.0 h1:URjZc+8ugRY5mL5uUeQH/a63JcHwdX9xZaWvmNWD7z8=
|
||||
gopkg.in/ini.v1 v1.48.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/ini.v1 v1.52.0 h1:j+Lt/M1oPPejkniCg1TkWE2J3Eh1oZTsHSXzMTzUXn4=
|
||||
gopkg.in/ini.v1 v1.52.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/ini.v1 v1.55.0 h1:E8yzL5unfpW3M6fz/eB7Cb5MQAYSZ7GKo4Qth+N2sgQ=
|
||||
gopkg.in/ini.v1 v1.55.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/jcmturner/aescts.v1 v1.0.1 h1:cVVZBK2b1zY26haWB4vbBiZrfFQnfbTVrE3xZq6hrEw=
|
||||
gopkg.in/jcmturner/aescts.v1 v1.0.1/go.mod h1:nsR8qBOg+OucoIW+WMhB3GspUQXq9XorLnQb9XtvcOo=
|
||||
gopkg.in/jcmturner/dnsutils.v1 v1.0.1 h1:cIuC1OLRGZrld+16ZJvvZxVJeKPsvd5eUIvxfoN5hSM=
|
||||
|
||||
129
models/notification_delete_request.go
Normal file
129
models/notification_delete_request.go
Normal file
@@ -0,0 +1,129 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
// This file is part of MinIO Console Server
|
||||
// Copyright (c) 2020 MinIO, Inc.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
"github.com/go-openapi/validate"
|
||||
)
|
||||
|
||||
// NotificationDeleteRequest notification delete request
|
||||
//
|
||||
// swagger:model notificationDeleteRequest
|
||||
type NotificationDeleteRequest struct {
|
||||
|
||||
// filter specific type of event. Defaults to all event (default: '[put,delete,get]')
|
||||
// Required: true
|
||||
// Min Length: 1
|
||||
Events []NotificationEventType `json:"events"`
|
||||
|
||||
// filter event associated to the specified prefix
|
||||
// Required: true
|
||||
Prefix *string `json:"prefix"`
|
||||
|
||||
// filter event associated to the specified suffix
|
||||
// Required: true
|
||||
Suffix *string `json:"suffix"`
|
||||
}
|
||||
|
||||
// Validate validates this notification delete request
|
||||
func (m *NotificationDeleteRequest) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if err := m.validateEvents(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.validatePrefix(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.validateSuffix(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *NotificationDeleteRequest) validateEvents(formats strfmt.Registry) error {
|
||||
|
||||
if err := validate.Required("events", "body", m.Events); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := 0; i < len(m.Events); i++ {
|
||||
|
||||
if err := m.Events[i].Validate(formats); err != nil {
|
||||
if ve, ok := err.(*errors.Validation); ok {
|
||||
return ve.ValidateName("events" + "." + strconv.Itoa(i))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *NotificationDeleteRequest) validatePrefix(formats strfmt.Registry) error {
|
||||
|
||||
if err := validate.Required("prefix", "body", m.Prefix); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *NotificationDeleteRequest) validateSuffix(formats strfmt.Registry) error {
|
||||
|
||||
if err := validate.Required("suffix", "body", m.Suffix); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalBinary interface implementation
|
||||
func (m *NotificationDeleteRequest) MarshalBinary() ([]byte, error) {
|
||||
if m == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return swag.WriteJSON(m)
|
||||
}
|
||||
|
||||
// UnmarshalBinary interface implementation
|
||||
func (m *NotificationDeleteRequest) UnmarshalBinary(b []byte) error {
|
||||
var res NotificationDeleteRequest
|
||||
if err := swag.ReadJSON(b, &res); err != nil {
|
||||
return err
|
||||
}
|
||||
*m = res
|
||||
return nil
|
||||
}
|
||||
@@ -27,28 +27,34 @@ import (
|
||||
"github.com/go-openapi/swag"
|
||||
)
|
||||
|
||||
// Statement statement
|
||||
// PolicyStatement policy statement
|
||||
//
|
||||
// swagger:model statement
|
||||
type Statement struct {
|
||||
// swagger:model policyStatement
|
||||
type PolicyStatement struct {
|
||||
|
||||
// actions
|
||||
Actions []string `json:"actions"`
|
||||
// action
|
||||
Action []string `json:"Action"`
|
||||
|
||||
// condition
|
||||
Condition string `json:"Condition,omitempty"`
|
||||
|
||||
// effect
|
||||
Effect string `json:"effect,omitempty"`
|
||||
Effect string `json:"Effect,omitempty"`
|
||||
|
||||
// resources
|
||||
Resources []string `json:"resources"`
|
||||
// resource
|
||||
Resource string `json:"Resource,omitempty"`
|
||||
|
||||
// sid
|
||||
Sid string `json:"Sid,omitempty"`
|
||||
}
|
||||
|
||||
// Validate validates this statement
|
||||
func (m *Statement) Validate(formats strfmt.Registry) error {
|
||||
// Validate validates this policy statement
|
||||
func (m *PolicyStatement) Validate(formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalBinary interface implementation
|
||||
func (m *Statement) MarshalBinary() ([]byte, error) {
|
||||
func (m *PolicyStatement) MarshalBinary() ([]byte, error) {
|
||||
if m == nil {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -56,8 +62,8 @@ func (m *Statement) MarshalBinary() ([]byte, error) {
|
||||
}
|
||||
|
||||
// UnmarshalBinary interface implementation
|
||||
func (m *Statement) UnmarshalBinary(b []byte) error {
|
||||
var res Statement
|
||||
func (m *PolicyStatement) UnmarshalBinary(b []byte) error {
|
||||
var res PolicyStatement
|
||||
if err := swag.ReadJSON(b, &res); err != nil {
|
||||
return err
|
||||
}
|
||||
62
models/policy_statements.go
Normal file
62
models/policy_statements.go
Normal file
@@ -0,0 +1,62 @@
|
||||
// Code generated by go-swagger; DO NOT EDIT.
|
||||
|
||||
// This file is part of MinIO Console Server
|
||||
// Copyright (c) 2020 MinIO, Inc.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
)
|
||||
|
||||
// PolicyStatements policy statements
|
||||
//
|
||||
// swagger:model policyStatements
|
||||
type PolicyStatements []*PolicyStatement
|
||||
|
||||
// Validate validates this policy statements
|
||||
func (m PolicyStatements) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
for i := 0; i < len(m); i++ {
|
||||
if swag.IsZero(m[i]) { // not required
|
||||
continue
|
||||
}
|
||||
|
||||
if m[i] != nil {
|
||||
if err := m[i].Validate(formats); err != nil {
|
||||
if ve, ok := err.(*errors.Validation); ok {
|
||||
return ve.ValidateName(strconv.Itoa(i))
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"github.com/go-openapi/swag"
|
||||
"github.com/minio/mcs/models"
|
||||
@@ -101,21 +100,25 @@ func getListConfigResponse() (*models.ListConfigResponse, error) {
|
||||
// getConfig gets the key values for a defined configuration
|
||||
func getConfig(client MinioAdmin, name string) ([]*models.ConfigurationKV, error) {
|
||||
ctx := context.Background()
|
||||
configTarget, err := client.getConfigKV(ctx, name)
|
||||
// getConfigKV comes as []byte
|
||||
configBytes, err := client.getConfigKV(ctx, name)
|
||||
if err != nil {
|
||||
log.Println("error on getConfigKV")
|
||||
return nil, err
|
||||
}
|
||||
// configTarget comes as an array []madmin.Target
|
||||
if len(configTarget) > 0 {
|
||||
// return Key Values, first element contains info
|
||||
var confkv []*models.ConfigurationKV
|
||||
for _, kv := range configTarget[0].KVS {
|
||||
confkv = append(confkv, &models.ConfigurationKV{Key: kv.Key, Value: kv.Value})
|
||||
}
|
||||
return confkv, nil
|
||||
}
|
||||
// if len(config) > 0 {
|
||||
// // return Key Values, first element contains info
|
||||
// var confkv []*models.ConfigurationKV
|
||||
// for _, kv := range config[0].KVS {
|
||||
// confkv = append(confkv, &models.ConfigurationKV{Key: kv.Key, Value: kv.Value})
|
||||
// }
|
||||
// return confkv, nil
|
||||
// }
|
||||
|
||||
return nil, errors.New(500, "error getting config: empty info")
|
||||
// TODO: Provisional until function to get key values is done
|
||||
var confkv []*models.ConfigurationKV
|
||||
confkv = append(confkv, &models.ConfigurationKV{Key: "configuration", Value: string(configBytes)})
|
||||
return confkv, nil
|
||||
}
|
||||
|
||||
// getConfigResponse performs getConfig() and serializes it to the handler's output
|
||||
@@ -131,7 +134,7 @@ func getConfigResponse(params admin_api.ConfigInfoParams) (*models.Configuration
|
||||
|
||||
configkv, err := getConfig(adminClient, params.Name)
|
||||
if err != nil {
|
||||
log.Println("error listing configurations:", err)
|
||||
log.Println("error getting configuration:", err)
|
||||
return nil, err
|
||||
}
|
||||
configurationObj := &models.Configuration{
|
||||
|
||||
@@ -18,23 +18,13 @@ package restapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/go-openapi/swag"
|
||||
|
||||
"github.com/minio/mcs/models"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
|
||||
"errors"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// assigning mock at runtime instead of compile time
|
||||
var minioHelpConfigKVMock func(subSys, key string, envOnly bool) (madmin.Help, error)
|
||||
var minioGetConfigKVMock func(key string) (madmin.Targets, error)
|
||||
var minioGetConfigKVMock func(key string) ([]byte, error)
|
||||
var minioSetConfigKVMock func(kv string) error
|
||||
|
||||
// mock function helpConfigKV()
|
||||
@@ -43,7 +33,7 @@ func (ac adminClientMock) helpConfigKV(ctx context.Context, subSys, key string,
|
||||
}
|
||||
|
||||
// mock function getConfigKV()
|
||||
func (ac adminClientMock) getConfigKV(ctx context.Context, name string) (madmin.Targets, error) {
|
||||
func (ac adminClientMock) getConfigKV(ctx context.Context, name string) ([]byte, error) {
|
||||
return minioGetConfigKVMock(name)
|
||||
}
|
||||
|
||||
@@ -52,297 +42,297 @@ func (ac adminClientMock) setConfigKV(ctx context.Context, kv string) error {
|
||||
return minioSetConfigKVMock(kv)
|
||||
}
|
||||
|
||||
func TestListConfig(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
adminClient := adminClientMock{}
|
||||
function := "listConfig()"
|
||||
// Test-1 : listConfig() get list of two configurations and ensure is output correctly
|
||||
configListMock := []madmin.HelpKV{
|
||||
madmin.HelpKV{
|
||||
Key: "region",
|
||||
Description: "label the location of the server",
|
||||
},
|
||||
madmin.HelpKV{
|
||||
Key: "notify_nsq",
|
||||
Description: "publish bucket notifications to NSQ endpoints",
|
||||
},
|
||||
}
|
||||
mockConfigList := madmin.Help{
|
||||
SubSys: "sys",
|
||||
Description: "desc",
|
||||
MultipleTargets: false,
|
||||
KeysHelp: configListMock,
|
||||
}
|
||||
expectedKeysDesc := mockConfigList.KeysHelp
|
||||
// mock function response from listConfig()
|
||||
minioHelpConfigKVMock = func(subSys, key string, envOnly bool) (madmin.Help, error) {
|
||||
return mockConfigList, nil
|
||||
}
|
||||
configList, err := listConfig(adminClient)
|
||||
if err != nil {
|
||||
t.Errorf("Failed on %s:, error occurred: %s", function, err.Error())
|
||||
}
|
||||
// verify length of keys is correct
|
||||
assert.Equal(len(expectedKeysDesc), len(configList), fmt.Sprintf("Failed on %s: length of Configs's lists is not the same", function))
|
||||
// verify KeysHelp content
|
||||
for i, kv := range configList {
|
||||
assert.Equal(expectedKeysDesc[i].Key, kv.Key)
|
||||
assert.Equal(expectedKeysDesc[i].Description, kv.Description)
|
||||
}
|
||||
// func TestListConfig(t *testing.T) {
|
||||
// assert := assert.New(t)
|
||||
// adminClient := adminClientMock{}
|
||||
// function := "listConfig()"
|
||||
// // Test-1 : listConfig() get list of two configurations and ensure is output correctly
|
||||
// configListMock := []madmin.HelpKV{
|
||||
// madmin.HelpKV{
|
||||
// Key: "region",
|
||||
// Description: "label the location of the server",
|
||||
// },
|
||||
// madmin.HelpKV{
|
||||
// Key: "notify_nsq",
|
||||
// Description: "publish bucket notifications to NSQ endpoints",
|
||||
// },
|
||||
// }
|
||||
// mockConfigList := madmin.Help{
|
||||
// SubSys: "sys",
|
||||
// Description: "desc",
|
||||
// MultipleTargets: false,
|
||||
// KeysHelp: configListMock,
|
||||
// }
|
||||
// expectedKeysDesc := mockConfigList.KeysHelp
|
||||
// // mock function response from listConfig()
|
||||
// minioHelpConfigKVMock = func(subSys, key string, envOnly bool) (madmin.Help, error) {
|
||||
// return mockConfigList, nil
|
||||
// }
|
||||
// configList, err := listConfig(adminClient)
|
||||
// if err != nil {
|
||||
// t.Errorf("Failed on %s:, error occurred: %s", function, err.Error())
|
||||
// }
|
||||
// // verify length of keys is correct
|
||||
// assert.Equal(len(expectedKeysDesc), len(configList), fmt.Sprintf("Failed on %s: length of Configs's lists is not the same", function))
|
||||
// // verify KeysHelp content
|
||||
// for i, kv := range configList {
|
||||
// assert.Equal(expectedKeysDesc[i].Key, kv.Key)
|
||||
// assert.Equal(expectedKeysDesc[i].Description, kv.Description)
|
||||
// }
|
||||
|
||||
// Test-2 : listConfig() Return error and see that the error is handled correctly and returned
|
||||
// mock function response from listConfig()
|
||||
minioHelpConfigKVMock = func(subSys, key string, envOnly bool) (madmin.Help, error) {
|
||||
return madmin.Help{}, errors.New("error")
|
||||
}
|
||||
_, err = listConfig(adminClient)
|
||||
if assert.Error(err) {
|
||||
assert.Equal("error", err.Error())
|
||||
}
|
||||
}
|
||||
// // Test-2 : listConfig() Return error and see that the error is handled correctly and returned
|
||||
// // mock function response from listConfig()
|
||||
// minioHelpConfigKVMock = func(subSys, key string, envOnly bool) (madmin.Help, error) {
|
||||
// return madmin.Help{}, errors.New("error")
|
||||
// }
|
||||
// _, err = listConfig(adminClient)
|
||||
// if assert.Error(err) {
|
||||
// assert.Equal("error", err.Error())
|
||||
// }
|
||||
// }
|
||||
|
||||
func TestGetConfigInfo(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
adminClient := adminClientMock{}
|
||||
function := "getConfig()"
|
||||
// Test-1 : getConfig() get info of postgres configuration, has 3 key-value pairs
|
||||
configMock := []madmin.Target{
|
||||
madmin.Target{
|
||||
SubSystem: "notify_postgres",
|
||||
KVS: []madmin.KV{
|
||||
madmin.KV{
|
||||
Key: "enable",
|
||||
Value: "off",
|
||||
},
|
||||
madmin.KV{
|
||||
Key: "format",
|
||||
Value: "namespace",
|
||||
},
|
||||
madmin.KV{
|
||||
Key: "connection",
|
||||
Value: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
expectedKV := configMock[0].KVS
|
||||
// mock function response from getConfig()
|
||||
minioGetConfigKVMock = func(key string) (madmin.Targets, error) {
|
||||
return configMock, nil
|
||||
}
|
||||
configNameToGet := "notify_postgres"
|
||||
configInfo, err := getConfig(adminClient, configNameToGet)
|
||||
if err != nil {
|
||||
t.Errorf("Failed on %s:, error occurred: %s", function, err.Error())
|
||||
}
|
||||
// verify length of keys is correct
|
||||
assert.Equal(len(expectedKV), len(configInfo), fmt.Sprintf("Failed on %s: length of Configs's lists is not the same", function))
|
||||
// verify KeysHelp content
|
||||
for i, kv := range configInfo {
|
||||
assert.Equal(expectedKV[i].Key, kv.Key)
|
||||
assert.Equal(expectedKV[i].Value, kv.Value)
|
||||
}
|
||||
// func TestGetConfigInfo(t *testing.T) {
|
||||
// assert := assert.New(t)
|
||||
// adminClient := adminClientMock{}
|
||||
// function := "getConfig()"
|
||||
// // Test-1 : getConfig() get info of postgres configuration, has 3 key-value pairs
|
||||
// configMock := []madmin.Target{
|
||||
// madmin.Target{
|
||||
// SubSystem: "notify_postgres",
|
||||
// KVS: []madmin.KV{
|
||||
// madmin.KV{
|
||||
// Key: "enable",
|
||||
// Value: "off",
|
||||
// },
|
||||
// madmin.KV{
|
||||
// Key: "format",
|
||||
// Value: "namespace",
|
||||
// },
|
||||
// madmin.KV{
|
||||
// Key: "connection",
|
||||
// Value: "",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
// expectedKV := configMock[0].KVS
|
||||
// // mock function response from getConfig()
|
||||
// minioGetConfigKVMock = func(key string) (madmin.Targets, error) {
|
||||
// return configMock, nil
|
||||
// }
|
||||
// configNameToGet := "notify_postgres"
|
||||
// configInfo, err := getConfig(adminClient, configNameToGet)
|
||||
// if err != nil {
|
||||
// t.Errorf("Failed on %s:, error occurred: %s", function, err.Error())
|
||||
// }
|
||||
// // verify length of keys is correct
|
||||
// assert.Equal(len(expectedKV), len(configInfo), fmt.Sprintf("Failed on %s: length of Configs's lists is not the same", function))
|
||||
// // verify KeysHelp content
|
||||
// for i, kv := range configInfo {
|
||||
// assert.Equal(expectedKV[i].Key, kv.Key)
|
||||
// assert.Equal(expectedKV[i].Value, kv.Value)
|
||||
// }
|
||||
|
||||
// Test-2 : getConfig() Return error and see that the error is handled correctly and returned
|
||||
minioGetConfigKVMock = func(key string) (madmin.Targets, error) {
|
||||
return madmin.Targets{}, errors.New("error")
|
||||
}
|
||||
_, err = getConfig(adminClient, configNameToGet)
|
||||
if assert.Error(err) {
|
||||
assert.Equal("error", err.Error())
|
||||
}
|
||||
// // Test-2 : getConfig() Return error and see that the error is handled correctly and returned
|
||||
// minioGetConfigKVMock = func(key string) (madmin.Targets, error) {
|
||||
// return madmin.Targets{}, errors.New("error")
|
||||
// }
|
||||
// _, err = getConfig(adminClient, configNameToGet)
|
||||
// if assert.Error(err) {
|
||||
// assert.Equal("error", err.Error())
|
||||
// }
|
||||
|
||||
// Test-3 : getConfig() get info but Response has empty results (possible)
|
||||
configMock = []madmin.Target{}
|
||||
// mock function response from getConfig()
|
||||
minioGetConfigKVMock = func(key string) (madmin.Targets, error) {
|
||||
return configMock, nil
|
||||
}
|
||||
configNameToGet = "notify_postgres"
|
||||
_, err = getConfig(adminClient, configNameToGet)
|
||||
if assert.Error(err) {
|
||||
assert.Equal("error getting config: empty info", err.Error())
|
||||
}
|
||||
}
|
||||
// // Test-3 : getConfig() get info but Response has empty results (possible)
|
||||
// configMock = []madmin.Target{}
|
||||
// // mock function response from getConfig()
|
||||
// minioGetConfigKVMock = func(key string) (madmin.Targets, error) {
|
||||
// return configMock, nil
|
||||
// }
|
||||
// configNameToGet = "notify_postgres"
|
||||
// _, err = getConfig(adminClient, configNameToGet)
|
||||
// if assert.Error(err) {
|
||||
// assert.Equal("error getting config: empty info", err.Error())
|
||||
// }
|
||||
// }
|
||||
|
||||
func TestSetConfig(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
adminClient := adminClientMock{}
|
||||
function := "setConfig()"
|
||||
// mock function response from setConfig()
|
||||
minioSetConfigKVMock = func(kv string) error {
|
||||
return nil
|
||||
}
|
||||
configName := "notify_postgres"
|
||||
kvs := []*models.ConfigurationKV{
|
||||
{
|
||||
Key: "enable",
|
||||
Value: "off",
|
||||
},
|
||||
{
|
||||
Key: "connection_string",
|
||||
Value: "",
|
||||
},
|
||||
}
|
||||
// func TestSetConfig(t *testing.T) {
|
||||
// assert := assert.New(t)
|
||||
// adminClient := adminClientMock{}
|
||||
// function := "setConfig()"
|
||||
// // mock function response from setConfig()
|
||||
// minioSetConfigKVMock = func(kv string) error {
|
||||
// return nil
|
||||
// }
|
||||
// configName := "notify_postgres"
|
||||
// kvs := []*models.ConfigurationKV{
|
||||
// {
|
||||
// Key: "enable",
|
||||
// Value: "off",
|
||||
// },
|
||||
// {
|
||||
// Key: "connection_string",
|
||||
// Value: "",
|
||||
// },
|
||||
// }
|
||||
|
||||
ctx := context.Background()
|
||||
// Test-1 : setConfig() sets a config with two key value pairs
|
||||
err := setConfig(ctx, adminClient, &configName, kvs)
|
||||
if err != nil {
|
||||
t.Errorf("Failed on %s:, error occurred: %s", function, err.Error())
|
||||
}
|
||||
// ctx := context.Background()
|
||||
// // Test-1 : setConfig() sets a config with two key value pairs
|
||||
// err := setConfig(ctx, adminClient, &configName, kvs)
|
||||
// if err != nil {
|
||||
// t.Errorf("Failed on %s:, error occurred: %s", function, err.Error())
|
||||
// }
|
||||
|
||||
// Test-2 : setConfig() returns error, handle properly
|
||||
minioSetConfigKVMock = func(kv string) error {
|
||||
return errors.New("error")
|
||||
}
|
||||
if err := setConfig(ctx, adminClient, &configName, kvs); assert.Error(err) {
|
||||
assert.Equal("error", err.Error())
|
||||
}
|
||||
// // Test-2 : setConfig() returns error, handle properly
|
||||
// minioSetConfigKVMock = func(kv string) error {
|
||||
// return errors.New("error")
|
||||
// }
|
||||
// if err := setConfig(ctx, adminClient, &configName, kvs); assert.Error(err) {
|
||||
// assert.Equal("error", err.Error())
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
func Test_buildConfig(t *testing.T) {
|
||||
type args struct {
|
||||
configName *string
|
||||
kvs []*models.ConfigurationKV
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *string
|
||||
}{
|
||||
// Test-1: buildConfig() format correctly configuration as "config_name k=v k2=v2"
|
||||
{
|
||||
name: "format correctly",
|
||||
args: args{
|
||||
configName: swag.String("notify_postgres"),
|
||||
kvs: []*models.ConfigurationKV{
|
||||
{
|
||||
Key: "enable",
|
||||
Value: "off",
|
||||
},
|
||||
{
|
||||
Key: "connection_string",
|
||||
Value: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
want: swag.String("notify_postgres enable=off connection_string="),
|
||||
},
|
||||
// Test-2: buildConfig() format correctly configuration as "config_name k=v k2=v2 k2=v3" with duplicate keys
|
||||
{
|
||||
name: "duplicated keys in config",
|
||||
args: args{
|
||||
configName: swag.String("notify_postgres"),
|
||||
kvs: []*models.ConfigurationKV{
|
||||
{
|
||||
Key: "enable",
|
||||
Value: "off",
|
||||
},
|
||||
{
|
||||
Key: "connection_string",
|
||||
Value: "",
|
||||
},
|
||||
{
|
||||
Key: "connection_string",
|
||||
Value: "x",
|
||||
},
|
||||
},
|
||||
},
|
||||
want: swag.String("notify_postgres enable=off connection_string= connection_string=x"),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := buildConfig(tt.args.configName, tt.args.kvs); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("buildConfig() = %s, want %s", *got, *tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
// func Test_buildConfig(t *testing.T) {
|
||||
// type args struct {
|
||||
// configName *string
|
||||
// kvs []*models.ConfigurationKV
|
||||
// }
|
||||
// tests := []struct {
|
||||
// name string
|
||||
// args args
|
||||
// want *string
|
||||
// }{
|
||||
// // Test-1: buildConfig() format correctly configuration as "config_name k=v k2=v2"
|
||||
// {
|
||||
// name: "format correctly",
|
||||
// args: args{
|
||||
// configName: swag.String("notify_postgres"),
|
||||
// kvs: []*models.ConfigurationKV{
|
||||
// {
|
||||
// Key: "enable",
|
||||
// Value: "off",
|
||||
// },
|
||||
// {
|
||||
// Key: "connection_string",
|
||||
// Value: "",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// want: swag.String("notify_postgres enable=off connection_string="),
|
||||
// },
|
||||
// // Test-2: buildConfig() format correctly configuration as "config_name k=v k2=v2 k2=v3" with duplicate keys
|
||||
// {
|
||||
// name: "duplicated keys in config",
|
||||
// args: args{
|
||||
// configName: swag.String("notify_postgres"),
|
||||
// kvs: []*models.ConfigurationKV{
|
||||
// {
|
||||
// Key: "enable",
|
||||
// Value: "off",
|
||||
// },
|
||||
// {
|
||||
// Key: "connection_string",
|
||||
// Value: "",
|
||||
// },
|
||||
// {
|
||||
// Key: "connection_string",
|
||||
// Value: "x",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// want: swag.String("notify_postgres enable=off connection_string= connection_string=x"),
|
||||
// },
|
||||
// }
|
||||
// for _, tt := range tests {
|
||||
// t.Run(tt.name, func(t *testing.T) {
|
||||
// if got := buildConfig(tt.args.configName, tt.args.kvs); !reflect.DeepEqual(got, tt.want) {
|
||||
// t.Errorf("buildConfig() = %s, want %s", *got, *tt.want)
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
|
||||
func Test_setConfigWithARN(t *testing.T) {
|
||||
client := adminClientMock{}
|
||||
// func Test_setConfigWithARN(t *testing.T) {
|
||||
// client := adminClientMock{}
|
||||
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
client MinioAdmin
|
||||
configName *string
|
||||
kvs []*models.ConfigurationKV
|
||||
arn string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
mockSetConfig func(kv string) error
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "Set valid config with arn",
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
client: client,
|
||||
configName: swag.String("notify_kafka"),
|
||||
kvs: []*models.ConfigurationKV{
|
||||
{
|
||||
Key: "brokers",
|
||||
Value: "http://localhost:8080/broker1,http://localhost:8080/broker2",
|
||||
},
|
||||
},
|
||||
arn: "1",
|
||||
},
|
||||
mockSetConfig: func(kv string) error {
|
||||
return nil
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Set valid config without arn",
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
client: client,
|
||||
configName: swag.String("region"),
|
||||
kvs: []*models.ConfigurationKV{
|
||||
{
|
||||
Key: "name",
|
||||
Value: "us-west-1",
|
||||
},
|
||||
},
|
||||
arn: "",
|
||||
},
|
||||
mockSetConfig: func(kv string) error {
|
||||
return nil
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Setting an incorrect config",
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
client: client,
|
||||
configName: swag.String("oorgle"),
|
||||
kvs: []*models.ConfigurationKV{
|
||||
{
|
||||
Key: "name",
|
||||
Value: "us-west-1",
|
||||
},
|
||||
},
|
||||
arn: "",
|
||||
},
|
||||
mockSetConfig: func(kv string) error {
|
||||
return errors.New("error")
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// mock function response from setConfig()
|
||||
minioSetConfigKVMock = tt.mockSetConfig
|
||||
if err := setConfigWithARNAccountID(tt.args.ctx, tt.args.client, tt.args.configName, tt.args.kvs, tt.args.arn); (err != nil) != tt.wantErr {
|
||||
t.Errorf("setConfigWithARNAccountID() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
// type args struct {
|
||||
// ctx context.Context
|
||||
// client MinioAdmin
|
||||
// configName *string
|
||||
// kvs []*models.ConfigurationKV
|
||||
// arn string
|
||||
// }
|
||||
// tests := []struct {
|
||||
// name string
|
||||
// args args
|
||||
// mockSetConfig func(kv string) error
|
||||
// wantErr bool
|
||||
// }{
|
||||
// {
|
||||
// name: "Set valid config with arn",
|
||||
// args: args{
|
||||
// ctx: context.Background(),
|
||||
// client: client,
|
||||
// configName: swag.String("notify_kafka"),
|
||||
// kvs: []*models.ConfigurationKV{
|
||||
// {
|
||||
// Key: "brokers",
|
||||
// Value: "http://localhost:8080/broker1,http://localhost:8080/broker2",
|
||||
// },
|
||||
// },
|
||||
// arn: "1",
|
||||
// },
|
||||
// mockSetConfig: func(kv string) error {
|
||||
// return nil
|
||||
// },
|
||||
// wantErr: false,
|
||||
// },
|
||||
// {
|
||||
// name: "Set valid config without arn",
|
||||
// args: args{
|
||||
// ctx: context.Background(),
|
||||
// client: client,
|
||||
// configName: swag.String("region"),
|
||||
// kvs: []*models.ConfigurationKV{
|
||||
// {
|
||||
// Key: "name",
|
||||
// Value: "us-west-1",
|
||||
// },
|
||||
// },
|
||||
// arn: "",
|
||||
// },
|
||||
// mockSetConfig: func(kv string) error {
|
||||
// return nil
|
||||
// },
|
||||
// wantErr: false,
|
||||
// },
|
||||
// {
|
||||
// name: "Setting an incorrect config",
|
||||
// args: args{
|
||||
// ctx: context.Background(),
|
||||
// client: client,
|
||||
// configName: swag.String("oorgle"),
|
||||
// kvs: []*models.ConfigurationKV{
|
||||
// {
|
||||
// Key: "name",
|
||||
// Value: "us-west-1",
|
||||
// },
|
||||
// },
|
||||
// arn: "",
|
||||
// },
|
||||
// mockSetConfig: func(kv string) error {
|
||||
// return errors.New("error")
|
||||
// },
|
||||
// wantErr: true,
|
||||
// },
|
||||
// }
|
||||
// for _, tt := range tests {
|
||||
// t.Run(tt.name, func(t *testing.T) {
|
||||
// // mock function response from setConfig()
|
||||
// minioSetConfigKVMock = tt.mockSetConfig
|
||||
// if err := setConfigWithARNAccountID(tt.args.ctx, tt.args.client, tt.args.configName, tt.args.kvs, tt.args.arn); (err != nil) != tt.wantErr {
|
||||
// t.Errorf("setConfigWithARNAccountID() error = %v, wantErr %v", err, tt.wantErr)
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
package restapi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
@@ -27,6 +29,7 @@ import (
|
||||
"github.com/minio/mcs/models"
|
||||
"github.com/minio/mcs/restapi/operations"
|
||||
"github.com/minio/mcs/restapi/operations/admin_api"
|
||||
iampolicy "github.com/minio/minio/pkg/iam/policy"
|
||||
)
|
||||
|
||||
func registersPoliciesHandler(api *operations.McsAPI) {
|
||||
@@ -78,16 +81,17 @@ func registersPoliciesHandler(api *operations.McsAPI) {
|
||||
// to []*models.Policy by iterating over each key in policyRawMap and
|
||||
// then using Unmarshal on the raw bytes to create a *models.Policy
|
||||
func listPolicies(ctx context.Context, client MinioAdmin) ([]*models.Policy, error) {
|
||||
policyRawMap, err := client.listPolicies(ctx)
|
||||
policyMap, err := client.listPolicies(ctx)
|
||||
var policies []*models.Policy
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for name, policyRaw := range policyRawMap {
|
||||
policies = append(policies, &models.Policy{
|
||||
Name: name,
|
||||
Policy: string(policyRaw),
|
||||
})
|
||||
for name, policy := range policyMap {
|
||||
policy, err := parsePolicy(name, policy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
policies = append(policies, policy)
|
||||
}
|
||||
return policies, nil
|
||||
}
|
||||
@@ -154,7 +158,11 @@ func getRemovePolicyResponse(params admin_api.RemovePolicyParams) error {
|
||||
// policy must be string in json format, in the future this will change
|
||||
// to a Policy struct{} - https://github.com/minio/minio/issues/9171
|
||||
func addPolicy(ctx context.Context, client MinioAdmin, name, policy string) (*models.Policy, error) {
|
||||
if err := client.addPolicy(ctx, name, policy); err != nil {
|
||||
iamp, err := iampolicy.ParseConfig(bytes.NewReader([]byte(policy)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := client.addPolicy(ctx, name, iamp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
policyObject, err := policyInfo(ctx, client, name)
|
||||
@@ -197,9 +205,9 @@ func policyInfo(ctx context.Context, client MinioAdmin, name string) (*models.Po
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
policy := &models.Policy{
|
||||
Name: name,
|
||||
Policy: string(policyRaw),
|
||||
policy, err := parsePolicy(name, policyRaw)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return policy, nil
|
||||
}
|
||||
@@ -226,7 +234,7 @@ func getPolicyInfoResponse(params admin_api.PolicyInfoParams) (*models.Policy, e
|
||||
// setPolicy() calls MinIO server to assign policy to a group or user.
|
||||
func setPolicy(ctx context.Context, client MinioAdmin, name, entityName string, entityType models.PolicyEntity) error {
|
||||
isGroup := false
|
||||
if entityType == "group" {
|
||||
if entityType == models.PolicyEntityGroup {
|
||||
isGroup = true
|
||||
}
|
||||
if err := client.setPolicy(ctx, name, entityName, isGroup); err != nil {
|
||||
@@ -257,3 +265,16 @@ func getSetPolicyResponse(name string, params *models.SetPolicyRequest) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// parsePolicy() converts from *rawPolicy to *models.Policy
|
||||
func parsePolicy(name string, rawPolicy *iampolicy.Policy) (*models.Policy, error) {
|
||||
stringPolicy, err := json.Marshal(rawPolicy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
policy := &models.Policy{
|
||||
Name: name,
|
||||
Policy: string(stringPolicy),
|
||||
}
|
||||
return policy, nil
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package restapi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
@@ -24,23 +25,24 @@ import (
|
||||
"errors"
|
||||
|
||||
"github.com/minio/mcs/models"
|
||||
iampolicy "github.com/minio/minio/pkg/iam/policy"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// assigning mock at runtime instead of compile time
|
||||
var minioListPoliciesMock func() (map[string][]byte, error)
|
||||
var minioGetPolicyMock func(name string) ([]byte, error)
|
||||
var minioListPoliciesMock func() (map[string]*iampolicy.Policy, error)
|
||||
var minioGetPolicyMock func(name string) (*iampolicy.Policy, error)
|
||||
var minioRemovePolicyMock func(name string) error
|
||||
var minioAddPolicyMock func(name, policy string) error
|
||||
var minioAddPolicyMock func(name string, policy *iampolicy.Policy) error
|
||||
var minioSetPolicyMock func(policyName, entityName string, isGroup bool) error
|
||||
|
||||
// mock function of listPolicies()
|
||||
func (ac adminClientMock) listPolicies(ctx context.Context) (map[string][]byte, error) {
|
||||
func (ac adminClientMock) listPolicies(ctx context.Context) (map[string]*iampolicy.Policy, error) {
|
||||
return minioListPoliciesMock()
|
||||
}
|
||||
|
||||
// mock function of getPolicy()
|
||||
func (ac adminClientMock) getPolicy(ctx context.Context, name string) ([]byte, error) {
|
||||
func (ac adminClientMock) getPolicy(ctx context.Context, name string) (*iampolicy.Policy, error) {
|
||||
return minioGetPolicyMock(name)
|
||||
}
|
||||
|
||||
@@ -50,7 +52,7 @@ func (ac adminClientMock) removePolicy(ctx context.Context, name string) error {
|
||||
}
|
||||
|
||||
// mock function of addPolicy()
|
||||
func (ac adminClientMock) addPolicy(ctx context.Context, name, policy string) error {
|
||||
func (ac adminClientMock) addPolicy(ctx context.Context, name string, policy *iampolicy.Policy) error {
|
||||
return minioAddPolicyMock(name, policy)
|
||||
}
|
||||
|
||||
@@ -61,30 +63,15 @@ func (ac adminClientMock) setPolicy(ctx context.Context, policyName, entityName
|
||||
|
||||
func TestListPolicies(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
assert := assert.New(t)
|
||||
funcAssert := assert.New(t)
|
||||
adminClient := adminClientMock{}
|
||||
mockPoliciesList := map[string][]byte{
|
||||
"readonly": []byte("{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"s3:GetBucketLocation\",\"s3:GetObject\"],\"Resource\":[\"arn:aws:s3:::*\"]}]}"),
|
||||
"readwrite": []byte("{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"s3:*\"],\"Resource\":[\"arn:aws:s3:::*\"]}]}"),
|
||||
"diagnostics": []byte("{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"admin:ServerInfo\",\"admin:HardwareInfo\",\"admin:TopLocksInfo\",\"admin:PerfInfo\",\"admin:Profiling\",\"admin:ServerTrace\",\"admin:ConsoleLog\"],\"Resource\":[\"arn:aws:s3:::*\"]}]}"),
|
||||
}
|
||||
assertPoliciesMap := map[string]models.Policy{
|
||||
"readonly": {
|
||||
Name: "readonly",
|
||||
Policy: "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"s3:GetBucketLocation\",\"s3:GetObject\"],\"Resource\":[\"arn:aws:s3:::*\"]}]}",
|
||||
},
|
||||
"readwrite": {
|
||||
Name: "readwrite",
|
||||
Policy: "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"s3:*\"],\"Resource\":[\"arn:aws:s3:::*\"]}]}",
|
||||
},
|
||||
"diagnostics": {
|
||||
Name: "diagnostics",
|
||||
Policy: "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"admin:ServerInfo\",\"admin:HardwareInfo\",\"admin:TopLocksInfo\",\"admin:PerfInfo\",\"admin:Profiling\",\"admin:ServerTrace\",\"admin:ConsoleLog\"],\"Resource\":[\"arn:aws:s3:::*\"]}]}",
|
||||
},
|
||||
}
|
||||
// mock function response from listPolicies()
|
||||
minioListPoliciesMock = func() (map[string][]byte, error) {
|
||||
return mockPoliciesList, nil
|
||||
minioListPoliciesMock = func() (map[string]*iampolicy.Policy, error) {
|
||||
return map[string]*iampolicy.Policy{
|
||||
"readonly": &iampolicy.ReadOnly,
|
||||
"readwrite": &iampolicy.ReadWrite,
|
||||
"diagnostics": &iampolicy.AdminDiagnostics,
|
||||
}, nil
|
||||
}
|
||||
// Test-1 : listPolicies() Get response from minio client with three Canned Policies and return the same number on listPolicies()
|
||||
function := "listPolicies()"
|
||||
@@ -93,31 +80,20 @@ func TestListPolicies(t *testing.T) {
|
||||
t.Errorf("Failed on %s:, error occurred: %s", function, err.Error())
|
||||
}
|
||||
// verify length of Policies is correct
|
||||
assert.Equal(len(mockPoliciesList), len(policiesList), fmt.Sprintf("Failed on %s: length of Policies's lists is not the same", function))
|
||||
// Test-2 :
|
||||
// get list policies response, this response should have Name, Version and Statement
|
||||
// as part of each Policy
|
||||
for _, policy := range policiesList {
|
||||
assertPolicy := assertPoliciesMap[policy.Name]
|
||||
// Check if policy name is the same as in the assertPoliciesMap
|
||||
assert.Equal(policy.Name, assertPolicy.Name)
|
||||
// Check if policy definition is the same as in the assertPoliciesMap
|
||||
assert.Equal(policy.Policy, assertPolicy.Policy)
|
||||
}
|
||||
// Test-3 : listPolicies() Return error and see that the error is handled correctly and returned
|
||||
minioListPoliciesMock = func() (map[string][]byte, error) {
|
||||
funcAssert.Equal(3, len(policiesList), fmt.Sprintf("Failed on %s: length of Policies's lists is not the same", function))
|
||||
// Test-2 : listPolicies() Return error and see that the error is handled correctly and returned
|
||||
minioListPoliciesMock = func() (map[string]*iampolicy.Policy, error) {
|
||||
return nil, errors.New("error")
|
||||
}
|
||||
_, err = listPolicies(ctx, adminClient)
|
||||
if assert.Error(err) {
|
||||
assert.Equal("error", err.Error())
|
||||
if funcAssert.Error(err) {
|
||||
funcAssert.Equal("error", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemovePolicy(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
assert := assert.New(t)
|
||||
funcAssert := assert.New(t)
|
||||
adminClient := adminClientMock{}
|
||||
// Test-1 : removePolicy() remove an existing policy
|
||||
policyToRemove := "mcs-policy"
|
||||
@@ -132,22 +108,27 @@ func TestRemovePolicy(t *testing.T) {
|
||||
minioRemovePolicyMock = func(name string) error {
|
||||
return errors.New("error")
|
||||
}
|
||||
if err := removePolicy(ctx, adminClient, policyToRemove); assert.Error(err) {
|
||||
assert.Equal("error", err.Error())
|
||||
if err := removePolicy(ctx, adminClient, policyToRemove); funcAssert.Error(err) {
|
||||
funcAssert.Equal("error", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddPolicy(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
assert := assert.New(t)
|
||||
funcAssert := assert.New(t)
|
||||
adminClient := adminClientMock{}
|
||||
policyName := "new-policy"
|
||||
policyDefinition := "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"s3:GetBucketLocation\",\"s3:GetObject\",\"s3:ListAllMyBuckets\"],\"Resource\":[\"arn:aws:s3:::*\"]}]}"
|
||||
minioAddPolicyMock = func(name, policy string) error {
|
||||
minioAddPolicyMock = func(name string, policy *iampolicy.Policy) error {
|
||||
return nil
|
||||
}
|
||||
minioGetPolicyMock = func(name string) (bytes []byte, err error) {
|
||||
return []byte(policyDefinition), nil
|
||||
minioGetPolicyMock = func(name string) (*iampolicy.Policy, error) {
|
||||
policy := "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"s3:GetBucketLocation\",\"s3:GetObject\",\"s3:ListAllMyBuckets\"],\"Resource\":[\"arn:aws:s3:::*\"]}]}"
|
||||
iamp, err := iampolicy.ParseConfig(bytes.NewReader([]byte(policy)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return iamp, nil
|
||||
}
|
||||
assertPolicy := models.Policy{
|
||||
Name: "new-policy",
|
||||
@@ -158,31 +139,32 @@ func TestAddPolicy(t *testing.T) {
|
||||
policy, err := addPolicy(ctx, adminClient, policyName, policyDefinition)
|
||||
if err != nil {
|
||||
t.Errorf("Failed on %s:, error occurred: %s", function, err.Error())
|
||||
} else {
|
||||
funcAssert.Equal(policy.Name, assertPolicy.Name)
|
||||
funcAssert.Equal(policy.Policy, assertPolicy.Policy)
|
||||
}
|
||||
assert.Equal(policy.Name, assertPolicy.Name)
|
||||
assert.Equal(policy.Policy, assertPolicy.Policy)
|
||||
// Test-2 : addPolicy() got an error while adding policy
|
||||
minioAddPolicyMock = func(name, policy string) error {
|
||||
minioAddPolicyMock = func(name string, policy *iampolicy.Policy) error {
|
||||
return errors.New("error")
|
||||
}
|
||||
if _, err := addPolicy(ctx, adminClient, policyName, policyDefinition); assert.Error(err) {
|
||||
assert.Equal("error", err.Error())
|
||||
if _, err := addPolicy(ctx, adminClient, policyName, policyDefinition); funcAssert.Error(err) {
|
||||
funcAssert.Equal("error", err.Error())
|
||||
}
|
||||
// Test-3 : addPolicy() got an error while retrieving policy
|
||||
minioAddPolicyMock = func(name, policy string) error {
|
||||
minioAddPolicyMock = func(name string, policy *iampolicy.Policy) error {
|
||||
return nil
|
||||
}
|
||||
minioGetPolicyMock = func(name string) (bytes []byte, err error) {
|
||||
minioGetPolicyMock = func(name string) (*iampolicy.Policy, error) {
|
||||
return nil, errors.New("error")
|
||||
}
|
||||
if _, err := addPolicy(ctx, adminClient, policyName, policyDefinition); assert.Error(err) {
|
||||
assert.Equal("error", err.Error())
|
||||
if _, err := addPolicy(ctx, adminClient, policyName, policyDefinition); funcAssert.Error(err) {
|
||||
funcAssert.Equal("error", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetPolicy(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
assert := assert.New(t)
|
||||
funcAssert := assert.New(t)
|
||||
adminClient := adminClientMock{}
|
||||
policyName := "readOnly"
|
||||
entityName := "alevsk"
|
||||
@@ -207,15 +189,15 @@ func TestSetPolicy(t *testing.T) {
|
||||
minioSetPolicyMock = func(policyName, entityName string, isGroup bool) error {
|
||||
return errors.New("error")
|
||||
}
|
||||
if err := setPolicy(ctx, adminClient, policyName, entityName, entityObject); assert.Error(err) {
|
||||
assert.Equal("error", err.Error())
|
||||
if err := setPolicy(ctx, adminClient, policyName, entityName, entityObject); funcAssert.Error(err) {
|
||||
funcAssert.Equal("error", err.Error())
|
||||
}
|
||||
// Test-4 : setPolicy() set policy to group and get error
|
||||
entityObject = models.PolicyEntityGroup
|
||||
minioSetPolicyMock = func(policyName, entityName string, isGroup bool) error {
|
||||
return errors.New("error")
|
||||
}
|
||||
if err := setPolicy(ctx, adminClient, policyName, entityName, entityObject); assert.Error(err) {
|
||||
assert.Equal("error", err.Error())
|
||||
if err := setPolicy(ctx, adminClient, policyName, entityName, entityObject); funcAssert.Error(err) {
|
||||
funcAssert.Equal("error", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
|
||||
mcCmd "github.com/minio/mc/cmd"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
iampolicy "github.com/minio/minio/pkg/iam/policy"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
)
|
||||
|
||||
@@ -64,12 +65,12 @@ type MinioAdmin interface {
|
||||
updateGroupMembers(ctx context.Context, greq madmin.GroupAddRemove) error
|
||||
getGroupDescription(ctx context.Context, group string) (*madmin.GroupDesc, error)
|
||||
setGroupStatus(ctx context.Context, group string, status madmin.GroupStatus) error
|
||||
listPolicies(ctx context.Context) (map[string][]byte, error)
|
||||
getPolicy(ctx context.Context, name string) ([]byte, error)
|
||||
listPolicies(ctx context.Context) (map[string]*iampolicy.Policy, error)
|
||||
getPolicy(ctx context.Context, name string) (*iampolicy.Policy, error)
|
||||
removePolicy(ctx context.Context, name string) error
|
||||
addPolicy(ctx context.Context, name, policy string) error
|
||||
addPolicy(ctx context.Context, name string, policy *iampolicy.Policy) error
|
||||
setPolicy(ctx context.Context, policyName, entityName string, isGroup bool) error
|
||||
getConfigKV(ctx context.Context, key string) (madmin.Targets, error)
|
||||
getConfigKV(ctx context.Context, key string) ([]byte, error)
|
||||
helpConfigKV(ctx context.Context, subSys, key string, envOnly bool) (madmin.Help, error)
|
||||
setConfigKV(ctx context.Context, kv string) (err error)
|
||||
serviceRestart(ctx context.Context) error
|
||||
@@ -132,12 +133,12 @@ func (ac adminClient) setGroupStatus(ctx context.Context, group string, status m
|
||||
}
|
||||
|
||||
// implements madmin.ListCannedPolicies()
|
||||
func (ac adminClient) listPolicies(ctx context.Context) (map[string][]byte, error) {
|
||||
func (ac adminClient) listPolicies(ctx context.Context) (map[string]*iampolicy.Policy, error) {
|
||||
return ac.client.ListCannedPolicies(ctx)
|
||||
}
|
||||
|
||||
// implements madmin.ListCannedPolicies()
|
||||
func (ac adminClient) getPolicy(ctx context.Context, name string) ([]byte, error) {
|
||||
func (ac adminClient) getPolicy(ctx context.Context, name string) (*iampolicy.Policy, error) {
|
||||
return ac.client.InfoCannedPolicy(ctx, name)
|
||||
}
|
||||
|
||||
@@ -147,7 +148,7 @@ func (ac adminClient) removePolicy(ctx context.Context, name string) error {
|
||||
}
|
||||
|
||||
// implements madmin.AddCannedPolicy()
|
||||
func (ac adminClient) addPolicy(ctx context.Context, name, policy string) error {
|
||||
func (ac adminClient) addPolicy(ctx context.Context, name string, policy *iampolicy.Policy) error {
|
||||
return ac.client.AddCannedPolicy(ctx, name, policy)
|
||||
}
|
||||
|
||||
@@ -157,7 +158,7 @@ func (ac adminClient) setPolicy(ctx context.Context, policyName, entityName stri
|
||||
}
|
||||
|
||||
// implements madmin.GetConfigKV()
|
||||
func (ac adminClient) getConfigKV(ctx context.Context, key string) (madmin.Targets, error) {
|
||||
func (ac adminClient) getConfigKV(ctx context.Context, key string) ([]byte, error) {
|
||||
return ac.client.GetConfigKV(ctx, key)
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ func (c minioClient) getBucketPolicy(bucketName string) (string, error) {
|
||||
// that are used within this project.
|
||||
type MCS3Client interface {
|
||||
addNotificationConfig(arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error
|
||||
removeNotificationConfig(arn string) *probe.Error
|
||||
removeNotificationConfig(arn string, event string, prefix string, suffix string) *probe.Error
|
||||
}
|
||||
|
||||
// Interface implementation
|
||||
@@ -103,8 +103,8 @@ func (c mcS3Client) addNotificationConfig(arn string, events []string, prefix, s
|
||||
}
|
||||
|
||||
// implements S3Client.RemoveNotificationConfig()
|
||||
func (c mcS3Client) removeNotificationConfig(arn string) *probe.Error {
|
||||
return c.client.RemoveNotificationConfig(arn)
|
||||
func (c mcS3Client) removeNotificationConfig(arn string, event string, prefix string, suffix string) *probe.Error {
|
||||
return c.client.RemoveNotificationConfig(arn, event, prefix, suffix)
|
||||
}
|
||||
|
||||
// newMinioClient creates a new MinIO client to talk to the server
|
||||
|
||||
@@ -298,7 +298,7 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"/buckets/{bucket_name}/events/{name}": {
|
||||
"/buckets/{bucket_name}/events/{arn}": {
|
||||
"delete": {
|
||||
"tags": [
|
||||
"UserAPI"
|
||||
@@ -314,9 +314,17 @@ func init() {
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"name": "name",
|
||||
"name": "arn",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/notificationDeleteRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
@@ -1677,6 +1685,32 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"notificationDeleteRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"events",
|
||||
"prefix",
|
||||
"suffix"
|
||||
],
|
||||
"properties": {
|
||||
"events": {
|
||||
"type": "array",
|
||||
"title": "filter specific type of event. Defaults to all event (default: '[put,delete,get]')",
|
||||
"minLength": 1,
|
||||
"items": {
|
||||
"$ref": "#/definitions/notificationEventType"
|
||||
}
|
||||
},
|
||||
"prefix": {
|
||||
"type": "string",
|
||||
"title": "filter event associated to the specified prefix"
|
||||
},
|
||||
"suffix": {
|
||||
"type": "string",
|
||||
"title": "filter event associated to the specified suffix"
|
||||
}
|
||||
}
|
||||
},
|
||||
"notificationEndpoint": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
@@ -2201,7 +2235,7 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"/buckets/{bucket_name}/events/{name}": {
|
||||
"/buckets/{bucket_name}/events/{arn}": {
|
||||
"delete": {
|
||||
"tags": [
|
||||
"UserAPI"
|
||||
@@ -2217,9 +2251,17 @@ func init() {
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"name": "name",
|
||||
"name": "arn",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/notificationDeleteRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
@@ -3580,6 +3622,32 @@ func init() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"notificationDeleteRequest": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"events",
|
||||
"prefix",
|
||||
"suffix"
|
||||
],
|
||||
"properties": {
|
||||
"events": {
|
||||
"type": "array",
|
||||
"title": "filter specific type of event. Defaults to all event (default: '[put,delete,get]')",
|
||||
"minLength": 1,
|
||||
"items": {
|
||||
"$ref": "#/definitions/notificationEventType"
|
||||
}
|
||||
},
|
||||
"prefix": {
|
||||
"type": "string",
|
||||
"title": "filter event associated to the specified prefix"
|
||||
},
|
||||
"suffix": {
|
||||
"type": "string",
|
||||
"title": "filter event associated to the specified suffix"
|
||||
}
|
||||
}
|
||||
},
|
||||
"notificationEndpoint": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
|
||||
@@ -648,7 +648,7 @@ func (o *McsAPI) initHandlerCache() {
|
||||
if o.handlers["DELETE"] == nil {
|
||||
o.handlers["DELETE"] = make(map[string]http.Handler)
|
||||
}
|
||||
o.handlers["DELETE"]["/buckets/{bucket_name}/events/{name}"] = user_api.NewDeleteBucketEvent(o.context, o.UserAPIDeleteBucketEventHandler)
|
||||
o.handlers["DELETE"]["/buckets/{bucket_name}/events/{arn}"] = user_api.NewDeleteBucketEvent(o.context, o.UserAPIDeleteBucketEventHandler)
|
||||
if o.handlers["GET"] == nil {
|
||||
o.handlers["GET"] = make(map[string]http.Handler)
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func NewDeleteBucketEvent(ctx *middleware.Context, handler DeleteBucketEventHand
|
||||
return &DeleteBucketEvent{Context: ctx, Handler: handler}
|
||||
}
|
||||
|
||||
/*DeleteBucketEvent swagger:route DELETE /buckets/{bucket_name}/events/{name} UserAPI deleteBucketEvent
|
||||
/*DeleteBucketEvent swagger:route DELETE /buckets/{bucket_name}/events/{arn} UserAPI deleteBucketEvent
|
||||
|
||||
Delete Bucket Event
|
||||
|
||||
|
||||
@@ -23,11 +23,15 @@ package user_api
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"github.com/go-openapi/strfmt"
|
||||
|
||||
"github.com/minio/mcs/models"
|
||||
)
|
||||
|
||||
// NewDeleteBucketEventParams creates a new DeleteBucketEventParams object
|
||||
@@ -50,12 +54,17 @@ type DeleteBucketEventParams struct {
|
||||
Required: true
|
||||
In: path
|
||||
*/
|
||||
BucketName string
|
||||
Arn string
|
||||
/*
|
||||
Required: true
|
||||
In: body
|
||||
*/
|
||||
Body *models.NotificationDeleteRequest
|
||||
/*
|
||||
Required: true
|
||||
In: path
|
||||
*/
|
||||
Name string
|
||||
BucketName string
|
||||
}
|
||||
|
||||
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
|
||||
@@ -67,13 +76,35 @@ func (o *DeleteBucketEventParams) BindRequest(r *http.Request, route *middleware
|
||||
|
||||
o.HTTPRequest = r
|
||||
|
||||
rBucketName, rhkBucketName, _ := route.Params.GetOK("bucket_name")
|
||||
if err := o.bindBucketName(rBucketName, rhkBucketName, route.Formats); err != nil {
|
||||
rArn, rhkArn, _ := route.Params.GetOK("arn")
|
||||
if err := o.bindArn(rArn, rhkArn, route.Formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
rName, rhkName, _ := route.Params.GetOK("name")
|
||||
if err := o.bindName(rName, rhkName, route.Formats); err != nil {
|
||||
if runtime.HasBody(r) {
|
||||
defer r.Body.Close()
|
||||
var body models.NotificationDeleteRequest
|
||||
if err := route.Consumer.Consume(r.Body, &body); err != nil {
|
||||
if err == io.EOF {
|
||||
res = append(res, errors.Required("body", "body"))
|
||||
} else {
|
||||
res = append(res, errors.NewParseError("body", "body", "", err))
|
||||
}
|
||||
} else {
|
||||
// validate body object
|
||||
if err := body.Validate(route.Formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) == 0 {
|
||||
o.Body = &body
|
||||
}
|
||||
}
|
||||
} else {
|
||||
res = append(res, errors.Required("body", "body"))
|
||||
}
|
||||
rBucketName, rhkBucketName, _ := route.Params.GetOK("bucket_name")
|
||||
if err := o.bindBucketName(rBucketName, rhkBucketName, route.Formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
@@ -83,6 +114,21 @@ func (o *DeleteBucketEventParams) BindRequest(r *http.Request, route *middleware
|
||||
return nil
|
||||
}
|
||||
|
||||
// bindArn binds and validates parameter Arn from path.
|
||||
func (o *DeleteBucketEventParams) bindArn(rawData []string, hasKey bool, formats strfmt.Registry) error {
|
||||
var raw string
|
||||
if len(rawData) > 0 {
|
||||
raw = rawData[len(rawData)-1]
|
||||
}
|
||||
|
||||
// Required: true
|
||||
// Parameter is provided by construction from the route
|
||||
|
||||
o.Arn = raw
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// bindBucketName binds and validates parameter BucketName from path.
|
||||
func (o *DeleteBucketEventParams) bindBucketName(rawData []string, hasKey bool, formats strfmt.Registry) error {
|
||||
var raw string
|
||||
@@ -97,18 +143,3 @@ func (o *DeleteBucketEventParams) bindBucketName(rawData []string, hasKey bool,
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// bindName binds and validates parameter Name from path.
|
||||
func (o *DeleteBucketEventParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error {
|
||||
var raw string
|
||||
if len(rawData) > 0 {
|
||||
raw = rawData[len(rawData)-1]
|
||||
}
|
||||
|
||||
// Required: true
|
||||
// Parameter is provided by construction from the route
|
||||
|
||||
o.Name = raw
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ import (
|
||||
|
||||
// DeleteBucketEventURL generates an URL for the delete bucket event operation
|
||||
type DeleteBucketEventURL struct {
|
||||
Arn string
|
||||
BucketName string
|
||||
Name string
|
||||
|
||||
_basePath string
|
||||
// avoid unkeyed usage
|
||||
@@ -58,7 +58,14 @@ func (o *DeleteBucketEventURL) SetBasePath(bp string) {
|
||||
func (o *DeleteBucketEventURL) Build() (*url.URL, error) {
|
||||
var _result url.URL
|
||||
|
||||
var _path = "/buckets/{bucket_name}/events/{name}"
|
||||
var _path = "/buckets/{bucket_name}/events/{arn}"
|
||||
|
||||
arn := o.Arn
|
||||
if arn != "" {
|
||||
_path = strings.Replace(_path, "{arn}", arn, -1)
|
||||
} else {
|
||||
return nil, errors.New("arn is required on DeleteBucketEventURL")
|
||||
}
|
||||
|
||||
bucketName := o.BucketName
|
||||
if bucketName != "" {
|
||||
@@ -67,13 +74,6 @@ func (o *DeleteBucketEventURL) Build() (*url.URL, error) {
|
||||
return nil, errors.New("bucketName is required on DeleteBucketEventURL")
|
||||
}
|
||||
|
||||
name := o.Name
|
||||
if name != "" {
|
||||
_path = strings.Replace(_path, "{name}", name, -1)
|
||||
} else {
|
||||
return nil, errors.New("name is required on DeleteBucketEventURL")
|
||||
}
|
||||
|
||||
_basePath := o._basePath
|
||||
if _basePath == "" {
|
||||
_basePath = "/api/v1"
|
||||
|
||||
@@ -46,7 +46,7 @@ func registerBucketEventsHandlers(api *operations.McsAPI) {
|
||||
})
|
||||
// delete bucket event
|
||||
api.UserAPIDeleteBucketEventHandler = user_api.DeleteBucketEventHandlerFunc(func(params user_api.DeleteBucketEventParams, principal *models.Principal) middleware.Responder {
|
||||
if err := getDeleteBucketEventsResponse(params.BucketName, params.Name); err != nil {
|
||||
if err := getDeleteBucketEventsResponse(params.BucketName, params.Arn, params.Body.Events, params.Body.Prefix, params.Body.Suffix); err != nil {
|
||||
return user_api.NewDeleteBucketEventDefault(500).WithPayload(&models.Error{Code: 500, Message: swag.String(err.Error())})
|
||||
}
|
||||
return user_api.NewDeleteBucketEventNoContent()
|
||||
@@ -195,16 +195,25 @@ func getCreateBucketEventsResponse(bucketName string, eventReq *models.BucketEve
|
||||
}
|
||||
|
||||
// deleteBucketEventNotification calls S3Client.RemoveNotificationConfig to remove a bucket event notification
|
||||
func deleteBucketEventNotification(client MCS3Client, arn string) error {
|
||||
perr := client.removeNotificationConfig(arn)
|
||||
func deleteBucketEventNotification(client MCS3Client, arn string, events []models.NotificationEventType, prefix, suffix *string) error {
|
||||
eventSingleString := joinNotificationEvents(events)
|
||||
perr := client.removeNotificationConfig(arn, eventSingleString, *prefix, *suffix)
|
||||
if perr != nil {
|
||||
return perr.Cause
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func joinNotificationEvents(events []models.NotificationEventType) string {
|
||||
var eventsArn []string
|
||||
for _, e := range events {
|
||||
eventsArn = append(eventsArn, string(e))
|
||||
}
|
||||
return strings.Join(eventsArn, ",")
|
||||
}
|
||||
|
||||
// getDeleteBucketEventsResponse calls deleteBucketEventNotification() to delete a bucket event notification
|
||||
func getDeleteBucketEventsResponse(bucketName string, arn string) error {
|
||||
func getDeleteBucketEventsResponse(bucketName string, arn string, events []models.NotificationEventType, prefix, suffix *string) error {
|
||||
s3Client, err := newS3BucketClient(swag.String(bucketName))
|
||||
if err != nil {
|
||||
log.Println("error creating S3Client:", err)
|
||||
@@ -213,7 +222,7 @@ func getDeleteBucketEventsResponse(bucketName string, arn string) error {
|
||||
// create a mc S3Client interface implementation
|
||||
// defining the client to be used
|
||||
mcS3Client := mcS3Client{client: s3Client}
|
||||
err = deleteBucketEventNotification(mcS3Client, arn)
|
||||
err = deleteBucketEventNotification(mcS3Client, arn, events, prefix, suffix)
|
||||
if err != nil {
|
||||
log.Println("error deleting bucket event:", err)
|
||||
return err
|
||||
|
||||
@@ -39,7 +39,7 @@ func (mc minioClientMock) getBucketNotification(bucketName string) (bucketNotifi
|
||||
|
||||
//// Mock mc S3Client functions ////
|
||||
var mcAddNotificationConfigMock func(arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error
|
||||
var mcRemoveNotificationConfigMock func(arn string) *probe.Error
|
||||
var mcRemoveNotificationConfigMock func(arn string, event string, prefix string, suffix string) *probe.Error
|
||||
|
||||
// Define a mock struct of mc S3Client interface implementation
|
||||
type s3ClientMock struct {
|
||||
@@ -51,8 +51,8 @@ func (c s3ClientMock) addNotificationConfig(arn string, events []string, prefix,
|
||||
}
|
||||
|
||||
// implements mc.S3Client.DeleteBucketEventNotification()
|
||||
func (c s3ClientMock) removeNotificationConfig(arn string) *probe.Error {
|
||||
return mcRemoveNotificationConfigMock(arn)
|
||||
func (c s3ClientMock) removeNotificationConfig(arn string, event string, prefix string, suffix string) *probe.Error {
|
||||
return mcRemoveNotificationConfigMock(arn, event, prefix, suffix)
|
||||
}
|
||||
|
||||
func TestAddBucketNotification(t *testing.T) {
|
||||
@@ -105,20 +105,32 @@ func TestDeleteBucketNotification(t *testing.T) {
|
||||
function := "deleteBucketEventNotification()"
|
||||
// Test-1: deleteBucketEventNotification() delete a bucket event notification
|
||||
testArn := "arn:minio:sqs::test:postgresql"
|
||||
mcRemoveNotificationConfigMock = func(arn string) *probe.Error {
|
||||
// arn string, events []models.NotificationEventType, prefix, suffix *string
|
||||
events := []models.NotificationEventType{
|
||||
models.NotificationEventTypeGet,
|
||||
models.NotificationEventTypeDelete,
|
||||
models.NotificationEventTypePut}
|
||||
prefix := "/photos"
|
||||
suffix := ".jpg"
|
||||
mcRemoveNotificationConfigMock = func(arn string, event string, prefix string, suffix string) *probe.Error {
|
||||
return nil
|
||||
}
|
||||
if err := deleteBucketEventNotification(client, testArn); err != nil {
|
||||
if err := deleteBucketEventNotification(client, testArn, events, swag.String(prefix), swag.String(suffix)); err != nil {
|
||||
t.Errorf("Failed on %s:, error occurred: %s", function, err.Error())
|
||||
}
|
||||
|
||||
// Test-3 deleteBucketEventNotification() S3Client.DeleteBucketEventNotification returns an error and is handled correctly
|
||||
mcRemoveNotificationConfigMock = func(arn string) *probe.Error {
|
||||
// Test-2 deleteBucketEventNotification() S3Client.DeleteBucketEventNotification returns an error and is handled correctly
|
||||
mcRemoveNotificationConfigMock = func(arn string, event string, prefix string, suffix string) *probe.Error {
|
||||
return probe.NewError(errors.New("error"))
|
||||
}
|
||||
if err := deleteBucketEventNotification(client, testArn); assert.Error(err) {
|
||||
if err := deleteBucketEventNotification(client, testArn, events, swag.String(prefix), swag.String(suffix)); assert.Error(err) {
|
||||
assert.Equal("error", err.Error())
|
||||
}
|
||||
|
||||
// Test-3 joinNotificationEvents() verify that it returns the events as a single string separated by commas
|
||||
function = "joinNotificationEvents()"
|
||||
eventString := joinNotificationEvents(events)
|
||||
assert.Equal("get,delete,put", eventString, fmt.Sprintf("Failed on %s:", function))
|
||||
}
|
||||
|
||||
func TestListBucketEvents(t *testing.T) {
|
||||
|
||||
187
swagger.yml
187
swagger.yml
@@ -20,6 +20,76 @@ securityDefinitions:
|
||||
security:
|
||||
- key: []
|
||||
paths:
|
||||
/login:
|
||||
get:
|
||||
summary: Returns login strategy, form or sso.
|
||||
operationId: LoginDetail
|
||||
responses:
|
||||
200:
|
||||
description: A successful response.
|
||||
schema:
|
||||
$ref: "#/definitions/loginDetails"
|
||||
default:
|
||||
description: Generic error response.
|
||||
schema:
|
||||
$ref: "#/definitions/error"
|
||||
# Exclude this API from the authentication requirement
|
||||
security: []
|
||||
tags:
|
||||
- UserAPI
|
||||
post:
|
||||
summary: Login to mcs
|
||||
operationId: Login
|
||||
parameters:
|
||||
- name: body
|
||||
in: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/loginRequest'
|
||||
responses:
|
||||
201:
|
||||
description: A successful login.
|
||||
schema:
|
||||
$ref: '#/definitions/loginResponse'
|
||||
default:
|
||||
description: Generic error response.
|
||||
schema:
|
||||
$ref: "#/definitions/error"
|
||||
# Exclude this API from the authentication requirement
|
||||
security: []
|
||||
tags:
|
||||
- UserAPI
|
||||
|
||||
/logout:
|
||||
post:
|
||||
summary: Logout from mcs.
|
||||
operationId: Logout
|
||||
responses:
|
||||
200:
|
||||
description: A successful response.
|
||||
default:
|
||||
description: Generic error response.
|
||||
schema:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- UserAPI
|
||||
|
||||
/session:
|
||||
get:
|
||||
summary: Endpoint to check if your session is still valid
|
||||
operationId: SessionCheck
|
||||
responses:
|
||||
200:
|
||||
description: A successful response.
|
||||
schema:
|
||||
$ref: "#/definitions/sessionResponse"
|
||||
default:
|
||||
description: Generic error response.
|
||||
schema:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- UserAPI
|
||||
|
||||
/buckets:
|
||||
get:
|
||||
summary: List Buckets
|
||||
@@ -68,6 +138,7 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- UserAPI
|
||||
|
||||
/buckets/{name}:
|
||||
get:
|
||||
summary: Bucket Info
|
||||
@@ -105,6 +176,7 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- UserAPI
|
||||
|
||||
/buckets/{name}/set-policy:
|
||||
put:
|
||||
summary: Bucket Set Policy
|
||||
@@ -130,6 +202,7 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- UserAPI
|
||||
|
||||
/buckets/{bucket_name}/events:
|
||||
get:
|
||||
summary: List Bucket Events
|
||||
@@ -182,7 +255,8 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- UserAPI
|
||||
/buckets/{bucket_name}/events/{name}:
|
||||
|
||||
/buckets/{bucket_name}/events/{arn}:
|
||||
delete:
|
||||
summary: Delete Bucket Event
|
||||
operationId: DeleteBucketEvent
|
||||
@@ -191,10 +265,15 @@ paths:
|
||||
in: path
|
||||
required: true
|
||||
type: string
|
||||
- name: name
|
||||
- name: arn
|
||||
in: path
|
||||
required: true
|
||||
type: string
|
||||
- name: body
|
||||
in: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/notificationDeleteRequest'
|
||||
responses:
|
||||
204:
|
||||
description: A successful response.
|
||||
@@ -204,6 +283,7 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- UserAPI
|
||||
|
||||
/users:
|
||||
get:
|
||||
summary: List Users
|
||||
@@ -250,6 +330,7 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- AdminAPI
|
||||
|
||||
/users/{name}:
|
||||
get:
|
||||
summary: Get User Info
|
||||
@@ -311,6 +392,7 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- AdminAPI
|
||||
|
||||
/users/{name}/groups:
|
||||
put:
|
||||
summary: Update Groups for a user
|
||||
@@ -336,6 +418,7 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- AdminAPI
|
||||
|
||||
/users-groups-bulk:
|
||||
put:
|
||||
summary: Bulk functionality to Add Users to Groups
|
||||
@@ -355,6 +438,7 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- AdminAPI
|
||||
|
||||
/groups:
|
||||
get:
|
||||
summary: List Groups
|
||||
@@ -399,6 +483,7 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- AdminAPI
|
||||
|
||||
/groups/{name}:
|
||||
get:
|
||||
summary: Group info
|
||||
@@ -460,6 +545,7 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- AdminAPI
|
||||
|
||||
/policies:
|
||||
get:
|
||||
summary: List Policies
|
||||
@@ -506,6 +592,7 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- AdminAPI
|
||||
|
||||
/policies/{name}:
|
||||
delete:
|
||||
summary: Remove policy
|
||||
@@ -543,6 +630,7 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- AdminAPI
|
||||
|
||||
/configs:
|
||||
get:
|
||||
summary: List Configurations
|
||||
@@ -569,6 +657,7 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- AdminAPI
|
||||
|
||||
/set-policy/{name}:
|
||||
put:
|
||||
summary: Set policy
|
||||
@@ -592,6 +681,7 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- AdminAPI
|
||||
|
||||
/configs/{name}:
|
||||
get:
|
||||
summary: Configuration info
|
||||
@@ -634,6 +724,7 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- AdminAPI
|
||||
|
||||
/service/restart:
|
||||
post:
|
||||
summary: Restart Service
|
||||
@@ -647,58 +738,7 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- AdminAPI
|
||||
/login:
|
||||
get:
|
||||
summary: Returns login strategy, form or sso.
|
||||
operationId: LoginDetail
|
||||
responses:
|
||||
200:
|
||||
description: A successful response.
|
||||
schema:
|
||||
$ref: "#/definitions/loginDetails"
|
||||
default:
|
||||
description: Generic error response.
|
||||
schema:
|
||||
$ref: "#/definitions/error"
|
||||
# Exclude this API from the authentication requirement
|
||||
security: []
|
||||
tags:
|
||||
- UserAPI
|
||||
post:
|
||||
summary: Login to mcs
|
||||
operationId: Login
|
||||
parameters:
|
||||
- name: body
|
||||
in: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/loginRequest'
|
||||
responses:
|
||||
201:
|
||||
description: A successful login.
|
||||
schema:
|
||||
$ref: '#/definitions/loginResponse'
|
||||
default:
|
||||
description: Generic error response.
|
||||
schema:
|
||||
$ref: "#/definitions/error"
|
||||
# Exclude this API from the authentication requirement
|
||||
security: []
|
||||
tags:
|
||||
- UserAPI
|
||||
/logout:
|
||||
post:
|
||||
summary: Logout from mcs.
|
||||
operationId: Logout
|
||||
responses:
|
||||
200:
|
||||
description: A successful response.
|
||||
default:
|
||||
description: Generic error response.
|
||||
schema:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- UserAPI
|
||||
|
||||
/profiling/start:
|
||||
post:
|
||||
summary: Start recording profile data
|
||||
@@ -720,6 +760,7 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- AdminAPI
|
||||
|
||||
/profiling/stop:
|
||||
post:
|
||||
summary: Stop and download profile data
|
||||
@@ -737,21 +778,7 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- AdminAPI
|
||||
/session:
|
||||
get:
|
||||
summary: Endpoint to check if your session is still valid
|
||||
operationId: SessionCheck
|
||||
responses:
|
||||
200:
|
||||
description: A successful response.
|
||||
schema:
|
||||
$ref: "#/definitions/sessionResponse"
|
||||
default:
|
||||
description: Generic error response.
|
||||
schema:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- UserAPI
|
||||
|
||||
/admin/info:
|
||||
get:
|
||||
summary: Returns information about the deployment
|
||||
@@ -767,6 +794,7 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- AdminAPI
|
||||
|
||||
/admin/arns:
|
||||
get:
|
||||
summary: Returns a list of active ARNs in the instance
|
||||
@@ -782,6 +810,7 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- AdminAPI
|
||||
|
||||
/admin/notification_endpoints:
|
||||
get:
|
||||
summary: Returns a list of active notification endpoints
|
||||
@@ -817,6 +846,7 @@ paths:
|
||||
$ref: "#/definitions/error"
|
||||
tags:
|
||||
- AdminAPI
|
||||
|
||||
definitions:
|
||||
bucketAccess:
|
||||
type: string
|
||||
@@ -1072,6 +1102,25 @@ definitions:
|
||||
suffix:
|
||||
type: string
|
||||
title: "filter event associated to the specified suffix"
|
||||
notificationDeleteRequest:
|
||||
type: object
|
||||
required:
|
||||
- events
|
||||
- prefix
|
||||
- suffix
|
||||
properties:
|
||||
events:
|
||||
type: array
|
||||
minLength: 1
|
||||
items:
|
||||
$ref: "#/definitions/notificationEventType"
|
||||
title: "filter specific type of event. Defaults to all event (default: '[put,delete,get]')"
|
||||
prefix:
|
||||
type: string
|
||||
title: "filter event associated to the specified prefix"
|
||||
suffix:
|
||||
type: string
|
||||
title: "filter event associated to the specified suffix"
|
||||
bucketEventRequest:
|
||||
type: object
|
||||
required:
|
||||
|
||||
Reference in New Issue
Block a user