Skip to content

Commit

Permalink
feat: add plugin ping (#2480)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahanmmi authored Jan 17, 2025
1 parent 8e32889 commit 925225c
Show file tree
Hide file tree
Showing 17 changed files with 201 additions and 117 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ require (
github.com/lib/pq v1.10.9
github.com/nats-io/nats.go v1.36.0
github.com/open-policy-agent/opa v0.69.0
github.com/opengovern/og-util v1.10.1
github.com/opengovern/og-util v1.11.0
github.com/opensearch-project/opensearch-go/v2 v2.3.0
github.com/opensearch-project/opensearch-go/v4 v4.2.0
github.com/ory/dockertest/v3 v3.10.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,8 @@ github.com/opengovern/og-util v1.10.0 h1:Fj3GIl9fpLzoWUwVbZsZ4pc6wlV8SZj5PIfL8wX
github.com/opengovern/og-util v1.10.0/go.mod h1:9uNpGalixRoQkUzPPBdT+JG1epg8FTRx/qmkfTyUZHE=
github.com/opengovern/og-util v1.10.1 h1:D51GVWKI1J1d9v50z6Eg4gG0Q79+aFLGrxe4ynJCAck=
github.com/opengovern/og-util v1.10.1/go.mod h1:9uNpGalixRoQkUzPPBdT+JG1epg8FTRx/qmkfTyUZHE=
github.com/opengovern/og-util v1.11.0 h1:Amct1bHXDF5TBnymstPUEWpWaC+Lji5dnJ8Mr6fkbMA=
github.com/opengovern/og-util v1.11.0/go.mod h1:9uNpGalixRoQkUzPPBdT+JG1epg8FTRx/qmkfTyUZHE=
github.com/opensearch-project/opensearch-go/v2 v2.3.0 h1:nQIEMr+A92CkhHrZgUhcfsrZjibvB3APXf2a1VwCmMQ=
github.com/opensearch-project/opensearch-go/v2 v2.3.0/go.mod h1:8LDr9FCgUTVoT+5ESjc2+iaZuldqE+23Iq0r1XeNue8=
github.com/opensearch-project/opensearch-go/v4 v4.2.0 h1:uaBexfVdeSU15yOUPYF+IY059koVP0oNQPyoSde6N/A=
Expand Down
17 changes: 14 additions & 3 deletions services/integration/api/integration-types/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ func (a *API) GetResourceTypeFromTableName(c echo.Context) error {

rtMap := a.typeManager.GetIntegrationTypeMap()
if value, ok := rtMap[a.typeManager.ParseType(integrationType)]; ok {
resourceType := value.GetResourceTypeFromTableName(tableName)
resourceType, err := value.GetResourceTypeFromTableName(tableName)
if err != nil {
return echo.NewHTTPError(500, err.Error())
}
if resourceType != "" {
res := models.GetResourceTypeFromTableNameResponse{
ResourceType: resourceType,
Expand Down Expand Up @@ -96,7 +99,12 @@ func (a *API) GetConfiguration(c echo.Context) error {

rtMap := a.typeManager.GetIntegrationTypeMap()
if value, ok := rtMap[a.typeManager.ParseType(integrationType)]; ok {
return c.JSON(200, value.GetConfiguration())
conf, err := value.GetConfiguration()
if err != nil {
return echo.NewHTTPError(500, err.Error())
}

return c.JSON(200, conf)
} else {
return echo.NewHTTPError(404, "integration type not found")
}
Expand Down Expand Up @@ -156,7 +164,10 @@ func (a *API) ListTables(c echo.Context) error {

rtMap := a.typeManager.GetIntegrationTypeMap()
if value, ok := rtMap[a.typeManager.ParseType(integrationType)]; ok {
tables := value.ListAllTables()
tables, err := value.ListAllTables()
if err != nil {
return echo.NewHTTPError(500, err.Error())
}
return c.JSON(200, models.ListTablesResponse{Tables: tables})
} else {
return echo.NewHTTPError(404, "integration type not found")
Expand Down
24 changes: 20 additions & 4 deletions services/integration/api/integrations/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,11 @@ func (h API) GetIntegrationTypeUiSpec(c echo.Context) error {
if !ok {
return echo.NewHTTPError(http.StatusNotFound, "invalid integration type")
}
cnf := integrationType.GetConfiguration()
cnf, err := integrationType.GetConfiguration()
if err != nil {
h.logger.Error("failed to get configuration", zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError, "failed to get configuration")
}

var result interface{}
if err := json.Unmarshal(cnf.UISpec, &result); err != nil {
Expand Down Expand Up @@ -1170,7 +1174,11 @@ func (h API) DisableIntegrationType(c echo.Context) error {
if !ok {
return echo.NewHTTPError(http.StatusNotFound, "invalid integration type")
}
cnf := integrationType.GetConfiguration()
cnf, err := integrationType.GetConfiguration()
if err != nil {
h.logger.Error("failed to get configuration", zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError, "failed to get configuration"+err.Error())
}

// Scheduled deployment
var describerDeployment appsv1.Deployment
Expand Down Expand Up @@ -1320,7 +1328,11 @@ func (h API) UpgradeIntegrationType(c echo.Context) error {
if !ok {
return echo.NewHTTPError(http.StatusNotFound, "invalid integration type")
}
cnf := integrationType.GetConfiguration()
cnf, err := integrationType.GetConfiguration()
if err != nil {
h.logger.Error("failed to get configuration", zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError, "failed to get configuration")
}

integrationTypeInfo, err := h.database.GetIntegrationType(integrationTypeName)
if err != nil {
Expand Down Expand Up @@ -1464,7 +1476,11 @@ func (h API) EnableIntegrationTypeHelper(ctx context.Context, logger *zap.Logger
if !ok {
return echo.NewHTTPError(http.StatusNotFound, "invalid integration type")
}
cnf := integrationType.GetConfiguration()
cnf, err := integrationType.GetConfiguration()
if err != nil {
logger.Error("failed to get integration type configuration", zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError, "failed to get integration type configuration")
}

describerDeployment.ObjectMeta.Name = cnf.DescriberDeploymentName
describerDeployment.ObjectMeta.Namespace = currentNamespace
Expand Down
22 changes: 13 additions & 9 deletions services/integration/integration-type/aws-account/aws_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

type Integration struct{}

func (i *Integration) GetConfiguration() interfaces.IntegrationConfiguration {
func (i *Integration) GetConfiguration() (interfaces.IntegrationConfiguration, error) {
return interfaces.IntegrationConfiguration{
NatsScheduledJobsTopic: configs.JobQueueTopic,
NatsManualJobsTopic: configs.JobQueueTopicManuals,
Expand All @@ -30,7 +30,7 @@ func (i *Integration) GetConfiguration() interfaces.IntegrationConfiguration {

DescriberDeploymentName: configs.DescriberDeploymentName,
DescriberRunCommand: configs.DescriberRunCommand,
}
}, nil
}

func (i *Integration) HealthCheck(jsonData []byte, providerId string, labels map[string]string, annotations map[string]string) (bool, error) {
Expand Down Expand Up @@ -117,17 +117,21 @@ func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[st
return resourceTypesMap, nil
}

func (i *Integration) GetResourceTypeFromTableName(tableName string) string {
func (i *Integration) GetResourceTypeFromTableName(tableName string) (string, error) {
if v, ok := configs.TablesToResourceTypes[tableName]; ok {
return v
return v, nil
}
return ""
return "", nil
}

func (i *Integration) GetIntegrationType() (integration.Type, error) {
return configs.IntegrationTypeAwsCloudAccount, nil
}

func (i *Integration) GetIntegrationType() integration.Type {
return configs.IntegrationTypeAwsCloudAccount
func (i *Integration) ListAllTables() (map[string][]interfaces.CloudQLColumn, error) {
return make(map[string][]interfaces.CloudQLColumn), nil
}

func (i *Integration) ListAllTables() map[string][]interfaces.CloudQLColumn {
return make(map[string][]interfaces.CloudQLColumn)
func (i *Integration) Ping() error {
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

type Integration struct{}

func (i *Integration) GetConfiguration() interfaces.IntegrationConfiguration {
func (i *Integration) GetConfiguration() (interfaces.IntegrationConfiguration, error) {
return interfaces.IntegrationConfiguration{
NatsScheduledJobsTopic: configs.JobQueueTopic,
NatsManualJobsTopic: configs.JobQueueTopicManuals,
Expand All @@ -25,7 +25,7 @@ func (i *Integration) GetConfiguration() interfaces.IntegrationConfiguration {

DescriberDeploymentName: configs.DescriberDeploymentName,
DescriberRunCommand: configs.DescriberRunCommand,
}
}, nil
}

func (i *Integration) HealthCheck(jsonData []byte, providerId string, labels map[string]string, annotations map[string]string) (bool, error) {
Expand Down Expand Up @@ -83,18 +83,22 @@ func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[st
return resourceTypesMap, nil
}

func (i *Integration) GetResourceTypeFromTableName(tableName string) string {
func (i *Integration) GetResourceTypeFromTableName(tableName string) (string, error) {
if v, ok := configs.TablesToResourceTypes[tableName]; ok {
return v
return v, nil
}

return ""
return "", nil
}

func (i *Integration) GetIntegrationType() (integration.Type, error) {
return configs.IntegrationTypeAzureSubscription, nil
}

func (i *Integration) GetIntegrationType() integration.Type {
return configs.IntegrationTypeAzureSubscription
func (i *Integration) ListAllTables() (map[string][]interfaces.CloudQLColumn, error) {
return make(map[string][]interfaces.CloudQLColumn), nil
}

func (i *Integration) ListAllTables() map[string][]interfaces.CloudQLColumn {
return make(map[string][]interfaces.CloudQLColumn)
func (i *Integration) Ping() error {
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

type Integration struct{}

func (i *Integration) GetConfiguration() interfaces.IntegrationConfiguration {
func (i *Integration) GetConfiguration() (interfaces.IntegrationConfiguration, error) {
return interfaces.IntegrationConfiguration{
NatsScheduledJobsTopic: configs.JobQueueTopic,
NatsManualJobsTopic: configs.JobQueueTopicManuals,
Expand All @@ -26,7 +26,7 @@ func (i *Integration) GetConfiguration() interfaces.IntegrationConfiguration {

DescriberRunCommand: configs.DescriberRunCommand,
DescriberDeploymentName: configs.DescriberDeploymentName,
}
}, nil
}

func (i *Integration) HealthCheck(jsonData []byte, providerId string, labels map[string]string, annotations map[string]string) (bool, error) {
Expand Down Expand Up @@ -82,18 +82,22 @@ func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[st
return resourceTypesMap, nil
}

func (i *Integration) GetResourceTypeFromTableName(tableName string) string {
func (i *Integration) GetResourceTypeFromTableName(tableName string) (string, error) {
if v, ok := configs.TablesToResourceTypes[tableName]; ok {
return v
return v, nil
}

return ""
return "", nil
}

func (i *Integration) GetIntegrationType() (integration.Type, error) {
return configs.IntegrationNameCloudflareAccount, nil
}

func (i *Integration) GetIntegrationType() integration.Type {
return configs.IntegrationNameCloudflareAccount
func (i *Integration) ListAllTables() (map[string][]interfaces.CloudQLColumn, error) {
return make(map[string][]interfaces.CloudQLColumn), nil
}

func (i *Integration) ListAllTables() map[string][]interfaces.CloudQLColumn {
return make(map[string][]interfaces.CloudQLColumn)
func (i *Integration) Ping() error {
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

type Integration struct{}

func (i *Integration) GetConfiguration() interfaces.IntegrationConfiguration {
func (i *Integration) GetConfiguration() (interfaces.IntegrationConfiguration, error) {
return interfaces.IntegrationConfiguration{
NatsScheduledJobsTopic: configs.JobQueueTopic,
NatsManualJobsTopic: configs.JobQueueTopicManuals,
Expand All @@ -26,7 +26,7 @@ func (i *Integration) GetConfiguration() interfaces.IntegrationConfiguration {

DescriberDeploymentName: configs.DescriberDeploymentName,
DescriberRunCommand: configs.DescriberRunCommand,
}
}, nil
}

func (i *Integration) HealthCheck(jsonData []byte, providerId string, labels map[string]string, annotations map[string]string) (bool, error) {
Expand Down Expand Up @@ -86,18 +86,22 @@ func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[st
return resourceTypesMap, nil
}

func (i *Integration) GetResourceTypeFromTableName(tableName string) string {
func (i *Integration) GetResourceTypeFromTableName(tableName string) (string, error) {
if v, ok := configs.TablesToResourceTypes[tableName]; ok {
return v
return v, nil
}

return ""
return "", nil
}

func (i *Integration) GetIntegrationType() (integration.Type, error) {
return configs.IntegrationTypeCohereaiProject, nil
}

func (i *Integration) GetIntegrationType() integration.Type {
return configs.IntegrationTypeCohereaiProject
func (i *Integration) ListAllTables() (map[string][]interfaces.CloudQLColumn, error) {
return make(map[string][]interfaces.CloudQLColumn), nil
}

func (i *Integration) ListAllTables() map[string][]interfaces.CloudQLColumn {
return make(map[string][]interfaces.CloudQLColumn)
func (i *Integration) Ping() error {
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

type Integration struct{}

func (i *Integration) GetConfiguration() interfaces.IntegrationConfiguration {
func (i *Integration) GetConfiguration() (interfaces.IntegrationConfiguration, error) {
return interfaces.IntegrationConfiguration{
NatsScheduledJobsTopic: configs.JobQueueTopic,
NatsManualJobsTopic: configs.JobQueueTopicManuals,
Expand All @@ -26,7 +26,7 @@ func (i *Integration) GetConfiguration() interfaces.IntegrationConfiguration {

DescriberDeploymentName: configs.DescriberDeploymentName,
DescriberRunCommand: configs.DescriberRunCommand,
}
}, nil
}

func (i *Integration) HealthCheck(jsonData []byte, _ string, _ map[string]string, _ map[string]string) (bool, error) {
Expand Down Expand Up @@ -71,18 +71,22 @@ func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[st
return resourceTypesMap, nil
}

func (i *Integration) GetResourceTypeFromTableName(tableName string) string {
func (i *Integration) GetResourceTypeFromTableName(tableName string) (string, error) {
if v, ok := configs.TablesToResourceTypes[tableName]; ok {
return v
return v, nil
}

return ""
return "", nil
}

func (i *Integration) GetIntegrationType() (integration.Type, error) {
return configs.IntegrationTypeDigitalOceanTeam, nil
}

func (i *Integration) GetIntegrationType() integration.Type {
return configs.IntegrationTypeDigitalOceanTeam
func (i *Integration) ListAllTables() (map[string][]interfaces.CloudQLColumn, error) {
return make(map[string][]interfaces.CloudQLColumn), nil
}

func (i *Integration) ListAllTables() map[string][]interfaces.CloudQLColumn {
return make(map[string][]interfaces.CloudQLColumn)
func (i *Integration) Ping() error {
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

type Integration struct{}

func (i *Integration) GetConfiguration() interfaces.IntegrationConfiguration {
func (i *Integration) GetConfiguration() (interfaces.IntegrationConfiguration, error) {
return interfaces.IntegrationConfiguration{
NatsScheduledJobsTopic: configs.JobQueueTopic,
NatsManualJobsTopic: configs.JobQueueTopicManuals,
Expand All @@ -26,7 +26,7 @@ func (i *Integration) GetConfiguration() interfaces.IntegrationConfiguration {

DescriberDeploymentName: configs.DescriberDeploymentName,
DescriberRunCommand: configs.DescriberRunCommand,
}
}, nil
}

func (i *Integration) HealthCheck(jsonData []byte, providerId string, labels map[string]string, annotations map[string]string) (bool, error) {
Expand Down Expand Up @@ -81,17 +81,21 @@ func (i *Integration) GetResourceTypesByLabels(labels map[string]string) (map[st
return resourceTypesMap, nil
}

func (i *Integration) GetResourceTypeFromTableName(tableName string) string {
func (i *Integration) GetResourceTypeFromTableName(tableName string) (string, error) {
if v, ok := configs.TablesToResourceTypes[tableName]; ok {
return v
return v, nil
}
return ""
return "", nil
}

func (i *Integration) GetIntegrationType() (integration.Type, error) {
return configs.IntegrationTypeDopplerAccount, nil
}

func (i *Integration) GetIntegrationType() integration.Type {
return configs.IntegrationTypeDopplerAccount
func (i *Integration) ListAllTables() (map[string][]interfaces.CloudQLColumn, error) {
return make(map[string][]interfaces.CloudQLColumn), nil
}

func (i *Integration) ListAllTables() map[string][]interfaces.CloudQLColumn {
return make(map[string][]interfaces.CloudQLColumn)
func (i *Integration) Ping() error {
return nil
}
Loading

0 comments on commit 925225c

Please sign in to comment.