20
vendor/k8s.io/apiserver/pkg/endpoints/request/context.go
generated
vendored
20
vendor/k8s.io/apiserver/pkg/endpoints/request/context.go
generated
vendored
@@ -21,9 +21,7 @@ import (
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apiserver/pkg/apis/audit"
|
||||
"k8s.io/apiserver/pkg/authentication/user"
|
||||
)
|
||||
|
||||
@@ -65,8 +63,7 @@ const (
|
||||
// userAgentKey is the context key for the request user agent.
|
||||
userAgentKey
|
||||
|
||||
// auditKey is the context key for the audit event.
|
||||
auditKey
|
||||
namespaceDefault = "default" // TODO(sttts): solve import cycle when using metav1.NamespaceDefault
|
||||
)
|
||||
|
||||
// NewContext instantiates a base context object for request flows.
|
||||
@@ -76,7 +73,7 @@ func NewContext() Context {
|
||||
|
||||
// NewDefaultContext instantiates a base context object for request flows in the default namespace
|
||||
func NewDefaultContext() Context {
|
||||
return WithNamespace(NewContext(), metav1.NamespaceDefault)
|
||||
return WithNamespace(NewContext(), namespaceDefault)
|
||||
}
|
||||
|
||||
// WithValue returns a copy of parent in which the value associated with key is val.
|
||||
@@ -109,7 +106,7 @@ func NamespaceValue(ctx Context) string {
|
||||
func WithNamespaceDefaultIfNone(parent Context) Context {
|
||||
namespace, ok := NamespaceFrom(parent)
|
||||
if !ok || len(namespace) == 0 {
|
||||
return WithNamespace(parent, metav1.NamespaceDefault)
|
||||
return WithNamespace(parent, namespaceDefault)
|
||||
}
|
||||
return parent
|
||||
}
|
||||
@@ -146,14 +143,3 @@ func UserAgentFrom(ctx Context) (string, bool) {
|
||||
userAgent, ok := ctx.Value(userAgentKey).(string)
|
||||
return userAgent, ok
|
||||
}
|
||||
|
||||
// WithAuditEvent returns set audit event struct.
|
||||
func WithAuditEvent(parent Context, ev *audit.Event) Context {
|
||||
return WithValue(parent, auditKey, ev)
|
||||
}
|
||||
|
||||
// AuditEventFrom returns the audit event struct on the ctx
|
||||
func AuditEventFrom(ctx Context) *audit.Event {
|
||||
ev, _ := ctx.Value(auditKey).(*audit.Event)
|
||||
return ev
|
||||
}
|
||||
|
||||
3
vendor/k8s.io/apiserver/pkg/endpoints/request/requestcontext.go
generated
vendored
3
vendor/k8s.io/apiserver/pkg/endpoints/request/requestcontext.go
generated
vendored
@@ -24,9 +24,6 @@ import (
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
// LongRunningRequestCheck is a predicate which is true for long-running http requests.
|
||||
type LongRunningRequestCheck func(r *http.Request, requestInfo *RequestInfo) bool
|
||||
|
||||
// RequestContextMapper keeps track of the context associated with a particular request
|
||||
type RequestContextMapper interface {
|
||||
// Get returns the context associated with the given request (if any), and true if the request has an associated context, and false if it does not.
|
||||
|
||||
28
vendor/k8s.io/apiserver/pkg/endpoints/request/requestinfo.go
generated
vendored
28
vendor/k8s.io/apiserver/pkg/endpoints/request/requestinfo.go
generated
vendored
@@ -21,14 +21,9 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
)
|
||||
|
||||
type RequestInfoResolver interface {
|
||||
NewRequestInfo(req *http.Request) (*RequestInfo, error)
|
||||
}
|
||||
|
||||
// RequestInfo holds information parsed from the http.Request
|
||||
type RequestInfo struct {
|
||||
// IsResourceRequest indicates whether or not the request is for an API resource or subresource
|
||||
@@ -59,10 +54,10 @@ type RequestInfo struct {
|
||||
// CRUDdy GET/POST/PUT/DELETE actions on REST objects.
|
||||
// TODO: find a way to keep this up to date automatically. Maybe dynamically populate list as handlers added to
|
||||
// master's Mux.
|
||||
var specialVerbs = sets.NewString("proxy", "watch")
|
||||
var specialVerbs = sets.NewString("proxy", "redirect", "watch")
|
||||
|
||||
// specialVerbsNoSubresources contains root verbs which do not allow subresources
|
||||
var specialVerbsNoSubresources = sets.NewString("proxy")
|
||||
var specialVerbsNoSubresources = sets.NewString("proxy", "redirect")
|
||||
|
||||
// namespaceSubresources contains subresources of namespace
|
||||
// this list allows the parser to distinguish between a namespace subresource, and a namespaced resource
|
||||
@@ -92,6 +87,8 @@ type RequestInfoFactory struct {
|
||||
// Special verbs without subresources:
|
||||
// /api/{version}/proxy/{resource}/{resourceName}
|
||||
// /api/{version}/proxy/namespaces/{namespace}/{resource}/{resourceName}
|
||||
// /api/{version}/redirect/namespaces/{namespace}/{resource}/{resourceName}
|
||||
// /api/{version}/redirect/{resource}/{resourceName}
|
||||
//
|
||||
// Special verbs with subresources:
|
||||
// /api/{version}/watch/{resource}
|
||||
@@ -179,7 +176,7 @@ func (r *RequestInfoFactory) NewRequestInfo(req *http.Request) (*RequestInfo, er
|
||||
}
|
||||
}
|
||||
} else {
|
||||
requestInfo.Namespace = metav1.NamespaceNone
|
||||
requestInfo.Namespace = "" // TODO(sttts): solve import cycle when using metav1.NamespaceNone
|
||||
}
|
||||
|
||||
// parsing successful, so we now know the proper value for .Parts
|
||||
@@ -200,17 +197,12 @@ func (r *RequestInfoFactory) NewRequestInfo(req *http.Request) (*RequestInfo, er
|
||||
// if there's no name on the request and we thought it was a get before, then the actual verb is a list or a watch
|
||||
if len(requestInfo.Name) == 0 && requestInfo.Verb == "get" {
|
||||
// Assumes v1.ListOptions
|
||||
// Any query value that is not 0 or false is considered true
|
||||
// see apimachinery/pkg/runtime/conversion.go Convert_Slice_string_To_bool
|
||||
if values := req.URL.Query()["watch"]; len(values) > 0 {
|
||||
switch strings.ToLower(values[0]) {
|
||||
case "false", "0":
|
||||
requestInfo.Verb = "list"
|
||||
default:
|
||||
requestInfo.Verb = "watch"
|
||||
}
|
||||
} else {
|
||||
// Duplicates logic of Convert_Slice_string_To_bool
|
||||
switch strings.ToLower(req.URL.Query().Get("watch")) {
|
||||
case "false", "0", "":
|
||||
requestInfo.Verb = "list"
|
||||
default:
|
||||
requestInfo.Verb = "watch"
|
||||
}
|
||||
}
|
||||
// if there's no name on the request and we thought it was a delete before, then the actual verb is deletecollection
|
||||
|
||||
Reference in New Issue
Block a user