Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add policy tags and masking policy support for maxcompute #78

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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.

Loading