summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2024-01-06Release share v0.52.0 (2024-01-06)v0.52.0Shulhan
=== New features * ssh/config: add method MarshalText and WriteTo * lib/ssh: implement method Output on Client * ssh/sftp: implement method MkdirAll on Client * cmd/httpdfs: implement [libhttp.Server] with [memfs.MemFS] === Breaking changes * ssh/config: refactoring the Config merge * ssh/config: add parameter Config to NewSection * lib/ssh: add parameter context to Execute method * lib/time: remove UnixMicro and UnixMilli * lib/io: removed, this package has been merged into "lib/os" * lib/parser: removed, this package has been merged into lib/strings === Bug fixes * ssh/config: fix setting the default values * ssh/config: set the Hostname if its not set on [Config.Get] * http/sseclient: fix data race on [Client.Close] * http/sseclient: fix Retry value not set to millisecond * ssh/sftp: fix Stat on empty remote file name * ssh/sftp: fix non-nil returned error on Close === Enhancements * ssh/config: merge the Section slice values on [Section.merge] * ssh/config: set the default UserKnownHostsFile in setDefaults
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-22lib/ssh: add parameter context to Execute methodShulhan
This changes require the fork of our golang.org/x/crypto.
2023-12-22go.mod: update golang.org/x/crypto to v0.17.0Shulhan
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-17http/sseclient: fix data race on [Client.Close]Shulhan
The data race happened when Close set conn to nil but the consume method still on Read. The fix is by waiting for 100ms so consume goroutine can check if closeq is triggered from Close or not.
2023-12-17http/sseclient: fix Retry value not set to millisecondShulhan
When client receive "retry:" message, the value is in millisecond, but when we store it we only convert it to [time.Duration] which default to nanosecond. While at it, update comments on field [Client.Retry] and [Client.Insecure].
2023-12-17lib/time: un-export the variable NowShulhan
The original idea of providing Now is to mock the current time in testing Scheduler. Since this variable can be overridden by other packages, it is not safe to export it, hence we un-export it here so it can be used internal only.
2023-12-17lib/time: remove UnixMicro and UnixMilliShulhan
Both of those methods has been added into standard library as [Time.UnixMicro] and [Time.UnixMilli] since Go 1.17.
2023-12-17lib/ssh: implement method Output on ClientShulhan
The Output method run the command and return its standard output and error as is. Any other error beside standard error, like connection, will be returned as error.
2023-12-17ssh/sftp: implement method MkdirAll on ClientShulhan
The MkdirAll create directory on the server, from left to right. Each directory is separated by '/', where the left part is the parent of the right part. This method is similar to [os.MkdirAll].
2023-12-17ssh/sftp: fix Stat on empty remote file nameShulhan
The implementation of SSH server for Stat is not consistent with the RFC. The RFC mentioned that An empty path name is valid, and it refers to the user's default directory (usually the user's home directory). But this only working on some command, like Mkdir, but not Stat.
2023-12-17ssh/sftp: use fixed slice length when converting in unpackFileAttrsShulhan
This is to make sure that the passed value is in the correct, expected size.
2023-12-17ssh/sftp: update comments to use references [...]Shulhan
2023-12-13ssh/sftp: fix non-nil returned error on CloseShulhan
2023-12-13lib/io: removed, this package has been merged into lib/osShulhan
While some functions are merged to lib/os, some are not used anymore like io.Reader.
2023-12-13lib/parser: removed, this package has been merged into lib/stringsShulhan
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-12-12_AUR: include httpdfs binary in packageShulhan
While at it, * cleaning up the PKGBUILD, * remove unused prepare(), and * use "make build" to build directly without running test and lint.
2023-12-12cmd/httpdfs: implement [libhttp.Server] with [memfs.MemFS]Shulhan
The httpdfs accept single directory to be served under HTTP server, with the following options, -address <IP:PORT> Run the HTTP server on specific IP address and port. Default to ` + defAddress + `. -exclude <regex> Exclude the files matched by regex from being served. Default to empty, none of files is excluded. -help Print this usage. -include <regex> Serve only list of files matched with regex. Default to include CSS, HTML, JavaScript, ICO, JPG, PNG, and SVG files only. -version Print the program version.
2023-12-09lib/memfs: add parameter withContent to [Node.JSON]Shulhan
If the parameter withContent is true, which is default in MarshalJSON, then all of the node content will be included in JSON output. This also changes the parameter withoutModTime to withModTime because working with negation make code not easy to read.
2023-12-06Release share v0.51.0 (2023-12-06)v0.51.0Shulhan
=== New features * lib/http: implement Server-Sent Events (SSE) * lib/net: add method Read * lib/crypto: add support for reading passphrase using SSH_ASKPASS * lib/memfs: add method JSON to Node === Enhancements * lib/ini: create the file if its not exist on Open * lib/net: use [time.Ticker] to loop in WaitAlive * lib/memfs: add sub file system * lib/memfs: improve the refresh method * lib/ini: append variable into section before any empty lines * lib/memfs: stop all Watcher spawn by DirWatcher * lib/memfs: remove embedding os.FileInfo and http.File * lib/memfs: refactoring, simplify DirWatcher logic * email/dkim: set ExpiredAt to MaxInt64 if value is greater than 12 digits
2023-12-06go.mod: update all dependenciesShulhan
2023-12-03http/sseclient: add test for multi lines with empty line in middleShulhan
When running the EventSource client in Firefox, we found out that when server send a multi line content with empty line in the middle, the empty line is ignored by Firefox. Just to make sure we test it here and the server send it as expected event:message\ndata:line 1\ndata:\ndata:line2\ndata:\ndata:\n\n This case is similar with case number 3 when testing raw data. So probably this is bug in our implementation of SSE in another project.
2023-11-27lib/http: add field KeepAliveInterval in SSEEndpointShulhan
The KeepAliveInterval define the interval where server will send a an empty message ":\n\n" to active connection periodically. This field is optional, default and minimum value is 5 seconds.
2023-11-26http/sseclient: add method IDInt to EventShulhan
The IDInt return the ID as int64. If the ID cannot be converted to integer it would return 0.
2023-11-26lib/http: simplify SSEConn API, remove the WriteMessageShulhan
Using the WriteEvent alone, we can skip writing "event:" line if the passed "event" parameter is empty, and write the rest of data and/or id.
2023-11-26lib/http: update comment on Client.PostJSON and ClientOptions.ServerUrlShulhan
2023-11-26lib/net: use [time.Ticker] to loop in WaitAliveShulhan
The Timeout field in net.Dialer sometimes does not have any effect. In the for-loop, we expect that each Dial at least consume 100 ms before returning an error. Turns out, on several occasion, the loop run too quickly, less than the passed timeout. This is probably because the listening address has not been active yet and we run it in the same machine, the OS (or Go?) return immediately without waiting for timeout.
2023-11-26http/sseclient: implement Client retryShulhan
This changes everything. On the server we split the SSEEndpoint to new type SSEConn, so each callback use different instance of conn. On the Client, we need to store the parsed serverUrl and the passed header so it can be reused.
2023-11-26http/sseclient: remove double check for non-empty packetShulhan
Let the parseEvent handle and check for empty packet.
2023-11-26lib/http: add method WriteRaw to SSEEndpointShulhan
The WriteRaw method write raw event message directly, without any parsing.
2023-11-26lib/http: change id type in WriteEvent/WriteMessage parameter to pointerShulhan
Server can send empty ID to signal client that the ID has been reset or set to empty value.
2023-11-26lib/http: implement Server-Sent Events (SSE)Shulhan
For server SSE, we add new type SSEEndpoint, for registering endpoint that can handle SSE. For client SSE, we add it in new sub package "sseclient". Implements: https://todo.sr.ht/~shulhan/share/1 Implements: https://todo.sr.ht/~shulhan/share/2 Signed-off-by: Shulhan <ms@kilabit.info>
2023-11-25lib/net: add method ReadShulhan
The Read method read packet from raw connection. If the conn parameter is nil it will return [net.ErrClosed]. The bufsize parameter set the size of buffer for each read operation, default to 1024 if not set or invalid (less than 0 or greater than 65535). The timeout parameter set how long to wait for data before considering it as failed. If its not set, less or equal to 0, it will wait forever. If no data received and timeout is set, it will return [ErrReadTimeout]. If there is data received and connection closed at the same time, it will return the data first without error. The subsequent Read will return empty packet with [ErrClosed]. Signed-off-by: Shulhan <ms@kilabit.info>
2023-11-22lib/memfs: add sub file systemShulhan
This implemented simplified version of merging multiple MemFS instances. The sub file system (subfs) can be added to the parent MemFS instance by calling new method "Merge". parent.Merge(other *MemfS) When Get method called, each subfs will be evaluated in order of Merge called. This deprecated the function Merge.
2023-11-22lib/http: update comment on Callback typeShulhan
2023-11-21lib/memfs: check for file not exist in scanDir and updateDirShulhan
Another error for handling fs.ErrNotExist when scanning directory which is may caused by broken symlink.
2023-11-19lib/crypto: trim the password read from SSH_ASKPASSShulhan
If user press enter on the GUI, the returned password will contains line feed, which makes the password invalid.
2023-11-18lib/crypto: add support for reading passphrase using SSH_ASKPASSShulhan
If the library failed to changes os.Stdin to raw, it will try to use a program defined in SSH_ASKPASS environment variable. The SSH_ASKPASS is controlled by environment SSH_ASKPASS_REQUIRE. - If SSH_ASKPASS_REQUIRE is empty the passphrase will read from terminal first, if not possible then using SSH_ASKPASS program. - If SSH_ASKPASS_REQUIRE is set to "never" the passphrase will read from terminal only. - If SSH_ASKPASS_REQUIRE is set to "prefer", the passphrase will read using SSH_ASKPASS program not from terminal, but require DISPLAY environment to be set. - If SSH_ASKPASS_REQUIRE is set to "force", the passphrase will read using SSH_ASKPASS program not from terminal, without checking DISPLAY environment. This changes affect the [ssh.NewClientInteractive] indirectly.
2023-11-17go.mod: update all dependenciesShulhan