From ca07e0490fd124083ea027e3897c4fd1c5f06029 Mon Sep 17 00:00:00 2001 From: Patrick Uiterwijk Date: Wed, 8 Aug 2018 19:15:39 +0200 Subject: [PATCH] Rename repoClient to repoBridge Signed-off-by: Patrick Uiterwijk --- .gitignore | 2 +- README.md | 2 +- SECURITY.md | 2 +- {client => bridge}/bridge.go | 14 ++++---- {client => bridge}/h2.go | 6 ++-- {client => bridge}/nonh2.go | 6 ++-- {client => bridge}/root.go | 10 +++--- ...json.example => bridge_config.json.example | 0 build.sh | 4 +-- cmd/{repoclient => repobridge}/main.go | 12 +++---- functional_tests/base.go | 36 +++++++------------ server/service/http-git-discovery.go | 4 +-- server/service/http.go | 6 ++-- 13 files changed, 46 insertions(+), 58 deletions(-) rename {client => bridge}/bridge.go (84%) rename {client => bridge}/h2.go (76%) rename {client => bridge}/nonh2.go (65%) rename {client => bridge}/root.go (96%) rename client_config.json.example => bridge_config.json.example (100%) rename cmd/{repoclient => repobridge}/main.go (50%) diff --git a/.gitignore b/.gitignore index 3b93155..2ff6042 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # Binaries for programs and plugins /repospanner -/repoclient +/repobridge /repohookrunner *.exe *.dll diff --git a/README.md b/README.md index 2456fad..acebb14 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ http.sslkey=/etc/pki/repospanner/someuser.key https://nodea.regiona.repospanner.local/repo/test.git". Alternatively, for ssh based pushing and pulling, make sure that the users' -entry console is the `repoclient` binary, and the client_config.yml file is setup +entry console is the `repobridge` binary, and the client_config.yml file is setup in /etc/repospanner. This client will automatically revert to plain git if it determines the repo that is being pushed to is not a repospanner repository. diff --git a/SECURITY.md b/SECURITY.md index dc1d59e..575cbb4 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -13,7 +13,7 @@ The RPC endpoint is used for communication between different nodes and within a It has very low-level calls that could bring the system in an inconsistent state by performing invalid requests. It can be firewalled so that only the other nodes and each node itself can communicate to it. -The user endpoint is used for requests by user clients (be that Git, repoclient, or any other client). +The user endpoint is used for requests by user clients (be that Git, repobridge, or any other client). TLS client certificates are optional, although unauthenticated requests are only able to clone public repositories and get the high-level version information of the system. This endpoint should be available from clients who need access to the repositories on this system. diff --git a/client/bridge.go b/bridge/bridge.go similarity index 84% rename from client/bridge.go rename to bridge/bridge.go index d63c0bd..e7f6156 100644 --- a/client/bridge.go +++ b/bridge/bridge.go @@ -1,4 +1,4 @@ -package client +package bridge import ( "crypto/tls" @@ -20,26 +20,26 @@ func getClient() *http.Client { cert, key := getCertAndKey() - clientcert, err := tls.LoadX509KeyPair( + bridgecert, err := tls.LoadX509KeyPair( cert, key, ) - checkError(err, "Error initializing client") + checkError(err, "Error initializing bridge") var certpool *x509.CertPool capath := configuration.Ca if capath != "" { cts, err := ioutil.ReadFile(capath) - checkError(err, "Error initializing client ca") + checkError(err, "Error initializing bridge ca") certpool = x509.NewCertPool() if ok := certpool.AppendCertsFromPEM(cts); !ok { - exitWithError("Error initializing client ca") + exitWithError("Error initializing bridge ca") } } transport := &http.Transport{ TLSClientConfig: &tls.Config{ - Certificates: []tls.Certificate{clientcert}, + Certificates: []tls.Certificate{bridgecert}, NextProtos: []string{"h2"}, PreferServerCipherSuites: true, MinVersion: tls.VersionTLS12, @@ -60,7 +60,7 @@ func getURL(service, reponame string) string { } func bridge(r *http.Request) { - r.Header["X-RepoClient-Version"] = []string{constants.VersionString()} + r.Header["X-RepoBridge-Version"] = []string{constants.VersionString()} resp, err := getClient().Do(r) checkError( diff --git a/client/h2.go b/bridge/h2.go similarity index 76% rename from client/h2.go rename to bridge/h2.go index c0ba02d..9c9918c 100644 --- a/client/h2.go +++ b/bridge/h2.go @@ -1,6 +1,6 @@ // +build !nonh2 -package client +package bridge import ( "net/http" @@ -8,7 +8,7 @@ import ( "golang.org/x/net/http2" ) -// HasH2 returns whether this client was compiled with h2 support +// HasH2 returns whether this bridge was compiled with h2 support func HasH2() bool { return true } @@ -16,4 +16,4 @@ func HasH2() bool { func maybeConfigureH2(transport *http.Transport) { err := http2.ConfigureTransport(transport) checkError(err, "Error initializing HTTP/2 transport") -} \ No newline at end of file +} diff --git a/client/nonh2.go b/bridge/nonh2.go similarity index 65% rename from client/nonh2.go rename to bridge/nonh2.go index b25cb8b..8ed5846 100644 --- a/client/nonh2.go +++ b/bridge/nonh2.go @@ -1,16 +1,16 @@ // +build nonh2 -package client +package bridge import ( "net/http" ) -// HasH2 returns whether this client was compiled with h2 support +// HasH2 returns whether this bridge was compiled with h2 support func HasH2() bool { return false } func maybeConfigureH2(transport *http.Transport) { // Not configuring h2 -} \ No newline at end of file +} diff --git a/client/root.go b/bridge/root.go similarity index 96% rename from client/root.go rename to bridge/root.go index 14e1d4a..5ccbed0 100644 --- a/client/root.go +++ b/bridge/root.go @@ -1,4 +1,4 @@ -package client +package bridge import ( "bytes" @@ -112,9 +112,9 @@ func isRawGitRepo(path string) (rawgit bool, gsname string, err error) { } func loadConfig() { - cfgFile := os.Getenv("REPOCLIENT_CONFIG") + cfgFile := os.Getenv("REPOBRIDGE_CONFIG") if cfgFile=="" { - cfgFile = "/etc/repospanner/client_config.json" + cfgFile = "/etc/repospanner/bridge_config.json" } cts, err := ioutil.ReadFile(cfgFile) checkError(err, "Error reading configuration") @@ -122,7 +122,7 @@ func loadConfig() { checkError(err, "Error parsing configuration") } -func ExecuteClient() { +func ExecuteBridge() { username = os.Getenv("USER") if username == "" { exitWithError("Unable to determine username") @@ -218,6 +218,6 @@ func getCertAndKey() (string, string) { } // Seems there was no configuration for this user, nor default... Abandon all hope - exitWithError("User does not have access to this client") + exitWithError("User does not have access to this bridge") return "", "" } diff --git a/client_config.json.example b/bridge_config.json.example similarity index 100% rename from client_config.json.example rename to bridge_config.json.example diff --git a/build.sh b/build.sh index 0049e97..5a4afb1 100755 --- a/build.sh +++ b/build.sh @@ -15,11 +15,11 @@ export GITDESCRIP="`git describe --long --tags --dirty --always`" -o ../../repospanner ) ( - cd cmd/repoclient/ + cd cmd/repobridge/ go build -ldflags \ "-X repospanner.org/repospanner/server/constants.version=$VERSION -X repospanner.org/repospanner/server/constants.gitdescrip=$GITDESCRIP" \ - -o ../../repoclient + -o ../../repobridge ) ( cd cmd/repohookrunner/ diff --git a/cmd/repoclient/main.go b/cmd/repobridge/main.go similarity index 50% rename from cmd/repoclient/main.go rename to cmd/repobridge/main.go index 45f13b8..72834b6 100644 --- a/cmd/repoclient/main.go +++ b/cmd/repobridge/main.go @@ -5,7 +5,7 @@ import ( "log" "os" - "repospanner.org/repospanner/client" + "repospanner.org/repospanner/bridge" "repospanner.org/repospanner/server/constants" ) @@ -15,14 +15,14 @@ func main() { os.Exit(1) } if len(os.Args) == 1 { - fmt.Println("repoSpanner client " + constants.PublicVersionString()) - if client.HasH2() { - fmt.Println("This client is HTTP/2 enabled") + fmt.Println("repoSpanner bridge " + constants.PublicVersionString()) + if bridge.HasH2() { + fmt.Println("This bridge is HTTP/2 enabled") } else { - fmt.Println("This client is deprived of HTTP/2 goodness") + fmt.Println("This bridge is deprived of HTTP/2 goodness") } os.Exit(0) } - client.ExecuteClient() + bridge.ExecuteBridge() } diff --git a/functional_tests/base.go b/functional_tests/base.go index 663345a..b758a59 100644 --- a/functional_tests/base.go +++ b/functional_tests/base.go @@ -20,7 +20,7 @@ import ( var ( binary string - clientbinary string + bridgebinary string hookrunnerbinary string ) @@ -33,22 +33,22 @@ func checkFileExist(t *testing.T, path string) { } func setBinaryPaths(t *testing.T) { - if binary != "" && clientbinary != "" { + if binary != "" && bridgebinary != "" { return } codedir, err := os.Getwd() failIfErr(t, err, "determining binary paths") codedir = filepath.Join(codedir, "..") possiblebinary := filepath.Join(codedir, "repospanner") - possibleclientbinary := filepath.Join(codedir, "repoclient") + possiblebridgebinary := filepath.Join(codedir, "repobridge") possiblehookrunnerbinary := filepath.Join(codedir, "repohookrunner") checkFileExist(t, possiblebinary) - checkFileExist(t, possibleclientbinary) + checkFileExist(t, possiblebridgebinary) checkFileExist(t, possiblehookrunnerbinary) binary = possiblebinary - clientbinary = possibleclientbinary + bridgebinary = possiblebridgebinary hookrunnerbinary = possiblehookrunnerbinary atleast110, sure := service.IsAtLeastGo110(runtime.Version()) @@ -146,7 +146,7 @@ func _runRawCommand(t *testing.T, binname, pwd string, envupdates []string, args envupdates = append( envupdates, "USER=admin", - "REPOCLIENT_CONFIG="+pwd+".json", + "REPOBRIDGE_CONFIG="+pwd+".json", ) cmd := exec.Command( binname, @@ -199,14 +199,8 @@ func runForTestedCloneMethods(t *testing.T, m func(*testing.T, cloneMethod)) { } } -func createSSHClientConfig(t *testing.T, node nodeNrType, confpath string) { - err := os.Mkdir(path.Join(testDir, "clientlogs"), 0755) - if os.IsExist(err) { - err = nil - } - failIfErr(t, err, "creating client logs folder") - - examplecfgB, err := ioutil.ReadFile("../client_config.json.example") +func createSSHBridgeConfig(t *testing.T, node nodeNrType, confpath string) { + examplecfgB, err := ioutil.ReadFile("../bridge_config.json.example") failIfErr(t, err, "reading example config") examplecfg := string(examplecfgB) @@ -217,12 +211,6 @@ func createSSHClientConfig(t *testing.T, node nodeNrType, confpath string) { path.Join(testDir, "ca"), -1, ) - examplecfg = strings.Replace( - examplecfg, - "/var/log/repospanner_client/", - path.Join(testDir, "clientlogs"), - -1, - ) examplecfg = strings.Replace( examplecfg, "debug: false", @@ -245,15 +233,15 @@ func createSSHClientConfig(t *testing.T, node nodeNrType, confpath string) { // Write generated config file examplecfgB = []byte(examplecfg) err = ioutil.WriteFile(confpath, examplecfgB, 0644) - failIfErr(t, err, "writing client config file") + failIfErr(t, err, "writing bridge config file") - t.Log("Client config for", node, confpath, examplecfg) + t.Log("Bridge config for", node, confpath, examplecfg) } func cloneCmdSSH(t *testing.T, node nodeNrType, reponame, username string) (cmd []string, envupdates []string) { cmd = []string{ "clone", - "ext::" + clientbinary + " " + reponame, + "ext::" + bridgebinary + " " + reponame, } return @@ -295,7 +283,7 @@ func clone(t *testing.T, method cloneMethod, node nodeNrType, reponame, username ourdir, err := ioutil.TempDir(cloneDir, fmt.Sprintf("clone_%s_%s_", reponame, username)) failIfErr(t, err, "creating clone directory") - createSSHClientConfig(t, node, ourdir+".json") + createSSHBridgeConfig(t, node, ourdir+".json") var cmd []string var envupdates []string diff --git a/server/service/http-git-discovery.go b/server/service/http-git-discovery.go index 0dc8e45..433e3bf 100644 --- a/server/service/http-git-discovery.go +++ b/server/service/http-git-discovery.go @@ -18,7 +18,7 @@ func (cfg *Service) serveGitDiscovery(w http.ResponseWriter, r *http.Request, pe http.NotFound(w, r) return } - isrepoclient := len(r.Header[http.CanonicalHeaderKey("X-RepoClient-Version")]) == 1 + isrepobridge := len(r.Header[http.CanonicalHeaderKey("X-RepoBridge-Version")]) == 1 service := services[0] w.Header()["Content-Type"] = []string{"application/x-" + service + "-advertisement"} reqlogger = reqlogger.WithField("service", service) @@ -35,7 +35,7 @@ func (cfg *Service) serveGitDiscovery(w http.ResponseWriter, r *http.Request, pe w.WriteHeader(200) - if !isrepoclient { + if !isrepobridge { if err := sendPacket(w, []byte("# service="+service+"\n")); err != nil { http.NotFound(w, r) return diff --git a/server/service/http.go b/server/service/http.go index 0c8ac9f..94b9b4d 100644 --- a/server/service/http.go +++ b/server/service/http.go @@ -67,10 +67,10 @@ func findProjectAndOp(parts []string) (string, string) { func (cfg *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) { reqlogger, perminfo := cfg.prereq(w, r, "gitservice") - repoclient := r.Header[http.CanonicalHeaderKey("X-RepoClient-Version")] - if len(repoclient) != 0 { + repobridge := r.Header[http.CanonicalHeaderKey("X-RepoBridge-Version")] + if len(repobridge) != 0 { reqlogger = reqlogger.WithField( - "RepoClient-Version", repoclient, + "RepoBridge-Version", repobridge, ) }