Allow namespaced repositories and functional options
@sosedoff are you accepting pull requests?
I've been working on some new features for a side project. One thing I needed was the ability to namespace repositories along the lines of github (e.g., repositories named like sosedoff/gitkit.git)
In the process, I changed the way configuration options are passed so that it starts out with sensible defaults and allows you to pass functional options as outlined in this post: http://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis
It allows you to start both a smart HTTP server and an SSH server at the same time with a default config that you can then modify using a format like the following:
func main() {
tls := gitkit.UseTLS("/path/to/key", "/path/to/cert")
auth := gitkit.UseAuthFunc(myAuthFunc)
nossh := gitkit.UseSSH(false)
httpPort := gitkit.HTTPPort(8000)
server := gitkit.New(tls, auth, nossh, httpPort)
server.Run()
}
That would disable the SSH server, use TLS using the provided certs, and change the HTTP port to 8000.
Summary:
- TLS-secured HTTP server
- Separate SSH authorization function that enables checking whether the user has access to a specific repository before any action (in addition to the SSH auth check for the connection)
- Run both the SSH and HTTP servers at the same time
- Smart defaults so you can just do
server := gitkit.New()and thenserver.Run()without configuring anything to get up and running quickly. - Examples directory that shows how to do common configurations
- Add hook scripts from files in addition to specifying them as []byte strings
- Prevent auto-create when trying to clone a repository that doesn't exist (only creates on initial push)
I still need to do some work on the tests and documentation, but I should be able to get you a pull-request shortly if you are interested. You can check it out at: https://github.com/BTBurke/gitkit
The main changes are in config.go for the functional options and in server.go for the concurrent server implementation.
Hi @BTBurke, thanks for all the contributions, i will check out your repo. While i accept pull requests for this project i still need to add and modify a few things in current implementation, i just didn't have time to do that.
Also, could you submit the PR from your repo's master branch? I'll help me track your changes.
Sure, let me know how it looks. I plan to implement a few more things I need for my project and add additional tests.
One thing I'm going to work on this weekend is a module to read configuration from the command line so that it's easier to configure certain things when running it in a container.
Something like:
$ git-server --http-port=8000 --enable-ssh=false --tls-key=./key --tls-cert=./cert
How would you mount the new git server implementation onto any existing http handler function?