diff --git a/Dockerfile b/Dockerfile index 472c9e51..4f5baf7c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,8 @@ FROM quay.io/konveyor/jdtls-server-base COPY --from=builder /analyzer-lsp/konveyor-analyzer /usr/bin/konveyor-analyzer COPY --from=builder /analyzer-lsp/konveyor-analyzer-dep /usr/bin/konveyor-analyzer-dep -COPY --from=builder /analyzer-lsp/external-providers/golang-external-provider/golang-external-provider /usr/bin/golang-external-provider +COPY --from=builder /analyzer-lsp/external-providers/generic-external-provider/generic-external-provider /usr/bin/generic-external-provider +COPY --from=builder /analyzer-lsp/external-providers/golang-dependency-provider/golang-dependency-provider /usr/bin/golang-dependency-provider COPY provider_container_settings.json /analyzer-lsp/provider_settings.json diff --git a/Makefile b/Makefile index bda87721..e05ae74e 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,15 @@ DOCKER_IMAGE = test -build: analyzer deps external-golang +build: analyzer deps external-generic golang-dependency-provider analyzer: go build -o konveyor-analyzer ./cmd/analyzer/main.go -external-golang: - ( cd external-providers/golang-external-provider && go build -o golang-external-provider main.go) +external-generic: + ( cd external-providers/generic-external-provider && go build -o generic-external-provider main.go) + +golang-dependency-provider: + go build -o ./external-providers/golang-dependency-provider/golang-dependency-provider ./external-providers/golang-dependency-provider/main.go deps: go build -o konveyor-analyzer-dep ./cmd/dep/main.go diff --git a/docs/experimental/python-provider.md b/docs/experimental/python-provider.md new file mode 100644 index 00000000..a71c4181 --- /dev/null +++ b/docs/experimental/python-provider.md @@ -0,0 +1,77 @@ +# Python Provider using Generic Provider + +We are using the jedi-language-server (https://github.com/pappasam/jedi-language-server) to make a python provider using the generic provider. + +jedi-language-server can be installed using + +``` +pip install jedi-langauge-server +``` + +It will be installed in `/home//.local/bin/jedi-language-server` + +It will run without any arguments, but for more information it can be run with `--log-file LOG_FILE --verbose` + +The configuration used was: + +```json + { + "name": "python", + "binaryPath": "/path/to/generic/provider/binary", + "initConfig": [{ + "location": "examples/python", + "analysisMode": "full", + "providerSpecificConfig": { + "name": "python", + "lspServerPath": "/path/to/jedi/language/server", + } + }] + }, +``` + +The rule used to test it out was: + +```yaml + - message: python sample rule + ruleID: python-sample-rule-001 + when: + python.referenced: + pattern: "create_custom_resource_definition" +``` + +The example used for testing was: +```python + #!/usr/bin/env python + + import kubernetes + + def main(): + print(kubernetes.client.ApiextensionsV1beta1Api.create_custom_resource_definition) + + if __name__ == '__main__': + main() +``` + +## Findings + +The jedi-language-server was able to get initialized and communicate with the analyzer-lsp. + +However, it returned `null` as a response to the rule. + +After further testing, it was found that the jedi-language-server isn't able to find references to imported functions. + +jedi-language-server returned a response when the rule was + +```yaml + - message: python sample rule + ruleID: python-sample-rule-001 + when: + python.referenced: + pattern: "main" +``` + +## Results + +We are going to move onto a different language server to test out the Generic Provider. + +We are also going to investigate the behaviour of jedi-language-server to see whether not recognizing imported functions is intended. And also investigate GoPls to see whether recognizing imported functions is intended. \ No newline at end of file diff --git a/docs/providers.md b/docs/providers.md index a752d7f9..208bd7b7 100644 --- a/docs/providers.md +++ b/docs/providers.md @@ -29,24 +29,40 @@ If an explicit `proxyConfig` is not specified for a provider, system-wide proxy ```Note For Java: full analysis mode will search all the dependency and source, source-only will only search the source code. for a Jar/Ear/War, this is the code that is compiled in that archive and nothing else. ``` -#### Go provider +#### Generic provider -Here's an example config for an external `go` provider that is initialized using a binary and works on gRPC: +Generic provider can be used to create an external provider for any language that is compliant with LSP 3.17 specifications. + +Here's an example config for a external `go` provider that is initialized using the generic provider binary. ```json { "name": "go", - "binaryPath": "/path/to/go/grpc/provider/binary", + "binaryPath": "/path/to/generic/provider/binary", "initConfig": [ { "location": "/path/to/application/source/code", - "lspServerPath": "/path/to/language/server/binary", "analysisMode": "full", + "providerSpecificConfig": { + "name": "go", + "lspServerPath": "/path/to/language/server/binary", + "lspArgs": ["arg1", "arg2", "arg3"], + "dependencyProviderPath": "/path/to/dependency/provider/binary" + } } ] } ``` +The `generic provider` takes the following options in `providerSpecificConfig`: + +* `name`: Name of the provider to be displayed in the logs. + +* `lspArgs`: Arguments to be passed to run the langauge server. Optional field. + +* `dependencyProviderPath`: Path to a binary that prints the dependencies of the application as a `map[uri.URI][]provider.Dep{}`. The Dep struct can be imported from +`"github.com/konveyor/analyzer-lsp/provider"`. + #### Java provider Here's an example config for `java` provider that is currently in-tree and does not use gRPC: diff --git a/engine/conditions.go b/engine/conditions.go index 15f00f1d..59936c8c 100644 --- a/engine/conditions.go +++ b/engine/conditions.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "regexp" + "strings" "github.com/go-logr/logr" "github.com/konveyor/analyzer-lsp/output/v1/konveyor" @@ -265,7 +266,11 @@ func (ce ConditionEntry) Evaluate(ctx context.Context, log logr.Logger, condCtx func incidentsToFilepaths(incident []IncidentContext) []string { filepaths := []string{} for _, ic := range incident { - filepaths = append(filepaths, ic.FileURI.Filename()) + if strings.HasPrefix(string(ic.FileURI), uri.FileScheme) { + filepaths = append(filepaths, ic.FileURI.Filename()) + } else { + filepaths = append(filepaths, string(ic.FileURI)) + } } return filepaths } diff --git a/external-providers/golang-external-provider/go.mod b/external-providers/generic-external-provider/go.mod similarity index 81% rename from external-providers/golang-external-provider/go.mod rename to external-providers/generic-external-provider/go.mod index aede0717..478c1b60 100644 --- a/external-providers/golang-external-provider/go.mod +++ b/external-providers/generic-external-provider/go.mod @@ -1,13 +1,13 @@ -module github.com/konveyor/golang-external-provider +module github.com/konveyor/generic-external-provider go 1.19 require ( - github.com/bombsimon/logrusr/v3 v3.0.0 - github.com/getkin/kin-openapi v0.116.0 + github.com/bombsimon/logrusr/v3 v3.1.0 + github.com/getkin/kin-openapi v0.118.0 github.com/go-logr/logr v1.2.4 - github.com/konveyor/analyzer-lsp v0.0.0-20230503143412-a13c5b7be8cb - github.com/sirupsen/logrus v1.9.0 + github.com/konveyor/analyzer-lsp v0.0.0-20230717225202-ba6d8da016c1 + github.com/sirupsen/logrus v1.9.3 go.lsp.dev/uri v0.3.0 gopkg.in/yaml.v2 v2.4.0 ) @@ -39,4 +39,4 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -replace github.com/konveyor/analyzer-lsp => ../../ +replace github.com/konveyor/analyzer-lsp => ../../ \ No newline at end of file diff --git a/external-providers/golang-external-provider/go.sum b/external-providers/generic-external-provider/go.sum similarity index 92% rename from external-providers/golang-external-provider/go.sum rename to external-providers/generic-external-provider/go.sum index 3e83bf84..65c3bc36 100644 --- a/external-providers/golang-external-provider/go.sum +++ b/external-providers/generic-external-provider/go.sum @@ -2,15 +2,15 @@ github.com/PaesslerAG/gval v1.2.2 h1:Y7iBzhgE09IGTt5QgGQ2IdaYYYOU134YGHBThD+wm9E github.com/PaesslerAG/gval v1.2.2/go.mod h1:XRFLwvmkTEdYziLdaCeCa5ImcGVrfQbeNUbVR+C6xac= github.com/PaesslerAG/jsonpath v0.1.0 h1:gADYeifvlqK3R3i2cR5B4DGgxLXIPb3TRTH1mGi0jPI= github.com/PaesslerAG/jsonpath v0.1.0/go.mod h1:4BzmtoM/PI8fPO4aQGIusjGxGir2BzcV0grWtFzq1Y8= -github.com/bombsimon/logrusr/v3 v3.0.0 h1:tcAoLfuAhKP9npBxWzSdpsvKPQt1XV02nSf2lZA82TQ= -github.com/bombsimon/logrusr/v3 v3.0.0/go.mod h1:PksPPgSFEL2I52pla2glgCyyd2OqOHAnFF5E+g8Ixco= +github.com/bombsimon/logrusr/v3 v3.1.0 h1:zORbLM943D+hDMGgyjMhSAz/iDz86ZV72qaak/CA0zQ= +github.com/bombsimon/logrusr/v3 v3.1.0/go.mod h1:PksPPgSFEL2I52pla2glgCyyd2OqOHAnFF5E+g8Ixco= github.com/cbroglie/mustache v1.4.0 h1:Azg0dVhxTml5me+7PsZ7WPrQq1Gkf3WApcHMjMprYoU= github.com/cbroglie/mustache v1.4.0/go.mod h1:SS1FTIghy0sjse4DUVGV1k/40B1qE1XkD9DtDsHo9iM= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/getkin/kin-openapi v0.116.0 h1:o986hwgMzR972JzOG5j6+WTwWqllZLs1EJKMKCivs2E= -github.com/getkin/kin-openapi v0.116.0/go.mod h1:l5e9PaFUo9fyLJCPGQeXI2ML8c3P8BHOEV2VaAVf/pc= +github.com/getkin/kin-openapi v0.118.0 h1:z43njxPmJ7TaPpMSCQb7PN0dEYno4tyBPQcrFdHoLuM= +github.com/getkin/kin-openapi v0.118.0/go.mod h1:l5e9PaFUo9fyLJCPGQeXI2ML8c3P8BHOEV2VaAVf/pc= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -35,6 +35,8 @@ github.com/invopop/yaml v0.1.0 h1:YW3WGUoJEXYfzWBjn00zIlrw7brGVD0fUKRYDPAPhrc= github.com/invopop/yaml v0.1.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/konveyor/analyzer-lsp v0.0.0-20230717225202-ba6d8da016c1 h1:ayGO4il6x3cb/CakkTZVUmAjteBzTiOvrVTlarlfUd4= +github.com/konveyor/analyzer-lsp v0.0.0-20230717225202-ba6d8da016c1/go.mod h1:+k6UreVv8ztI29/RyQN8/71AAmB0aWwQoWwZd3yR8sc= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -52,8 +54,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= -github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= -github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= diff --git a/external-providers/golang-external-provider/main.go b/external-providers/generic-external-provider/main.go similarity index 87% rename from external-providers/golang-external-provider/main.go rename to external-providers/generic-external-provider/main.go index e268a251..a23a1ef2 100644 --- a/external-providers/golang-external-provider/main.go +++ b/external-providers/generic-external-provider/main.go @@ -8,7 +8,7 @@ import ( "github.com/bombsimon/logrusr/v3" "github.com/konveyor/analyzer-lsp/provider" - "github.com/konveyor/golang-external-provider/pkg/golang" + "github.com/konveyor/generic-external-provider/pkg/generic" "github.com/sirupsen/logrus" ) @@ -26,7 +26,7 @@ func main() { log := logrusr.New(logrusLog) - client := golang.NewGolangProvider() + client := generic.NewGenericProvider() if port == nil || *port == 0 { panic(fmt.Errorf("must pass in the port for the external provider")) diff --git a/external-providers/generic-external-provider/pkg/generic/dependency.go b/external-providers/generic-external-provider/pkg/generic/dependency.go new file mode 100644 index 00000000..4a90cdb1 --- /dev/null +++ b/external-providers/generic-external-provider/pkg/generic/dependency.go @@ -0,0 +1,38 @@ +package generic + +import ( + "encoding/json" + "fmt" + "os/exec" + + "github.com/konveyor/analyzer-lsp/provider" + "go.lsp.dev/uri" +) + +func (g *genericServiceClient) GetDependencies() (map[uri.URI][]*provider.Dep, error) { + cmdStr, isString := g.config.ProviderSpecificConfig["dependencyProviderPath"].(string) + if !isString { + return nil, fmt.Errorf("dependency provider path is not a string") + } + // Expects dependency provider to output provider.Dep structs to stdout + cmd := exec.Command(cmdStr) + cmd.Dir = g.config.Location + dataR, err := cmd.Output() + if err != nil { + return nil, err + } + data := string(dataR) + if len(data) == 0 { + return nil, nil + } + m := map[uri.URI][]*provider.Dep{} + err = json.Unmarshal([]byte(data), &m) + if err != nil { + return nil, err + } + return m, err +} + +func (p *genericServiceClient) GetDependenciesDAG() (map[uri.URI][]provider.DepDAGItem, error) { + return nil, nil +} diff --git a/external-providers/golang-external-provider/pkg/golang/dependency_test.go b/external-providers/generic-external-provider/pkg/generic/dependency_test.go similarity index 99% rename from external-providers/golang-external-provider/pkg/golang/dependency_test.go rename to external-providers/generic-external-provider/pkg/generic/dependency_test.go index 1a2466fd..45b77a44 100644 --- a/external-providers/golang-external-provider/pkg/golang/dependency_test.go +++ b/external-providers/generic-external-provider/pkg/generic/dependency_test.go @@ -1,4 +1,4 @@ -package golang +package generic import ( "fmt" diff --git a/external-providers/golang-external-provider/pkg/golang/provider.go b/external-providers/generic-external-provider/pkg/generic/provider.go similarity index 61% rename from external-providers/golang-external-provider/pkg/golang/provider.go rename to external-providers/generic-external-provider/pkg/generic/provider.go index 223e8ca6..32e0bf0d 100644 --- a/external-providers/golang-external-provider/pkg/golang/provider.go +++ b/external-providers/generic-external-provider/pkg/generic/provider.go @@ -1,4 +1,4 @@ -package golang +package generic import ( "context" @@ -14,17 +14,17 @@ import ( // TODO(shawn-hurley): Pipe the logger through // Determine how and where external providers will add the logs to make the logs viewable in a single location. -type golangProvider struct { +type genericProvider struct { ctx context.Context } -var _ provider.BaseClient = &golangProvider{} +var _ provider.BaseClient = &genericProvider{} -func NewGolangProvider() *golangProvider { - return &golangProvider{} +func NewGenericProvider() *genericProvider { + return &genericProvider{} } -func (p *golangProvider) Capabilities() []provider.Capability { +func (p *genericProvider) Capabilities() []provider.Capability { return []provider.Capability{ { Name: "referenced", @@ -37,18 +37,24 @@ func (p *golangProvider) Capabilities() []provider.Capability { } } -type golangCondition struct { - Referenced string `yaml:"referenced"` +type genericCondition struct { + Referenced referenceCondition `yaml:"referenced"` } -func (p *golangProvider) Init(ctx context.Context, log logr.Logger, c provider.InitConfig) (provider.ServiceClient, error) { +type referenceCondition struct { + Pattern string `yaml:"pattern"` +} + +func (p *genericProvider) Init(ctx context.Context, log logr.Logger, c provider.InitConfig) (provider.ServiceClient, error) { if c.AnalysisMode != provider.FullAnalysisMode { return nil, fmt.Errorf("only full analysis is supported") } - // handle proxy settings - for k, v := range c.Proxy.ToEnvVars() { - os.Setenv(k, v) + if c.Proxy != nil { + // handle proxy settings + for k, v := range c.Proxy.ToEnvVars() { + os.Setenv(k, v) + } } lspServerPath, ok := c.ProviderSpecificConfig[provider.LspServerPathConfigKey].(string) @@ -57,8 +63,22 @@ func (p *golangProvider) Init(ctx context.Context, log logr.Logger, c provider.I } ctx, cancelFunc := context.WithCancel(ctx) - log = log.WithValues("provider", "golang") - cmd := exec.CommandContext(ctx, lspServerPath) + log = log.WithValues("provider", c.ProviderSpecificConfig["name"]) + var args []string + if lspArgs, ok := c.ProviderSpecificConfig["lspArgs"]; ok { + rawArgs, isArray := lspArgs.([]interface{}) + if !isArray { + return nil, fmt.Errorf("lspArgs is not an array") + } + for _, rawArg := range rawArgs { + if arg, ok := rawArg.(string); ok { + args = append(args, arg) + } else { + return nil, fmt.Errorf("item of lspArgs is not a string") + } + } + } + cmd := exec.CommandContext(ctx, lspServerPath, args...) stdin, err := cmd.StdinPipe() if err != nil { return nil, err @@ -88,7 +108,7 @@ func (p *golangProvider) Init(ctx context.Context, log logr.Logger, c provider.I } }() - svcClient := golangServiceClient{ + svcClient := genericServiceClient{ rpc: rpc, ctx: ctx, cancelFunc: cancelFunc, diff --git a/external-providers/golang-external-provider/pkg/golang/service_client.go b/external-providers/generic-external-provider/pkg/generic/service_client.go similarity index 66% rename from external-providers/golang-external-provider/pkg/golang/service_client.go rename to external-providers/generic-external-provider/pkg/generic/service_client.go index c8c11621..06f4600b 100644 --- a/external-providers/golang-external-provider/pkg/golang/service_client.go +++ b/external-providers/generic-external-provider/pkg/generic/service_client.go @@ -1,4 +1,4 @@ -package golang +package generic import ( "context" @@ -15,7 +15,7 @@ import ( "gopkg.in/yaml.v2" ) -type golangServiceClient struct { +type genericServiceClient struct { rpc *jsonrpc2.Conn ctx context.Context cancelFunc context.CancelFunc @@ -24,19 +24,19 @@ type golangServiceClient struct { config provider.InitConfig } -var _ provider.ServiceClient = &golangServiceClient{} +var _ provider.ServiceClient = &genericServiceClient{} -func (p *golangServiceClient) Stop() { +func (p *genericServiceClient) Stop() { p.cancelFunc() p.cmd.Wait() } -func (p *golangServiceClient) Evaluate(cap string, conditionInfo []byte) (provider.ProviderEvaluateResponse, error) { - var cond golangCondition +func (p *genericServiceClient) Evaluate(cap string, conditionInfo []byte) (provider.ProviderEvaluateResponse, error) { + var cond genericCondition err := yaml.Unmarshal(conditionInfo, &cond) if err != nil { return provider.ProviderEvaluateResponse{}, fmt.Errorf("unable to get query info") } - query := cond.Referenced + query := cond.Referenced.Pattern if query == "" { return provider.ProviderEvaluateResponse{}, fmt.Errorf("unable to get query info") } @@ -45,23 +45,21 @@ func (p *golangServiceClient) Evaluate(cap string, conditionInfo []byte) (provid incidents := []provider.IncidentContext{} for _, s := range symbols { - if s.Kind == protocol.Struct { - references := p.GetAllReferences(s) - for _, ref := range references { - // Look for things that are in the location loaded, //Note may need to filter out vendor at some point - if strings.Contains(ref.URI, p.config.Location) { - u, err := uri.Parse(ref.URI) - if err != nil { - return provider.ProviderEvaluateResponse{}, err - } - lineNumber := int(ref.Range.Start.Line) - incidents = append(incidents, provider.IncidentContext{ - FileURI: u, - LineNumber: &lineNumber, - Variables: map[string]interface{}{ - "file": ref.URI}, - }) + references := p.GetAllReferences(s) + for _, ref := range references { + // Look for things that are in the location loaded, //Note may need to filter out vendor at some point + if strings.Contains(ref.URI, p.config.Location) { + u, err := uri.Parse(ref.URI) + if err != nil { + return provider.ProviderEvaluateResponse{}, err } + lineNumber := int(ref.Range.Start.Line) + incidents = append(incidents, provider.IncidentContext{ + FileURI: u, + LineNumber: &lineNumber, + Variables: map[string]interface{}{ + "file": ref.URI}, + }) } } } @@ -76,7 +74,7 @@ func (p *golangServiceClient) Evaluate(cap string, conditionInfo []byte) (provid }, nil } -func (p *golangServiceClient) GetAllSymbols(query string) []protocol.WorkspaceSymbol { +func (p *genericServiceClient) GetAllSymbols(query string) []protocol.WorkspaceSymbol { wsp := &protocol.WorkspaceSymbolParams{ Query: query, @@ -93,7 +91,7 @@ func (p *golangServiceClient) GetAllSymbols(query string) []protocol.WorkspaceSy return refs } -func (p *golangServiceClient) GetAllReferences(symbol protocol.WorkspaceSymbol) []protocol.Location { +func (p *genericServiceClient) GetAllReferences(symbol protocol.WorkspaceSymbol) []protocol.Location { params := &protocol.ReferenceParams{ TextDocumentPositionParams: protocol.TextDocumentPositionParams{ TextDocument: protocol.TextDocumentIdentifier{ @@ -111,7 +109,7 @@ func (p *golangServiceClient) GetAllReferences(symbol protocol.WorkspaceSymbol) return res } -func (p *golangServiceClient) initialization(ctx context.Context, log logr.Logger) { +func (p *genericServiceClient) initialization(ctx context.Context, log logr.Logger) { // Get abosulte path of location. abs, err := filepath.Abs(p.config.Location) if err != nil { @@ -139,6 +137,6 @@ func (p *golangServiceClient) initialization(ctx context.Context, log logr.Logge if err := p.rpc.Notify(ctx, "initialized", &protocol.InitializedParams{}); err != nil { fmt.Printf("initialized failed: %v", err) } - fmt.Printf("golang connection initialized") - log.V(2).Info("golang connection initialized") + fmt.Printf("provider connection initialized") + log.V(2).Info("provider connection initialized") } diff --git a/external-providers/golang-dependency-provider/go.mod b/external-providers/golang-dependency-provider/go.mod new file mode 100644 index 00000000..db3c9694 --- /dev/null +++ b/external-providers/golang-dependency-provider/go.mod @@ -0,0 +1,36 @@ +module github.com/konveyor/golang-dependency-provider + +go 1.19 + +require ( + github.com/konveyor/analyzer-lsp v0.0.0-20230720174825-d5121b9d0fdd + go.lsp.dev/uri v0.3.0 +) + +require ( + github.com/PaesslerAG/gval v1.2.2 // indirect + github.com/cbroglie/mustache v1.4.0 // indirect + github.com/getkin/kin-openapi v0.108.0 // indirect + github.com/go-logr/logr v1.2.3 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/go-openapi/jsonpointer v0.19.5 // indirect + github.com/go-openapi/swag v0.19.5 // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/hashicorp/go-version v1.6.0 // indirect + github.com/invopop/yaml v0.1.0 // indirect + github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e // indirect + github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect + github.com/shopspring/decimal v1.3.1 // indirect + go.opentelemetry.io/otel v1.11.2 // indirect + go.opentelemetry.io/otel/exporters/jaeger v1.11.2 // indirect + go.opentelemetry.io/otel/sdk v1.11.2 // indirect + go.opentelemetry.io/otel/trace v1.11.2 // indirect + golang.org/x/net v0.8.0 // indirect + golang.org/x/sys v0.6.0 // indirect + golang.org/x/text v0.8.0 // indirect + google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect + google.golang.org/grpc v1.54.0 // indirect + google.golang.org/protobuf v1.30.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/external-providers/golang-dependency-provider/go.sum b/external-providers/golang-dependency-provider/go.sum new file mode 100644 index 00000000..ebb73f02 --- /dev/null +++ b/external-providers/golang-dependency-provider/go.sum @@ -0,0 +1,93 @@ +github.com/PaesslerAG/gval v1.2.2 h1:Y7iBzhgE09IGTt5QgGQ2IdaYYYOU134YGHBThD+wm9E= +github.com/PaesslerAG/gval v1.2.2/go.mod h1:XRFLwvmkTEdYziLdaCeCa5ImcGVrfQbeNUbVR+C6xac= +github.com/PaesslerAG/jsonpath v0.1.0 h1:gADYeifvlqK3R3i2cR5B4DGgxLXIPb3TRTH1mGi0jPI= +github.com/PaesslerAG/jsonpath v0.1.0/go.mod h1:4BzmtoM/PI8fPO4aQGIusjGxGir2BzcV0grWtFzq1Y8= +github.com/bombsimon/logrusr/v3 v3.0.0 h1:tcAoLfuAhKP9npBxWzSdpsvKPQt1XV02nSf2lZA82TQ= +github.com/cbroglie/mustache v1.4.0 h1:Azg0dVhxTml5me+7PsZ7WPrQq1Gkf3WApcHMjMprYoU= +github.com/cbroglie/mustache v1.4.0/go.mod h1:SS1FTIghy0sjse4DUVGV1k/40B1qE1XkD9DtDsHo9iM= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/getkin/kin-openapi v0.108.0 h1:EYf0GtsKa4hQNIlplGS+Au7NEfGQ1F7MoHD2kcVevPQ= +github.com/getkin/kin-openapi v0.108.0/go.mod h1:QtwUNt0PAAgIIBEvFWYfB7dfngxtAaqCX1zYHMZDeK8= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= +github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= +github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY= +github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= +github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= +github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/invopop/yaml v0.1.0 h1:YW3WGUoJEXYfzWBjn00zIlrw7brGVD0fUKRYDPAPhrc= +github.com/invopop/yaml v0.1.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q= +github.com/konveyor/analyzer-lsp v0.0.0-20230720174825-d5121b9d0fdd h1:vRpRriiYMxBcT1Avz3IuIqTAINX+8hGAdDfEDfPT3kM= +github.com/konveyor/analyzer-lsp v0.0.0-20230720174825-d5121b9d0fdd/go.mod h1:+k6UreVv8ztI29/RyQN8/71AAmB0aWwQoWwZd3yR8sc= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq0y3QnmWAArdw9PqbmotexnWx/FU8= +github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= +github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= +github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +go.lsp.dev/uri v0.3.0 h1:KcZJmh6nFIBeJzTugn5JTU6OOyG0lDOo3R9KwTxTYbo= +go.lsp.dev/uri v0.3.0/go.mod h1:P5sbO1IQR+qySTWOCnhnK7phBx+W3zbLqSMDJNTw88I= +go.opentelemetry.io/otel v1.11.2 h1:YBZcQlsVekzFsFbjygXMOXSs6pialIZxcjfO/mBDmR0= +go.opentelemetry.io/otel v1.11.2/go.mod h1:7p4EUV+AqgdlNV9gL97IgUZiVR3yrFXYo53f9BM3tRI= +go.opentelemetry.io/otel/exporters/jaeger v1.11.2 h1:ES8/j2+aB+3/BUw51ioxa50V9btN1eew/2J7N7n1tsE= +go.opentelemetry.io/otel/exporters/jaeger v1.11.2/go.mod h1:nwcF/DK4Hk0auZ/a5vw20uMsaJSXbzeeimhN5f9d0Lc= +go.opentelemetry.io/otel/sdk v1.11.2 h1:GF4JoaEx7iihdMFu30sOyRx52HDHOkl9xQ8SMqNXUiU= +go.opentelemetry.io/otel/sdk v1.11.2/go.mod h1:wZ1WxImwpq+lVRo4vsmSOxdd+xwoUJ6rqyLc3SyX9aU= +go.opentelemetry.io/otel/trace v1.11.2 h1:Xf7hWSF2Glv0DE3MH7fBHvtpSBsjcBUe5MYAmZM/+y0= +go.opentelemetry.io/otel/trace v1.11.2/go.mod h1:4N+yC7QEz7TTsG9BSRLNAa63eg5E06ObSbKPmxQ/pKA= +golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f h1:BWUVssLB0HVOSY78gIdvk1dTVYtT1y8SBWtPYuTJ/6w= +google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= +google.golang.org/grpc v1.54.0 h1:EhTqbhiYeixwWQtAEZAxmV9MGqcjEU2mFx52xCzNyag= +google.golang.org/grpc v1.54.0/go.mod h1:PUSEXI6iWghWaB6lXM4knEgpJNu2qUcKfDtNci3EC2g= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= +google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/external-providers/golang-dependency-provider/golang-dependency-provider b/external-providers/golang-dependency-provider/golang-dependency-provider new file mode 100755 index 00000000..a859a08b Binary files /dev/null and b/external-providers/golang-dependency-provider/golang-dependency-provider differ diff --git a/external-providers/golang-external-provider/pkg/golang/dependency.go b/external-providers/golang-dependency-provider/main.go similarity index 80% rename from external-providers/golang-external-provider/pkg/golang/dependency.go rename to external-providers/golang-dependency-provider/main.go index a0f07904..8f6ce776 100644 --- a/external-providers/golang-external-provider/pkg/golang/dependency.go +++ b/external-providers/golang-dependency-provider/main.go @@ -1,8 +1,10 @@ -package golang +package main import ( "bytes" + "encoding/json" "fmt" + "log" "os/exec" "path/filepath" "strings" @@ -18,27 +20,14 @@ const ( ) // TODO implement this for real -func (g *golangServiceClient) findGoMod() string { - var depPath string - if g.config.DependencyPath == "" { - depPath = "go.mod" - } else { - depPath = g.config.DependencyPath - } - f, err := filepath.Abs(filepath.Join(g.config.Location, depPath)) +func main() { + ll, err := GetDependenciesDAG() if err != nil { - return "" - } - return f -} - -func (g *golangServiceClient) GetDependencies() (map[uri.URI][]*provider.Dep, error) { - ll, err := g.GetDependenciesDAG() - if err != nil { - return nil, err + log.Fatal(err) + return } if len(ll) == 0 { - return nil, nil + return } m := map[uri.URI][]*provider.Dep{} @@ -46,14 +35,32 @@ func (g *golangServiceClient) GetDependencies() (map[uri.URI][]*provider.Dep, er m[u] = provider.ConvertDagItemsToList(d) } - return m, err + jsonStr, err := json.Marshal(m) + if err != nil { + log.Fatal(fmt.Errorf("unable to marshal dependencies")) + return + } + + // Outputs the dependency list for the generic provider + fmt.Println(string(jsonStr)) + +} + +func ConvertDagItemsToList(items []provider.DepDAGItem) []provider.Dep { + deps := []provider.Dep{} + for _, i := range items { + d := i.Dep + deps = append(deps, d) + deps = append(deps, ConvertDagItemsToList(i.AddedDeps)...) + } + return deps } -func (g *golangServiceClient) GetDependenciesDAG() (map[uri.URI][]provider.DepDAGItem, error) { +func GetDependenciesDAG() (map[uri.URI][]provider.DepDAGItem, error) { // We are going to run the graph command, and write a parser for this. // This is so that we can get the tree of deps. - path := g.findGoMod() + path := "go.mod" file := uri.File(path) moddir := filepath.Dir(path) @@ -93,8 +100,8 @@ func parseGoDepString(dep string) (provider.Dep, error) { d.Name = strings.TrimSpace(v[0]) d.Version = strings.TrimSpace(strings.ReplaceAll(v[1], "@", "")) d.Labels = []string{ - labels.AsString(provider.DepSourceLabel,golangDownloadableDepSourceLabel), - labels.AsString(provider.DepLanguageLabel,"go"), + labels.AsString(provider.DepSourceLabel, golangDownloadableDepSourceLabel), + labels.AsString(provider.DepLanguageLabel, "go"), } return d, nil } diff --git a/parser/testdata/no-actions.yaml b/parser/testdata/no-actions.yaml index fc1057a7..bf249dde 100644 --- a/parser/testdata/no-actions.yaml +++ b/parser/testdata/no-actions.yaml @@ -2,4 +2,5 @@ - ruleID: no-actions-001 when: and: - - go.referenced: "a" \ No newline at end of file + - go.referenced: + pattern: "a" \ No newline at end of file diff --git a/provider/internal/builtin/service_client.go b/provider/internal/builtin/service_client.go index 8a7e81f5..f7a8a3d4 100644 --- a/provider/internal/builtin/service_client.go +++ b/provider/internal/builtin/service_client.go @@ -87,7 +87,12 @@ func (p *builtintServiceClient) Evaluate(cap string, conditionInfo []byte) (prov } return response, fmt.Errorf("could not run grep with provided pattern %+v", err) } - matches := strings.Split(strings.TrimSpace(string(outputBytes)), "\n") + + matches := []string{} + outputString := strings.TrimSpace(string(outputBytes)) + if outputString != "" { + matches = append(matches, strings.Split(outputString, "\n")...) + } for _, match := range matches { //TODO(fabianvf): This will not work if there is a `:` in the filename, do we care? @@ -95,7 +100,8 @@ func (p *builtintServiceClient) Evaluate(cap string, conditionInfo []byte) (prov if len(pieces) != 3 { //TODO(fabianvf): Just log or return? //(shawn-hurley): I think the return is good personally - return response, fmt.Errorf("Malformed response from grep, cannot parse %s with pattern {filepath}:{lineNumber}:{matchingText}", match) + return response, fmt.Errorf( + "malformed response from grep, cannot parse grep output '%s' with pattern {filepath}:{lineNumber}:{matchingText}", match) } containsFile, err := provider.FilterFilePattern(c.FilePattern, pieces[0]) diff --git a/provider/internal/java/provider.go b/provider/internal/java/provider.go index b2a9deae..b31f16aa 100644 --- a/provider/internal/java/provider.go +++ b/provider/internal/java/provider.go @@ -251,7 +251,10 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide go func() { err := cmd.Start() if err != nil { - fmt.Printf("here cmd failed- %v", err) + cancelFunc() + returnErr = err + log.Error(err, "unable to start lsp command") + return } }() rpc := jsonrpc2.NewConn(jsonrpc2.NewHeaderStream(stdout, stdin), log) @@ -264,6 +267,8 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide //TODO: we need to pipe the ctx further into the stream header and run. // basically it is checking if done, then reading. When it gets EOF it errors. // We need the read to be at the same level of selection to fully implment graceful shutdown + cancelFunc() + returnErr = err return } }() diff --git a/provider/internal/java/service_client.go b/provider/internal/java/service_client.go index a1b3880c..13f87c84 100644 --- a/provider/internal/java/service_client.go +++ b/provider/internal/java/service_client.go @@ -196,7 +196,7 @@ func (p *javaServiceClient) initialization() { } var result protocol.InitializeResult - for { + for i:=0; i < 10; i++ { if err := p.rpc.Call(p.ctx, "initialize", params, &result); err != nil { p.log.Error(err, "initialize failed") continue diff --git a/provider_container_settings.json b/provider_container_settings.json index b00a9717..4cf48669 100644 --- a/provider_container_settings.json +++ b/provider_container_settings.json @@ -1,12 +1,14 @@ [ { "name": "go", - "binaryPath": "/usr/bin/golang-external-provider", + "binaryPath": "/usr/bin/generic-external-provider", "initConfig": [{ "location": "examples/golang", "analysisMode": "full", "providerSpecificConfig": { - "lspServerPath": "/root/go/bin/gopls" + "name": "go", + "lspServerPath": "/root/go/bin/gopls", + "dependencyProviderPath": "/usr/bin/golang-dependency-provider" } }] }, diff --git a/rule-example.yaml b/rule-example.yaml index 5ef0248f..a2ac341f 100644 --- a/rule-example.yaml +++ b/rule-example.yaml @@ -42,18 +42,21 @@ - java.referenced: pattern: "*apiextensions.v1beta1.CustomResourceDefinition*" location: TYPE - - go.referenced: "v1beta1.CustomResourceDefinition" + - go.referenced: + pattern: "v1beta1.CustomResourceDefinition" - message: 'golang apiextensions/v1/customresourcedefinitions found {{file}}:{{lineNumber}}' ruleID: go-lang-ref-001 when: - go.referenced: "v1beta1.CustomResourceDefinition" + go.referenced: + pattern: "v1beta1.CustomResourceDefinition" - message: testing nested conditions ruleID: lang-ref-002 when: # This is purposfully failing, the golang reference will not # find anything. testing that `and` will work correctly and: - - go.referenced: "*CustomResourceDefinition*" + - go.referenced: + pattern: "*CustomResourceDefinition*" - java.referenced: pattern: "*CustomResourceDefinition*" location: TYPE