-
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.
feat: add github account integration
- Loading branch information
Showing
10 changed files
with
449 additions
and
1 deletion.
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
9 changes: 9 additions & 0 deletions
9
services/integration/integration-type/github-account/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,9 @@ | ||
package configs | ||
|
||
type IntegrationCredentials struct { | ||
Token string `json:"token"` | ||
BaseURL string `json:"base_url"` | ||
AppId string `json:"app_id"` | ||
InstallationId string `json:"installation_id"` | ||
PrivateKeyPath string `json:"private_key_path"` | ||
} |
7 changes: 7 additions & 0 deletions
7
services/integration/integration-type/github-account/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 ( | ||
IntegrationTypeGithubAccount = integration.Type("github_account") // example: aws_cloud, azure_subscription | ||
) |
9 changes: 9 additions & 0 deletions
9
services/integration/integration-type/github-account/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_github" | ||
JobQueueTopic = "og_describer_github_job_queue" | ||
ConsumerGroup = "describer-github" | ||
JobQueueTopicManuals = "og_describer_github_manuals_job_queue" | ||
ConsumerGroupManuals = "describer-github-manuals" | ||
) |
93 changes: 93 additions & 0 deletions
93
services/integration/integration-type/github-account/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,93 @@ | ||
package configs | ||
|
||
var TablesToResourceTypes = map[string]string{ | ||
"github_actions_artifact": "Github/Actions/Artifact", | ||
"github_actions_repository_runner": "Github/Actions/Repository/Runner", | ||
"github_actions_repository_secret": "Github/Actions/Repository/Secret", | ||
"github_actions_repository_workflow_run": "Github/Actions/Repository/Workflow_run", | ||
"github_audit_log": "Github/AuditLog", | ||
"github_blob": "Github/Blob", | ||
"github_branch": "Github/Branch", | ||
"github_branch_protection": "Github/Branch/Protection", | ||
"github_commit": "Github/Commit", | ||
"github_community_profile": "Github/CommunityProfile", | ||
"github_my_gist": "Github/Gist", | ||
"github_gitignore": "Github/Gitignore", | ||
"github_my_issue": "Github/Issue", | ||
"github_issue_comment": "Github/Issue/Comment", | ||
"github_license": "Github/License", | ||
"github_my_organization": "Github/Organization", | ||
"github_organization_collaborators": "Github/Organization/Collaborator", | ||
"github_organization_dependabot_alert": "Github/Organization/DependabotAlert", | ||
"github_organization_external_identity": "Github/Organization/ExternalIdentity", | ||
"github_organization_member": "Github/Organization/Member", | ||
"github_pull_request": "Github/PullRequest", | ||
"github_my_repository": "Github/Repository", | ||
"github_repository_collaborator": "Github/Repository/Collaborator", | ||
"github_repository_dependabot_alert": "Github/Repository/DependabotAlert", | ||
"github_repository_deployment": "Github/Repository/Deployment", | ||
"github_repository_environment": "Github/Repository/Environment", | ||
"github_repository_ruleset": "Github/Repository/Ruleset", | ||
"github_repository_sbom": "Github/Repository/SBOM", | ||
"github_repository_vulnerability_alert": "Github/Repository/VulnerabilityAlert", | ||
"github_search_code": "Github/Search/Code", | ||
"github_search_commit": "Github/Search/Commit", | ||
"github_search_issue": "Github/Search/Issue", | ||
"github_my_star": "Github/Star", | ||
"github_stargazer": "Github/Stargazer", | ||
"github_tag": "Github/Tag", | ||
"github_my_team": "Github/Team", | ||
"github_team_member": "Github/Team/Member", | ||
"github_team_repository": "Github/Team/Repository", | ||
"github_traffic_view_daily": "Github/Traffic/View/Daily", | ||
"github_traffic_view_weekly": "Github/Traffic/View/Weekly", | ||
"github_tree": "Github/Tree", | ||
"github_user": "GithubUser", | ||
"github_workflow": "GithubWorkflow", | ||
} | ||
|
||
var ResourceTypesList = []string{ | ||
"Github/Actions/Artifact", | ||
"Github/Actions/Repository/Runner", | ||
"Github/Actions/Repository/Secret", | ||
"Github/Actions/Repository/Workflow_run", | ||
"Github/AuditLog", | ||
"Github/Blob", | ||
"Github/Branch", | ||
"Github/Branch/Protection", | ||
"Github/Commit", | ||
"Github/CommunityProfile", | ||
"Github/Gist", | ||
"Github/Gitignore", | ||
"Github/Issue", | ||
"Github/Issue/Comment", | ||
"Github/License", | ||
"Github/Organization", | ||
"Github/Organization/Collaborator", | ||
"Github/Organization/DependabotAlert", | ||
"Github/Organization/ExternalIdentity", | ||
"Github/Organization/Member", | ||
"Github/PullRequest", | ||
"Github/Repository", | ||
"Github/Repository/Collaborator", | ||
"Github/Repository/DependabotAlert", | ||
"Github/Repository/Deployment", | ||
"Github/Repository/Environment", | ||
"Github/Repository/Ruleset", | ||
"Github/Repository/SBOM", | ||
"Github/Repository/VulnerabilityAlert", | ||
"Github/Search/Code", | ||
"Github/Search/Commit", | ||
"Github/Search/Issue", | ||
"Github/Star", | ||
"Github/Stargazer", | ||
"Github/Tag", | ||
"Github/Team", | ||
"Github/Team/Member", | ||
"Github/Team/Repository", | ||
"Github/Traffic/View/Daily", | ||
"Github/Traffic/View/Weekly", | ||
"Github/Tree", | ||
"GithubUser", | ||
"GithubWorkflow", | ||
} |
46 changes: 46 additions & 0 deletions
46
...ces/integration/integration-type/github-account/discovery/github_integration_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,46 @@ | ||
package discovery | ||
|
||
import ( | ||
"context" | ||
"github.com/opengovern/opengovernance/services/integration/integration-type/github-account/healthcheck" | ||
"strconv" | ||
) | ||
|
||
// Config represents the JSON input configuration | ||
type Config struct { | ||
Token string `json:"token"` | ||
BaseURL string `json:"base_url"` | ||
AppId string `json:"app_id"` | ||
InstallationId string `json:"installation_id"` | ||
PrivateKeyPath string `json:"private_key_path"` | ||
} | ||
|
||
type Account struct { | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
Type string `json:"type"` | ||
IsHealthy bool `json:"isHealthy"` | ||
} | ||
|
||
func GithubIntegrationDiscovery(config Config) ([]Account, error) { | ||
isHealthy, client, err := healthcheck.GithubIntegrationHealthcheck(healthcheck.Config{ | ||
Token: config.Token, | ||
BaseURL: config.BaseURL, | ||
AppId: config.AppId, | ||
InstallationId: config.InstallationId, | ||
PrivateKeyPath: config.PrivateKeyPath, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
account, _, err := client.Users.Get(context.Background(), "") | ||
if err != nil { | ||
return nil, err | ||
} | ||
return []Account{{ | ||
ID: strconv.Itoa(int(*account.ID)), | ||
Name: *account.Login, | ||
Type: *account.Type, | ||
IsHealthy: isHealthy, | ||
}}, nil | ||
} |
88 changes: 88 additions & 0 deletions
88
services/integration/integration-type/github-account/github_account.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,88 @@ | ||
package github_account | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/jackc/pgtype" | ||
githubDescriberLocal "github.com/opengovern/opengovernance/services/integration/integration-type/github-account/configs" | ||
"github.com/opengovern/opengovernance/services/integration/integration-type/github-account/discovery" | ||
"github.com/opengovern/opengovernance/services/integration/integration-type/github-account/healthcheck" | ||
"github.com/opengovern/opengovernance/services/integration/integration-type/interfaces" | ||
"github.com/opengovern/opengovernance/services/integration/models" | ||
) | ||
|
||
type GithubAccountIntegration struct{} | ||
|
||
func (i *GithubAccountIntegration) GetConfiguration() interfaces.IntegrationConfiguration { | ||
return interfaces.IntegrationConfiguration{ | ||
NatsScheduledJobsTopic: githubDescriberLocal.JobQueueTopic, | ||
NatsManualJobsTopic: githubDescriberLocal.JobQueueTopicManuals, | ||
NatsStreamName: githubDescriberLocal.StreamName, | ||
|
||
UISpecFileName: "github-account.json", | ||
} | ||
} | ||
|
||
func (i *GithubAccountIntegration) HealthCheck(jsonData []byte, providerId string, labels map[string]string, annotations map[string]string) (bool, error) { | ||
var credentials githubDescriberLocal.IntegrationCredentials | ||
err := json.Unmarshal(jsonData, &credentials) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
isHealthy, _, err := healthcheck.GithubIntegrationHealthcheck(healthcheck.Config{ | ||
Token: credentials.Token, | ||
BaseURL: credentials.BaseURL, | ||
AppId: credentials.AppId, | ||
InstallationId: credentials.InstallationId, | ||
PrivateKeyPath: credentials.PrivateKeyPath, | ||
}) | ||
return isHealthy, err | ||
} | ||
|
||
func (i *GithubAccountIntegration) DiscoverIntegrations(jsonData []byte) ([]models.Integration, error) { | ||
var credentials githubDescriberLocal.IntegrationCredentials | ||
err := json.Unmarshal(jsonData, &credentials) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var integrations []models.Integration | ||
accounts, err := discovery.GithubIntegrationDiscovery(discovery.Config{ | ||
Token: credentials.Token, | ||
BaseURL: credentials.BaseURL, | ||
AppId: credentials.AppId, | ||
InstallationId: credentials.InstallationId, | ||
PrivateKeyPath: credentials.PrivateKeyPath, | ||
}) | ||
for _, a := range accounts { | ||
labels := map[string]string{ | ||
"AccountType": a.Type, | ||
} | ||
labelsJsonData, err := json.Marshal(labels) | ||
if err != nil { | ||
return nil, err | ||
} | ||
integrationLabelsJsonb := pgtype.JSONB{} | ||
err = integrationLabelsJsonb.Set(labelsJsonData) | ||
if err != nil { | ||
return nil, err | ||
} | ||
integrations = append(integrations, models.Integration{ | ||
ProviderID: a.ID, | ||
Name: a.Name, | ||
Labels: integrationLabelsJsonb, | ||
}) | ||
} | ||
return integrations, nil | ||
} | ||
|
||
func (i *GithubAccountIntegration) GetResourceTypesByLabels(map[string]string) ([]string, error) { | ||
return githubDescriberLocal.ResourceTypesList, nil | ||
} | ||
|
||
func (i *GithubAccountIntegration) GetResourceTypeFromTableName(tableName string) string { | ||
if v, ok := githubDescriberLocal.TablesToResourceTypes[tableName]; ok { | ||
return v | ||
} | ||
|
||
return "" | ||
} |
Oops, something went wrong.