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:
pprof listening address, e.g. 'localhost:6060'
-proxyHeadersTimeout duration
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")
-version
Print version and exit
......
......@@ -32,7 +32,7 @@ func runPreAuthorizeHandler(t *testing.T, ts *httptest.Server, suffix string, ur
t.Fatal(err)
}
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()
a.PreAuthorizeHandler(okHandler, suffix).ServeHTTP(response, httpRequest)
......@@ -86,7 +86,7 @@ func TestPreAuthorizeJWT(t *testing.T) {
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
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 {
return nil, fmt.Errorf("read secret from file: %v", err)
}
......
......@@ -27,12 +27,12 @@ type API struct {
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{
Client: &http.Client{Transport: roundTripper},
URL: myURL,
Version: version,
Secret: &Secret{File: secretFile},
Secret: &Secret{Path: secretPath},
}
}
......
......@@ -10,7 +10,7 @@ import (
const numSecretBytes = 32
type Secret struct {
File string
Path string
bytes []byte
sync.RWMutex
}
......@@ -33,9 +33,9 @@ func (s *Secret) getBytes() []byte {
}
func (s *Secret) setBytes() ([]byte, error) {
base64Bytes, err := ioutil.ReadFile(s.File)
base64Bytes, err := ioutil.ReadFile(s.Path)
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)))
......@@ -45,7 +45,7 @@ func (s *Secret) setBytes() ([]byte, error) {
}
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()
......
......@@ -93,7 +93,7 @@ func testUploadArtifacts(contentType string, body io.Reader, t *testing.T, ts *h
response := httptest.NewRecorder()
parsedURL := helper.URLMustParse(ts.URL)
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)
UploadArtifacts(apiClient, proxyClient).ServeHTTP(response, httpRequest)
return response
......
......@@ -15,7 +15,7 @@ import (
"testing"
)
func SecretFile() string {
func SecretPath() string {
return path.Join(RootDir(), "testdata/test-secret")
}
......
......@@ -37,7 +37,7 @@ func (u *Upstream) configureRoutes() {
api := apipkg.NewAPI(
u.Backend,
u.Version,
u.SecretFile,
u.SecretPath,
u.RoundTripper,
)
static := &staticpages.Static{u.DocumentRoot}
......
......@@ -23,7 +23,7 @@ var DefaultBackend = helper.URLMustParse("http://localhost:8080")
type Upstream struct {
Backend *url.URL
Version string
SecretFile string
SecretPath string
DocumentRoot string
DevelopmentMode bool
......@@ -36,7 +36,7 @@ func NewUpstream(backend *url.URL, socket, version, secretFile, documentRoot str
up := Upstream{
Backend: backend,
Version: version,
SecretFile: secretFile,
SecretPath: secretFile,
DocumentRoot: documentRoot,
DevelopmentMode: developmentMode,
}
......
......@@ -40,7 +40,7 @@ var pprofListenAddr = flag.String("pprofListenAddr", "", "pprof listening addres
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 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() {
flag.Usage = func() {
......@@ -87,7 +87,7 @@ func main() {
*authBackend,
*authSocket,
Version,
*secretFile,
*secretPath,
*documentRoot,
*developmentMode,
*proxyHeadersTimeout,
......
......@@ -868,7 +868,7 @@ func startWorkhorseServer(authBackend string) *httptest.Server {
helper.URLMustParse(authBackend),
"",
"123",
testhelper.SecretFile(),
testhelper.SecretPath(),
testDocumentRoot,
false,
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