diff --git a/CHANGELOG.md b/CHANGELOG.md index 83b29b20e1..7be43b3600 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ This format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v1.40.2](https://github.com/flipt-io/flipt/releases/tag/v1.40.2) - 2024-04-23 + +### Fixed + +- `cmd/grpc`: skip eval data service when evaluation API auth excluded (#3018) + ## [v1.40.1](https://github.com/flipt-io/flipt/releases/tag/v1.40.1) - 2024-04-11 ### Changed diff --git a/codecov.yml b/codecov.yml index 373bde27ca..b6d6869aaf 100644 --- a/codecov.yml +++ b/codecov.yml @@ -9,3 +9,4 @@ ignore: - "rpc/flipt/flipt.pb.*" - "rpc/flipt/meta" - "ui" + - "**/mock_*.go" diff --git a/core/go.mod b/core/go.mod index 2387bb212e..14a0e75cb5 100644 --- a/core/go.mod +++ b/core/go.mod @@ -17,7 +17,7 @@ require ( github.com/google/uuid v1.6.0 // indirect github.com/lib/pq v1.10.9 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect - golang.org/x/net v0.22.0 // indirect + golang.org/x/net v0.23.0 // indirect golang.org/x/text v0.14.0 // indirect google.golang.org/appengine v1.6.8 // indirect ) diff --git a/core/go.sum b/core/go.sum index 2ccb62a80d..f2004aa6cd 100644 --- a/core/go.sum +++ b/core/go.sum @@ -1,8 +1,11 @@ cuelabs.dev/go/oci/ociregistry v0.0.0-20240314152124-224736b49f2e h1:GwCVItFUPxwdsEYnlUcJ6PJxOjTeFFCKOh6QWg4oAzQ= +cuelabs.dev/go/oci/ociregistry v0.0.0-20240314152124-224736b49f2e/go.mod h1:ApHceQLLwcOkCEXM1+DyCXTHEJhNGDpJ2kmV6axsx24= cuelang.org/go v0.8.0 h1:fO1XPe/SUGtc7dhnGnTPbpIDoQm/XxhDtoSF7jzO01c= +cuelang.org/go v0.8.0/go.mod h1:CoDbYolfMms4BhWUlhD+t5ORnihR7wvjcfgyO9lL5FI= github.com/cockroachdb/apd/v3 v3.2.1 h1:U+8j7t0axsIgvQUqthuNm82HIrYXodOV2iWLWtEaIwg= github.com/cockroachdb/apd/v3 v3.2.1/go.mod h1:klXJcjp+FffLTHlhIG69tezTDvdP065naDsHzKhYSqc= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/emicklei/proto v1.10.0 h1:pDGyFRVV5RvV+nkBK9iy3q67FBy9Xa7vwrOTE+g5aGw= github.com/emicklei/proto v1.10.0/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A= github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= @@ -11,32 +14,76 @@ github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7 github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow= github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= +github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug= +github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/protocolbuffers/txtpbfmt v0.0.0-20230328191034-3462fbc510c0 h1:sadMIsgmHpEOGbUs6VtHBXRR1OHevnj7hLx9ZcdNGW4= github.com/protocolbuffers/txtpbfmt v0.0.0-20230328191034-3462fbc510c0/go.mod h1:jgxiZysxFPM+iWKwQwPR+y+Jvo54ARd4EisXxKYpB5c= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic= -golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= +golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= +golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/oauth2 v0.18.0 h1:09qnuIAgzdx1XplqJvW6CQqMCtGZykZWcXzPMPUusvI= +golang.org/x/oauth2 v0.18.0/go.mod h1:Wf7knwG0MPoWIMMBgFlEaSUDaKskp0dCfrlJRJXbBi8= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw= +golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= +google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/go.mod b/go.mod index 06b4ebbbdb..6e62ee78a7 100644 --- a/go.mod +++ b/go.mod @@ -40,7 +40,7 @@ require ( github.com/hashicorp/cap v0.6.0 github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/golang-lru/v2 v2.0.7 - github.com/lib/pq v1.10.9 + github.com/jackc/pgx/v5 v5.5.5 github.com/libsql/libsql-client-go v0.0.0-20230917132930-48c310b27e7b github.com/magefile/mage v1.15.0 github.com/mattn/go-sqlite3 v1.14.22 @@ -175,6 +175,10 @@ require ( github.com/hashicorp/go-uuid v1.0.3 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa // indirect + github.com/jackc/pgpassfile v1.0.0 // indirect + github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect + github.com/jackc/puddle/v2 v2.2.1 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect @@ -183,6 +187,7 @@ require ( github.com/kylelemons/godebug v1.1.0 // indirect github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect + github.com/lib/pq v1.10.9 // indirect github.com/libsql/sqlite-antlr4-parser v0.0.0-20230802215326-5cb5bb604475 // indirect github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect github.com/magiconair/properties v1.8.7 // indirect diff --git a/go.sum b/go.sum index 7ff9b02f4b..6ffcfb087b 100644 --- a/go.sum +++ b/go.sum @@ -395,8 +395,11 @@ github.com/jackc/pgconn v1.4.0/go.mod h1:Y2O3ZDF0q4mMacyWV3AstPJpeHXWGEetiFttmq5 github.com/jackc/pgconn v1.5.0/go.mod h1:QeD3lBfpTFe8WUnPZWN5KY/mB8FGMIYRdd8P8Jr0fAI= github.com/jackc/pgconn v1.5.1-0.20200601181101-fa742c524853/go.mod h1:QeD3lBfpTFe8WUnPZWN5KY/mB8FGMIYRdd8P8Jr0fAI= github.com/jackc/pgconn v1.8.0/go.mod h1:1C2Pb36bGIP9QHGBYCjnyhqu7Rv3sGshaQUvmfGIB/o= +github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa h1:s+4MhCQ6YrzisK6hFJUX53drDT4UsSW3DEhKn0ifuHw= +github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa/go.mod h1:a/s9Lp5W7n/DD0VrVoyJ00FbP2ytTPDVOivvn2bMlds= github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8= github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE= +github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= github.com/jackc/pgproto3 v1.1.0/go.mod h1:eR5FA3leWg7p9aeAqi37XOTgTIbkABlvcPB3E5rlc78= github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190420180111-c116219b62db/go.mod h1:bhq50y+xrl9n5mRYyCBFKkpRVTLYJVWeCc+mEAI3yXA= @@ -407,6 +410,8 @@ github.com/jackc/pgproto3/v2 v2.0.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwX github.com/jackc/pgproto3/v2 v2.0.6/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= github.com/jackc/pgservicefile v0.0.0-20200307190119-3430c5407db8/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E= github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01CGwFsrv11mJRHWJ6aifDLfdV3aVjFF0zg= github.com/jackc/pgtype v0.0.0-20190824184912-ab885b375b90/go.mod h1:KcahbBH1nCMSo2DXpzsoWOAfFkdEtEJpPbVLq8eE+mc= github.com/jackc/pgtype v0.0.0-20190828014616-a8802b16cc59/go.mod h1:MWlu30kVJrUS8lot6TQqcg7mtthZ9T0EoIBFiJcmcyw= @@ -421,11 +426,15 @@ github.com/jackc/pgx/v4 v4.5.0/go.mod h1:EpAKPLdnTorwmPUUsqrPxy5fphV18j9q3wrfRXg github.com/jackc/pgx/v4 v4.6.1-0.20200510190926-94ba730bb1e9/go.mod h1:t3/cdRQl6fOLDxqtlyhe9UWgfIi9R8+8v8GKV5TRA/o= github.com/jackc/pgx/v4 v4.6.1-0.20200606145419-4e5062306904/go.mod h1:ZDaNWkt9sW1JMiNn0kdYBaLelIhw7Pg4qd+Vk6tw7Hg= github.com/jackc/pgx/v4 v4.10.1/go.mod h1:QlrWebbs3kqEZPHCTGyxecvzG6tvIsYu+A5b1raylkA= +github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw= +github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A= github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.1.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.1.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= +github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= +github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= diff --git a/go.work.sum b/go.work.sum index 923e822037..dcfb499004 100644 --- a/go.work.sum +++ b/go.work.sum @@ -660,14 +660,21 @@ github.com/intel/goresctrl v0.2.0/go.mod h1:+CZdzouYFn5EsxgqAQTEzMfwKwuc0fVdMrT9 github.com/intel/goresctrl v0.3.0/go.mod h1:fdz3mD85cmP9sHD8JUlrNWAxvwM86CrbmVXltEKd7zk= github.com/j-keck/arping v0.0.0-20160618110441-2cf9dc699c56/go.mod h1:ymszkNOg6tORTn+6F6j+Jc8TOr5osrynvN6ivFWZ2GA= github.com/j-keck/arping v1.0.2/go.mod h1:aJbELhR92bSk7tp79AWM/ftfc90EfEi2bQJrbBFOsPw= +github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0= +github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8= +github.com/jackc/pgconn v1.14.0 h1:vrbA9Ud87g6JdFWkHTJXppVce58qPIdP7N8y0Ml/A7Q= github.com/jackc/pgconn v1.14.0/go.mod h1:9mBNlny0UvkgJdCDvdVHYSjI+8tD2rnKK69Wz8ti++E= -github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa/go.mod h1:a/s9Lp5W7n/DD0VrVoyJ00FbP2ytTPDVOivvn2bMlds= +github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE= +github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2 h1:JVX6jT/XfzNqIjye4717ITLaNwV9mWbJx0dLCpcRzdA= +github.com/jackc/pgproto3 v1.1.0 h1:FYYE4yRw+AgI8wXIinMlNjBbp/UitDJwfj5LqqewP1A= +github.com/jackc/pgproto3/v2 v2.3.2 h1:7eY55bdBeCz1F2fTzSz69QC+pG46jYq9/jtSPiJ5nn0= github.com/jackc/pgproto3/v2 v2.3.2/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= -github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgtype v1.14.0 h1:y+xUdabmyMkJLyApYuPj38mW+aAIqCe5uuBB51rH3Vw= github.com/jackc/pgtype v1.14.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4= +github.com/jackc/pgx/v4 v4.18.1 h1:YP7G1KABtKpB5IHrO9vYwSrCOhs7p3uqhvhhQBptya0= github.com/jackc/pgx/v4 v4.18.1/go.mod h1:FydWkUyadDmdNH/mHnGob881GawxeEm7TcMCzkb+qQE= -github.com/jackc/pgx/v5 v5.3.1/go.mod h1:t3JDKnCBlYIc0ewLF0Q7B8MXmoIaBOZj/ic7iHozM/8= -github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/jackc/puddle v1.1.3 h1:JnPg/5Q9xVJGfjsO5CPUOjnJps1JaRUm8I9FXVCFK94= +github.com/jackc/puddle v1.3.0 h1:eHK/5clGOatcjX3oWGBO/MpxpbHzSwud5EWTSCI+MX0= github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs= github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM= github.com/jcmturner/gofork v1.7.6/go.mod h1:1622LH6i/EZqLloHfE7IeZ0uEJwMSUyQ/nDd82IeqRo= @@ -1186,7 +1193,6 @@ golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= -golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= diff --git a/internal/cmd/grpc.go b/internal/cmd/grpc.go index 9cf5c4b13f..188e2f7834 100644 --- a/internal/cmd/grpc.go +++ b/internal/cmd/grpc.go @@ -227,6 +227,7 @@ func NewGRPCServer( skipAuthIfExcluded(fliptsrv, cfg.Authentication.Exclude.Management) skipAuthIfExcluded(evalsrv, cfg.Authentication.Exclude.Evaluation) + skipAuthIfExcluded(evalDataSrv, cfg.Authentication.Exclude.Evaluation) var checker *audit.Checker diff --git a/internal/storage/sql/adapted_driver.go b/internal/storage/sql/adapted_driver.go new file mode 100644 index 0000000000..7785be2e24 --- /dev/null +++ b/internal/storage/sql/adapted_driver.go @@ -0,0 +1,64 @@ +package sql + +import ( + "context" + "database/sql/driver" + "time" + + pgx "github.com/jackc/pgx/v5/stdlib" +) + +const adaptedDriverOpenTimeout = 60 * time.Second + +// This is the wrapper around sql driver. By default, pgx driver returns connection +// error with the host, username and password. `adaptedDriver` and `postgresConnector` +// allow to customize errors and preventing leakage of the credentials to outside. +func newAdaptedPostgresDriver(d Driver) driver.Driver { + return &adaptedDriver{origin: &pgx.Driver{}, adapter: d} +} + +var _ driver.Driver = (*adaptedDriver)(nil) +var _ driver.DriverContext = (*adaptedDriver)(nil) + +type adaptedDriver struct { + adapter Driver + origin driver.DriverContext +} + +func (d *adaptedDriver) Open(name string) (driver.Conn, error) { + connector, err := d.OpenConnector(name) + if err != nil { + return nil, d.adapter.AdaptError(err) + } + ctx, cancel := context.WithTimeout(context.Background(), adaptedDriverOpenTimeout) + defer cancel() + return connector.Connect(ctx) +} + +func (d *adaptedDriver) OpenConnector(name string) (driver.Connector, error) { + connector, err := d.origin.OpenConnector(name) + if err != nil { + return nil, d.adapter.AdaptError(err) + } + return &adaptedConnector{origin: connector, driver: d, adapter: d.adapter}, nil +} + +var _ driver.Connector = (*adaptedConnector)(nil) + +type adaptedConnector struct { + origin driver.Connector + driver driver.Driver + adapter Driver +} + +func (c *adaptedConnector) Driver() driver.Driver { + return c.driver +} + +func (c *adaptedConnector) Connect(ctx context.Context) (driver.Conn, error) { + conn, err := c.origin.Connect(ctx) + if err != nil { + return nil, c.adapter.AdaptError(err) + } + return conn, nil +} diff --git a/internal/storage/sql/adapted_driver_test.go b/internal/storage/sql/adapted_driver_test.go new file mode 100644 index 0000000000..2b29a25705 --- /dev/null +++ b/internal/storage/sql/adapted_driver_test.go @@ -0,0 +1,61 @@ +package sql + +import ( + "context" + + "testing" + + "github.com/jackc/pgx/v5/pgconn" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" +) + +func TestAdaptedDriver(t *testing.T) { + mockDriver := NewMockDriverContext(t) + t.Run("failure", func(t *testing.T) { + name := "pgx://failure" + mockDriver.On("OpenConnector", name).Return(nil, &pgconn.PgError{}) + d := &adaptedDriver{origin: mockDriver, adapter: Postgres} + _, err := d.Open(name) + require.Error(t, err) + }) + t.Run("success", func(t *testing.T) { + o := newMockConnector(t) + var mockConn = &mockDriverConn{} + o.On("Connect", mock.Anything).Once().Return(mockConn, nil) + name := "pgx://success" + mockDriver.On("OpenConnector", name).Return(o, nil) + d := &adaptedDriver{origin: mockDriver, adapter: Postgres} + conn, err := d.Open(name) + require.NoError(t, err) + require.Equal(t, mockConn, conn) + }) +} + +func TestAdaptedConnectorConnect(t *testing.T) { + o := newMockConnector(t) + d := &adaptedDriver{} + c := &adaptedConnector{ + origin: o, + adapter: Postgres, + driver: d, + } + require.Equal(t, d, c.Driver()) + t.Run("failure", func(t *testing.T) { + var mockConn *mockDriverConn + ctx := context.Background() + o.On("Connect", ctx).Once().Return(mockConn, &pgconn.ConnectError{}) + _, err := c.Connect(ctx) + require.Error(t, err) + require.Equal(t, err, errConnectionFailed) + }) + + t.Run("success", func(t *testing.T) { + var mockConn = &mockDriverConn{} + ctx := context.Background() + o.On("Connect", ctx).Once().Return(mockConn, nil) + conn, err := c.Connect(ctx) + require.NoError(t, err) + require.Equal(t, mockConn, conn) + }) +} diff --git a/internal/storage/sql/db.go b/internal/storage/sql/db.go index 6b253172b5..ef4bcf4b59 100644 --- a/internal/storage/sql/db.go +++ b/internal/storage/sql/db.go @@ -12,7 +12,7 @@ import ( sq "github.com/Masterminds/squirrel" "github.com/XSAM/otelsql" "github.com/go-sql-driver/mysql" - "github.com/lib/pq" + "github.com/libsql/libsql-client-go/libsql" "github.com/mattn/go-sqlite3" "github.com/xo/dburl" @@ -49,6 +49,9 @@ func init() { Aliases: []string{"libsql", "http", "https"}, Override: "file", }) + // drop references to lib/pq and relay on pgx + dburl.Unregister("postgres") + dburl.RegisterAlias("pgx", "postgres") } // Open opens a connection to the db @@ -123,10 +126,10 @@ func open(cfg config.Config, opts Options) (*sql.DB, Driver, error) { dr = &libsql.Driver{} attrs = []attribute.KeyValue{semconv.DBSystemSqlite} case Postgres: - dr = &pq.Driver{} + dr = newAdaptedPostgresDriver(d) attrs = []attribute.KeyValue{semconv.DBSystemPostgreSQL} case CockroachDB: - dr = &pq.Driver{} + dr = newAdaptedPostgresDriver(d) attrs = []attribute.KeyValue{semconv.DBSystemCockroachdb} case MySQL: dr = &mysql.MySQLDriver{} @@ -203,7 +206,7 @@ var ( stringToDriver = map[string]Driver{ "sqlite3": SQLite, "libsql": LibSQL, - "postgres": Postgres, + "pgx": Postgres, "mysql": MySQL, "cockroachdb": CockroachDB, "clickhouse": Clickhouse, diff --git a/internal/storage/sql/db_internal_test.go b/internal/storage/sql/db_internal_test.go index 66fdcf1f2c..dbd10b04f7 100644 --- a/internal/storage/sql/db_internal_test.go +++ b/internal/storage/sql/db_internal_test.go @@ -41,7 +41,7 @@ func TestParse(t *testing.T) { PreparedStatementsEnabled: true, }, driver: Postgres, - dsn: "dbname=flipt host=localhost port=5432 sslmode=disable user=postgres", + dsn: "postgres://postgres@localhost:5432/flipt?sslmode=disable", }, { name: "postgres url", @@ -49,7 +49,7 @@ func TestParse(t *testing.T) { URL: "postgres://postgres@localhost:5432/flipt?sslmode=disable", }, driver: Postgres, - dsn: "binary_parameters=yes dbname=flipt host=localhost port=5432 sslmode=disable user=postgres", + dsn: "postgres://postgres@localhost:5432/flipt?binary_parameters=yes&sslmode=disable", }, { name: "postgres no disable sslmode", @@ -57,7 +57,7 @@ func TestParse(t *testing.T) { URL: "postgres://postgres@localhost:5432/flipt", }, driver: Postgres, - dsn: "binary_parameters=yes dbname=flipt host=localhost port=5432 user=postgres", + dsn: "postgres://postgres@localhost:5432/flipt?binary_parameters=yes", }, { name: "postgres disable sslmode via opts", @@ -70,7 +70,7 @@ func TestParse(t *testing.T) { }, options: []Option{WithSSLDisabled}, driver: Postgres, - dsn: "binary_parameters=yes dbname=flipt host=localhost port=5432 sslmode=disable user=postgres", + dsn: "postgres://postgres@localhost:5432/flipt?binary_parameters=yes&sslmode=disable", }, { name: "postgres no port", @@ -81,7 +81,7 @@ func TestParse(t *testing.T) { User: "postgres", }, driver: Postgres, - dsn: "binary_parameters=yes dbname=flipt host=localhost user=postgres", + dsn: "postgres://postgres@localhost:5432/flipt?binary_parameters=yes", }, { name: "postgres no password", @@ -93,7 +93,7 @@ func TestParse(t *testing.T) { User: "postgres", }, driver: Postgres, - dsn: "binary_parameters=yes dbname=flipt host=localhost port=5432 user=postgres", + dsn: "postgres://postgres@localhost:5432/flipt?binary_parameters=yes", }, { name: "postgres with password", @@ -106,7 +106,7 @@ func TestParse(t *testing.T) { Password: "foo", }, driver: Postgres, - dsn: "binary_parameters=yes dbname=flipt host=localhost password=foo port=5432 user=postgres", + dsn: "postgres://postgres:foo@localhost:5432/flipt?binary_parameters=yes", }, { name: "mysql url", @@ -276,6 +276,15 @@ func TestParse(t *testing.T) { }, wantErr: true, }, + { + name: "postgres multi hosts url", + cfg: config.DatabaseConfig{ + URL: "postgres://user:pass@host1:5432,host2:2345/flipt?application_name=flipt&target_session_attrs=primary", + PreparedStatementsEnabled: false, + }, + driver: Postgres, + dsn: "postgres://user:pass@host1:5432,host2:2345/flipt?application_name=flipt&binary_parameters=yes&target_session_attrs=primary", + }, } for _, tt := range tests { diff --git a/internal/storage/sql/errors.go b/internal/storage/sql/errors.go index 82a2984dae..049af97af2 100644 --- a/internal/storage/sql/errors.go +++ b/internal/storage/sql/errors.go @@ -5,7 +5,7 @@ import ( "errors" "github.com/go-sql-driver/mysql" - "github.com/lib/pq" + "github.com/jackc/pgx/v5/pgconn" "github.com/mattn/go-sqlite3" errs "go.flipt.io/flipt/errors" ) @@ -16,6 +16,7 @@ var ( errNotUnique = errs.ErrInvalid("not unique") errForeignKeyNotFound = errs.ErrNotFound("associated resource not found") errCanceled = errs.ErrCanceled("query canceled") + errConnectionFailed = errs.ErrCanceled("failed to connect to database") ) // AdaptError converts specific known-driver errors into wrapped storage errors. @@ -61,15 +62,15 @@ func adaptSQLiteError(err error) error { func adaptPostgresError(err error) error { const ( - constraintForeignKeyErr = "foreign_key_violation" - constraintUniqueErr = "unique_violation" - queryCanceled = "query_canceled" + constraintForeignKeyErr = "23503" // "foreign_key_violation" + constraintUniqueErr = "23505" // "unique_violation" + queryCanceled = "57014" // "query_canceled" ) - var perr *pq.Error + var perr *pgconn.PgError if errors.As(err, &perr) { - switch perr.Code.Name() { + switch perr.Code { case constraintUniqueErr: return errNotUnique case constraintForeignKeyErr: @@ -79,6 +80,11 @@ func adaptPostgresError(err error) error { } } + var cerr *pgconn.ConnectError + if errors.As(err, &cerr) { + return errConnectionFailed + } + return err } diff --git a/internal/storage/sql/errors_test.go b/internal/storage/sql/errors_test.go index 94390db257..d4732f45bb 100644 --- a/internal/storage/sql/errors_test.go +++ b/internal/storage/sql/errors_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/go-sql-driver/mysql" - "github.com/lib/pq" + "github.com/jackc/pgx/v5/pgconn" "github.com/mattn/go-sqlite3" "github.com/stretchr/testify/require" "go.flipt.io/flipt/errors" @@ -97,25 +97,31 @@ func Test_AdaptError(t *testing.T) { {driver: Postgres}, { driver: Postgres, - inputErr: &pq.Error{}, + inputErr: &pgconn.PgError{}, }, { driver: Postgres, - inputErr: &pq.Error{Code: pq.ErrorCode("01000")}, + inputErr: &pgconn.PgError{Code: "01000"}, }, // Adjusted errors { driver: Postgres, // foreign_key_violation - inputErr: &pq.Error{Code: pq.ErrorCode("23503")}, + inputErr: &pgconn.PgError{Code: "23503"}, outputErrAs: errPtr(errors.ErrNotFound("")), }, { driver: Postgres, // unique_violation - inputErr: &pq.Error{Code: pq.ErrorCode("23505")}, + inputErr: &pgconn.PgError{Code: "23505"}, outputErrAs: errPtr(errors.ErrInvalid("")), }, + { + driver: Postgres, + // connection error + inputErr: &pgconn.ConnectError{}, + outputErrAs: errPtr(errConnectionFailed), + }, // MySQL // Unchanged errors {driver: MySQL}, diff --git a/internal/storage/sql/migrator.go b/internal/storage/sql/migrator.go index ee272a2b7a..d4709eb893 100644 --- a/internal/storage/sql/migrator.go +++ b/internal/storage/sql/migrator.go @@ -10,7 +10,7 @@ import ( clickhouseMigrate "github.com/golang-migrate/migrate/v4/database/clickhouse" "github.com/golang-migrate/migrate/v4/database/cockroachdb" "github.com/golang-migrate/migrate/v4/database/mysql" - "github.com/golang-migrate/migrate/v4/database/postgres" + "github.com/golang-migrate/migrate/v4/database/pgx/v5" "github.com/golang-migrate/migrate/v4/database/sqlite3" "github.com/golang-migrate/migrate/v4/source/iofs" "go.flipt.io/flipt/config/migrations" @@ -50,7 +50,7 @@ func NewMigrator(cfg config.Config, logger *zap.Logger) (*Migrator, error) { case SQLite, LibSQL: dr, err = sqlite3.WithInstance(sql, &sqlite3.Config{}) case Postgres: - dr, err = postgres.WithInstance(sql, &postgres.Config{}) + dr, err = pgx.WithInstance(sql, &pgx.Config{}) case CockroachDB: dr, err = cockroachdb.WithInstance(sql, &cockroachdb.Config{}) case MySQL: diff --git a/internal/storage/sql/mock_pg_driver.go b/internal/storage/sql/mock_pg_driver.go new file mode 100644 index 0000000000..0a35e8700b --- /dev/null +++ b/internal/storage/sql/mock_pg_driver.go @@ -0,0 +1,133 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package sql + +import ( + "context" + "database/sql/driver" + "errors" + + "github.com/stretchr/testify/mock" +) + +// MockConnector is an autogenerated mock type for the Connector type +type mockConnector struct { + mock.Mock +} + +// Connect provides a mock function with given fields: _a0 +func (_m *mockConnector) Connect(_a0 context.Context) (driver.Conn, error) { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for Connect") + } + + var r0 driver.Conn + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (driver.Conn, error)); ok { + return rf(_a0) + } + if rf, ok := ret.Get(0).(func(context.Context) driver.Conn); ok { + r0 = rf(_a0) + } else { + r0 = ret.Get(0).(driver.Conn) + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Driver provides a mock function with given fields: +func (_m *mockConnector) Driver() driver.Driver { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Driver") + } + + var r0 driver.Driver + if rf, ok := ret.Get(0).(func() driver.Driver); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(driver.Driver) + } + + return r0 +} + +// newMockConnector creates a new instance of MockConnector. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newMockConnector(t interface { + mock.TestingT + Cleanup(func()) +}) *mockConnector { + mock := &mockConnector{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} + +type mockDriverConn struct{} + +func (*mockDriverConn) Prepare(query string) (driver.Stmt, error) { + return nil, errors.New("unexpected call") +} +func (*mockDriverConn) Close() error { return nil } +func (*mockDriverConn) Begin() (driver.Tx, error) { return nil, errors.New("unexpected call") } + +// MockDriverContext is an autogenerated mock type for the DriverContext type +type MockDriverContext struct { + mock.Mock +} + +// OpenConnector provides a mock function with given fields: name +func (_m *MockDriverContext) OpenConnector(name string) (driver.Connector, error) { + ret := _m.Called(name) + + if len(ret) == 0 { + panic("no return value specified for OpenConnector") + } + + var r0 driver.Connector + var r1 error + if rf, ok := ret.Get(0).(func(string) (driver.Connector, error)); ok { + return rf(name) + } + if rf, ok := ret.Get(0).(func(string) driver.Connector); ok { + r0 = rf(name) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(driver.Connector) + } + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(name) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewMockDriverContext creates a new instance of MockDriverContext. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockDriverContext(t interface { + mock.TestingT + Cleanup(func()) +}) *MockDriverContext { + mock := &MockDriverContext{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/storage/sql/postgres/postgres.go b/internal/storage/sql/postgres/postgres.go index 9caa207f88..0a48d8ef5e 100644 --- a/internal/storage/sql/postgres/postgres.go +++ b/internal/storage/sql/postgres/postgres.go @@ -7,7 +7,7 @@ import ( "errors" sq "github.com/Masterminds/squirrel" - "github.com/lib/pq" + "github.com/jackc/pgx/v5/pgconn" errs "go.flipt.io/flipt/errors" "go.flipt.io/flipt/internal/storage" "go.flipt.io/flipt/internal/storage/sql/common" @@ -16,8 +16,8 @@ import ( ) const ( - constraintForeignKeyErr = "foreign_key_violation" - constraintUniqueErr = "unique_violation" + constraintForeignKeyErr = "23503" // "foreign_key_violation" + constraintUniqueErr = "23505" // "unique_violation" ) var _ storage.Store = &Store{} @@ -40,9 +40,9 @@ func (s *Store) CreateNamespace(ctx context.Context, r *flipt.CreateNamespaceReq namespace, err := s.Store.CreateNamespace(ctx, r) if err != nil { - var perr *pq.Error + var perr *pgconn.PgError - if errors.As(err, &perr) && perr.Code.Name() == constraintUniqueErr { + if errors.As(err, &perr) && perr.Code == constraintUniqueErr { return nil, errs.ErrInvalidf(`namespace %q is not unique`, r.Key) } @@ -56,10 +56,10 @@ func (s *Store) CreateFlag(ctx context.Context, r *flipt.CreateFlagRequest) (*fl flag, err := s.Store.CreateFlag(ctx, r) if err != nil { - var perr *pq.Error + var perr *pgconn.PgError if errors.As(err, &perr) { - switch perr.Code.Name() { + switch perr.Code { case constraintForeignKeyErr: return nil, errs.ErrNotFoundf("namespace %q", r.NamespaceKey) case constraintUniqueErr: @@ -77,10 +77,10 @@ func (s *Store) CreateVariant(ctx context.Context, r *flipt.CreateVariantRequest variant, err := s.Store.CreateVariant(ctx, r) if err != nil { - var perr *pq.Error + var perr *pgconn.PgError if errors.As(err, &perr) { - switch perr.Code.Name() { + switch perr.Code { case constraintForeignKeyErr: return nil, errs.ErrNotFoundf(`flag "%s/%s"`, r.NamespaceKey, r.FlagKey) case constraintUniqueErr: @@ -98,9 +98,9 @@ func (s *Store) UpdateVariant(ctx context.Context, r *flipt.UpdateVariantRequest variant, err := s.Store.UpdateVariant(ctx, r) if err != nil { - var perr *pq.Error + var perr *pgconn.PgError - if errors.As(err, &perr) && perr.Code.Name() == constraintUniqueErr { + if errors.As(err, &perr) && perr.Code == constraintUniqueErr { return nil, errs.ErrInvalidf(`variant %q is not unique for flag "%s/%s"`, r.Key, r.NamespaceKey, r.FlagKey) } @@ -114,10 +114,10 @@ func (s *Store) CreateSegment(ctx context.Context, r *flipt.CreateSegmentRequest segment, err := s.Store.CreateSegment(ctx, r) if err != nil { - var perr *pq.Error + var perr *pgconn.PgError if errors.As(err, &perr) { - switch perr.Code.Name() { + switch perr.Code { case constraintForeignKeyErr: return nil, errs.ErrNotFoundf("namespace %q", r.NamespaceKey) case constraintUniqueErr: @@ -135,9 +135,9 @@ func (s *Store) CreateConstraint(ctx context.Context, r *flipt.CreateConstraintR constraint, err := s.Store.CreateConstraint(ctx, r) if err != nil { - var perr *pq.Error + var perr *pgconn.PgError - if errors.As(err, &perr) && perr.Code.Name() == constraintForeignKeyErr { + if errors.As(err, &perr) && perr.Code == constraintForeignKeyErr { return nil, errs.ErrNotFoundf(`segment "%s/%s"`, r.NamespaceKey, r.SegmentKey) } @@ -151,9 +151,9 @@ func (s *Store) CreateRollout(ctx context.Context, r *flipt.CreateRolloutRequest rollout, err := s.Store.CreateRollout(ctx, r) if err != nil { - var perr *pq.Error + var perr *pgconn.PgError - if errors.As(err, &perr) && perr.Code.Name() == constraintForeignKeyErr { + if errors.As(err, &perr) && perr.Code == constraintForeignKeyErr { if segment := r.GetSegment(); segment != nil { return nil, errs.ErrNotFoundf(`flag "%s/%s or segment %s"`, r.NamespaceKey, r.FlagKey, segment.SegmentKey) } @@ -170,9 +170,9 @@ func (s *Store) CreateRule(ctx context.Context, r *flipt.CreateRuleRequest) (*fl rule, err := s.Store.CreateRule(ctx, r) if err != nil { - var perr *pq.Error + var perr *pgconn.PgError - if errors.As(err, &perr) && perr.Code.Name() == constraintForeignKeyErr { + if errors.As(err, &perr) && perr.Code == constraintForeignKeyErr { return nil, errs.ErrNotFoundf(`flag "%s/%s" or segment "%s/%s"`, r.NamespaceKey, r.FlagKey, r.NamespaceKey, r.SegmentKey) } @@ -186,9 +186,9 @@ func (s *Store) UpdateRule(ctx context.Context, r *flipt.UpdateRuleRequest) (*fl rule, err := s.Store.UpdateRule(ctx, r) if err != nil { - var perr *pq.Error + var perr *pgconn.PgError - if errors.As(err, &perr) && perr.Code.Name() == constraintForeignKeyErr { + if errors.As(err, &perr) && perr.Code == constraintForeignKeyErr { return nil, errs.ErrNotFoundf(`rule "%s/%s"`, r.NamespaceKey, r.Id) } @@ -202,9 +202,9 @@ func (s *Store) CreateDistribution(ctx context.Context, r *flipt.CreateDistribut dist, err := s.Store.CreateDistribution(ctx, r) if err != nil { - var perr *pq.Error + var perr *pgconn.PgError - if errors.As(err, &perr) && perr.Code.Name() == constraintForeignKeyErr { + if errors.As(err, &perr) && perr.Code == constraintForeignKeyErr { return nil, errs.ErrNotFoundf("variant %q, rule %q, flag %q in namespace %q", r.VariantId, r.RuleId, r.FlagKey, r.NamespaceKey) } diff --git a/sdk/go/go.mod b/sdk/go/go.mod index 0d6657a058..3626a861f6 100644 --- a/sdk/go/go.mod +++ b/sdk/go/go.mod @@ -19,7 +19,7 @@ require ( go.flipt.io/flipt/errors v1.19.3 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.27.0 // indirect - golang.org/x/net v0.22.0 // indirect + golang.org/x/net v0.23.0 // indirect golang.org/x/sys v0.18.0 // indirect golang.org/x/text v0.14.0 // indirect google.golang.org/genproto v0.0.0-20240311173647-c811ad7063a7 // indirect diff --git a/sdk/go/go.sum b/sdk/go/go.sum index 4f9d43fe5d..47d4f69cc4 100644 --- a/sdk/go/go.sum +++ b/sdk/go/go.sum @@ -18,6 +18,7 @@ github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= @@ -32,6 +33,7 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= @@ -51,7 +53,8 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= +golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= +golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -63,6 +66,7 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= @@ -78,14 +82,18 @@ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoA google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20240311173647-c811ad7063a7 h1:ImUcDPHjTrAqNhlOkSocDLfG9rrNHH7w7uoKWPaWZ8s= +google.golang.org/genproto v0.0.0-20240311173647-c811ad7063a7/go.mod h1:/3XmxOjePkvmKrHuBy4zNFw7IzxJXtAgdpXi8Ll990U= google.golang.org/genproto/googleapis/api v0.0.0-20240325203815-454cdb8f5daa h1:Jt1XW5PaLXF1/ePZrznsh/aAUvI7Adfc3LY1dAKlzRs= +google.golang.org/genproto/googleapis/api v0.0.0-20240325203815-454cdb8f5daa/go.mod h1:K4kfzHtI0kqWA79gecJarFtDn/Mls+GxQcg3Zox91Ac= google.golang.org/genproto/googleapis/rpc v0.0.0-20240325203815-454cdb8f5daa h1:RBgMaUMP+6soRkik4VoN8ojR2nex2TqZwjSSogic+eo= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240325203815-454cdb8f5daa/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk= +google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE= google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=