-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
165 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
services/integration/integration-type/digitalocean-team/configs/credentials.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package configs | ||
|
||
type IntegrationCredentials struct { | ||
AuthToken string `json:"auth_token"` | ||
} |
7 changes: 7 additions & 0 deletions
7
services/integration/integration-type/digitalocean-team/configs/general.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package configs | ||
|
||
import "github.com/opengovern/og-util/pkg/integration" | ||
|
||
const ( | ||
IntegrationTypeDigitalOceanTeam = integration.Type("digitalocean_team") // example: AWS_ACCOUNT, AZURE_SUBSCRIPTION | ||
) |
9 changes: 9 additions & 0 deletions
9
services/integration/integration-type/digitalocean-team/configs/nats.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package configs | ||
|
||
const ( | ||
StreamName = "og_describer_digitalocean_team" | ||
JobQueueTopic = "og_describer_digitalocean_team_job_queue" | ||
ConsumerGroup = "describer-digitalocean-team" | ||
JobQueueTopicManuals = "og_describer_digitalocean_team_manuals_job_queue" | ||
ConsumerGroupManuals = "describer-digitalocean-team-manuals" | ||
) |
5 changes: 5 additions & 0 deletions
5
services/integration/integration-type/digitalocean-team/configs/resource_types_list.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package configs | ||
|
||
var TablesToResourceTypes = map[string]string{} | ||
|
||
var ResourceTypesList = []string{} |
69 changes: 69 additions & 0 deletions
69
services/integration/integration-type/digitalocean-team/digitalocean-team.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package digitalocean_team | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
digitaloceanDescriberLocal "github.com/opengovern/opengovernance/services/integration/integration-type/digitalocean-team/configs" | ||
"github.com/opengovern/opengovernance/services/integration/integration-type/digitalocean-team/discovery" | ||
"github.com/opengovern/opengovernance/services/integration/integration-type/digitalocean-team/healthcheck" | ||
"github.com/opengovern/opengovernance/services/integration/integration-type/interfaces" | ||
"github.com/opengovern/opengovernance/services/integration/models" | ||
) | ||
|
||
type DigitaloceanTeamIntegration struct{} | ||
|
||
func (i *DigitaloceanTeamIntegration) GetConfiguration() interfaces.IntegrationConfiguration { | ||
return interfaces.IntegrationConfiguration{ | ||
NatsScheduledJobsTopic: digitaloceanDescriberLocal.JobQueueTopic, | ||
NatsManualJobsTopic: digitaloceanDescriberLocal.JobQueueTopicManuals, | ||
NatsStreamName: digitaloceanDescriberLocal.StreamName, | ||
|
||
UISpecFileName: "digitalocean-team.json", | ||
} | ||
} | ||
|
||
func (i *DigitaloceanTeamIntegration) HealthCheck(jsonData []byte, _ string, _ map[string]string, _ map[string]string) (bool, error) { | ||
var credentials digitaloceanDescriberLocal.IntegrationCredentials | ||
err := json.Unmarshal(jsonData, &credentials) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
return healthcheck.DigitalOceanTeamHealthcheck(context.TODO(), healthcheck.Config{ | ||
AuthToken: credentials.AuthToken, | ||
}) | ||
} | ||
|
||
func (i *DigitaloceanTeamIntegration) DiscoverIntegrations(jsonData []byte) ([]models.Integration, error) { | ||
var credentials digitaloceanDescriberLocal.IntegrationCredentials | ||
err := json.Unmarshal(jsonData, &credentials) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
team, err := discovery.DigitalOceanTeamDiscovery(context.TODO(), discovery.Config{ | ||
AuthToken: credentials.AuthToken, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return []models.Integration{ | ||
{ | ||
ProviderID: team.ID, | ||
Name: team.Name, | ||
}, | ||
}, nil | ||
} | ||
|
||
func (i *DigitaloceanTeamIntegration) GetResourceTypesByLabels(_ map[string]string) ([]string, error) { | ||
return digitaloceanDescriberLocal.ResourceTypesList, nil | ||
} | ||
|
||
func (i *DigitaloceanTeamIntegration) GetResourceTypeFromTableName(tableName string) string { | ||
if v, ok := digitaloceanDescriberLocal.TablesToResourceTypes[tableName]; ok { | ||
return v | ||
} | ||
|
||
return "" | ||
} |
36 changes: 36 additions & 0 deletions
36
services/integration/integration-type/digitalocean-team/discovery/discovery.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package discovery | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"github.com/digitalocean/godo" | ||
) | ||
|
||
type Config struct { | ||
AuthToken string | ||
} | ||
|
||
type Team struct { | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
} | ||
|
||
func DigitalOceanTeamDiscovery(ctx context.Context, config Config) (*Team, error) { | ||
client := godo.NewFromToken(config.AuthToken) | ||
|
||
account, resp, err := client.Account.Get(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if resp.StatusCode != 200 { | ||
return nil, err | ||
} | ||
if account.Team == nil { | ||
return nil, errors.New("team not found") | ||
} | ||
|
||
return &Team{ | ||
ID: account.Team.UUID, | ||
Name: account.Team.Name, | ||
}, nil | ||
} |
25 changes: 25 additions & 0 deletions
25
services/integration/integration-type/digitalocean-team/healthcheck/healthcheck.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package healthcheck | ||
|
||
import ( | ||
"context" | ||
"github.com/digitalocean/godo" | ||
) | ||
|
||
type Config struct { | ||
AuthToken string | ||
} | ||
|
||
func DigitalOceanTeamHealthcheck(ctx context.Context, config Config) (bool, error) { | ||
client := godo.NewFromToken(config.AuthToken) | ||
|
||
_, resp, err := client.Account.Get(ctx) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
if resp.StatusCode != 200 { | ||
return false, err | ||
} | ||
|
||
return true, nil | ||
} |