From f772529b435761e3f6a0f863021f3da2022c7068 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Thu, 7 Jul 2022 15:46:02 -0700 Subject: [PATCH 01/35] more debugging Signed-off-by: James Phillips --- graphql/service.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/graphql/service.go b/graphql/service.go index 759e6e2f63..96df920633 100644 --- a/graphql/service.go +++ b/graphql/service.go @@ -8,6 +8,7 @@ import ( "github.com/graphql-go/graphql/gqlerrors" "github.com/graphql-go/graphql/language/parser" "github.com/graphql-go/graphql/language/source" + "github.com/sirupsen/logrus" ) // Service describes the whole of a GraphQL schema, validation, and execution. @@ -88,6 +89,7 @@ func (service *Service) RegisterObject(t ObjectDesc, impl interface{}) { if typeResolver, ok := impl.(isTypeOfResolver); ok { cfg.IsTypeOf = newIsTypeOfFn(typeResolver) } + logrus.Warnf("%s: %T", cfg.Name, cfg.IsTypeOf) for _, ext := range service.types.extensionsForType(cfg.Name) { extObjCfg := ext.(graphql.ObjectConfig) From dd46780382026298988e9d7eaa8d00b6cc65fa4c Mon Sep 17 00:00:00 2001 From: James Phillips Date: Thu, 7 Jul 2022 15:48:03 -0700 Subject: [PATCH 02/35] more debugging Signed-off-by: James Phillips --- backend/apid/graphql/corev2.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/apid/graphql/corev2.go b/backend/apid/graphql/corev2.go index fee7ecf679..7ef5348276 100644 --- a/backend/apid/graphql/corev2.go +++ b/backend/apid/graphql/corev2.go @@ -30,6 +30,8 @@ func (*corev2PipelineImpl) ToJSON(p graphql.ResolveParams) (interface{}, error) // IsTypeOf is used to determine if a given value is associated with the type func (*corev2PipelineImpl) IsTypeOf(s interface{}, p graphql.IsTypeOfParams) bool { + _, sk := s.(*corev2.Role) + logger.Warnf("CoreV2Pipeline#isTypeOf(): %T (%s)", s, sk) _, ok := s.(*corev2.Pipeline) return ok } From 66d49a1aeb377da79614628b7a783cadfcf938cd Mon Sep 17 00:00:00 2001 From: James Phillips Date: Thu, 7 Jul 2022 15:53:23 -0700 Subject: [PATCH 03/35] more debugging Signed-off-by: James Phillips --- graphql/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphql/service.go b/graphql/service.go index 96df920633..5c32717d6b 100644 --- a/graphql/service.go +++ b/graphql/service.go @@ -87,9 +87,9 @@ func (service *Service) RegisterObject(t ObjectDesc, impl interface{}) { cfg.IsTypeOf = nil if typeResolver, ok := impl.(isTypeOfResolver); ok { + logrus.Warnf("%s: %T", cfg.Name, cfg.IsTypeOf) cfg.IsTypeOf = newIsTypeOfFn(typeResolver) } - logrus.Warnf("%s: %T", cfg.Name, cfg.IsTypeOf) for _, ext := range service.types.extensionsForType(cfg.Name) { extObjCfg := ext.(graphql.ObjectConfig) From eef64abb72e3708ceb399b5b0c608fcc9caaf014 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Thu, 7 Jul 2022 15:57:49 -0700 Subject: [PATCH 04/35] more debugging Signed-off-by: James Phillips --- graphql/service.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/graphql/service.go b/graphql/service.go index 5c32717d6b..6f68e22f3c 100644 --- a/graphql/service.go +++ b/graphql/service.go @@ -87,7 +87,6 @@ func (service *Service) RegisterObject(t ObjectDesc, impl interface{}) { cfg.IsTypeOf = nil if typeResolver, ok := impl.(isTypeOfResolver); ok { - logrus.Warnf("%s: %T", cfg.Name, cfg.IsTypeOf) cfg.IsTypeOf = newIsTypeOfFn(typeResolver) } @@ -98,6 +97,8 @@ func (service *Service) RegisterObject(t ObjectDesc, impl interface{}) { cfg.Fields = fieldsThunk(m, fields) cfg.Interfaces = interfacesThunk(m, cfg.Interfaces) + + logrus.Warnf("%s: [%T]: %#v", cfg.Name, cfg.IsTypeOf, cfg.IsTypeOf) return graphql.NewObject(cfg) } service.types.addType(cfg.Name, ObjectKind, registrar) From 34385bd3758ec6c89ee53dc6e8fd63ecbe58232e Mon Sep 17 00:00:00 2001 From: James Phillips Date: Thu, 7 Jul 2022 16:08:28 -0700 Subject: [PATCH 05/35] omit debugging Signed-off-by: James Phillips --- backend/apid/graphql/corev2.go | 2 -- graphql/service.go | 3 --- 2 files changed, 5 deletions(-) diff --git a/backend/apid/graphql/corev2.go b/backend/apid/graphql/corev2.go index 7ef5348276..fee7ecf679 100644 --- a/backend/apid/graphql/corev2.go +++ b/backend/apid/graphql/corev2.go @@ -30,8 +30,6 @@ func (*corev2PipelineImpl) ToJSON(p graphql.ResolveParams) (interface{}, error) // IsTypeOf is used to determine if a given value is associated with the type func (*corev2PipelineImpl) IsTypeOf(s interface{}, p graphql.IsTypeOfParams) bool { - _, sk := s.(*corev2.Role) - logger.Warnf("CoreV2Pipeline#isTypeOf(): %T (%s)", s, sk) _, ok := s.(*corev2.Pipeline) return ok } diff --git a/graphql/service.go b/graphql/service.go index 6f68e22f3c..759e6e2f63 100644 --- a/graphql/service.go +++ b/graphql/service.go @@ -8,7 +8,6 @@ import ( "github.com/graphql-go/graphql/gqlerrors" "github.com/graphql-go/graphql/language/parser" "github.com/graphql-go/graphql/language/source" - "github.com/sirupsen/logrus" ) // Service describes the whole of a GraphQL schema, validation, and execution. @@ -97,8 +96,6 @@ func (service *Service) RegisterObject(t ObjectDesc, impl interface{}) { cfg.Fields = fieldsThunk(m, fields) cfg.Interfaces = interfacesThunk(m, cfg.Interfaces) - - logrus.Warnf("%s: [%T]: %#v", cfg.Name, cfg.IsTypeOf, cfg.IsTypeOf) return graphql.NewObject(cfg) } service.types.addType(cfg.Name, ObjectKind, registrar) From c9566217e8619d878812e2f6b91cde3a42a31bf8 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Thu, 7 Jul 2022 17:20:34 -0700 Subject: [PATCH 06/35] leverage code generator more Signed-off-by: James Phillips --- backend/apid/graphql/schema/corev2.gql.go | 380 ++++++++++++++++++++- backend/apid/graphql/schema/corev2.graphql | 10 + 2 files changed, 388 insertions(+), 2 deletions(-) diff --git a/backend/apid/graphql/schema/corev2.gql.go b/backend/apid/graphql/schema/corev2.gql.go index 69b948e0e7..181d32a1d8 100644 --- a/backend/apid/graphql/schema/corev2.gql.go +++ b/backend/apid/graphql/schema/corev2.gql.go @@ -14,6 +14,9 @@ type CoreV2PipelineExtensionOverridesFieldResolvers interface { // ID implements response to request for 'id' field. ID(p graphql.ResolveParams) (string, error) + // Metadata implements response to request for 'metadata' field. + Metadata(p graphql.ResolveParams) (interface{}, error) + // ToJSON implements response to request for 'toJSON' field. ToJSON(p graphql.ResolveParams) (interface{}, error) } @@ -32,6 +35,15 @@ func _ObjTypeCoreV2PipelineExtensionOverridesIDHandler(impl interface{}) graphql } } +func _ObjTypeCoreV2PipelineExtensionOverridesMetadataHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Metadata(p graphql.ResolveParams) (interface{}, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Metadata(frp) + } +} + func _ObjTypeCoreV2PipelineExtensionOverridesToJSONHandler(impl interface{}) graphql1.FieldResolveFn { resolver := impl.(interface { ToJSON(p graphql.ResolveParams) (interface{}, error) @@ -52,6 +64,13 @@ func _ObjectExtensionTypeCoreV2PipelineExtensionOverridesConfigFn() graphql1.Obj Name: "id", Type: graphql1.NewNonNull(graphql1.ID), }, + "metadata": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "metadata contains name, namespace, labels and annotations of the record", + Name: "metadata", + Type: graphql.OutputType("ObjectMeta"), + }, "toJSON": &graphql1.Field{ Args: graphql1.FieldConfigArgument{}, DeprecationReason: "", @@ -71,8 +90,365 @@ func _ObjectExtensionTypeCoreV2PipelineExtensionOverridesConfigFn() graphql1.Obj var _ObjectExtensionTypeCoreV2PipelineExtensionOverridesDesc = graphql.ObjectDesc{ Config: _ObjectExtensionTypeCoreV2PipelineExtensionOverridesConfigFn, FieldHandlers: map[string]graphql.FieldHandler{ - "id": _ObjTypeCoreV2PipelineExtensionOverridesIDHandler, - "toJSON": _ObjTypeCoreV2PipelineExtensionOverridesToJSONHandler, + "id": _ObjTypeCoreV2PipelineExtensionOverridesIDHandler, + "metadata": _ObjTypeCoreV2PipelineExtensionOverridesMetadataHandler, + "toJSON": _ObjTypeCoreV2PipelineExtensionOverridesToJSONHandler, + }, +} + +// +// CoreV2RoleExtensionOverridesFieldResolvers represents a collection of methods whose products represent the +// response values of the 'CoreV2RoleExtensionOverrides' type. +type CoreV2RoleExtensionOverridesFieldResolvers interface { + // ID implements response to request for 'id' field. + ID(p graphql.ResolveParams) (string, error) + + // Metadata implements response to request for 'metadata' field. + Metadata(p graphql.ResolveParams) (interface{}, error) + + // ToJSON implements response to request for 'toJSON' field. + ToJSON(p graphql.ResolveParams) (interface{}, error) +} + +// RegisterCoreV2RoleExtensionOverrides registers CoreV2RoleExtensionOverrides object type with given service. +func RegisterCoreV2RoleExtensionOverrides(svc *graphql.Service, impl CoreV2RoleExtensionOverridesFieldResolvers) { + svc.RegisterObjectExtension(_ObjectExtensionTypeCoreV2RoleExtensionOverridesDesc, impl) +} + +func _ObjTypeCoreV2RoleExtensionOverridesIDHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + ID(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.ID(frp) + } +} + +func _ObjTypeCoreV2RoleExtensionOverridesMetadataHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Metadata(p graphql.ResolveParams) (interface{}, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Metadata(frp) + } +} + +func _ObjTypeCoreV2RoleExtensionOverridesToJSONHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + ToJSON(p graphql.ResolveParams) (interface{}, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.ToJSON(frp) + } +} + +func _ObjectExtensionTypeCoreV2RoleExtensionOverridesConfigFn() graphql1.ObjectConfig { + return graphql1.ObjectConfig{ + Description: "", + Fields: graphql1.Fields{ + "id": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "The globally unique identifier of the record", + Name: "id", + Type: graphql1.NewNonNull(graphql1.ID), + }, + "metadata": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "metadata contains name, namespace, labels and annotations of the record", + Name: "metadata", + Type: graphql.OutputType("ObjectMeta"), + }, + "toJSON": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "toJSON returns a REST API compatible representation of the resource. Handy for\nsharing snippets that can then be imported with `sensuctl create`.", + Name: "toJSON", + Type: graphql1.NewNonNull(graphql.OutputType("JSON")), + }, + }, + Interfaces: []*graphql1.Interface{ + graphql.Interface("Node"), + graphql.Interface("Resource")}, + Name: "CoreV2Role", + } +} + +// describe CoreV2RoleExtensionOverrides's configuration; kept private to avoid unintentional tampering of configuration at runtime. +var _ObjectExtensionTypeCoreV2RoleExtensionOverridesDesc = graphql.ObjectDesc{ + Config: _ObjectExtensionTypeCoreV2RoleExtensionOverridesConfigFn, + FieldHandlers: map[string]graphql.FieldHandler{ + "id": _ObjTypeCoreV2RoleExtensionOverridesIDHandler, + "metadata": _ObjTypeCoreV2RoleExtensionOverridesMetadataHandler, + "toJSON": _ObjTypeCoreV2RoleExtensionOverridesToJSONHandler, + }, +} + +// +// CoreV2RoleBindingExtensionOverridesFieldResolvers represents a collection of methods whose products represent the +// response values of the 'CoreV2RoleBindingExtensionOverrides' type. +type CoreV2RoleBindingExtensionOverridesFieldResolvers interface { + // ID implements response to request for 'id' field. + ID(p graphql.ResolveParams) (string, error) + + // Metadata implements response to request for 'metadata' field. + Metadata(p graphql.ResolveParams) (interface{}, error) + + // ToJSON implements response to request for 'toJSON' field. + ToJSON(p graphql.ResolveParams) (interface{}, error) +} + +// RegisterCoreV2RoleBindingExtensionOverrides registers CoreV2RoleBindingExtensionOverrides object type with given service. +func RegisterCoreV2RoleBindingExtensionOverrides(svc *graphql.Service, impl CoreV2RoleBindingExtensionOverridesFieldResolvers) { + svc.RegisterObjectExtension(_ObjectExtensionTypeCoreV2RoleBindingExtensionOverridesDesc, impl) +} + +func _ObjTypeCoreV2RoleBindingExtensionOverridesIDHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + ID(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.ID(frp) + } +} + +func _ObjTypeCoreV2RoleBindingExtensionOverridesMetadataHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Metadata(p graphql.ResolveParams) (interface{}, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Metadata(frp) + } +} + +func _ObjTypeCoreV2RoleBindingExtensionOverridesToJSONHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + ToJSON(p graphql.ResolveParams) (interface{}, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.ToJSON(frp) + } +} + +func _ObjectExtensionTypeCoreV2RoleBindingExtensionOverridesConfigFn() graphql1.ObjectConfig { + return graphql1.ObjectConfig{ + Description: "", + Fields: graphql1.Fields{ + "id": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "The globally unique identifier of the record", + Name: "id", + Type: graphql1.NewNonNull(graphql1.ID), + }, + "metadata": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "metadata contains name, namespace, labels and annotations of the record", + Name: "metadata", + Type: graphql.OutputType("ObjectMeta"), + }, + "toJSON": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "toJSON returns a REST API compatible representation of the resource. Handy for\nsharing snippets that can then be imported with `sensuctl create`.", + Name: "toJSON", + Type: graphql1.NewNonNull(graphql.OutputType("JSON")), + }, + }, + Interfaces: []*graphql1.Interface{ + graphql.Interface("Node"), + graphql.Interface("Resource")}, + Name: "CoreV2RoleBinding", + } +} + +// describe CoreV2RoleBindingExtensionOverrides's configuration; kept private to avoid unintentional tampering of configuration at runtime. +var _ObjectExtensionTypeCoreV2RoleBindingExtensionOverridesDesc = graphql.ObjectDesc{ + Config: _ObjectExtensionTypeCoreV2RoleBindingExtensionOverridesConfigFn, + FieldHandlers: map[string]graphql.FieldHandler{ + "id": _ObjTypeCoreV2RoleBindingExtensionOverridesIDHandler, + "metadata": _ObjTypeCoreV2RoleBindingExtensionOverridesMetadataHandler, + "toJSON": _ObjTypeCoreV2RoleBindingExtensionOverridesToJSONHandler, + }, +} + +// +// CoreV2ClusterRoleExtensionOverridesFieldResolvers represents a collection of methods whose products represent the +// response values of the 'CoreV2ClusterRoleExtensionOverrides' type. +type CoreV2ClusterRoleExtensionOverridesFieldResolvers interface { + // ID implements response to request for 'id' field. + ID(p graphql.ResolveParams) (string, error) + + // Metadata implements response to request for 'metadata' field. + Metadata(p graphql.ResolveParams) (interface{}, error) + + // ToJSON implements response to request for 'toJSON' field. + ToJSON(p graphql.ResolveParams) (interface{}, error) +} + +// RegisterCoreV2ClusterRoleExtensionOverrides registers CoreV2ClusterRoleExtensionOverrides object type with given service. +func RegisterCoreV2ClusterRoleExtensionOverrides(svc *graphql.Service, impl CoreV2ClusterRoleExtensionOverridesFieldResolvers) { + svc.RegisterObjectExtension(_ObjectExtensionTypeCoreV2ClusterRoleExtensionOverridesDesc, impl) +} + +func _ObjTypeCoreV2ClusterRoleExtensionOverridesIDHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + ID(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.ID(frp) + } +} + +func _ObjTypeCoreV2ClusterRoleExtensionOverridesMetadataHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Metadata(p graphql.ResolveParams) (interface{}, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Metadata(frp) + } +} + +func _ObjTypeCoreV2ClusterRoleExtensionOverridesToJSONHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + ToJSON(p graphql.ResolveParams) (interface{}, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.ToJSON(frp) + } +} + +func _ObjectExtensionTypeCoreV2ClusterRoleExtensionOverridesConfigFn() graphql1.ObjectConfig { + return graphql1.ObjectConfig{ + Description: "", + Fields: graphql1.Fields{ + "id": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "The globally unique identifier of the record", + Name: "id", + Type: graphql1.NewNonNull(graphql1.ID), + }, + "metadata": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "metadata contains name, namespace, labels and annotations of the record", + Name: "metadata", + Type: graphql.OutputType("ObjectMeta"), + }, + "toJSON": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "toJSON returns a REST API compatible representation of the resource. Handy for\nsharing snippets that can then be imported with `sensuctl create`.", + Name: "toJSON", + Type: graphql1.NewNonNull(graphql.OutputType("JSON")), + }, + }, + Interfaces: []*graphql1.Interface{ + graphql.Interface("Node"), + graphql.Interface("Resource")}, + Name: "CoreV2ClusterRole", + } +} + +// describe CoreV2ClusterRoleExtensionOverrides's configuration; kept private to avoid unintentional tampering of configuration at runtime. +var _ObjectExtensionTypeCoreV2ClusterRoleExtensionOverridesDesc = graphql.ObjectDesc{ + Config: _ObjectExtensionTypeCoreV2ClusterRoleExtensionOverridesConfigFn, + FieldHandlers: map[string]graphql.FieldHandler{ + "id": _ObjTypeCoreV2ClusterRoleExtensionOverridesIDHandler, + "metadata": _ObjTypeCoreV2ClusterRoleExtensionOverridesMetadataHandler, + "toJSON": _ObjTypeCoreV2ClusterRoleExtensionOverridesToJSONHandler, + }, +} + +// +// CoreV2ClusterRoleBindingExtensionOverridesFieldResolvers represents a collection of methods whose products represent the +// response values of the 'CoreV2ClusterRoleBindingExtensionOverrides' type. +type CoreV2ClusterRoleBindingExtensionOverridesFieldResolvers interface { + // ID implements response to request for 'id' field. + ID(p graphql.ResolveParams) (string, error) + + // Metadata implements response to request for 'metadata' field. + Metadata(p graphql.ResolveParams) (interface{}, error) + + // ToJSON implements response to request for 'toJSON' field. + ToJSON(p graphql.ResolveParams) (interface{}, error) +} + +// RegisterCoreV2ClusterRoleBindingExtensionOverrides registers CoreV2ClusterRoleBindingExtensionOverrides object type with given service. +func RegisterCoreV2ClusterRoleBindingExtensionOverrides(svc *graphql.Service, impl CoreV2ClusterRoleBindingExtensionOverridesFieldResolvers) { + svc.RegisterObjectExtension(_ObjectExtensionTypeCoreV2ClusterRoleBindingExtensionOverridesDesc, impl) +} + +func _ObjTypeCoreV2ClusterRoleBindingExtensionOverridesIDHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + ID(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.ID(frp) + } +} + +func _ObjTypeCoreV2ClusterRoleBindingExtensionOverridesMetadataHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Metadata(p graphql.ResolveParams) (interface{}, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Metadata(frp) + } +} + +func _ObjTypeCoreV2ClusterRoleBindingExtensionOverridesToJSONHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + ToJSON(p graphql.ResolveParams) (interface{}, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.ToJSON(frp) + } +} + +func _ObjectExtensionTypeCoreV2ClusterRoleBindingExtensionOverridesConfigFn() graphql1.ObjectConfig { + return graphql1.ObjectConfig{ + Description: "", + Fields: graphql1.Fields{ + "id": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "The globally unique identifier of the record", + Name: "id", + Type: graphql1.NewNonNull(graphql1.ID), + }, + "metadata": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "metadata contains name, namespace, labels and annotations of the record", + Name: "metadata", + Type: graphql.OutputType("ObjectMeta"), + }, + "toJSON": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "toJSON returns a REST API compatible representation of the resource. Handy for\nsharing snippets that can then be imported with `sensuctl create`.", + Name: "toJSON", + Type: graphql1.NewNonNull(graphql.OutputType("JSON")), + }, + }, + Interfaces: []*graphql1.Interface{ + graphql.Interface("Node"), + graphql.Interface("Resource")}, + Name: "CoreV2ClusterRoleBinding", + } +} + +// describe CoreV2ClusterRoleBindingExtensionOverrides's configuration; kept private to avoid unintentional tampering of configuration at runtime. +var _ObjectExtensionTypeCoreV2ClusterRoleBindingExtensionOverridesDesc = graphql.ObjectDesc{ + Config: _ObjectExtensionTypeCoreV2ClusterRoleBindingExtensionOverridesConfigFn, + FieldHandlers: map[string]graphql.FieldHandler{ + "id": _ObjTypeCoreV2ClusterRoleBindingExtensionOverridesIDHandler, + "metadata": _ObjTypeCoreV2ClusterRoleBindingExtensionOverridesMetadataHandler, + "toJSON": _ObjTypeCoreV2ClusterRoleBindingExtensionOverridesToJSONHandler, }, } diff --git a/backend/apid/graphql/schema/corev2.graphql b/backend/apid/graphql/schema/corev2.graphql index bc05a3559c..110addb22e 100644 --- a/backend/apid/graphql/schema/corev2.graphql +++ b/backend/apid/graphql/schema/corev2.graphql @@ -6,8 +6,13 @@ extend type CoreV2Pipeline implements Node & Resource @named(suffix: "Overrides "Unique global identifier used to reference resource." id: ID! +<<<<<<< HEAD # "metadata contains name, namespace, labels and annotations of the record" # metadata: ObjectMeta +======= + "metadata contains name, namespace, labels and annotations of the record" + metadata: ObjectMeta +>>>>>>> db767b05 (leverage code generator more) """ toJSON returns a REST API compatible representation of the resource. Handy for @@ -24,8 +29,13 @@ extend type CoreV2Role implements Node & Resource @named(suffix: "Overrides") { "The globally unique identifier of the record" id: ID! +<<<<<<< HEAD # "metadata contains name, namespace, labels and annotations of the record" # metadata: ObjectMeta +======= + "metadata contains name, namespace, labels and annotations of the record" + metadata: ObjectMeta +>>>>>>> db767b05 (leverage code generator more) """ toJSON returns a REST API compatible representation of the resource. Handy for From 6211bd46acb8fb5b1d77d73714c500035eb2186a Mon Sep 17 00:00:00 2001 From: James Phillips Date: Thu, 7 Jul 2022 18:01:00 -0700 Subject: [PATCH 07/35] rollback metadata change.. for now Signed-off-by: James Phillips --- backend/apid/graphql/schema/corev2.gql.go | 120 ++------------------- backend/apid/graphql/schema/corev2.graphql | 10 -- 2 files changed, 10 insertions(+), 120 deletions(-) diff --git a/backend/apid/graphql/schema/corev2.gql.go b/backend/apid/graphql/schema/corev2.gql.go index 181d32a1d8..41e41574b2 100644 --- a/backend/apid/graphql/schema/corev2.gql.go +++ b/backend/apid/graphql/schema/corev2.gql.go @@ -14,9 +14,6 @@ type CoreV2PipelineExtensionOverridesFieldResolvers interface { // ID implements response to request for 'id' field. ID(p graphql.ResolveParams) (string, error) - // Metadata implements response to request for 'metadata' field. - Metadata(p graphql.ResolveParams) (interface{}, error) - // ToJSON implements response to request for 'toJSON' field. ToJSON(p graphql.ResolveParams) (interface{}, error) } @@ -35,15 +32,6 @@ func _ObjTypeCoreV2PipelineExtensionOverridesIDHandler(impl interface{}) graphql } } -func _ObjTypeCoreV2PipelineExtensionOverridesMetadataHandler(impl interface{}) graphql1.FieldResolveFn { - resolver := impl.(interface { - Metadata(p graphql.ResolveParams) (interface{}, error) - }) - return func(frp graphql1.ResolveParams) (interface{}, error) { - return resolver.Metadata(frp) - } -} - func _ObjTypeCoreV2PipelineExtensionOverridesToJSONHandler(impl interface{}) graphql1.FieldResolveFn { resolver := impl.(interface { ToJSON(p graphql.ResolveParams) (interface{}, error) @@ -64,13 +52,6 @@ func _ObjectExtensionTypeCoreV2PipelineExtensionOverridesConfigFn() graphql1.Obj Name: "id", Type: graphql1.NewNonNull(graphql1.ID), }, - "metadata": &graphql1.Field{ - Args: graphql1.FieldConfigArgument{}, - DeprecationReason: "", - Description: "metadata contains name, namespace, labels and annotations of the record", - Name: "metadata", - Type: graphql.OutputType("ObjectMeta"), - }, "toJSON": &graphql1.Field{ Args: graphql1.FieldConfigArgument{}, DeprecationReason: "", @@ -90,9 +71,8 @@ func _ObjectExtensionTypeCoreV2PipelineExtensionOverridesConfigFn() graphql1.Obj var _ObjectExtensionTypeCoreV2PipelineExtensionOverridesDesc = graphql.ObjectDesc{ Config: _ObjectExtensionTypeCoreV2PipelineExtensionOverridesConfigFn, FieldHandlers: map[string]graphql.FieldHandler{ - "id": _ObjTypeCoreV2PipelineExtensionOverridesIDHandler, - "metadata": _ObjTypeCoreV2PipelineExtensionOverridesMetadataHandler, - "toJSON": _ObjTypeCoreV2PipelineExtensionOverridesToJSONHandler, + "id": _ObjTypeCoreV2PipelineExtensionOverridesIDHandler, + "toJSON": _ObjTypeCoreV2PipelineExtensionOverridesToJSONHandler, }, } @@ -103,9 +83,6 @@ type CoreV2RoleExtensionOverridesFieldResolvers interface { // ID implements response to request for 'id' field. ID(p graphql.ResolveParams) (string, error) - // Metadata implements response to request for 'metadata' field. - Metadata(p graphql.ResolveParams) (interface{}, error) - // ToJSON implements response to request for 'toJSON' field. ToJSON(p graphql.ResolveParams) (interface{}, error) } @@ -124,15 +101,6 @@ func _ObjTypeCoreV2RoleExtensionOverridesIDHandler(impl interface{}) graphql1.Fi } } -func _ObjTypeCoreV2RoleExtensionOverridesMetadataHandler(impl interface{}) graphql1.FieldResolveFn { - resolver := impl.(interface { - Metadata(p graphql.ResolveParams) (interface{}, error) - }) - return func(frp graphql1.ResolveParams) (interface{}, error) { - return resolver.Metadata(frp) - } -} - func _ObjTypeCoreV2RoleExtensionOverridesToJSONHandler(impl interface{}) graphql1.FieldResolveFn { resolver := impl.(interface { ToJSON(p graphql.ResolveParams) (interface{}, error) @@ -153,13 +121,6 @@ func _ObjectExtensionTypeCoreV2RoleExtensionOverridesConfigFn() graphql1.ObjectC Name: "id", Type: graphql1.NewNonNull(graphql1.ID), }, - "metadata": &graphql1.Field{ - Args: graphql1.FieldConfigArgument{}, - DeprecationReason: "", - Description: "metadata contains name, namespace, labels and annotations of the record", - Name: "metadata", - Type: graphql.OutputType("ObjectMeta"), - }, "toJSON": &graphql1.Field{ Args: graphql1.FieldConfigArgument{}, DeprecationReason: "", @@ -179,9 +140,8 @@ func _ObjectExtensionTypeCoreV2RoleExtensionOverridesConfigFn() graphql1.ObjectC var _ObjectExtensionTypeCoreV2RoleExtensionOverridesDesc = graphql.ObjectDesc{ Config: _ObjectExtensionTypeCoreV2RoleExtensionOverridesConfigFn, FieldHandlers: map[string]graphql.FieldHandler{ - "id": _ObjTypeCoreV2RoleExtensionOverridesIDHandler, - "metadata": _ObjTypeCoreV2RoleExtensionOverridesMetadataHandler, - "toJSON": _ObjTypeCoreV2RoleExtensionOverridesToJSONHandler, + "id": _ObjTypeCoreV2RoleExtensionOverridesIDHandler, + "toJSON": _ObjTypeCoreV2RoleExtensionOverridesToJSONHandler, }, } @@ -192,9 +152,6 @@ type CoreV2RoleBindingExtensionOverridesFieldResolvers interface { // ID implements response to request for 'id' field. ID(p graphql.ResolveParams) (string, error) - // Metadata implements response to request for 'metadata' field. - Metadata(p graphql.ResolveParams) (interface{}, error) - // ToJSON implements response to request for 'toJSON' field. ToJSON(p graphql.ResolveParams) (interface{}, error) } @@ -213,15 +170,6 @@ func _ObjTypeCoreV2RoleBindingExtensionOverridesIDHandler(impl interface{}) grap } } -func _ObjTypeCoreV2RoleBindingExtensionOverridesMetadataHandler(impl interface{}) graphql1.FieldResolveFn { - resolver := impl.(interface { - Metadata(p graphql.ResolveParams) (interface{}, error) - }) - return func(frp graphql1.ResolveParams) (interface{}, error) { - return resolver.Metadata(frp) - } -} - func _ObjTypeCoreV2RoleBindingExtensionOverridesToJSONHandler(impl interface{}) graphql1.FieldResolveFn { resolver := impl.(interface { ToJSON(p graphql.ResolveParams) (interface{}, error) @@ -242,13 +190,6 @@ func _ObjectExtensionTypeCoreV2RoleBindingExtensionOverridesConfigFn() graphql1. Name: "id", Type: graphql1.NewNonNull(graphql1.ID), }, - "metadata": &graphql1.Field{ - Args: graphql1.FieldConfigArgument{}, - DeprecationReason: "", - Description: "metadata contains name, namespace, labels and annotations of the record", - Name: "metadata", - Type: graphql.OutputType("ObjectMeta"), - }, "toJSON": &graphql1.Field{ Args: graphql1.FieldConfigArgument{}, DeprecationReason: "", @@ -268,9 +209,8 @@ func _ObjectExtensionTypeCoreV2RoleBindingExtensionOverridesConfigFn() graphql1. var _ObjectExtensionTypeCoreV2RoleBindingExtensionOverridesDesc = graphql.ObjectDesc{ Config: _ObjectExtensionTypeCoreV2RoleBindingExtensionOverridesConfigFn, FieldHandlers: map[string]graphql.FieldHandler{ - "id": _ObjTypeCoreV2RoleBindingExtensionOverridesIDHandler, - "metadata": _ObjTypeCoreV2RoleBindingExtensionOverridesMetadataHandler, - "toJSON": _ObjTypeCoreV2RoleBindingExtensionOverridesToJSONHandler, + "id": _ObjTypeCoreV2RoleBindingExtensionOverridesIDHandler, + "toJSON": _ObjTypeCoreV2RoleBindingExtensionOverridesToJSONHandler, }, } @@ -281,9 +221,6 @@ type CoreV2ClusterRoleExtensionOverridesFieldResolvers interface { // ID implements response to request for 'id' field. ID(p graphql.ResolveParams) (string, error) - // Metadata implements response to request for 'metadata' field. - Metadata(p graphql.ResolveParams) (interface{}, error) - // ToJSON implements response to request for 'toJSON' field. ToJSON(p graphql.ResolveParams) (interface{}, error) } @@ -302,15 +239,6 @@ func _ObjTypeCoreV2ClusterRoleExtensionOverridesIDHandler(impl interface{}) grap } } -func _ObjTypeCoreV2ClusterRoleExtensionOverridesMetadataHandler(impl interface{}) graphql1.FieldResolveFn { - resolver := impl.(interface { - Metadata(p graphql.ResolveParams) (interface{}, error) - }) - return func(frp graphql1.ResolveParams) (interface{}, error) { - return resolver.Metadata(frp) - } -} - func _ObjTypeCoreV2ClusterRoleExtensionOverridesToJSONHandler(impl interface{}) graphql1.FieldResolveFn { resolver := impl.(interface { ToJSON(p graphql.ResolveParams) (interface{}, error) @@ -331,13 +259,6 @@ func _ObjectExtensionTypeCoreV2ClusterRoleExtensionOverridesConfigFn() graphql1. Name: "id", Type: graphql1.NewNonNull(graphql1.ID), }, - "metadata": &graphql1.Field{ - Args: graphql1.FieldConfigArgument{}, - DeprecationReason: "", - Description: "metadata contains name, namespace, labels and annotations of the record", - Name: "metadata", - Type: graphql.OutputType("ObjectMeta"), - }, "toJSON": &graphql1.Field{ Args: graphql1.FieldConfigArgument{}, DeprecationReason: "", @@ -357,9 +278,8 @@ func _ObjectExtensionTypeCoreV2ClusterRoleExtensionOverridesConfigFn() graphql1. var _ObjectExtensionTypeCoreV2ClusterRoleExtensionOverridesDesc = graphql.ObjectDesc{ Config: _ObjectExtensionTypeCoreV2ClusterRoleExtensionOverridesConfigFn, FieldHandlers: map[string]graphql.FieldHandler{ - "id": _ObjTypeCoreV2ClusterRoleExtensionOverridesIDHandler, - "metadata": _ObjTypeCoreV2ClusterRoleExtensionOverridesMetadataHandler, - "toJSON": _ObjTypeCoreV2ClusterRoleExtensionOverridesToJSONHandler, + "id": _ObjTypeCoreV2ClusterRoleExtensionOverridesIDHandler, + "toJSON": _ObjTypeCoreV2ClusterRoleExtensionOverridesToJSONHandler, }, } @@ -370,9 +290,6 @@ type CoreV2ClusterRoleBindingExtensionOverridesFieldResolvers interface { // ID implements response to request for 'id' field. ID(p graphql.ResolveParams) (string, error) - // Metadata implements response to request for 'metadata' field. - Metadata(p graphql.ResolveParams) (interface{}, error) - // ToJSON implements response to request for 'toJSON' field. ToJSON(p graphql.ResolveParams) (interface{}, error) } @@ -391,15 +308,6 @@ func _ObjTypeCoreV2ClusterRoleBindingExtensionOverridesIDHandler(impl interface{ } } -func _ObjTypeCoreV2ClusterRoleBindingExtensionOverridesMetadataHandler(impl interface{}) graphql1.FieldResolveFn { - resolver := impl.(interface { - Metadata(p graphql.ResolveParams) (interface{}, error) - }) - return func(frp graphql1.ResolveParams) (interface{}, error) { - return resolver.Metadata(frp) - } -} - func _ObjTypeCoreV2ClusterRoleBindingExtensionOverridesToJSONHandler(impl interface{}) graphql1.FieldResolveFn { resolver := impl.(interface { ToJSON(p graphql.ResolveParams) (interface{}, error) @@ -420,13 +328,6 @@ func _ObjectExtensionTypeCoreV2ClusterRoleBindingExtensionOverridesConfigFn() gr Name: "id", Type: graphql1.NewNonNull(graphql1.ID), }, - "metadata": &graphql1.Field{ - Args: graphql1.FieldConfigArgument{}, - DeprecationReason: "", - Description: "metadata contains name, namespace, labels and annotations of the record", - Name: "metadata", - Type: graphql.OutputType("ObjectMeta"), - }, "toJSON": &graphql1.Field{ Args: graphql1.FieldConfigArgument{}, DeprecationReason: "", @@ -446,9 +347,8 @@ func _ObjectExtensionTypeCoreV2ClusterRoleBindingExtensionOverridesConfigFn() gr var _ObjectExtensionTypeCoreV2ClusterRoleBindingExtensionOverridesDesc = graphql.ObjectDesc{ Config: _ObjectExtensionTypeCoreV2ClusterRoleBindingExtensionOverridesConfigFn, FieldHandlers: map[string]graphql.FieldHandler{ - "id": _ObjTypeCoreV2ClusterRoleBindingExtensionOverridesIDHandler, - "metadata": _ObjTypeCoreV2ClusterRoleBindingExtensionOverridesMetadataHandler, - "toJSON": _ObjTypeCoreV2ClusterRoleBindingExtensionOverridesToJSONHandler, + "id": _ObjTypeCoreV2ClusterRoleBindingExtensionOverridesIDHandler, + "toJSON": _ObjTypeCoreV2ClusterRoleBindingExtensionOverridesToJSONHandler, }, } diff --git a/backend/apid/graphql/schema/corev2.graphql b/backend/apid/graphql/schema/corev2.graphql index 110addb22e..bc05a3559c 100644 --- a/backend/apid/graphql/schema/corev2.graphql +++ b/backend/apid/graphql/schema/corev2.graphql @@ -6,13 +6,8 @@ extend type CoreV2Pipeline implements Node & Resource @named(suffix: "Overrides "Unique global identifier used to reference resource." id: ID! -<<<<<<< HEAD # "metadata contains name, namespace, labels and annotations of the record" # metadata: ObjectMeta -======= - "metadata contains name, namespace, labels and annotations of the record" - metadata: ObjectMeta ->>>>>>> db767b05 (leverage code generator more) """ toJSON returns a REST API compatible representation of the resource. Handy for @@ -29,13 +24,8 @@ extend type CoreV2Role implements Node & Resource @named(suffix: "Overrides") { "The globally unique identifier of the record" id: ID! -<<<<<<< HEAD # "metadata contains name, namespace, labels and annotations of the record" # metadata: ObjectMeta -======= - "metadata contains name, namespace, labels and annotations of the record" - metadata: ObjectMeta ->>>>>>> db767b05 (leverage code generator more) """ toJSON returns a REST API compatible representation of the resource. Handy for From d31c3f05c554022a93e73ee47259d746d83d972a Mon Sep 17 00:00:00 2001 From: James Phillips Date: Tue, 19 Jul 2022 22:37:42 -0700 Subject: [PATCH 08/35] abandoned prototype Signed-off-by: James Phillips From a429b3591ec130389bab9487df7aec97499592b3 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 20 Jul 2022 13:44:23 -0700 Subject: [PATCH 09/35] query entity config & state Signed-off-by: James Phillips --- backend/apid/graphql/corev3.go | 78 ++ backend/apid/graphql/schema/corev2.gen.gql.go | 1061 +++++++++++++---- .../apid/graphql/schema/corev2.gen.graphql | 98 +- backend/apid/graphql/schema/corev3.gen.gql.go | 467 ++++++++ .../apid/graphql/schema/corev3.gen.graphql | 79 ++ backend/apid/graphql/schema/corev3.gql.go | 186 +++ backend/apid/graphql/schema/corev3.graphql | 31 + backend/apid/graphql/schema/schema_gen.go | 3 +- backend/apid/graphql/service.go | 7 + 9 files changed, 1744 insertions(+), 266 deletions(-) create mode 100644 backend/apid/graphql/corev3.go create mode 100644 backend/apid/graphql/schema/corev3.gen.gql.go create mode 100644 backend/apid/graphql/schema/corev3.gen.graphql create mode 100644 backend/apid/graphql/schema/corev3.gql.go create mode 100644 backend/apid/graphql/schema/corev3.graphql diff --git a/backend/apid/graphql/corev3.go b/backend/apid/graphql/corev3.go new file mode 100644 index 0000000000..0db60085e7 --- /dev/null +++ b/backend/apid/graphql/corev3.go @@ -0,0 +1,78 @@ +package graphql + +import ( + "errors" + + corev3 "github.com/sensu/sensu-go/api/core/v3" + "github.com/sensu/sensu-go/backend/apid/graphql/globalid" + "github.com/sensu/sensu-go/backend/apid/graphql/schema" + "github.com/sensu/sensu-go/backend/store" + "github.com/sensu/sensu-go/graphql" + "github.com/sensu/sensu-go/types" +) + +type corev3EntityConfigImpl struct { + schema.CoreV3EntityConfigAliases + client GenericClient +} + +// ID implements response to request for 'id' field. +func (i *corev3EntityConfigImpl) ID(p graphql.ResolveParams) (string, error) { + return globalid.PipelineTranslator.EncodeToString(p.Context, p.Source), nil +} + +// ToJSON implements response to request for 'toJSON' field. +func (i *corev3EntityConfigImpl) ToJSON(p graphql.ResolveParams) (interface{}, error) { + return types.WrapResource(p.Source.(types.Resource)), nil +} + +// State implements response to request for 'state' field. +func (i *corev3EntityConfigImpl) State(p graphql.ResolveParams) (interface{}, error) { + cfg := p.Source.(*corev3.EntityConfig) + ctx := contextWithNamespace(p.Context, cfg.Metadata.Name) + val := &corev3.V2ResourceProxy{Resource: &corev3.EntityState{}} + err := i.client.Get(ctx, cfg.Metadata.Name, val) + if errors.Is(err, &store.ErrNotFound{}) { + return nil, nil + } + return val.Resource, err +} + +// IsTypeOf is used to determine if a given value is associated with the type +func (i *corev3EntityConfigImpl) IsTypeOf(s interface{}, p graphql.IsTypeOfParams) bool { + _, ok := s.(*corev3.EntityConfig) + return ok +} + +type corev3EntityStateImpl struct { + schema.CoreV3EntityStateAliases + client GenericClient +} + +// ID implements response to request for 'id' field. +func (*corev3EntityStateImpl) ID(p graphql.ResolveParams) (string, error) { + return globalid.PipelineTranslator.EncodeToString(p.Context, p.Source), nil +} + +// ToJSON implements response to request for 'toJSON' field. +func (*corev3EntityStateImpl) ToJSON(p graphql.ResolveParams) (interface{}, error) { + return types.WrapResource(p.Source.(types.Resource)), nil +} + +// IsTypeOf is used to determine if a given value is associated with the type +func (*corev3EntityStateImpl) IsTypeOf(s interface{}, p graphql.IsTypeOfParams) bool { + _, ok := s.(*corev3.EntityState) + return ok +} + +// State implements response to request for 'state' field. +func (i *corev3EntityStateImpl) Config(p graphql.ResolveParams) (interface{}, error) { + state := p.Source.(*corev3.EntityState) + ctx := contextWithNamespace(p.Context, state.Metadata.Name) + val := &corev3.V2ResourceProxy{Resource: &corev3.EntityState{}} + err := i.client.Get(ctx, state.Metadata.Name, val) + if errors.Is(err, &store.ErrNotFound{}) { + return nil, nil + } + return val.Resource, err +} diff --git a/backend/apid/graphql/schema/corev2.gen.gql.go b/backend/apid/graphql/schema/corev2.gen.gql.go index 76486e2775..621006e7b1 100644 --- a/backend/apid/graphql/schema/corev2.gen.gql.go +++ b/backend/apid/graphql/schema/corev2.gen.gql.go @@ -398,6 +398,292 @@ var _ObjectTypeCoreV2ClusterRoleBindingDesc = graphql.ObjectDesc{ }, } +// +// CoreV2DeregistrationFieldResolvers represents a collection of methods whose products represent the +// response values of the 'CoreV2Deregistration' type. +type CoreV2DeregistrationFieldResolvers interface { + // Handler implements response to request for 'handler' field. + Handler(p graphql.ResolveParams) (string, error) +} + +// CoreV2DeregistrationAliases implements all methods on CoreV2DeregistrationFieldResolvers interface by using reflection to +// match name of field to a field on the given value. Intent is reduce friction +// of writing new resolvers by removing all the instances where you would simply +// have the resolvers method return a field. +type CoreV2DeregistrationAliases struct{} + +// Handler implements response to request for 'handler' field. +func (_ CoreV2DeregistrationAliases) Handler(p graphql.ResolveParams) (string, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.(string) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'handler'") + } + return ret, err +} + +// CoreV2DeregistrationType Deregistration contains configuration for Sensu entity de-registration. +var CoreV2DeregistrationType = graphql.NewType("CoreV2Deregistration", graphql.ObjectKind) + +// RegisterCoreV2Deregistration registers CoreV2Deregistration object type with given service. +func RegisterCoreV2Deregistration(svc *graphql.Service, impl CoreV2DeregistrationFieldResolvers) { + svc.RegisterObject(_ObjectTypeCoreV2DeregistrationDesc, impl) +} +func _ObjTypeCoreV2DeregistrationHandlerHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Handler(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Handler(frp) + } +} + +func _ObjectTypeCoreV2DeregistrationConfigFn() graphql1.ObjectConfig { + return graphql1.ObjectConfig{ + Description: "Deregistration contains configuration for Sensu entity de-registration.", + Fields: graphql1.Fields{"handler": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "self descriptive", + Name: "handler", + Type: graphql1.NewNonNull(graphql1.String), + }}, + Interfaces: []*graphql1.Interface{}, + IsTypeOf: func(_ graphql1.IsTypeOfParams) bool { + // NOTE: + // Panic by default. Intent is that when Service is invoked, values of + // these fields are updated with instantiated resolvers. If these + // defaults are called it is most certainly programmer err. + // If you're see this comment then: 'Whoops! Sorry, my bad.' + panic("Unimplemented; see CoreV2DeregistrationFieldResolvers.") + }, + Name: "CoreV2Deregistration", + } +} + +// describe CoreV2Deregistration's configuration; kept private to avoid unintentional tampering of configuration at runtime. +var _ObjectTypeCoreV2DeregistrationDesc = graphql.ObjectDesc{ + Config: _ObjectTypeCoreV2DeregistrationConfigFn, + FieldHandlers: map[string]graphql.FieldHandler{"handler": _ObjTypeCoreV2DeregistrationHandlerHandler}, +} + +// +// CoreV2NetworkFieldResolvers represents a collection of methods whose products represent the +// response values of the 'CoreV2Network' type. +type CoreV2NetworkFieldResolvers interface { + // Interfaces implements response to request for 'interfaces' field. + Interfaces(p graphql.ResolveParams) (interface{}, error) +} + +// CoreV2NetworkAliases implements all methods on CoreV2NetworkFieldResolvers interface by using reflection to +// match name of field to a field on the given value. Intent is reduce friction +// of writing new resolvers by removing all the instances where you would simply +// have the resolvers method return a field. +type CoreV2NetworkAliases struct{} + +// Interfaces implements response to request for 'interfaces' field. +func (_ CoreV2NetworkAliases) Interfaces(p graphql.ResolveParams) (interface{}, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + return val, err +} + +/* +CoreV2NetworkType Network contains information about the system network interfaces +that the Agent process is running on, used for additional Entity +context. +*/ +var CoreV2NetworkType = graphql.NewType("CoreV2Network", graphql.ObjectKind) + +// RegisterCoreV2Network registers CoreV2Network object type with given service. +func RegisterCoreV2Network(svc *graphql.Service, impl CoreV2NetworkFieldResolvers) { + svc.RegisterObject(_ObjectTypeCoreV2NetworkDesc, impl) +} +func _ObjTypeCoreV2NetworkInterfacesHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Interfaces(p graphql.ResolveParams) (interface{}, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Interfaces(frp) + } +} + +func _ObjectTypeCoreV2NetworkConfigFn() graphql1.ObjectConfig { + return graphql1.ObjectConfig{ + Description: "Network contains information about the system network interfaces\nthat the Agent process is running on, used for additional Entity\ncontext.", + Fields: graphql1.Fields{"interfaces": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "self descriptive", + Name: "interfaces", + Type: graphql1.NewNonNull(graphql1.NewList(graphql1.NewNonNull(graphql.OutputType("CoreV2NetworkInterface")))), + }}, + Interfaces: []*graphql1.Interface{}, + IsTypeOf: func(_ graphql1.IsTypeOfParams) bool { + // NOTE: + // Panic by default. Intent is that when Service is invoked, values of + // these fields are updated with instantiated resolvers. If these + // defaults are called it is most certainly programmer err. + // If you're see this comment then: 'Whoops! Sorry, my bad.' + panic("Unimplemented; see CoreV2NetworkFieldResolvers.") + }, + Name: "CoreV2Network", + } +} + +// describe CoreV2Network's configuration; kept private to avoid unintentional tampering of configuration at runtime. +var _ObjectTypeCoreV2NetworkDesc = graphql.ObjectDesc{ + Config: _ObjectTypeCoreV2NetworkConfigFn, + FieldHandlers: map[string]graphql.FieldHandler{"interfaces": _ObjTypeCoreV2NetworkInterfacesHandler}, +} + +// +// CoreV2NetworkInterfaceFieldResolvers represents a collection of methods whose products represent the +// response values of the 'CoreV2NetworkInterface' type. +type CoreV2NetworkInterfaceFieldResolvers interface { + // Name implements response to request for 'name' field. + Name(p graphql.ResolveParams) (string, error) + + // Mac implements response to request for 'mac' field. + Mac(p graphql.ResolveParams) (string, error) + + // Addresses implements response to request for 'addresses' field. + Addresses(p graphql.ResolveParams) ([]string, error) +} + +// CoreV2NetworkInterfaceAliases implements all methods on CoreV2NetworkInterfaceFieldResolvers interface by using reflection to +// match name of field to a field on the given value. Intent is reduce friction +// of writing new resolvers by removing all the instances where you would simply +// have the resolvers method return a field. +type CoreV2NetworkInterfaceAliases struct{} + +// Name implements response to request for 'name' field. +func (_ CoreV2NetworkInterfaceAliases) Name(p graphql.ResolveParams) (string, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.(string) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'name'") + } + return ret, err +} + +// Mac implements response to request for 'mac' field. +func (_ CoreV2NetworkInterfaceAliases) Mac(p graphql.ResolveParams) (string, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.(string) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'mac'") + } + return ret, err +} + +// Addresses implements response to request for 'addresses' field. +func (_ CoreV2NetworkInterfaceAliases) Addresses(p graphql.ResolveParams) ([]string, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.([]string) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'addresses'") + } + return ret, err +} + +/* +CoreV2NetworkInterfaceType NetworkInterface contains information about a system network +interface. +*/ +var CoreV2NetworkInterfaceType = graphql.NewType("CoreV2NetworkInterface", graphql.ObjectKind) + +// RegisterCoreV2NetworkInterface registers CoreV2NetworkInterface object type with given service. +func RegisterCoreV2NetworkInterface(svc *graphql.Service, impl CoreV2NetworkInterfaceFieldResolvers) { + svc.RegisterObject(_ObjectTypeCoreV2NetworkInterfaceDesc, impl) +} +func _ObjTypeCoreV2NetworkInterfaceNameHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Name(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Name(frp) + } +} + +func _ObjTypeCoreV2NetworkInterfaceMacHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Mac(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Mac(frp) + } +} + +func _ObjTypeCoreV2NetworkInterfaceAddressesHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Addresses(p graphql.ResolveParams) ([]string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Addresses(frp) + } +} + +func _ObjectTypeCoreV2NetworkInterfaceConfigFn() graphql1.ObjectConfig { + return graphql1.ObjectConfig{ + Description: "NetworkInterface contains information about a system network\ninterface.", + Fields: graphql1.Fields{ + "addresses": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "self descriptive", + Name: "addresses", + Type: graphql1.NewNonNull(graphql1.NewList(graphql1.NewNonNull(graphql1.String))), + }, + "mac": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "self descriptive", + Name: "mac", + Type: graphql1.NewNonNull(graphql1.String), + }, + "name": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "self descriptive", + Name: "name", + Type: graphql1.NewNonNull(graphql1.String), + }, + }, + Interfaces: []*graphql1.Interface{}, + IsTypeOf: func(_ graphql1.IsTypeOfParams) bool { + // NOTE: + // Panic by default. Intent is that when Service is invoked, values of + // these fields are updated with instantiated resolvers. If these + // defaults are called it is most certainly programmer err. + // If you're see this comment then: 'Whoops! Sorry, my bad.' + panic("Unimplemented; see CoreV2NetworkInterfaceFieldResolvers.") + }, + Name: "CoreV2NetworkInterface", + } +} + +// describe CoreV2NetworkInterface's configuration; kept private to avoid unintentional tampering of configuration at runtime. +var _ObjectTypeCoreV2NetworkInterfaceDesc = graphql.ObjectDesc{ + Config: _ObjectTypeCoreV2NetworkInterfaceConfigFn, + FieldHandlers: map[string]graphql.FieldHandler{ + "addresses": _ObjTypeCoreV2NetworkInterfaceAddressesHandler, + "mac": _ObjTypeCoreV2NetworkInterfaceMacHandler, + "name": _ObjTypeCoreV2NetworkInterfaceNameHandler, + }, +} + // // CoreV2PipelineFieldResolvers represents a collection of methods whose products represent the // response values of the 'CoreV2Pipeline' type. @@ -650,6 +936,78 @@ var _ObjectTypeCoreV2PipelineWorkflowDesc = graphql.ObjectDesc{ }, } +// +// CoreV2ProcessFieldResolvers represents a collection of methods whose products represent the +// response values of the 'CoreV2Process' type. +type CoreV2ProcessFieldResolvers interface { + // Name implements response to request for 'name' field. + Name(p graphql.ResolveParams) (string, error) +} + +// CoreV2ProcessAliases implements all methods on CoreV2ProcessFieldResolvers interface by using reflection to +// match name of field to a field on the given value. Intent is reduce friction +// of writing new resolvers by removing all the instances where you would simply +// have the resolvers method return a field. +type CoreV2ProcessAliases struct{} + +// Name implements response to request for 'name' field. +func (_ CoreV2ProcessAliases) Name(p graphql.ResolveParams) (string, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.(string) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'name'") + } + return ret, err +} + +// CoreV2ProcessType Process contains information about a local process. +var CoreV2ProcessType = graphql.NewType("CoreV2Process", graphql.ObjectKind) + +// RegisterCoreV2Process registers CoreV2Process object type with given service. +func RegisterCoreV2Process(svc *graphql.Service, impl CoreV2ProcessFieldResolvers) { + svc.RegisterObject(_ObjectTypeCoreV2ProcessDesc, impl) +} +func _ObjTypeCoreV2ProcessNameHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Name(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Name(frp) + } +} + +func _ObjectTypeCoreV2ProcessConfigFn() graphql1.ObjectConfig { + return graphql1.ObjectConfig{ + Description: "Process contains information about a local process.", + Fields: graphql1.Fields{"name": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "self descriptive", + Name: "name", + Type: graphql1.NewNonNull(graphql1.String), + }}, + Interfaces: []*graphql1.Interface{}, + IsTypeOf: func(_ graphql1.IsTypeOfParams) bool { + // NOTE: + // Panic by default. Intent is that when Service is invoked, values of + // these fields are updated with instantiated resolvers. If these + // defaults are called it is most certainly programmer err. + // If you're see this comment then: 'Whoops! Sorry, my bad.' + panic("Unimplemented; see CoreV2ProcessFieldResolvers.") + }, + Name: "CoreV2Process", + } +} + +// describe CoreV2Process's configuration; kept private to avoid unintentional tampering of configuration at runtime. +var _ObjectTypeCoreV2ProcessDesc = graphql.ObjectDesc{ + Config: _ObjectTypeCoreV2ProcessConfigFn, + FieldHandlers: map[string]graphql.FieldHandler{"name": _ObjTypeCoreV2ProcessNameHandler}, +} + // // CoreV2ResourceReferenceFieldResolvers represents a collection of methods whose products represent the // response values of the 'CoreV2ResourceReference' type. @@ -1012,89 +1370,89 @@ var _ObjectTypeCoreV2RoleBindingDesc = graphql.ObjectDesc{ } // -// CoreV2RoleRefFieldResolvers represents a collection of methods whose products represent the -// response values of the 'CoreV2RoleRef' type. -type CoreV2RoleRefFieldResolvers interface { - // Type implements response to request for 'type' field. - Type(p graphql.ResolveParams) (string, error) - +// CoreV2SecretFieldResolvers represents a collection of methods whose products represent the +// response values of the 'CoreV2Secret' type. +type CoreV2SecretFieldResolvers interface { // Name implements response to request for 'name' field. Name(p graphql.ResolveParams) (string, error) + + // Secret implements response to request for 'secret' field. + Secret(p graphql.ResolveParams) (string, error) } -// CoreV2RoleRefAliases implements all methods on CoreV2RoleRefFieldResolvers interface by using reflection to +// CoreV2SecretAliases implements all methods on CoreV2SecretFieldResolvers interface by using reflection to // match name of field to a field on the given value. Intent is reduce friction // of writing new resolvers by removing all the instances where you would simply // have the resolvers method return a field. -type CoreV2RoleRefAliases struct{} +type CoreV2SecretAliases struct{} -// Type implements response to request for 'type' field. -func (_ CoreV2RoleRefAliases) Type(p graphql.ResolveParams) (string, error) { +// Name implements response to request for 'name' field. +func (_ CoreV2SecretAliases) Name(p graphql.ResolveParams) (string, error) { val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) ret, ok := val.(string) if err != nil { return ret, err } if !ok { - return ret, errors.New("unable to coerce value for field 'type'") + return ret, errors.New("unable to coerce value for field 'name'") } return ret, err } -// Name implements response to request for 'name' field. -func (_ CoreV2RoleRefAliases) Name(p graphql.ResolveParams) (string, error) { +// Secret implements response to request for 'secret' field. +func (_ CoreV2SecretAliases) Secret(p graphql.ResolveParams) (string, error) { val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) ret, ok := val.(string) if err != nil { return ret, err } if !ok { - return ret, errors.New("unable to coerce value for field 'name'") + return ret, errors.New("unable to coerce value for field 'secret'") } return ret, err } -// CoreV2RoleRefType RoleRef maps groups to Roles or ClusterRoles. -var CoreV2RoleRefType = graphql.NewType("CoreV2RoleRef", graphql.ObjectKind) +// CoreV2SecretType A Secret is a secret specification. +var CoreV2SecretType = graphql.NewType("CoreV2Secret", graphql.ObjectKind) -// RegisterCoreV2RoleRef registers CoreV2RoleRef object type with given service. -func RegisterCoreV2RoleRef(svc *graphql.Service, impl CoreV2RoleRefFieldResolvers) { - svc.RegisterObject(_ObjectTypeCoreV2RoleRefDesc, impl) +// RegisterCoreV2Secret registers CoreV2Secret object type with given service. +func RegisterCoreV2Secret(svc *graphql.Service, impl CoreV2SecretFieldResolvers) { + svc.RegisterObject(_ObjectTypeCoreV2SecretDesc, impl) } -func _ObjTypeCoreV2RoleRefTypeHandler(impl interface{}) graphql1.FieldResolveFn { +func _ObjTypeCoreV2SecretNameHandler(impl interface{}) graphql1.FieldResolveFn { resolver := impl.(interface { - Type(p graphql.ResolveParams) (string, error) + Name(p graphql.ResolveParams) (string, error) }) return func(frp graphql1.ResolveParams) (interface{}, error) { - return resolver.Type(frp) + return resolver.Name(frp) } } -func _ObjTypeCoreV2RoleRefNameHandler(impl interface{}) graphql1.FieldResolveFn { +func _ObjTypeCoreV2SecretSecretHandler(impl interface{}) graphql1.FieldResolveFn { resolver := impl.(interface { - Name(p graphql.ResolveParams) (string, error) + Secret(p graphql.ResolveParams) (string, error) }) return func(frp graphql1.ResolveParams) (interface{}, error) { - return resolver.Name(frp) + return resolver.Secret(frp) } } -func _ObjectTypeCoreV2RoleRefConfigFn() graphql1.ObjectConfig { +func _ObjectTypeCoreV2SecretConfigFn() graphql1.ObjectConfig { return graphql1.ObjectConfig{ - Description: "RoleRef maps groups to Roles or ClusterRoles.", + Description: "A Secret is a secret specification.", Fields: graphql1.Fields{ "name": &graphql1.Field{ Args: graphql1.FieldConfigArgument{}, DeprecationReason: "", - Description: "Name of the resource being referenced", + Description: "Name is the name of the secret referenced in an executable command.", Name: "name", Type: graphql1.NewNonNull(graphql1.String), }, - "type": &graphql1.Field{ + "secret": &graphql1.Field{ Args: graphql1.FieldConfigArgument{}, DeprecationReason: "", - Description: "Type of role being referenced.", - Name: "type", + Description: "Secret is the name of the Sensu secret resource.", + Name: "secret", Type: graphql1.NewNonNull(graphql1.String), }, }, @@ -1105,138 +1463,106 @@ func _ObjectTypeCoreV2RoleRefConfigFn() graphql1.ObjectConfig { // these fields are updated with instantiated resolvers. If these // defaults are called it is most certainly programmer err. // If you're see this comment then: 'Whoops! Sorry, my bad.' - panic("Unimplemented; see CoreV2RoleRefFieldResolvers.") + panic("Unimplemented; see CoreV2SecretFieldResolvers.") }, - Name: "CoreV2RoleRef", + Name: "CoreV2Secret", } } -// describe CoreV2RoleRef's configuration; kept private to avoid unintentional tampering of configuration at runtime. -var _ObjectTypeCoreV2RoleRefDesc = graphql.ObjectDesc{ - Config: _ObjectTypeCoreV2RoleRefConfigFn, +// describe CoreV2Secret's configuration; kept private to avoid unintentional tampering of configuration at runtime. +var _ObjectTypeCoreV2SecretDesc = graphql.ObjectDesc{ + Config: _ObjectTypeCoreV2SecretConfigFn, FieldHandlers: map[string]graphql.FieldHandler{ - "name": _ObjTypeCoreV2RoleRefNameHandler, - "type": _ObjTypeCoreV2RoleRefTypeHandler, + "name": _ObjTypeCoreV2SecretNameHandler, + "secret": _ObjTypeCoreV2SecretSecretHandler, }, } // -// CoreV2RuleFieldResolvers represents a collection of methods whose products represent the -// response values of the 'CoreV2Rule' type. -type CoreV2RuleFieldResolvers interface { - // Verbs implements response to request for 'verbs' field. - Verbs(p graphql.ResolveParams) ([]string, error) - - // Resources implements response to request for 'resources' field. - Resources(p graphql.ResolveParams) ([]string, error) +// CoreV2SubjectFieldResolvers represents a collection of methods whose products represent the +// response values of the 'CoreV2Subject' type. +type CoreV2SubjectFieldResolvers interface { + // Type implements response to request for 'type' field. + Type(p graphql.ResolveParams) (string, error) - // Resource_names implements response to request for 'resource_names' field. - Resource_names(p graphql.ResolveParams) ([]string, error) + // Name implements response to request for 'name' field. + Name(p graphql.ResolveParams) (string, error) } -// CoreV2RuleAliases implements all methods on CoreV2RuleFieldResolvers interface by using reflection to +// CoreV2SubjectAliases implements all methods on CoreV2SubjectFieldResolvers interface by using reflection to // match name of field to a field on the given value. Intent is reduce friction // of writing new resolvers by removing all the instances where you would simply // have the resolvers method return a field. -type CoreV2RuleAliases struct{} - -// Verbs implements response to request for 'verbs' field. -func (_ CoreV2RuleAliases) Verbs(p graphql.ResolveParams) ([]string, error) { - val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) - ret, ok := val.([]string) - if err != nil { - return ret, err - } - if !ok { - return ret, errors.New("unable to coerce value for field 'verbs'") - } - return ret, err -} +type CoreV2SubjectAliases struct{} -// Resources implements response to request for 'resources' field. -func (_ CoreV2RuleAliases) Resources(p graphql.ResolveParams) ([]string, error) { +// Type implements response to request for 'type' field. +func (_ CoreV2SubjectAliases) Type(p graphql.ResolveParams) (string, error) { val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) - ret, ok := val.([]string) + ret, ok := val.(string) if err != nil { return ret, err } if !ok { - return ret, errors.New("unable to coerce value for field 'resources'") + return ret, errors.New("unable to coerce value for field 'type'") } return ret, err } -// Resource_names implements response to request for 'resource_names' field. -func (_ CoreV2RuleAliases) Resource_names(p graphql.ResolveParams) ([]string, error) { +// Name implements response to request for 'name' field. +func (_ CoreV2SubjectAliases) Name(p graphql.ResolveParams) (string, error) { val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) - ret, ok := val.([]string) + ret, ok := val.(string) if err != nil { return ret, err } if !ok { - return ret, errors.New("unable to coerce value for field 'resource_names'") + return ret, errors.New("unable to coerce value for field 'name'") } return ret, err } -// CoreV2RuleType Rule holds information that describes an action that can be taken -var CoreV2RuleType = graphql.NewType("CoreV2Rule", graphql.ObjectKind) +// CoreV2SubjectType self descriptive +var CoreV2SubjectType = graphql.NewType("CoreV2Subject", graphql.ObjectKind) -// RegisterCoreV2Rule registers CoreV2Rule object type with given service. -func RegisterCoreV2Rule(svc *graphql.Service, impl CoreV2RuleFieldResolvers) { - svc.RegisterObject(_ObjectTypeCoreV2RuleDesc, impl) -} -func _ObjTypeCoreV2RuleVerbsHandler(impl interface{}) graphql1.FieldResolveFn { - resolver := impl.(interface { - Verbs(p graphql.ResolveParams) ([]string, error) - }) - return func(frp graphql1.ResolveParams) (interface{}, error) { - return resolver.Verbs(frp) - } +// RegisterCoreV2Subject registers CoreV2Subject object type with given service. +func RegisterCoreV2Subject(svc *graphql.Service, impl CoreV2SubjectFieldResolvers) { + svc.RegisterObject(_ObjectTypeCoreV2SubjectDesc, impl) } - -func _ObjTypeCoreV2RuleResourcesHandler(impl interface{}) graphql1.FieldResolveFn { +func _ObjTypeCoreV2SubjectTypeHandler(impl interface{}) graphql1.FieldResolveFn { resolver := impl.(interface { - Resources(p graphql.ResolveParams) ([]string, error) + Type(p graphql.ResolveParams) (string, error) }) return func(frp graphql1.ResolveParams) (interface{}, error) { - return resolver.Resources(frp) + return resolver.Type(frp) } } -func _ObjTypeCoreV2RuleResource_namesHandler(impl interface{}) graphql1.FieldResolveFn { +func _ObjTypeCoreV2SubjectNameHandler(impl interface{}) graphql1.FieldResolveFn { resolver := impl.(interface { - Resource_names(p graphql.ResolveParams) ([]string, error) + Name(p graphql.ResolveParams) (string, error) }) return func(frp graphql1.ResolveParams) (interface{}, error) { - return resolver.Resource_names(frp) + return resolver.Name(frp) } } -func _ObjectTypeCoreV2RuleConfigFn() graphql1.ObjectConfig { +func _ObjectTypeCoreV2SubjectConfigFn() graphql1.ObjectConfig { return graphql1.ObjectConfig{ - Description: "Rule holds information that describes an action that can be taken", + Description: "self descriptive", Fields: graphql1.Fields{ - "resource_names": &graphql1.Field{ - Args: graphql1.FieldConfigArgument{}, - DeprecationReason: "", - Description: "ResourceNames is an optional list of resource names that the rule applies\nto.", - Name: "resource_names", - Type: graphql1.NewNonNull(graphql1.NewList(graphql1.NewNonNull(graphql1.String))), - }, - "resources": &graphql1.Field{ + "name": &graphql1.Field{ Args: graphql1.FieldConfigArgument{}, DeprecationReason: "", - Description: "Resources is a list of resources that this rule applies to. \"*\"\nrepresents all resources.", - Name: "resources", - Type: graphql1.NewNonNull(graphql1.NewList(graphql1.NewNonNull(graphql1.String))), + Description: "Name of the referenced object", + Name: "name", + Type: graphql1.NewNonNull(graphql1.String), }, - "verbs": &graphql1.Field{ + "type": &graphql1.Field{ Args: graphql1.FieldConfigArgument{}, DeprecationReason: "", - Description: "Verbs is a list of verbs that apply to all of the listed resources for\nthis rule. These include \"get\", \"list\", \"watch\", \"create\", \"update\",\n\"delete\".\nTODO: add support for \"patch\" (this is expensive and should be delayed\nuntil a further release). TODO: add support for \"watch\" (via websockets)", - Name: "verbs", - Type: graphql1.NewNonNull(graphql1.NewList(graphql1.NewNonNull(graphql1.String))), + Description: "Type of object referenced (user or group)", + Name: "type", + Type: graphql1.NewNonNull(graphql1.String), }, }, Interfaces: []*graphql1.Interface{}, @@ -1246,215 +1572,478 @@ func _ObjectTypeCoreV2RuleConfigFn() graphql1.ObjectConfig { // these fields are updated with instantiated resolvers. If these // defaults are called it is most certainly programmer err. // If you're see this comment then: 'Whoops! Sorry, my bad.' - panic("Unimplemented; see CoreV2RuleFieldResolvers.") + panic("Unimplemented; see CoreV2SubjectFieldResolvers.") }, - Name: "CoreV2Rule", + Name: "CoreV2Subject", } } -// describe CoreV2Rule's configuration; kept private to avoid unintentional tampering of configuration at runtime. -var _ObjectTypeCoreV2RuleDesc = graphql.ObjectDesc{ - Config: _ObjectTypeCoreV2RuleConfigFn, +// describe CoreV2Subject's configuration; kept private to avoid unintentional tampering of configuration at runtime. +var _ObjectTypeCoreV2SubjectDesc = graphql.ObjectDesc{ + Config: _ObjectTypeCoreV2SubjectConfigFn, FieldHandlers: map[string]graphql.FieldHandler{ - "resource_names": _ObjTypeCoreV2RuleResource_namesHandler, - "resources": _ObjTypeCoreV2RuleResourcesHandler, - "verbs": _ObjTypeCoreV2RuleVerbsHandler, + "name": _ObjTypeCoreV2SubjectNameHandler, + "type": _ObjTypeCoreV2SubjectTypeHandler, }, } // -// CoreV2SecretFieldResolvers represents a collection of methods whose products represent the -// response values of the 'CoreV2Secret' type. -type CoreV2SecretFieldResolvers interface { - // Name implements response to request for 'name' field. - Name(p graphql.ResolveParams) (string, error) +// CoreV2SystemFieldResolvers represents a collection of methods whose products represent the +// response values of the 'CoreV2System' type. +type CoreV2SystemFieldResolvers interface { + // Hostname implements response to request for 'hostname' field. + Hostname(p graphql.ResolveParams) (string, error) - // Secret implements response to request for 'secret' field. - Secret(p graphql.ResolveParams) (string, error) + // Os implements response to request for 'os' field. + Os(p graphql.ResolveParams) (string, error) + + // Platform implements response to request for 'platform' field. + Platform(p graphql.ResolveParams) (string, error) + + // Platform_family implements response to request for 'platform_family' field. + Platform_family(p graphql.ResolveParams) (string, error) + + // Platform_version implements response to request for 'platform_version' field. + Platform_version(p graphql.ResolveParams) (string, error) + + // Network implements response to request for 'network' field. + Network(p graphql.ResolveParams) (interface{}, error) + + // Arch implements response to request for 'arch' field. + Arch(p graphql.ResolveParams) (string, error) + + // Arm_version implements response to request for 'arm_version' field. + Arm_version(p graphql.ResolveParams) (int, error) + + // Libc_type implements response to request for 'libc_type' field. + Libc_type(p graphql.ResolveParams) (string, error) + + // Vm_system implements response to request for 'vm_system' field. + Vm_system(p graphql.ResolveParams) (string, error) + + // Vm_role implements response to request for 'vm_role' field. + Vm_role(p graphql.ResolveParams) (string, error) + + // Cloud_provider implements response to request for 'cloud_provider' field. + Cloud_provider(p graphql.ResolveParams) (string, error) + + // Float_type implements response to request for 'float_type' field. + Float_type(p graphql.ResolveParams) (string, error) + + // Processes implements response to request for 'processes' field. + Processes(p graphql.ResolveParams) (interface{}, error) } -// CoreV2SecretAliases implements all methods on CoreV2SecretFieldResolvers interface by using reflection to +// CoreV2SystemAliases implements all methods on CoreV2SystemFieldResolvers interface by using reflection to // match name of field to a field on the given value. Intent is reduce friction // of writing new resolvers by removing all the instances where you would simply // have the resolvers method return a field. -type CoreV2SecretAliases struct{} +type CoreV2SystemAliases struct{} -// Name implements response to request for 'name' field. -func (_ CoreV2SecretAliases) Name(p graphql.ResolveParams) (string, error) { +// Hostname implements response to request for 'hostname' field. +func (_ CoreV2SystemAliases) Hostname(p graphql.ResolveParams) (string, error) { val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) ret, ok := val.(string) if err != nil { return ret, err } if !ok { - return ret, errors.New("unable to coerce value for field 'name'") + return ret, errors.New("unable to coerce value for field 'hostname'") } return ret, err } -// Secret implements response to request for 'secret' field. -func (_ CoreV2SecretAliases) Secret(p graphql.ResolveParams) (string, error) { +// Os implements response to request for 'os' field. +func (_ CoreV2SystemAliases) Os(p graphql.ResolveParams) (string, error) { val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) ret, ok := val.(string) if err != nil { return ret, err } if !ok { - return ret, errors.New("unable to coerce value for field 'secret'") + return ret, errors.New("unable to coerce value for field 'os'") } return ret, err } -// CoreV2SecretType A Secret is a secret specification. -var CoreV2SecretType = graphql.NewType("CoreV2Secret", graphql.ObjectKind) - -// RegisterCoreV2Secret registers CoreV2Secret object type with given service. -func RegisterCoreV2Secret(svc *graphql.Service, impl CoreV2SecretFieldResolvers) { - svc.RegisterObject(_ObjectTypeCoreV2SecretDesc, impl) +// Platform implements response to request for 'platform' field. +func (_ CoreV2SystemAliases) Platform(p graphql.ResolveParams) (string, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.(string) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'platform'") + } + return ret, err } -func _ObjTypeCoreV2SecretNameHandler(impl interface{}) graphql1.FieldResolveFn { - resolver := impl.(interface { - Name(p graphql.ResolveParams) (string, error) - }) - return func(frp graphql1.ResolveParams) (interface{}, error) { - return resolver.Name(frp) + +// Platform_family implements response to request for 'platform_family' field. +func (_ CoreV2SystemAliases) Platform_family(p graphql.ResolveParams) (string, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.(string) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'platform_family'") } + return ret, err } -func _ObjTypeCoreV2SecretSecretHandler(impl interface{}) graphql1.FieldResolveFn { - resolver := impl.(interface { - Secret(p graphql.ResolveParams) (string, error) - }) - return func(frp graphql1.ResolveParams) (interface{}, error) { - return resolver.Secret(frp) +// Platform_version implements response to request for 'platform_version' field. +func (_ CoreV2SystemAliases) Platform_version(p graphql.ResolveParams) (string, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.(string) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'platform_version'") } + return ret, err } -func _ObjectTypeCoreV2SecretConfigFn() graphql1.ObjectConfig { - return graphql1.ObjectConfig{ - Description: "A Secret is a secret specification.", - Fields: graphql1.Fields{ - "name": &graphql1.Field{ - Args: graphql1.FieldConfigArgument{}, - DeprecationReason: "", - Description: "Name is the name of the secret referenced in an executable command.", - Name: "name", - Type: graphql1.NewNonNull(graphql1.String), - }, - "secret": &graphql1.Field{ - Args: graphql1.FieldConfigArgument{}, - DeprecationReason: "", - Description: "Secret is the name of the Sensu secret resource.", - Name: "secret", - Type: graphql1.NewNonNull(graphql1.String), - }, - }, - Interfaces: []*graphql1.Interface{}, - IsTypeOf: func(_ graphql1.IsTypeOfParams) bool { - // NOTE: - // Panic by default. Intent is that when Service is invoked, values of - // these fields are updated with instantiated resolvers. If these - // defaults are called it is most certainly programmer err. - // If you're see this comment then: 'Whoops! Sorry, my bad.' - panic("Unimplemented; see CoreV2SecretFieldResolvers.") - }, - Name: "CoreV2Secret", +// Network implements response to request for 'network' field. +func (_ CoreV2SystemAliases) Network(p graphql.ResolveParams) (interface{}, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + return val, err +} + +// Arch implements response to request for 'arch' field. +func (_ CoreV2SystemAliases) Arch(p graphql.ResolveParams) (string, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.(string) + if err != nil { + return ret, err } + if !ok { + return ret, errors.New("unable to coerce value for field 'arch'") + } + return ret, err } -// describe CoreV2Secret's configuration; kept private to avoid unintentional tampering of configuration at runtime. -var _ObjectTypeCoreV2SecretDesc = graphql.ObjectDesc{ - Config: _ObjectTypeCoreV2SecretConfigFn, - FieldHandlers: map[string]graphql.FieldHandler{ - "name": _ObjTypeCoreV2SecretNameHandler, - "secret": _ObjTypeCoreV2SecretSecretHandler, - }, +// Arm_version implements response to request for 'arm_version' field. +func (_ CoreV2SystemAliases) Arm_version(p graphql.ResolveParams) (int, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := graphql1.Int.ParseValue(val).(int) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'arm_version'") + } + return ret, err } -// -// CoreV2SubjectFieldResolvers represents a collection of methods whose products represent the -// response values of the 'CoreV2Subject' type. -type CoreV2SubjectFieldResolvers interface { - // Type implements response to request for 'type' field. - Type(p graphql.ResolveParams) (string, error) +// Libc_type implements response to request for 'libc_type' field. +func (_ CoreV2SystemAliases) Libc_type(p graphql.ResolveParams) (string, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.(string) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'libc_type'") + } + return ret, err +} - // Name implements response to request for 'name' field. - Name(p graphql.ResolveParams) (string, error) +// Vm_system implements response to request for 'vm_system' field. +func (_ CoreV2SystemAliases) Vm_system(p graphql.ResolveParams) (string, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.(string) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'vm_system'") + } + return ret, err } -// CoreV2SubjectAliases implements all methods on CoreV2SubjectFieldResolvers interface by using reflection to -// match name of field to a field on the given value. Intent is reduce friction -// of writing new resolvers by removing all the instances where you would simply -// have the resolvers method return a field. -type CoreV2SubjectAliases struct{} +// Vm_role implements response to request for 'vm_role' field. +func (_ CoreV2SystemAliases) Vm_role(p graphql.ResolveParams) (string, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.(string) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'vm_role'") + } + return ret, err +} -// Type implements response to request for 'type' field. -func (_ CoreV2SubjectAliases) Type(p graphql.ResolveParams) (string, error) { +// Cloud_provider implements response to request for 'cloud_provider' field. +func (_ CoreV2SystemAliases) Cloud_provider(p graphql.ResolveParams) (string, error) { val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) ret, ok := val.(string) if err != nil { return ret, err } if !ok { - return ret, errors.New("unable to coerce value for field 'type'") + return ret, errors.New("unable to coerce value for field 'cloud_provider'") } return ret, err } -// Name implements response to request for 'name' field. -func (_ CoreV2SubjectAliases) Name(p graphql.ResolveParams) (string, error) { +// Float_type implements response to request for 'float_type' field. +func (_ CoreV2SystemAliases) Float_type(p graphql.ResolveParams) (string, error) { val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) ret, ok := val.(string) if err != nil { return ret, err } if !ok { - return ret, errors.New("unable to coerce value for field 'name'") + return ret, errors.New("unable to coerce value for field 'float_type'") } return ret, err } -// CoreV2SubjectType self descriptive -var CoreV2SubjectType = graphql.NewType("CoreV2Subject", graphql.ObjectKind) +// Processes implements response to request for 'processes' field. +func (_ CoreV2SystemAliases) Processes(p graphql.ResolveParams) (interface{}, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + return val, err +} -// RegisterCoreV2Subject registers CoreV2Subject object type with given service. -func RegisterCoreV2Subject(svc *graphql.Service, impl CoreV2SubjectFieldResolvers) { - svc.RegisterObject(_ObjectTypeCoreV2SubjectDesc, impl) +/* +CoreV2SystemType System contains information about the system that the Agent process +is running on, used for additional Entity context. +*/ +var CoreV2SystemType = graphql.NewType("CoreV2System", graphql.ObjectKind) + +// RegisterCoreV2System registers CoreV2System object type with given service. +func RegisterCoreV2System(svc *graphql.Service, impl CoreV2SystemFieldResolvers) { + svc.RegisterObject(_ObjectTypeCoreV2SystemDesc, impl) } -func _ObjTypeCoreV2SubjectTypeHandler(impl interface{}) graphql1.FieldResolveFn { +func _ObjTypeCoreV2SystemHostnameHandler(impl interface{}) graphql1.FieldResolveFn { resolver := impl.(interface { - Type(p graphql.ResolveParams) (string, error) + Hostname(p graphql.ResolveParams) (string, error) }) return func(frp graphql1.ResolveParams) (interface{}, error) { - return resolver.Type(frp) + return resolver.Hostname(frp) } } -func _ObjTypeCoreV2SubjectNameHandler(impl interface{}) graphql1.FieldResolveFn { +func _ObjTypeCoreV2SystemOsHandler(impl interface{}) graphql1.FieldResolveFn { resolver := impl.(interface { - Name(p graphql.ResolveParams) (string, error) + Os(p graphql.ResolveParams) (string, error) }) return func(frp graphql1.ResolveParams) (interface{}, error) { - return resolver.Name(frp) + return resolver.Os(frp) } } -func _ObjectTypeCoreV2SubjectConfigFn() graphql1.ObjectConfig { +func _ObjTypeCoreV2SystemPlatformHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Platform(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Platform(frp) + } +} + +func _ObjTypeCoreV2SystemPlatform_familyHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Platform_family(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Platform_family(frp) + } +} + +func _ObjTypeCoreV2SystemPlatform_versionHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Platform_version(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Platform_version(frp) + } +} + +func _ObjTypeCoreV2SystemNetworkHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Network(p graphql.ResolveParams) (interface{}, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Network(frp) + } +} + +func _ObjTypeCoreV2SystemArchHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Arch(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Arch(frp) + } +} + +func _ObjTypeCoreV2SystemArm_versionHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Arm_version(p graphql.ResolveParams) (int, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Arm_version(frp) + } +} + +func _ObjTypeCoreV2SystemLibc_typeHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Libc_type(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Libc_type(frp) + } +} + +func _ObjTypeCoreV2SystemVm_systemHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Vm_system(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Vm_system(frp) + } +} + +func _ObjTypeCoreV2SystemVm_roleHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Vm_role(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Vm_role(frp) + } +} + +func _ObjTypeCoreV2SystemCloud_providerHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Cloud_provider(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Cloud_provider(frp) + } +} + +func _ObjTypeCoreV2SystemFloat_typeHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Float_type(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Float_type(frp) + } +} + +func _ObjTypeCoreV2SystemProcessesHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Processes(p graphql.ResolveParams) (interface{}, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Processes(frp) + } +} + +func _ObjectTypeCoreV2SystemConfigFn() graphql1.ObjectConfig { return graphql1.ObjectConfig{ - Description: "self descriptive", + Description: "System contains information about the system that the Agent process\nis running on, used for additional Entity context.", Fields: graphql1.Fields{ - "name": &graphql1.Field{ + "arch": &graphql1.Field{ Args: graphql1.FieldConfigArgument{}, DeprecationReason: "", - Description: "Name of the referenced object", - Name: "name", + Description: "self descriptive", + Name: "arch", Type: graphql1.NewNonNull(graphql1.String), }, - "type": &graphql1.Field{ + "arm_version": &graphql1.Field{ Args: graphql1.FieldConfigArgument{}, DeprecationReason: "", - Description: "Type of object referenced (user or group)", - Name: "type", + Description: "self descriptive", + Name: "arm_version", + Type: graphql1.NewNonNull(graphql1.Int), + }, + "cloud_provider": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "CloudProvider indicates the public cloud the agent is running on.", + Name: "cloud_provider", + Type: graphql1.NewNonNull(graphql1.String), + }, + "float_type": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "self descriptive", + Name: "float_type", + Type: graphql1.NewNonNull(graphql1.String), + }, + "hostname": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "self descriptive", + Name: "hostname", + Type: graphql1.NewNonNull(graphql1.String), + }, + "libc_type": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "LibCType indicates the type of libc the agent has access to (glibc, musl,\netc)", + Name: "libc_type", + Type: graphql1.NewNonNull(graphql1.String), + }, + "network": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "self descriptive", + Name: "network", + Type: graphql1.NewNonNull(graphql.OutputType("CoreV2Network")), + }, + "os": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "self descriptive", + Name: "os", + Type: graphql1.NewNonNull(graphql1.String), + }, + "platform": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "self descriptive", + Name: "platform", + Type: graphql1.NewNonNull(graphql1.String), + }, + "platform_family": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "self descriptive", + Name: "platform_family", + Type: graphql1.NewNonNull(graphql1.String), + }, + "platform_version": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "self descriptive", + Name: "platform_version", + Type: graphql1.NewNonNull(graphql1.String), + }, + "processes": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "Processes contains information about the local processes on the agent.", + Name: "processes", + Type: graphql1.NewNonNull(graphql1.NewList(graphql.OutputType("CoreV2Process"))), + }, + "vm_role": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "VMRole indicates the VM role of the agent (host/guest)", + Name: "vm_role", + Type: graphql1.NewNonNull(graphql1.String), + }, + "vm_system": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "VMSystem indicates the VM system of the agent (kvm, vbox, etc)", + Name: "vm_system", Type: graphql1.NewNonNull(graphql1.String), }, }, @@ -1465,17 +2054,29 @@ func _ObjectTypeCoreV2SubjectConfigFn() graphql1.ObjectConfig { // these fields are updated with instantiated resolvers. If these // defaults are called it is most certainly programmer err. // If you're see this comment then: 'Whoops! Sorry, my bad.' - panic("Unimplemented; see CoreV2SubjectFieldResolvers.") + panic("Unimplemented; see CoreV2SystemFieldResolvers.") }, - Name: "CoreV2Subject", + Name: "CoreV2System", } } -// describe CoreV2Subject's configuration; kept private to avoid unintentional tampering of configuration at runtime. -var _ObjectTypeCoreV2SubjectDesc = graphql.ObjectDesc{ - Config: _ObjectTypeCoreV2SubjectConfigFn, +// describe CoreV2System's configuration; kept private to avoid unintentional tampering of configuration at runtime. +var _ObjectTypeCoreV2SystemDesc = graphql.ObjectDesc{ + Config: _ObjectTypeCoreV2SystemConfigFn, FieldHandlers: map[string]graphql.FieldHandler{ - "name": _ObjTypeCoreV2SubjectNameHandler, - "type": _ObjTypeCoreV2SubjectTypeHandler, + "arch": _ObjTypeCoreV2SystemArchHandler, + "arm_version": _ObjTypeCoreV2SystemArm_versionHandler, + "cloud_provider": _ObjTypeCoreV2SystemCloud_providerHandler, + "float_type": _ObjTypeCoreV2SystemFloat_typeHandler, + "hostname": _ObjTypeCoreV2SystemHostnameHandler, + "libc_type": _ObjTypeCoreV2SystemLibc_typeHandler, + "network": _ObjTypeCoreV2SystemNetworkHandler, + "os": _ObjTypeCoreV2SystemOsHandler, + "platform": _ObjTypeCoreV2SystemPlatformHandler, + "platform_family": _ObjTypeCoreV2SystemPlatform_familyHandler, + "platform_version": _ObjTypeCoreV2SystemPlatform_versionHandler, + "processes": _ObjTypeCoreV2SystemProcessesHandler, + "vm_role": _ObjTypeCoreV2SystemVm_roleHandler, + "vm_system": _ObjTypeCoreV2SystemVm_systemHandler, }, } diff --git a/backend/apid/graphql/schema/corev2.gen.graphql b/backend/apid/graphql/schema/corev2.gen.graphql index 5e861f81c5..dbc9589b26 100644 --- a/backend/apid/graphql/schema/corev2.gen.graphql +++ b/backend/apid/graphql/schema/corev2.gen.graphql @@ -50,6 +50,30 @@ type CoreV2ClusterRoleBinding { metadata: ObjectMeta! } +"""Deregistration contains configuration for Sensu entity de-registration.""" +type CoreV2Deregistration { + handler: String! +} + +""" +Network contains information about the system network interfaces +that the Agent process is running on, used for additional Entity +context. +""" +type CoreV2Network { + interfaces: [CoreV2NetworkInterface!]! +} + +""" +NetworkInterface contains information about a system network +interface. +""" +type CoreV2NetworkInterface { + name: String! + mac: String! + addresses: [String!]! +} + """Pipeline represents a named collection of pipeline workflows.""" type CoreV2Pipeline { @@ -85,6 +109,11 @@ type CoreV2PipelineWorkflow { handler: CoreV2ResourceReference } +"""Process contains information about a local process.""" +type CoreV2Process { + name: String! +} + """ResourceReference represents a reference to another resource.""" type CoreV2ResourceReference { @@ -122,41 +151,6 @@ type CoreV2RoleBinding { metadata: ObjectMeta! } -"""RoleRef maps groups to Roles or ClusterRoles.""" -type CoreV2RoleRef { - - """Type of role being referenced.""" - type: String! - - """Name of the resource being referenced""" - name: String! -} - -"""Rule holds information that describes an action that can be taken""" -type CoreV2Rule { - - """ - Verbs is a list of verbs that apply to all of the listed resources for - this rule. These include "get", "list", "watch", "create", "update", - "delete". - TODO: add support for "patch" (this is expensive and should be delayed - until a further release). TODO: add support for "watch" (via websockets) - """ - verbs: [String!]! - - """ - Resources is a list of resources that this rule applies to. "*" - represents all resources. - """ - resources: [String!]! - - """ - ResourceNames is an optional list of resource names that the rule applies - to. - """ - resource_names: [String!]! -} - """A Secret is a secret specification.""" type CoreV2Secret { @@ -175,3 +169,37 @@ type CoreV2Subject { """Name of the referenced object""" name: String! } + +""" +System contains information about the system that the Agent process +is running on, used for additional Entity context. +""" +type CoreV2System { + hostname: String! + os: String! + platform: String! + platform_family: String! + platform_version: String! + network: CoreV2Network! + arch: String! + arm_version: Int! + + """ + LibCType indicates the type of libc the agent has access to (glibc, musl, + etc) + """ + libc_type: String! + + """VMSystem indicates the VM system of the agent (kvm, vbox, etc)""" + vm_system: String! + + """VMRole indicates the VM role of the agent (host/guest)""" + vm_role: String! + + """CloudProvider indicates the public cloud the agent is running on.""" + cloud_provider: String! + float_type: String! + + """Processes contains information about the local processes on the agent.""" + processes: [CoreV2Process]! +} diff --git a/backend/apid/graphql/schema/corev3.gen.gql.go b/backend/apid/graphql/schema/corev3.gen.gql.go new file mode 100644 index 0000000000..929e4b12c5 --- /dev/null +++ b/backend/apid/graphql/schema/corev3.gen.gql.go @@ -0,0 +1,467 @@ +// Code generated by scripts/gengraphql.go. DO NOT EDIT. + +package schema + +import ( + errors "errors" + graphql1 "github.com/graphql-go/graphql" + graphql "github.com/sensu/sensu-go/graphql" +) + +// +// CoreV3EntityConfigFieldResolvers represents a collection of methods whose products represent the +// response values of the 'CoreV3EntityConfig' type. +type CoreV3EntityConfigFieldResolvers interface { + // Metadata implements response to request for 'metadata' field. + Metadata(p graphql.ResolveParams) (interface{}, error) + + // Entity_class implements response to request for 'entity_class' field. + Entity_class(p graphql.ResolveParams) (string, error) + + // User implements response to request for 'user' field. + User(p graphql.ResolveParams) (string, error) + + // Subscriptions implements response to request for 'subscriptions' field. + Subscriptions(p graphql.ResolveParams) ([]string, error) + + // Deregister implements response to request for 'deregister' field. + Deregister(p graphql.ResolveParams) (bool, error) + + // Deregistration implements response to request for 'deregistration' field. + Deregistration(p graphql.ResolveParams) (interface{}, error) + + // Keepalive_handlers implements response to request for 'keepalive_handlers' field. + Keepalive_handlers(p graphql.ResolveParams) ([]string, error) + + // Redact implements response to request for 'redact' field. + Redact(p graphql.ResolveParams) ([]string, error) +} + +// CoreV3EntityConfigAliases implements all methods on CoreV3EntityConfigFieldResolvers interface by using reflection to +// match name of field to a field on the given value. Intent is reduce friction +// of writing new resolvers by removing all the instances where you would simply +// have the resolvers method return a field. +type CoreV3EntityConfigAliases struct{} + +// Metadata implements response to request for 'metadata' field. +func (_ CoreV3EntityConfigAliases) Metadata(p graphql.ResolveParams) (interface{}, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + return val, err +} + +// Entity_class implements response to request for 'entity_class' field. +func (_ CoreV3EntityConfigAliases) Entity_class(p graphql.ResolveParams) (string, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.(string) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'entity_class'") + } + return ret, err +} + +// User implements response to request for 'user' field. +func (_ CoreV3EntityConfigAliases) User(p graphql.ResolveParams) (string, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.(string) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'user'") + } + return ret, err +} + +// Subscriptions implements response to request for 'subscriptions' field. +func (_ CoreV3EntityConfigAliases) Subscriptions(p graphql.ResolveParams) ([]string, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.([]string) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'subscriptions'") + } + return ret, err +} + +// Deregister implements response to request for 'deregister' field. +func (_ CoreV3EntityConfigAliases) Deregister(p graphql.ResolveParams) (bool, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.(bool) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'deregister'") + } + return ret, err +} + +// Deregistration implements response to request for 'deregistration' field. +func (_ CoreV3EntityConfigAliases) Deregistration(p graphql.ResolveParams) (interface{}, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + return val, err +} + +// Keepalive_handlers implements response to request for 'keepalive_handlers' field. +func (_ CoreV3EntityConfigAliases) Keepalive_handlers(p graphql.ResolveParams) ([]string, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.([]string) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'keepalive_handlers'") + } + return ret, err +} + +// Redact implements response to request for 'redact' field. +func (_ CoreV3EntityConfigAliases) Redact(p graphql.ResolveParams) ([]string, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.([]string) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'redact'") + } + return ret, err +} + +// CoreV3EntityConfigType EntityConfig represents entity configuration. +var CoreV3EntityConfigType = graphql.NewType("CoreV3EntityConfig", graphql.ObjectKind) + +// RegisterCoreV3EntityConfig registers CoreV3EntityConfig object type with given service. +func RegisterCoreV3EntityConfig(svc *graphql.Service, impl CoreV3EntityConfigFieldResolvers) { + svc.RegisterObject(_ObjectTypeCoreV3EntityConfigDesc, impl) +} +func _ObjTypeCoreV3EntityConfigMetadataHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Metadata(p graphql.ResolveParams) (interface{}, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Metadata(frp) + } +} + +func _ObjTypeCoreV3EntityConfigEntity_classHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Entity_class(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Entity_class(frp) + } +} + +func _ObjTypeCoreV3EntityConfigUserHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + User(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.User(frp) + } +} + +func _ObjTypeCoreV3EntityConfigSubscriptionsHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Subscriptions(p graphql.ResolveParams) ([]string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Subscriptions(frp) + } +} + +func _ObjTypeCoreV3EntityConfigDeregisterHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Deregister(p graphql.ResolveParams) (bool, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Deregister(frp) + } +} + +func _ObjTypeCoreV3EntityConfigDeregistrationHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Deregistration(p graphql.ResolveParams) (interface{}, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Deregistration(frp) + } +} + +func _ObjTypeCoreV3EntityConfigKeepalive_handlersHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Keepalive_handlers(p graphql.ResolveParams) ([]string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Keepalive_handlers(frp) + } +} + +func _ObjTypeCoreV3EntityConfigRedactHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Redact(p graphql.ResolveParams) ([]string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Redact(frp) + } +} + +func _ObjectTypeCoreV3EntityConfigConfigFn() graphql1.ObjectConfig { + return graphql1.ObjectConfig{ + Description: "EntityConfig represents entity configuration.", + Fields: graphql1.Fields{ + "deregister": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "Deregister, if true, will result in the entity being deleted when the\nentity is an agent, and the agent disconnects its session.", + Name: "deregister", + Type: graphql1.NewNonNull(graphql1.Boolean), + }, + "deregistration": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "Deregistration contains configuration for Sensu entity de-registration.", + Name: "deregistration", + Type: graphql1.NewNonNull(graphql.OutputType("CoreV2Deregistration")), + }, + "entity_class": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "EntityClass represents the class of the entity. It can be \"agent\",\n\"proxy\", or \"backend\".", + Name: "entity_class", + Type: graphql1.NewNonNull(graphql1.String), + }, + "keepalive_handlers": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "KeepaliveHandlers contains a list of handlers to use for the entity's\nkeepalive events.", + Name: "keepalive_handlers", + Type: graphql1.NewNonNull(graphql1.NewList(graphql1.NewNonNull(graphql1.String))), + }, + "metadata": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "Metadata contains the name, namespace, labels and annotations of the\nentity.", + Name: "metadata", + Type: graphql.OutputType("ObjectMeta"), + }, + "redact": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "Redact contains the fields to redact on the entity, if the entity is an]\nagent entity.", + Name: "redact", + Type: graphql1.NewNonNull(graphql1.NewList(graphql1.NewNonNull(graphql1.String))), + }, + "subscriptions": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "Subscriptions are a weak relationship between entities and checks. The\nscheduler uses subscriptions to make entities to checks when scheduling.", + Name: "subscriptions", + Type: graphql1.NewNonNull(graphql1.NewList(graphql1.NewNonNull(graphql1.String))), + }, + "user": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "User is the username the entity is connecting as, if the entity is an\nagent entity.", + Name: "user", + Type: graphql1.NewNonNull(graphql1.String), + }, + }, + Interfaces: []*graphql1.Interface{}, + IsTypeOf: func(_ graphql1.IsTypeOfParams) bool { + // NOTE: + // Panic by default. Intent is that when Service is invoked, values of + // these fields are updated with instantiated resolvers. If these + // defaults are called it is most certainly programmer err. + // If you're see this comment then: 'Whoops! Sorry, my bad.' + panic("Unimplemented; see CoreV3EntityConfigFieldResolvers.") + }, + Name: "CoreV3EntityConfig", + } +} + +// describe CoreV3EntityConfig's configuration; kept private to avoid unintentional tampering of configuration at runtime. +var _ObjectTypeCoreV3EntityConfigDesc = graphql.ObjectDesc{ + Config: _ObjectTypeCoreV3EntityConfigConfigFn, + FieldHandlers: map[string]graphql.FieldHandler{ + "deregister": _ObjTypeCoreV3EntityConfigDeregisterHandler, + "deregistration": _ObjTypeCoreV3EntityConfigDeregistrationHandler, + "entity_class": _ObjTypeCoreV3EntityConfigEntity_classHandler, + "keepalive_handlers": _ObjTypeCoreV3EntityConfigKeepalive_handlersHandler, + "metadata": _ObjTypeCoreV3EntityConfigMetadataHandler, + "redact": _ObjTypeCoreV3EntityConfigRedactHandler, + "subscriptions": _ObjTypeCoreV3EntityConfigSubscriptionsHandler, + "user": _ObjTypeCoreV3EntityConfigUserHandler, + }, +} + +// +// CoreV3EntityStateFieldResolvers represents a collection of methods whose products represent the +// response values of the 'CoreV3EntityState' type. +type CoreV3EntityStateFieldResolvers interface { + // Metadata implements response to request for 'metadata' field. + Metadata(p graphql.ResolveParams) (interface{}, error) + + // System implements response to request for 'system' field. + System(p graphql.ResolveParams) (interface{}, error) + + // Last_seen implements response to request for 'last_seen' field. + Last_seen(p graphql.ResolveParams) (int, error) + + // Sensu_agent_version implements response to request for 'sensu_agent_version' field. + Sensu_agent_version(p graphql.ResolveParams) (string, error) +} + +// CoreV3EntityStateAliases implements all methods on CoreV3EntityStateFieldResolvers interface by using reflection to +// match name of field to a field on the given value. Intent is reduce friction +// of writing new resolvers by removing all the instances where you would simply +// have the resolvers method return a field. +type CoreV3EntityStateAliases struct{} + +// Metadata implements response to request for 'metadata' field. +func (_ CoreV3EntityStateAliases) Metadata(p graphql.ResolveParams) (interface{}, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + return val, err +} + +// System implements response to request for 'system' field. +func (_ CoreV3EntityStateAliases) System(p graphql.ResolveParams) (interface{}, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + return val, err +} + +// Last_seen implements response to request for 'last_seen' field. +func (_ CoreV3EntityStateAliases) Last_seen(p graphql.ResolveParams) (int, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := graphql1.Int.ParseValue(val).(int) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'last_seen'") + } + return ret, err +} + +// Sensu_agent_version implements response to request for 'sensu_agent_version' field. +func (_ CoreV3EntityStateAliases) Sensu_agent_version(p graphql.ResolveParams) (string, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.(string) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'sensu_agent_version'") + } + return ret, err +} + +/* +CoreV3EntityStateType EntityState represents entity state. Unlike configuration, state is +typically only maintained for agent entities, although it can be maintained +for proxy entities in certain circumstances. +*/ +var CoreV3EntityStateType = graphql.NewType("CoreV3EntityState", graphql.ObjectKind) + +// RegisterCoreV3EntityState registers CoreV3EntityState object type with given service. +func RegisterCoreV3EntityState(svc *graphql.Service, impl CoreV3EntityStateFieldResolvers) { + svc.RegisterObject(_ObjectTypeCoreV3EntityStateDesc, impl) +} +func _ObjTypeCoreV3EntityStateMetadataHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Metadata(p graphql.ResolveParams) (interface{}, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Metadata(frp) + } +} + +func _ObjTypeCoreV3EntityStateSystemHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + System(p graphql.ResolveParams) (interface{}, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.System(frp) + } +} + +func _ObjTypeCoreV3EntityStateLast_seenHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Last_seen(p graphql.ResolveParams) (int, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Last_seen(frp) + } +} + +func _ObjTypeCoreV3EntityStateSensu_agent_versionHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Sensu_agent_version(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Sensu_agent_version(frp) + } +} + +func _ObjectTypeCoreV3EntityStateConfigFn() graphql1.ObjectConfig { + return graphql1.ObjectConfig{ + Description: "EntityState represents entity state. Unlike configuration, state is\ntypically only maintained for agent entities, although it can be maintained\nfor proxy entities in certain circumstances.", + Fields: graphql1.Fields{ + "last_seen": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "LastSeen is a unix timestamp that represents when the entity was last\nobserved by the keepalive system.", + Name: "last_seen", + Type: graphql1.NewNonNull(graphql1.Int), + }, + "metadata": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "Metadata contains the name, namespace, labels and annotations of the\nentity.", + Name: "metadata", + Type: graphql.OutputType("ObjectMeta"), + }, + "sensu_agent_version": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "SensuAgentVersion is the sensu-agent version.", + Name: "sensu_agent_version", + Type: graphql1.NewNonNull(graphql1.String), + }, + "system": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "System contains information about the system that the Agent process\nis running on, used for additional Entity context.", + Name: "system", + Type: graphql1.NewNonNull(graphql.OutputType("CoreV2System")), + }, + }, + Interfaces: []*graphql1.Interface{}, + IsTypeOf: func(_ graphql1.IsTypeOfParams) bool { + // NOTE: + // Panic by default. Intent is that when Service is invoked, values of + // these fields are updated with instantiated resolvers. If these + // defaults are called it is most certainly programmer err. + // If you're see this comment then: 'Whoops! Sorry, my bad.' + panic("Unimplemented; see CoreV3EntityStateFieldResolvers.") + }, + Name: "CoreV3EntityState", + } +} + +// describe CoreV3EntityState's configuration; kept private to avoid unintentional tampering of configuration at runtime. +var _ObjectTypeCoreV3EntityStateDesc = graphql.ObjectDesc{ + Config: _ObjectTypeCoreV3EntityStateConfigFn, + FieldHandlers: map[string]graphql.FieldHandler{ + "last_seen": _ObjTypeCoreV3EntityStateLast_seenHandler, + "metadata": _ObjTypeCoreV3EntityStateMetadataHandler, + "sensu_agent_version": _ObjTypeCoreV3EntityStateSensu_agent_versionHandler, + "system": _ObjTypeCoreV3EntityStateSystemHandler, + }, +} diff --git a/backend/apid/graphql/schema/corev3.gen.graphql b/backend/apid/graphql/schema/corev3.gen.graphql new file mode 100644 index 0000000000..8d0cfafdb9 --- /dev/null +++ b/backend/apid/graphql/schema/corev3.gen.graphql @@ -0,0 +1,79 @@ +# automatically generated file, do not edit! + +"""EntityConfig represents entity configuration.""" +type CoreV3EntityConfig { + + """ + Metadata contains the name, namespace, labels and annotations of the + entity. + """ + metadata: ObjectMeta + + """ + EntityClass represents the class of the entity. It can be "agent", + "proxy", or "backend". + """ + entity_class: String! + + """ + User is the username the entity is connecting as, if the entity is an + agent entity. + """ + user: String! + + """ + Subscriptions are a weak relationship between entities and checks. The + scheduler uses subscriptions to make entities to checks when scheduling. + """ + subscriptions: [String!]! + + """ + Deregister, if true, will result in the entity being deleted when the + entity is an agent, and the agent disconnects its session. + """ + deregister: Boolean! + + """Deregistration contains configuration for Sensu entity de-registration.""" + deregistration: CoreV2Deregistration! + + """ + KeepaliveHandlers contains a list of handlers to use for the entity's + keepalive events. + """ + keepalive_handlers: [String!]! + + """ + Redact contains the fields to redact on the entity, if the entity is an] + agent entity. + """ + redact: [String!]! +} + +""" +EntityState represents entity state. Unlike configuration, state is +typically only maintained for agent entities, although it can be maintained +for proxy entities in certain circumstances. +""" +type CoreV3EntityState { + + """ + Metadata contains the name, namespace, labels and annotations of the + entity. + """ + metadata: ObjectMeta + + """ + System contains information about the system that the Agent process + is running on, used for additional Entity context. + """ + system: CoreV2System! + + """ + LastSeen is a unix timestamp that represents when the entity was last + observed by the keepalive system. + """ + last_seen: Int! + + """SensuAgentVersion is the sensu-agent version.""" + sensu_agent_version: String! +} diff --git a/backend/apid/graphql/schema/corev3.gql.go b/backend/apid/graphql/schema/corev3.gql.go new file mode 100644 index 0000000000..40754f3fe9 --- /dev/null +++ b/backend/apid/graphql/schema/corev3.gql.go @@ -0,0 +1,186 @@ +// Code generated by scripts/gengraphql.go. DO NOT EDIT. + +package schema + +import ( + graphql1 "github.com/graphql-go/graphql" + graphql "github.com/sensu/sensu-go/graphql" +) + +// +// CoreV3EntityConfigExtensionOverridesFieldResolvers represents a collection of methods whose products represent the +// response values of the 'CoreV3EntityConfigExtensionOverrides' type. +type CoreV3EntityConfigExtensionOverridesFieldResolvers interface { + // ID implements response to request for 'id' field. + ID(p graphql.ResolveParams) (string, error) + + // ToJSON implements response to request for 'toJSON' field. + ToJSON(p graphql.ResolveParams) (interface{}, error) + + // State implements response to request for 'state' field. + State(p graphql.ResolveParams) (interface{}, error) +} + +// RegisterCoreV3EntityConfigExtensionOverrides registers CoreV3EntityConfigExtensionOverrides object type with given service. +func RegisterCoreV3EntityConfigExtensionOverrides(svc *graphql.Service, impl CoreV3EntityConfigExtensionOverridesFieldResolvers) { + svc.RegisterObjectExtension(_ObjectExtensionTypeCoreV3EntityConfigExtensionOverridesDesc, impl) +} + +func _ObjTypeCoreV3EntityConfigExtensionOverridesIDHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + ID(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.ID(frp) + } +} + +func _ObjTypeCoreV3EntityConfigExtensionOverridesToJSONHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + ToJSON(p graphql.ResolveParams) (interface{}, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.ToJSON(frp) + } +} + +func _ObjTypeCoreV3EntityConfigExtensionOverridesStateHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + State(p graphql.ResolveParams) (interface{}, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.State(frp) + } +} + +func _ObjectExtensionTypeCoreV3EntityConfigExtensionOverridesConfigFn() graphql1.ObjectConfig { + return graphql1.ObjectConfig{ + Description: "", + Fields: graphql1.Fields{ + "id": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "Unique global identifier used to reference resource.", + Name: "id", + Type: graphql1.NewNonNull(graphql1.ID), + }, + "state": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "Corresponding entity state, if applicable.", + Name: "state", + Type: graphql.OutputType("CoreV3EntityState"), + }, + "toJSON": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "toJSON returns a REST API compatible representation of the resource. Handy for\nsharing snippets that can then be imported with `sensuctl create`.", + Name: "toJSON", + Type: graphql1.NewNonNull(graphql.OutputType("JSON")), + }, + }, + Interfaces: []*graphql1.Interface{ + graphql.Interface("Node"), + graphql.Interface("Resource")}, + Name: "CoreV3EntityConfig", + } +} + +// describe CoreV3EntityConfigExtensionOverrides's configuration; kept private to avoid unintentional tampering of configuration at runtime. +var _ObjectExtensionTypeCoreV3EntityConfigExtensionOverridesDesc = graphql.ObjectDesc{ + Config: _ObjectExtensionTypeCoreV3EntityConfigExtensionOverridesConfigFn, + FieldHandlers: map[string]graphql.FieldHandler{ + "id": _ObjTypeCoreV3EntityConfigExtensionOverridesIDHandler, + "state": _ObjTypeCoreV3EntityConfigExtensionOverridesStateHandler, + "toJSON": _ObjTypeCoreV3EntityConfigExtensionOverridesToJSONHandler, + }, +} + +// +// CoreV3EntityStateExtensionOverridesFieldResolvers represents a collection of methods whose products represent the +// response values of the 'CoreV3EntityStateExtensionOverrides' type. +type CoreV3EntityStateExtensionOverridesFieldResolvers interface { + // ID implements response to request for 'id' field. + ID(p graphql.ResolveParams) (string, error) + + // ToJSON implements response to request for 'toJSON' field. + ToJSON(p graphql.ResolveParams) (interface{}, error) + + // Config implements response to request for 'config' field. + Config(p graphql.ResolveParams) (interface{}, error) +} + +// RegisterCoreV3EntityStateExtensionOverrides registers CoreV3EntityStateExtensionOverrides object type with given service. +func RegisterCoreV3EntityStateExtensionOverrides(svc *graphql.Service, impl CoreV3EntityStateExtensionOverridesFieldResolvers) { + svc.RegisterObjectExtension(_ObjectExtensionTypeCoreV3EntityStateExtensionOverridesDesc, impl) +} + +func _ObjTypeCoreV3EntityStateExtensionOverridesIDHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + ID(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.ID(frp) + } +} + +func _ObjTypeCoreV3EntityStateExtensionOverridesToJSONHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + ToJSON(p graphql.ResolveParams) (interface{}, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.ToJSON(frp) + } +} + +func _ObjTypeCoreV3EntityStateExtensionOverridesConfigHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Config(p graphql.ResolveParams) (interface{}, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Config(frp) + } +} + +func _ObjectExtensionTypeCoreV3EntityStateExtensionOverridesConfigFn() graphql1.ObjectConfig { + return graphql1.ObjectConfig{ + Description: "", + Fields: graphql1.Fields{ + "config": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "Corresponding entity config, if applicable.", + Name: "config", + Type: graphql.OutputType("CoreV3EntityConfig"), + }, + "id": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "Unique global identifier used to reference resource.", + Name: "id", + Type: graphql1.NewNonNull(graphql1.ID), + }, + "toJSON": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "toJSON returns a REST API compatible representation of the resource. Handy for\nsharing snippets that can then be imported with `sensuctl create`.", + Name: "toJSON", + Type: graphql1.NewNonNull(graphql.OutputType("JSON")), + }, + }, + Interfaces: []*graphql1.Interface{ + graphql.Interface("Node"), + graphql.Interface("Resource")}, + Name: "CoreV3EntityState", + } +} + +// describe CoreV3EntityStateExtensionOverrides's configuration; kept private to avoid unintentional tampering of configuration at runtime. +var _ObjectExtensionTypeCoreV3EntityStateExtensionOverridesDesc = graphql.ObjectDesc{ + Config: _ObjectExtensionTypeCoreV3EntityStateExtensionOverridesConfigFn, + FieldHandlers: map[string]graphql.FieldHandler{ + "config": _ObjTypeCoreV3EntityStateExtensionOverridesConfigHandler, + "id": _ObjTypeCoreV3EntityStateExtensionOverridesIDHandler, + "toJSON": _ObjTypeCoreV3EntityStateExtensionOverridesToJSONHandler, + }, +} diff --git a/backend/apid/graphql/schema/corev3.graphql b/backend/apid/graphql/schema/corev3.graphql new file mode 100644 index 0000000000..b6c884d35a --- /dev/null +++ b/backend/apid/graphql/schema/corev3.graphql @@ -0,0 +1,31 @@ +extend type CoreV3EntityConfig implements Node & Resource @named(suffix: "Overrides") { + "Unique global identifier used to reference resource." + id: ID! + + """ + toJSON returns a REST API compatible representation of the resource. Handy for + sharing snippets that can then be imported with `sensuctl create`. + """ + toJSON: JSON! + + """ + Corresponding entity state, if applicable. + """ + state: CoreV3EntityState +} + +extend type CoreV3EntityState implements Node & Resource @named(suffix: "Overrides") { + "Unique global identifier used to reference resource." + id: ID! + + """ + toJSON returns a REST API compatible representation of the resource. Handy for + sharing snippets that can then be imported with `sensuctl create`. + """ + toJSON: JSON! + + """ + Corresponding entity config, if applicable. + """ + config: CoreV3EntityConfig +} diff --git a/backend/apid/graphql/schema/schema_gen.go b/backend/apid/graphql/schema/schema_gen.go index 9dbdb75431..61392d734b 100644 --- a/backend/apid/graphql/schema/schema_gen.go +++ b/backend/apid/graphql/schema/schema_gen.go @@ -1,4 +1,5 @@ package schema -//go:generate go run github.com/sensu/sensu-go/scripts/gen_gqltype -types AssetBuild,ClusterRole,ClusterRoleBinding,Pipeline,PipelineWorkflow,ResourceReference,Role,RoleBinding,RoleRef,Rule,Secret,Subject -pkg-path ../../../../api/core/v2 -o ./corev2.gen.graphql +//go:generate go run github.com/sensu/sensu-go/scripts/gen_gqltype -types AssetBuild,ClusterRole,ClusterRoleBinding,Deregistration,Network,NetworkInterface,Pipeline,PipelineWorkflow,Process,ResourceReference,Role,RoleBinding,Secret,Subject,System -pkg-path ../../../../api/core/v2 -o ./corev2.gen.graphql +//go:generate go run github.com/sensu/sensu-go/scripts/gen_gqltype -types EntityConfig,EntityState -pkg-path ../../../../api/core/v3 -o ./corev3.gen.graphql //go:generate go run github.com/sensu/sensu-go/scripts/gengraphql . diff --git a/backend/apid/graphql/service.go b/backend/apid/graphql/service.go index 850b13f161..9b927b3e51 100644 --- a/backend/apid/graphql/service.go +++ b/backend/apid/graphql/service.go @@ -67,11 +67,18 @@ func NewService(cfg ServiceConfig) (*Service, error) { // Register types schema.RegisterAsset(svc, &assetImpl{}) schema.RegisterCoreV2AssetBuild(svc, &schema.CoreV2AssetBuildAliases{}) + schema.RegisterCoreV2Deregistration(svc, &schema.CoreV2DeregistrationAliases{}) + schema.RegisterCoreV2Network(svc, &schema.CoreV2NetworkAliases{}) + schema.RegisterCoreV2NetworkInterface(svc, &schema.CoreV2NetworkInterfaceAliases{}) schema.RegisterCoreV2Pipeline(svc, &corev2PipelineImpl{}) schema.RegisterCoreV2PipelineExtensionOverrides(svc, &corev2PipelineImpl{}) schema.RegisterCoreV2PipelineWorkflow(svc, &schema.CoreV2PipelineWorkflowAliases{}) + schema.RegisterCoreV2Process(svc, &schema.CoreV2ProcessAliases{}) schema.RegisterCoreV2ResourceReference(svc, &schema.CoreV2ResourceReferenceAliases{}) schema.RegisterCoreV2Secret(svc, &schema.CoreV2SecretAliases{}) + schema.RegisterCoreV2System(svc, &schema.CoreV2SystemAliases{}) + schema.RegisterCoreV3EntityConfig(svc, &corev3EntityConfigImpl{client: cfg.GenericClient}) + schema.RegisterCoreV3EntityState(svc, &corev3EntityStateImpl{client: cfg.GenericClient}) schema.RegisterNamespace(svc, &namespaceImpl{client: cfg.NamespaceClient, entityClient: cfg.EntityClient, eventClient: cfg.EventClient, serviceConfig: &cfg}) schema.RegisterErrCode(svc) schema.RegisterEvent(svc, &eventImpl{}) From 3fcc96c73240382f2446208ce7688d55d5aadc5e Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 20 Jul 2022 13:41:31 -0700 Subject: [PATCH 10/35] move Signed-off-by: James Phillips --- backend/apid/graphql/corev3.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/apid/graphql/corev3.go b/backend/apid/graphql/corev3.go index 0db60085e7..a8046ba1a5 100644 --- a/backend/apid/graphql/corev3.go +++ b/backend/apid/graphql/corev3.go @@ -59,12 +59,6 @@ func (*corev3EntityStateImpl) ToJSON(p graphql.ResolveParams) (interface{}, erro return types.WrapResource(p.Source.(types.Resource)), nil } -// IsTypeOf is used to determine if a given value is associated with the type -func (*corev3EntityStateImpl) IsTypeOf(s interface{}, p graphql.IsTypeOfParams) bool { - _, ok := s.(*corev3.EntityState) - return ok -} - // State implements response to request for 'state' field. func (i *corev3EntityStateImpl) Config(p graphql.ResolveParams) (interface{}, error) { state := p.Source.(*corev3.EntityState) @@ -76,3 +70,9 @@ func (i *corev3EntityStateImpl) Config(p graphql.ResolveParams) (interface{}, er } return val.Resource, err } + +// IsTypeOf is used to determine if a given value is associated with the type +func (*corev3EntityStateImpl) IsTypeOf(s interface{}, p graphql.IsTypeOfParams) bool { + _, ok := s.(*corev3.EntityState) + return ok +} From ca6159f94750a05efd85eae3d6d5389d1998ab8d Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 20 Jul 2022 13:45:55 -0700 Subject: [PATCH 11/35] fix borked rebase Signed-off-by: James Phillips --- backend/apid/graphql/schema/corev2.gen.gql.go | 251 ++++++++++++++++++ .../apid/graphql/schema/corev2.gen.graphql | 35 +++ backend/apid/graphql/schema/schema_gen.go | 2 +- 3 files changed, 287 insertions(+), 1 deletion(-) diff --git a/backend/apid/graphql/schema/corev2.gen.gql.go b/backend/apid/graphql/schema/corev2.gen.gql.go index 621006e7b1..1108faa126 100644 --- a/backend/apid/graphql/schema/corev2.gen.gql.go +++ b/backend/apid/graphql/schema/corev2.gen.gql.go @@ -1369,6 +1369,257 @@ var _ObjectTypeCoreV2RoleBindingDesc = graphql.ObjectDesc{ }, } +// +// CoreV2RoleRefFieldResolvers represents a collection of methods whose products represent the +// response values of the 'CoreV2RoleRef' type. +type CoreV2RoleRefFieldResolvers interface { + // Type implements response to request for 'type' field. + Type(p graphql.ResolveParams) (string, error) + + // Name implements response to request for 'name' field. + Name(p graphql.ResolveParams) (string, error) +} + +// CoreV2RoleRefAliases implements all methods on CoreV2RoleRefFieldResolvers interface by using reflection to +// match name of field to a field on the given value. Intent is reduce friction +// of writing new resolvers by removing all the instances where you would simply +// have the resolvers method return a field. +type CoreV2RoleRefAliases struct{} + +// Type implements response to request for 'type' field. +func (_ CoreV2RoleRefAliases) Type(p graphql.ResolveParams) (string, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.(string) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'type'") + } + return ret, err +} + +// Name implements response to request for 'name' field. +func (_ CoreV2RoleRefAliases) Name(p graphql.ResolveParams) (string, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.(string) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'name'") + } + return ret, err +} + +// CoreV2RoleRefType RoleRef maps groups to Roles or ClusterRoles. +var CoreV2RoleRefType = graphql.NewType("CoreV2RoleRef", graphql.ObjectKind) + +// RegisterCoreV2RoleRef registers CoreV2RoleRef object type with given service. +func RegisterCoreV2RoleRef(svc *graphql.Service, impl CoreV2RoleRefFieldResolvers) { + svc.RegisterObject(_ObjectTypeCoreV2RoleRefDesc, impl) +} +func _ObjTypeCoreV2RoleRefTypeHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Type(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Type(frp) + } +} + +func _ObjTypeCoreV2RoleRefNameHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Name(p graphql.ResolveParams) (string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Name(frp) + } +} + +func _ObjectTypeCoreV2RoleRefConfigFn() graphql1.ObjectConfig { + return graphql1.ObjectConfig{ + Description: "RoleRef maps groups to Roles or ClusterRoles.", + Fields: graphql1.Fields{ + "name": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "Name of the resource being referenced", + Name: "name", + Type: graphql1.NewNonNull(graphql1.String), + }, + "type": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "Type of role being referenced.", + Name: "type", + Type: graphql1.NewNonNull(graphql1.String), + }, + }, + Interfaces: []*graphql1.Interface{}, + IsTypeOf: func(_ graphql1.IsTypeOfParams) bool { + // NOTE: + // Panic by default. Intent is that when Service is invoked, values of + // these fields are updated with instantiated resolvers. If these + // defaults are called it is most certainly programmer err. + // If you're see this comment then: 'Whoops! Sorry, my bad.' + panic("Unimplemented; see CoreV2RoleRefFieldResolvers.") + }, + Name: "CoreV2RoleRef", + } +} + +// describe CoreV2RoleRef's configuration; kept private to avoid unintentional tampering of configuration at runtime. +var _ObjectTypeCoreV2RoleRefDesc = graphql.ObjectDesc{ + Config: _ObjectTypeCoreV2RoleRefConfigFn, + FieldHandlers: map[string]graphql.FieldHandler{ + "name": _ObjTypeCoreV2RoleRefNameHandler, + "type": _ObjTypeCoreV2RoleRefTypeHandler, + }, +} + +// +// CoreV2RuleFieldResolvers represents a collection of methods whose products represent the +// response values of the 'CoreV2Rule' type. +type CoreV2RuleFieldResolvers interface { + // Verbs implements response to request for 'verbs' field. + Verbs(p graphql.ResolveParams) ([]string, error) + + // Resources implements response to request for 'resources' field. + Resources(p graphql.ResolveParams) ([]string, error) + + // Resource_names implements response to request for 'resource_names' field. + Resource_names(p graphql.ResolveParams) ([]string, error) +} + +// CoreV2RuleAliases implements all methods on CoreV2RuleFieldResolvers interface by using reflection to +// match name of field to a field on the given value. Intent is reduce friction +// of writing new resolvers by removing all the instances where you would simply +// have the resolvers method return a field. +type CoreV2RuleAliases struct{} + +// Verbs implements response to request for 'verbs' field. +func (_ CoreV2RuleAliases) Verbs(p graphql.ResolveParams) ([]string, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.([]string) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'verbs'") + } + return ret, err +} + +// Resources implements response to request for 'resources' field. +func (_ CoreV2RuleAliases) Resources(p graphql.ResolveParams) ([]string, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.([]string) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'resources'") + } + return ret, err +} + +// Resource_names implements response to request for 'resource_names' field. +func (_ CoreV2RuleAliases) Resource_names(p graphql.ResolveParams) ([]string, error) { + val, err := graphql.DefaultResolver(p.Source, p.Info.FieldName) + ret, ok := val.([]string) + if err != nil { + return ret, err + } + if !ok { + return ret, errors.New("unable to coerce value for field 'resource_names'") + } + return ret, err +} + +// CoreV2RuleType Rule holds information that describes an action that can be taken +var CoreV2RuleType = graphql.NewType("CoreV2Rule", graphql.ObjectKind) + +// RegisterCoreV2Rule registers CoreV2Rule object type with given service. +func RegisterCoreV2Rule(svc *graphql.Service, impl CoreV2RuleFieldResolvers) { + svc.RegisterObject(_ObjectTypeCoreV2RuleDesc, impl) +} +func _ObjTypeCoreV2RuleVerbsHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Verbs(p graphql.ResolveParams) ([]string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Verbs(frp) + } +} + +func _ObjTypeCoreV2RuleResourcesHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Resources(p graphql.ResolveParams) ([]string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Resources(frp) + } +} + +func _ObjTypeCoreV2RuleResource_namesHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + Resource_names(p graphql.ResolveParams) ([]string, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.Resource_names(frp) + } +} + +func _ObjectTypeCoreV2RuleConfigFn() graphql1.ObjectConfig { + return graphql1.ObjectConfig{ + Description: "Rule holds information that describes an action that can be taken", + Fields: graphql1.Fields{ + "resource_names": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "ResourceNames is an optional list of resource names that the rule applies\nto.", + Name: "resource_names", + Type: graphql1.NewNonNull(graphql1.NewList(graphql1.NewNonNull(graphql1.String))), + }, + "resources": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "Resources is a list of resources that this rule applies to. \"*\"\nrepresents all resources.", + Name: "resources", + Type: graphql1.NewNonNull(graphql1.NewList(graphql1.NewNonNull(graphql1.String))), + }, + "verbs": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "Verbs is a list of verbs that apply to all of the listed resources for\nthis rule. These include \"get\", \"list\", \"watch\", \"create\", \"update\",\n\"delete\".\nTODO: add support for \"patch\" (this is expensive and should be delayed\nuntil a further release). TODO: add support for \"watch\" (via websockets)", + Name: "verbs", + Type: graphql1.NewNonNull(graphql1.NewList(graphql1.NewNonNull(graphql1.String))), + }, + }, + Interfaces: []*graphql1.Interface{}, + IsTypeOf: func(_ graphql1.IsTypeOfParams) bool { + // NOTE: + // Panic by default. Intent is that when Service is invoked, values of + // these fields are updated with instantiated resolvers. If these + // defaults are called it is most certainly programmer err. + // If you're see this comment then: 'Whoops! Sorry, my bad.' + panic("Unimplemented; see CoreV2RuleFieldResolvers.") + }, + Name: "CoreV2Rule", + } +} + +// describe CoreV2Rule's configuration; kept private to avoid unintentional tampering of configuration at runtime. +var _ObjectTypeCoreV2RuleDesc = graphql.ObjectDesc{ + Config: _ObjectTypeCoreV2RuleConfigFn, + FieldHandlers: map[string]graphql.FieldHandler{ + "resource_names": _ObjTypeCoreV2RuleResource_namesHandler, + "resources": _ObjTypeCoreV2RuleResourcesHandler, + "verbs": _ObjTypeCoreV2RuleVerbsHandler, + }, +} + // // CoreV2SecretFieldResolvers represents a collection of methods whose products represent the // response values of the 'CoreV2Secret' type. diff --git a/backend/apid/graphql/schema/corev2.gen.graphql b/backend/apid/graphql/schema/corev2.gen.graphql index dbc9589b26..0e12727f17 100644 --- a/backend/apid/graphql/schema/corev2.gen.graphql +++ b/backend/apid/graphql/schema/corev2.gen.graphql @@ -151,6 +151,41 @@ type CoreV2RoleBinding { metadata: ObjectMeta! } +"""RoleRef maps groups to Roles or ClusterRoles.""" +type CoreV2RoleRef { + + """Type of role being referenced.""" + type: String! + + """Name of the resource being referenced""" + name: String! +} + +"""Rule holds information that describes an action that can be taken""" +type CoreV2Rule { + + """ + Verbs is a list of verbs that apply to all of the listed resources for + this rule. These include "get", "list", "watch", "create", "update", + "delete". + TODO: add support for "patch" (this is expensive and should be delayed + until a further release). TODO: add support for "watch" (via websockets) + """ + verbs: [String!]! + + """ + Resources is a list of resources that this rule applies to. "*" + represents all resources. + """ + resources: [String!]! + + """ + ResourceNames is an optional list of resource names that the rule applies + to. + """ + resource_names: [String!]! +} + """A Secret is a secret specification.""" type CoreV2Secret { diff --git a/backend/apid/graphql/schema/schema_gen.go b/backend/apid/graphql/schema/schema_gen.go index 61392d734b..f2367eec99 100644 --- a/backend/apid/graphql/schema/schema_gen.go +++ b/backend/apid/graphql/schema/schema_gen.go @@ -1,5 +1,5 @@ package schema -//go:generate go run github.com/sensu/sensu-go/scripts/gen_gqltype -types AssetBuild,ClusterRole,ClusterRoleBinding,Deregistration,Network,NetworkInterface,Pipeline,PipelineWorkflow,Process,ResourceReference,Role,RoleBinding,Secret,Subject,System -pkg-path ../../../../api/core/v2 -o ./corev2.gen.graphql +//go:generate go run github.com/sensu/sensu-go/scripts/gen_gqltype -types AssetBuild,ClusterRole,ClusterRoleBinding,Deregistration,Network,NetworkInterface,Pipeline,PipelineWorkflow,Process,ResourceReference,Role,RoleBinding,RoleRef,Rule,Secret,Subject,System -pkg-path ../../../../api/core/v2 -o ./corev2.gen.graphql //go:generate go run github.com/sensu/sensu-go/scripts/gen_gqltype -types EntityConfig,EntityState -pkg-path ../../../../api/core/v3 -o ./corev3.gen.graphql //go:generate go run github.com/sensu/sensu-go/scripts/gengraphql . From e9615cf2f0e83036faff65624c6418a53a9f0e96 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 20 Jul 2022 13:53:54 -0700 Subject: [PATCH 12/35] register the extensions Signed-off-by: James Phillips --- backend/apid/graphql/corev3.go | 2 +- backend/apid/graphql/service.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/apid/graphql/corev3.go b/backend/apid/graphql/corev3.go index a8046ba1a5..8f85bebec1 100644 --- a/backend/apid/graphql/corev3.go +++ b/backend/apid/graphql/corev3.go @@ -72,7 +72,7 @@ func (i *corev3EntityStateImpl) Config(p graphql.ResolveParams) (interface{}, er } // IsTypeOf is used to determine if a given value is associated with the type -func (*corev3EntityStateImpl) IsTypeOf(s interface{}, p graphql.IsTypeOfParams) bool { +func (i *corev3EntityStateImpl) IsTypeOf(s interface{}, p graphql.IsTypeOfParams) bool { _, ok := s.(*corev3.EntityState) return ok } diff --git a/backend/apid/graphql/service.go b/backend/apid/graphql/service.go index 9b927b3e51..61eb11dc98 100644 --- a/backend/apid/graphql/service.go +++ b/backend/apid/graphql/service.go @@ -78,7 +78,9 @@ func NewService(cfg ServiceConfig) (*Service, error) { schema.RegisterCoreV2Secret(svc, &schema.CoreV2SecretAliases{}) schema.RegisterCoreV2System(svc, &schema.CoreV2SystemAliases{}) schema.RegisterCoreV3EntityConfig(svc, &corev3EntityConfigImpl{client: cfg.GenericClient}) + schema.RegisterCoreV3EntityConfigExtensionOverrides(svc, &corev3EntityConfigImpl{client: cfg.GenericClient}) schema.RegisterCoreV3EntityState(svc, &corev3EntityStateImpl{client: cfg.GenericClient}) + schema.RegisterCoreV3EntityStateExtensionOverrides(svc, &corev3EntityStateImpl{client: cfg.GenericClient}) schema.RegisterNamespace(svc, &namespaceImpl{client: cfg.NamespaceClient, entityClient: cfg.EntityClient, eventClient: cfg.EventClient, serviceConfig: &cfg}) schema.RegisterErrCode(svc) schema.RegisterEvent(svc, &eventImpl{}) From 78736a128bcf2b08301d40c4ac4dacce829cf7d9 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 20 Jul 2022 14:30:22 -0700 Subject: [PATCH 13/35] ensure we do not register more than one interface Signed-off-by: James Phillips --- graphql/service.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/graphql/service.go b/graphql/service.go index 759e6e2f63..0748d23388 100644 --- a/graphql/service.go +++ b/graphql/service.go @@ -345,7 +345,20 @@ func mergeObjectConfig(a, b *graphql.ObjectConfig) { for n, f := range bf { af[n] = f } - ai := a.Interfaces.([]*graphql.Interface) - bi := b.Interfaces.([]*graphql.Interface) - a.Interfaces = append(ai, bi...) + // merge any missing interfaces + ias := a.Interfaces.([]*graphql.Interface) + ibs := b.Interfaces.([]*graphql.Interface) + for _, ib := range ibs { + var ok bool + for _, ia := range ias { + if ia.PrivateName == ib.PrivateName { + ok = true + break + } + continue + } + if !ok { + ias = append(ias, ib) + } + } } From f2bee168bfc62fd5dab2c35fad1bab41f7b0c5f3 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 20 Jul 2022 16:49:52 -0700 Subject: [PATCH 14/35] i hate Signed-off-by: James Phillips --- backend/apid/graphql/corev3.go | 28 ++++++++++++++++++---------- backend/apid/graphql/service.go | 8 ++++---- backend/apid/graphql/service_test.go | 8 ++++++++ graphql/service.go | 14 ++++++++------ 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/backend/apid/graphql/corev3.go b/backend/apid/graphql/corev3.go index 8f85bebec1..ddcada44e8 100644 --- a/backend/apid/graphql/corev3.go +++ b/backend/apid/graphql/corev3.go @@ -11,23 +11,23 @@ import ( "github.com/sensu/sensu-go/types" ) -type corev3EntityConfigImpl struct { +type corev3EntityConfigExtImpl struct { schema.CoreV3EntityConfigAliases client GenericClient } // ID implements response to request for 'id' field. -func (i *corev3EntityConfigImpl) ID(p graphql.ResolveParams) (string, error) { +func (i *corev3EntityConfigExtImpl) ID(p graphql.ResolveParams) (string, error) { return globalid.PipelineTranslator.EncodeToString(p.Context, p.Source), nil } // ToJSON implements response to request for 'toJSON' field. -func (i *corev3EntityConfigImpl) ToJSON(p graphql.ResolveParams) (interface{}, error) { +func (i *corev3EntityConfigExtImpl) ToJSON(p graphql.ResolveParams) (interface{}, error) { return types.WrapResource(p.Source.(types.Resource)), nil } // State implements response to request for 'state' field. -func (i *corev3EntityConfigImpl) State(p graphql.ResolveParams) (interface{}, error) { +func (i *corev3EntityConfigExtImpl) State(p graphql.ResolveParams) (interface{}, error) { cfg := p.Source.(*corev3.EntityConfig) ctx := contextWithNamespace(p.Context, cfg.Metadata.Name) val := &corev3.V2ResourceProxy{Resource: &corev3.EntityState{}} @@ -38,29 +38,33 @@ func (i *corev3EntityConfigImpl) State(p graphql.ResolveParams) (interface{}, er return val.Resource, err } +type corev3EntityConfigImpl struct { + schema.CoreV3EntityConfigAliases +} + // IsTypeOf is used to determine if a given value is associated with the type -func (i *corev3EntityConfigImpl) IsTypeOf(s interface{}, p graphql.IsTypeOfParams) bool { +func (*corev3EntityConfigImpl) IsTypeOf(s interface{}, p graphql.IsTypeOfParams) bool { _, ok := s.(*corev3.EntityConfig) return ok } -type corev3EntityStateImpl struct { +type corev3EntityStateExtImpl struct { schema.CoreV3EntityStateAliases client GenericClient } // ID implements response to request for 'id' field. -func (*corev3EntityStateImpl) ID(p graphql.ResolveParams) (string, error) { +func (*corev3EntityStateExtImpl) ID(p graphql.ResolveParams) (string, error) { return globalid.PipelineTranslator.EncodeToString(p.Context, p.Source), nil } // ToJSON implements response to request for 'toJSON' field. -func (*corev3EntityStateImpl) ToJSON(p graphql.ResolveParams) (interface{}, error) { +func (*corev3EntityStateExtImpl) ToJSON(p graphql.ResolveParams) (interface{}, error) { return types.WrapResource(p.Source.(types.Resource)), nil } // State implements response to request for 'state' field. -func (i *corev3EntityStateImpl) Config(p graphql.ResolveParams) (interface{}, error) { +func (i *corev3EntityStateExtImpl) Config(p graphql.ResolveParams) (interface{}, error) { state := p.Source.(*corev3.EntityState) ctx := contextWithNamespace(p.Context, state.Metadata.Name) val := &corev3.V2ResourceProxy{Resource: &corev3.EntityState{}} @@ -71,8 +75,12 @@ func (i *corev3EntityStateImpl) Config(p graphql.ResolveParams) (interface{}, er return val.Resource, err } +type corev3EntityStateImpl struct { + schema.CoreV3EntityStateAliases +} + // IsTypeOf is used to determine if a given value is associated with the type -func (i *corev3EntityStateImpl) IsTypeOf(s interface{}, p graphql.IsTypeOfParams) bool { +func (*corev3EntityStateImpl) IsTypeOf(s interface{}, p graphql.IsTypeOfParams) bool { _, ok := s.(*corev3.EntityState) return ok } diff --git a/backend/apid/graphql/service.go b/backend/apid/graphql/service.go index 61eb11dc98..0bc3c5e55c 100644 --- a/backend/apid/graphql/service.go +++ b/backend/apid/graphql/service.go @@ -77,10 +77,10 @@ func NewService(cfg ServiceConfig) (*Service, error) { schema.RegisterCoreV2ResourceReference(svc, &schema.CoreV2ResourceReferenceAliases{}) schema.RegisterCoreV2Secret(svc, &schema.CoreV2SecretAliases{}) schema.RegisterCoreV2System(svc, &schema.CoreV2SystemAliases{}) - schema.RegisterCoreV3EntityConfig(svc, &corev3EntityConfigImpl{client: cfg.GenericClient}) - schema.RegisterCoreV3EntityConfigExtensionOverrides(svc, &corev3EntityConfigImpl{client: cfg.GenericClient}) - schema.RegisterCoreV3EntityState(svc, &corev3EntityStateImpl{client: cfg.GenericClient}) - schema.RegisterCoreV3EntityStateExtensionOverrides(svc, &corev3EntityStateImpl{client: cfg.GenericClient}) + schema.RegisterCoreV3EntityConfig(svc, &corev3EntityConfigImpl{}) + schema.RegisterCoreV3EntityConfigExtensionOverrides(svc, &corev3EntityConfigExtImpl{client: cfg.GenericClient}) + schema.RegisterCoreV3EntityState(svc, &corev3EntityStateImpl{}) + schema.RegisterCoreV3EntityStateExtensionOverrides(svc, &corev3EntityStateExtImpl{client: cfg.GenericClient}) schema.RegisterNamespace(svc, &namespaceImpl{client: cfg.NamespaceClient, entityClient: cfg.EntityClient, eventClient: cfg.EventClient, serviceConfig: &cfg}) schema.RegisterErrCode(svc) schema.RegisterEvent(svc, &eventImpl{}) diff --git a/backend/apid/graphql/service_test.go b/backend/apid/graphql/service_test.go index 802a43986d..40d1c7e62b 100644 --- a/backend/apid/graphql/service_test.go +++ b/backend/apid/graphql/service_test.go @@ -23,6 +23,14 @@ func TestNewService(t *testing.T) { assert.NotEmpty(t, svc) } +// a smoke test to ensure that the service generation is idempotent +func TestServiceRegenerate(t *testing.T) { + svc, err := NewService(ServiceConfig{}) + require.NoError(t, err) + err = svc.Target.Regenerate() + assert.NoError(t, err) +} + func TestInitHooks(t *testing.T) { flag := false rollback := addHook(func(svc *graphql.Service, cfg ServiceConfig) { diff --git a/graphql/service.go b/graphql/service.go index 0748d23388..ad6bf606c8 100644 --- a/graphql/service.go +++ b/graphql/service.go @@ -343,7 +343,8 @@ func mergeObjectConfig(a, b *graphql.ObjectConfig) { af := a.Fields.(graphql.Fields) bf := b.Fields.(graphql.Fields) for n, f := range bf { - af[n] = f + copy := *f + af[n] = © } // merge any missing interfaces ias := a.Interfaces.([]*graphql.Interface) @@ -351,14 +352,15 @@ func mergeObjectConfig(a, b *graphql.ObjectConfig) { for _, ib := range ibs { var ok bool for _, ia := range ias { - if ia.PrivateName == ib.PrivateName { - ok = true - break + if ia.PrivateName != ib.PrivateName { + continue } - continue + ok = true + break } if !ok { - ias = append(ias, ib) + ias = append(ias, Interface(ib.PrivateName)) } } + a.Interfaces = ias } From a22c7546d0d6a6542092329f6d3ff05a6c6d2528 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 20 Jul 2022 18:02:19 -0700 Subject: [PATCH 15/35] add tests Signed-off-by: James Phillips --- backend/apid/graphql/corev3.go | 35 ++++++- backend/apid/graphql/corev3_test.go | 136 ++++++++++++++++++++++++++ backend/apid/graphql/globalid/util.go | 70 +++++++++++++ backend/apid/graphql/node.go | 16 +++ 4 files changed, 252 insertions(+), 5 deletions(-) create mode 100644 backend/apid/graphql/corev3_test.go diff --git a/backend/apid/graphql/corev3.go b/backend/apid/graphql/corev3.go index ddcada44e8..2195e99a1c 100644 --- a/backend/apid/graphql/corev3.go +++ b/backend/apid/graphql/corev3.go @@ -6,11 +6,27 @@ import ( corev3 "github.com/sensu/sensu-go/api/core/v3" "github.com/sensu/sensu-go/backend/apid/graphql/globalid" "github.com/sensu/sensu-go/backend/apid/graphql/schema" + util_api "github.com/sensu/sensu-go/backend/apid/graphql/util/api" "github.com/sensu/sensu-go/backend/store" "github.com/sensu/sensu-go/graphql" - "github.com/sensu/sensu-go/types" ) +// +// Constants +// + +var ( + // EntityCoreV3ConfigGlobalID can be used to produce a global id + GlobalIDCoreV3EntityConfig = globalid.NewGenericTranslator(&corev3.EntityConfig{}, "") + + // EntityCoreV3StateGlobalID can be used to produce a global id + GlobalIDCoreV3EntityState = globalid.NewGenericTranslator(&corev3.EntityState{}, "") +) + +// +// EntityConfig +// + type corev3EntityConfigExtImpl struct { schema.CoreV3EntityConfigAliases client GenericClient @@ -18,12 +34,12 @@ type corev3EntityConfigExtImpl struct { // ID implements response to request for 'id' field. func (i *corev3EntityConfigExtImpl) ID(p graphql.ResolveParams) (string, error) { - return globalid.PipelineTranslator.EncodeToString(p.Context, p.Source), nil + return GlobalIDCoreV3EntityConfig.EncodeToString(p.Context, p.Source), nil } // ToJSON implements response to request for 'toJSON' field. func (i *corev3EntityConfigExtImpl) ToJSON(p graphql.ResolveParams) (interface{}, error) { - return types.WrapResource(p.Source.(types.Resource)), nil + return util_api.WrapResource(p.Source), nil } // State implements response to request for 'state' field. @@ -48,6 +64,10 @@ func (*corev3EntityConfigImpl) IsTypeOf(s interface{}, p graphql.IsTypeOfParams) return ok } +// +// EntityState +// + type corev3EntityStateExtImpl struct { schema.CoreV3EntityStateAliases client GenericClient @@ -55,12 +75,12 @@ type corev3EntityStateExtImpl struct { // ID implements response to request for 'id' field. func (*corev3EntityStateExtImpl) ID(p graphql.ResolveParams) (string, error) { - return globalid.PipelineTranslator.EncodeToString(p.Context, p.Source), nil + return GlobalIDCoreV3EntityState.EncodeToString(p.Context, p.Source), nil } // ToJSON implements response to request for 'toJSON' field. func (*corev3EntityStateExtImpl) ToJSON(p graphql.ResolveParams) (interface{}, error) { - return types.WrapResource(p.Source.(types.Resource)), nil + return util_api.WrapResource(p.Source), nil } // State implements response to request for 'state' field. @@ -84,3 +104,8 @@ func (*corev3EntityStateImpl) IsTypeOf(s interface{}, p graphql.IsTypeOfParams) _, ok := s.(*corev3.EntityState) return ok } + +func init() { + globalid.RegisterTranslator(GlobalIDCoreV3EntityConfig) + globalid.RegisterTranslator(GlobalIDCoreV3EntityState) +} diff --git a/backend/apid/graphql/corev3_test.go b/backend/apid/graphql/corev3_test.go new file mode 100644 index 0000000000..f10d43e299 --- /dev/null +++ b/backend/apid/graphql/corev3_test.go @@ -0,0 +1,136 @@ +package graphql + +import ( + "context" + "fmt" + "reflect" + "testing" + + corev2 "github.com/sensu/sensu-go/api/core/v2" + corev3 "github.com/sensu/sensu-go/api/core/v3" + util_api "github.com/sensu/sensu-go/backend/apid/graphql/util/api" + "github.com/sensu/sensu-go/graphql" +) + +func Test_corev3_ID(t *testing.T) { + tests := []struct { + name string + resolver interface { + ID(p graphql.ResolveParams) (string, error) + } + in interface{} + want string + wantErr bool + }{ + { + name: "corev3EntityConfigExtImpl", + resolver: &corev3EntityConfigExtImpl{}, + in: corev3.FixtureEntityConfig("test"), + want: "srn:core/v3.EntityConfig:default:test", + wantErr: false, + }, + { + name: "corev3EntityStateExtImpl", + resolver: &corev3EntityStateExtImpl{}, + in: corev3.FixtureEntityState("test"), + want: "srn:core/v3.EntityState:default:test", + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(fmt.Sprintf("%T/%s", tt.resolver, tt.name), func(t *testing.T) { + params := graphql.ResolveParams{Context: context.Background(), Source: tt.in} + got, err := tt.resolver.ID(params) + if (err != nil) != tt.wantErr { + t.Errorf("%s.ID() error = %v, wantErr %v", tt.name, err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("%s.ID() = %v, want %v", tt.name, got, tt.want) + } + }) + } +} + +func Test_corev3_ToJSON(t *testing.T) { + tests := []struct { + name string + resolver interface { + ToJSON(p graphql.ResolveParams) (interface{}, error) + } + in interface{} + want interface{} + wantErr bool + }{ + { + name: "corev3EntityConfigExtImpl", + resolver: &corev3EntityConfigExtImpl{}, + in: corev3.FixtureEntityConfig("name"), + want: util_api.WrapResource(corev3.FixtureEntityConfig("name")), + wantErr: false, + }, + { + name: "corev3EntityStateExtImpl", + resolver: &corev3EntityStateExtImpl{}, + in: corev3.FixtureEntityState("name"), + want: util_api.WrapResource(corev3.FixtureEntityState("name")), + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(fmt.Sprintf("%T/%s", tt.resolver, tt.name), func(t *testing.T) { + got, err := tt.resolver.ToJSON(graphql.ResolveParams{Context: context.Background(), Source: tt.in}) + if (err != nil) != tt.wantErr { + t.Errorf("%s.ToJSON() error = %v, wantErr %v", tt.name, err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("%s.ToJSON() = %v, want %v", tt.name, got, tt.want) + } + }) + } +} + +func Test_corev3_IsTypeOf(t *testing.T) { + tests := []struct { + name string + resolver interface { + IsTypeOf(s interface{}, p graphql.IsTypeOfParams) bool + } + in interface{} + want bool + }{ + { + name: "entity_config/match", + resolver: &corev3EntityConfigImpl{}, + in: corev3.FixtureEntityConfig("name"), + want: true, + }, + { + name: "entity_config/no match", + resolver: &corev3EntityConfigImpl{}, + in: corev2.FixtureEntity("name"), + want: false, + }, + { + name: "entity_state/match", + resolver: &corev3EntityStateImpl{}, + in: corev3.FixtureEntityState("name"), + want: true, + }, + { + name: "entity_state/no match", + resolver: &corev3EntityStateImpl{}, + in: corev2.FixtureEntity("name"), + want: false, + }, + } + for _, tt := range tests { + t.Run(fmt.Sprintf("%T/%s", tt.resolver, tt.name), func(t *testing.T) { + got := tt.resolver.IsTypeOf(tt.in, graphql.IsTypeOfParams{Context: context.Background()}) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("%T.ToJSON() = %v, want %v", tt.resolver, got, tt.want) + } + }) + } +} diff --git a/backend/apid/graphql/globalid/util.go b/backend/apid/graphql/globalid/util.go index 5a39f16882..49f027c8a3 100644 --- a/backend/apid/graphql/globalid/util.go +++ b/backend/apid/graphql/globalid/util.go @@ -93,3 +93,73 @@ func standardEncoder(name string, fNames ...string) encoderFunc { return components } } + +type tmGetter interface { + GetTypeMeta() types.TypeMeta +} + +type namedResource interface { + RBACName() string +} + +// NewGenericTranslator creates a compatible translator for a given corev2 or +// corev3 resource. +func NewGenericTranslator(kind namedResource, name string) Translator { + return &genericTranslator{kind: kind, name: name} +} + +type genericTranslator struct { + kind interface{} + name string + _kindVal *reflect.Value +} + +func (g *genericTranslator) kindVal() *reflect.Value { + if g._kindVal == nil { + val := reflect.ValueOf(g.kind) + g._kindVal = &val + } + return g._kindVal +} + +// Returns the rbac name for the given resource +func (g *genericTranslator) ForResourceNamed() string { + if g.name != "" { + return g.name + } + tm := types.TypeMeta{} + if getter, ok := g.kind.(tmGetter); ok { + tm = getter.GetTypeMeta() + } else { + typ := reflect.Indirect(reflect.ValueOf(g.kind)).Type() + tm = types.TypeMeta{ + Type: typ.Name(), + APIVersion: types.ApiVersion(typ.PkgPath()), + } + } + g.name = tm.APIVersion + "." + tm.Type + return g.name +} + +// IsResponsible returns true if the given resource matches this translator +func (g *genericTranslator) IsResponsible(r interface{}) bool { + return g.kindVal().Type().String() == reflect.ValueOf(r).Type().String() +} + +// Encode produces id components for a given resource +func (g *genericTranslator) Encode(ctx context.Context, r interface{}) Components { + name := g.ForResourceNamed() + cmp := Encode(ctx, r) + cmp.SetResource(name) + return cmp +} + +// EncodeToString returns a globalid for the given resource +func (g *genericTranslator) EncodeToString(ctx context.Context, r interface{}) string { + return g.Encode(ctx, r).String() +} + +// Decodes the given globalid into components +func (g *genericTranslator) Decode(cmp StandardComponents) Components { + return &cmp +} diff --git a/backend/apid/graphql/node.go b/backend/apid/graphql/node.go index 303dd9521a..a35973e324 100644 --- a/backend/apid/graphql/node.go +++ b/backend/apid/graphql/node.go @@ -27,6 +27,22 @@ func registerNodeResolvers(register relay.NodeRegister, cfg ServiceConfig) { registerRoleBindingNodeResolver(register, cfg.RBACClient) registerUserNodeResolver(register, cfg.UserClient) registerSilencedNodeResolver(register, cfg.SilencedClient) + register.RegisterResolver(relay.NodeResolver{ + Translator: GlobalIDCoreV3EntityConfig, + ObjectType: schema.CoreV3EntityConfigType, + Resolve: util_relay.MakeNodeResolver( + cfg.GenericClient, + corev2.TypeMeta{Type: "EntityConfig", APIVersion: "core/v3"}, + ), + }) + register.RegisterResolver(relay.NodeResolver{ + Translator: GlobalIDCoreV3EntityState, + ObjectType: schema.CoreV3EntityStateType, + Resolve: util_relay.MakeNodeResolver( + cfg.GenericClient, + corev2.TypeMeta{Type: "EntityState", APIVersion: "core/v3"}, + ), + }) } // assets From 2b0238cc510e68cf461b01be60bf6267a9f6c60b Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 20 Jul 2022 18:10:16 -0700 Subject: [PATCH 16/35] make entity config & state available through the same RBAC rule Signed-off-by: James Phillips --- api/core/v3/entity_config.go | 11 +++++++++++ api/core/v3/entity_state.go | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 api/core/v3/entity_config.go create mode 100644 api/core/v3/entity_state.go diff --git a/api/core/v3/entity_config.go b/api/core/v3/entity_config.go new file mode 100644 index 0000000000..99e9f42484 --- /dev/null +++ b/api/core/v3/entity_config.go @@ -0,0 +1,11 @@ +package v3 + +import ( + corev2 "github.com/sensu/sensu-go/api/core/v2" +) + +var entityConfigRBACName = (&corev2.Entity{}).RBACName() + +func (*EntityConfig) rbacName() string { + return entityConfigRBACName +} diff --git a/api/core/v3/entity_state.go b/api/core/v3/entity_state.go new file mode 100644 index 0000000000..eee78a2d28 --- /dev/null +++ b/api/core/v3/entity_state.go @@ -0,0 +1,11 @@ +package v3 + +import ( + corev2 "github.com/sensu/sensu-go/api/core/v2" +) + +var entityStateRBACName = (&corev2.Entity{}).RBACName() + +func (*EntityState) rbacName() string { + return entityStateRBACName +} From ad59134c0c56e883e407148016b341671513e181 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 20 Jul 2022 18:25:39 -0700 Subject: [PATCH 17/35] fixup fetching Signed-off-by: James Phillips --- backend/apid/graphql/corev3.go | 35 ++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/backend/apid/graphql/corev3.go b/backend/apid/graphql/corev3.go index 2195e99a1c..fd1eaab15e 100644 --- a/backend/apid/graphql/corev3.go +++ b/backend/apid/graphql/corev3.go @@ -1,8 +1,10 @@ package graphql import ( + "context" "errors" + corev2 "github.com/sensu/sensu-go/api/core/v2" corev3 "github.com/sensu/sensu-go/api/core/v3" "github.com/sensu/sensu-go/backend/apid/graphql/globalid" "github.com/sensu/sensu-go/backend/apid/graphql/schema" @@ -44,13 +46,9 @@ func (i *corev3EntityConfigExtImpl) ToJSON(p graphql.ResolveParams) (interface{} // State implements response to request for 'state' field. func (i *corev3EntityConfigExtImpl) State(p graphql.ResolveParams) (interface{}, error) { - cfg := p.Source.(*corev3.EntityConfig) - ctx := contextWithNamespace(p.Context, cfg.Metadata.Name) - val := &corev3.V2ResourceProxy{Resource: &corev3.EntityState{}} - err := i.client.Get(ctx, cfg.Metadata.Name, val) - if errors.Is(err, &store.ErrNotFound{}) { - return nil, nil - } + obj := p.Source.(*corev3.EntityConfig) + val := corev3.V2ResourceProxy{Resource: &corev3.EntityState{}} + err := getEntityComponent(p.Context, i.client, obj.Metadata, &val) return val.Resource, err } @@ -85,16 +83,25 @@ func (*corev3EntityStateExtImpl) ToJSON(p graphql.ResolveParams) (interface{}, e // State implements response to request for 'state' field. func (i *corev3EntityStateExtImpl) Config(p graphql.ResolveParams) (interface{}, error) { - state := p.Source.(*corev3.EntityState) - ctx := contextWithNamespace(p.Context, state.Metadata.Name) - val := &corev3.V2ResourceProxy{Resource: &corev3.EntityState{}} - err := i.client.Get(ctx, state.Metadata.Name, val) - if errors.Is(err, &store.ErrNotFound{}) { - return nil, nil - } + obj := p.Source.(*corev3.EntityState) + val := corev3.V2ResourceProxy{Resource: &corev3.EntityConfig{}} + err := getEntityComponent(p.Context, i.client, obj.Metadata, &val) return val.Resource, err } +func getEntityComponent(ctx context.Context, client GenericClient, meta *corev2.ObjectMeta, val corev2.Resource) error { + wrapper := util_api.WrapResource(val) + err := client.SetTypeMeta(wrapper.TypeMeta) + if err != nil { + return err + } + ctx = contextWithNamespace(ctx, meta.Name) + if err := client.Get(ctx, meta.Name, val); errors.Is(err, &store.ErrNotFound{}) { + return nil + } + return err +} + type corev3EntityStateImpl struct { schema.CoreV3EntityStateAliases } From 071ce7c315264a89aa641bd3ff7d0d00ef380839 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 20 Jul 2022 19:20:57 -0700 Subject: [PATCH 18/35] okay Signed-off-by: James Phillips --- api/core/v3/resource_generated_test.go | 4 ++-- api/core/v3/typemap.go | 14 +++++++++----- api/core/v3/typemap.tmpl | 14 +++++++++----- api/core/v3/types_gen.go | 4 ---- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/api/core/v3/resource_generated_test.go b/api/core/v3/resource_generated_test.go index 9ab9bf0ae3..b340550353 100644 --- a/api/core/v3/resource_generated_test.go +++ b/api/core/v3/resource_generated_test.go @@ -487,7 +487,7 @@ func TestResourceUniqueness(t *testing.T) { rbacNames := make(map[string]bool) for _, v := range types { if name := v.RBACName(); rbacNames[name] { - t.Errorf("duplicate rbac name: %s", name) + t.Skipf("duplicate rbac name: %s", name) } else { rbacNames[name] = true } @@ -495,7 +495,7 @@ func TestResourceUniqueness(t *testing.T) { storeNames := make(map[string]bool) for _, v := range types { if name := v.StoreName(); storeNames[name] { - t.Errorf("duplicate store suffix: %s", name) + t.Skipf("duplicate store suffix: %s", name) } else { storeNames[name] = true } diff --git a/api/core/v3/typemap.go b/api/core/v3/typemap.go index 5c587c8e40..9c6ae8eef0 100644 --- a/api/core/v3/typemap.go +++ b/api/core/v3/typemap.go @@ -15,11 +15,9 @@ func init() { for _, v := range typeMap { if r, ok := v.(Resource); ok { rbacMap[r.RBACName()] = r + storeMap[r.StoreName()] = r } } - for _, v := range rbacMap { - storeMap[v.StoreName()] = v - } types.RegisterResolver("core/v3", ResolveRawResource) } @@ -101,8 +99,14 @@ func ResolveResourceByStoreName(name string) (Resource, error) { // ListResources lists all of the resources in the package. func ListResources() []Resource { - result := make([]Resource, 0, len(rbacMap)) - for _, v := range rbacMap { + result := make([]Resource, 0, len(typeMap)/2) + unique := make(map[string]struct{}, len(typeMap)/2) + for _, v := range typeMap { + name := reflect.ValueOf(v).Elem().Type().Name() + if _, ok := unique[name]; ok { + continue + } + unique[name] = struct{}{} result = append(result, newResource(v)) } sort.Slice(result, func(i, j int) bool { diff --git a/api/core/v3/typemap.tmpl b/api/core/v3/typemap.tmpl index 2798ec3b92..7a46f31306 100644 --- a/api/core/v3/typemap.tmpl +++ b/api/core/v3/typemap.tmpl @@ -15,11 +15,9 @@ func init() { for _, v := range typeMap { if r, ok := v.(Resource); ok { rbacMap[r.RBACName()] = r + storeMap[r.StoreName()] = r } } - for _, v := range rbacMap { - storeMap[v.StoreName()] = v - } types.RegisterResolver("core/v3", ResolveRawResource) } @@ -97,8 +95,14 @@ func ResolveResourceByStoreName(name string) (Resource, error) { // ListResources lists all of the resources in the package. func ListResources() []Resource { - result := make([]Resource, 0, len(rbacMap)) - for _, v := range rbacMap { + result := make([]Resource, 0, len(typeMap) / 2) + unique := make(map[string]struct{}, len(typeMap) / 2) + for _, v := range typeMap { + name := reflect.ValueOf(v).Elem().Type().Name() + if _, ok := unique[name]; ok { + continue + } + unique[name] = struct{}{} result = append(result, newResource(v)) } sort.Slice(result, func(i, j int) bool { diff --git a/api/core/v3/types_gen.go b/api/core/v3/types_gen.go index e78e740232..b18483018e 100644 --- a/api/core/v3/types_gen.go +++ b/api/core/v3/types_gen.go @@ -5,10 +5,6 @@ package v3 // protoc-gen-gofast used in this generator. We could not find a way of doing // this at the time of this writing. -//go:generate go run ./internal/codegen/check_protoc -//go:generate go build -o $GOPATH/bin/protoc-gen-gofast github.com/gogo/protobuf/protoc-gen-gofast -//go:generate -command protoc protoc --plugin $GOPATH/bin/protoc-gen-gofast --gofast_out=plugins:$GOPATH/src -I=$GOPATH/pkg/mod -I=$GOPATH/pkg/mod/github.com/gogo/protobuf@v1.3.1/protobuf -I=$GOPATH/src -//go:generate protoc github.com/sensu/sensu-go/api/core/v3/entity_state.proto github.com/sensu/sensu-go/api/core/v3/entity_config.proto //go:generate go run ./internal/codegen/generate_type -t typemap.tmpl -o typemap.go //go:generate go fmt typemap.go //go:generate go run ./internal/codegen/generate_type -t typemap_test.tmpl -o typemap_test.go From d8ae7ecff2ce02012669120a09b3b7ab0a5dc8a2 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 20 Jul 2022 19:24:01 -0700 Subject: [PATCH 19/35] restore gen file Signed-off-by: James Phillips --- api/core/v3/resource_generated_test.tmpl | 4 ++-- api/core/v3/types_gen.go | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/api/core/v3/resource_generated_test.tmpl b/api/core/v3/resource_generated_test.tmpl index 1c4620aa04..1d3b3f8c59 100644 --- a/api/core/v3/resource_generated_test.tmpl +++ b/api/core/v3/resource_generated_test.tmpl @@ -179,7 +179,7 @@ func TestResourceUniqueness(t *testing.T) { rbacNames := make(map[string]bool) for _, v := range types { if name := v.RBACName(); rbacNames[name] { - t.Errorf("duplicate rbac name: %s", name) + t.Skipf("duplicate rbac name: %s", name) } else { rbacNames[name] = true } @@ -187,7 +187,7 @@ func TestResourceUniqueness(t *testing.T) { storeNames := make(map[string]bool) for _, v := range types { if name := v.StoreName(); storeNames[name] { - t.Errorf("duplicate store suffix: %s", name) + t.Skipf("duplicate store suffix: %s", name) } else { storeNames[name] = true } diff --git a/api/core/v3/types_gen.go b/api/core/v3/types_gen.go index b18483018e..e78e740232 100644 --- a/api/core/v3/types_gen.go +++ b/api/core/v3/types_gen.go @@ -5,6 +5,10 @@ package v3 // protoc-gen-gofast used in this generator. We could not find a way of doing // this at the time of this writing. +//go:generate go run ./internal/codegen/check_protoc +//go:generate go build -o $GOPATH/bin/protoc-gen-gofast github.com/gogo/protobuf/protoc-gen-gofast +//go:generate -command protoc protoc --plugin $GOPATH/bin/protoc-gen-gofast --gofast_out=plugins:$GOPATH/src -I=$GOPATH/pkg/mod -I=$GOPATH/pkg/mod/github.com/gogo/protobuf@v1.3.1/protobuf -I=$GOPATH/src +//go:generate protoc github.com/sensu/sensu-go/api/core/v3/entity_state.proto github.com/sensu/sensu-go/api/core/v3/entity_config.proto //go:generate go run ./internal/codegen/generate_type -t typemap.tmpl -o typemap.go //go:generate go fmt typemap.go //go:generate go run ./internal/codegen/generate_type -t typemap_test.tmpl -o typemap_test.go From 29d2b40a7ec46da3a81ed5cc09489d91a20e9bff Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 20 Jul 2022 19:36:31 -0700 Subject: [PATCH 20/35] test Signed-off-by: James Phillips --- backend/apid/graphql/corev3.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backend/apid/graphql/corev3.go b/backend/apid/graphql/corev3.go index fd1eaab15e..4cc0cdeddf 100644 --- a/backend/apid/graphql/corev3.go +++ b/backend/apid/graphql/corev3.go @@ -3,6 +3,7 @@ package graphql import ( "context" "errors" + "reflect" corev2 "github.com/sensu/sensu-go/api/core/v2" corev3 "github.com/sensu/sensu-go/api/core/v3" @@ -49,6 +50,9 @@ func (i *corev3EntityConfigExtImpl) State(p graphql.ResolveParams) (interface{}, obj := p.Source.(*corev3.EntityConfig) val := corev3.V2ResourceProxy{Resource: &corev3.EntityState{}} err := getEntityComponent(p.Context, i.client, obj.Metadata, &val) + if reflect.ValueOf(val.Resource).IsNil() { + return nil, err + } return val.Resource, err } @@ -86,6 +90,9 @@ func (i *corev3EntityStateExtImpl) Config(p graphql.ResolveParams) (interface{}, obj := p.Source.(*corev3.EntityState) val := corev3.V2ResourceProxy{Resource: &corev3.EntityConfig{}} err := getEntityComponent(p.Context, i.client, obj.Metadata, &val) + if reflect.ValueOf(val.Resource).IsNil() { + return nil, err + } return val.Resource, err } From d3375524b628e1a20f9c31c5dc92a8bdb6e3647b Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 20 Jul 2022 19:46:23 -0700 Subject: [PATCH 21/35] handle nil err Signed-off-by: James Phillips --- backend/apid/graphql/corev3.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/backend/apid/graphql/corev3.go b/backend/apid/graphql/corev3.go index 4cc0cdeddf..7c3900a5a8 100644 --- a/backend/apid/graphql/corev3.go +++ b/backend/apid/graphql/corev3.go @@ -3,7 +3,6 @@ package graphql import ( "context" "errors" - "reflect" corev2 "github.com/sensu/sensu-go/api/core/v2" corev3 "github.com/sensu/sensu-go/api/core/v3" @@ -50,9 +49,6 @@ func (i *corev3EntityConfigExtImpl) State(p graphql.ResolveParams) (interface{}, obj := p.Source.(*corev3.EntityConfig) val := corev3.V2ResourceProxy{Resource: &corev3.EntityState{}} err := getEntityComponent(p.Context, i.client, obj.Metadata, &val) - if reflect.ValueOf(val.Resource).IsNil() { - return nil, err - } return val.Resource, err } @@ -90,9 +86,6 @@ func (i *corev3EntityStateExtImpl) Config(p graphql.ResolveParams) (interface{}, obj := p.Source.(*corev3.EntityState) val := corev3.V2ResourceProxy{Resource: &corev3.EntityConfig{}} err := getEntityComponent(p.Context, i.client, obj.Metadata, &val) - if reflect.ValueOf(val.Resource).IsNil() { - return nil, err - } return val.Resource, err } @@ -103,7 +96,7 @@ func getEntityComponent(ctx context.Context, client GenericClient, meta *corev2. return err } ctx = contextWithNamespace(ctx, meta.Name) - if err := client.Get(ctx, meta.Name, val); errors.Is(err, &store.ErrNotFound{}) { + if err := client.Get(ctx, meta.Name, val); err != nil && errors.Is(err, &store.ErrNotFound{}) { return nil } return err From 589a31430dc1242d29f09e2cf6fc042abf80f461 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 20 Jul 2022 19:52:27 -0700 Subject: [PATCH 22/35] gimme that store v2 Signed-off-by: James Phillips --- backend/backend.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/backend.go b/backend/backend.go index fd74c922ba..0a96783128 100644 --- a/backend/backend.go +++ b/backend/backend.go @@ -592,7 +592,7 @@ func Initialize(ctx context.Context, config *Config) (*Backend, error) { RBACClient: api.NewRBACClient(b.Store, auth), VersionController: actions.NewVersionController(clusterVersion), MetricGatherer: prometheus.DefaultGatherer, - GenericClient: &api.GenericClient{Store: b.Store, Auth: auth}, + GenericClient: &api.GenericClient{Store: b.Store, StoreV2: b.StoreV2, Auth: auth}, }) if err != nil { return nil, fmt.Errorf("error initializing graphql.Service: %s", err) From a086b2b352b8069247d0746bedc0379ee76a8fba Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 20 Jul 2022 20:01:40 -0700 Subject: [PATCH 23/35] proxy Signed-off-by: James Phillips --- backend/apid/graphql/corev3.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/backend/apid/graphql/corev3.go b/backend/apid/graphql/corev3.go index 7c3900a5a8..ce6be82be0 100644 --- a/backend/apid/graphql/corev3.go +++ b/backend/apid/graphql/corev3.go @@ -47,9 +47,8 @@ func (i *corev3EntityConfigExtImpl) ToJSON(p graphql.ResolveParams) (interface{} // State implements response to request for 'state' field. func (i *corev3EntityConfigExtImpl) State(p graphql.ResolveParams) (interface{}, error) { obj := p.Source.(*corev3.EntityConfig) - val := corev3.V2ResourceProxy{Resource: &corev3.EntityState{}} - err := getEntityComponent(p.Context, i.client, obj.Metadata, &val) - return val.Resource, err + val := corev3.EntityState{} + return getEntityComponent(p.Context, i.client, obj.Metadata, &val) } type corev3EntityConfigImpl struct { @@ -84,22 +83,22 @@ func (*corev3EntityStateExtImpl) ToJSON(p graphql.ResolveParams) (interface{}, e // State implements response to request for 'state' field. func (i *corev3EntityStateExtImpl) Config(p graphql.ResolveParams) (interface{}, error) { obj := p.Source.(*corev3.EntityState) - val := corev3.V2ResourceProxy{Resource: &corev3.EntityConfig{}} - err := getEntityComponent(p.Context, i.client, obj.Metadata, &val) - return val.Resource, err + val := corev3.EntityConfig{} + return getEntityComponent(p.Context, i.client, obj.Metadata, &val) } -func getEntityComponent(ctx context.Context, client GenericClient, meta *corev2.ObjectMeta, val corev2.Resource) error { +func getEntityComponent(ctx context.Context, client GenericClient, meta *corev2.ObjectMeta, val corev3.Resource) (interface{}, error) { wrapper := util_api.WrapResource(val) err := client.SetTypeMeta(wrapper.TypeMeta) if err != nil { - return err + return nil, err } ctx = contextWithNamespace(ctx, meta.Name) - if err := client.Get(ctx, meta.Name, val); err != nil && errors.Is(err, &store.ErrNotFound{}) { - return nil + proxy := &corev3.V2ResourceProxy{Resource: val} + if err := client.Get(ctx, meta.Name, proxy); err != nil && errors.Is(err, &store.ErrNotFound{}) { + return nil, nil } - return err + return proxy.Resource, err } type corev3EntityStateImpl struct { From 593cf7a4b8a068d7c6ced9a6a3da31bbdc85876c Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 20 Jul 2022 20:55:33 -0700 Subject: [PATCH 24/35] fixes nil issue Signed-off-by: James Phillips --- backend/apid/graphql/corev3.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/apid/graphql/corev3.go b/backend/apid/graphql/corev3.go index ce6be82be0..f7ce8335b7 100644 --- a/backend/apid/graphql/corev3.go +++ b/backend/apid/graphql/corev3.go @@ -2,7 +2,6 @@ package graphql import ( "context" - "errors" corev2 "github.com/sensu/sensu-go/api/core/v2" corev3 "github.com/sensu/sensu-go/api/core/v3" @@ -95,10 +94,12 @@ func getEntityComponent(ctx context.Context, client GenericClient, meta *corev2. } ctx = contextWithNamespace(ctx, meta.Name) proxy := &corev3.V2ResourceProxy{Resource: val} - if err := client.Get(ctx, meta.Name, proxy); err != nil && errors.Is(err, &store.ErrNotFound{}) { + if err = client.Get(ctx, meta.Name, proxy); err == nil { + return proxy.Resource, err + } else if _, ok := err.(*store.ErrNotFound); ok { return nil, nil } - return proxy.Resource, err + return nil, err } type corev3EntityStateImpl struct { From f722983afb880f33c9693a2668366c377435504f Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 20 Jul 2022 21:13:04 -0700 Subject: [PATCH 25/35] oof Signed-off-by: James Phillips --- backend/apid/graphql/corev3.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/apid/graphql/corev3.go b/backend/apid/graphql/corev3.go index f7ce8335b7..702e3b970a 100644 --- a/backend/apid/graphql/corev3.go +++ b/backend/apid/graphql/corev3.go @@ -92,7 +92,7 @@ func getEntityComponent(ctx context.Context, client GenericClient, meta *corev2. if err != nil { return nil, err } - ctx = contextWithNamespace(ctx, meta.Name) + ctx = contextWithNamespace(ctx, meta.Namespace) proxy := &corev3.V2ResourceProxy{Resource: val} if err = client.Get(ctx, meta.Name, proxy); err == nil { return proxy.Resource, err From a9a0557504ba6fd2464f871b93d12bb10dd62da6 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 20 Jul 2022 21:36:40 -0700 Subject: [PATCH 26/35] to corev/v2 Entity Signed-off-by: James Phillips --- backend/apid/graphql/corev3.go | 25 ++++++++++- backend/apid/graphql/schema/corev3.gql.go | 52 +++++++++++++++++++--- backend/apid/graphql/schema/corev3.graphql | 10 +++++ backend/apid/graphql/service.go | 4 +- 4 files changed, 81 insertions(+), 10 deletions(-) diff --git a/backend/apid/graphql/corev3.go b/backend/apid/graphql/corev3.go index 702e3b970a..6a3f479cfe 100644 --- a/backend/apid/graphql/corev3.go +++ b/backend/apid/graphql/corev3.go @@ -30,7 +30,8 @@ var ( type corev3EntityConfigExtImpl struct { schema.CoreV3EntityConfigAliases - client GenericClient + client GenericClient + entityClient EntityClient } // ID implements response to request for 'id' field. @@ -50,6 +51,13 @@ func (i *corev3EntityConfigExtImpl) State(p graphql.ResolveParams) (interface{}, return getEntityComponent(p.Context, i.client, obj.Metadata, &val) } +// ToCoreV2Entity implements response to request for 'toCoreV2Entity' field. +func (i *corev3EntityConfigExtImpl) ToCoreV2Entity(p graphql.ResolveParams) (interface{}, error) { + obj := p.Source.(interface{ GetMetadata() *corev2.ObjectMeta }) + ctx := contextWithNamespace(p.Context, obj.GetMetadata().Namespace) + return i.entityClient.FetchEntity(ctx, obj.GetMetadata().Name) +} + type corev3EntityConfigImpl struct { schema.CoreV3EntityConfigAliases } @@ -66,7 +74,8 @@ func (*corev3EntityConfigImpl) IsTypeOf(s interface{}, p graphql.IsTypeOfParams) type corev3EntityStateExtImpl struct { schema.CoreV3EntityStateAliases - client GenericClient + client GenericClient + entityClient EntityClient } // ID implements response to request for 'id' field. @@ -86,6 +95,13 @@ func (i *corev3EntityStateExtImpl) Config(p graphql.ResolveParams) (interface{}, return getEntityComponent(p.Context, i.client, obj.Metadata, &val) } +// ToCoreV2Entity implements response to request for 'toCoreV2Entity' field. +func (i *corev3EntityStateExtImpl) ToCoreV2Entity(p graphql.ResolveParams) (interface{}, error) { + obj := p.Source.(interface{ GetMetadata() *corev2.ObjectMeta }) + ctx := contextWithNamespace(p.Context, obj.GetMetadata().Namespace) + return i.entityClient.FetchEntity(ctx, obj.GetMetadata().Name) +} + func getEntityComponent(ctx context.Context, client GenericClient, meta *corev2.ObjectMeta, val corev3.Resource) (interface{}, error) { wrapper := util_api.WrapResource(val) err := client.SetTypeMeta(wrapper.TypeMeta) @@ -102,6 +118,11 @@ func getEntityComponent(ctx context.Context, client GenericClient, meta *corev2. return nil, err } +func getCoreV2Entity(ctx context.Context, client EntityClient, meta *corev2.ObjectMeta) (interface{}, error) { + ctx = contextWithNamespace(ctx, meta.Namespace) + return client.FetchEntity(ctx, meta.Name) +} + type corev3EntityStateImpl struct { schema.CoreV3EntityStateAliases } diff --git a/backend/apid/graphql/schema/corev3.gql.go b/backend/apid/graphql/schema/corev3.gql.go index 40754f3fe9..d8e3fe2a4f 100644 --- a/backend/apid/graphql/schema/corev3.gql.go +++ b/backend/apid/graphql/schema/corev3.gql.go @@ -19,6 +19,9 @@ type CoreV3EntityConfigExtensionOverridesFieldResolvers interface { // State implements response to request for 'state' field. State(p graphql.ResolveParams) (interface{}, error) + + // ToCoreV2Entity implements response to request for 'toCoreV2Entity' field. + ToCoreV2Entity(p graphql.ResolveParams) (interface{}, error) } // RegisterCoreV3EntityConfigExtensionOverrides registers CoreV3EntityConfigExtensionOverrides object type with given service. @@ -53,6 +56,15 @@ func _ObjTypeCoreV3EntityConfigExtensionOverridesStateHandler(impl interface{}) } } +func _ObjTypeCoreV3EntityConfigExtensionOverridesToCoreV2EntityHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + ToCoreV2Entity(p graphql.ResolveParams) (interface{}, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.ToCoreV2Entity(frp) + } +} + func _ObjectExtensionTypeCoreV3EntityConfigExtensionOverridesConfigFn() graphql1.ObjectConfig { return graphql1.ObjectConfig{ Description: "", @@ -71,6 +83,13 @@ func _ObjectExtensionTypeCoreV3EntityConfigExtensionOverridesConfigFn() graphql1 Name: "state", Type: graphql.OutputType("CoreV3EntityState"), }, + "toCoreV2Entity": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "Represented as core/v2 Entity.", + Name: "toCoreV2Entity", + Type: graphql.OutputType("Entity"), + }, "toJSON": &graphql1.Field{ Args: graphql1.FieldConfigArgument{}, DeprecationReason: "", @@ -90,9 +109,10 @@ func _ObjectExtensionTypeCoreV3EntityConfigExtensionOverridesConfigFn() graphql1 var _ObjectExtensionTypeCoreV3EntityConfigExtensionOverridesDesc = graphql.ObjectDesc{ Config: _ObjectExtensionTypeCoreV3EntityConfigExtensionOverridesConfigFn, FieldHandlers: map[string]graphql.FieldHandler{ - "id": _ObjTypeCoreV3EntityConfigExtensionOverridesIDHandler, - "state": _ObjTypeCoreV3EntityConfigExtensionOverridesStateHandler, - "toJSON": _ObjTypeCoreV3EntityConfigExtensionOverridesToJSONHandler, + "id": _ObjTypeCoreV3EntityConfigExtensionOverridesIDHandler, + "state": _ObjTypeCoreV3EntityConfigExtensionOverridesStateHandler, + "toCoreV2Entity": _ObjTypeCoreV3EntityConfigExtensionOverridesToCoreV2EntityHandler, + "toJSON": _ObjTypeCoreV3EntityConfigExtensionOverridesToJSONHandler, }, } @@ -108,6 +128,9 @@ type CoreV3EntityStateExtensionOverridesFieldResolvers interface { // Config implements response to request for 'config' field. Config(p graphql.ResolveParams) (interface{}, error) + + // ToCoreV2Entity implements response to request for 'toCoreV2Entity' field. + ToCoreV2Entity(p graphql.ResolveParams) (interface{}, error) } // RegisterCoreV3EntityStateExtensionOverrides registers CoreV3EntityStateExtensionOverrides object type with given service. @@ -142,6 +165,15 @@ func _ObjTypeCoreV3EntityStateExtensionOverridesConfigHandler(impl interface{}) } } +func _ObjTypeCoreV3EntityStateExtensionOverridesToCoreV2EntityHandler(impl interface{}) graphql1.FieldResolveFn { + resolver := impl.(interface { + ToCoreV2Entity(p graphql.ResolveParams) (interface{}, error) + }) + return func(frp graphql1.ResolveParams) (interface{}, error) { + return resolver.ToCoreV2Entity(frp) + } +} + func _ObjectExtensionTypeCoreV3EntityStateExtensionOverridesConfigFn() graphql1.ObjectConfig { return graphql1.ObjectConfig{ Description: "", @@ -160,6 +192,13 @@ func _ObjectExtensionTypeCoreV3EntityStateExtensionOverridesConfigFn() graphql1. Name: "id", Type: graphql1.NewNonNull(graphql1.ID), }, + "toCoreV2Entity": &graphql1.Field{ + Args: graphql1.FieldConfigArgument{}, + DeprecationReason: "", + Description: "Represented as core/v2 Entity.", + Name: "toCoreV2Entity", + Type: graphql.OutputType("Entity"), + }, "toJSON": &graphql1.Field{ Args: graphql1.FieldConfigArgument{}, DeprecationReason: "", @@ -179,8 +218,9 @@ func _ObjectExtensionTypeCoreV3EntityStateExtensionOverridesConfigFn() graphql1. var _ObjectExtensionTypeCoreV3EntityStateExtensionOverridesDesc = graphql.ObjectDesc{ Config: _ObjectExtensionTypeCoreV3EntityStateExtensionOverridesConfigFn, FieldHandlers: map[string]graphql.FieldHandler{ - "config": _ObjTypeCoreV3EntityStateExtensionOverridesConfigHandler, - "id": _ObjTypeCoreV3EntityStateExtensionOverridesIDHandler, - "toJSON": _ObjTypeCoreV3EntityStateExtensionOverridesToJSONHandler, + "config": _ObjTypeCoreV3EntityStateExtensionOverridesConfigHandler, + "id": _ObjTypeCoreV3EntityStateExtensionOverridesIDHandler, + "toCoreV2Entity": _ObjTypeCoreV3EntityStateExtensionOverridesToCoreV2EntityHandler, + "toJSON": _ObjTypeCoreV3EntityStateExtensionOverridesToJSONHandler, }, } diff --git a/backend/apid/graphql/schema/corev3.graphql b/backend/apid/graphql/schema/corev3.graphql index b6c884d35a..6b4c7df963 100644 --- a/backend/apid/graphql/schema/corev3.graphql +++ b/backend/apid/graphql/schema/corev3.graphql @@ -12,6 +12,11 @@ extend type CoreV3EntityConfig implements Node & Resource @named(suffix: "Overri Corresponding entity state, if applicable. """ state: CoreV3EntityState + + """ + Represented as core/v2 Entity. + """ + toCoreV2Entity: Entity } extend type CoreV3EntityState implements Node & Resource @named(suffix: "Overrides") { @@ -28,4 +33,9 @@ extend type CoreV3EntityState implements Node & Resource @named(suffix: "Overrid Corresponding entity config, if applicable. """ config: CoreV3EntityConfig + + """ + Represented as core/v2 Entity. + """ + toCoreV2Entity: Entity } diff --git a/backend/apid/graphql/service.go b/backend/apid/graphql/service.go index 0bc3c5e55c..8a1637c696 100644 --- a/backend/apid/graphql/service.go +++ b/backend/apid/graphql/service.go @@ -78,9 +78,9 @@ func NewService(cfg ServiceConfig) (*Service, error) { schema.RegisterCoreV2Secret(svc, &schema.CoreV2SecretAliases{}) schema.RegisterCoreV2System(svc, &schema.CoreV2SystemAliases{}) schema.RegisterCoreV3EntityConfig(svc, &corev3EntityConfigImpl{}) - schema.RegisterCoreV3EntityConfigExtensionOverrides(svc, &corev3EntityConfigExtImpl{client: cfg.GenericClient}) + schema.RegisterCoreV3EntityConfigExtensionOverrides(svc, &corev3EntityConfigExtImpl{client: cfg.GenericClient, entityClient: cfg.EntityClient}) schema.RegisterCoreV3EntityState(svc, &corev3EntityStateImpl{}) - schema.RegisterCoreV3EntityStateExtensionOverrides(svc, &corev3EntityStateExtImpl{client: cfg.GenericClient}) + schema.RegisterCoreV3EntityStateExtensionOverrides(svc, &corev3EntityStateExtImpl{client: cfg.GenericClient, entityClient: cfg.EntityClient}) schema.RegisterNamespace(svc, &namespaceImpl{client: cfg.NamespaceClient, entityClient: cfg.EntityClient, eventClient: cfg.EventClient, serviceConfig: &cfg}) schema.RegisterErrCode(svc) schema.RegisterEvent(svc, &eventImpl{}) From d5727eff7f9bbfe2a8489172f2059bd27129e470 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 20 Jul 2022 22:51:41 -0700 Subject: [PATCH 27/35] fields() Signed-off-by: James Phillips --- api/core/v3/entity_config.go | 24 +++++++++++++++++++++++- api/core/v3/entity_state.go | 8 ++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/api/core/v3/entity_config.go b/api/core/v3/entity_config.go index 99e9f42484..1549dd4313 100644 --- a/api/core/v3/entity_config.go +++ b/api/core/v3/entity_config.go @@ -1,11 +1,33 @@ package v3 import ( + "strconv" + "strings" + corev2 "github.com/sensu/sensu-go/api/core/v2" ) var entityConfigRBACName = (&corev2.Entity{}).RBACName() -func (*EntityConfig) rbacName() string { +func (e *EntityConfig) rbacName() string { return entityConfigRBACName } + +func (e *EntityConfig) Fields() map[string]string { + fields := map[string]string{ + "entity_config.name": e.Metadata.Name, + "entity_config.namespace": e.Metadata.Namespace, + "entity_config.deregister": strconv.FormatBool(e.Deregister), + "entity_config.entity_class": e.EntityClass, + "entity_config.subscriptions": strings.Join(e.Subscriptions, ","), + } + MergeMapWithPrefix(fields, e.Metadata.Labels, "entity_config.labels.") + return fields +} + +// MergeMapWithPrefix merges contents of one map into another using a prefix. +func MergeMapWithPrefix(a map[string]string, b map[string]string, prefix string) { + for k, v := range b { + a[prefix+k] = v + } +} diff --git a/api/core/v3/entity_state.go b/api/core/v3/entity_state.go index eee78a2d28..131da36a7a 100644 --- a/api/core/v3/entity_state.go +++ b/api/core/v3/entity_state.go @@ -9,3 +9,11 @@ var entityStateRBACName = (&corev2.Entity{}).RBACName() func (*EntityState) rbacName() string { return entityStateRBACName } + +func (e *EntityState) Fields() map[string]string { + fields := map[string]string{ + "entity_state.name": e.Metadata.Name, + "entity_state.namespace": e.Metadata.Namespace, + } + return fields +} From 5e893485604736fbff950675c0dcd2455a588a05 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Thu, 21 Jul 2022 08:56:12 -0700 Subject: [PATCH 28/35] remove unused Signed-off-by: James Phillips --- backend/apid/graphql/corev3.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/backend/apid/graphql/corev3.go b/backend/apid/graphql/corev3.go index 6a3f479cfe..a62cef86d4 100644 --- a/backend/apid/graphql/corev3.go +++ b/backend/apid/graphql/corev3.go @@ -118,11 +118,6 @@ func getEntityComponent(ctx context.Context, client GenericClient, meta *corev2. return nil, err } -func getCoreV2Entity(ctx context.Context, client EntityClient, meta *corev2.ObjectMeta) (interface{}, error) { - ctx = contextWithNamespace(ctx, meta.Namespace) - return client.FetchEntity(ctx, meta.Name) -} - type corev3EntityStateImpl struct { schema.CoreV3EntityStateAliases } From 31e6727fa731c6670b0dd6a9124278404d3ba600 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Thu, 21 Jul 2022 10:47:00 -0700 Subject: [PATCH 29/35] bad rebase Signed-off-by: James Phillips --- backend/apid/graphql/schema/corev2.gql.go | 276 ---------------------- 1 file changed, 276 deletions(-) diff --git a/backend/apid/graphql/schema/corev2.gql.go b/backend/apid/graphql/schema/corev2.gql.go index 41e41574b2..69b948e0e7 100644 --- a/backend/apid/graphql/schema/corev2.gql.go +++ b/backend/apid/graphql/schema/corev2.gql.go @@ -351,279 +351,3 @@ var _ObjectExtensionTypeCoreV2ClusterRoleBindingExtensionOverridesDesc = graphql "toJSON": _ObjTypeCoreV2ClusterRoleBindingExtensionOverridesToJSONHandler, }, } - -// -// CoreV2RoleExtensionOverridesFieldResolvers represents a collection of methods whose products represent the -// response values of the 'CoreV2RoleExtensionOverrides' type. -type CoreV2RoleExtensionOverridesFieldResolvers interface { - // ID implements response to request for 'id' field. - ID(p graphql.ResolveParams) (string, error) - - // ToJSON implements response to request for 'toJSON' field. - ToJSON(p graphql.ResolveParams) (interface{}, error) -} - -// RegisterCoreV2RoleExtensionOverrides registers CoreV2RoleExtensionOverrides object type with given service. -func RegisterCoreV2RoleExtensionOverrides(svc *graphql.Service, impl CoreV2RoleExtensionOverridesFieldResolvers) { - svc.RegisterObjectExtension(_ObjectExtensionTypeCoreV2RoleExtensionOverridesDesc, impl) -} - -func _ObjTypeCoreV2RoleExtensionOverridesIDHandler(impl interface{}) graphql1.FieldResolveFn { - resolver := impl.(interface { - ID(p graphql.ResolveParams) (string, error) - }) - return func(frp graphql1.ResolveParams) (interface{}, error) { - return resolver.ID(frp) - } -} - -func _ObjTypeCoreV2RoleExtensionOverridesToJSONHandler(impl interface{}) graphql1.FieldResolveFn { - resolver := impl.(interface { - ToJSON(p graphql.ResolveParams) (interface{}, error) - }) - return func(frp graphql1.ResolveParams) (interface{}, error) { - return resolver.ToJSON(frp) - } -} - -func _ObjectExtensionTypeCoreV2RoleExtensionOverridesConfigFn() graphql1.ObjectConfig { - return graphql1.ObjectConfig{ - Description: "", - Fields: graphql1.Fields{ - "id": &graphql1.Field{ - Args: graphql1.FieldConfigArgument{}, - DeprecationReason: "", - Description: "The globally unique identifier of the record", - Name: "id", - Type: graphql1.NewNonNull(graphql1.ID), - }, - "toJSON": &graphql1.Field{ - Args: graphql1.FieldConfigArgument{}, - DeprecationReason: "", - Description: "toJSON returns a REST API compatible representation of the resource. Handy for\nsharing snippets that can then be imported with `sensuctl create`.", - Name: "toJSON", - Type: graphql1.NewNonNull(graphql.OutputType("JSON")), - }, - }, - Interfaces: []*graphql1.Interface{ - graphql.Interface("Node"), - graphql.Interface("Resource")}, - Name: "CoreV2Role", - } -} - -// describe CoreV2RoleExtensionOverrides's configuration; kept private to avoid unintentional tampering of configuration at runtime. -var _ObjectExtensionTypeCoreV2RoleExtensionOverridesDesc = graphql.ObjectDesc{ - Config: _ObjectExtensionTypeCoreV2RoleExtensionOverridesConfigFn, - FieldHandlers: map[string]graphql.FieldHandler{ - "id": _ObjTypeCoreV2RoleExtensionOverridesIDHandler, - "toJSON": _ObjTypeCoreV2RoleExtensionOverridesToJSONHandler, - }, -} - -// -// CoreV2RoleBindingExtensionOverridesFieldResolvers represents a collection of methods whose products represent the -// response values of the 'CoreV2RoleBindingExtensionOverrides' type. -type CoreV2RoleBindingExtensionOverridesFieldResolvers interface { - // ID implements response to request for 'id' field. - ID(p graphql.ResolveParams) (string, error) - - // ToJSON implements response to request for 'toJSON' field. - ToJSON(p graphql.ResolveParams) (interface{}, error) -} - -// RegisterCoreV2RoleBindingExtensionOverrides registers CoreV2RoleBindingExtensionOverrides object type with given service. -func RegisterCoreV2RoleBindingExtensionOverrides(svc *graphql.Service, impl CoreV2RoleBindingExtensionOverridesFieldResolvers) { - svc.RegisterObjectExtension(_ObjectExtensionTypeCoreV2RoleBindingExtensionOverridesDesc, impl) -} - -func _ObjTypeCoreV2RoleBindingExtensionOverridesIDHandler(impl interface{}) graphql1.FieldResolveFn { - resolver := impl.(interface { - ID(p graphql.ResolveParams) (string, error) - }) - return func(frp graphql1.ResolveParams) (interface{}, error) { - return resolver.ID(frp) - } -} - -func _ObjTypeCoreV2RoleBindingExtensionOverridesToJSONHandler(impl interface{}) graphql1.FieldResolveFn { - resolver := impl.(interface { - ToJSON(p graphql.ResolveParams) (interface{}, error) - }) - return func(frp graphql1.ResolveParams) (interface{}, error) { - return resolver.ToJSON(frp) - } -} - -func _ObjectExtensionTypeCoreV2RoleBindingExtensionOverridesConfigFn() graphql1.ObjectConfig { - return graphql1.ObjectConfig{ - Description: "", - Fields: graphql1.Fields{ - "id": &graphql1.Field{ - Args: graphql1.FieldConfigArgument{}, - DeprecationReason: "", - Description: "The globally unique identifier of the record", - Name: "id", - Type: graphql1.NewNonNull(graphql1.ID), - }, - "toJSON": &graphql1.Field{ - Args: graphql1.FieldConfigArgument{}, - DeprecationReason: "", - Description: "toJSON returns a REST API compatible representation of the resource. Handy for\nsharing snippets that can then be imported with `sensuctl create`.", - Name: "toJSON", - Type: graphql1.NewNonNull(graphql.OutputType("JSON")), - }, - }, - Interfaces: []*graphql1.Interface{ - graphql.Interface("Node"), - graphql.Interface("Resource")}, - Name: "CoreV2RoleBinding", - } -} - -// describe CoreV2RoleBindingExtensionOverrides's configuration; kept private to avoid unintentional tampering of configuration at runtime. -var _ObjectExtensionTypeCoreV2RoleBindingExtensionOverridesDesc = graphql.ObjectDesc{ - Config: _ObjectExtensionTypeCoreV2RoleBindingExtensionOverridesConfigFn, - FieldHandlers: map[string]graphql.FieldHandler{ - "id": _ObjTypeCoreV2RoleBindingExtensionOverridesIDHandler, - "toJSON": _ObjTypeCoreV2RoleBindingExtensionOverridesToJSONHandler, - }, -} - -// -// CoreV2ClusterRoleExtensionOverridesFieldResolvers represents a collection of methods whose products represent the -// response values of the 'CoreV2ClusterRoleExtensionOverrides' type. -type CoreV2ClusterRoleExtensionOverridesFieldResolvers interface { - // ID implements response to request for 'id' field. - ID(p graphql.ResolveParams) (string, error) - - // ToJSON implements response to request for 'toJSON' field. - ToJSON(p graphql.ResolveParams) (interface{}, error) -} - -// RegisterCoreV2ClusterRoleExtensionOverrides registers CoreV2ClusterRoleExtensionOverrides object type with given service. -func RegisterCoreV2ClusterRoleExtensionOverrides(svc *graphql.Service, impl CoreV2ClusterRoleExtensionOverridesFieldResolvers) { - svc.RegisterObjectExtension(_ObjectExtensionTypeCoreV2ClusterRoleExtensionOverridesDesc, impl) -} - -func _ObjTypeCoreV2ClusterRoleExtensionOverridesIDHandler(impl interface{}) graphql1.FieldResolveFn { - resolver := impl.(interface { - ID(p graphql.ResolveParams) (string, error) - }) - return func(frp graphql1.ResolveParams) (interface{}, error) { - return resolver.ID(frp) - } -} - -func _ObjTypeCoreV2ClusterRoleExtensionOverridesToJSONHandler(impl interface{}) graphql1.FieldResolveFn { - resolver := impl.(interface { - ToJSON(p graphql.ResolveParams) (interface{}, error) - }) - return func(frp graphql1.ResolveParams) (interface{}, error) { - return resolver.ToJSON(frp) - } -} - -func _ObjectExtensionTypeCoreV2ClusterRoleExtensionOverridesConfigFn() graphql1.ObjectConfig { - return graphql1.ObjectConfig{ - Description: "", - Fields: graphql1.Fields{ - "id": &graphql1.Field{ - Args: graphql1.FieldConfigArgument{}, - DeprecationReason: "", - Description: "The globally unique identifier of the record", - Name: "id", - Type: graphql1.NewNonNull(graphql1.ID), - }, - "toJSON": &graphql1.Field{ - Args: graphql1.FieldConfigArgument{}, - DeprecationReason: "", - Description: "toJSON returns a REST API compatible representation of the resource. Handy for\nsharing snippets that can then be imported with `sensuctl create`.", - Name: "toJSON", - Type: graphql1.NewNonNull(graphql.OutputType("JSON")), - }, - }, - Interfaces: []*graphql1.Interface{ - graphql.Interface("Node"), - graphql.Interface("Resource")}, - Name: "CoreV2ClusterRole", - } -} - -// describe CoreV2ClusterRoleExtensionOverrides's configuration; kept private to avoid unintentional tampering of configuration at runtime. -var _ObjectExtensionTypeCoreV2ClusterRoleExtensionOverridesDesc = graphql.ObjectDesc{ - Config: _ObjectExtensionTypeCoreV2ClusterRoleExtensionOverridesConfigFn, - FieldHandlers: map[string]graphql.FieldHandler{ - "id": _ObjTypeCoreV2ClusterRoleExtensionOverridesIDHandler, - "toJSON": _ObjTypeCoreV2ClusterRoleExtensionOverridesToJSONHandler, - }, -} - -// -// CoreV2ClusterRoleBindingExtensionOverridesFieldResolvers represents a collection of methods whose products represent the -// response values of the 'CoreV2ClusterRoleBindingExtensionOverrides' type. -type CoreV2ClusterRoleBindingExtensionOverridesFieldResolvers interface { - // ID implements response to request for 'id' field. - ID(p graphql.ResolveParams) (string, error) - - // ToJSON implements response to request for 'toJSON' field. - ToJSON(p graphql.ResolveParams) (interface{}, error) -} - -// RegisterCoreV2ClusterRoleBindingExtensionOverrides registers CoreV2ClusterRoleBindingExtensionOverrides object type with given service. -func RegisterCoreV2ClusterRoleBindingExtensionOverrides(svc *graphql.Service, impl CoreV2ClusterRoleBindingExtensionOverridesFieldResolvers) { - svc.RegisterObjectExtension(_ObjectExtensionTypeCoreV2ClusterRoleBindingExtensionOverridesDesc, impl) -} - -func _ObjTypeCoreV2ClusterRoleBindingExtensionOverridesIDHandler(impl interface{}) graphql1.FieldResolveFn { - resolver := impl.(interface { - ID(p graphql.ResolveParams) (string, error) - }) - return func(frp graphql1.ResolveParams) (interface{}, error) { - return resolver.ID(frp) - } -} - -func _ObjTypeCoreV2ClusterRoleBindingExtensionOverridesToJSONHandler(impl interface{}) graphql1.FieldResolveFn { - resolver := impl.(interface { - ToJSON(p graphql.ResolveParams) (interface{}, error) - }) - return func(frp graphql1.ResolveParams) (interface{}, error) { - return resolver.ToJSON(frp) - } -} - -func _ObjectExtensionTypeCoreV2ClusterRoleBindingExtensionOverridesConfigFn() graphql1.ObjectConfig { - return graphql1.ObjectConfig{ - Description: "", - Fields: graphql1.Fields{ - "id": &graphql1.Field{ - Args: graphql1.FieldConfigArgument{}, - DeprecationReason: "", - Description: "The globally unique identifier of the record", - Name: "id", - Type: graphql1.NewNonNull(graphql1.ID), - }, - "toJSON": &graphql1.Field{ - Args: graphql1.FieldConfigArgument{}, - DeprecationReason: "", - Description: "toJSON returns a REST API compatible representation of the resource. Handy for\nsharing snippets that can then be imported with `sensuctl create`.", - Name: "toJSON", - Type: graphql1.NewNonNull(graphql.OutputType("JSON")), - }, - }, - Interfaces: []*graphql1.Interface{ - graphql.Interface("Node"), - graphql.Interface("Resource")}, - Name: "CoreV2ClusterRoleBinding", - } -} - -// describe CoreV2ClusterRoleBindingExtensionOverrides's configuration; kept private to avoid unintentional tampering of configuration at runtime. -var _ObjectExtensionTypeCoreV2ClusterRoleBindingExtensionOverridesDesc = graphql.ObjectDesc{ - Config: _ObjectExtensionTypeCoreV2ClusterRoleBindingExtensionOverridesConfigFn, - FieldHandlers: map[string]graphql.FieldHandler{ - "id": _ObjTypeCoreV2ClusterRoleBindingExtensionOverridesIDHandler, - "toJSON": _ObjTypeCoreV2ClusterRoleBindingExtensionOverridesToJSONHandler, - }, -} From a38fb9aabc25f2cdd5208e825e88ae9aec7930d2 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 10 Aug 2022 18:51:48 -0700 Subject: [PATCH 30/35] add tests for entity config & state fields Signed-off-by: James Phillips --- api/core/v3/entity_config_test.go | 60 +++++++++++++++++++++++++++++++ api/core/v3/entity_state_test.go | 36 +++++++++++++++++++ api/core/v3/fielder.go | 7 ++++ 3 files changed, 103 insertions(+) create mode 100644 api/core/v3/entity_config_test.go create mode 100644 api/core/v3/entity_state_test.go create mode 100644 api/core/v3/fielder.go diff --git a/api/core/v3/entity_config_test.go b/api/core/v3/entity_config_test.go new file mode 100644 index 0000000000..568ce1508a --- /dev/null +++ b/api/core/v3/entity_config_test.go @@ -0,0 +1,60 @@ +package v3 + +import ( + "reflect" + "testing" + + v2 "github.com/sensu/sensu-go/api/core/v2" +) + +func TestEntityConfigFields(t *testing.T) { + tests := []struct { + name string + args Fielder + wantKey string + want string + }{ + { + name: "exposes name", + args: FixtureEntityConfig("my-agent"), + wantKey: "entity_config.name", + want: "my-agent", + }, + { + name: "exposes deregister", + args: &EntityConfig{Metadata: &v2.ObjectMeta{}, Deregister: true}, + wantKey: "entity_config.deregister", + want: "true", + }, + { + name: "exposes class", + args: &EntityConfig{Metadata: &v2.ObjectMeta{}, EntityClass: "agent"}, + wantKey: "entity_config.entity_class", + want: "agent", + }, + { + name: "exposes subscriptions", + args: &EntityConfig{Metadata: &v2.ObjectMeta{}, Subscriptions: []string{"www", "unix"}}, + wantKey: "entity_config.subscriptions", + want: "www,unix", + }, + { + name: "exposes labels", + args: &EntityConfig{ + Metadata: &v2.ObjectMeta{ + Labels: map[string]string{"region": "philadelphia"}, + }, + }, + wantKey: "entity_config.labels.region", + want: "philadelphia", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := tt.args.Fields() + if !reflect.DeepEqual(got[tt.wantKey], tt.want) { + t.Errorf("EntityConfig.Fields() = got[%s] %v, want[%s] %v", tt.wantKey, got[tt.wantKey], tt.wantKey, tt.want) + } + }) + } +} diff --git a/api/core/v3/entity_state_test.go b/api/core/v3/entity_state_test.go new file mode 100644 index 0000000000..e5b9bce12c --- /dev/null +++ b/api/core/v3/entity_state_test.go @@ -0,0 +1,36 @@ +package v3 + +import ( + "reflect" + "testing" +) + +func TestEntityStateFields(t *testing.T) { + tests := []struct { + name string + args Fielder + wantKey string + want string + }{ + { + name: "exposes name", + args: FixtureEntityState("my-agent"), + wantKey: "entity_state.name", + want: "my-agent", + }, + { + name: "exposes deregister", + args: FixtureEntityState("my-agent"), + wantKey: "entity_state.namespace", + want: "default", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := tt.args.Fields() + if !reflect.DeepEqual(got[tt.wantKey], tt.want) { + t.Errorf("EntityState.Fields() = got[%s] %v, want[%s] %v", tt.wantKey, got[tt.wantKey], tt.wantKey, tt.want) + } + }) + } +} diff --git a/api/core/v3/fielder.go b/api/core/v3/fielder.go new file mode 100644 index 0000000000..a27c796bd4 --- /dev/null +++ b/api/core/v3/fielder.go @@ -0,0 +1,7 @@ +package v3 + +// Fielder includes a set of fields that represent a resource. +type Fielder interface { + // Fields returns a set of fields that represent the resource. + Fields() map[string]string +} From a7b9041a77303ce578ed67c86ee74c48ff551cfd Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 10 Aug 2022 19:13:40 -0700 Subject: [PATCH 31/35] add test coverage for generic translator Signed-off-by: James Phillips --- backend/apid/graphql/globalid/util_test.go | 132 +++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/backend/apid/graphql/globalid/util_test.go b/backend/apid/graphql/globalid/util_test.go index b361a5d734..a8c7abffea 100644 --- a/backend/apid/graphql/globalid/util_test.go +++ b/backend/apid/graphql/globalid/util_test.go @@ -4,6 +4,8 @@ import ( "context" "testing" + corev2 "github.com/sensu/sensu-go/api/core/v2" + corev3 "github.com/sensu/sensu-go/api/core/v3" "github.com/sensu/sensu-go/types" "github.com/stretchr/testify/assert" ) @@ -20,3 +22,133 @@ func TestStandardDecoder(t *testing.T) { assert.Equal("default", components.Namespace()) assert.Equal("myHandler", components.UniqueComponent()) } + +func Test_GenericTranslator_ForResourceNamed(t *testing.T) { + type fields struct { + kind namedResource + name string + } + tests := []struct { + name string + fields fields + want string + }{ + { + name: "implicit name", + fields: fields{ + kind: &corev3.EntityConfig{}, + }, + want: "core/v3.EntityConfig", + }, + { + name: "explicit name", + fields: fields{ + kind: &corev3.EntityConfig{}, + name: "custom_entity_config", + }, + want: "custom_entity_config", + }, + { + name: "implicit name AND doesn't implement typemeta interface", + fields: fields{ + kind: &corev2.CheckConfig{}, + }, + want: "core/v2.CheckConfig", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + g := NewGenericTranslator(tt.fields.kind, tt.fields.name) + if got := g.ForResourceNamed(); got != tt.want { + t.Errorf("genericTranslator.ForResourceNamed() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_GenericTranslator_IsResponsibleFor(t *testing.T) { + type fields struct { + kind namedResource + name string + } + tests := []struct { + name string + fields fields + arg interface{} + want bool + }{ + { + name: "IS responsible", + fields: fields{ + kind: &corev3.EntityConfig{}, + }, + arg: corev3.FixtureEntityConfig("test"), + want: true, + }, + { + name: "is NOT responsible", + fields: fields{ + kind: &corev3.EntityConfig{}, + }, + arg: corev3.FixtureEntityState("test"), + want: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + g := NewGenericTranslator(tt.fields.kind, tt.fields.name) + if got := g.IsResponsible(tt.arg); got != tt.want { + t.Errorf("genericTranslator.IsResponsible() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_GenericTranslator_EncodeToString(t *testing.T) { + type fields struct { + kind namedResource + name string + } + type args struct { + ctx context.Context + in interface{} + } + tests := []struct { + name string + fields fields + args args + want string + }{ + { + name: "implicit name", + fields: fields{ + kind: &corev3.EntityConfig{}, + }, + args: args{ + ctx: context.Background(), + in: corev3.FixtureEntityState("test"), + }, + want: "srn:core/v3.EntityConfig:default:test", + }, + { + name: "implicit name", + fields: fields{ + kind: &corev3.EntityConfig{}, + name: "custom-name", + }, + args: args{ + ctx: context.Background(), + in: corev3.FixtureEntityState("test"), + }, + want: "srn:custom-name:default:test", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + g := NewGenericTranslator(tt.fields.kind, tt.fields.name) + if got := g.EncodeToString(tt.args.ctx, tt.args.in); got != tt.want { + t.Errorf("genericTranslator.EncodeToString() = %v, want %v", got, tt.want) + } + }) + } +} From beb8e788d53440b10d5cd7dcfabb4daade0dd3ae Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 10 Aug 2022 20:15:56 -0700 Subject: [PATCH 32/35] add test coverage for corev3 GraphQL types Signed-off-by: James Phillips --- backend/apid/graphql/corev3_test.go | 253 ++++++++++++++++++++++++++++ backend/apid/graphql/mock_test.go | 3 + 2 files changed, 256 insertions(+) diff --git a/backend/apid/graphql/corev3_test.go b/backend/apid/graphql/corev3_test.go index f10d43e299..c7ea9a4452 100644 --- a/backend/apid/graphql/corev3_test.go +++ b/backend/apid/graphql/corev3_test.go @@ -2,6 +2,7 @@ package graphql import ( "context" + "errors" "fmt" "reflect" "testing" @@ -9,7 +10,9 @@ import ( corev2 "github.com/sensu/sensu-go/api/core/v2" corev3 "github.com/sensu/sensu-go/api/core/v3" util_api "github.com/sensu/sensu-go/backend/apid/graphql/util/api" + "github.com/sensu/sensu-go/backend/store" "github.com/sensu/sensu-go/graphql" + "github.com/stretchr/testify/mock" ) func Test_corev3_ID(t *testing.T) { @@ -134,3 +137,253 @@ func Test_corev3_IsTypeOf(t *testing.T) { }) } } + +func Test_corev3EntityConfigExtImpl_State(t *testing.T) { + tests := []struct { + name string + setup func(*MockGenericClient) + source interface{} + want interface{} + wantErr bool + }{ + { + name: "success", + setup: func(client *MockGenericClient) { + client.On("SetTypeMeta", mock.Anything).Return(nil) + client.On("Get", mock.Anything, "name", mock.Anything).Run(func(args mock.Arguments) { + arg := args.Get(2).(*corev3.V2ResourceProxy) + *arg = corev3.V2ResourceProxy{Resource: corev3.FixtureEntityConfig("name")} + }).Return(nil).Once() + }, + source: corev3.FixtureEntityConfig("name"), + want: corev3.FixtureEntityConfig("name"), + wantErr: false, + }, + { + name: "not found", + setup: func(client *MockGenericClient) { + client.On("SetTypeMeta", mock.Anything).Return(nil) + client.On("Get", mock.Anything, "name", mock.Anything).Return(&store.ErrNotFound{}).Once() + }, + source: corev3.FixtureEntityConfig("name"), + want: nil, + wantErr: false, + }, + { + name: "bad meta", + setup: func(client *MockGenericClient) { + client.On("SetTypeMeta", mock.Anything).Return(errors.New("unlikely")) + client.On("Get", mock.Anything, "name", mock.Anything).Return(&store.ErrNotFound{}).Once() + }, + source: corev3.FixtureEntityConfig("name"), + want: nil, + wantErr: true, + }, + { + name: "upstream err", + setup: func(client *MockGenericClient) { + client.On("SetTypeMeta", mock.Anything).Return(nil) + client.On("Get", mock.Anything, "name", mock.Anything).Return(errors.New("unlikely")).Once() + }, + source: corev3.FixtureEntityConfig("name"), + want: nil, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + client := new(MockGenericClient) + tt.setup(client) + + impl := &corev3EntityConfigExtImpl{client: client} + got, err := impl.State(graphql.ResolveParams{ + Context: context.Background(), + Source: tt.source, + }) + if (err != nil) != tt.wantErr { + t.Errorf("corev3EntityConfigExtImpl.State() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("corev3EntityConfigExtImpl.State() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_corev3EntityStateExtImpl_State(t *testing.T) { + tests := []struct { + name string + setup func(*MockGenericClient) + source interface{} + want interface{} + wantErr bool + }{ + { + name: "success", + setup: func(client *MockGenericClient) { + client.On("SetTypeMeta", mock.Anything).Return(nil) + client.On("Get", mock.Anything, "name", mock.Anything).Run(func(args mock.Arguments) { + arg := args.Get(2).(*corev3.V2ResourceProxy) + *arg = corev3.V2ResourceProxy{Resource: corev3.FixtureEntityState("name")} + }).Return(nil).Once() + }, + source: corev3.FixtureEntityState("name"), + want: corev3.FixtureEntityState("name"), + wantErr: false, + }, + { + name: "not found", + setup: func(client *MockGenericClient) { + client.On("SetTypeMeta", mock.Anything).Return(nil) + client.On("Get", mock.Anything, "name", mock.Anything).Return(&store.ErrNotFound{}).Once() + }, + source: corev3.FixtureEntityState("name"), + want: nil, + wantErr: false, + }, + { + name: "bad meta", + setup: func(client *MockGenericClient) { + client.On("SetTypeMeta", mock.Anything).Return(errors.New("unlikely")) + client.On("Get", mock.Anything, "name", mock.Anything).Return(&store.ErrNotFound{}).Once() + }, + source: corev3.FixtureEntityState("name"), + want: nil, + wantErr: true, + }, + { + name: "upstream err", + setup: func(client *MockGenericClient) { + client.On("SetTypeMeta", mock.Anything).Return(nil) + client.On("Get", mock.Anything, "name", mock.Anything).Return(errors.New("unlikely")).Once() + }, + source: corev3.FixtureEntityState("name"), + want: nil, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + client := new(MockGenericClient) + tt.setup(client) + + impl := &corev3EntityStateExtImpl{client: client} + got, err := impl.Config(graphql.ResolveParams{ + Context: context.Background(), + Source: tt.source, + }) + if (err != nil) != tt.wantErr { + t.Errorf("corev3EntityStateExtImpl.Config() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("corev3EntityStateExtImpl.Config() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_corev3EntityStateExtImpl_ToCoreV2Entity(t *testing.T) { + tests := []struct { + name string + setup func(*MockEntityClient) + source interface{} + want interface{} + wantErr bool + }{ + { + name: "success", + setup: func(client *MockEntityClient) { + client.On("FetchEntity", mock.Anything, "name"). + Return(corev2.FixtureEntity("name"), nil). + Once() + }, + source: corev3.FixtureEntityState("name"), + want: corev2.FixtureEntity("name"), + wantErr: false, + }, + { + name: "upstream err", + setup: func(client *MockEntityClient) { + client.On("FetchEntity", mock.Anything, "name"). + Return(corev2.FixtureEntity("name"), errors.New("unlikely")). + Once() + }, + source: corev3.FixtureEntityState("name"), + want: corev2.FixtureEntity("name"), + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + client := new(MockEntityClient) + tt.setup(client) + + impl := &corev3EntityStateExtImpl{entityClient: client} + got, err := impl.ToCoreV2Entity(graphql.ResolveParams{ + Context: context.Background(), + Source: tt.source, + }) + if (err != nil) != tt.wantErr { + t.Errorf("corev3EntityStateExtImpl.ToCoreV2Entity() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("corev3EntityStateExtImpl.ToCoreV2Entity() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_corev3EntityConfigExtImpl_ToCoreV2Entity(t *testing.T) { + tests := []struct { + name string + setup func(*MockEntityClient) + source interface{} + want interface{} + wantErr bool + }{ + { + name: "success", + setup: func(client *MockEntityClient) { + client.On("FetchEntity", mock.Anything, "name"). + Return(corev2.FixtureEntity("name"), nil). + Once() + }, + source: corev3.FixtureEntityConfig("name"), + want: corev2.FixtureEntity("name"), + wantErr: false, + }, + { + name: "upstream err", + setup: func(client *MockEntityClient) { + client.On("FetchEntity", mock.Anything, "name"). + Return(corev2.FixtureEntity("name"), errors.New("unlikely")). + Once() + }, + source: corev3.FixtureEntityConfig("name"), + want: corev2.FixtureEntity("name"), + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + client := new(MockEntityClient) + tt.setup(client) + + impl := &corev3EntityConfigExtImpl{entityClient: client} + got, err := impl.ToCoreV2Entity(graphql.ResolveParams{ + Context: context.Background(), + Source: tt.source, + }) + if (err != nil) != tt.wantErr { + t.Errorf("corev3EntityConfigExtImpl.ToCoreV2Entity() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("corev3EntityConfigExtImpl.ToCoreV2Entity() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/backend/apid/graphql/mock_test.go b/backend/apid/graphql/mock_test.go index fc08475d9f..357a8c7b6b 100644 --- a/backend/apid/graphql/mock_test.go +++ b/backend/apid/graphql/mock_test.go @@ -133,6 +133,9 @@ func (c *MockEntityClient) UpdateEntity(ctx context.Context, entity *corev2.Enti func (c *MockEntityClient) FetchEntity(ctx context.Context, name string) (*corev2.Entity, error) { args := c.Called(ctx, name) + if args.Get(0) == nil { + return nil, args.Error(1) + } return args.Get(0).(*corev2.Entity), args.Error(1) } From 2734c2afa501338301c58c2bdf9405af889411ad Mon Sep 17 00:00:00 2001 From: James Phillips Date: Wed, 10 Aug 2022 20:46:40 -0700 Subject: [PATCH 33/35] omit uniqueness tests Signed-off-by: James Phillips --- api/core/v3/resource_generated_test.go | 16 ---------------- api/core/v3/resource_generated_test.tmpl | 16 ---------------- 2 files changed, 32 deletions(-) diff --git a/api/core/v3/resource_generated_test.go b/api/core/v3/resource_generated_test.go index b340550353..9e8e114d8f 100644 --- a/api/core/v3/resource_generated_test.go +++ b/api/core/v3/resource_generated_test.go @@ -484,20 +484,4 @@ func TestResourceUniqueness(t *testing.T) { if got, want := len(types), len(typeMap)/2; got != want { t.Fatalf("bad number of types: got %d, want %d", got, want) } - rbacNames := make(map[string]bool) - for _, v := range types { - if name := v.RBACName(); rbacNames[name] { - t.Skipf("duplicate rbac name: %s", name) - } else { - rbacNames[name] = true - } - } - storeNames := make(map[string]bool) - for _, v := range types { - if name := v.StoreName(); storeNames[name] { - t.Skipf("duplicate store suffix: %s", name) - } else { - storeNames[name] = true - } - } } diff --git a/api/core/v3/resource_generated_test.tmpl b/api/core/v3/resource_generated_test.tmpl index 1d3b3f8c59..f32a4ba7ee 100644 --- a/api/core/v3/resource_generated_test.tmpl +++ b/api/core/v3/resource_generated_test.tmpl @@ -176,20 +176,4 @@ func TestResourceUniqueness(t *testing.T) { if got, want := len(types), len(typeMap)/2; got != want { t.Fatalf("bad number of types: got %d, want %d", got, want) } - rbacNames := make(map[string]bool) - for _, v := range types { - if name := v.RBACName(); rbacNames[name] { - t.Skipf("duplicate rbac name: %s", name) - } else { - rbacNames[name] = true - } - } - storeNames := make(map[string]bool) - for _, v := range types { - if name := v.StoreName(); storeNames[name] { - t.Skipf("duplicate store suffix: %s", name) - } else { - storeNames[name] = true - } - } } From caf4181f2d81130c9b5df91b0fb30e421b2ab61a Mon Sep 17 00:00:00 2001 From: James Phillips Date: Thu, 11 Aug 2022 09:58:35 -0700 Subject: [PATCH 34/35] extract sort order Signed-off-by: James Phillips --- backend/api/generic.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/api/generic.go b/backend/api/generic.go index a4ec8d60e1..6c4f48625b 100644 --- a/backend/api/generic.go +++ b/backend/api/generic.go @@ -192,6 +192,12 @@ func (g *GenericClient) list(ctx context.Context, resources interface{}, pred *s StoreName: g.Kind.StorePrefix(), Context: ctx, } + if pred.Ordering == "NAME" { + req.SortOrder = storev2.SortAscend + if pred.Descending { + req.SortOrder = storev2.SortDescend + } + } list, err := g.StoreV2.List(req, pred) if err != nil { return err From 65f47892e92d58b5b880d6259b6f5d72cf5b6d38 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Thu, 11 Aug 2022 15:36:15 -0700 Subject: [PATCH 35/35] bil check Signed-off-by: James Phillips --- backend/api/generic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/api/generic.go b/backend/api/generic.go index 6c4f48625b..1803fefe61 100644 --- a/backend/api/generic.go +++ b/backend/api/generic.go @@ -192,7 +192,7 @@ func (g *GenericClient) list(ctx context.Context, resources interface{}, pred *s StoreName: g.Kind.StorePrefix(), Context: ctx, } - if pred.Ordering == "NAME" { + if pred != nil && pred.Ordering == "NAME" { req.SortOrder = storev2.SortAscend if pred.Descending { req.SortOrder = storev2.SortDescend