From 006319cf4f38d09447e0dfc557ccfa3a003cbc67 Mon Sep 17 00:00:00 2001 From: artaasadi Date: Thu, 19 Dec 2024 17:35:55 +0100 Subject: [PATCH] fix: resolve import cycle --- services/integration/api/integrations/api.go | 11 ++++----- .../api/models/integration_type.go | 7 ------ .../integration/api/models/resource_type.go | 22 ++++++++++++++++++ .../interfaces/resource_type.go | 23 +++++++++++++++++++ 4 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 services/integration/api/models/resource_type.go diff --git a/services/integration/api/integrations/api.go b/services/integration/api/integrations/api.go index 870c7a5ba..ac6b261e7 100644 --- a/services/integration/api/integrations/api.go +++ b/services/integration/api/integrations/api.go @@ -19,7 +19,6 @@ import ( "github.com/opengovern/opencomply/services/integration/db" "github.com/opengovern/opencomply/services/integration/entities" integration_type "github.com/opengovern/opencomply/services/integration/integration-type" - "github.com/opengovern/opencomply/services/integration/integration-type/interfaces" models2 "github.com/opengovern/opencomply/services/integration/models" "go.uber.org/zap" "golang.org/x/net/context" @@ -1650,7 +1649,7 @@ func (h API) ListIntegrationTypeResourceTypes(c echo.Context) error { cursor, _ = strconv.ParseInt(cursorStr, 10, 64) } - var items []interfaces.ResourceTypeConfiguration + var items []models.ResourceTypeConfiguration if it, ok := integration_type.IntegrationTypes[integration_type.ParseType(integrationType)]; ok { resourceTypes, err := it.GetResourceTypesByLabels(nil) if err != nil { @@ -1659,9 +1658,9 @@ func (h API) ListIntegrationTypeResourceTypes(c echo.Context) error { } for rt, rtConfig := range resourceTypes { if rtConfig != nil { - items = append(items, *rtConfig) + items = append(items, rtConfig.ToAPI()) } else { - items = append(items, interfaces.ResourceTypeConfiguration{ + items = append(items, models.ResourceTypeConfiguration{ Name: rt, IntegrationType: integration_type.ParseType(integrationType), }) @@ -1713,9 +1712,9 @@ func (h API) GetIntegrationTypeResourceType(c echo.Context) error { } if rt, ok := resourceTypes[resourceType]; ok { if rt != nil { - return c.JSON(http.StatusOK, *rt) + return c.JSON(http.StatusOK, rt.ToAPI()) } else { - return c.JSON(http.StatusOK, interfaces.ResourceTypeConfiguration{ + return c.JSON(http.StatusOK, models.ResourceTypeConfiguration{ Name: resourceType, IntegrationType: integration_type.ParseType(integrationType), }) diff --git a/services/integration/api/models/integration_type.go b/services/integration/api/models/integration_type.go index a4fcc35d3..dd5007ded 100644 --- a/services/integration/api/models/integration_type.go +++ b/services/integration/api/models/integration_type.go @@ -1,7 +1,5 @@ package models -import "github.com/opengovern/opencomply/services/integration/integration-type/interfaces" - type IntegrationType struct { ID int64 `json:"id"` Name string `json:"name"` @@ -35,8 +33,3 @@ type ListIntegrationTypesResponse struct { IntegrationTypes []ListIntegrationTypesItem `json:"integration_types"` TotalCount int `json:"total_count"` } - -type ListIntegrationTypeResourceTypesResponse struct { - ResourceTypes []interfaces.ResourceTypeConfiguration `json:"integration_types"` - TotalCount int `json:"total_count"` -} diff --git a/services/integration/api/models/resource_type.go b/services/integration/api/models/resource_type.go new file mode 100644 index 000000000..05ef877a3 --- /dev/null +++ b/services/integration/api/models/resource_type.go @@ -0,0 +1,22 @@ +package models + +import "github.com/opengovern/og-util/pkg/integration" + +type ResourceTypeConfiguration struct { + Name string `json:"name"` + IntegrationType integration.Type `json:"integration_type"` + Description string `json:"description"` + Params []Param `json:"params"` +} + +type Param struct { + Name string `json:"name"` + Description string `json:"description"` + Required bool `json:"required"` + Default *string `json:"default"` +} + +type ListIntegrationTypeResourceTypesResponse struct { + ResourceTypes []ResourceTypeConfiguration `json:"integration_types"` + TotalCount int `json:"total_count"` +} diff --git a/services/integration/integration-type/interfaces/resource_type.go b/services/integration/integration-type/interfaces/resource_type.go index b5be2bad0..76c447096 100644 --- a/services/integration/integration-type/interfaces/resource_type.go +++ b/services/integration/integration-type/interfaces/resource_type.go @@ -2,6 +2,7 @@ package interfaces import ( "github.com/opengovern/og-util/pkg/integration" + "github.com/opengovern/opencomply/services/integration/api/models" ) type ResourceTypeConfiguration struct { @@ -17,3 +18,25 @@ type Param struct { Required bool `json:"required"` Default *string `json:"default"` } + +func (c *ResourceTypeConfiguration) ToAPI() models.ResourceTypeConfiguration { + var params []models.Param + for _, param := range c.Params { + params = append(params, param.ToAPI()) + } + return models.ResourceTypeConfiguration{ + Name: c.Name, + IntegrationType: c.IntegrationType, + Description: c.Description, + Params: params, + } +} + +func (p *Param) ToAPI() models.Param { + return models.Param{ + Name: p.Name, + Description: p.Description, + Required: p.Required, + Default: p.Default, + } +}