Skip to content

Commit

Permalink
feat: add policy tags and masking policy support for maxcompute
Browse files Browse the repository at this point in the history
  • Loading branch information
solsticemj25 committed Jan 23, 2025
1 parent 3711fea commit b06064e
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 2 deletions.
14 changes: 14 additions & 0 deletions plugins/extractors/maxcompute/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,17 @@ func (c *Client) GetTablePreview(_ context.Context, partitionValue string, table

return columnNames, protoList, nil
}

func (_ *Client) GetPolicyTagsAndMaskingPolicy(table *odps.Table) (string, []string, error) {

Check failure on line 122 in plugins/extractors/maxcompute/client/client.go

View workflow job for this annotation

GitHub Actions / golangci

unnamedResult: consider giving a name to these results (gocritic)

Check failure on line 122 in plugins/extractors/maxcompute/client/client.go

View workflow job for this annotation

GitHub Actions / golangci

ST1006: receiver name should not be an underscore, omit the name if it is unused (stylecheck)
var policyTags []string
var maskingPolicy string
colPolicyTags, err := table.ColumnMaskInfos()
if err != nil {
return maskingPolicy, nil, err
}
for _, policyTag := range colPolicyTags {
maskingPolicy = policyTag.Name
policyTags = append(policyTags, policyTag.PolicyNameList...)
}
return maskingPolicy, policyTags, nil
}
14 changes: 12 additions & 2 deletions plugins/extractors/maxcompute/maxcompute.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type Client interface {
ListTable(ctx context.Context, schemaName string) ([]*odps.Table, error)
GetTableSchema(ctx context.Context, table *odps.Table) (string, *tableschema.TableSchema, error)
GetTablePreview(ctx context.Context, partitionValue string, table *odps.Table, maxRows int) ([]string, *structpb.ListValue, error)
GetPolicyTagsAndMaskingPolicy(table *odps.Table) (string, []string, error)
}

func New(logger log.Logger, clientFunc NewClientFunc, randFn randFn) *Extractor {
Expand Down Expand Up @@ -212,7 +213,7 @@ func (e *Extractor) buildAsset(ctx context.Context, schema *odps.Schema,
Service: maxcomputeService,
}

tableAttributesData := e.buildTableAttributesData(schemaName, tableType, tableSchema)
tableAttributesData := e.buildTableAttributesData(schemaName, tableType, table, tableSchema)

if tableType == config.TableTypeView {
query := tableSchema.ViewText
Expand Down Expand Up @@ -298,7 +299,7 @@ func buildColumns(dataType datatype.DataType) []*v1beta2.Column {
return columns
}

func (e *Extractor) buildTableAttributesData(schemaName, tableType string, tableInfo *tableschema.TableSchema) map[string]interface{} {
func (e *Extractor) buildTableAttributesData(schemaName, tableType string, table *odps.Table, tableInfo *tableschema.TableSchema) map[string]interface{} {
attributesData := map[string]interface{}{}

attributesData["project_name"] = e.config.ProjectName
Expand All @@ -321,6 +322,15 @@ func (e *Extractor) buildTableAttributesData(schemaName, tableType string, table
attributesData["partition_fields"] = partitionNames
}

maskingPolicy, policyTags, err := e.client.GetPolicyTagsAndMaskingPolicy(table)
if err != nil {
e.logger.Warn("error getting policy tags", "error", err)
}
attributesData["masking_policy"] = maskingPolicy
if len(policyTags) > 0 {
attributesData["policy_tags"] = policyTags
}

return attributesData
}

Expand Down
65 changes: 65 additions & 0 deletions plugins/extractors/maxcompute/mocks/maxcompute_client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b06064e

Please sign in to comment.