Skip to content

Commit cf02f1a

Browse files
refactor: snyk code client improvements (#11)
1 parent 8c21c1f commit cf02f1a

File tree

17 files changed

+392
-311
lines changed

17 files changed

+392
-311
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ $(TOOLS_BIN)/pact/bin/pact:
2525
.PHONY: format
2626
format:
2727
@gofmt -w -l -e .
28+
@$(TOOLS_BIN)/golangci-lint run --fix -v ./...
2829

2930
.PHONY: lint
3031
lint: $(TOOLS_BIN)/golangci-lint

go.mod

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
module github.com/snyk/code-client-go
22

3-
go 1.21.7
3+
go 1.21
44

55
require (
66
github.com/golang/mock v1.6.0
77
github.com/google/uuid v1.6.0
88
github.com/pact-foundation/pact-go v1.7.0
9-
github.com/pkg/errors v0.9.1
109
github.com/rs/zerolog v1.32.0
11-
github.com/snyk/snyk-ls v0.0.0-20240313154204-cd9e82b13dfb
10+
github.com/snyk/go-application-framework v0.0.0-20240111143643-fa847b8a9a3b
1211
github.com/stretchr/testify v1.8.4
1312
golang.org/x/net v0.22.0
1413
)
1514

1615
require (
17-
github.com/adrg/xdg v0.4.0 // indirect
1816
github.com/alexbrainman/sspi v0.0.0-20231016080023-1a75b4708caa // indirect
19-
github.com/creachadair/jrpc2 v1.1.2 // indirect
20-
github.com/creachadair/mds v0.12.2 // indirect
2117
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
22-
github.com/denisbrodbeck/machineid v1.0.1 // indirect
2318
github.com/fatih/color v1.16.0 // indirect
2419
github.com/fsnotify/fsnotify v1.7.0 // indirect
2520
github.com/golang/protobuf v1.5.4 // indirect
21+
github.com/google/go-cmp v0.6.0 // indirect
2622
github.com/hashicorp/go-uuid v1.0.3 // indirect
2723
github.com/hashicorp/go-version v1.6.0 // indirect
2824
github.com/hashicorp/hcl v1.0.0 // indirect
@@ -40,28 +36,20 @@ require (
4036
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
4137
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
4238
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
43-
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect
4439
github.com/sagikazarmark/locafero v0.4.0 // indirect
4540
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
46-
github.com/snyk/go-application-framework v0.0.0-20240111143643-fa847b8a9a3b // indirect
4741
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65 // indirect
4842
github.com/sourcegraph/conc v0.3.0 // indirect
49-
github.com/sourcegraph/go-lsp v0.0.0-20240223163137-f80c5dd31dfd // indirect
5043
github.com/spf13/afero v1.11.0 // indirect
5144
github.com/spf13/cast v1.6.0 // indirect
5245
github.com/spf13/pflag v1.0.5 // indirect
5346
github.com/spf13/viper v1.18.2 // indirect
5447
github.com/subosito/gotenv v1.6.0 // indirect
55-
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
56-
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
57-
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
58-
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
5948
go.uber.org/multierr v1.11.0 // indirect
6049
golang.org/x/crypto v0.21.0 // indirect
6150
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
6251
golang.org/x/mod v0.16.0 // indirect
6352
golang.org/x/oauth2 v0.18.0 // indirect
64-
golang.org/x/sync v0.6.0 // indirect
6553
golang.org/x/sys v0.18.0 // indirect
6654
golang.org/x/text v0.14.0 // indirect
6755
golang.org/x/tools v0.19.0 // indirect

go.sum

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7
1414
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
1515
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
1616
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
17-
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
18-
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
1917
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
2018
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
2119
github.com/alexbrainman/sspi v0.0.0-20231016080023-1a75b4708caa h1:LHTHcTQiSGT7VVbI0o4wBRNQIgn917usHWOd6VAffYI=
@@ -37,25 +35,17 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7
3735
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
3836
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
3937
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
40-
github.com/creachadair/jrpc2 v1.1.2 h1:UOYMipEFYlwd5qmcvs9GZBurn3oXt1UDIX5JLjWWFzo=
41-
github.com/creachadair/jrpc2 v1.1.2/go.mod h1:JcCe2Eny3lIvVwZLm92WXyU+tNUgTBWFCLMsfNkjEGk=
42-
github.com/creachadair/mds v0.12.2 h1:CyJUaInwFnLUcMgJjVMLG3qYDziSbaY1KXBCvsLrTwQ=
43-
github.com/creachadair/mds v0.12.2/go.mod h1:4vrFYUzTXMJpMBU+OA292I6IUxKWCCfZkgXg+/kBZMo=
4438
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4539
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4640
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
4741
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
48-
github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ=
49-
github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI=
5042
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
5143
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
5244
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
5345
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
5446
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
5547
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
5648
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
57-
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
58-
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
5949
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
6050
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
6151
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
@@ -240,7 +230,6 @@ github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmd
240230
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
241231
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
242232
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
243-
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
244233
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
245234
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
246235
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
@@ -265,8 +254,6 @@ github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0=
265254
github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
266255
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
267256
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
268-
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=
269-
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=
270257
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
271258
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
272259
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
@@ -280,13 +267,9 @@ github.com/snyk/go-application-framework v0.0.0-20240111143643-fa847b8a9a3b h1:8
280267
github.com/snyk/go-application-framework v0.0.0-20240111143643-fa847b8a9a3b/go.mod h1:Yz/qxFyfhf0xbA+z8Vzr5IM9IDG+BS+2PiGaP1yAsEw=
281268
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65 h1:CEQuYv0Go6MEyRCD3YjLYM2u3Oxkx8GpCpFBd4rUTUk=
282269
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65/go.mod h1:88KbbvGYlmLgee4OcQ19yr0bNpXpOr2kciOthaSzCAg=
283-
github.com/snyk/snyk-ls v0.0.0-20240313154204-cd9e82b13dfb h1:XYI4eNNMpXYF3QLN+1Gc2jOx+FhBF+4mH03hJqecyQc=
284-
github.com/snyk/snyk-ls v0.0.0-20240313154204-cd9e82b13dfb/go.mod h1:nJi8bkjV5pQwgscee2FUqMw/pQ2cibsZsTT7js4/jbc=
285270
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
286271
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
287272
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
288-
github.com/sourcegraph/go-lsp v0.0.0-20240223163137-f80c5dd31dfd h1:Dq5WSzWsP1TbVi10zPWBI5LKEBDg4Y1OhWEph1wr5WQ=
289-
github.com/sourcegraph/go-lsp v0.0.0-20240223163137-f80c5dd31dfd/go.mod h1:SULmZY7YNBsvNiQbrb/BEDdEJ84TGnfyUQxaHt8t8rY=
290273
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
291274
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
292275
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
@@ -309,8 +292,6 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE
309292
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
310293
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
311294
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
312-
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
313-
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
314295
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
315296
github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
316297
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
@@ -323,16 +304,7 @@ github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSW
323304
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
324305
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
325306
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
326-
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
327-
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo=
328-
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
329-
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
330-
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
331-
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
332-
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
333307
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
334-
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c h1:3lbZUMbMiGUW/LMkfsEABsc5zNT9+b1CvsJx47JzJ8g=
335-
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c/go.mod h1:UrdRz5enIKZ63MEE3IF9l2/ebyx59GyGgPi+tICQdmM=
336308
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
337309
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
338310
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
@@ -412,8 +384,6 @@ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJ
412384
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
413385
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
414386
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
415-
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
416-
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
417387
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
418388
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
419389
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -433,7 +403,6 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w
433403
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
434404
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
435405
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
436-
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
437406
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
438407
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
439408
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

internal/deepcode/client.go

Lines changed: 80 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,34 @@ package deepcode
1919
import (
2020
"context"
2121
"encoding/json"
22+
"errors"
23+
"net/url"
24+
"regexp"
2225
"strconv"
2326

24-
"github.com/rs/zerolog/log"
25-
http2 "github.com/snyk/code-client-go/internal/http"
27+
"github.com/rs/zerolog"
28+
"github.com/snyk/go-application-framework/pkg/configuration"
29+
"github.com/snyk/go-application-framework/pkg/workflow"
30+
31+
codeClientHTTP "github.com/snyk/code-client-go/internal/http"
2632
"github.com/snyk/code-client-go/observability"
2733
)
2834

2935
//go:generate mockgen -destination=mocks/client.go -source=client.go -package mocks
3036
type SnykCodeClient interface {
31-
GetFilters(ctx context.Context) (
37+
GetFilters(ctx context.Context, host string) (
3238
filters FiltersResponse,
3339
err error)
3440

3541
CreateBundle(
3642
ctx context.Context,
43+
host string,
3744
files map[string]string,
3845
) (newBundleHash string, missingFiles []string, err error)
3946

4047
ExtendBundle(
4148
ctx context.Context,
49+
host string,
4250
bundleHash string,
4351
files map[string]BundleFile,
4452
removedFiles []string,
@@ -61,28 +69,40 @@ type BundleResponse struct {
6169
}
6270

6371
type snykCodeClient struct {
64-
httpClient http2.HTTPClient
72+
httpClient codeClientHTTP.HTTPClient
6573
instrumentor observability.Instrumentor
74+
engine workflow.Engine
75+
logger *zerolog.Logger
6676
}
6777

6878
func NewSnykCodeClient(
69-
httpClient http2.HTTPClient,
79+
engine workflow.Engine,
80+
httpClient codeClientHTTP.HTTPClient,
7081
instrumentor observability.Instrumentor,
71-
) SnykCodeClient {
72-
return &snykCodeClient{httpClient, instrumentor}
82+
) *snykCodeClient {
83+
logger := engine.GetLogger()
84+
return &snykCodeClient{httpClient, instrumentor, engine, logger}
7385
}
7486

75-
func (s *snykCodeClient) GetFilters(ctx context.Context) (
87+
func (s *snykCodeClient) GetFilters(ctx context.Context, snykCodeApiUrl string) (
7688
filters FiltersResponse,
7789
err error,
7890
) {
7991
method := "code.GetFilters"
80-
log.Debug().Str("method", method).Msg("API: Getting file extension filters")
92+
log := s.logger.With().Str("method", method).Logger()
93+
log.Debug().Msg("API: Getting file extension filters")
8194

8295
span := s.instrumentor.StartSpan(ctx, method)
8396
defer s.instrumentor.Finish(span)
8497

85-
responseBody, err := s.httpClient.DoCall(span.Context(), "GET", "/filters", nil)
98+
c := s.engine.GetConfiguration()
99+
100+
host, err := s.FormatCodeApiURL(snykCodeApiUrl)
101+
if err != nil {
102+
return FiltersResponse{ConfigFiles: nil, Extensions: nil}, err
103+
}
104+
105+
responseBody, err := s.httpClient.DoCall(span.Context(), c, host, "GET", "/filters", nil)
86106
if err != nil {
87107
return FiltersResponse{ConfigFiles: nil, Extensions: nil}, err
88108
}
@@ -91,16 +111,18 @@ func (s *snykCodeClient) GetFilters(ctx context.Context) (
91111
if err != nil {
92112
return FiltersResponse{ConfigFiles: nil, Extensions: nil}, err
93113
}
94-
log.Debug().Str("method", method).Msg("API: Finished getting filters")
114+
log.Debug().Msg("API: Finished getting filters")
95115
return filters, nil
96116
}
97117

98118
func (s *snykCodeClient) CreateBundle(
99119
ctx context.Context,
120+
snykCodeApiUrl string,
100121
filesToFilehashes map[string]string,
101122
) (string, []string, error) {
102123
method := "code.CreateBundle"
103-
log.Debug().Str("method", method).Msg("API: Creating bundle for " + strconv.Itoa(len(filesToFilehashes)) + " files")
124+
log := s.logger.With().Str("method", method).Logger()
125+
log.Debug().Msg("API: Creating bundle for " + strconv.Itoa(len(filesToFilehashes)) + " files")
104126

105127
span := s.instrumentor.StartSpan(ctx, method)
106128
defer s.instrumentor.Finish(span)
@@ -110,7 +132,14 @@ func (s *snykCodeClient) CreateBundle(
110132
return "", nil, err
111133
}
112134

113-
responseBody, err := s.httpClient.DoCall(span.Context(), "POST", "/bundle", requestBody)
135+
c := s.engine.GetConfiguration()
136+
137+
host, err := s.FormatCodeApiURL(snykCodeApiUrl)
138+
if err != nil {
139+
return "", nil, err
140+
}
141+
142+
responseBody, err := s.httpClient.DoCall(span.Context(), c, host, "POST", "/bundle", requestBody)
114143
if err != nil {
115144
return "", nil, err
116145
}
@@ -120,18 +149,20 @@ func (s *snykCodeClient) CreateBundle(
120149
if err != nil {
121150
return "", nil, err
122151
}
123-
log.Debug().Str("method", method).Msg("API: Create done")
152+
log.Debug().Msg("API: Create done")
124153
return bundle.BundleHash, bundle.MissingFiles, nil
125154
}
126155

127156
func (s *snykCodeClient) ExtendBundle(
128157
ctx context.Context,
158+
snykCodeApiUrl string,
129159
bundleHash string,
130160
files map[string]BundleFile,
131161
removedFiles []string,
132162
) (string, []string, error) {
133163
method := "code.ExtendBundle"
134-
log.Debug().Str("method", method).Msg("API: Extending bundle for " + strconv.Itoa(len(files)) + " files")
164+
log := s.logger.With().Str("method", method).Logger()
165+
log.Debug().Msg("API: Extending bundle for " + strconv.Itoa(len(files)) + " files")
135166
defer log.Debug().Str("method", method).Msg("API: Extend done")
136167

137168
span := s.instrumentor.StartSpan(ctx, method)
@@ -145,11 +176,44 @@ func (s *snykCodeClient) ExtendBundle(
145176
return "", nil, err
146177
}
147178

148-
responseBody, err := s.httpClient.DoCall(span.Context(), "PUT", "/bundle/"+bundleHash, requestBody)
179+
c := s.engine.GetConfiguration()
180+
181+
host, err := s.FormatCodeApiURL(snykCodeApiUrl)
182+
if err != nil {
183+
return "", nil, err
184+
}
185+
186+
responseBody, err := s.httpClient.DoCall(span.Context(), c, host, "PUT", "/bundle/"+bundleHash, requestBody)
149187
if err != nil {
150188
return "", nil, err
151189
}
152190
var bundleResponse BundleResponse
153191
err = json.Unmarshal(responseBody, &bundleResponse)
154192
return bundleResponse.BundleHash, bundleResponse.MissingFiles, err
155193
}
194+
195+
var codeApiRegex = regexp.MustCompile(`^(deeproxy\.)?`)
196+
197+
// This is only exported for tests.
198+
func (s *snykCodeClient) FormatCodeApiURL(snykCodeApiUrl string) (string, error) {
199+
config := s.engine.GetConfiguration()
200+
201+
if !config.GetBool(configuration.IS_FEDRAMP) {
202+
return snykCodeApiUrl, nil
203+
}
204+
u, err := url.Parse(snykCodeApiUrl)
205+
if err != nil {
206+
return "", err
207+
}
208+
209+
u.Host = codeApiRegex.ReplaceAllString(u.Host, "api.")
210+
211+
organization := config.GetString(configuration.ORGANIZATION)
212+
if organization == "" {
213+
return "", errors.New("Organization is required in a fedramp environment")
214+
}
215+
216+
u.Path = "/hidden/orgs/" + organization + "/code"
217+
218+
return u.String(), nil
219+
}

0 commit comments

Comments
 (0)