forked from SW/traefik
Compare commits
9 Commits
v1.0.alpha
...
v1.0.alpha
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f10bbd8c69 | ||
|
|
6bcb6f92f5 | ||
|
|
f6b5684a5b | ||
|
|
866e8db5f7 | ||
|
|
a9925c7521 | ||
|
|
f955cc33c5 | ||
|
|
e728f32a15 | ||
|
|
4abb4c6489 | ||
|
|
66998e60b8 |
@@ -1,4 +1,5 @@
|
||||
FROM scratch
|
||||
COPY script/ca-certificates.crt /etc/ssl/certs/
|
||||
COPY dist/traefik /
|
||||
EXPOSE 80
|
||||
ENTRYPOINT ["/traefik"]
|
||||
|
||||
@@ -243,6 +243,11 @@ address = ":8080"
|
||||
#
|
||||
# CertFile = "traefik.crt"
|
||||
# KeyFile = "traefik.key"
|
||||
#
|
||||
# Set REST API to read-only mode
|
||||
#
|
||||
# Optional
|
||||
# ReadOnly = false
|
||||
```
|
||||
|
||||
- `/`: provides a simple HTML frontend of Træfik
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"github.com/docker/libkv"
|
||||
"github.com/docker/libkv/store"
|
||||
"github.com/emilevauge/traefik/types"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Kv holds common configurations of key-value providers.
|
||||
@@ -74,10 +73,9 @@ func (provider *Kv) loadConfig() *types.Configuration {
|
||||
provider.Prefix,
|
||||
}
|
||||
var KvFuncMap = template.FuncMap{
|
||||
"List": provider.list,
|
||||
"Get": provider.get,
|
||||
"GetBool": provider.getBool,
|
||||
"Last": provider.last,
|
||||
"List": provider.list,
|
||||
"Get": provider.get,
|
||||
"Last": provider.last,
|
||||
}
|
||||
|
||||
configuration, err := provider.getConfiguration("templates/kv.tmpl", KvFuncMap, templateObjects)
|
||||
@@ -114,16 +112,6 @@ func (provider *Kv) get(keys ...string) string {
|
||||
return string(keyPair.Value)
|
||||
}
|
||||
|
||||
func (provider *Kv) getBool(keys ...string) bool {
|
||||
value := provider.get(keys...)
|
||||
b, err := strconv.ParseBool(string(value))
|
||||
if err != nil {
|
||||
log.Error("Error getting key: ", strings.Join(keys, ""), err)
|
||||
return false
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func (provider *Kv) last(key string) string {
|
||||
splittedKey := strings.Split(key, "/")
|
||||
return splittedKey[len(splittedKey)-1]
|
||||
|
||||
@@ -194,61 +194,6 @@ func TestKvGet(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestKvGetBool(t *testing.T) {
|
||||
cases := []struct {
|
||||
provider *Kv
|
||||
keys []string
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
provider: &Kv{
|
||||
kvclient: &Mock{
|
||||
KVPairs: []*store.KVPair{
|
||||
{
|
||||
Key: "foo",
|
||||
Value: []byte("true"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
keys: []string{"foo"},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
provider: &Kv{
|
||||
kvclient: &Mock{
|
||||
KVPairs: []*store.KVPair{
|
||||
{
|
||||
Key: "foo",
|
||||
Value: []byte("false"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
keys: []string{"foo"},
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
actual := c.provider.getBool(c.keys...)
|
||||
if actual != c.expected {
|
||||
t.Fatalf("expected %v, got %v for %v and %v", c.expected, actual, c.keys, c.provider)
|
||||
}
|
||||
}
|
||||
|
||||
// Error case
|
||||
provider := &Kv{
|
||||
kvclient: &Mock{
|
||||
Error: true,
|
||||
},
|
||||
}
|
||||
actual := provider.get("anything")
|
||||
if actual != "" {
|
||||
t.Fatalf("Should have return nil, got %v", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestKvLast(t *testing.T) {
|
||||
cases := []struct {
|
||||
key string
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
{{$frontend := Last .}}
|
||||
[frontends.{{$frontend}}]
|
||||
backend = "{{Get . "/backend"}}"
|
||||
passHostHeader = "{{GetBool . "/passHostHeader"}}"
|
||||
passHostHeader = {{Get . "/passHostHeader"}}
|
||||
{{$routes := List . "/routes/"}}
|
||||
{{range $routes}}
|
||||
[frontends.{{$frontend}}.routes.{{Last .}}]
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
[frontends.frontend{{.ID | replace "/" "-"}}]
|
||||
backend = "backend{{.ID | replace "/" "-"}}"
|
||||
passHostHeader = {{getPassHostHeader .}}
|
||||
[frontends.frontend-{{.ID | replace "/" ""}}.routes.route-host-{{.ID | replace "/" ""}}]
|
||||
[frontends.frontend{{.ID | replace "/" "-"}}.routes.route-host{{.ID | replace "/" "-"}}]
|
||||
rule = "{{getFrontendRule .}}"
|
||||
value = "{{getFrontendValue .}}"
|
||||
{{end}}
|
||||
6
web.go
6
web.go
@@ -19,6 +19,7 @@ import (
|
||||
type WebProvider struct {
|
||||
Address string
|
||||
CertFile, KeyFile string
|
||||
ReadOnly bool
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -40,6 +41,11 @@ func (provider *WebProvider) Provide(configurationChan chan<- types.ConfigMessag
|
||||
systemRouter.Methods("GET").Path("/api/providers").HandlerFunc(getConfigHandler)
|
||||
systemRouter.Methods("GET").Path("/api/providers/{provider}").HandlerFunc(getProviderHandler)
|
||||
systemRouter.Methods("PUT").Path("/api/providers/{provider}").HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
|
||||
if provider.ReadOnly {
|
||||
response.WriteHeader(http.StatusForbidden)
|
||||
fmt.Fprintf(response, "REST API is in read-only mode")
|
||||
return
|
||||
}
|
||||
vars := mux.Vars(request)
|
||||
if vars["provider"] != "web" {
|
||||
response.WriteHeader(http.StatusBadRequest)
|
||||
|
||||
Reference in New Issue
Block a user