chore: Apply gofmt

This commit is contained in:
Myzel394 2024-07-28 18:05:24 +02:00
parent 403cc9a336
commit 1d55158fc8
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185
12 changed files with 579 additions and 580 deletions

View File

@ -14,20 +14,22 @@ type Value interface {
type EnumValue struct {
Values []string
}
func (v EnumValue) getTypeDescription() []string {
lines := make([]string, len(v.Values) + 1)
lines := make([]string, len(v.Values)+1)
lines[0] = "Enum of:"
for index, value := range v.Values {
lines[index + 1] += "\t* " + value
lines[index+1] += "\t* " + value
}
return lines
}
type PositiveNumberValue struct {}
type PositiveNumberValue struct{}
func (v PositiveNumberValue) getTypeDescription() []string {
return []string{ "Positive number" }
return []string{"Positive number"}
}
type ArrayValue struct {
@ -35,18 +37,20 @@ type ArrayValue struct {
Separator string
AllowDuplicates bool
}
func (v ArrayValue) getTypeDescription() []string {
subValue := v.SubValue.(Value)
return append(
[]string{ "An Array separated by " + v.Separator + " of:" },
subValue.getTypeDescription()...
[]string{"An Array separated by " + v.Separator + " of:"},
subValue.getTypeDescription()...,
)
}
type OrValue struct {
Values []Value
}
func (v OrValue) getTypeDescription() []string {
lines := make([]string, 0)
@ -66,21 +70,23 @@ func (v OrValue) getTypeDescription() []string {
}
return append(
[]string{ "One of:" },
lines...
[]string{"One of:"},
lines...,
)
}
type StringValue struct {}
type StringValue struct{}
func (v StringValue) getTypeDescription() []string {
return []string{ "String" }
return []string{"String"}
}
type CustomValue struct {
FetchValue func() Value
}
func (v CustomValue) getTypeDescription() []string {
return []string{ "Custom" }
return []string{"Custom"}
}
type Prefix struct {
@ -91,6 +97,7 @@ type PrefixWithMeaningValue struct {
Prefixes []Prefix
SubValue Value
}
func (v PrefixWithMeaningValue) getTypeDescription() []string {
subDescription := v.SubValue.getTypeDescription()
@ -100,13 +107,12 @@ func (v PrefixWithMeaningValue) getTypeDescription() []string {
return append(subDescription,
append(
[]string{ "The following prefixes are allowed:" },
[]string{"The following prefixes are allowed:"},
prefixDescription...,
)...,
)
}
type Option struct {
Documentation string
Value Value
@ -124,4 +130,3 @@ func GetDocumentation(o *Option) protocol.MarkupContent {
func NewOption(documentation string, value Value) Option {
return Option{documentation, value}
}

View File

@ -5,12 +5,13 @@ import (
"strings"
)
type ParserError interface {}
type ParserError interface{}
type OptionAlreadyExistsError struct {
Option string
FoundOnLine uint32
}
func (e OptionAlreadyExistsError) Error() string {
return fmt.Sprintf("Option %s already exists", e.Option)
}
@ -18,6 +19,7 @@ func (e OptionAlreadyExistsError) Error() string {
type OptionUnknownError struct {
Option string
}
func (e OptionUnknownError) Error() string {
return fmt.Sprintf("Option '%s' does not exist", e.Option)
}
@ -25,11 +27,13 @@ func (e OptionUnknownError) Error() string {
type MalformedLineError struct {
Line string
}
func (e MalformedLineError) Error() string {
return fmt.Sprintf("Malformed line: %s", e.Line)
}
type LineNotFoundError struct {}
type LineNotFoundError struct{}
func (e LineNotFoundError) Error() string {
return "Line not found"
}
@ -38,7 +42,7 @@ type ValueNotInEnumError struct {
availableValues []string
providedValue string
}
func (e ValueNotInEnumError) Error() string {
return fmt.Sprint("'%s' is not valid. Select one from: %s", e.providedValue, strings.Join(e.availableValues, ","))
}

View File

@ -50,7 +50,6 @@ func fetchPasswdInfo() ([]passwdInfo, error) {
return infos, nil
}
// UserValue returns a Value that fetches user names from /etc/passwd
// if `separatorForMultiple` is not empty, it will return an ArrayValue
func UserValue(separatorForMultiple string) Value {
@ -80,4 +79,3 @@ func UserValue(separatorForMultiple string) Value {
},
}
}

View File

@ -91,7 +91,7 @@ func (p *SimpleConfigParser) UpsertOption(option string, value string) {
if _, exists := p.Lines[option]; exists {
p.ReplaceOption(option, value)
} else {
p.AddLine(option + p.Options.Separator + value, len(p.Lines))
p.AddLine(option+p.Options.Separator+value, len(p.Lines))
}
}
@ -144,4 +144,3 @@ func (p *SimpleConfigParser) FindByLineNumber(lineNumber int) (string, SimpleCon
return "", SimpleConfigLine{Value: "", Position: SimpleConfigPosition{Line: 0}}, LineNotFoundError{}
}

View File

@ -28,4 +28,3 @@ func Map[T any, O any](values []T, f func(T) O) []O {
return result
}

View File

@ -24,7 +24,8 @@ func SendDiagnosticsFromParserErrors(context *glsp.Context, uri protocol.Documen
for _, parserError := range parserErrors {
switch parserError.(type) {
case common.OptionAlreadyExistsError: {
case common.OptionAlreadyExistsError:
{
err := parserError.(common.OptionAlreadyExistsError)
existingOption, _ := Parser.GetOption(err.Option)
@ -39,7 +40,7 @@ func SendDiagnosticsFromParserErrors(context *glsp.Context, uri protocol.Documen
Character: uint32(utf8.RuneCountInString(err.Option)),
},
},
Message: fmt.Sprintf("Option '%s' has already been declared on line %v", err.Option, existingOption.Position.Line + 1),
Message: fmt.Sprintf("Option '%s' has already been declared on line %v", err.Option, existingOption.Position.Line+1),
})
}
}
@ -53,4 +54,3 @@ func SendDiagnosticsFromParserErrors(context *glsp.Context, uri protocol.Documen
},
)
}

View File

@ -34,7 +34,7 @@ func PrefixPlusMinusCaret(values []string) common.PrefixWithMeaningValue {
}
}
var Options = map[string] common.Option{
var Options = map[string]common.Option{
"AcceptEnv": common.NewOption(
`Specifies what environment variables sent by the client will be copied into the session's environ(7). See SendEnv and SetEnv in ssh_config(5) for how to configure the client. The TERM environment variable is always accepted whenever the client requests a pseudo-terminal as it is required by the protocol. Variables are specified by name, which may contain the wildcard characters * and ?. Multiple environment variables may be separated by whitespace or spread across multiple AcceptEnv directives. Be warned that some environment variables could be used to bypass restricted user environments. For this reason, care should be taken in the use of this directive. The default is not to accept any environment variables.`,
common.StringValue{},
@ -87,9 +87,9 @@ See PATTERNS in ssh_config(5) for more information on patterns. This keyword may
If the publickey method is listed more than once, sshd(8) verifies that keys that have been used successfully are not reused for subsequent authentications. For example, "publickey,publickey" requires successful authentication using two different public keys.PATTERNS
Note that each authentication method listed should also be explicitly enabled in the configuration.
The available authentication methods are: "gssapi-with-mic", "hostbased", "keyboard-interactive", "none" (used for access to password-less accounts when PermitEmptyPasswords is enabled), "password" and "publickey".`,
common.OrValue {
common.OrValue{
Values: []common.Value{
common.EnumValue{ Values: []string{"any"}, },
common.EnumValue{Values: []string{"any"}},
common.ArrayValue{
AllowDuplicates: true,
SubValue: common.EnumValue{
@ -123,7 +123,7 @@ See PATTERNS in ssh_config(5) for more information on patterns. This keyword may
`Specifies a program to be used to look up the user's public keys. The program must be owned by root, not writable by group or others and specified by an absolute path. Arguments to AuthorizedKeysCommand accept the tokens described in the TOKENS section. If no arguments are specified then the username of the target user is used.
The program should produce on standard output zero or more lines of authorized_keys output (see AUTHORIZED_KEYS in sshd(8)). AuthorizedKeysCommand is tried after the usual AuthorizedKeysFile files and will not be executed if a matching key is found there. By default, no AuthorizedKeysCommand is run.`,
common.StringValue{},
),
),
"AuthorizedKeysCommandUser": common.NewOption(
`Specifies the user under whose account the AuthorizedKeysCommand is run. It is recommended to use a dedicated user that has no other role on the host than running authorized keys commands. If AuthorizedKeysCommand is specified but AuthorizedKeysCommandUser is not, then sshd(8) will refuse to start.`,
@ -141,7 +141,7 @@ See PATTERNS in ssh_config(5) for more information on patterns. This keyword may
`Specifies a program to be used to generate the list of allowed certificate principals as per AuthorizedPrincipalsFile. The program must be owned by root, not writable by group or others and specified by an absolute path. Arguments to AuthorizedPrincipalsCommand accept the tokens described in the TOKENS section. If no arguments are specified then the username of the target user is used.
The program should produce on standard output zero or more lines of AuthorizedPrincipalsFile output. If either AuthorizedPrincipalsCommand or AuthorizedPrincipalsFile is specified, then certificates offered by the client for authentication must contain a principal that is listed. By default, no AuthorizedPrincipalsCommand is run.`,
common.StringValue{},
),
),
"AuthorizedPrincipalsCommandUser": common.NewOption(
`Specifies the user under whose account the AuthorizedPrincipalsCommand is run. It is recommended to use a dedicated user that has no other role on the host than running authorized principals commands. If AuthorizedPrincipalsCommand is specified but AuthorizedPrincipalsCommandUser is not, then sshd(8) will refuse to start.`,
common.UserValue(""),
@ -154,7 +154,7 @@ See PATTERNS in ssh_config(5) for more information on patterns. This keyword may
),
"Banner": common.NewOption(`The contents of the specified file are sent to the remote user before authentication is allowed. If the argument is none then no banner is displayed. By default, no banner is displayed.`,
common.StringValue{},
),
),
"CASignatureAlgorithms": common.NewOption(
`Specifies which algorithms are allowed for signing of certificates by certificate authorities (CAs). The default is:
ssh-ed25519,ecdsa-sha2-nistp256, ecdsa-sha2-nistp384,ecdsa-sha2-nistp521, sk-ssh-ed25519@openssh.com, sk-ecdsa-sha2-nistp256@openssh.com, rsa-sha2-512,rsa-sha2-256
@ -177,7 +177,7 @@ See PATTERNS in ssh_config(5) for more information on patterns. This keyword may
SubValue: common.StringValue{},
},
},
),
),
// "ChannelTimeout": `Specifies whether and how quickly sshd(8) should close inactive channels. Timeouts are specified as one or more “type=interval” pairs separated by whitespace, where the “type” must be the special keyword “global” or a channel type name from the list below, optionally containing wildcard characters.
// The timeout value “interval” is specified in seconds or may use any of the units documented in the “TIME FORMATS” section. For example, “session=5m” would cause interactive sessions to terminate after five minutes of inactivity. Specifying a zero value disables the inactivity timeout.
// The special timeout “global” applies to all active channels, taken together. Traffic on any active channel will reset the timeout, but when the timeout expires then all open channels will be closed. Note that this global timeout is not matched by wildcards and must be specified explicitly.
@ -198,7 +198,7 @@ See PATTERNS in ssh_config(5) for more information on patterns. This keyword may
For safety, it is very important that the directory hierarchy be prevented from modification by other processes on the system (especially those outside the jail). Misconfiguration can lead to unsafe environments which sshd(8) cannot detect.
The default is none, indicating not to chroot(2).`,
common.StringValue{},
),
),
"Ciphers": common.NewOption(`Specifies the ciphers allowed. Multiple ciphers must be comma-separated. If the specified list begins with a + character, then the specified ciphers will be appended to the default set instead of replacing them. If the specified list begins with a - character, then the specified ciphers (including wildcards) will be removed from the default set instead of replacing them. If the specified list begins with a ^ character, then the specified ciphers will be placed at the head of the default set.
The supported ciphers are:
3des-cbc aes128-cbc aes192-cbc aes256-cbc aes128-ctr aes192-ctr aes256-ctr aes128-gcm@openssh.com aes256-gcm@openssh.com chacha20-poly1305@openssh.com
@ -221,7 +221,7 @@ See PATTERNS in ssh_config(5) for more information on patterns. This keyword may
"ClientAliveCountMax": common.NewOption(`Sets the number of client alive messages which may be sent without sshd(8) receiving any messages back from the client. If this threshold is reached while client alive messages are being sent, sshd will disconnect the client, terminating the session. It is important to note that the use of client alive messages is very different from TCPKeepAlive. The client alive messages are sent through the encrypted channel and therefore will not be spoofable. The TCP keepalive option enabled by TCPKeepAlive is spoofable. The client alive mechanism is valuable when the client or server depend on knowing when a connection has become unresponsive.
// The default value is 3. If ClientAliveInterval is set to 15, and ClientAliveCountMax is left at the default, unresponsive SSH clients will be disconnected after approximately 45 seconds. Setting a zero ClientAliveCountMax disables connection termination.`,
common.PositiveNumberValue{},
),
),
"ClientAliveInterval": common.NewOption(
`Sets a timeout interval in seconds after which if no data has been received from the client, sshd(8) will send a message through the encrypted channel to request a response from the client. The default is 0, indicating that these messages will not be sent to the client.`,
common.PositiveNumberValue{},
@ -316,17 +316,17 @@ See PATTERNS in ssh_config(5) for more information on patterns. This keyword may
common.EnumValue{
Values: []string{"yes", "shosts-only", "no"},
},
),
),
"IgnoreUserKnownHosts": common.NewOption(
`Specifies whether sshd(8) should ignore the user's ~/.ssh/known_hosts during HostbasedAuthentication and use only the system-wide known hosts file /etc/ssh/ssh_known_hosts. The default is “no”.`,
BooleanEnumValue,
),
"Include": common.NewOption(`Include the specified configuration file(s). Multiple pathnames may be specified and each pathname may contain glob(7) wildcards that will be expanded and processed in lexical order. Files without absolute paths are assumed to be in /etc/ssh. An Include directive may appear inside a Match block to perform conditional inclusion.`,
common.StringValue{},
),
),
"IPQoS": common.NewOption(`Specifies the IPv4 type-of-service or DSCP class for the connection. Accepted values are af11, af12, af13, af21, af22, af23, af31, af32, af33, af41, af42, af43, cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7, ef, le, lowdelay, throughput, reliability, a numeric value, or none to use the operating system default. This option may take one or two arguments, separated by whitespace. If one argument is specified, it is used as the packet class unconditionally. If two values are specified, the first is automatically selected for interactive sessions and the second for non-interactive sessions. The default is af21 (Low-Latency Data) for interactive sessions and cs1 (Lower Effort) for non-interactive sessions.`,
common.ArrayValue{
"IPQoS": common.NewOption(`Specifies the IPv4 type-of-service or DSCP class for the connection. Accepted values are af11, af12, af13, af21, af22, af23, af31, af32, af33, af41, af42, af43, cs0, cs1, cs2, cs3, cs4, cs5, cs6, cs7, ef, le, lowdelay, throughput, reliability, a numeric value, or none to use the operating system default. This option may take one or two arguments, separated by whitespace. If one argument is specified, it is used as the packet class unconditionally. If two values are specified, the first is automatically selected for interactive sessions and the second for non-interactive sessions. The default is af21 (Low-Latency Data) for interactive sessions and cs1 (Lower Effort) for non-interactive sessions.`,
common.ArrayValue{
AllowDuplicates: true,
Separator: " ",
SubValue: common.OrValue{
@ -344,8 +344,8 @@ common.ArrayValue{
},
},
},
},
),
},
),
"KbdInteractiveAuthentication": common.NewOption(
`Specifies whether to allow keyboard-interactive authentication. All authentication styles from login.conf(5) are supported. The default is yes. The argument to this keyword must be yes or no. ChallengeResponseAuthentication is a deprecated alias for this.`,
BooleanEnumValue,
@ -386,7 +386,7 @@ common.ArrayValue{
"DEBUG2",
"DEBUG3",
},
},
},
),
// "LogVerbose": `Specify one or more overrides to LogLevel. An override consists of a pattern lists that matches the source file, function and line number to force detailed logging for. For example, an override pattern of:
// kex.c:*:1000,*:kex_exchange_identification():*,packet.c:*
@ -457,7 +457,7 @@ common.ArrayValue{
"no",
},
},
),
),
"PermitTTY": common.NewOption(`Specifies whether pty(4) allocation is permitted. The default is yes.`,
BooleanEnumValue,
),
@ -471,7 +471,7 @@ common.ArrayValue{
"no",
},
},
),
),
// "PermitUserEnvironment": `Specifies whether ~/.ssh/environment and environment= options in ~/.ssh/authorized_keys are processed by sshd(8). Valid options are yes, no or a pattern-list specifying which environment variable names to accept (for example "LANG,LC_*"). The default is no. Enabling environment processing may enable users to bypass access restrictions in some configurations using mechanisms such as LD_PRELOAD.`,
"PermitUserRC": common.NewOption(`Specifies whether any ~/.ssh/rc file is executed. The default is yes.`,
BooleanEnumValue,
@ -514,7 +514,7 @@ common.ArrayValue{
Values: []string{"none", "touch-required", "verify-required"},
},
},
),
),
"PubkeyAuthentication": common.NewOption(`Specifies whether public key authentication is allowed. The default is yes.`,
BooleanEnumValue,
),
@ -534,7 +534,7 @@ common.ArrayValue{
"StreamLocalBindUnlink": common.NewOption(`Specifies whether to remove an existing Unix-domain socket file for local or remote port forwarding before creating a new one. If the socket file already exists and StreamLocalBindUnlink is not enabled, sshd will be unable to forward the port to the Unix-domain socket file. This option is only used for port forwarding to a Unix-domain socket file.
The argument must be yes or no. The default is no.`,
BooleanEnumValue,
),
),
"StrictModes": common.NewOption(`Specifies whether sshd(8) should check file modes and ownership of the user's files and home directory before accepting login. This is normally desirable because novices sometimes accidentally leave their directory or files world-writable. The default is yes. Note that this does not apply to ChrootDirectory, whose permissions and ownership are checked unconditionally.`,
BooleanEnumValue,
),
@ -558,12 +558,12 @@ common.ArrayValue{
"LOCAL7",
},
},
),
),
"TCPKeepAlive": common.NewOption(`Specifies whether the system should send TCP keepalive messages to the other side. If they are sent, death of the connection or crash of one of the machines will be properly noticed. However, this means that connections will die if the route is down temporarily, and some people find it annoying. On the other hand, if TCP keepalives are not sent, sessions may hang indefinitely on the server, leaving "ghost" users and consuming server resources.
The default is yes (to send TCP keepalive messages), and the server will notice if the network goes down or the client host crashes. This avoids infinitely hanging sessions.
To disable TCP keepalive messages, the value should be set to no.`,
BooleanEnumValue,
),
),
"TrustedUserCAKeys": common.NewOption(`Specifies a file containing public keys of certificate authorities that are trusted to sign user certificates for authentication, or none to not use one. Keys are listed one per line; empty lines and comments starting with # are allowed. If a certificate is presented for authentication and has its signing CA key listed in this file, then it may be used for authentication for any user listed in the certificate's principals list. Note that certificates that lack a list of principals will not be permitted for authentication using TrustedUserCAKeys. For more details on certificates, see the CERTIFICATES section in ssh-keygen(1).`,
common.StringValue{},
),
@ -574,13 +574,13 @@ common.ArrayValue{
"UseDNS": common.NewOption(`Specifies whether sshd(8) should look up the remote host name, and to check that the resolved host name for the remote IP address maps back to the very same IP address.
If this option is set to no (the default) then only addresses and not host names may be used in ~/.ssh/authorized_keys from and sshd_config Match Host directives.`,
BooleanEnumValue,
),
),
"UsePAM": common.NewOption(`Enables the Pluggable Authentication Module interface. If set to yes this will enable PAM authentication using KbdInteractiveAuthentication and PasswordAuthentication in addition to PAM account and session module processing for all authentication types.
"UsePAM": common.NewOption(`Enables the Pluggable Authentication Module interface. If set to yes this will enable PAM authentication using KbdInteractiveAuthentication and PasswordAuthentication in addition to PAM account and session module processing for all authentication types.
Because PAM keyboard-interactive authentication usually serves an equivalent role to password authentication, you should disable either PasswordAuthentication or KbdInteractiveAuthentication.
If UsePAM is enabled, you will not be able to run sshd(8) as a non-root user. The default is no.`,
BooleanEnumValue,
),
),
"VersionAddendum": common.NewOption(`Optionally specifies additional text to append to the SSH protocol banner sent by the server upon connection. The default is none.`,
common.OrValue{
Values: []common.Value{
@ -590,7 +590,7 @@ common.ArrayValue{
common.StringValue{},
},
},
),
),
"X11DisplayOffset": common.NewOption(`Specifies the first display number available for sshd(8)'s X11 forwarding. This prevents sshd from interfering with real X11 servers. The default is 10.`,
common.PositiveNumberValue{},
),
@ -598,7 +598,7 @@ common.ArrayValue{
When X11 forwarding is enabled, there may be additional exposure to the server and to client displays if the sshd(8) proxy display is configured to listen on the wildcard address (see X11UseLocalhost), though this is not the default. Additionally, the authentication spoofing and authentication data verification and substitution occur on the client side. The security risk of using X11 forwarding is that the client's X11 display server may be exposed to attack when the SSH client requests forwarding (see the warnings for ForwardX11 in ssh_config(5)). A system administrator may have a stance in which they want to protect clients that may expose themselves to attack by unwittingly requesting X11 forwarding, which can warrant a no setting.
Note that disabling X11 forwarding does not prevent users from forwarding X11 traffic, as users can always install their own forwarders.`,
BooleanEnumValue,
),
),
"X11UseLocalhost": common.NewOption(`Specifies whether sshd(8) should bind the X11 forwarding server to the loopback address or to the wildcard address. By default, sshd binds the forwarding server to the loopback address and sets the hostname part of the DISPLAY environment variable to localhost. This prevents remote hosts from connecting to the proxy display. However, some older X11 clients may not function with this configuration. X11UseLocalhost may be set to no to specify that the forwarding server should be bound to the wildcard address. The argument must be yes or no. The default is yes.`,
BooleanEnumValue,
),

View File

@ -8,7 +8,7 @@ import (
func createOpenSSHConfigParser() common.SimpleConfigParser {
pattern, err := regexp.Compile(`^(?:#|\s*$)`)
if (err != nil) {
if err != nil {
panic(err)
}
@ -23,4 +23,3 @@ func createOpenSSHConfigParser() common.SimpleConfigParser {
}
var Parser = createOpenSSHConfigParser()

View File

@ -100,4 +100,3 @@ func getOptionCompletions(optionName string) []protocol.CompletionItem {
return completions
}

View File

@ -18,6 +18,5 @@ func TextDocumentDidChange(context *glsp.Context, params *protocol.DidChangeText
ClearDiagnostics(context, params.TextDocument.URI)
}
return nil
}

View File

@ -22,5 +22,3 @@ func TextDocumentDidOpen(context *glsp.Context, params *protocol.DidOpenTextDocu
return nil
}

View File

@ -65,4 +65,3 @@ func setTrace(context *glsp.Context, params *protocol.SetTraceParams) error {
protocol.SetTraceValue(params.Value)
return nil
}