Skip to content

Commit

Permalink
Merge pull request #2286 from opengovern/fix-tasks
Browse files Browse the repository at this point in the history
fix: resolve import cycle
  • Loading branch information
artaasadi authored Dec 19, 2024
2 parents e2a3648 + 006319c commit 5a57eda
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 13 deletions.
11 changes: 5 additions & 6 deletions services/integration/api/integrations/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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),
})
Expand Down Expand Up @@ -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),
})
Expand Down
7 changes: 0 additions & 7 deletions services/integration/api/models/integration_type.go
Original file line number Diff line number Diff line change
@@ -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"`
Expand Down Expand Up @@ -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"`
}
22 changes: 22 additions & 0 deletions services/integration/api/models/resource_type.go
Original file line number Diff line number Diff line change
@@ -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"`
}
23 changes: 23 additions & 0 deletions services/integration/integration-type/interfaces/resource_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}
}

0 comments on commit 5a57eda

Please sign in to comment.