Skip to content

Commit

Permalink
Refactor glue schema generation and decouple logtypes module from aws…
Browse files Browse the repository at this point in the history
…glue (#2068)

* Fix awsglue slice schema for pointer structs

* Adds glueschema module

* Decouples logtypes from awsglue

* Add comments and use bettern names to describe the code

* remove deprecated registry functions

* Move glueschema registrations to the relevant modules

* WIP

* Split gluetimestamp module

* Add package comment

* Fix conflicts

* Remove deprecated registry methods

* remove unused logtypes.Registry type

* further reduce code surface

* Remove unused interface methods

* Fix master.yml

* mage gen fmt

* Restore $ fix for field names

* feedback

* Fail glue schema generation when name collisions occur

* Handle non-ASCII leters gracefully

* mage fmt

* add test for transliteration

* add more test cases

* fix checkGlue

* Add comments and fixme for confusing log tables handling

* Add comments explaining the recursive functions in glueschema

* spelling apparently fails builds now, what next?

* Allow '-' in column names

* Fix TruncateComments flag

* Fix GCP Audit log

* add log output to custom resource manager

* mage gen fmt

* Set CFN event id as the trace id for the database sync

* Fix EnsureDatabases

* return error from athenaviews

* mage gen fmt

* Fix transliteration test

Co-authored-by: panther-bot <[email protected]>
Co-authored-by: Kostas Papageorgiou <[email protected]>
  • Loading branch information
3 people authored Nov 25, 2020
1 parent fd141ff commit 47a1f04
Show file tree
Hide file tree
Showing 44 changed files with 1,052 additions and 1,192 deletions.
3 changes: 2 additions & 1 deletion cmd/devtools/logprocessor/logprocessor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/panther-labs/panther/api/lambda/source/models"
"github.com/panther-labs/panther/internal/log_analysis/log_processor/common"
"github.com/panther-labs/panther/internal/log_analysis/log_processor/destinations"
"github.com/panther-labs/panther/internal/log_analysis/log_processor/logtypes"
"github.com/panther-labs/panther/internal/log_analysis/log_processor/processor"
"github.com/panther-labs/panther/internal/log_analysis/log_processor/registry"
)
Expand Down Expand Up @@ -96,7 +97,7 @@ func main() {
logTypes = append(logTypes, *LOGTYPE)
} else {
// Use all available log types
logTypes = registry.AvailableLogTypes()
logTypes = logtypes.CollectNames(registry.NativeLogTypes())
}

dataStream := &common.DataStream{
Expand Down
21 changes: 20 additions & 1 deletion cmd/devtools/pantherlog/pantherlog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ import (
"log"
"os"

"github.com/pkg/errors"

"github.com/panther-labs/panther/internal/log_analysis/log_processor/classification"
"github.com/panther-labs/panther/internal/log_analysis/log_processor/common"
"github.com/panther-labs/panther/internal/log_analysis/log_processor/parsers"
"github.com/panther-labs/panther/internal/log_analysis/log_processor/registry"
)

Expand Down Expand Up @@ -66,7 +69,7 @@ func main() {

jsonAPI := common.ConfigForDataLakeWriters()

parsers := registry.AvailableParsers()
parsers := availableParsers()

classifier := classification.NewClassifier(parsers)
lines := bufio.NewScanner(stdin)
Expand Down Expand Up @@ -111,3 +114,19 @@ func main() {
debugLog.Printf("Scanned %d lines\n", numLines)
debugLog.Printf("Parsed %d events\n", numEvents)
}

// availableParsers returns log parsers for all native log types with nil parameters.
// Panics if a parser factory in the default registry fails with nil params.
func availableParsers() map[string]parsers.Interface {
entries := registry.NativeLogTypes().Entries()
available := make(map[string]parsers.Interface, len(entries))
for _, entry := range entries {
logType := entry.String()
parser, err := entry.NewParser(nil)
if err != nil {
panic(errors.Errorf("failed to create %q parser with nil params", logType))
}
available[logType] = parser
}
return available
}
6 changes: 0 additions & 6 deletions deployments/log_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ Parameters:
Description: KMS key ID for SQS encryption
# Example: "484fb80c-4ae5-40d0-b22a-bdd5d0953b3e"
AllowedPattern: '^[0-9a-f-]{36}$'
TablesSignature:
Type: String
Description: Value from gluetable.DeployedTablesSignature() or the Panther version if using CF
MinLength: 1
TracingMode:
Type: String
Description: Enable XRay tracing on Lambda and API Gateway
Expand Down Expand Up @@ -120,8 +116,6 @@ Resources:
- UpdaterFunction
Type: Custom::UpdateLogProcessorTables
Properties:
# Update in case TablesSignature or CustomResourceVersion has changed
TablesSignature: !Ref TablesSignature
CustomResourceVersion: !Ref CustomResourceVersion
DataCatalogUpdaterQueueURL: !Ref UpdaterQueue
ServiceToken: !Sub arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:panther-cfn-custom-resources
Expand Down
1 change: 0 additions & 1 deletion deployments/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ Resources:
ProcessedDataTopicArn: !GetAtt Bootstrap.Outputs.ProcessedDataTopicArn
PythonLayerVersionArn: !GetAtt BootstrapGateway.Outputs.PythonLayerVersionArn
SqsKeyId: !GetAtt Bootstrap.Outputs.QueueEncryptionKeyId
TablesSignature: !FindInMap [Constants, Panther, Version] # this changes with version, forcing table schema updates
TracingMode: !Ref TracingMode
Tags:
- Key: Application
Expand Down
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/panther-labs/panther
go 1.15

require (
github.com/anyascii/go v0.1.7
github.com/aws/aws-lambda-go v1.20.0
github.com/aws/aws-sdk-go v1.35.34
github.com/cenkalti/backoff/v4 v4.1.0
Expand All @@ -17,17 +18,22 @@ require (
github.com/joho/godotenv v1.3.0
github.com/json-iterator/go v1.1.10
github.com/kelseyhightower/envconfig v1.4.0
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.2.0 // indirect
github.com/magefile/mage v1.10.0
github.com/modern-go/reflect2 v1.0.1
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pkg/errors v0.9.1
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.6.1
github.com/tidwall/gjson v1.6.3
github.com/valyala/fasttemplate v1.2.1
go.uber.org/multierr v1.6.0
go.uber.org/zap v1.16.0
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9
golang.org/x/text v0.3.4 // indirect
golang.org/x/tools v0.0.0-20201110175055-ae6603bdc3c4
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/go-playground/validator.v9 v9.31.0
gopkg.in/yaml.v2 v2.3.0
Expand Down
13 changes: 13 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/anyascii/go v0.1.7 h1:86zUeo7fM/bNGneugDDWAaclkSWdQRjSMR3ydpeg7cg=
github.com/anyascii/go v0.1.7/go.mod h1:HDvbMmSpqJyIe+xtSkHmAYTjc8PzvO3l1Jmgx/IFUPs=
github.com/aws/aws-lambda-go v1.20.0 h1:ZSweJx/Hy9BoIDXKBEh16vbHH0t0dehnF8MKpMiOWc0=
github.com/aws/aws-lambda-go v1.20.0/go.mod h1:jJmlefzPfGnckuHdXX7/80O3BvUUi12XOkbv4w9SGLU=
github.com/aws/aws-sdk-go v1.35.34 h1:PfsnVvEq7FgsgIOsW8YeParB9ZknW4NXPXcsgqt4srE=
Expand All @@ -8,6 +10,7 @@ github.com/cenkalti/backoff/v4 v4.1.0 h1:c8LkOFQTzuO0WBM/ae5HdGQuZPfPxp7lqBRwQRm
github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -48,6 +51,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/leodido/ragel-machinery v0.0.0-20181214104525-299bdde78165/go.mod h1:WZxr2/6a/Ar9bMDc2rN/LJrE/hF6bXE4LPyDSIxwAfg=
Expand All @@ -58,6 +63,8 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJ
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand All @@ -68,6 +75,8 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
Expand Down Expand Up @@ -119,6 +128,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4 h1:0YWbFKbhXG/wIiuHDSKpS0Iy7FSA+u45VtBMfQcFTTc=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
Expand All @@ -135,6 +146,8 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
Expand Down
24 changes: 17 additions & 7 deletions internal/core/custom_resources/resources/log_processor_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,50 +31,60 @@ import (
"github.com/panther-labs/panther/internal/log_analysis/awsglue"
"github.com/panther-labs/panther/internal/log_analysis/datacatalog_updater/datacatalog"
"github.com/panther-labs/panther/pkg/awsutils"
"github.com/panther-labs/panther/pkg/lambdalogger"
)

type UpdateLogProcessorTablesProperties struct {
// TablesSignature should change every time the tables change (for CF master.yml this can be the Panther version)
TablesSignature string `validate:"required"`
DataCatalogUpdaterQueueURL string `validate:"required"`
}

func customUpdateLogProcessorTables(ctx context.Context, event cfn.Event) (string, map[string]interface{}, error) {
logger := lambdalogger.FromContext(ctx).With(
zap.String("requestID", event.RequestID),
zap.String("requestType", string(event.RequestType)),
zap.String("stackID", event.StackID),
zap.String("eventPhysicalResourceID", event.PhysicalResourceID),
)
logger.Debug("received UpdateLogProcessorTables event", zap.String("requestType", string(event.RequestType)))
switch event.RequestType {
case cfn.RequestCreate, cfn.RequestUpdate:
// It's important to always return this physicalResourceID
const physicalResourceID = "custom:glue:update-log-processor-tables"
var props UpdateLogProcessorTablesProperties
if err := parseProperties(event.ResourceProperties, &props); err != nil {
zap.L().Error("failed to parse resource properties", zap.Error(err))
logger.Error("failed to parse resource properties", zap.Error(err))
return physicalResourceID, nil, err
}
requiredLogTypes, err := apifunctions.ListLogTypes(ctx, lambdaClient)
if err != nil {
logger.Error("failed to fetch required log types", zap.Error(err))
return physicalResourceID, nil, errors.Wrap(err, "failed to fetch required log types from Sources API")
}
client := datacatalog.Client{
SQSAPI: sqsClient,
QueueURL: props.DataCatalogUpdaterQueueURL,
}
if err := client.SendSyncDatabase(ctx, "", requiredLogTypes); err != nil {
zap.L().Error("failed to update glue tables", zap.Error(err))
if err := client.SendSyncDatabase(ctx, event.RequestID, requiredLogTypes); err != nil {
logger.Error("failed to update glue tables", zap.Error(err))
return physicalResourceID, nil, err
}
logger.Info("started database sync", zap.Strings("logTypes", requiredLogTypes))
return physicalResourceID, nil, nil
case cfn.RequestDelete:
for pantherDatabase := range awsglue.PantherDatabases {
zap.L().Info("deleting database", zap.String("database", pantherDatabase))
logger.Info("deleting database", zap.String("database", pantherDatabase))
if _, err := awsglue.DeleteDatabase(glueClient, pantherDatabase); err != nil {
if awsutils.IsAnyError(err, glue.ErrCodeEntityNotFoundException) {
zap.L().Info("already deleted", zap.String("database", pantherDatabase))
logger.Info("already deleted", zap.String("database", pantherDatabase))
} else {
logger.Error("failed to delete", zap.String("database", pantherDatabase))
return "", nil, errors.Wrapf(err, "failed deleting %s", pantherDatabase)
}
}
}
return event.PhysicalResourceID, nil, nil
default:
logger.Error("unknown request type")
return "", nil, fmt.Errorf("unknown request type %s", event.RequestType)
}
}
6 changes: 5 additions & 1 deletion internal/core/logtypesapi/main/lambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"gopkg.in/go-playground/validator.v9"

"github.com/panther-labs/panther/internal/core/logtypesapi"
"github.com/panther-labs/panther/internal/log_analysis/log_processor/logtypes"
"github.com/panther-labs/panther/internal/log_analysis/log_processor/registry"
"github.com/panther-labs/panther/pkg/lambdalogger"
"github.com/panther-labs/panther/pkg/x/lambdamux"
Expand All @@ -48,9 +49,12 @@ func main() {
// Syncing the zap.Logger always results in Lambda errors. Commented code kept as a reminder.
// defer logger.Sync()

nativeLogTypes := logtypes.CollectNames(registry.NativeLogTypes())
api := &logtypesapi.LogTypesAPI{
// Use the default registry with all available log types
NativeLogTypes: registry.AvailableLogTypes,
NativeLogTypes: func() []string {
return nativeLogTypes
},
Database: &logtypesapi.DynamoDBLogTypes{
DB: dynamodb.New(session.Must(session.NewSession())),
TableName: config.LogTypesTableName,
Expand Down
22 changes: 16 additions & 6 deletions internal/log_analysis/athenaviews/athenaviews.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"github.com/panther-labs/panther/api/lambda/core/log_analysis/log_processor/models"
"github.com/panther-labs/panther/internal/log_analysis/awsglue"
"github.com/panther-labs/panther/internal/log_analysis/awsglue/glueschema"
"github.com/panther-labs/panther/internal/log_analysis/log_processor/parsers"
"github.com/panther-labs/panther/pkg/awsathena"
)
Expand Down Expand Up @@ -123,7 +124,10 @@ func generateViewAllHelper(viewName string, tables []*awsglue.GlueTableMetadata,
}

// collect the Panther fields, add "NULL" for fields not present in some tables but present in others
pantherViewColumns := newPantherViewColumns(tables, extraColumns)
pantherViewColumns, err := newPantherViewColumns(tables, extraColumns)
if err != nil {
return "", err
}

var sqlLines []string
sqlLines = append(sqlLines, fmt.Sprintf("create or replace view %s.%s as", awsglue.ViewsDatabaseName, viewName))
Expand All @@ -148,14 +152,16 @@ type pantherViewColumns struct {
columnsByTable map[string]map[string]struct{} // table -> map of column names in that table
}

func newPantherViewColumns(tables []*awsglue.GlueTableMetadata, extraColumns []awsglue.Column) *pantherViewColumns {
func newPantherViewColumns(tables []*awsglue.GlueTableMetadata, extraColumns []awsglue.Column) (*pantherViewColumns, error) {
pvc := &pantherViewColumns{
allColumnsSet: make(map[string]struct{}),
columnsByTable: make(map[string]map[string]struct{}),
}

for _, table := range tables {
pvc.inferViewColumns(table, extraColumns)
if err := pvc.inferViewColumns(table, extraColumns); err != nil {
return nil, err
}
}

// convert set to sorted slice
Expand All @@ -165,11 +171,14 @@ func newPantherViewColumns(tables []*awsglue.GlueTableMetadata, extraColumns []a
}
sort.Strings(pvc.allColumns) // order needs to be preserved

return pvc
return pvc, nil
}
func (pvc *pantherViewColumns) inferViewColumns(table *awsglue.GlueTableMetadata, extraColumns []awsglue.Column) {
func (pvc *pantherViewColumns) inferViewColumns(table *awsglue.GlueTableMetadata, extraColumns []awsglue.Column) error {
// NOTE: in the future when we tag columns for views, the mapping would be resolved here
columns, _ := awsglue.InferJSONColumns(table.EventStruct(), awsglue.GlueMappings...)
columns, err := glueschema.InferColumns(table.EventStruct())
if err != nil {
return err
}
columns = append(columns, extraColumns...)
var selectColumns []string
for _, col := range columns {
Expand All @@ -191,6 +200,7 @@ func (pvc *pantherViewColumns) inferViewColumns(table *awsglue.GlueTableMetadata
pvc.allColumnsSet[column] = struct{}{}
}
}
return nil
}

func (pvc *pantherViewColumns) viewColumns(table *awsglue.GlueTableMetadata) string {
Expand Down
Loading

0 comments on commit 47a1f04

Please sign in to comment.