From 40445d9cd45eb99b3b72b6e363698d2742ea0fbf Mon Sep 17 00:00:00 2001 From: Bastian Doetsch Date: Mon, 19 Aug 2024 08:38:23 +0200 Subject: [PATCH 1/8] chore: update go to 1.23 --- go.mod | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 90ecf6003..a973db157 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,8 @@ module github.com/snyk/snyk-ls -go 1.22 +go 1.23 -toolchain go1.22.5 +toolchain go1.23.0 require ( github.com/adrg/strutil v0.3.1 From 6807fa911266fd3f47af3ea4f51c782cbb1d9a29 Mon Sep 17 00:00:00 2001 From: Bastian Doetsch Date: Mon, 19 Aug 2024 08:41:00 +0200 Subject: [PATCH 2/8] chore: update go dependencies --- go.mod | 26 +++++++++++++------------- go.sum | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index a973db157..8af7a18b5 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/getsentry/sentry-go v0.28.1 github.com/go-git/go-git/v5 v5.12.0 github.com/golang/mock v1.6.0 - github.com/gomarkdown/markdown v0.0.0-20240626202925-2eda941fd024 + github.com/gomarkdown/markdown v0.0.0-20240730141124-034f12af3bf6 github.com/google/uuid v1.6.0 github.com/hexops/gotextdiff v1.0.3 github.com/otiai10/copy v1.14.0 @@ -22,11 +22,11 @@ require ( github.com/pingcap/errors v0.11.4 github.com/pkg/errors v0.9.1 github.com/puzpuzpuz/xsync v1.5.2 - github.com/puzpuzpuz/xsync/v3 v3.3.1 + github.com/puzpuzpuz/xsync/v3 v3.4.0 github.com/rs/zerolog v1.33.0 github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 github.com/shirou/gopsutil v3.21.11+incompatible - github.com/snyk/code-client-go v1.8.0 + github.com/snyk/code-client-go v1.10.0 github.com/snyk/go-application-framework v0.0.0-20240814101709-b335a1ce00ac github.com/sourcegraph/go-lsp v0.0.0-20240223163137-f80c5dd31dfd github.com/spf13/pflag v1.0.5 @@ -34,16 +34,16 @@ require ( github.com/subosito/gotenv v1.6.0 github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c go.lsp.dev/uri v0.3.0 - golang.org/x/exp v0.0.0-20240707233637-46b078467d37 - golang.org/x/mod v0.19.0 - golang.org/x/net v0.27.0 - golang.org/x/oauth2 v0.21.0 - golang.org/x/sync v0.7.0 + golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa + golang.org/x/mod v0.20.0 + golang.org/x/net v0.28.0 + golang.org/x/oauth2 v0.22.0 + golang.org/x/sync v0.8.0 gopkg.in/yaml.v3 v3.0.1 ) require ( - dario.cat/mergo v1.0.0 // indirect + dario.cat/mergo v1.0.1 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect github.com/ProtonMail/go-crypto v1.0.0 // indirect github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74 // indirect @@ -116,10 +116,10 @@ require ( github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect github.com/xeipuuv/gojsonschema v1.2.0 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect - golang.org/x/crypto v0.25.0 // indirect - golang.org/x/sys v0.22.0 // indirect - golang.org/x/text v0.16.0 // indirect - golang.org/x/tools v0.23.0 // indirect + golang.org/x/crypto v0.26.0 // indirect + golang.org/x/sys v0.23.0 // indirect + golang.org/x/text v0.17.0 // indirect + golang.org/x/tools v0.24.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index 706aa4284..19beb536e 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= +dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s= +dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= @@ -130,6 +132,8 @@ github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QD github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/gomarkdown/markdown v0.0.0-20240626202925-2eda941fd024 h1:saBP362Qm7zDdDXqv61kI4rzhmLFq3Z1gx34xpl6cWE= github.com/gomarkdown/markdown v0.0.0-20240626202925-2eda941fd024/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA= +github.com/gomarkdown/markdown v0.0.0-20240730141124-034f12af3bf6 h1:ZPy+2XJ8u0bB3sNFi+I72gMEMS7MTg7aZCCXPOjV8iw= +github.com/gomarkdown/markdown v0.0.0-20240730141124-034f12af3bf6/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -264,6 +268,8 @@ github.com/puzpuzpuz/xsync v1.5.2 h1:yRAP4wqSOZG+/4pxJ08fPTwrfL0IzE/LKQ/cw509qGY github.com/puzpuzpuz/xsync v1.5.2/go.mod h1:K98BYhX3k1dQ2M63t1YNVDanbwUPmBCAhNmVrrxfiGg= github.com/puzpuzpuz/xsync/v3 v3.3.1 h1:vZPJk3OOfoaSjy3cdTX3BZxhDCUVp9SqdHnd+ilGlbQ= github.com/puzpuzpuz/xsync/v3 v3.3.1/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA= +github.com/puzpuzpuz/xsync/v3 v3.4.0 h1:DuVBAdXuGFHv8adVXjWWZ63pJq+NRXOWVXlKDBZ+mJ4= +github.com/puzpuzpuz/xsync/v3 v3.4.0/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= @@ -285,6 +291,8 @@ github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= github.com/snyk/code-client-go v1.8.0 h1:6H883KAn7ybiSIxhvL2QR9yEyHgAwA2+9WVHMDNEKa8= github.com/snyk/code-client-go v1.8.0/go.mod h1:orU911flV1kJQOlxxx0InUQkAfpBrcERsb2olfnlI8s= +github.com/snyk/code-client-go v1.10.0 h1:t/hBINxj4lKvoo681uGhxHBpMued/j68p2sHbB9qbfo= +github.com/snyk/code-client-go v1.10.0/go.mod h1:orU911flV1kJQOlxxx0InUQkAfpBrcERsb2olfnlI8s= github.com/snyk/error-catalog-golang-public v0.0.0-20240809094525-c48d19c27edb h1:w9tJhpTFxWqAhLeraGsMExDjGK9x5Dwj1NRFwb+t+QE= github.com/snyk/error-catalog-golang-public v0.0.0-20240809094525-c48d19c27edb/go.mod h1:Ytttq7Pw4vOCu9NtRQaOeDU2dhBYUyNBe6kX4+nIIQ4= github.com/snyk/go-application-framework v0.0.0-20240814101709-b335a1ce00ac h1:Dr+hPN5kI4CDjHxsCHkonI4tJDYrAfoG4QvqHCMhrKY= @@ -370,9 +378,13 @@ golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2Uz golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= +golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= +golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20240707233637-46b078467d37 h1:uLDX+AfeFCct3a2C7uIWBKMJIR3CJMhcgfrUAqjRK6w= golang.org/x/exp v0.0.0-20240707233637-46b078467d37/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= +golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa h1:ELnwvuAXPNtPk1TJRuGkI9fDTwym6AYBu0qzT8AcHdI= +golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= @@ -383,6 +395,8 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91 golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8= golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0= +golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -400,9 +414,13 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= +golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= +golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA= +golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -411,6 +429,8 @@ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -437,6 +457,8 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= +golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 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/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= @@ -444,6 +466,7 @@ golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= +golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -454,6 +477,8 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -466,6 +491,8 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg= golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI= +golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= +golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= 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/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= From a586b0e4b2a5f7e5f82a514f580c2381403c58a4 Mon Sep 17 00:00:00 2001 From: Bastian Doetsch Date: Mon, 19 Aug 2024 08:42:34 +0200 Subject: [PATCH 3/8] feat: add executeCLI command --- application/server/server.go | 1 + application/server/server_test.go | 1 + domain/ide/command/command_factory.go | 2 + domain/ide/command/execute_cli.go | 58 +++++++++++++++++++++++++++ internal/types/command.go | 3 +- 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 domain/ide/command/execute_cli.go diff --git a/application/server/server.go b/application/server/server.go index 183a760d0..1c29d108b 100644 --- a/application/server/server.go +++ b/application/server/server.go @@ -277,6 +277,7 @@ func initializeHandler(srv *jrpc2.Server) handler.Func { types.CodeFixCommand, types.CodeSubmitFixFeedback, types.CodeFixDiffsCommand, + types.ExecuteCLICommand, }, }, }, diff --git a/application/server/server_test.go b/application/server/server_test.go index 4c0f2d5a3..545392ddc 100644 --- a/application/server/server_test.go +++ b/application/server/server_test.go @@ -260,6 +260,7 @@ func Test_initialize_shouldSupportAllCommands(t *testing.T) { assert.Contains(t, result.Capabilities.ExecuteCommandProvider.Commands, types.CodeFixCommand) assert.Contains(t, result.Capabilities.ExecuteCommandProvider.Commands, types.CodeSubmitFixFeedback) assert.Contains(t, result.Capabilities.ExecuteCommandProvider.Commands, types.CodeFixDiffsCommand) + assert.Contains(t, result.Capabilities.ExecuteCommandProvider.Commands, types.ExecuteCLICommand) } func Test_initialize_shouldSupportDocumentSaving(t *testing.T) { diff --git a/domain/ide/command/command_factory.go b/domain/ide/command/command_factory.go index 0551d292c..6b00f3282 100644 --- a/domain/ide/command/command_factory.go +++ b/domain/ide/command/command_factory.go @@ -76,6 +76,8 @@ func CreateFromCommandData(c *config.Config, commandData types.CommandData, srv issueProvider: issueProvider, notifier: notifier, }, nil + case types.ExecuteCLICommand: + return &executeCLICommand{command: commandData, authService: authService, notifier: notifier, logger: c.Logger()}, nil } return nil, fmt.Errorf("unknown command %v", commandData) diff --git a/domain/ide/command/execute_cli.go b/domain/ide/command/execute_cli.go new file mode 100644 index 000000000..b2cafbc7e --- /dev/null +++ b/domain/ide/command/execute_cli.go @@ -0,0 +1,58 @@ +/* + * © 2023-2024 Snyk Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package command + +import ( + "context" + "fmt" + + "github.com/rs/zerolog" + + "github.com/snyk/snyk-ls/infrastructure/authentication" + "github.com/snyk/snyk-ls/infrastructure/cli" + noti "github.com/snyk/snyk-ls/internal/notification" + "github.com/snyk/snyk-ls/internal/types" +) + +type executeCLICommand struct { + command types.CommandData + authService authentication.AuthenticationService + notifier noti.Notifier + logger *zerolog.Logger + cli cli.Executor +} + +func (cmd *executeCLICommand) Command() types.CommandData { + return cmd.command +} + +func (cmd *executeCLICommand) Execute(ctx context.Context) (any, error) { + if len(cmd.command.Arguments) < 2 { + return nil, fmt.Errorf("invalid usage of executeCLICommand. First arg needs to be the workDir, then CLI arguments without binary path") + } + workDir := cmd.command.Arguments[0].(string) + + var args []string + for _, argument := range cmd.command.Arguments[1:] { + args = append(args, argument.(string)) + } + resp, err := cmd.cli.Execute(ctx, args, workDir) + if err != nil { + return nil, err + } + return string(resp), nil +} diff --git a/internal/types/command.go b/internal/types/command.go index e2d9aa71c..8f053a345 100644 --- a/internal/types/command.go +++ b/internal/types/command.go @@ -38,6 +38,7 @@ const ( GetFeatureFlagStatus = "snyk.getFeatureFlagStatus" GetActiveUserCommand = "snyk.getActiveUser" ReportAnalyticsCommand = "snyk.reportAnalytics" + ExecuteCLICommand = "snyk.executeCLI" // Snyk Code specific commands CodeFixCommand = "snyk.code.fix" @@ -100,7 +101,7 @@ func NewCommandServiceMock() *CommandServiceMock { return &CommandServiceMock{} } -func (service *CommandServiceMock) ExecuteCommandData(_ context.Context, command CommandData, server Server) (any, error) { +func (service *CommandServiceMock) ExecuteCommandData(_ context.Context, command CommandData, _ Server) (any, error) { service.m.Lock() service.executedCommands = append(service.executedCommands, command) service.m.Unlock() From a85f2ecabe734c1926ac29e48496328e6694b1f0 Mon Sep 17 00:00:00 2001 From: Bastian Doetsch Date: Mon, 19 Aug 2024 09:05:14 +0200 Subject: [PATCH 4/8] fix: linter errors after linting update --- Makefile | 2 +- application/config/config.go | 5 +++-- go.mod | 4 ++-- go.sum | 37 +++++--------------------------- infrastructure/code/autofix.go | 5 +++-- infrastructure/code/convert.go | 2 +- internal/util/math_extensions.go | 16 +++++++------- main.go | 3 ++- 8 files changed, 25 insertions(+), 49 deletions(-) diff --git a/Makefile b/Makefile index 500277710..0539177be 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ LDFLAGS_DEV := "-X 'github.com/snyk/snyk-ls/application/config.Development=true' TOOLS_BIN := $(shell pwd)/.bin -OVERRIDE_GOCI_LINT_V := v1.55.2 +OVERRIDE_GOCI_LINT_V := v1.60.1 PACT_V := 2.4.2 NOCACHE := "-count=1" diff --git a/application/config/config.go b/application/config/config.go index a704ba1eb..194b193c3 100644 --- a/application/config/config.go +++ b/application/config/config.go @@ -18,6 +18,7 @@ package config import ( "encoding/json" + "errors" "fmt" "io" "net/url" @@ -885,9 +886,9 @@ func (c *Config) Logger() *zerolog.Logger { func (c *Config) TokenAsOAuthToken() (oauth2.Token, error) { var oauthToken oauth2.Token if _, err := uuid.Parse(c.Token()); err == nil { - msg := "creds are legacy, not oauth2" + const msg = "creds are legacy, not oauth2" c.Logger().Trace().Msgf(msg) - return oauthToken, fmt.Errorf(msg) + return oauthToken, errors.New(msg) } err := json.Unmarshal([]byte(c.Token()), &oauthToken) if err != nil { diff --git a/go.mod b/go.mod index 8af7a18b5..b5bb4a0d8 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/adrg/strutil v0.3.1 github.com/adrg/xdg v0.5.0 github.com/atotto/clipboard v0.1.4 - github.com/creachadair/jrpc2 v1.2.0 + github.com/creachadair/jrpc2 v1.2.1 github.com/denisbrodbeck/machineid v1.0.1 github.com/erni27/imcache v1.2.0 github.com/getsentry/sentry-go v0.28.1 @@ -51,7 +51,7 @@ require ( github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/charmbracelet/lipgloss v0.10.0 // indirect github.com/cloudflare/circl v1.3.8 // indirect - github.com/creachadair/mds v0.13.4 // indirect + github.com/creachadair/mds v0.16.0 // indirect github.com/cyphar/filepath-securejoin v0.2.5 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/deepmap/oapi-codegen v1.16.3 // indirect diff --git a/go.sum b/go.sum index 19beb536e..24af12740 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,4 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= -dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s= dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= @@ -38,10 +36,10 @@ github.com/cloudflare/circl v1.3.8/go.mod h1:PDRU+oXvdD7KCtgKxW95M5Z8BpSCJXQORiZ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/creachadair/jrpc2 v1.2.0 h1:SXr0OgnwM0X18P+HccJP0uT3KGSDk/BCSRlJBvE2bMY= -github.com/creachadair/jrpc2 v1.2.0/go.mod h1:66uKSdr6tR5ZeNvkIjDSbbVUtOv0UhjS/vcd8ECP7Iw= -github.com/creachadair/mds v0.13.4 h1:RgU0MhiVqkzp6/xtNWhK6Pw7tDeaVuGFtA0UA2RBYvY= -github.com/creachadair/mds v0.13.4/go.mod h1:4vrFYUzTXMJpMBU+OA292I6IUxKWCCfZkgXg+/kBZMo= +github.com/creachadair/jrpc2 v1.2.1 h1:eIgmguoqLbEjn4Pb/XYMg5U1PhVpAClGdhI/Q4gfC5o= +github.com/creachadair/jrpc2 v1.2.1/go.mod h1:RvEKAYVpDBKn3YWlTVQJIFmxG5GuLD7ztp9FMTJx8eI= +github.com/creachadair/mds v0.16.0 h1:v6DlvKXClowXFg4hkjLCR1FEFiREMf0qgX+Lm5GsEKk= +github.com/creachadair/mds v0.16.0/go.mod h1:4vrFYUzTXMJpMBU+OA292I6IUxKWCCfZkgXg+/kBZMo= github.com/cyphar/filepath-securejoin v0.2.5 h1:6iR5tXJ/e6tJZzzdMc1km3Sa7RRIVBKAK32O2s7AYfo= github.com/cyphar/filepath-securejoin v0.2.5/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -130,8 +128,6 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/gomarkdown/markdown v0.0.0-20240626202925-2eda941fd024 h1:saBP362Qm7zDdDXqv61kI4rzhmLFq3Z1gx34xpl6cWE= -github.com/gomarkdown/markdown v0.0.0-20240626202925-2eda941fd024/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA= github.com/gomarkdown/markdown v0.0.0-20240730141124-034f12af3bf6 h1:ZPy+2XJ8u0bB3sNFi+I72gMEMS7MTg7aZCCXPOjV8iw= github.com/gomarkdown/markdown v0.0.0-20240730141124-034f12af3bf6/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -266,8 +262,6 @@ 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/puzpuzpuz/xsync v1.5.2 h1:yRAP4wqSOZG+/4pxJ08fPTwrfL0IzE/LKQ/cw509qGY= github.com/puzpuzpuz/xsync v1.5.2/go.mod h1:K98BYhX3k1dQ2M63t1YNVDanbwUPmBCAhNmVrrxfiGg= -github.com/puzpuzpuz/xsync/v3 v3.3.1 h1:vZPJk3OOfoaSjy3cdTX3BZxhDCUVp9SqdHnd+ilGlbQ= -github.com/puzpuzpuz/xsync/v3 v3.3.1/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA= github.com/puzpuzpuz/xsync/v3 v3.4.0 h1:DuVBAdXuGFHv8adVXjWWZ63pJq+NRXOWVXlKDBZ+mJ4= github.com/puzpuzpuz/xsync/v3 v3.4.0/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= @@ -289,8 +283,6 @@ github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMT github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A= github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= -github.com/snyk/code-client-go v1.8.0 h1:6H883KAn7ybiSIxhvL2QR9yEyHgAwA2+9WVHMDNEKa8= -github.com/snyk/code-client-go v1.8.0/go.mod h1:orU911flV1kJQOlxxx0InUQkAfpBrcERsb2olfnlI8s= github.com/snyk/code-client-go v1.10.0 h1:t/hBINxj4lKvoo681uGhxHBpMued/j68p2sHbB9qbfo= github.com/snyk/code-client-go v1.10.0/go.mod h1:orU911flV1kJQOlxxx0InUQkAfpBrcERsb2olfnlI8s= github.com/snyk/error-catalog-golang-public v0.0.0-20240809094525-c48d19c27edb h1:w9tJhpTFxWqAhLeraGsMExDjGK9x5Dwj1NRFwb+t+QE= @@ -376,13 +368,9 @@ golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= -golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20240707233637-46b078467d37 h1:uLDX+AfeFCct3a2C7uIWBKMJIR3CJMhcgfrUAqjRK6w= -golang.org/x/exp v0.0.0-20240707233637-46b078467d37/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa h1:ELnwvuAXPNtPk1TJRuGkI9fDTwym6AYBu0qzT8AcHdI= golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -393,8 +381,6 @@ golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPI golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8= -golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0= golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -412,13 +398,9 @@ golang.org/x/net v0.0.0-20220725212005-46097bf591d3/go.mod h1:AaygXjzTFtRAg2ttMY golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= -golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= -golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= -golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA= golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -427,8 +409,6 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -455,8 +435,6 @@ golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= -golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -464,9 +442,8 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= -golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= -golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU= +golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -475,8 +452,6 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -489,8 +464,6 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg= -golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI= golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/infrastructure/code/autofix.go b/infrastructure/code/autofix.go index 7e20af4e2..3cea38db3 100644 --- a/infrastructure/code/autofix.go +++ b/infrastructure/code/autofix.go @@ -18,6 +18,7 @@ package code import ( "context" + "errors" "fmt" "time" @@ -92,9 +93,9 @@ func (sc *Scanner) GetAutoFixDiffs( for { select { case <-timeoutTimer.C: - msg := "Timeout waiting for code fix diffs." + const msg = "Timeout waiting for code fix diffs." logger.Error().Msg(msg) - return nil, fmt.Errorf(msg) + return nil, errors.New(msg) case <-ticker.C: suggestions, err := codeClient.GetAutoFixDiffs(span.Context(), baseDir, options) if err != nil { diff --git a/infrastructure/code/convert.go b/infrastructure/code/convert.go index 61f2dd6fd..c7d697ac1 100644 --- a/infrastructure/code/convert.go +++ b/infrastructure/code/convert.go @@ -584,7 +584,7 @@ func (s *AutofixResponse) toUnifiedDiffSuggestions(baseDir string, filePath stri edits := myers.ComputeEdits(span.URIFromPath(baseDir), contentBefore, suggestion.Value) unifiedDiff := fmt.Sprint(gotextdiff.ToUnified(baseDir, baseDir+"-fixed", contentBefore, edits)) - logger.Trace().Msgf(unifiedDiff) + logger.Trace().Msg(unifiedDiff) if len(edits) == 0 { return fixSuggestions diff --git a/internal/util/math_extensions.go b/internal/util/math_extensions.go index ad3f18a8f..22503261e 100644 --- a/internal/util/math_extensions.go +++ b/internal/util/math_extensions.go @@ -5,23 +5,23 @@ type ordered interface { } func Max[T ordered](values ...T) T { - max := values[0] + m := values[0] for _, v := range values { - if v > max { - max = v + if v > m { + m = v } } - return max + return m } func Min[T ordered](values ...T) T { - min := values[0] + m := values[0] for _, v := range values { - if v < min { - min = v + if v < m { + m = v } } - return min + return m } diff --git a/main.go b/main.go index a40f3c283..812abc94a 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,7 @@ package main import ( "bytes" + "errors" "flag" "fmt" "os" @@ -90,7 +91,7 @@ func parseFlags(args []string, c *config.Config) (string, error) { } if *versionFlag { - return buf.String(), fmt.Errorf(config.Version) + return buf.String(), errors.New(config.Version) } if *licensesFlag { From bcdc69b3eb8d40bcf2074efc2fd6edaab0523332 Mon Sep 17 00:00:00 2001 From: Bastian Doetsch Date: Mon, 19 Aug 2024 09:07:30 +0200 Subject: [PATCH 5/8] fix: clean up --- application/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/config/config.go b/application/config/config.go index 194b193c3..780d6740f 100644 --- a/application/config/config.go +++ b/application/config/config.go @@ -887,7 +887,7 @@ func (c *Config) TokenAsOAuthToken() (oauth2.Token, error) { var oauthToken oauth2.Token if _, err := uuid.Parse(c.Token()); err == nil { const msg = "creds are legacy, not oauth2" - c.Logger().Trace().Msgf(msg) + c.Logger().Trace().Msg(msg) return oauthToken, errors.New(msg) } err := json.Unmarshal([]byte(c.Token()), &oauthToken) From 1a268e9027881a057550eec98d7a4de7005a3ba3 Mon Sep 17 00:00:00 2001 From: bastiandoetsch Date: Mon, 19 Aug 2024 07:08:29 +0000 Subject: [PATCH 6/8] docs: updated licenses --- licenses/github.com/creachadair/mds/LICENSE | 4 +++- licenses/golang.org/x/crypto/LICENSE | 4 ++-- licenses/golang.org/x/exp/LICENSE | 4 ++-- licenses/golang.org/x/mod/semver/LICENSE | 4 ++-- licenses/golang.org/x/net/LICENSE | 4 ++-- licenses/golang.org/x/oauth2/LICENSE | 4 ++-- licenses/golang.org/x/sync/LICENSE | 4 ++-- licenses/golang.org/x/sys/LICENSE | 4 ++-- licenses/golang.org/x/text/LICENSE | 4 ++-- 9 files changed, 19 insertions(+), 17 deletions(-) diff --git a/licenses/github.com/creachadair/mds/LICENSE b/licenses/github.com/creachadair/mds/LICENSE index b587dcbb3..0426076d4 100644 --- a/licenses/github.com/creachadair/mds/LICENSE +++ b/licenses/github.com/creachadair/mds/LICENSE @@ -1,4 +1,6 @@ -Copyright (C) 2016-2022, Michael J. Fromberger +BSD 3-Clause License + +Copyright (C) 2015 and on, Michael J. Fromberger All Rights Reserved. Redistribution and use in source and binary forms, with or without diff --git a/licenses/golang.org/x/crypto/LICENSE b/licenses/golang.org/x/crypto/LICENSE index 6a66aea5e..2a7cf70da 100644 --- a/licenses/golang.org/x/crypto/LICENSE +++ b/licenses/golang.org/x/crypto/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009 The Go Authors. All rights reserved. +Copyright 2009 The Go Authors. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are @@ -10,7 +10,7 @@ notice, this list of conditions and the following disclaimer. copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. diff --git a/licenses/golang.org/x/exp/LICENSE b/licenses/golang.org/x/exp/LICENSE index 6a66aea5e..2a7cf70da 100644 --- a/licenses/golang.org/x/exp/LICENSE +++ b/licenses/golang.org/x/exp/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009 The Go Authors. All rights reserved. +Copyright 2009 The Go Authors. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are @@ -10,7 +10,7 @@ notice, this list of conditions and the following disclaimer. copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. diff --git a/licenses/golang.org/x/mod/semver/LICENSE b/licenses/golang.org/x/mod/semver/LICENSE index 6a66aea5e..2a7cf70da 100644 --- a/licenses/golang.org/x/mod/semver/LICENSE +++ b/licenses/golang.org/x/mod/semver/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009 The Go Authors. All rights reserved. +Copyright 2009 The Go Authors. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are @@ -10,7 +10,7 @@ notice, this list of conditions and the following disclaimer. copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. diff --git a/licenses/golang.org/x/net/LICENSE b/licenses/golang.org/x/net/LICENSE index 6a66aea5e..2a7cf70da 100644 --- a/licenses/golang.org/x/net/LICENSE +++ b/licenses/golang.org/x/net/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009 The Go Authors. All rights reserved. +Copyright 2009 The Go Authors. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are @@ -10,7 +10,7 @@ notice, this list of conditions and the following disclaimer. copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. diff --git a/licenses/golang.org/x/oauth2/LICENSE b/licenses/golang.org/x/oauth2/LICENSE index 6a66aea5e..2a7cf70da 100644 --- a/licenses/golang.org/x/oauth2/LICENSE +++ b/licenses/golang.org/x/oauth2/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009 The Go Authors. All rights reserved. +Copyright 2009 The Go Authors. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are @@ -10,7 +10,7 @@ notice, this list of conditions and the following disclaimer. copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. diff --git a/licenses/golang.org/x/sync/LICENSE b/licenses/golang.org/x/sync/LICENSE index 6a66aea5e..2a7cf70da 100644 --- a/licenses/golang.org/x/sync/LICENSE +++ b/licenses/golang.org/x/sync/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009 The Go Authors. All rights reserved. +Copyright 2009 The Go Authors. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are @@ -10,7 +10,7 @@ notice, this list of conditions and the following disclaimer. copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. diff --git a/licenses/golang.org/x/sys/LICENSE b/licenses/golang.org/x/sys/LICENSE index 6a66aea5e..2a7cf70da 100644 --- a/licenses/golang.org/x/sys/LICENSE +++ b/licenses/golang.org/x/sys/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009 The Go Authors. All rights reserved. +Copyright 2009 The Go Authors. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are @@ -10,7 +10,7 @@ notice, this list of conditions and the following disclaimer. copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. diff --git a/licenses/golang.org/x/text/LICENSE b/licenses/golang.org/x/text/LICENSE index 6a66aea5e..2a7cf70da 100644 --- a/licenses/golang.org/x/text/LICENSE +++ b/licenses/golang.org/x/text/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009 The Go Authors. All rights reserved. +Copyright 2009 The Go Authors. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are @@ -10,7 +10,7 @@ notice, this list of conditions and the following disclaimer. copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Google Inc. nor the names of its + * Neither the name of Google LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. From a0713bf2143e27f842144ae333ccab0a034d0f04 Mon Sep 17 00:00:00 2001 From: Bastian Doetsch Date: Mon, 19 Aug 2024 09:20:23 +0200 Subject: [PATCH 7/8] feat: add test for executeCLI --- domain/ide/command/execute_cli_test.go | 54 ++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 domain/ide/command/execute_cli_test.go diff --git a/domain/ide/command/execute_cli_test.go b/domain/ide/command/execute_cli_test.go new file mode 100644 index 000000000..d68ce2094 --- /dev/null +++ b/domain/ide/command/execute_cli_test.go @@ -0,0 +1,54 @@ +/* + * © 2024 Snyk Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package command + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + cli2 "github.com/snyk/snyk-ls/infrastructure/cli" + "github.com/snyk/snyk-ls/internal/testutil" + "github.com/snyk/snyk-ls/internal/types" +) + +func Test_executeCLI_callsCli(t *testing.T) { + c := testutil.UnitTest(t) + expected := `{ "outputKey": "outputValue" }` + dir := t.TempDir() + + cli := cli2.NewTestExecutorWithResponse(expected) + + args := []any{dir, "iac", "test", "--json"} + cut := executeCLICommand{ + command: types.CommandData{ + Title: "testCMD", + CommandId: types.ExecuteCLICommand, + Arguments: args, + }, + logger: c.Logger(), + cli: cli, + } + + response, err := cut.Execute(context.Background()) + require.NoError(t, err) + + assert.True(t, cli.WasExecuted()) + assert.Equal(t, expected, response) +} From d0efb6c4e8a267e696772a37fbde76a1c820e7da Mon Sep 17 00:00:00 2001 From: Bastian Doetsch Date: Mon, 19 Aug 2024 10:23:49 +0200 Subject: [PATCH 8/8] feat: add smoke test --- application/codeaction/codeaction_test.go | 9 +----- application/di/init.go | 15 ++++------ application/server/execute_command_test.go | 9 +----- application/server/server_smoke_test.go | 33 ++++++++++++++++++++++ domain/ide/command/command_factory.go | 16 +++++++++-- domain/ide/command/command_service.go | 14 ++++----- domain/ide/command/command_service_test.go | 2 +- domain/ide/command/execute_cli.go | 23 +++++++++++++-- domain/ide/command/execute_cli_test.go | 3 +- 9 files changed, 82 insertions(+), 42 deletions(-) diff --git a/application/codeaction/codeaction_test.go b/application/codeaction/codeaction_test.go index 75128e83a..2b65bb806 100644 --- a/application/codeaction/codeaction_test.go +++ b/application/codeaction/codeaction_test.go @@ -209,14 +209,7 @@ func Test_ResolveCodeAction_UnknownCommandIsReported(t *testing.T) { testutil.UnitTest(t) // Arrange service := setupService(t) - command.SetService(command.NewService( - nil, - nil, - nil, - nil, - nil, - nil, - )) + command.SetService(command.NewService(nil, nil, nil, nil, nil, nil, nil)) id := types.CodeActionData(uuid.New()) c := &sglsp.Command{ diff --git a/application/di/init.go b/application/di/init.go index f30b3562d..577938ba4 100644 --- a/application/di/init.go +++ b/application/di/init.go @@ -17,11 +17,12 @@ package di import ( - "github.com/snyk/snyk-ls/domain/snyk/persistence" "path/filepath" "runtime" "sync" + "github.com/snyk/snyk-ls/domain/snyk/persistence" + "github.com/adrg/xdg" codeClient "github.com/snyk/code-client-go" @@ -75,6 +76,7 @@ var notifier notification.Notifier var codeInstrumentor codeClientObservability.Instrumentor var codeErrorReporter codeClientObservability.ErrorReporter var scanPersister persistence.ScanSnapshotPersister +var snykCli cli.Executor func Init() { initMutex.Lock() @@ -128,7 +130,7 @@ func initInfrastructure(c *config.Config) { // so that the oauth2 provider can use it for its callback authenticationService.ConfigureProviders(c) - snykCli := cli.NewExecutor(c, errorReporter, notifier) + snykCli = cli.NewExecutor(c, errorReporter, notifier) if gafConfiguration.GetString(cli_constants.EXECUTION_MODE_KEY) == cli_constants.EXECUTION_MODE_VALUE_EXTENSION { snykCli = cli.NewExtensionExecutor(c) @@ -173,14 +175,7 @@ func initApplication(c *config.Config) { workspace.Set(w) fileWatcher = watcher.NewFileWatcher() codeActionService = codeaction.NewService(c, w, fileWatcher, notifier, snykCodeClient) - command.SetService(command.NewService( - authenticationService, - notifier, - learnService, - w, - snykCodeClient, - snykCodeScanner, - )) + command.SetService(command.NewService(authenticationService, notifier, learnService, w, snykCodeClient, snykCodeScanner, snykCli)) } /* diff --git a/application/server/execute_command_test.go b/application/server/execute_command_test.go index 428f08cf4..cc19a4d76 100644 --- a/application/server/execute_command_test.go +++ b/application/server/execute_command_test.go @@ -124,14 +124,7 @@ func Test_loginCommand_StartsAuthentication(t *testing.T) { loc, jsonRPCRecorder := setupServer(t) // reset to use real service - command.SetService(command.NewService( - di.AuthenticationService(), - nil, - nil, - nil, - nil, - nil, - )) + command.SetService(command.NewService(di.AuthenticationService(), nil, nil, nil, nil, nil, nil)) config.CurrentConfig().SetAutomaticAuthentication(false) _, err := loc.Client.Call(ctx, "initialize", nil) diff --git a/application/server/server_smoke_test.go b/application/server/server_smoke_test.go index c68ac53f3..970e49c40 100644 --- a/application/server/server_smoke_test.go +++ b/application/server/server_smoke_test.go @@ -285,6 +285,39 @@ func Test_SmokeIssueCaching(t *testing.T) { }) } +func Test_SmokeExecuteCLICommand(t *testing.T) { + loc, _ := setupServer(t) + c := testutil.SmokeTest(t, false) + c.EnableSnykCodeSecurity(false) + c.EnableSnykCodeQuality(false) + c.SetSnykIacEnabled(false) + c.SetSnykOssEnabled(true) + di.Init() + + var cloneTargetDirGoof = setupRepoAndInitialize(t, nodejsGoof, "0336589", loc, c) + folderGoof := workspace.Get().GetFolderContaining(cloneTargetDirGoof) + + // wait till the whole workspace is scanned + assert.Eventually(t, func() bool { + return folderGoof != nil && folderGoof.IsScanned() + }, maxIntegTestDuration, time.Millisecond) + + // execute scan cli command + response, err := loc.Client.Call(context.Background(), "workspace/executeCommand", sglsp.ExecuteCommandParams{ + Command: types.ExecuteCLICommand, + Arguments: []any{folderGoof.Path(), "test", "--json"}, + }) + require.NoError(t, err) + + var resp map[string]any + err = response.UnmarshalResult(&resp) + require.NoError(t, err) + + require.NotEmpty(t, resp) + require.Equal(t, float64(1), resp["exitCode"]) + require.NotEmpty(t, resp["stdOut"]) +} + func addJuiceShopAsWorkspaceFolder(t *testing.T, loc server.Local, c *config.Config) *workspace.Folder { t.Helper() var cloneTargetDirJuice, err = testutil.SetupCustomTestRepo(t, t.TempDir(), "https://github.com/juice-shop/juice-shop", "bc9cef127", c.Logger()) diff --git a/domain/ide/command/command_factory.go b/domain/ide/command/command_factory.go index 6b00f3282..bed239f55 100644 --- a/domain/ide/command/command_factory.go +++ b/domain/ide/command/command_factory.go @@ -22,6 +22,7 @@ import ( "github.com/snyk/snyk-ls/application/config" "github.com/snyk/snyk-ls/domain/snyk" "github.com/snyk/snyk-ls/infrastructure/authentication" + "github.com/snyk/snyk-ls/infrastructure/cli" "github.com/snyk/snyk-ls/infrastructure/code" "github.com/snyk/snyk-ls/infrastructure/learn" "github.com/snyk/snyk-ls/infrastructure/snyk_api" @@ -31,7 +32,18 @@ import ( // CreateFromCommandData gets a command based on the given parameters that can be passed to the CommandService // nolint: gocyclo, nolintlint // this is a factory, it's ok to have high cyclomatic complexity here -func CreateFromCommandData(c *config.Config, commandData types.CommandData, srv types.Server, authService authentication.AuthenticationService, learnService learn.Service, notifier noti.Notifier, issueProvider snyk.IssueProvider, codeApiClient SnykCodeHttpClient, codeScanner *code.Scanner) (types.Command, error) { +func CreateFromCommandData( + c *config.Config, + commandData types.CommandData, + srv types.Server, + authService authentication.AuthenticationService, + learnService learn.Service, + notifier noti.Notifier, + issueProvider snyk.IssueProvider, + codeApiClient SnykCodeHttpClient, + codeScanner *code.Scanner, + cli cli.Executor, +) (types.Command, error) { httpClient := c.Engine().GetNetworkAccess().GetHttpClient switch commandData.CommandId { @@ -77,7 +89,7 @@ func CreateFromCommandData(c *config.Config, commandData types.CommandData, srv notifier: notifier, }, nil case types.ExecuteCLICommand: - return &executeCLICommand{command: commandData, authService: authService, notifier: notifier, logger: c.Logger()}, nil + return &executeCLICommand{command: commandData, authService: authService, notifier: notifier, logger: c.Logger(), cli: cli}, nil } return nil, fmt.Errorf("unknown command %v", commandData) diff --git a/domain/ide/command/command_service.go b/domain/ide/command/command_service.go index db40969a5..9ec148129 100644 --- a/domain/ide/command/command_service.go +++ b/domain/ide/command/command_service.go @@ -25,6 +25,7 @@ import ( "github.com/snyk/snyk-ls/application/config" "github.com/snyk/snyk-ls/domain/snyk" "github.com/snyk/snyk-ls/infrastructure/authentication" + "github.com/snyk/snyk-ls/infrastructure/cli" "github.com/snyk/snyk-ls/infrastructure/code" "github.com/snyk/snyk-ls/infrastructure/learn" noti "github.com/snyk/snyk-ls/internal/notification" @@ -40,16 +41,10 @@ type serviceImpl struct { issueProvider snyk.IssueProvider codeApiClient SnykCodeHttpClient codeScanner *code.Scanner + cli cli.Executor } -func NewService( - authService authentication.AuthenticationService, - notifier noti.Notifier, - learnService learn.Service, - issueProvider snyk.IssueProvider, - codeApiClient SnykCodeHttpClient, - codeScanner *code.Scanner, -) types.CommandService { +func NewService(authService authentication.AuthenticationService, notifier noti.Notifier, learnService learn.Service, issueProvider snyk.IssueProvider, codeApiClient SnykCodeHttpClient, codeScanner *code.Scanner, cli cli.Executor) types.CommandService { return &serviceImpl{ authService: authService, notifier: notifier, @@ -57,6 +52,7 @@ func NewService( issueProvider: issueProvider, codeApiClient: codeApiClient, codeScanner: codeScanner, + cli: cli, } } @@ -77,7 +73,7 @@ func (service *serviceImpl) ExecuteCommandData(ctx context.Context, commandData logger.Debug().Msgf("executing command %s", commandData.CommandId) - command, err := CreateFromCommandData(c, commandData, server, service.authService, service.learnService, service.notifier, service.issueProvider, service.codeApiClient, service.codeScanner) + command, err := CreateFromCommandData(c, commandData, server, service.authService, service.learnService, service.notifier, service.issueProvider, service.codeApiClient, service.codeScanner, service.cli) if err != nil { logger.Err(err).Msg("failed to create command") return nil, err diff --git a/domain/ide/command/command_service_test.go b/domain/ide/command/command_service_test.go index 478735b23..b6dd7fa32 100644 --- a/domain/ide/command/command_service_test.go +++ b/domain/ide/command/command_service_test.go @@ -33,7 +33,7 @@ func Test_ExecuteCommand(t *testing.T) { ExpectedAuthURL: "https://auth.url", } authenticationService := authentication.NewAuthenticationService(c, authProvider, nil, nil) - service := NewService(authenticationService, nil, nil, nil, nil, nil) + service := NewService(authenticationService, nil, nil, nil, nil, nil, nil) cmd := types.CommandData{ CommandId: types.CopyAuthLinkCommand, } diff --git a/domain/ide/command/execute_cli.go b/domain/ide/command/execute_cli.go index b2cafbc7e..eae1ee5ab 100644 --- a/domain/ide/command/execute_cli.go +++ b/domain/ide/command/execute_cli.go @@ -18,10 +18,13 @@ package command import ( "context" + "errors" "fmt" + "os/exec" "github.com/rs/zerolog" + "github.com/snyk/snyk-ls/application/config" "github.com/snyk/snyk-ls/infrastructure/authentication" "github.com/snyk/snyk-ls/infrastructure/cli" noti "github.com/snyk/snyk-ls/internal/notification" @@ -36,6 +39,11 @@ type executeCLICommand struct { cli cli.Executor } +type cliScanResult struct { + ExitCode int `json:"exitCode"` + StdOut string `json:"stdOut"` +} + func (cmd *executeCLICommand) Command() types.CommandData { return cmd.command } @@ -46,13 +54,22 @@ func (cmd *executeCLICommand) Execute(ctx context.Context) (any, error) { } workDir := cmd.command.Arguments[0].(string) - var args []string + args := []string{config.CurrentConfig().CliSettings().Path()} for _, argument := range cmd.command.Arguments[1:] { args = append(args, argument.(string)) } + + args = cmd.cli.ExpandParametersFromConfig(args) + var exitCode int resp, err := cmd.cli.Execute(ctx, args, workDir) if err != nil { - return nil, err + var exitError *exec.ExitError + if errors.As(err, &exitError) { + exitCode = exitError.ExitCode() + } } - return string(resp), nil + return cliScanResult{ + ExitCode: exitCode, + StdOut: string(resp), + }, nil } diff --git a/domain/ide/command/execute_cli_test.go b/domain/ide/command/execute_cli_test.go index d68ce2094..b88a95824 100644 --- a/domain/ide/command/execute_cli_test.go +++ b/domain/ide/command/execute_cli_test.go @@ -50,5 +50,6 @@ func Test_executeCLI_callsCli(t *testing.T) { require.NoError(t, err) assert.True(t, cli.WasExecuted()) - assert.Equal(t, expected, response) + assert.IsType(t, cliScanResult{}, response) + assert.Equal(t, expected, response.(cliScanResult).StdOut) }