mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
feat: Add ssh diagnoser
This commit is contained in:
parent
267a0ff604
commit
4d7297e7b9
@ -25,3 +25,20 @@ func SendDiagnostics(context *glsp.Context, uri protocol.DocumentUri, diagnostic
|
||||
)
|
||||
}
|
||||
|
||||
func DiagnoseOption(
|
||||
context *glsp.Context,
|
||||
uri protocol.DocumentUri,
|
||||
parser *SimpleConfigParser,
|
||||
optionName string,
|
||||
checkerFunc func (string, SimpleConfigPosition) []protocol.Diagnostic,
|
||||
) []protocol.Diagnostic {
|
||||
option, err := parser.GetOption(optionName)
|
||||
|
||||
if err != nil {
|
||||
// Nothing to diagnose
|
||||
return nil
|
||||
}
|
||||
|
||||
return checkerFunc(option.Value, option.Position)
|
||||
}
|
||||
|
||||
|
52
handlers/openssh/diagnose-ssh-options.go
Normal file
52
handlers/openssh/diagnose-ssh-options.go
Normal file
@ -0,0 +1,52 @@
|
||||
package openssh
|
||||
|
||||
import (
|
||||
"config-lsp/common"
|
||||
|
||||
"github.com/tliron/glsp"
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func DiagnoseSSHOptions(
|
||||
context *glsp.Context,
|
||||
params *protocol.DidChangeTextDocumentParams,
|
||||
) []protocol.Diagnostic {
|
||||
diagnostics := make([]protocol.Diagnostic, 0)
|
||||
|
||||
diagnostics = append(
|
||||
diagnostics,
|
||||
common.DiagnoseOption(
|
||||
context,
|
||||
params.TextDocument.URI,
|
||||
&Parser,
|
||||
"Port",
|
||||
func (value string, position common.SimpleConfigPosition) []protocol.Diagnostic {
|
||||
if (value == "22") {
|
||||
severity := protocol.DiagnosticSeverityWarning
|
||||
|
||||
return []protocol.Diagnostic{
|
||||
{
|
||||
Range: protocol.Range{
|
||||
Start: protocol.Position{
|
||||
Line: position.Line,
|
||||
Character: uint32(len("Port ")),
|
||||
},
|
||||
End: protocol.Position{
|
||||
Line: position.Line,
|
||||
Character: uint32(len("Port " + value)),
|
||||
},
|
||||
},
|
||||
Severity: &severity,
|
||||
Message: "Port should not be 22 as it's often enumarated by attackers",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return []protocol.Diagnostic{}
|
||||
},
|
||||
)...
|
||||
)
|
||||
|
||||
return diagnostics
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ func TextDocumentDidChange(context *glsp.Context, params *protocol.DidChangeText
|
||||
)...,
|
||||
)
|
||||
|
||||
diagnostics = DiagnoseSSHOptions(context, params)
|
||||
|
||||
if len(diagnostics) > 0 {
|
||||
common.SendDiagnostics(context, params.TextDocument.URI, diagnostics)
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user