ingress-nginx-helm/core/pkg/ingress/annotations/rewrite/main.go

67 lines
2 KiB
Go
Raw Normal View History

2016-05-25 21:04:34 +00:00
/*
Copyright 2016 The Kubernetes Authors.
2016-05-25 21:04:34 +00:00
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package rewrite
import (
2016-11-16 18:24:26 +00:00
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/ingress/core/pkg/ingress/annotations/parser"
"k8s.io/ingress/core/pkg/ingress/resolver"
2016-05-25 21:04:34 +00:00
)
const (
rewriteTo = "ingress.kubernetes.io/rewrite-target"
addBaseURL = "ingress.kubernetes.io/add-base-url"
sslRedirect = "ingress.kubernetes.io/ssl-redirect"
2016-05-25 21:04:34 +00:00
)
// Redirect describes the per location redirect config
2016-05-25 21:04:34 +00:00
type Redirect struct {
// Target URI where the traffic must be redirected
2016-11-16 18:24:26 +00:00
Target string `json:"target"`
// AddBaseURL indicates if is required to add a base tag in the head
// of the responses from the upstream servers
2016-11-16 18:24:26 +00:00
AddBaseURL bool `json:"addBaseUrl"`
// SSLRedirect indicates if the location section is accessible SSL only
2016-11-16 18:24:26 +00:00
SSLRedirect bool `json:"sslRedirect"`
2016-05-25 21:04:34 +00:00
}
type rewrite struct {
backendResolver resolver.DefaultBackend
}
// NewParser creates a new reqrite annotation parser
func NewParser(br resolver.DefaultBackend) parser.IngressAnnotation {
return rewrite{br}
}
2016-05-25 21:04:34 +00:00
// ParseAnnotations parses the annotations contained in the ingress
// rule used to rewrite the defined paths
func (a rewrite) Parse(ing *extensions.Ingress) (interface{}, error) {
2017-02-11 21:34:50 +00:00
rt, _ := parser.GetStringAnnotation(rewriteTo, ing)
sslRe, err := parser.GetBoolAnnotation(sslRedirect, ing)
if err != nil {
sslRe = a.backendResolver.GetDefaultBackend().SSLRedirect
}
abu, _ := parser.GetBoolAnnotation(addBaseURL, ing)
2016-05-25 21:04:34 +00:00
return &Redirect{
Target: rt,
AddBaseURL: abu,
SSLRedirect: sslRe,
2016-05-25 21:04:34 +00:00
}, nil
}