Skip to content

Commit

Permalink
Fixed ingress route redirect problem. Fixes spacecloud-io#1394
Browse files Browse the repository at this point in the history
  • Loading branch information
YourTechBud committed Nov 9, 2020
1 parent b80d39e commit d165ddc
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions gateway/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM golang:1.13.5-alpine3.10
WORKDIR /build

# Take the current space cloud version as a argument
ARG SC_VERSION=0.19.6
ARG SC_VERSION=0.19.7

# Copy all the source files
COPY . .
Expand All @@ -16,7 +16,7 @@ RUN GOOS=linux CGO_ENABLED=0 go build -a -ldflags '-s -w -extldflags "-static"'
RUN echo $SC_VERSION && wget https://storage.googleapis.com/space-cloud/mission-control/mission-control-v$SC_VERSION.zip && unzip mission-control-v$SC_VERSION.zip

FROM alpine:3.10
ARG SC_VERSION=0.19.6
ARG SC_VERSION=0.19.7

RUN apk --no-cache add ca-certificates

Expand Down
14 changes: 10 additions & 4 deletions gateway/modules/global/routing/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ type modulesInterface interface {
Auth() *auth.Module
}

var httpClient = http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}

// HandleRoutes handles incoming http requests and routes them according to the configured rules.
func (r *Routing) HandleRoutes(modules modulesInterface) http.HandlerFunc {
return func(writer http.ResponseWriter, request *http.Request) {
Expand All @@ -36,7 +42,7 @@ func (r *Routing) HandleRoutes(modules modulesInterface) http.HandlerFunc {
return
}

token, auth, status, err := r.modifyRequest(request.Context(), modules, route, request)
token, claims, status, err := r.modifyRequest(request.Context(), modules, route, request)
if err != nil {
writer.WriteHeader(status)
_ = json.NewEncoder(writer).Encode(map[string]string{"error": err.Error()})
Expand All @@ -59,7 +65,7 @@ func (r *Routing) HandleRoutes(modules modulesInterface) http.HandlerFunc {
}

// TODO: Use http2 client if that was the incoming request protocol
response, err := http.DefaultClient.Do(request)
response, err := httpClient.Do(request)
if err != nil {
writer.WriteHeader(http.StatusInternalServerError)
_ = json.NewEncoder(writer).Encode(map[string]string{"error": err.Error()})
Expand All @@ -68,7 +74,7 @@ func (r *Routing) HandleRoutes(modules modulesInterface) http.HandlerFunc {
}
defer utils.CloseTheCloser(response.Body)

if err := r.modifyResponse(request.Context(), response, route, token, auth); err != nil {
if err := r.modifyResponse(request.Context(), response, route, token, claims); err != nil {
writer.WriteHeader(http.StatusInternalServerError)
_ = json.NewEncoder(writer).Encode(map[string]string{"error": err.Error()})
return
Expand Down Expand Up @@ -128,7 +134,7 @@ func setRequest(ctx context.Context, request *http.Request, route *config.Route,
return nil
}

func prepareHeaders(ctx context.Context, headers config.Headers, state map[string]interface{}) config.Headers {
func prepareHeaders(headers config.Headers, state map[string]interface{}) config.Headers {
out := make([]config.Header, len(headers))
for i, header := range headers {
// First create a new header object
Expand Down
4 changes: 2 additions & 2 deletions gateway/modules/global/routing/modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (r *Routing) modifyRequest(ctx context.Context, modules modulesInterface, r
// Set the headers
state := map[string]interface{}{"args": params, "auth": auth}
headers := append(r.globalConfig.RequestHeaders, route.Modify.RequestHeaders...)
prepareHeaders(ctx, headers, state).UpdateHeader(req.Header)
prepareHeaders(headers, state).UpdateHeader(req.Header)

// Don't forget to reset the body
if params != nil {
Expand Down Expand Up @@ -87,7 +87,7 @@ func (r *Routing) modifyResponse(ctx context.Context, res *http.Response, route
// Set the headers
state := map[string]interface{}{"args": params, "auth": auth}
headers := append(r.globalConfig.ResponseHeaders, route.Modify.ResponseHeaders...)
prepareHeaders(ctx, headers, state).UpdateHeader(res.Header)
prepareHeaders(headers, state).UpdateHeader(res.Header)

// If params is not nil we need to template the response
if params != nil {
Expand Down
2 changes: 1 addition & 1 deletion gateway/utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

// BuildVersion is the current version of Space Cloud
const BuildVersion = "0.19.6"
const BuildVersion = "0.19.7"

// DLQEventTriggerPrefix used as suffix for DLQ event trigger
const DLQEventTriggerPrefix = "dlq_"
Expand Down
4 changes: 2 additions & 2 deletions install-manifests/kubernetes/local/space-cloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ spec:
containers:
- name: runner
command: ["./app", "start"]
image: spaceuptech/runner:0.19.6
image: spaceuptech/runner:0.19.7
imagePullPolicy: IfNotPresent # IfNotPresent | Always
env:
- name: "LOG_LEVEL"
Expand Down Expand Up @@ -368,7 +368,7 @@ spec:
containers:
- name: gateway
command: ["./app", "run"]
image: spaceuptech/gateway:0.19.6
image: spaceuptech/gateway:0.19.7
imagePullPolicy: IfNotPresent # IfNotPresent | Always
env:
- name: "NODE_ID"
Expand Down
4 changes: 2 additions & 2 deletions install-manifests/kubernetes/prod/space-cloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ spec:
containers:
- name: runner
command: ["./app", "start"]
image: spaceuptech/runner:0.19.6
image: spaceuptech/runner:0.19.7
imagePullPolicy: IfNotPresent # IfNotPresent | Always
env:
- name: "LOG_LEVEL"
Expand Down Expand Up @@ -372,7 +372,7 @@ spec:
containers:
- name: gateway
command: ["./app", "run"]
image: spaceuptech/gateway:0.19.6
image: spaceuptech/gateway:0.19.7
imagePullPolicy: IfNotPresent # IfNotPresent | Always
env:
- name: "NODE_ID"
Expand Down
2 changes: 1 addition & 1 deletion runner/model/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package model

// Version represents the current runner version
const Version string = "v0.19.6"
const Version string = "v0.19.7"
2 changes: 1 addition & 1 deletion space-cli/cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package cmd

const version string = "0.19.6"
const version string = "0.19.7"

0 comments on commit d165ddc

Please sign in to comment.