diff --git a/plugins/extractors/maxcompute/client/client.go b/plugins/extractors/maxcompute/client/client.go index 000d1db6..e8bfab7b 100644 --- a/plugins/extractors/maxcompute/client/client.go +++ b/plugins/extractors/maxcompute/client/client.go @@ -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) { + 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 +} diff --git a/plugins/extractors/maxcompute/maxcompute.go b/plugins/extractors/maxcompute/maxcompute.go index 22fcc54f..5f2b87ae 100644 --- a/plugins/extractors/maxcompute/maxcompute.go +++ b/plugins/extractors/maxcompute/maxcompute.go @@ -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 { @@ -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 @@ -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 @@ -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 } diff --git a/plugins/extractors/maxcompute/mocks/maxcompute_client_mock.go b/plugins/extractors/maxcompute/mocks/maxcompute_client_mock.go index bef24d34..33b9f57d 100644 --- a/plugins/extractors/maxcompute/mocks/maxcompute_client_mock.go +++ b/plugins/extractors/maxcompute/mocks/maxcompute_client_mock.go @@ -27,6 +27,71 @@ func (_m *MaxComputeClient) EXPECT() *MaxComputeClient_Expecter { return &MaxComputeClient_Expecter{mock: &_m.Mock} } +// GetPolicyTagsAndMaskingPolicy provides a mock function with given fields: table +func (_m *MaxComputeClient) GetPolicyTagsAndMaskingPolicy(table *odps.Table) (string, []string, error) { + ret := _m.Called(table) + + if len(ret) == 0 { + panic("no return value specified for GetPolicyTagsAndMaskingPolicy") + } + + var r0 string + var r1 []string + var r2 error + if rf, ok := ret.Get(0).(func(*odps.Table) (string, []string, error)); ok { + return rf(table) + } + if rf, ok := ret.Get(0).(func(*odps.Table) string); ok { + r0 = rf(table) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(*odps.Table) []string); ok { + r1 = rf(table) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).([]string) + } + } + + if rf, ok := ret.Get(2).(func(*odps.Table) error); ok { + r2 = rf(table) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// MaxComputeClient_GetPolicyTagsAndMaskingPolicy_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPolicyTagsAndMaskingPolicy' +type MaxComputeClient_GetPolicyTagsAndMaskingPolicy_Call struct { + *mock.Call +} + +// GetPolicyTagsAndMaskingPolicy is a helper method to define mock.On call +// - table *odps.Table +func (_e *MaxComputeClient_Expecter) GetPolicyTagsAndMaskingPolicy(table interface{}) *MaxComputeClient_GetPolicyTagsAndMaskingPolicy_Call { + return &MaxComputeClient_GetPolicyTagsAndMaskingPolicy_Call{Call: _e.mock.On("GetPolicyTagsAndMaskingPolicy", table)} +} + +func (_c *MaxComputeClient_GetPolicyTagsAndMaskingPolicy_Call) Run(run func(table *odps.Table)) *MaxComputeClient_GetPolicyTagsAndMaskingPolicy_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*odps.Table)) + }) + return _c +} + +func (_c *MaxComputeClient_GetPolicyTagsAndMaskingPolicy_Call) Return(_a0 string, _a1 []string, _a2 error) *MaxComputeClient_GetPolicyTagsAndMaskingPolicy_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *MaxComputeClient_GetPolicyTagsAndMaskingPolicy_Call) RunAndReturn(run func(*odps.Table) (string, []string, error)) *MaxComputeClient_GetPolicyTagsAndMaskingPolicy_Call { + _c.Call.Return(run) + return _c +} + // GetTablePreview provides a mock function with given fields: ctx, partitionValue, table, maxRows func (_m *MaxComputeClient) GetTablePreview(ctx context.Context, partitionValue string, table *odps.Table, maxRows int) ([]string, *structpb.ListValue, error) { ret := _m.Called(ctx, partitionValue, table, maxRows)