Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

passthrough #40

Merged
merged 4 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gateway/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Tenant struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
ID string `yaml:"id"`
Passthrough bool `yaml:"passthrough"`
}

func Init(filePath string) (Config, error) {
Expand Down
31 changes: 31 additions & 0 deletions gateway/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func TestStartGateway(t *testing.T) {
testCases := []struct {
name string
authHeader string
orgID string
config *Config
paths []string
expectedStatus int
Expand Down Expand Up @@ -220,6 +221,31 @@ func TestStartGateway(t *testing.T) {
authHeader: "Basic " + base64.StdEncoding.EncodeToString([]byte("username:password")),
expectedStatus: http.StatusOK,
},
{
name: "passthrough config",
config: &Config{
Tenants: []Tenant{
{
Authentication: "basic",
Username: "username",
Password: "password",
Passthrough: true,
},
},
Distributor: Upstream{
URL: distributorServer.URL,
Paths: []string{
"/test/distributor",
},
},
},
paths: []string{
"/test/distributor",
},
authHeader: "Basic " + base64.StdEncoding.EncodeToString([]byte("username:password")),
orgID: "orgID",
expectedStatus: http.StatusOK,
},
{
name: "not found route",
config: &Config{
Expand Down Expand Up @@ -348,6 +374,11 @@ func TestStartGateway(t *testing.T) {
for _, path := range tc.paths {
req, _ := http.NewRequest("GET", mockServer.URL+path, nil)
req.Header.Set("Authorization", tc.authHeader)

if tc.orgID != "" {
req.Header.Set("X-Scope-OrgID", tc.orgID)
}

resp, err := client.Do(req)
if err != nil {
t.Fatal(err)
Expand Down
4 changes: 3 additions & 1 deletion gateway/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ func (tenant *Tenant) basicAuth(w http.ResponseWriter, r *http.Request) bool {
return false
}

r.Header.Set("X-Scope-OrgID", tenant.ID)
if !tenant.Passthrough {
r.Header.Set("X-Scope-OrgID", tenant.ID)
}
return true
}

Expand Down
Loading