Skip to content

Commit

Permalink
move to plugin (#2465)
Browse files Browse the repository at this point in the history
* fix: pointer

* fix: pointer

* fix: pointer
  • Loading branch information
Mahanmmi authored Jan 15, 2025
1 parent fa64fc7 commit 78c4995
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 43 deletions.
5 changes: 2 additions & 3 deletions services/integration/api/integrations/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ type API struct {
}

const (
UiSpecsPath string = "/ui-specs"
TemplateDeploymentPath string = "/integrations/deployment-template.yaml"
TemplateManualsDeploymentPath string = "/integrations/deployment-template-manuals.yaml"
TemplateScaledObjectPath string = "/integrations/scaled-object-template.yaml"
Expand Down Expand Up @@ -1698,7 +1697,7 @@ func (h API) ListIntegrationTypeResourceTypes(c echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, "failed to list integration type resource types")
}
for rt, rtConfig := range resourceTypes {
if rtConfig != nil {
if !rtConfig.IsEmpty() {
items = append(items, rtConfig.ToAPI())
} else {
items = append(items, models.ResourceTypeConfiguration{
Expand Down Expand Up @@ -1752,7 +1751,7 @@ func (h API) GetIntegrationTypeResourceType(c echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, "failed to list integration type resource types")
}
if rt, ok := resourceTypes[resourceType]; ok {
if rt != nil {
if !rt.IsEmpty() {
return c.JSON(http.StatusOK, rt.ToAPI())
} else {
return c.JSON(http.StatusOK, models.ResourceTypeConfiguration{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ func (i *Integration) DiscoverIntegrations(jsonData []byte) ([]models.Integratio
return integrations, nil
}

func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[string]*interfaces.ResourceTypeConfiguration, error) {
func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[string]interfaces.ResourceTypeConfiguration, error) {
resourceTypes := configs.ResourceTypesList
if labels["integration/aws/organization-master"] == "true" {
resourceTypes = append(resourceTypes, configs.OrganizationMasterResourceTypesList...)
}
resourceTypesMap := make(map[string]*interfaces.ResourceTypeConfiguration)
resourceTypesMap := make(map[string]interfaces.ResourceTypeConfiguration)
for _, resourceType := range resourceTypes {
resourceTypesMap[resourceType] = nil
resourceTypesMap[resourceType] = interfaces.ResourceTypeConfiguration{}
}
return resourceTypesMap, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ func (i *Integration) DiscoverIntegrations(jsonData []byte) ([]models.Integratio
return integrations, nil
}

func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[string]*interfaces.ResourceTypeConfiguration, error) {
resourceTypesMap := make(map[string]*interfaces.ResourceTypeConfiguration)
func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[string]interfaces.ResourceTypeConfiguration, error) {
resourceTypesMap := make(map[string]interfaces.ResourceTypeConfiguration)
for _, resourceType := range configs.ResourceTypesList {
resourceTypesMap[resourceType] = nil
resourceTypesMap[resourceType] = interfaces.ResourceTypeConfiguration{}
}
return resourceTypesMap, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ func (i *Integration) DiscoverIntegrations(jsonData []byte) ([]models.Integratio
return integrations, nil
}

func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[string]*interfaces.ResourceTypeConfiguration, error) {
resourceTypesMap := make(map[string]*interfaces.ResourceTypeConfiguration)
func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[string]interfaces.ResourceTypeConfiguration, error) {
resourceTypesMap := make(map[string]interfaces.ResourceTypeConfiguration)
for _, resourceType := range configs.ResourceTypesList {
resourceTypesMap[resourceType] = nil
resourceTypesMap[resourceType] = interfaces.ResourceTypeConfiguration{}
}
return resourceTypesMap, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ func (i *Integration) DiscoverIntegrations(jsonData []byte) ([]models.Integratio
return integrations, nil
}

func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[string]*interfaces.ResourceTypeConfiguration, error) {
resourceTypesMap := make(map[string]*interfaces.ResourceTypeConfiguration)
func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[string]interfaces.ResourceTypeConfiguration, error) {
resourceTypesMap := make(map[string]interfaces.ResourceTypeConfiguration)
for _, resourceType := range configs.ResourceTypesList {
resourceTypesMap[resourceType] = nil
resourceTypesMap[resourceType] = interfaces.ResourceTypeConfiguration{}
}
return resourceTypesMap, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ func (i *Integration) DiscoverIntegrations(jsonData []byte) ([]models.Integratio
}, nil
}

func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[string]*interfaces.ResourceTypeConfiguration, error) {
resourceTypesMap := make(map[string]*interfaces.ResourceTypeConfiguration)
func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[string]interfaces.ResourceTypeConfiguration, error) {
resourceTypesMap := make(map[string]interfaces.ResourceTypeConfiguration)
for _, resourceType := range configs.ResourceTypesList {
resourceTypesMap[resourceType] = nil
resourceTypesMap[resourceType] = interfaces.ResourceTypeConfiguration{}
}
return resourceTypesMap, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ func (i *Integration) DiscoverIntegrations(jsonData []byte) ([]models.Integratio
return integrations, nil
}

func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[string]*interfaces.ResourceTypeConfiguration, error) {
resourceTypesMap := make(map[string]*interfaces.ResourceTypeConfiguration)
func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[string]interfaces.ResourceTypeConfiguration, error) {
resourceTypesMap := make(map[string]interfaces.ResourceTypeConfiguration)
for _, resourceType := range configs.ResourceTypesList {
resourceTypesMap[resourceType] = nil
resourceTypesMap[resourceType] = interfaces.ResourceTypeConfiguration{}
}
return resourceTypesMap, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ func (i *Integration) DiscoverIntegrations(jsonData []byte) ([]models.Integratio
return integrations, nil
}

func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[string]*interfaces.ResourceTypeConfiguration, error) {
resourceTypesMap := make(map[string]*interfaces.ResourceTypeConfiguration)
func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[string]interfaces.ResourceTypeConfiguration, error) {
resourceTypesMap := make(map[string]interfaces.ResourceTypeConfiguration)
for _, resourceType := range configs.ResourceTypesList {
resourceTypesMap[resourceType] = nil
resourceTypesMap[resourceType] = interfaces.ResourceTypeConfiguration{}
}
return resourceTypesMap, nil
}
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ func (i *Integration) DiscoverIntegrations(jsonData []byte) ([]models.Integratio
return integrations, nil
}

func (i *Integration) GetResourceTypesByLabels(map[string]string) (map[string]*interfaces.ResourceTypeConfiguration, error) {
resourceTypesMap := make(map[string]*interfaces.ResourceTypeConfiguration)
func (i *Integration) GetResourceTypesByLabels(map[string]string) (map[string]interfaces.ResourceTypeConfiguration, error) {
resourceTypesMap := make(map[string]interfaces.ResourceTypeConfiguration)
for _, resourceType := range configs.ResourceTypesList {
resourceTypesMap[resourceType] = nil
resourceTypesMap[resourceType] = interfaces.ResourceTypeConfiguration{}
}
return resourceTypesMap, nil
}
Expand Down
1 change: 1 addition & 0 deletions services/integration/integration-type/integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func NewIntegrationTypeManager(logger *zap.Logger, integrationTypeDb *gorm.DB) *
Plugins: map[string]plugin.Plugin{pluginName: &interfaces.IntegrationTypePlugin{}},
Cmd: exec.Command(pluginPath),
Logger: hcLogger,
Managed: true,
})

rpcClient, err := client.Client()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type IntegrationConfiguration struct {
type IntegrationType interface {
GetIntegrationType() integration.Type
GetConfiguration() IntegrationConfiguration
GetResourceTypesByLabels(map[string]string) (map[string]*ResourceTypeConfiguration, error)
GetResourceTypesByLabels(map[string]string) (map[string]ResourceTypeConfiguration, error)
HealthCheck(jsonData []byte, providerId string, labels map[string]string, annotations map[string]string) (bool, error)
DiscoverIntegrations(jsonData []byte) ([]models.Integration, error)
GetResourceTypeFromTableName(tableName string) string
Expand Down Expand Up @@ -62,8 +62,8 @@ func (i *IntegrationTypeRPC) GetConfiguration() IntegrationConfiguration {
return configuration
}

func (i *IntegrationTypeRPC) GetResourceTypesByLabels(labels map[string]string) (map[string]*ResourceTypeConfiguration, error) {
var resourceTypes map[string]*ResourceTypeConfiguration
func (i *IntegrationTypeRPC) GetResourceTypesByLabels(labels map[string]string) (map[string]ResourceTypeConfiguration, error) {
var resourceTypes map[string]ResourceTypeConfiguration
err := i.client.Call("Plugin.GetResourceTypesByLabels", labels, &resourceTypes)
return resourceTypes, err
}
Expand Down Expand Up @@ -115,7 +115,7 @@ func (i *IntegrationTypeRPCServer) GetConfiguration(_ struct{}, configuration *I
return nil
}

func (i *IntegrationTypeRPCServer) GetResourceTypesByLabels(labels map[string]string, resourceTypes *map[string]*ResourceTypeConfiguration) error {
func (i *IntegrationTypeRPCServer) GetResourceTypesByLabels(labels map[string]string, resourceTypes *map[string]ResourceTypeConfiguration) error {
var err error
*resourceTypes, err = i.Impl.GetResourceTypesByLabels(labels)
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func (c *ResourceTypeConfiguration) ToAPI() models.ResourceTypeConfiguration {
}
}

func (p *ResourceTypeConfiguration) IsEmpty() bool {
return p.Name == "" && p.Description == "" && len(p.Params) == 0 && p.IntegrationType == ""
}

func (p *Param) ToAPI() models.Param {
return models.Param{
Name: p.Name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ func (i *Integration) DiscoverIntegrations(jsonData []byte) ([]models.Integratio
return integrations, nil
}

func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[string]*interfaces.ResourceTypeConfiguration, error) {
resourceTypesMap := make(map[string]*interfaces.ResourceTypeConfiguration)
func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[string]interfaces.ResourceTypeConfiguration, error) {
resourceTypesMap := make(map[string]interfaces.ResourceTypeConfiguration)
for _, resourceType := range configs.ResourceTypesList {
resourceTypesMap[resourceType] = nil
resourceTypesMap[resourceType] = interfaces.ResourceTypeConfiguration{}
}
return resourceTypesMap, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ func (i *Integration) DiscoverIntegrations(jsonData []byte) ([]models.Integratio
return nil, fmt.Errorf("unknown registry type: %s", credentials.GetRegistryType())
}

func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[string]*interfaces.ResourceTypeConfiguration, error) {
resourceTypesMap := make(map[string]*interfaces.ResourceTypeConfiguration)
func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[string]interfaces.ResourceTypeConfiguration, error) {
resourceTypesMap := make(map[string]interfaces.ResourceTypeConfiguration)
for _, resourceType := range configs.ResourceTypesList {
resourceTypesMap[resourceType] = nil
resourceTypesMap[resourceType] = interfaces.ResourceTypeConfiguration{}
}
return resourceTypesMap, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ func (i *Integration) DiscoverIntegrations(jsonData []byte) ([]models.Integratio
return integrations, nil
}

func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[string]*interfaces.ResourceTypeConfiguration, error) {
resourceTypesMap := make(map[string]*interfaces.ResourceTypeConfiguration)
func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[string]interfaces.ResourceTypeConfiguration, error) {
resourceTypesMap := make(map[string]interfaces.ResourceTypeConfiguration)
for _, resourceType := range configs.ResourceTypesList {
resourceTypesMap[resourceType] = nil
resourceTypesMap[resourceType] = interfaces.ResourceTypeConfiguration{}
}
return resourceTypesMap, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ func (i *Integration) DiscoverIntegrations(jsonData []byte) ([]models.Integratio
return integrations, nil
}

func (i *Integration) GetResourceTypesByLabels(map[string]string) (map[string]*interfaces.ResourceTypeConfiguration, error) {
resourceTypesMap := make(map[string]*interfaces.ResourceTypeConfiguration)
func (i *Integration) GetResourceTypesByLabels(map[string]string) (map[string]interfaces.ResourceTypeConfiguration, error) {
resourceTypesMap := make(map[string]interfaces.ResourceTypeConfiguration)
for _, resourceType := range configs.ResourceTypesList {
resourceTypesMap[resourceType] = nil
resourceTypesMap[resourceType] = interfaces.ResourceTypeConfiguration{}
}
return resourceTypesMap, nil
}
Expand Down

0 comments on commit 78c4995

Please sign in to comment.