mirror of
https://github.com/rancher/types.git
synced 2025-08-31 21:00:16 +00:00
Update vendor for norman
This commit is contained in:
9
vendor/github.com/rancher/norman/clientbase/ops.go
generated
vendored
9
vendor/github.com/rancher/norman/clientbase/ops.go
generated
vendored
@@ -285,6 +285,10 @@ func (a *APIOperations) doAction(
|
||||
|
||||
var input io.Reader
|
||||
|
||||
if debug {
|
||||
fmt.Println("POST " + actionURL)
|
||||
}
|
||||
|
||||
if inputObject != nil {
|
||||
bodyContent, err := json.Marshal(inputObject)
|
||||
if err != nil {
|
||||
@@ -325,5 +329,8 @@ func (a *APIOperations) doAction(
|
||||
fmt.Println("Response <= " + string(byteContent))
|
||||
}
|
||||
|
||||
return json.Unmarshal(byteContent, respObject)
|
||||
if nil != respObject {
|
||||
return json.Unmarshal(byteContent, respObject)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
5
vendor/github.com/rancher/norman/controller/cluster_check.go
generated
vendored
5
vendor/github.com/rancher/norman/controller/cluster_check.go
generated
vendored
@@ -39,6 +39,11 @@ func ObjectInCluster(cluster string, obj interface{}) bool {
|
||||
}
|
||||
}
|
||||
}
|
||||
if clusterName == "" {
|
||||
if c := getValue(obj, "Namespace"); c.IsValid() {
|
||||
clusterName = c.String()
|
||||
}
|
||||
}
|
||||
|
||||
return clusterName == cluster
|
||||
}
|
||||
|
2
vendor/github.com/rancher/norman/generator/generator.go
generated
vendored
2
vendor/github.com/rancher/norman/generator/generator.go
generated
vendored
@@ -78,6 +78,8 @@ func getTypeString(nullable bool, typeName string, schema *types.Schema, schemas
|
||||
return "intstr.IntOrString"
|
||||
case "dnsLabel":
|
||||
return "string"
|
||||
case "hostname":
|
||||
return "string"
|
||||
default:
|
||||
if schema != nil && schemas != nil {
|
||||
otherSchema := schemas.Schema(&schema.Version, typeName)
|
||||
|
27
vendor/github.com/rancher/norman/types/condition.go
generated
vendored
27
vendor/github.com/rancher/norman/types/condition.go
generated
vendored
@@ -39,35 +39,44 @@ type QueryCondition struct {
|
||||
left, right *QueryCondition
|
||||
}
|
||||
|
||||
func (q *QueryCondition) Valid(data map[string]interface{}) bool {
|
||||
func (q *QueryCondition) Valid(schema *Schema, data map[string]interface{}) bool {
|
||||
switch q.conditionType {
|
||||
case CondAnd:
|
||||
if q.left == nil || q.right == nil {
|
||||
return false
|
||||
}
|
||||
return q.left.Valid(data) && q.right.Valid(data)
|
||||
return q.left.Valid(schema, data) && q.right.Valid(schema, data)
|
||||
case CondOr:
|
||||
if q.left == nil || q.right == nil {
|
||||
return false
|
||||
}
|
||||
return q.left.Valid(data) || q.right.Valid(data)
|
||||
return q.left.Valid(schema, data) || q.right.Valid(schema, data)
|
||||
case CondEQ:
|
||||
return q.Value == convert.ToString(data[q.Field])
|
||||
return q.Value == convert.ToString(valueOrDefault(schema, data, q))
|
||||
case CondNE:
|
||||
return q.Value != convert.ToString(data[q.Field])
|
||||
return q.Value != convert.ToString(valueOrDefault(schema, data, q))
|
||||
case CondIn:
|
||||
return q.Values[convert.ToString(data[q.Field])]
|
||||
return q.Values[convert.ToString(valueOrDefault(schema, data, q))]
|
||||
case CondNotIn:
|
||||
return !q.Values[convert.ToString(data[q.Field])]
|
||||
return !q.Values[convert.ToString(valueOrDefault(schema, data, q))]
|
||||
case CondNotNull:
|
||||
return convert.ToString(data[q.Field]) != ""
|
||||
return convert.ToString(valueOrDefault(schema, data, q)) != ""
|
||||
case CondNull:
|
||||
return convert.ToString(data[q.Field]) == ""
|
||||
return convert.ToString(valueOrDefault(schema, data, q)) == ""
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func valueOrDefault(schema *Schema, data map[string]interface{}, q *QueryCondition) interface{} {
|
||||
value := data[q.Field]
|
||||
if value == nil {
|
||||
value = schema.ResourceFields[q.Field].Default
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
func (q *QueryCondition) ToCondition() Condition {
|
||||
cond := Condition{
|
||||
Modifier: q.conditionType.Name,
|
||||
|
6
vendor/github.com/rancher/norman/types/reflection.go
generated
vendored
6
vendor/github.com/rancher/norman/types/reflection.go
generated
vendored
@@ -48,6 +48,10 @@ func (s *Schemas) AddMapperForType(version *APIVersion, obj interface{}, mapper
|
||||
}
|
||||
|
||||
func (s *Schemas) MustImport(version *APIVersion, obj interface{}, externalOverrides ...interface{}) *Schemas {
|
||||
if reflect.ValueOf(obj).Kind() == reflect.Ptr {
|
||||
panic(fmt.Errorf("obj cannot be a pointer"))
|
||||
}
|
||||
|
||||
if _, err := s.Import(version, obj, externalOverrides...); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -97,6 +101,8 @@ func (s *Schemas) setupFilters(schema *Schema) {
|
||||
mods = []ModifierType{ModifierEQ, ModifierNE, ModifierIn, ModifierNotIn}
|
||||
case "dnsLabel":
|
||||
fallthrough
|
||||
case "hostname":
|
||||
fallthrough
|
||||
case "string":
|
||||
mods = []ModifierType{ModifierEQ, ModifierNE, ModifierIn, ModifierNotIn}
|
||||
case "int":
|
||||
|
16
vendor/github.com/rancher/norman/types/server_types.go
generated
vendored
16
vendor/github.com/rancher/norman/types/server_types.go
generated
vendored
@@ -49,7 +49,7 @@ type ActionHandler func(actionName string, action *Action, request *APIContext)
|
||||
|
||||
type RequestHandler func(request *APIContext, next RequestHandler) error
|
||||
|
||||
type QueryFilter func(opts *QueryOptions, data []map[string]interface{}) []map[string]interface{}
|
||||
type QueryFilter func(opts *QueryOptions, schema *Schema, data []map[string]interface{}) []map[string]interface{}
|
||||
|
||||
type Validator func(request *APIContext, schema *Schema, data map[string]interface{}) error
|
||||
|
||||
@@ -127,25 +127,25 @@ func (r *APIContext) WriteResponse(code int, obj interface{}) {
|
||||
r.ResponseWriter.Write(r, code, obj)
|
||||
}
|
||||
|
||||
func (r *APIContext) FilterList(opts *QueryOptions, obj []map[string]interface{}) []map[string]interface{} {
|
||||
return r.QueryFilter(opts, obj)
|
||||
func (r *APIContext) FilterList(opts *QueryOptions, schema *Schema, obj []map[string]interface{}) []map[string]interface{} {
|
||||
return r.QueryFilter(opts, schema, obj)
|
||||
}
|
||||
|
||||
func (r *APIContext) FilterObject(opts *QueryOptions, obj map[string]interface{}) map[string]interface{} {
|
||||
func (r *APIContext) FilterObject(opts *QueryOptions, schema *Schema, obj map[string]interface{}) map[string]interface{} {
|
||||
opts.Pagination = nil
|
||||
result := r.QueryFilter(opts, []map[string]interface{}{obj})
|
||||
result := r.QueryFilter(opts, schema, []map[string]interface{}{obj})
|
||||
if len(result) == 0 {
|
||||
return nil
|
||||
}
|
||||
return result[0]
|
||||
}
|
||||
|
||||
func (r *APIContext) Filter(opts *QueryOptions, obj interface{}) interface{} {
|
||||
func (r *APIContext) Filter(opts *QueryOptions, schema *Schema, obj interface{}) interface{} {
|
||||
switch v := obj.(type) {
|
||||
case []map[string]interface{}:
|
||||
return r.FilterList(opts, v)
|
||||
return r.FilterList(opts, schema, v)
|
||||
case map[string]interface{}:
|
||||
return r.FilterObject(opts, v)
|
||||
return r.FilterObject(opts, schema, v)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user