Skip to content

Commit

Permalink
Fixed #347
Browse files Browse the repository at this point in the history
  • Loading branch information
vfarcic committed Oct 14, 2017
1 parent d80bc34 commit 4da835c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ENV CERTS="" \
DEFAULT_PORTS="80,443:ssl" \
DEFAULT_REQ_MODE="http" \
DO_NOT_RESOLVE_ADDR="false" \
HTTPS_ONLY="false" \
EXTRA_FRONTEND="" \
LISTENER_ADDRESS="" \
MODE="default" \
Expand Down
1 change: 1 addition & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ The following environment variables can be used to configure the *Docker Flow Pr
|DO_NOT_RESOLVE_ADDR|Whether not to resolve addresses. If set to `true`, the proxy will NOT fail if the service is not available.<br>**Default value:** `false`|
|EXTRA_FRONTEND |Value will be added to the default `frontend` configuration. Multiple lines should be separated with comma (*,*).|
|EXTRA_GLOBAL |Value will be added to the default `global` configuration. Multiple lines should be separated with comma (*,*).|
|HTTPS_ONLY |If set to true, all requests to all the service will be redirected to HTTPS.<br>**Example:** `true`<br>**Default Value:** `false`|
|LISTENER_ADDRESS |The address of the [Docker Flow: Swarm Listener](https://github.com/vfarcic/docker-flow-swarm-listener) used for automatic proxy configuration.<br>**Example:** `swarm-listener:8080`|
PROXY_INSTANCE_NAME|The name of the proxy instance. Useful if multiple proxies are running inside a cluster.<br>**Default value:** `docker-flow`|
|SERVICE_NAME |The name of the service. It must be the same as the value of the `--name` argument used to create the proxy service. Used only in the *swarm* mode.<br>**Example:** `my-proxy`<br>**Default value:** `proxy`|
Expand Down
3 changes: 3 additions & 0 deletions proxy/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ func getServiceDestList(sr *Service, provider ServiceParameterProvider) []Servic
serviceDomain = sd.ServiceDomain
}
httpsOnly := sd.HttpsOnly
if !httpsOnly {
httpsOnly, _ = strconv.ParseBool(os.Getenv("HTTPS_ONLY"))
}
for i := 1; i <= 10; i++ {
sd := getServiceDest(sr, provider, i)
if isServiceDestValid(&sd) {
Expand Down
35 changes: 31 additions & 4 deletions proxy/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,27 +289,54 @@ func (s *TypesTestSuite) Test_GetServiceFromProvider_MovesHttpsOnlyToIndexedEntr
Index: 1,
Port: "1234",
RedirectFromDomain: []string{},
ReqMode: "reqMode",
ReqMode: "http",
ServiceDomain: []string{},
ServiceHeader: map[string]string{},
ServicePath: []string{"/"},
}},
ServiceName: "serviceName",
}
serviceMap := map[string]string{
// "serviceDomain": strings.Join(expected.ServiceDest[0].ServiceDomain, ","),
"httpsOnly": strconv.FormatBool(expected.ServiceDest[0].HttpsOnly),
"httpsRedirectCode": expected.ServiceDest[0].HttpsRedirectCode,
"serviceName": expected.ServiceName,
"port.1": expected.ServiceDest[0].Port,
"reqMode.1": expected.ServiceDest[0].ReqMode,
"servicePath.1": strings.Join(expected.ServiceDest[0].ServicePath, ","),
}
provider := mapParameterProvider{&serviceMap}
actual := GetServiceFromProvider(&provider)
s.Equal(expected, *actual)
}

func (s *TypesTestSuite) Test_GetServiceFromProvider_UsesHttpsOnlyFromEnvVar() {
defer func() { os.Unsetenv("HTTPS_ONLY") }()
os.Setenv("HTTPS_ONLY", "true")
expected := Service{
ServiceDest: []ServiceDest{{
AllowedMethods: []string{},
DeniedMethods: []string{},
HttpsOnly: true,
Index: 1,
Port: "1234",
RedirectFromDomain: []string{},
ReqMode: "http",
ServiceDomain: []string{},
ServiceHeader: map[string]string{},
ServicePath: []string{"/"},
}},
ServiceName: "serviceName",
}
serviceMap := map[string]string{
"serviceName": expected.ServiceName,
"port.1": expected.ServiceDest[0].Port,
"servicePath.1": strings.Join(expected.ServiceDest[0].ServicePath, ","),
}
provider := mapParameterProvider{&serviceMap}

actual := GetServiceFromProvider(&provider)

s.Equal(expected, *actual)
}

// Util

func (s *TypesTestSuite) getServiceMap(expected Service, indexSuffix, separator string) map[string]string {
Expand Down

0 comments on commit 4da835c

Please sign in to comment.