aboutsummaryrefslogtreecommitdiff
path: root/lib/ssh/config
AgeCommit message (Collapse)Author
2024-03-09lib: move package "ssh/config" to "lib/sshconfig"Shulhan
Previously the "ssh/config" is used by the parent package "ssh" and "ssh/sftp" which is break the rule of package layer (the top package should be imported by sub package, not the other way around).
2024-03-05all: comply with linter recommendations #2Shulhan
HTTP request now implicitly create request with context. Any false positive related to not closing HTTP response body has been annotated with "nolint:bodyclose". In the example code, use consistent "// Output:" comment format, by prefixing with single space. Any comment on code now also prefixing with single space. An error returned without variables now use [errors.New] instead of [fmt.Errorf]. Any error returned using [fmt.Errorf] now wrapped using "%w" instead of "%s". Also, replace error checking using [errors.Is] or [errors.As], instead of using equal/not-equal operator. Any statement like "x = x OP y" now replaced with "x OP= y". Also, swap statement is simplified using "x, y = y, x". Any switch statement with single case now replaced with if-condition. Any call to defer on function or program that call [os.Exit], now replaced by calling the deferred function directly. Any if-else condition now replaced with switch statement, if possible.
2024-03-05all: comply with linter recommendations #1Shulhan
Instead of annotating the lines that caught by linters, fix it to comply with the recommendations. This causes several breaking changes, especially related to naming, * api/slack: [Message.IconUrl] become [Message.IconURL] * lib/dns: DefaultSoaMinumumTtl become DefaultSoaMinimumTTL * lib/email: [Message.SetBodyHtml] become [Message.SetBodyHTML] * lib/http: [Client.GenerateHttpRequest] become [Client.GenerateHTTPRequest] * lib/http: [ClientOptions.ServerUrl] become [ClientOptions.ServerURL] * lib/http: [EndpointRequest.HttpWriter] become [EndpointRequest.HTTPWriter] * lib/http: [EndpointRequest.HttpRequest] become [EndpointRequest.HTTPRequest] * lib/http: [ServerOptions.EnableIndexHtml] become [ServerOptions.EnableIndexHTML] * lib/http: [SSEConn.HttpRequest] become [SSEConn.HTTPRequest] * lib/smtp: [ClientOptions.ServerUrl] become [ClientOptions.ServerURL] * lib/ssh/sftp: [FileAttrs.SetUid] become [FileAttrs.SetUID] * lib/ssh/sftp: [FileAttrs.Uid] become [FileAttrs.UID]
2024-03-02all: move the repository to "git.sr.ht/~shulhan/pakakeh.go"Shulhan
There are several reasons that why we move from github.com. First, related to the name of package. We accidentally name the package with "share" a common word in English that does not reflect the content of repository. By moving to other repository, we can rename it to better and unique name, in this "pakakeh.go". Pakakeh is Minang word for tools, and ".go" suffix indicate that the repository related to Go programming language. Second, supporting open source. The new repository is hosted under sourcehut.org, the founder is known to support open source, and all their services are licensed under AGPL, unlike GitHub that are closed sources. Third, regarding GitHub CoPilot. The GitHub Terms of Service [1], allow any public content that are hosted there granted them to parse the content. On one side, GitHub helps and flourish the open source, but on another side have an issues regarding scraping the copyleft license [2]. [1]: https://docs.github.com/en/site-policy/github-terms/github-terms-of-service#4-license-grant-to-us [2]: https://githubcopilotinvestigation.com
2023-12-26ssh/config: refactoring the Config mergeShulhan
This changes rename method [Config.Prepend] to [Config.Merge]. The way that how the other Config merged is changed. Instead of appending all of other's sections into the current Config, append the other Config instance to the current instance of Config. During [Config.Get] the top Config will be evaluated first, and then the other Config is evaluated in order of Merge.
2023-12-26ssh/config: merge the Section slice values on [Section.merge]Shulhan
Instead of using [Section.Set], set the key-value directly. While at it, merge the certificateFile, IdentityFile, knownHostFiles, and sendEnv.
2023-12-25ssh/config: set the default UserKnownHostsFile in setDefaultsShulhan
While at it, unfold each value of IdentityFile and UserKnownHostsFile in setDefaults, by expanding "~" into user's home directory or joining with "config" directory if its relative.
2023-12-25ssh/config: update comment on [Config.Get]Shulhan
Make it clear that the passed parameter is a host name and the returned section will contains default values if no host or match found.
2023-12-25ssh/config: add parameter Config to NewSectionShulhan
This changes how the Section and parser initialized. Previously, the Config depends on the parser to set the workDir and homeDir and Section depends on Config only on Get; now its the other way around, from top to bottom. Config initialized first, then parser initialized using Config instance, and then Section initialized also using Config instance.
2023-12-25ssh/config: fix setting the default valuesShulhan
The field default value should be set on Get, after all the Host or Match fields merged. In this way, if the field key already set, its not overridden by the default value or subsequent Host or Match vaue.
2023-12-19ssh/config: set the Hostname if its not set on [Config.Get]Shulhan
Per manual ssh_config(5) on Hostname, The default is the name given on the command line. So, if the requested host name match with one of Host or Match, but Hostname is not set, it should be default to the requested parameter name.
2023-12-19ssh/config: rewrite unit tests for [Config.Get] using [lib.test.Data]Shulhan
Using test.Data make the output easy to audit and modified.
2023-12-19ssh/config: set default section name to '*' if parameter is emptyShulhan
2023-12-18ssh/config: fix negate not resetted when parsing new section MatchShulhan
2023-12-18ssh/config: add method MarshalText and WriteToShulhan
The MarshalText method encode the Section back to ssh_config format with two spaces as indentation in key. The WriteTo method marshal the Section into text and write it to [io.Writer] w.
2023-12-13all: fix linter warnings reported by reviveShulhan
There are some reports that I disagree with revive, in example, code should not declare the type after variables. In my opinion, on some cases, declaring the type make the code more readable and explicit. Since I did not want to add new configuration file, we changes it and follow revive for now.
2023-09-24shsh/config: remove field PrivateKeys and PrivateKeyFileShulhan
The goal of config package is to store the configuration key and value from ssh_config(5), everything else should be stored by user of this package, including the valid private key file and object or parsed identity file.
2023-09-14ssh/config: change the FieldInt to FieldInt64 that return int64Shulhan
Using the maximum int64 allow the section key contains value larger than int.
2023-09-11ssh/config: add missing comment to type PermittedCNAMEsShulhan
2023-08-08ssh/config: export the function to create new SectionShulhan
The NewSection function are required to test NewClientInteractive later.
2023-08-07ssh/config: handle key UserKnownHostsFileShulhan
The UserKnownHostsFile define list of the known_hosts files to be read, separated by spaces. If not set default to "~/.ssh/known_hosts" and "~/.ssh/known_hosts2".
2023-08-07ssh/config: convert value of CASignatureAlgorithms and Hostname to lowercaseShulhan
An example of CASignatureAlgorithms is ssh-ed25519, so it make senses to convert it to lowercase. The value of Hostname is either a domain or IP address so it also make senses to convert it to lowercase. The value of User is not case insensitive since we can create user name "Foo" and "foo" in the same system.
2023-07-26ssh/config: refactoring, simplify the Section fieldsShulhan
Instead of storing each Section value in separate field, store them inside a map, Field. This reduce the size of Section and simplify adding or getting the key that we are not supported but maybe usable by user in the future. This changes introduce several new methods as replacement of field: * CASignatureAlgorithms: a method that return list of signature algorithms that Section set or the default * CanonicalDomains: a method that return CanonicalDomains set in Section * CanonicalizePermittedCNames: return the permitted CNAMEs set in Section, from KeyCanonicalizePermittedCNames. * CertificateFile: return list of certificate file * Environments: return system and/or custom environment that will be passed to remote machine. The key and value is derived from "SendEnv" and "SetEnv". * FieldBool: return field value as boolean * FieldInt: return the field value as int * Hostname: return the Hostname in this Section * IdentityAgent: return the path to SSH agent socket to be used * Port: return the remote machine port * User: return the remote user name * Set: set the Field using key and value
2023-07-24ssh/config: make Config Get return Section with patternShulhan
Previously, if ssh config contains non-wildacard and wildcard pattern, and the requested hostname only return the first section that match. For example, given the following SSH config foo.local User foo *foo.local User allfoo If we request Get("foo.local"), tt will return all fields under "foo.local" only not "*foo.local". This changes fix this by returning new section that contains all fields from matched Section.
2023-07-24ssh/config: store the section nameShulhan
The section name is the string after "Host" or "Match" keyword. By storing the section name, we can tell which host or pattern the Section belong.
2023-07-24ssh/config: store the workDir and homeDir in ConfigShulhan
The idea is to make the Config know the working directory and home directory of all sections that they store.
2023-07-24ssh/config: add Field to SectionShulhan
The Field store the unpacked key and value of Section. Using the Field, we can set store unknown key while inside Section.
2023-07-23ssh/config: move setting the Section field into methodShulhan
Instead of setting them inside the Config, move them into the method set under Section so we can re-use them later. This changes also move the constants for key under Host or Match into Section file.
2023-07-23ssh/config: reorder struct fields for better alignmentShulhan
Changes, * Config: changes allocated size from 32 to 16 bytes (-8 bytes) * parser: changes allocated size from 40 to 32 bytes (-8 bytes) * Section: changes allocated size from 392 to 360 bytes (-32 bytes) The rest of changes that are not mentioned are from test files.
2022-10-20ssh/config: change the method GenerateSigners to SignersShulhan
This is to make the method compatible with ssh.PublicKeysCallback. Each parsed and unsigned IdentityFile is stored in field PrivateKeys, replacing the Signers field (which is conflict with method names).
2022-05-09all: reformat all codes using gofmt 1.19 (the Go tip)Shulhan
2022-04-06all: replace any usage of ioutil package with os or ioShulhan
Since Go 1.16, the ioutil package has been deprecated. This changes replace any usage that use functions from ioutil package with their replacement from package os or package io.
2021-11-06ssh/config: add support for section variable IdentityAgentShulhan
There are four possible value for IdentityAgent: SSH_AUTH_SOCK, <$STRING>, <PATH>, or "none". If SSH_AUTH_SOCK, the socket path is read from the environment variable SSH_AUTH_SOCK. If value start with "$", then the socket path is set based on value of that environment variable. Other string beside "none" will be considered as path to socket.
2021-07-05lib/ssh: move the config parser to subpackage "config"Shulhan
There are two reasons for moving to sub-package. First, the code for parsing the ssh_config(5) take almost 99% of the lines in the ssh package. Second, in case we want to submit the code to upstream, golang.org/x/crypto, we need the package to be independent, less external dependencies as possible.