@@ -2,19 +2,39 @@ package main
22
33import (
44 "encoding/json"
5+ "strconv"
6+
7+ "github.com/hashicorp/go-plugin"
58 "github.com/jackc/pgtype"
69 "github.com/opengovern/og-describer-github/global"
710 "github.com/opengovern/og-describer-github/global/maps"
811 "github.com/opengovern/og-util/pkg/integration"
9- "github.com/opengovern/opencomply/services/integration/integration-type/interfaces"
1012 "github.com/opengovern/opencomply/services/integration/models"
11- "strconv"
13+ "net/rpc"
14+
1215)
1316
1417type Integration struct {}
1518
16- func (i * Integration ) GetConfiguration () interfaces.IntegrationConfiguration {
17- return interfaces.IntegrationConfiguration {
19+
20+
21+
22+ type IntegrationConfiguration struct {
23+ NatsScheduledJobsTopic string
24+ NatsManualJobsTopic string
25+ NatsStreamName string
26+ NatsConsumerGroup string
27+ NatsConsumerGroupManuals string
28+
29+ SteampipePluginName string
30+
31+ UISpec []byte
32+
33+ DescriberDeploymentName string
34+ DescriberRunCommand string
35+ }
36+ func (i * Integration ) GetConfiguration () IntegrationConfiguration {
37+ return IntegrationConfiguration {
1838 NatsScheduledJobsTopic : global .JobQueueTopic ,
1939 NatsManualJobsTopic : global .JobQueueTopicManuals ,
2040 NatsStreamName : global .StreamName ,
@@ -83,13 +103,13 @@ func (i *Integration) DiscoverIntegrations(jsonData []byte) ([]models.Integratio
83103 return integrations , nil
84104}
85105
86- func (i * Integration ) GetResourceTypesByLabels (labels map [string ]string ) (map [string ]interfaces .ResourceTypeConfiguration , error ) {
87- resourceTypesMap := make (map [string ]interfaces .ResourceTypeConfiguration )
106+ func (i * Integration ) GetResourceTypesByLabels (labels map [string ]string ) (map [string ]maps .ResourceTypeConfiguration , error ) {
107+ resourceTypesMap := make (map [string ]maps .ResourceTypeConfiguration )
88108 for _ , resourceType := range maps .ResourceTypesList {
89109 if v , ok := maps .ResourceTypeConfigs [resourceType ]; ok {
90110 resourceTypesMap [resourceType ] = * v
91111 } else {
92- resourceTypesMap [resourceType ] = interfaces .ResourceTypeConfiguration {}
112+ resourceTypesMap [resourceType ] = maps .ResourceTypeConfiguration {}
93113 }
94114 }
95115 return resourceTypesMap , nil
@@ -120,3 +140,78 @@ func (i *Integration) ListAllTables() map[string][]string {
120140
121141 return tables
122142}
143+ var HandshakeConfig = plugin.HandshakeConfig {
144+ ProtocolVersion : 1 ,
145+ MagicCookieKey : "platform-integration-plugin" ,
146+ MagicCookieValue : "integration" ,
147+ }
148+
149+ type IntegrationTypePlugin struct {
150+ Impl IntegrationType
151+ }
152+ type IntegrationType interface {
153+ GetIntegrationType () integration.Type
154+ GetConfiguration () IntegrationConfiguration
155+ GetResourceTypesByLabels (map [string ]string ) (map [string ]maps.ResourceTypeConfiguration , error )
156+ HealthCheck (jsonData []byte , providerId string , labels map [string ]string , annotations map [string ]string ) (bool , error )
157+ DiscoverIntegrations (jsonData []byte ) ([]models.Integration , error )
158+ GetResourceTypeFromTableName (tableName string ) string
159+ ListAllTables () map [string ][]string
160+ }
161+ type IntegrationTypeRPCServer struct {
162+ Impl IntegrationType
163+ }
164+ type IntegrationTypeRPC struct {
165+ client * rpc.Client
166+ }
167+ func (p * IntegrationTypePlugin ) Server (* plugin.MuxBroker ) (any , error ) {
168+ return & IntegrationTypeRPCServer {Impl : p .Impl }, nil
169+ }
170+
171+ func (IntegrationTypePlugin ) Client (b * plugin.MuxBroker , c * rpc.Client ) (any , error ) {
172+ return & IntegrationTypeRPC {client : c }, nil
173+ }
174+
175+
176+ func (i * IntegrationTypeRPCServer ) GetIntegrationType (_ struct {}, integrationType * integration.Type ) error {
177+ * integrationType = i .Impl .GetIntegrationType ()
178+ return nil
179+ }
180+
181+ func (i * IntegrationTypeRPCServer ) GetConfiguration (_ struct {}, configuration * IntegrationConfiguration ) error {
182+ * configuration = i .Impl .GetConfiguration ()
183+ return nil
184+ }
185+
186+ func (i * IntegrationTypeRPCServer ) GetResourceTypesByLabels (labels map [string ]string , resourceTypes * map [string ]maps.ResourceTypeConfiguration ) error {
187+ var err error
188+ * resourceTypes , err = i .Impl .GetResourceTypesByLabels (labels )
189+ return err
190+ }
191+ type HealthCheckRequest struct {
192+ JsonData []byte
193+ ProviderId string
194+ Labels map [string ]string
195+ Annotations map [string ]string
196+ }
197+ func (i * IntegrationTypeRPCServer ) HealthCheck (request HealthCheckRequest , result * bool ) error {
198+ var err error
199+ * result , err = i .Impl .HealthCheck (request .JsonData , request .ProviderId , request .Labels , request .Annotations )
200+ return err
201+ }
202+
203+ func (i * IntegrationTypeRPCServer ) DiscoverIntegrations (jsonData []byte , integrations * []models.Integration ) error {
204+ var err error
205+ * integrations , err = i .Impl .DiscoverIntegrations (jsonData )
206+ return err
207+ }
208+
209+ func (i * IntegrationTypeRPCServer ) GetResourceTypeFromTableName (tableName string , resourceType * string ) error {
210+ * resourceType = i .Impl .GetResourceTypeFromTableName (tableName )
211+ return nil
212+ }
213+
214+ func (i * IntegrationTypeRPCServer ) ListAllTables (_ struct {}, tables * map [string ][]string ) error {
215+ * tables = i .Impl .ListAllTables ()
216+ return nil
217+ }
0 commit comments