Commit 0f28c9bf authored by Jacob Vosmaer's avatar Jacob Vosmaer

Rename api.Secret.File to api.Secret.Path

parent 1dc2ab91
...@@ -31,7 +31,7 @@ Options: ...@@ -31,7 +31,7 @@ Options:
pprof listening address, e.g. 'localhost:6060' pprof listening address, e.g. 'localhost:6060'
-proxyHeadersTimeout duration -proxyHeadersTimeout duration
How long to wait for response headers when proxying the request (default 5m0s) How long to wait for response headers when proxying the request (default 5m0s)
-secretFile string -secretPath string
File with secret key to authenticate with authBackend (default "./.gitlab_workhorse_secret") File with secret key to authenticate with authBackend (default "./.gitlab_workhorse_secret")
-version -version
Print version and exit Print version and exit
......
...@@ -32,7 +32,7 @@ func runPreAuthorizeHandler(t *testing.T, ts *httptest.Server, suffix string, ur ...@@ -32,7 +32,7 @@ func runPreAuthorizeHandler(t *testing.T, ts *httptest.Server, suffix string, ur
t.Fatal(err) t.Fatal(err)
} }
parsedURL := helper.URLMustParse(ts.URL) parsedURL := helper.URLMustParse(ts.URL)
a := api.NewAPI(parsedURL, "123", testhelper.SecretFile(), badgateway.TestRoundTripper(parsedURL)) a := api.NewAPI(parsedURL, "123", testhelper.SecretPath(), badgateway.TestRoundTripper(parsedURL))
response := httptest.NewRecorder() response := httptest.NewRecorder()
a.PreAuthorizeHandler(okHandler, suffix).ServeHTTP(response, httpRequest) a.PreAuthorizeHandler(okHandler, suffix).ServeHTTP(response, httpRequest)
...@@ -86,7 +86,7 @@ func TestPreAuthorizeJWT(t *testing.T) { ...@@ -86,7 +86,7 @@ func TestPreAuthorizeJWT(t *testing.T) {
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok { if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"]) return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"])
} }
secretBytes, err := (&api.Secret{File: testhelper.SecretFile()}).Bytes() secretBytes, err := (&api.Secret{Path: testhelper.SecretPath()}).Bytes()
if err != nil { if err != nil {
return nil, fmt.Errorf("read secret from file: %v", err) return nil, fmt.Errorf("read secret from file: %v", err)
} }
......
...@@ -27,12 +27,12 @@ type API struct { ...@@ -27,12 +27,12 @@ type API struct {
Secret *Secret Secret *Secret
} }
func NewAPI(myURL *url.URL, version, secretFile string, roundTripper *badgateway.RoundTripper) *API { func NewAPI(myURL *url.URL, version, secretPath string, roundTripper *badgateway.RoundTripper) *API {
return &API{ return &API{
Client: &http.Client{Transport: roundTripper}, Client: &http.Client{Transport: roundTripper},
URL: myURL, URL: myURL,
Version: version, Version: version,
Secret: &Secret{File: secretFile}, Secret: &Secret{Path: secretPath},
} }
} }
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
const numSecretBytes = 32 const numSecretBytes = 32
type Secret struct { type Secret struct {
File string Path string
bytes []byte bytes []byte
sync.RWMutex sync.RWMutex
} }
...@@ -33,9 +33,9 @@ func (s *Secret) getBytes() []byte { ...@@ -33,9 +33,9 @@ func (s *Secret) getBytes() []byte {
} }
func (s *Secret) setBytes() ([]byte, error) { func (s *Secret) setBytes() ([]byte, error) {
base64Bytes, err := ioutil.ReadFile(s.File) base64Bytes, err := ioutil.ReadFile(s.Path)
if err != nil { if err != nil {
return nil, fmt.Errorf("read Secret.File: %v", err) return nil, fmt.Errorf("read Secret.Path: %v", err)
} }
secretBytes := make([]byte, base64.StdEncoding.DecodedLen(len(base64Bytes))) secretBytes := make([]byte, base64.StdEncoding.DecodedLen(len(base64Bytes)))
...@@ -45,7 +45,7 @@ func (s *Secret) setBytes() ([]byte, error) { ...@@ -45,7 +45,7 @@ func (s *Secret) setBytes() ([]byte, error) {
} }
if n != numSecretBytes { if n != numSecretBytes {
return nil, fmt.Errorf("expected %d secretBytes in %s, found %d", numSecretBytes, s.File, n) return nil, fmt.Errorf("expected %d secretBytes in %s, found %d", numSecretBytes, s.Path, n)
} }
s.Lock() s.Lock()
......
...@@ -93,7 +93,7 @@ func testUploadArtifacts(contentType string, body io.Reader, t *testing.T, ts *h ...@@ -93,7 +93,7 @@ func testUploadArtifacts(contentType string, body io.Reader, t *testing.T, ts *h
response := httptest.NewRecorder() response := httptest.NewRecorder()
parsedURL := helper.URLMustParse(ts.URL) parsedURL := helper.URLMustParse(ts.URL)
roundTripper := badgateway.TestRoundTripper(parsedURL) roundTripper := badgateway.TestRoundTripper(parsedURL)
apiClient := api.NewAPI(parsedURL, "123", testhelper.SecretFile(), roundTripper) apiClient := api.NewAPI(parsedURL, "123", testhelper.SecretPath(), roundTripper)
proxyClient := proxy.NewProxy(parsedURL, "123", roundTripper) proxyClient := proxy.NewProxy(parsedURL, "123", roundTripper)
UploadArtifacts(apiClient, proxyClient).ServeHTTP(response, httpRequest) UploadArtifacts(apiClient, proxyClient).ServeHTTP(response, httpRequest)
return response return response
......
...@@ -15,7 +15,7 @@ import ( ...@@ -15,7 +15,7 @@ import (
"testing" "testing"
) )
func SecretFile() string { func SecretPath() string {
return path.Join(RootDir(), "testdata/test-secret") return path.Join(RootDir(), "testdata/test-secret")
} }
......
...@@ -37,7 +37,7 @@ func (u *Upstream) configureRoutes() { ...@@ -37,7 +37,7 @@ func (u *Upstream) configureRoutes() {
api := apipkg.NewAPI( api := apipkg.NewAPI(
u.Backend, u.Backend,
u.Version, u.Version,
u.SecretFile, u.SecretPath,
u.RoundTripper, u.RoundTripper,
) )
static := &staticpages.Static{u.DocumentRoot} static := &staticpages.Static{u.DocumentRoot}
......
...@@ -23,7 +23,7 @@ var DefaultBackend = helper.URLMustParse("http://localhost:8080") ...@@ -23,7 +23,7 @@ var DefaultBackend = helper.URLMustParse("http://localhost:8080")
type Upstream struct { type Upstream struct {
Backend *url.URL Backend *url.URL
Version string Version string
SecretFile string SecretPath string
DocumentRoot string DocumentRoot string
DevelopmentMode bool DevelopmentMode bool
...@@ -36,7 +36,7 @@ func NewUpstream(backend *url.URL, socket, version, secretFile, documentRoot str ...@@ -36,7 +36,7 @@ func NewUpstream(backend *url.URL, socket, version, secretFile, documentRoot str
up := Upstream{ up := Upstream{
Backend: backend, Backend: backend,
Version: version, Version: version,
SecretFile: secretFile, SecretPath: secretFile,
DocumentRoot: documentRoot, DocumentRoot: documentRoot,
DevelopmentMode: developmentMode, DevelopmentMode: developmentMode,
} }
......
...@@ -40,7 +40,7 @@ var pprofListenAddr = flag.String("pprofListenAddr", "", "pprof listening addres ...@@ -40,7 +40,7 @@ var pprofListenAddr = flag.String("pprofListenAddr", "", "pprof listening addres
var documentRoot = flag.String("documentRoot", "public", "Path to static files content") var documentRoot = flag.String("documentRoot", "public", "Path to static files content")
var proxyHeadersTimeout = flag.Duration("proxyHeadersTimeout", 5*time.Minute, "How long to wait for response headers when proxying the request") var proxyHeadersTimeout = flag.Duration("proxyHeadersTimeout", 5*time.Minute, "How long to wait for response headers when proxying the request")
var developmentMode = flag.Bool("developmentMode", false, "Allow to serve assets from Rails app") var developmentMode = flag.Bool("developmentMode", false, "Allow to serve assets from Rails app")
var secretFile = flag.String("secretFile", "./.gitlab_workhorse_secret", "File with secret key to authenticate with authBackend") var secretPath = flag.String("secretPath", "./.gitlab_workhorse_secret", "File with secret key to authenticate with authBackend")
func main() { func main() {
flag.Usage = func() { flag.Usage = func() {
...@@ -87,7 +87,7 @@ func main() { ...@@ -87,7 +87,7 @@ func main() {
*authBackend, *authBackend,
*authSocket, *authSocket,
Version, Version,
*secretFile, *secretPath,
*documentRoot, *documentRoot,
*developmentMode, *developmentMode,
*proxyHeadersTimeout, *proxyHeadersTimeout,
......
...@@ -868,7 +868,7 @@ func startWorkhorseServer(authBackend string) *httptest.Server { ...@@ -868,7 +868,7 @@ func startWorkhorseServer(authBackend string) *httptest.Server {
helper.URLMustParse(authBackend), helper.URLMustParse(authBackend),
"", "",
"123", "123",
testhelper.SecretFile(), testhelper.SecretPath(),
testDocumentRoot, testDocumentRoot,
false, false,
0, 0,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment