diff --git a/CHANGELOG.md b/CHANGELOG.md index 725b3f4e..ab2f3d45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Update to use wrp-go v3 to be able to use the MIME constants. [#252](https://github.com/xmidt-org/caduceus/pull/252) - Remove some unused code. [#254](https://github.com/xmidt-org/caduceus/pull/254) - Bump webpa-common version with xwebhook item ID format update. [#257](https://github.com/xmidt-org/caduceus/pull/257) +- Update webhook integration to use xmidt-org/ancla. [#259](https://github.com/xmidt-org/caduceus/pull/259) ## [v0.4.2] ### Fixed diff --git a/caduceus.yaml b/caduceus.yaml index c25322d3..b76fa560 100644 --- a/caduceus.yaml +++ b/caduceus.yaml @@ -237,17 +237,17 @@ authHeader: ["xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=", "dXNlcjpwYXNz"] # information using Argus. webhook: argus: - # bucket is the partition name for storing webhooks. - bucket: "webhooks" + # listen is the subsection that configures the listening feature of the argus client + # (Optional) + listen: + # pullInterval provides how often the current webhooks list gets refreshed. + pullInterval: 5s - # pullInterval provides how often the current webhooks list gets refreshed. - pullInterval: 5s + # bucket is the partition name where webhooks will be stored. + bucket: "webhooks" # address is Argus' network location. - address: "http://argus:6600" - - # adminToken provides internal access to webhooks stored on behalf of users. - adminToken: "Hzu1WpIe7S8G" + address: "http://localhost:6600" # auth the authentication method for argus. auth: diff --git a/caduceus_type.go b/caduceus_type.go index 7f4249c8..9ecfec8b 100644 --- a/caduceus_type.go +++ b/caduceus_type.go @@ -22,8 +22,8 @@ import ( "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" "github.com/go-kit/kit/metrics" + "github.com/xmidt-org/ancla" "github.com/xmidt-org/webpa-common/logging" - "github.com/xmidt-org/webpa-common/xwebhook" "github.com/xmidt-org/wrp-go/v3" ) @@ -35,7 +35,7 @@ type CaduceusConfig struct { JobQueueSize int Sender SenderConfig JWTValidators []JWTValidator - Webhook xwebhook.Config + Webhook ancla.Config AllowInsecureTLS bool } diff --git a/deploy/packaging/caduceus_spruce.yaml b/deploy/packaging/caduceus_spruce.yaml index c1ffd3c4..280bdbdc 100644 --- a/deploy/packaging/caduceus_spruce.yaml +++ b/deploy/packaging/caduceus_spruce.yaml @@ -237,18 +237,47 @@ jwtValidators: authHeader: - (( grab $AUTH_HEADER || "dXNlcjpwYXNz" )) +# authtoken used to make spruce work better for authAcquirer +authToken: (( grab $AUTH_TOKEN || "dXNlcjpwYXNz" )) + ######################################## # Webhook Related Configuration ######################################## # Argus Config for storing the webhook information -webhookStore: - bucket: (( grab $ARGUS_BUCKET || "webhooks" )) - address: (( grab $ARGUS_HOST || "argus:6600" )) - pullInterval: (( grab $ARGUS_PULL_INTERVAL || "2s" )) - adminToken: (( grab $ARGUS_ADMIN_TOKEN || "Hzu1WpIe7S8G" )) - defaultTTL: (( grab $ARGUS_DEFAULT_TTL || "300" )) - auth: - basic: (( grab $AUTH_HEADER || "Basic dXNlcjpwYXNz" )) +webhook: + argus: + listen: + # pullInterval is how often to call argus to update the webhook structure. + pullInterval: (( grab $ARGUS_PULL_INTERVAL || "5s" )) + + # bucket to store and retrieve webhooks. + bucket: (( grab $ARGUS_BUCKET || "webhooks" )) + + # address it the location to talk to argus. + address: (( grab $ARGUS_ENDPOINT || "http://argus:6600" )) + + # auth the authentication method for argus. + auth: + # basic configures basic authentication for argus. + # Must be of form: 'Basic xyz==' + basic: (( concat "Basic " authToken )) + + # # jwt configures jwt style authentication for argus. + # jwt: + # # requestHeaders are added to the request for the token. + # # (Optional) + # # requestHeaders: + # # "": "" + + # # authURL is the URL to access for the token. + # authURL: "http://themis:6501/issue" + + # # timeout is how long the request to get the token will take before + # # timing out. + # timeout: "1m" + + # # buffer is the length of time before a token expires to get a new token. + # buffer: "2m" ######################################## # Delivery Pipeline Related Configuration ######################################## diff --git a/go.mod b/go.mod index 35fac2c7..2dd972fa 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,8 @@ require ( github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.7.0 - github.com/stretchr/testify v1.5.1 - github.com/xmidt-org/webpa-common v1.11.5-0.20210120235745-b98c7113262c + github.com/stretchr/testify v1.7.0 + github.com/xmidt-org/ancla v0.1.2 + github.com/xmidt-org/webpa-common v1.11.5 github.com/xmidt-org/wrp-go/v3 v3.0.2 ) diff --git a/go.sum b/go.sum index 1d660f0f..2c4e4527 100644 --- a/go.sum +++ b/go.sum @@ -11,7 +11,9 @@ cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqCl cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +emperror.dev/emperror v0.30.0 h1:RLQ9WaCdFMD2Nhp/+8RN/iaXjaaqRCh+UFVrkThHOO4= emperror.dev/emperror v0.30.0/go.mod h1:ZasUgT1WGMbTYZzEWmyPuc6pCxRjO6Kp8lZz4FRRIiM= +emperror.dev/errors v0.7.0 h1:vf0gZ0j9BJCXQYm0M21DPKeXy9PUjvX1YHXhNzIsqOY= emperror.dev/errors v0.7.0/go.mod h1:X4dljzQehaz3WfBKc6c7bR+ve2ZsRzbBkFBF+HTcW0M= github.com/Azure/azure-sdk-for-go v16.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= github.com/Azure/go-autorest v10.7.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= @@ -610,6 +612,9 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tencentcloud/tencentcloud-sdk-go v3.0.83+incompatible/go.mod h1:0PfYow01SHPMhKY31xa+EFz2RStxIqj6JFAJS+IkCi4= @@ -626,11 +631,14 @@ github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijb github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/vmware/govmomi v0.18.0/go.mod h1:URlwyTFZX72RmxtxuaFL2Uj3fD1JTvZdx59bHWk6aFU= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/xmidt-org/ancla v0.1.2 h1:AXpbBKC1VR893LnQACFHNv9WQwtYm4yHyuMkg6FS9a0= +github.com/xmidt-org/ancla v0.1.2/go.mod h1:Hzc3XGTzuP4xIAVixK5qS9fbyB2rM1hUD7TMKIbHFd4= github.com/xmidt-org/argus v0.3.9 h1:zmKDRq5e3Gy/hPxym3U4S1aba4ehNnTYGmmsJYIClKU= github.com/xmidt-org/argus v0.3.9/go.mod h1:mDFS44R704gl9Fif3gkfAyvnZa53SvMepmXjYWABPvk= github.com/xmidt-org/argus v0.3.10-0.20201217204602-66f69b12c498 h1:Hs6xX7RLCB1YHdwVSfutQw/xxfawOf/C1Mi93Cjo3dk= github.com/xmidt-org/argus v0.3.10-0.20201217204602-66f69b12c498/go.mod h1:lnMCVB/i0gOlUOOd2WbzDDgzTEqP5TipzQ8xKIw+N/I= -github.com/xmidt-org/argus v0.3.10-0.20210120221042-bffa41d6f5c9/go.mod h1:8hg7zvFS/217+zY2yNxKIvfPs5+qzAPLfeJN0aWjF84= +github.com/xmidt-org/argus v0.3.12 h1:U51WL5+1VVmiiXNtKdGputhoeWHAhQQnAwYisZErj9w= +github.com/xmidt-org/argus v0.3.12/go.mod h1:T0oHbqQ1SAjE616Q9f1p+7nsmuvmHNoC0zAIUpUiFuE= github.com/xmidt-org/arrange v0.1.9 h1:MgMCRH7uMg+LZWvuo3c+63UmEV73LRMyrYmm267E8oM= github.com/xmidt-org/arrange v0.1.9/go.mod h1:PRA8iEZ11L93NsEkDP56x1mZyfDcWxzDULgHj56TaEk= github.com/xmidt-org/bascule v0.8.0 h1:xk/c8zqqNjoSW4b4oSrUwemm786Bs5DabmX7AgUgNPw= @@ -639,6 +647,8 @@ github.com/xmidt-org/bascule v0.8.1 h1:8EWPhNf2GzLS70ttjUiJOPK0sw1NX8NFeOd/ckQKb github.com/xmidt-org/bascule v0.8.1/go.mod h1:dPxlbNT3lCwYAtOq2zbzyzTEKgM+azLSbKKcVmgSHBY= github.com/xmidt-org/bascule v0.9.0 h1:CsMtwiDO4jjoOIh4pWe2U9tXA9A73CfohDsSvwzXm9Q= github.com/xmidt-org/bascule v0.9.0/go.mod h1:C64nSBtUTTK/f2/mCvvp/qJhav5raD0T+by68DCp/gU= +github.com/xmidt-org/httpaux v0.1.1 h1:jqMPHfS/k6EuGSH+KIOedhnQ8Vs9x9AXGbnRiWshrso= +github.com/xmidt-org/httpaux v0.1.1/go.mod h1:qZnH2uObGPwHnOz8HcPNlbcd3gKEvdmxbIK3rgbQhto= github.com/xmidt-org/themis v0.4.4 h1:KewitRxStW1xOehDBi0YyGZyRv3PjFdYUEDvQFf1Nmk= github.com/xmidt-org/themis v0.4.4/go.mod h1:0qRYFvKdrQhwjxH/1nAiTgBGT4cegJR76gfEYF5P7so= github.com/xmidt-org/webpa-common v1.1.0/go.mod h1:oCpKzOC+9h2vYHVzAU/06tDTQuBN4RZz+rhgIXptpOI= @@ -647,15 +657,11 @@ github.com/xmidt-org/webpa-common v1.10.2-0.20200604164000-f07406b4eb63 h1:nNNzT github.com/xmidt-org/webpa-common v1.10.2-0.20200604164000-f07406b4eb63/go.mod h1:Fmt3wIxBzwJY0KeRHX6RaLZx2xpKTbXCLEA3Xtd6kq8= github.com/xmidt-org/webpa-common v1.11.2 h1:m/7qmqcYZUUye5LIE1jEfXU+GqOc0ON3kwAKX04g1no= github.com/xmidt-org/webpa-common v1.11.2/go.mod h1:BaP0q1tlorm1Egq2qeLelon4Avy9n1eKJQAYhL3Zxg0= -github.com/xmidt-org/webpa-common v1.11.5-0.20210105175335-4574961a4c05 h1:6RCKGWnHV8YrC3ZQ5e1glyzXyVZZ48DZvHc8EvNiA4c= -github.com/xmidt-org/webpa-common v1.11.5-0.20210105175335-4574961a4c05/go.mod h1:2/lWTv4njLgyHk2qFMB81pOz6J1xmqElTPHTdeR9EPs= +github.com/xmidt-org/webpa-common v1.11.5-0.20210120003553-3d03d7329aee h1:BkR9TzO2+JCylI7rvNWk37/gwUlkCXI7RiuFH/Rhgi0= github.com/xmidt-org/webpa-common v1.11.5-0.20210120003553-3d03d7329aee/go.mod h1:NtJzdNhDznwjWiRKDnj/vxdQZnPOhuQ6haemx+nDMSY= -github.com/xmidt-org/webpa-common v1.11.5-0.20210120221303-49e7424ed591 h1:6g3lPbCT+jW1dWbuaoLLyDb7HLLPhti58t/WJJCADTg= -github.com/xmidt-org/webpa-common v1.11.5-0.20210120221303-49e7424ed591/go.mod h1:0hmAReSHUcze/0YWluX9M1pJOalSMJYqc6KzpCPUwHM= -github.com/xmidt-org/webpa-common v1.11.5-0.20210120234333-25979d3ac5d1 h1:QQgWc4AR8qU7L8nqfun5rlUURN1kfe96YrPK8OBrIpo= -github.com/xmidt-org/webpa-common v1.11.5-0.20210120234333-25979d3ac5d1/go.mod h1:0hmAReSHUcze/0YWluX9M1pJOalSMJYqc6KzpCPUwHM= -github.com/xmidt-org/webpa-common v1.11.5-0.20210120235745-b98c7113262c h1:n5nAWAJ0pfMe3JnWIV4RAFwJnawd5G7Olh0Pv4HOd1Q= -github.com/xmidt-org/webpa-common v1.11.5-0.20210120235745-b98c7113262c/go.mod h1:0hmAReSHUcze/0YWluX9M1pJOalSMJYqc6KzpCPUwHM= +github.com/xmidt-org/webpa-common v1.11.5 h1:kUR7fvtZ4tBlRMNLlyhFiHQN0No42F/6DApU4VniBzw= +github.com/xmidt-org/webpa-common v1.11.5/go.mod h1:jMyROPQmgvNS+P0csPodDMikqesqPFzlb3v/JVw2SmY= +github.com/xmidt-org/wrp-go v1.3.4 h1:7kj+1VXRNNEI7G0Z3z7C58QpIXrWzTw/eI79FdAhyPA= github.com/xmidt-org/wrp-go v1.3.4/go.mod h1:EWC9BgcYYO1hKgLzz6VFPpg3LU6ZWSDV/uNiWC7zP+o= github.com/xmidt-org/wrp-go/v2 v2.0.1/go.mod h1:v0HK0go/7OSVDvKbnXsUn6c+M987p0yyxWEs8/Fmf60= github.com/xmidt-org/wrp-go/v3 v3.0.1/go.mod h1:08zAEevd+fM81/asCgsMJdgO8sfKLvqclqJGX1pphnE= @@ -678,10 +684,12 @@ go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk= go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/dig v1.7.0/go.mod h1:z+dSd2TP9Usi48jL8M3v63iSBVkiwtVyMKxMZYYauPg= go.uber.org/dig v1.9.0/go.mod h1:X34SnWGr8Fyla9zQNO2GSO2D+TIuqB14OS8JhYocIyw= +go.uber.org/dig v1.10.0 h1:yLmDDj9/zuDjv3gz8GQGviXMs9TfysIUMUilCpgzUJY= go.uber.org/dig v1.10.0/go.mod h1:X34SnWGr8Fyla9zQNO2GSO2D+TIuqB14OS8JhYocIyw= go.uber.org/fx v1.9.0/go.mod h1:mFdUyAUuJ3w4jAckiKSKbldsxy1ojpAMJ+dVZg5Y0Aw= go.uber.org/fx v1.12.0/go.mod h1:egT3Kyg1JFYQkvKLZ3EsykxkNrZxgXS+gKoKo7abERY= go.uber.org/fx v1.13.0/go.mod h1:bREWhavnedxpJeTq9pQT53BbvwhUv7TcpsOqcH4a+3w= +go.uber.org/fx v1.13.1 h1:CFNTr1oin5OJ0VCZ8EycL3wzF29Jz2g0xe55RFsf2a4= go.uber.org/fx v1.13.1/go.mod h1:bREWhavnedxpJeTq9pQT53BbvwhUv7TcpsOqcH4a+3w= go.uber.org/goleak v0.10.0/go.mod h1:VCZuO8V8mFPlL0F5J5GK1rtHV3DrFcQ1R8ryq7FK0aI= go.uber.org/goleak v1.0.0 h1:qsup4IcBdlmsnGfqyLl4Ntn3C2XCCuKAE7DwHpScyUo= @@ -689,7 +697,9 @@ go.uber.org/goleak v1.0.0/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/multierr v1.4.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= +go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A= go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= @@ -719,6 +729,7 @@ golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f h1:J5lckAjkw6qYlOZNj90mLYNTEKDvWeuc1yieZ8qUzUE= golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= @@ -803,6 +814,7 @@ 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= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -841,6 +853,7 @@ golang.org/x/tools v0.0.0-20200513154647-78b527d18275 h1:e7nYe9s94RHunFJ7b+mmPxi golang.org/x/tools v0.0.0-20200513154647-78b527d18275/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.0.0-20180829000535-087779f1d2c9/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= @@ -884,6 +897,7 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d/go.mod h1:cuepJuh7vyXfUyUwEgHQXw849cJrilpS5NeIjOWESAw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= @@ -891,7 +905,9 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o= gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKWaSkCsqBpgog8nAV2xsGOxlo= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno= gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/square/go-jose.v2 v2.3.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= @@ -904,11 +920,14 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= istio.io/gogo-genproto v0.0.0-20190124151557-6d926a6e6feb/go.mod h1:eIDJ6jNk/IeJz6ODSksHl5Aiczy5JUq6vFhJWI5OtiI= k8s.io/api v0.0.0-20180806132203-61b11ee65332/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA= diff --git a/main.go b/main.go index e0d7a94e..9f0ad169 100644 --- a/main.go +++ b/main.go @@ -29,7 +29,7 @@ import ( "time" "github.com/go-kit/kit/log" - "github.com/xmidt-org/webpa-common/xwebhook" + "github.com/xmidt-org/ancla" "github.com/go-kit/kit/log/level" "github.com/xmidt-org/webpa-common/service/servicecfg" @@ -62,7 +62,7 @@ func caduceus(arguments []string) int { f = pflag.NewFlagSet(applicationName, pflag.ContinueOnError) v = viper.New() - logger, metricsRegistry, webPA, err = server.Initialize(applicationName, arguments, f, v, Metrics, xwebhook.Metrics) + logger, metricsRegistry, webPA, err = server.Initialize(applicationName, arguments, f, v, Metrics, ancla.Metrics) ) if parseErr, done := printVersion(f, arguments); done { @@ -132,16 +132,16 @@ func caduceus(arguments []string) int { modifiedWRPCount: metricsRegistry.NewCounter(ModifiedWRPCounter), maxOutstanding: 0, } - caduceusConfig.Webhook.Argus.Logger = logger - caduceusConfig.Webhook.Argus.MetricsProvider = metricsRegistry - svc, stopWatches, err := xwebhook.Initialize(&caduceusConfig.Webhook, caduceusSenderWrapper) + caduceusConfig.Webhook.Logger = logger + caduceusConfig.Webhook.MetricsProvider = metricsRegistry + svc, stopWatches, err := ancla.Initialize(caduceusConfig.Webhook, caduceusSenderWrapper) if err != nil { fmt.Fprintf(os.Stderr, "Webhook service initialization error: %v\n", err) return 1 } - primaryHandler, err := NewPrimaryHandler(logger, v, serverWrapper, svc) + primaryHandler, err := NewPrimaryHandler(logger, v, serverWrapper, svc, metricsRegistry) if err != nil { fmt.Fprintf(os.Stderr, "Validator error: %v\n", err) return 1 diff --git a/mocks_test.go b/mocks_test.go index 560d01b6..c0e4a1a4 100644 --- a/mocks_test.go +++ b/mocks_test.go @@ -21,7 +21,7 @@ import ( "github.com/go-kit/kit/metrics" "github.com/stretchr/testify/mock" - "github.com/xmidt-org/webpa-common/xwebhook" + "github.com/xmidt-org/ancla" "github.com/xmidt-org/wrp-go/v3" ) @@ -39,7 +39,7 @@ type mockSenderWrapper struct { mock.Mock } -func (m *mockSenderWrapper) Update(list []xwebhook.Webhook) { +func (m *mockSenderWrapper) Update(list []ancla.Webhook) { m.Called(list) } diff --git a/outboundSender.go b/outboundSender.go index 414459cd..8953546d 100644 --- a/outboundSender.go +++ b/outboundSender.go @@ -40,11 +40,11 @@ import ( "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" "github.com/go-kit/kit/metrics" + "github.com/xmidt-org/ancla" "github.com/xmidt-org/webpa-common/device" "github.com/xmidt-org/webpa-common/logging" "github.com/xmidt-org/webpa-common/semaphore" "github.com/xmidt-org/webpa-common/xhttp" - "github.com/xmidt-org/webpa-common/xwebhook" "github.com/xmidt-org/wrp-go/v3" "github.com/xmidt-org/wrp-go/v3/wrphttp" ) @@ -59,17 +59,17 @@ const failureText = `Unfortunately, your endpoint is not able to keep up with th // FailureMessage is a helper that lets us easily create a json struct to send // when we have to cut and endpoint off. type FailureMessage struct { - Text string `json:"text"` - Original xwebhook.Webhook `json:"webhook_registration"` - CutOffPeriod string `json:"cut_off_period"` - QueueSize int `json:"queue_size"` - Workers int `json:"worker_count"` + Text string `json:"text"` + Original ancla.Webhook `json:"webhook_registration"` + CutOffPeriod string `json:"cut_off_period"` + QueueSize int `json:"queue_size"` + Workers int `json:"worker_count"` } // OutboundSenderFactory is a configurable factory for OutboundSender objects. type OutboundSenderFactory struct { // The WebHookListener to service - Listener xwebhook.Webhook + Listener ancla.Webhook // The http client Do() function to use for outbound requests. Sender func(*http.Request) (*http.Response, error) @@ -102,7 +102,7 @@ type OutboundSenderFactory struct { } type OutboundSender interface { - Update(xwebhook.Webhook) error + Update(ancla.Webhook) error Shutdown(bool) RetiredSince() time.Time Queue(*wrp.Message) @@ -112,7 +112,7 @@ type OutboundSender interface { type CaduceusOutboundSender struct { id string urls *ring.Ring - listener xwebhook.Webhook + listener ancla.Webhook deliverUntil time.Time dropUntil time.Time sender func(*http.Request) (*http.Response, error) @@ -217,7 +217,7 @@ func (osf OutboundSenderFactory) New() (obs OutboundSender, err error) { // Update applies user configurable values for the outbound sender when a // webhook is registered -func (obs *CaduceusOutboundSender) Update(wh xwebhook.Webhook) (err error) { +func (obs *CaduceusOutboundSender) Update(wh ancla.Webhook) (err error) { // Validate the failure URL, if present if "" != wh.FailureURL { diff --git a/outboundSender_test.go b/outboundSender_test.go index e2b67ed3..4a043eae 100644 --- a/outboundSender_test.go +++ b/outboundSender_test.go @@ -24,7 +24,7 @@ import ( "github.com/go-kit/kit/log" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" - "github.com/xmidt-org/webpa-common/xwebhook" + "github.com/xmidt-org/ancla" "github.com/xmidt-org/wrp-go/v3" //"github.com/stretchr/testify/mock" @@ -85,7 +85,7 @@ func simpleFactorySetup(trans *transport, cutOffPeriod time.Duration, matcher [] } } - w := xwebhook.Webhook{ + w := ancla.Webhook{ Until: time.Now().Add(60 * time.Second), Events: []string{"iot", "test"}, } @@ -292,7 +292,7 @@ func TestAltURL(t *testing.T) { urls := map[string]int{} - w := xwebhook.Webhook{ + w := ancla.Webhook{ Until: time.Now().Add(60 * time.Second), Events: []string{".*"}, } @@ -508,7 +508,7 @@ func TestInvalidEventRegex(t *testing.T) { assert := assert.New(t) - w := xwebhook.Webhook{ + w := ancla.Webhook{ Until: time.Now().Add(60 * time.Second), Events: []string{"[[:123"}, } @@ -532,7 +532,7 @@ func TestInvalidUrl(t *testing.T) { assert := assert.New(t) - w := xwebhook.Webhook{ + w := ancla.Webhook{ Until: time.Now().Add(60 * time.Second), Events: []string{"iot"}, } @@ -549,7 +549,7 @@ func TestInvalidUrl(t *testing.T) { assert.Nil(obs) assert.NotNil(err) - w2 := xwebhook.Webhook{ + w2 := ancla.Webhook{ Until: time.Now().Add(60 * time.Second), Events: []string{"iot"}, } @@ -583,7 +583,7 @@ func TestInvalidSender(t *testing.T) { func TestInvalidLogger(t *testing.T) { assert := assert.New(t) - w := xwebhook.Webhook{ + w := ancla.Webhook{ Until: time.Now().Add(60 * time.Second), Events: []string{"iot"}, } @@ -605,7 +605,7 @@ func TestInvalidLogger(t *testing.T) { func TestFailureURL(t *testing.T) { assert := assert.New(t) - w := xwebhook.Webhook{ + w := ancla.Webhook{ Until: time.Now().Add(60 * time.Second), FailureURL: "invalid", Events: []string{"iot"}, @@ -626,7 +626,7 @@ func TestFailureURL(t *testing.T) { func TestInvalidEvents(t *testing.T) { assert := assert.New(t) - w := xwebhook.Webhook{ + w := ancla.Webhook{ Until: time.Now().Add(60 * time.Second), } w.Config.URL = "http://localhost:9999/foo" @@ -641,7 +641,7 @@ func TestInvalidEvents(t *testing.T) { assert.Nil(obs) assert.NotNil(err) - w2 := xwebhook.Webhook{ + w2 := ancla.Webhook{ Until: time.Now().Add(60 * time.Second), Events: []string{"iot(.*"}, } @@ -663,7 +663,7 @@ func TestUpdate(t *testing.T) { assert := assert.New(t) now := time.Now() - w1 := xwebhook.Webhook{ + w1 := ancla.Webhook{ Until: now, Events: []string{"iot", "test"}, } @@ -671,7 +671,7 @@ func TestUpdate(t *testing.T) { w1.Config.ContentType = wrp.MimeTypeMsgpack later := time.Now().Add(30 * time.Second) - w2 := xwebhook.Webhook{ + w2 := ancla.Webhook{ Until: later, Events: []string{"more", "messages"}, } @@ -703,7 +703,7 @@ func TestOverflowNoFailureURL(t *testing.T) { var output bytes.Buffer logger := getNewTestOutputLogger(&output) - w := xwebhook.Webhook{ + w := ancla.Webhook{ Until: time.Now(), Events: []string{"iot", "test"}, } @@ -749,7 +749,7 @@ func TestOverflowValidFailureURL(t *testing.T) { return } - w := xwebhook.Webhook{ + w := ancla.Webhook{ Until: time.Now(), FailureURL: "http://localhost:12345/bar", Events: []string{"iot", "test"}, @@ -793,7 +793,7 @@ func TestOverflowValidFailureURLWithSecret(t *testing.T) { return } - w := xwebhook.Webhook{ + w := ancla.Webhook{ Until: time.Now(), FailureURL: "http://localhost:12345/bar", Events: []string{"iot", "test"}, @@ -830,7 +830,7 @@ func TestOverflowValidFailureURLError(t *testing.T) { return } - w := xwebhook.Webhook{ + w := ancla.Webhook{ Until: time.Now(), FailureURL: "http://localhost:12345/bar", Events: []string{"iot", "test"}, @@ -877,7 +877,7 @@ func TestOverflow(t *testing.T) { return } - w := xwebhook.Webhook{ + w := ancla.Webhook{ Until: time.Now().Add(30 * time.Second), FailureURL: "http://localhost:12345/bar", Events: []string{"iot", "test"}, diff --git a/primaryHandler.go b/primaryHandler.go index 12b93107..88f4e854 100644 --- a/primaryHandler.go +++ b/primaryHandler.go @@ -6,13 +6,14 @@ import ( "github.com/SermoDigital/jose/jwt" "github.com/go-kit/kit/log" + "github.com/go-kit/kit/metrics/provider" "github.com/gorilla/mux" "github.com/justinas/alice" "github.com/spf13/viper" + "github.com/xmidt-org/ancla" "github.com/xmidt-org/webpa-common/secure" "github.com/xmidt-org/webpa-common/secure/handler" "github.com/xmidt-org/webpa-common/secure/key" - "github.com/xmidt-org/webpa-common/xwebhook" ) const ( @@ -29,7 +30,7 @@ type JWTValidator struct { Custom secure.JWTValidatorFactory } -func NewPrimaryHandler(l log.Logger, v *viper.Viper, sw *ServerHandler, webhookSvc xwebhook.Service) (*mux.Router, error) { +func NewPrimaryHandler(l log.Logger, v *viper.Viper, sw *ServerHandler, webhookSvc ancla.Service, metricsRegistry provider.Provider) (*mux.Router, error) { var ( router = mux.NewRouter() ) @@ -48,17 +49,19 @@ func NewPrimaryHandler(l log.Logger, v *viper.Viper, sw *ServerHandler, webhookS authorizationDecorator := alice.New(authHandler.Decorate) - return configServerRouter(router, authorizationDecorator, sw, webhookSvc), nil + return configServerRouter(router, authorizationDecorator, sw, webhookSvc, metricsRegistry), nil } -func configServerRouter(router *mux.Router, primaryHandler alice.Chain, serverWrapper *ServerHandler, webhookSvc xwebhook.Service) *mux.Router { +func configServerRouter(router *mux.Router, primaryHandler alice.Chain, serverWrapper *ServerHandler, webhookSvc ancla.Service, metricsRegistry provider.Provider) *mux.Router { var singleContentType = func(r *http.Request, _ *mux.RouteMatch) bool { return len(r.Header["Content-Type"]) == 1 // require single specification for Content-Type Header } router.Handle("/"+fmt.Sprintf("%s/%s", baseURI, version)+"/notify", primaryHandler.Then(serverWrapper)).Methods("POST").HeadersRegexp("Content-Type", "application/msgpack").MatcherFunc(singleContentType) - addWebhookHandler := xwebhook.NewAddWebhookHandler(webhookSvc) + addWebhookHandler := ancla.NewAddWebhookHandler(webhookSvc, ancla.HandlerConfig{ + MetricsProvider: metricsRegistry, + }) // register webhook end points router.Handle("/hook", primaryHandler.Then(addWebhookHandler)).Methods("POST") diff --git a/primaryHandler_test.go b/primaryHandler_test.go index 503ec0e6..245b37b7 100644 --- a/primaryHandler_test.go +++ b/primaryHandler_test.go @@ -7,6 +7,7 @@ import ( "net/http/httptest" "testing" + "github.com/go-kit/kit/metrics/provider" "github.com/gorilla/mux" "github.com/justinas/alice" "github.com/spf13/viper" @@ -26,7 +27,7 @@ func TestNewPrimaryHandler(t *testing.T) { ) viper.Set("authHeader", expectedAuthHeader) - if _, err := NewPrimaryHandler(l, viper, sw, nil); err != nil { + if _, err := NewPrimaryHandler(l, viper, sw, nil, provider.NewDiscardProvider()); err != nil { t.Fatalf("NewPrimaryHandler failed: %v", err) } @@ -92,7 +93,7 @@ func TestMuxServerConfig(t *testing.T) { authHandler := handler.AuthorizationHandler{Validator: nil} caduceusHandler := alice.New(authHandler.Decorate) - router := configServerRouter(mux.NewRouter(), caduceusHandler, serverWrapper, nil) + router := configServerRouter(mux.NewRouter(), caduceusHandler, serverWrapper, nil, provider.NewDiscardProvider()) t.Run("TestMuxResponseCorrectMSP", func(t *testing.T) { req := exampleRequest("1234", "application/msgpack", "/api/v3/notify") diff --git a/senderWrapper.go b/senderWrapper.go index c294ea29..3326d56c 100644 --- a/senderWrapper.go +++ b/senderWrapper.go @@ -24,7 +24,7 @@ import ( "github.com/go-kit/kit/log" "github.com/go-kit/kit/metrics" - "github.com/xmidt-org/webpa-common/xwebhook" + "github.com/xmidt-org/ancla" "github.com/xmidt-org/wrp-go/v3" ) @@ -68,7 +68,7 @@ type SenderWrapperFactory struct { } type SenderWrapper interface { - Update([]xwebhook.Webhook) + Update([]ancla.Webhook) Queue(*wrp.Message) Shutdown(bool) } @@ -129,7 +129,7 @@ func (swf SenderWrapperFactory) New() (sw SenderWrapper, err error) { // Update is called when we get changes to our webhook listeners with either // additions, or updates. This code takes care of building new OutboundSenders // and maintaining the existing OutboundSenders. -func (sw *CaduceusSenderWrapper) Update(list []xwebhook.Webhook) { +func (sw *CaduceusSenderWrapper) Update(list []ancla.Webhook) { // We'll like need this, so let's get one ready osf := OutboundSenderFactory{ Sender: sw.sender, @@ -144,7 +144,7 @@ func (sw *CaduceusSenderWrapper) Update(list []xwebhook.Webhook) { } ids := make([]struct { - Listener xwebhook.Webhook + Listener ancla.Webhook ID string }, len(list)) diff --git a/senderWrapper_test.go b/senderWrapper_test.go index d83694d5..ca279a36 100644 --- a/senderWrapper_test.go +++ b/senderWrapper_test.go @@ -25,8 +25,8 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/xmidt-org/ancla" "github.com/xmidt-org/webpa-common/logging" - "github.com/xmidt-org/webpa-common/xwebhook" "github.com/xmidt-org/wrp-go/v3" ) @@ -184,7 +184,7 @@ func TestSwSimple(t *testing.T) { assert.Equal(int32(0), trans.i) - w1 := xwebhook.Webhook{ + w1 := ancla.Webhook{ Duration: 6 * time.Second, Until: time.Now().Add(6 * time.Second), Events: []string{"iot"}, @@ -193,7 +193,7 @@ func TestSwSimple(t *testing.T) { w1.Config.ContentType = wrp.MimeTypeJson w1.Matcher.DeviceID = []string{"mac:112233445566"} - w2 := xwebhook.Webhook{ + w2 := ancla.Webhook{ Duration: 4 * time.Second, Until: time.Now().Add(4 * time.Second), Events: []string{"iot", "test/extra-stuff", "wrp"}, @@ -203,7 +203,7 @@ func TestSwSimple(t *testing.T) { w2.Matcher.DeviceID = []string{"mac:112233445566"} // Add 2 listeners - list := []xwebhook.Webhook{w1, w2} + list := []ancla.Webhook{w1, w2} sw.Update(list) @@ -217,14 +217,14 @@ func TestSwSimple(t *testing.T) { // Send it again sw.Queue(test) - w3 := xwebhook.Webhook{ + w3 := ancla.Webhook{ Events: []string{"iot"}, } w3.Config.URL = "http://localhost:9999/foo" w3.Config.ContentType = wrp.MimeTypeJson // We get a registration - list2 := []xwebhook.Webhook{w3} + list2 := []ancla.Webhook{w3} sw.Update(list2) time.Sleep(time.Second)