Skip to content

Commit

Permalink
fix: fix tags
Browse files Browse the repository at this point in the history
  • Loading branch information
artaasadi committed Nov 10, 2024
1 parent 7242b27 commit 41fc413
Show file tree
Hide file tree
Showing 133 changed files with 4,812 additions and 3,394 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ require (
github.com/hashicorp/go-hclog v1.6.3
github.com/nats-io/nats.go v1.36.0
github.com/opengovern/og-aws-describer v0.60.0
github.com/opengovern/og-util v1.0.6-0.20241108102418-e20a35efc8ca
github.com/opengovern/og-util v1.1.0
github.com/opengovern/opengovernance v0.434.62-feat-integrations-service.0
github.com/spf13/cobra v1.8.1
github.com/turbot/steampipe-plugin-sdk/v5 v5.10.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,8 @@ github.com/opengovern/og-aws-describer v0.60.0 h1:Cl0a4KW8eV9gmtFyDbNRtfxR+jyRNk
github.com/opengovern/og-aws-describer v0.60.0/go.mod h1:gHBFpQcnj1KAX/s6/PzitZxQ/5ockN7cjzaOdPoBYCs=
github.com/opengovern/og-util v1.0.6-0.20241108102418-e20a35efc8ca h1:yeF0lhv15WWULbOb811lVAv/KTY5nfsA0dkzd4GODlk=
github.com/opengovern/og-util v1.0.6-0.20241108102418-e20a35efc8ca/go.mod h1:7l7fNhK6uewIwA0cs7QagJuhjt/E6hEAC01SR8Y0kKk=
github.com/opengovern/og-util v1.1.0 h1:bV2XKX8aIpJGC2CR4kh9CU/rJWPQed76gtVXM2zBDXM=
github.com/opengovern/og-util v1.1.0/go.mod h1:dyn8rhmxq59o1jnbgGfmcUvW7iB/eN6OxoTUUx6jEHA=
github.com/opengovern/opengovernance v0.434.62-feat-integrations-service.0 h1:DYxFV9K4IGm9xe5TpXMi8HAVEdlb4sYDKbBkRTgZRms=
github.com/opengovern/opengovernance v0.434.62-feat-integrations-service.0/go.mod h1:ozdf1nCN4iXbHT+CzmgboQLd6aPE1coa09Ze599g9SE=
github.com/opensearch-project/opensearch-go/v2 v2.3.0 h1:nQIEMr+A92CkhHrZgUhcfsrZjibvB3APXf2a1VwCmMQ=
Expand Down
22 changes: 11 additions & 11 deletions pkg/describer/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,17 @@ func doDescribe(
}

rs.Send(&es.Resource{
PlatformID: uuid.New().String(),
ResourceID: resource.UniqueID(),
ResourceName: resource.Name,
Description: description,
IntegrationType: configs.IntegrationName,
ResourceType: strings.ToLower(job.ResourceType),
IntegrationID: job.IntegrationID,
IntegrationMetadata: metadata,
CanonicalTags: newTags,
DescribedAt: job.DescribedAt,
DescribedBy: strconv.FormatUint(uint64(job.JobID), 10),
PlatformID: uuid.New().String(),
ResourceID: resource.UniqueID(),
ResourceName: resource.Name,
Description: description,
IntegrationType: configs.IntegrationName,
ResourceType: strings.ToLower(job.ResourceType),
IntegrationID: job.IntegrationID,
Metadata: metadata,
CanonicalTags: newTags,
DescribedAt: job.DescribedAt,
DescribedBy: strconv.FormatUint(uint64(job.JobID), 10),
})
return nil
}
Expand Down
2,363 changes: 1,828 additions & 535 deletions pkg/sdk/es/resources_clients.go

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions pkg/sdk/models/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ package models
type StreamSender func(Resource) error

type Resource struct {
// ARN uniquely identifies an AWS resource across regions, accounts and types.
ARN string
// ID doesn't uniquely identifies a resource. It will be used to create a
// unique identifier by concating PARTITION|REGION|ACCOUNT|TYPE|ID
ID string
Description interface{}

Name string
Type string
IntegrationMetadata interface{}
Name string
Account string
Region string
Partition string
Type string
}

func (r Resource) UniqueID() string {
Expand Down
3 changes: 3 additions & 0 deletions pkg/sdk/runable/steampipe_es_client_generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type {{ .Name }} struct {
ResourceID string ` + "`json:\"resource_id\"`" + `
PlatformID string ` + "`json:\"platform_id\"`" + `
Description {{ .IntegrationType }}.{{ .Name }}Description ` + "`json:\"description\"`" + `
Metadata {{ .IntegrationType }}.Metadata ` + "`json:\"metadata\"`" + `
DescribedBy int ` + "`json:\"described_by\"`" + `
ResourceType string ` + "`json:\"resource_type\"`" + `
IntegrationType string ` + "`json:\"integration_type\"`" + `
Expand Down Expand Up @@ -383,6 +384,8 @@ func Get{{ .Name }}(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateD
s.ListFilters[fparts[0]] = fparts[1]
}
}
s.GetFilters["og_account_id"] = "metadata.IntegrationID"
s.ListFilters["og_account_id"] = "metadata.IntegrationID"
}

if s.Index != "" {
Expand Down
18 changes: 18 additions & 0 deletions provider/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
awsmodel "github.com/opengovern/og-aws-describer/aws/model"
model "github.com/opengovern/og-describer-aws/pkg/sdk/models"
"github.com/opengovern/og-describer-aws/provider/configs"
"github.com/opengovern/og-util/pkg/describe"
"golang.org/x/net/context"
"strings"
)

// GenerateAWSConfig creates an AWS configuration using the provided credentials provider.
Expand Down Expand Up @@ -56,7 +58,23 @@ func AccountCredentialsFromMap(m map[string]any) (configs.IntegrationCredentials
// GetResourceMetadata TODO: Get metadata as a map to add to the resources
func GetResourceMetadata(job describe.DescribeJob, resource model.Resource) (map[string]string, error) {
metadata := make(map[string]string)
awsMetadata := awsmodel.Metadata{
Name: resource.Name,
AccountID: job.IntegrationID,
SourceID: job.ProviderID,
Region: resource.Region,
ResourceType: strings.ToLower(job.ResourceType),
}

awsMetadataBytes, err := json.Marshal(awsMetadata)
if err != nil {
return nil, fmt.Errorf("marshal metadata: %v", err.Error())
}

err = json.Unmarshal(awsMetadataBytes, &metadata)
if err != nil {
return nil, fmt.Errorf("unmarshal metadata: %v", err.Error())
}
return metadata, nil
}

Expand Down
16 changes: 8 additions & 8 deletions provider/describer/accessanalyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/opengovern/og-describer-aws/provider/model"
)

func GetAccessAnalyzerAnalyzer(ctx context.Context, cfg aws.Config, fields map[string]string) ([]Resource, error) {
func GetAccessAnalyzerAnalyzer(ctx context.Context, cfg aws.Config, fields map[string]string) ([]models.Resource, error) {
describeCtx := GetDescribeContext(ctx)
analyzerName := fields["name"]
client := accessanalyzer.NewFromConfig(cfg)
Expand All @@ -25,7 +25,7 @@ func GetAccessAnalyzerAnalyzer(ctx context.Context, cfg aws.Config, fields map[s
return nil, err
}

return []Resource{
return []models.Resource{
{
Region: describeCtx.OGRegion,
ARN: *v.Analyzer.Arn,
Expand All @@ -37,12 +37,12 @@ func GetAccessAnalyzerAnalyzer(ctx context.Context, cfg aws.Config, fields map[s
}}, nil
}

func AccessAnalyzerAnalyzer(ctx context.Context, cfg aws.Config, stream *StreamSender) ([]Resource, error) {
func AccessAnalyzerAnalyzer(ctx context.Context, cfg aws.Config, stream *models.StreamSender) ([]models.Resource, error) {
describeCtx := GetDescribeContext(ctx)
client := accessanalyzer.NewFromConfig(cfg)
paginator := accessanalyzer.NewListAnalyzersPaginator(client, &accessanalyzer.ListAnalyzersInput{})

var values []Resource
var values []models.Resource
for paginator.HasMorePages() {
page, err := paginator.NextPage(ctx)
if err != nil {
Expand All @@ -54,7 +54,7 @@ func AccessAnalyzerAnalyzer(ctx context.Context, cfg aws.Config, stream *StreamS
if err != nil {
return nil, err
}
resource := Resource{
resource := models.Resource{
Region: describeCtx.OGRegion,
ARN: *v.Arn,
Name: *v.Name,
Expand Down Expand Up @@ -96,12 +96,12 @@ func getAnalyzerFindings(ctx context.Context, client *accessanalyzer.Client, ana
return findings, nil
}

func AccessAnalyzerAnalyzerFinding(ctx context.Context, cfg aws.Config, stream *StreamSender) ([]Resource, error) {
func AccessAnalyzerAnalyzerFinding(ctx context.Context, cfg aws.Config, stream *models.StreamSender) ([]models.Resource, error) {
describeCtx := GetDescribeContext(ctx)
client := accessanalyzer.NewFromConfig(cfg)
paginator := accessanalyzer.NewListAnalyzersPaginator(client, &accessanalyzer.ListAnalyzersInput{})

var values []Resource
var values []models.Resource
for paginator.HasMorePages() {
page, err := paginator.NextPage(ctx)
if err != nil {
Expand All @@ -114,7 +114,7 @@ func AccessAnalyzerAnalyzerFinding(ctx context.Context, cfg aws.Config, stream *
return nil, err
}
for _, finding := range findings {
resource := Resource{
resource := models.Resource{
Region: describeCtx.OGRegion,
ID: *finding.Id,
Description: model.AccessAnalyzerAnalyzerFindingDescription{
Expand Down
25 changes: 13 additions & 12 deletions provider/describer/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package describer

import (
"context"
"github.com/opengovern/og-describer-aws/pkg/sdk/models"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/account"
"github.com/aws/aws-sdk-go-v2/service/account/types"
"github.com/opengovern/og-describer-aws/provider/model"
)

func AccountAlternateContact(ctx context.Context, cfg aws.Config, stream *StreamSender) ([]Resource, error) {
func AccountAlternateContact(ctx context.Context, cfg aws.Config, stream *models.StreamSender) ([]models.Resource, error) {
describeCtx := GetDescribeContext(ctx)

var values []Resource
var values []models.Resource

contactTypes := []types.AlternateContactType{types.AlternateContactTypeBilling, types.AlternateContactTypeOperations, types.AlternateContactTypeSecurity}
input := &account.GetAlternateContactInput{
Expand All @@ -24,7 +25,7 @@ func AccountAlternateContact(ctx context.Context, cfg aws.Config, stream *Stream
if err != nil {
return nil, err
}
emptyResource := Resource{}
emptyResource := models.Resource{}
if err == nil && resource == emptyResource {
continue
}
Expand All @@ -42,7 +43,7 @@ func AccountAlternateContact(ctx context.Context, cfg aws.Config, stream *Stream

return values, nil
}
func accountAlternateContactHandle(ctx context.Context, cfg aws.Config, accountId string, contactType types.AlternateContactType) (Resource, error) {
func accountAlternateContactHandle(ctx context.Context, cfg aws.Config, accountId string, contactType types.AlternateContactType) (models.Resource, error) {
describeCtx := GetDescribeContext(ctx)

client := account.NewFromConfig(cfg)
Expand All @@ -54,10 +55,10 @@ func accountAlternateContactHandle(ctx context.Context, cfg aws.Config, accountI
if isErr(err, "ResourceNotFoundException") {
op = &account.GetAlternateContactOutput{}
}
return Resource{}, err
return models.Resource{}, err
}

resource := Resource{
resource := models.Resource{
Region: describeCtx.OGRegion,
Name: *op.AlternateContact.Name,
Description: model.AccountAlternateContactDescription{
Expand All @@ -67,16 +68,16 @@ func accountAlternateContactHandle(ctx context.Context, cfg aws.Config, accountI
}
return resource, nil
}
func GetAccountAlternateContact(ctx context.Context, cfg aws.Config, fields map[string]string) ([]Resource, error) {
func GetAccountAlternateContact(ctx context.Context, cfg aws.Config, fields map[string]string) ([]models.Resource, error) {
accountId := fields["accountId"]
contactTypes := []types.AlternateContactType{types.AlternateContactTypeBilling, types.AlternateContactTypeOperations, types.AlternateContactTypeSecurity}
var values []Resource
var values []models.Resource
for _, contactType := range contactTypes {
resource, err := accountAlternateContactHandle(ctx, cfg, accountId, contactType)
if err != nil {
return nil, err
}
emptyResource := Resource{}
emptyResource := models.Resource{}
if err == nil && resource == emptyResource {
return nil, nil
}
Expand All @@ -85,20 +86,20 @@ func GetAccountAlternateContact(ctx context.Context, cfg aws.Config, fields map[
return values, nil
}

func AccountContact(ctx context.Context, cfg aws.Config, stream *StreamSender) ([]Resource, error) {
func AccountContact(ctx context.Context, cfg aws.Config, stream *models.StreamSender) ([]models.Resource, error) {
describeCtx := GetDescribeContext(ctx)

client := account.NewFromConfig(cfg)

var values []Resource
var values []models.Resource

input := &account.GetContactInformationInput{}
op, err := client.GetContactInformation(ctx, input)
if err != nil {
return nil, err
}

resource := Resource{
resource := models.Resource{
Region: describeCtx.OGRegion,
Name: *op.ContactInformation.FullName,
Description: model.AccountContactDescription{
Expand Down
Loading

0 comments on commit 41fc413

Please sign in to comment.