From 9cb22ba673e4e65d158e88a8c4520949369ce6d7 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 14 Jan 2025 15:08:11 +0330 Subject: [PATCH 1/2] feat: added tailscale and fly integrations --- .../fly-account/configs/credentials.go | 5 + .../fly-account/configs/deployment.go | 6 + .../fly-account/configs/general.go | 7 ++ .../fly-account/configs/nats.go | 9 ++ .../configs/resource_types_list.go | 15 +++ .../discovery/fly_integration_discovery.go | 59 ++++++++++ .../fly-account/fly_account.go | 104 ++++++++++++++++++ .../fly_integration_healthcheck.go | 65 +++++++++++ .../integration-type/integrations.go | 10 ++ .../tailscale-account/configs/credentials.go | 5 + .../tailscale-account/configs/deployment.go | 6 + .../tailscale-account/configs/general.go | 7 ++ .../tailscale-account/configs/nats.go | 9 ++ .../configs/resource_types_list.go | 29 +++++ .../tailscale_integration_discovery.go | 66 +++++++++++ .../tailscale_integration_healthcheck.go | 69 ++++++++++++ .../tailscale-account/tailscale_account.go | 96 ++++++++++++++++ 17 files changed, 567 insertions(+) create mode 100644 services/integration/integration-type/fly-account/configs/credentials.go create mode 100644 services/integration/integration-type/fly-account/configs/deployment.go create mode 100644 services/integration/integration-type/fly-account/configs/general.go create mode 100644 services/integration/integration-type/fly-account/configs/nats.go create mode 100644 services/integration/integration-type/fly-account/configs/resource_types_list.go create mode 100644 services/integration/integration-type/fly-account/discovery/fly_integration_discovery.go create mode 100644 services/integration/integration-type/fly-account/fly_account.go create mode 100644 services/integration/integration-type/fly-account/healthcheck/fly_integration_healthcheck.go create mode 100644 services/integration/integration-type/tailscale-account/configs/credentials.go create mode 100644 services/integration/integration-type/tailscale-account/configs/deployment.go create mode 100644 services/integration/integration-type/tailscale-account/configs/general.go create mode 100644 services/integration/integration-type/tailscale-account/configs/nats.go create mode 100644 services/integration/integration-type/tailscale-account/configs/resource_types_list.go create mode 100644 services/integration/integration-type/tailscale-account/discovery/tailscale_integration_discovery.go create mode 100644 services/integration/integration-type/tailscale-account/healthcheck/tailscale_integration_healthcheck.go create mode 100644 services/integration/integration-type/tailscale-account/tailscale_account.go diff --git a/services/integration/integration-type/fly-account/configs/credentials.go b/services/integration/integration-type/fly-account/configs/credentials.go new file mode 100644 index 000000000..826824a4b --- /dev/null +++ b/services/integration/integration-type/fly-account/configs/credentials.go @@ -0,0 +1,5 @@ +package configs + +type IntegrationCredentials struct { + Token string `json:"token"` +} diff --git a/services/integration/integration-type/fly-account/configs/deployment.go b/services/integration/integration-type/fly-account/configs/deployment.go new file mode 100644 index 000000000..b218af2fc --- /dev/null +++ b/services/integration/integration-type/fly-account/configs/deployment.go @@ -0,0 +1,6 @@ +package configs + +const ( + DescriberDeploymentName = "og-describer-fly" + DescriberRunCommand = "/og-describer-fly" +) diff --git a/services/integration/integration-type/fly-account/configs/general.go b/services/integration/integration-type/fly-account/configs/general.go new file mode 100644 index 000000000..ef741c4b2 --- /dev/null +++ b/services/integration/integration-type/fly-account/configs/general.go @@ -0,0 +1,7 @@ +package configs + +import "github.com/opengovern/og-util/pkg/integration" + +const ( + IntegrationTypeFlyAccount = integration.Type("fly_account") // example: AWS_ACCOUNT, AZURE_SUBSCRIPTION +) diff --git a/services/integration/integration-type/fly-account/configs/nats.go b/services/integration/integration-type/fly-account/configs/nats.go new file mode 100644 index 000000000..2e1956a49 --- /dev/null +++ b/services/integration/integration-type/fly-account/configs/nats.go @@ -0,0 +1,9 @@ +package configs + +const ( + StreamName = "og_describer_fly" + JobQueueTopic = "og_describer_fly_job_queue" + ConsumerGroup = "describer-fly" + JobQueueTopicManuals = "og_describer_fly_manuals_job_queue" + ConsumerGroupManuals = "describer-fly-manuals" +) diff --git a/services/integration/integration-type/fly-account/configs/resource_types_list.go b/services/integration/integration-type/fly-account/configs/resource_types_list.go new file mode 100644 index 000000000..e654f727e --- /dev/null +++ b/services/integration/integration-type/fly-account/configs/resource_types_list.go @@ -0,0 +1,15 @@ +package configs + +var TablesToResourceTypes = map[string]string{ + "fly_app": "Fly/App", + "fly_machine": "Fly/Machine", + "fly_volume": "Fly/Volume", + "fly_secret": "Fly/Secret", +} + +var ResourceTypesList = []string{ + "Fly/App", + "Fly/Machine", + "Fly/Volume", + "Fly/Secret", +} diff --git a/services/integration/integration-type/fly-account/discovery/fly_integration_discovery.go b/services/integration/integration-type/fly-account/discovery/fly_integration_discovery.go new file mode 100644 index 000000000..e688c4832 --- /dev/null +++ b/services/integration/integration-type/fly-account/discovery/fly_integration_discovery.go @@ -0,0 +1,59 @@ +package discovery + +import ( + "encoding/json" + "errors" + "fmt" + "net/http" +) + +// Config represents the JSON input configuration +type Config struct { + Token string `json:"token"` +} + +type App struct { + ID string `json:"id"` + Name string `json:"name"` + Status string `json:"status"` +} + +type Response struct { + Apps []App `json:"apps"` +} + +// Discover retrieves fly user info +func Discover(token string) ([]App, error) { + var response Response + + url := "https://api.machines.dev/v1/apps?org_slug=personal" + + client := http.DefaultClient + + req, err := http.NewRequest("GET", url, nil) + if err != nil { + return nil, err + } + req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token)) + + resp, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("request execution failed: %w", err) + } + defer resp.Body.Close() + + if err = json.NewDecoder(resp.Body).Decode(&response); err != nil { + return nil, fmt.Errorf("failed to decode response: %w", err) + } + + return response.Apps, nil +} + +func FlyIntegrationDiscovery(cfg Config) ([]App, error) { + // Check for the token + if cfg.Token == "" { + return nil, errors.New("token must be configured") + } + + return Discover(cfg.Token) +} diff --git a/services/integration/integration-type/fly-account/fly_account.go b/services/integration/integration-type/fly-account/fly_account.go new file mode 100644 index 000000000..8deed0dba --- /dev/null +++ b/services/integration/integration-type/fly-account/fly_account.go @@ -0,0 +1,104 @@ +package doppler_account + +import ( + "encoding/json" + "github.com/jackc/pgtype" + flyDescriberLocal "github.com/opengovern/opencomply/services/integration/integration-type/fly-account/configs" + "github.com/opengovern/opencomply/services/integration/integration-type/fly-account/discovery" + "github.com/opengovern/opencomply/services/integration/integration-type/fly-account/healthcheck" + "github.com/opengovern/opencomply/services/integration/integration-type/interfaces" + "github.com/opengovern/opencomply/services/integration/models" +) + +type FlyAccountIntegration struct{} + +func (i *FlyAccountIntegration) GetConfiguration() interfaces.IntegrationConfiguration { + return interfaces.IntegrationConfiguration{ + NatsScheduledJobsTopic: flyDescriberLocal.JobQueueTopic, + NatsManualJobsTopic: flyDescriberLocal.JobQueueTopicManuals, + NatsStreamName: flyDescriberLocal.StreamName, + NatsConsumerGroup: flyDescriberLocal.ConsumerGroup, + NatsConsumerGroupManuals: flyDescriberLocal.ConsumerGroupManuals, + + SteampipePluginName: "fly", + + UISpecFileName: "fly-account.json", + + DescriberDeploymentName: flyDescriberLocal.DescriberDeploymentName, + DescriberRunCommand: flyDescriberLocal.DescriberRunCommand, + } +} + +func (i *FlyAccountIntegration) HealthCheck(jsonData []byte, providerId string, labels map[string]string, annotations map[string]string) (bool, error) { + var credentials flyDescriberLocal.IntegrationCredentials + err := json.Unmarshal(jsonData, &credentials) + if err != nil { + return false, err + } + + var appName string + if v, ok := labels["AppName"]; ok { + appName = v + } + isHealthy, err := healthcheck.FlyIntegrationHealthcheck(healthcheck.Config{ + Token: credentials.Token, + AppName: appName, + }) + return isHealthy, err +} + +func (i *FlyAccountIntegration) DiscoverIntegrations(jsonData []byte) ([]models.Integration, error) { + var credentials flyDescriberLocal.IntegrationCredentials + err := json.Unmarshal(jsonData, &credentials) + if err != nil { + return nil, err + } + var integrations []models.Integration + apps, err := discovery.FlyIntegrationDiscovery(discovery.Config{ + Token: credentials.Token, + }) + for _, app := range apps { + labels := map[string]string{ + "AppName": app.Name, + "Status": app.Status, + } + 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: app.ID, + Name: app.Name, + Labels: integrationLabelsJsonb, + }) + } + return integrations, nil +} + +func (i *FlyAccountIntegration) GetResourceTypesByLabels(labels map[string]string) (map[string]*interfaces.ResourceTypeConfiguration, error) { + resourceTypesMap := make(map[string]*interfaces.ResourceTypeConfiguration) + for _, resourceType := range flyDescriberLocal.ResourceTypesList { + resourceTypesMap[resourceType] = nil + } + return resourceTypesMap, nil +} + +func (i *FlyAccountIntegration) GetResourceTypeFromTableName(tableName string) string { + if v, ok := flyDescriberLocal.TablesToResourceTypes[tableName]; ok { + return v + } + return "" +} + +func (i *FlyAccountIntegration) GetTablesByLabels(map[string]string) ([]string, error) { + var tables []string + for t, _ := range flyDescriberLocal.TablesToResourceTypes { + tables = append(tables, t) + } + return tables, nil +} diff --git a/services/integration/integration-type/fly-account/healthcheck/fly_integration_healthcheck.go b/services/integration/integration-type/fly-account/healthcheck/fly_integration_healthcheck.go new file mode 100644 index 000000000..86ad7e7f0 --- /dev/null +++ b/services/integration/integration-type/fly-account/healthcheck/fly_integration_healthcheck.go @@ -0,0 +1,65 @@ +package healthcheck + +import ( + "encoding/json" + "errors" + "fmt" + "net/http" +) + +// Config represents the JSON input configuration +type Config struct { + Token string `json:"token"` + AppName string `json:"app_name"` +} + +type App struct { + ID string `json:"id"` + Name string `json:"name"` + Status string `json:"status"` +} + +// IsHealthy checks if the JWT has read access to all required resources +func IsHealthy(token, appName string) error { + var app App + + url := fmt.Sprintf("https://api.machines.dev/v1/apps/%s", appName) + + client := http.DefaultClient + + req, err := http.NewRequest("GET", url, nil) + if err != nil { + return err + } + req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token)) + + resp, err := client.Do(req) + if err != nil { + return fmt.Errorf("request execution failed: %w", err) + } + defer resp.Body.Close() + + if err = json.NewDecoder(resp.Body).Decode(&app); err != nil { + return fmt.Errorf("failed to decode response: %w", err) + } + + return nil +} + +func FlyIntegrationHealthcheck(cfg Config) (bool, error) { + // Check for the token + if cfg.Token == "" { + return false, errors.New("token must be configured") + } + + if cfg.AppName == "" { + return false, errors.New("app name must be configured") + } + + err := IsHealthy(cfg.Token, cfg.AppName) + if err != nil { + return false, err + } + + return true, nil +} diff --git a/services/integration/integration-type/integrations.go b/services/integration/integration-type/integrations.go index 4873b0021..378e44a7d 100644 --- a/services/integration/integration-type/integrations.go +++ b/services/integration/integration-type/integrations.go @@ -18,6 +18,8 @@ import ( dopplerConfigs "github.com/opengovern/opencomply/services/integration/integration-type/doppler-account/configs" "github.com/opengovern/opencomply/services/integration/integration-type/entra-id-directory" entraidConfigs "github.com/opengovern/opencomply/services/integration/integration-type/entra-id-directory/configs" + fly "github.com/opengovern/opencomply/services/integration/integration-type/fly-account" + flyConfigs "github.com/opengovern/opencomply/services/integration/integration-type/fly-account/configs" githubaccount "github.com/opengovern/opencomply/services/integration/integration-type/github-account" githubConfigs "github.com/opengovern/opencomply/services/integration/integration-type/github-account/configs" google_workspace_account "github.com/opengovern/opencomply/services/integration/integration-type/google-workspace-account" @@ -31,6 +33,8 @@ import ( openaiConfigs "github.com/opengovern/opencomply/services/integration/integration-type/openai-integration/configs" render "github.com/opengovern/opencomply/services/integration/integration-type/render-account" renderConfigs "github.com/opengovern/opencomply/services/integration/integration-type/render-account/configs" + tailscale "github.com/opengovern/opencomply/services/integration/integration-type/tailscale-account" + tailscaleConfigs "github.com/opengovern/opencomply/services/integration/integration-type/tailscale-account/configs" ) const ( @@ -47,6 +51,8 @@ const ( IntegrationTypeOCIRepository = ociConfigs.IntegrationTypeOciRepository IntegrationTypeRenderAccount = renderConfigs.IntegrationTypeRenderAccount IntegrationTypeDopplerAccount = dopplerConfigs.IntegrationTypeDopplerAccount + IntegrationTypeTailScaleAccount = tailscaleConfigs.IntegrationTypeTailScaleAccount + IntegrationTypeFlyAccount = flyConfigs.IntegrationTypeFlyAccount ) var AllIntegrationTypes = []integration.Type{ @@ -63,6 +69,8 @@ var AllIntegrationTypes = []integration.Type{ IntegrationTypeOCIRepository, IntegrationTypeRenderAccount, IntegrationTypeDopplerAccount, + IntegrationTypeTailScaleAccount, + IntegrationTypeFlyAccount, } var IntegrationTypes = map[integration.Type]interfaces.IntegrationType{ @@ -79,6 +87,8 @@ var IntegrationTypes = map[integration.Type]interfaces.IntegrationType{ IntegrationTypeOCIRepository: &oci.Integration{}, IntegrationTypeRenderAccount: &render.RenderAccountIntegration{}, IntegrationTypeDopplerAccount: &doppler.DopplerAccountIntegration{}, + IntegrationTypeTailScaleAccount: &tailscale.TailScaleAccountIntegration{}, + IntegrationTypeFlyAccount: &fly.FlyAccountIntegration{}, } func ParseType(str string) integration.Type { diff --git a/services/integration/integration-type/tailscale-account/configs/credentials.go b/services/integration/integration-type/tailscale-account/configs/credentials.go new file mode 100644 index 000000000..826824a4b --- /dev/null +++ b/services/integration/integration-type/tailscale-account/configs/credentials.go @@ -0,0 +1,5 @@ +package configs + +type IntegrationCredentials struct { + Token string `json:"token"` +} diff --git a/services/integration/integration-type/tailscale-account/configs/deployment.go b/services/integration/integration-type/tailscale-account/configs/deployment.go new file mode 100644 index 000000000..40d726aa6 --- /dev/null +++ b/services/integration/integration-type/tailscale-account/configs/deployment.go @@ -0,0 +1,6 @@ +package configs + +const ( + DescriberDeploymentName = "og-describer-tailscale" + DescriberRunCommand = "/og-describer-tailscale" +) diff --git a/services/integration/integration-type/tailscale-account/configs/general.go b/services/integration/integration-type/tailscale-account/configs/general.go new file mode 100644 index 000000000..fcd7db679 --- /dev/null +++ b/services/integration/integration-type/tailscale-account/configs/general.go @@ -0,0 +1,7 @@ +package configs + +import "github.com/opengovern/og-util/pkg/integration" + +const ( + IntegrationTypeTailScaleAccount = integration.Type("tailscale_account") // example: AWS_ACCOUNT, AZURE_SUBSCRIPTION +) diff --git a/services/integration/integration-type/tailscale-account/configs/nats.go b/services/integration/integration-type/tailscale-account/configs/nats.go new file mode 100644 index 000000000..3c9012993 --- /dev/null +++ b/services/integration/integration-type/tailscale-account/configs/nats.go @@ -0,0 +1,9 @@ +package configs + +const ( + StreamName = "og_describer_tailscale" + JobQueueTopic = "og_describer_tailscale_job_queue" + ConsumerGroup = "describer-tailscale" + JobQueueTopicManuals = "og_describer_tailscale_manuals_job_queue" + ConsumerGroupManuals = "describer-tailscale-manuals" +) diff --git a/services/integration/integration-type/tailscale-account/configs/resource_types_list.go b/services/integration/integration-type/tailscale-account/configs/resource_types_list.go new file mode 100644 index 000000000..edfb95fc0 --- /dev/null +++ b/services/integration/integration-type/tailscale-account/configs/resource_types_list.go @@ -0,0 +1,29 @@ +package configs + +var TablesToResourceTypes = map[string]string{ + "tailscale_device": "TailScale/Device", + "tailscale_user": "TailScale/User", + "tailscale_contact": "TailScale/Contact", + "tailscale_device_invite": "TailScale/Device/Invite", + "tailscale_device_posture": "TailScale/Device/Posture", + "tailscale_user_invite": "TailScale/User/Invite", + "tailscale_key": "TailScale/Key", + "tailscale_policy": "TailScale/Policy", + "tailscale_tailnet_setting": "TailScale/TailnetSetting", + "tailscale_webhook": "TailScale/Webhook", + "tailscale_dns": "TailScale/DNS", +} + +var ResourceTypesList = []string{ + "TailScale/Device", + "TailScale/User", + "TailScale/Contact", + "TailScale/Device/Invite", + "TailScale/Device/Posture", + "TailScale/User/Invite", + "TailScale/Key", + "TailScale/Policy", + "TailScale/TailnetSetting", + "TailScale/Webhook", + "TailScale/DNS", +} diff --git a/services/integration/integration-type/tailscale-account/discovery/tailscale_integration_discovery.go b/services/integration/integration-type/tailscale-account/discovery/tailscale_integration_discovery.go new file mode 100644 index 000000000..f415b4864 --- /dev/null +++ b/services/integration/integration-type/tailscale-account/discovery/tailscale_integration_discovery.go @@ -0,0 +1,66 @@ +package discovery + +import ( + "encoding/json" + "errors" + "fmt" + "net/http" +) + +// Config represents the JSON input configuration +type Config struct { + Token string `json:"token"` +} + +type User struct { + ID string `json:"id"` + LoginName string `json:"loginName"` + Role string `json:"role"` + Status string `json:"status"` +} + +type Response struct { + Users []User `json:"users"` +} + +// Discover retrieves tailscale user info +func Discover(token string) (*User, error) { + var response Response + + url := "https://api.tailscale.com/api/v2/tailnet/-/users" + + client := http.DefaultClient + + req, err := http.NewRequest("GET", url, nil) + if err != nil { + return nil, err + } + req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token)) + + resp, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("request execution failed: %w", err) + } + defer resp.Body.Close() + + if err = json.NewDecoder(resp.Body).Decode(&response); err != nil { + return nil, fmt.Errorf("failed to decode response: %w", err) + } + + for _, user := range response.Users { + if user.Role == "owner" { + return &user, nil + } + } + + return nil, nil +} + +func TailScaleIntegrationDiscovery(cfg Config) (*User, error) { + // Check for the token + if cfg.Token == "" { + return nil, errors.New("token must be configured") + } + + return Discover(cfg.Token) +} diff --git a/services/integration/integration-type/tailscale-account/healthcheck/tailscale_integration_healthcheck.go b/services/integration/integration-type/tailscale-account/healthcheck/tailscale_integration_healthcheck.go new file mode 100644 index 000000000..97c635ad1 --- /dev/null +++ b/services/integration/integration-type/tailscale-account/healthcheck/tailscale_integration_healthcheck.go @@ -0,0 +1,69 @@ +package healthcheck + +import ( + "encoding/json" + "errors" + "fmt" + "net/http" +) + +// Config represents the JSON input configuration +type Config struct { + Token string `json:"token"` +} + +type User struct { + ID string `json:"id"` + LoginName string `json:"loginName"` + Role string `json:"role"` + Status string `json:"status"` +} + +type Response struct { + Users []User `json:"users"` +} + +// IsHealthy checks if the JWT has read access to all required resources +func IsHealthy(token string) error { + var response Response + + url := "https://api.tailscale.com/api/v2/tailnet/-/users" + + client := http.DefaultClient + + req, err := http.NewRequest("GET", url, nil) + if err != nil { + return err + } + req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token)) + + resp, err := client.Do(req) + if err != nil { + return fmt.Errorf("request execution failed: %w", err) + } + defer resp.Body.Close() + + if err = json.NewDecoder(resp.Body).Decode(&response); err != nil { + return fmt.Errorf("failed to decode response: %w", err) + } + + if len(response.Users) == 0 { + return errors.New("no user defined on this token") + } + + return nil +} + +func TailScaleIntegrationHealthcheck(cfg Config) (bool, error) { + // Check for the token + if cfg.Token == "" { + return false, errors.New("token must be configured") + } + + err := IsHealthy(cfg.Token) + if err != nil { + return false, err + } + + return true, nil +} diff --git a/services/integration/integration-type/tailscale-account/tailscale_account.go b/services/integration/integration-type/tailscale-account/tailscale_account.go new file mode 100644 index 000000000..296a00c48 --- /dev/null +++ b/services/integration/integration-type/tailscale-account/tailscale_account.go @@ -0,0 +1,96 @@ +package doppler_account + +import ( + "encoding/json" + "github.com/jackc/pgtype" + "github.com/opengovern/opencomply/services/integration/integration-type/interfaces" + tailScaleDescriberLocal "github.com/opengovern/opencomply/services/integration/integration-type/tailscale-account/configs" + "github.com/opengovern/opencomply/services/integration/integration-type/tailscale-account/discovery" + "github.com/opengovern/opencomply/services/integration/integration-type/tailscale-account/healthcheck" + "github.com/opengovern/opencomply/services/integration/models" +) + +type TailScaleAccountIntegration struct{} + +func (i *TailScaleAccountIntegration) GetConfiguration() interfaces.IntegrationConfiguration { + return interfaces.IntegrationConfiguration{ + NatsScheduledJobsTopic: tailScaleDescriberLocal.JobQueueTopic, + NatsManualJobsTopic: tailScaleDescriberLocal.JobQueueTopicManuals, + NatsStreamName: tailScaleDescriberLocal.StreamName, + NatsConsumerGroup: tailScaleDescriberLocal.ConsumerGroup, + NatsConsumerGroupManuals: tailScaleDescriberLocal.ConsumerGroupManuals, + + SteampipePluginName: "tailscale", + + UISpecFileName: "tailscale-account.json", + + DescriberDeploymentName: tailScaleDescriberLocal.DescriberDeploymentName, + DescriberRunCommand: tailScaleDescriberLocal.DescriberRunCommand, + } +} + +func (i *TailScaleAccountIntegration) HealthCheck(jsonData []byte, providerId string, labels map[string]string, annotations map[string]string) (bool, error) { + var credentials tailScaleDescriberLocal.IntegrationCredentials + err := json.Unmarshal(jsonData, &credentials) + if err != nil { + return false, err + } + + isHealthy, err := healthcheck.TailScaleIntegrationHealthcheck(healthcheck.Config{ + Token: credentials.Token, + }) + return isHealthy, err +} + +func (i *TailScaleAccountIntegration) DiscoverIntegrations(jsonData []byte) ([]models.Integration, error) { + var credentials tailScaleDescriberLocal.IntegrationCredentials + err := json.Unmarshal(jsonData, &credentials) + if err != nil { + return nil, err + } + var integrations []models.Integration + user, err := discovery.TailScaleIntegrationDiscovery(discovery.Config{ + Token: credentials.Token, + }) + labels := map[string]string{ + "Status": user.Status, + } + 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: user.ID, + Name: user.LoginName, + Labels: integrationLabelsJsonb, + }) + return integrations, nil +} + +func (i *TailScaleAccountIntegration) GetResourceTypesByLabels(labels map[string]string) (map[string]*interfaces.ResourceTypeConfiguration, error) { + resourceTypesMap := make(map[string]*interfaces.ResourceTypeConfiguration) + for _, resourceType := range tailScaleDescriberLocal.ResourceTypesList { + resourceTypesMap[resourceType] = nil + } + return resourceTypesMap, nil +} + +func (i *TailScaleAccountIntegration) GetResourceTypeFromTableName(tableName string) string { + if v, ok := tailScaleDescriberLocal.TablesToResourceTypes[tableName]; ok { + return v + } + return "" +} + +func (i *TailScaleAccountIntegration) GetTablesByLabels(map[string]string) ([]string, error) { + var tables []string + for t, _ := range tailScaleDescriberLocal.TablesToResourceTypes { + tables = append(tables, t) + } + return tables, nil +} From 7426136a2f02f16e355c36aaef54da3d25641117 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 15 Jan 2025 12:20:11 +0330 Subject: [PATCH 2/2] fix: fixed package name --- .../integration/integration-type/fly-account/fly_account.go | 2 +- .../integration-type/tailscale-account/tailscale_account.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/integration/integration-type/fly-account/fly_account.go b/services/integration/integration-type/fly-account/fly_account.go index 8deed0dba..30d2e09d1 100644 --- a/services/integration/integration-type/fly-account/fly_account.go +++ b/services/integration/integration-type/fly-account/fly_account.go @@ -1,4 +1,4 @@ -package doppler_account +package fly_account import ( "encoding/json" diff --git a/services/integration/integration-type/tailscale-account/tailscale_account.go b/services/integration/integration-type/tailscale-account/tailscale_account.go index 296a00c48..53b2e5305 100644 --- a/services/integration/integration-type/tailscale-account/tailscale_account.go +++ b/services/integration/integration-type/tailscale-account/tailscale_account.go @@ -1,4 +1,4 @@ -package doppler_account +package tailscale_account import ( "encoding/json"