github.com/Axway/agent-sdk@v1.1.101/pkg/agent/handler/instance.go (about) 1 package handler 2 3 import ( 4 "context" 5 6 agentcache "github.com/Axway/agent-sdk/pkg/agent/cache" 7 apiv1 "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/api/v1" 8 management "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/management/v1alpha1" 9 "github.com/Axway/agent-sdk/pkg/watchmanager/proto" 10 ) 11 12 type instanceHandler struct { 13 agentCacheManager agentcache.Manager 14 envName string 15 } 16 17 // NewInstanceHandler creates a Handler for API Service Instances. 18 func NewInstanceHandler(agentCacheManager agentcache.Manager, envName string) Handler { 19 return &instanceHandler{ 20 agentCacheManager: agentCacheManager, 21 envName: envName, 22 } 23 } 24 25 func (h *instanceHandler) Handle(ctx context.Context, _ *proto.EventMeta, resource *apiv1.ResourceInstance) error { 26 action := GetActionFromContext(ctx) 27 if resource.Kind != management.APIServiceInstanceGVK().Kind { 28 return nil 29 } 30 31 if resource.Metadata.Scope.Name != h.envName { 32 return nil 33 } 34 35 if action != proto.Event_DELETED { 36 h.agentCacheManager.AddAPIServiceInstance(resource) 37 return nil 38 } 39 40 return h.agentCacheManager.DeleteAPIServiceInstance(resource.Metadata.ID) 41 }