-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Feature/aspects on entry links #16621
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
Open
AnujJhunjhunwala
wants to merge
13
commits into
GoogleCloudPlatform:main
Choose a base branch
from
AnujJhunjhunwala:feature/aspects-on-entry-links
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0268545
Add support for creating aspects on entry links
AnujJhunjhunwala 5d94c32
Merge branch 'GoogleCloudPlatform:main' into feature/create-aspects-o…
AnujJhunjhunwala ca4a5bb
Changes to support update AOEL
AnujJhunjhunwala 7a55455
remove ignored aspects from update test
AnujJhunjhunwala e74d60d
Revert staging temp changes
AnujJhunjhunwala a18fddd
Revert flatten and decoder
AnujJhunjhunwala 000107b
Remove extra newline
AnujJhunjhunwala dce888f
Remove unnecessary tests
AnujJhunjhunwala 8561d17
Add retry for 1P entry not found
AnujJhunjhunwala 17b5b25
Merge branch 'feature/update-aspects-on-entry-links-new-internal' int…
AnujJhunjhunwala 9e7a344
Remove depends on
AnujJhunjhunwala 30c49eb
Add immutable to entry_references
AnujJhunjhunwala 36ffe6a
Retry when ingested @bigquery entry
AnujJhunjhunwala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
mmv1/templates/terraform/constants/dataplex_entry_link.go.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| var ( | ||
| entryLinkProjectNumberRegex = regexp.MustCompile(`^projects\/[1-9]\d*\/.+$`) | ||
| ) | ||
|
|
||
| // EntryLinkProjectNumberValidation checks if the input string conforms to the pattern: | ||
| // "projects/<project-number>/<anything>" | ||
| func EntryLinkProjectNumberValidation(i interface{}, k string) (warnings []string, errors []error) { | ||
| v, ok := i.(string) | ||
|
|
||
| if !ok { | ||
| errors = append(errors, fmt.Errorf("expected type of field %q to be string, but got %T", k, i)) | ||
| return warnings, errors | ||
| } | ||
|
|
||
| if !entryLinkProjectNumberRegex.MatchString(v) { | ||
| errors = append(errors, fmt.Errorf( | ||
| "field %q has an invalid format: %q. Expected format: 'projects/<project-number>/<anything>'. Please note that project IDs are not supported.", | ||
| k, v, | ||
| )) | ||
| } | ||
|
|
||
| return warnings, errors | ||
| } | ||
|
|
||
| // FilterEntryLinkAspects filters the aspects in res based on aspectKeySet. | ||
| // It returns an error if type assertions fail. | ||
| func FilterEntryLinkAspects(aspectKeySet map[string]struct{}, res map[string]interface{}) error { | ||
| aspectsRaw, ok := res["aspects"] | ||
| if !ok || aspectsRaw == nil { | ||
| return nil | ||
| } | ||
|
|
||
| aspectsMap, ok := aspectsRaw.(map[string]interface{}) | ||
| if !ok { | ||
| return fmt.Errorf("FilterEntryLinkAspects: 'aspects' field is not a map[string]interface{}, got %T", aspectsRaw) | ||
| } | ||
|
|
||
| for key := range aspectsMap { | ||
| if _, keep := aspectKeySet[key]; !keep { | ||
| delete(aspectsMap, key) | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // AddEntryLinkAspectsToSet adds aspect keys from the aspects interface to the aspectKeySet. | ||
| // It returns an error if type assertions fail or expected keys are missing. | ||
| func AddEntryLinkAspectsToSet(aspectKeySet map[string]struct{}, aspects interface{}) error { | ||
| if aspects == nil { | ||
| return nil | ||
| } | ||
| aspectsSlice, ok := aspects.([]interface{}) | ||
| if !ok { | ||
| return fmt.Errorf("AddEntryLinkAspectsToSet: input 'aspects' is not a []interface{}, got %T", aspects) | ||
| } | ||
|
|
||
| for i, aspectItemRaw := range aspectsSlice { | ||
| aspectMap, ok := aspectItemRaw.(map[string]interface{}) | ||
| if !ok { | ||
| return fmt.Errorf("AddEntryLinkAspectsToSet: item at index %d is not a map[string]interface{}, got %T", i, aspectItemRaw) | ||
| } | ||
|
|
||
| keyRaw, keyExists := aspectMap["aspect_key"] | ||
| if !keyExists { | ||
| return fmt.Errorf("AddEntryLinkAspectsToSet: 'aspect_key' not found in aspect item at index %d", i) | ||
| } | ||
|
|
||
| keyString, ok := keyRaw.(string) | ||
| if !ok { | ||
| return fmt.Errorf("AddEntryLinkAspectsToSet: 'aspect_key' in item at index %d is not a string, got %T", i, keyRaw) | ||
| } | ||
| aspectKeySet[keyString] = struct{}{} | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // InverseTransformEntryLinkAspects converts the "aspects" map back to a slice of maps, | ||
| // re-inserting the "aspectKey". Modifies obj in-place. | ||
| // It returns an error if type assertions fail. | ||
| func InverseTransformEntryLinkAspects(res map[string]interface{}) error { | ||
| aspectsRaw, ok := res["aspects"] | ||
| if !ok || aspectsRaw == nil { | ||
| return nil | ||
| } | ||
|
|
||
| originalMap, ok := aspectsRaw.(map[string]interface{}) | ||
| if !ok { | ||
| return fmt.Errorf("InverseTransformEntryLinkAspects: 'aspects' field is not a map[string]interface{}, got %T", aspectsRaw) | ||
| } | ||
|
|
||
| newSlice := make([]interface{}, 0, len(originalMap)) | ||
|
|
||
| for key, value := range originalMap { | ||
| innerMap, ok := value.(map[string]interface{}) | ||
| if !ok { | ||
| return fmt.Errorf("InverseTransformEntryLinkAspects: value for key '%s' is not a map[string]interface{}, got %T", key, value) | ||
| } | ||
| box := make(map[string]interface{}, 2) | ||
| box["aspectKey"] = key | ||
| box["aspect"] = innerMap | ||
| newSlice = append(newSlice, box) | ||
| } | ||
| res["aspects"] = newSlice | ||
| return nil | ||
| } | ||
|
|
||
| // TransformEntryLinkAspects concisely transforms the "aspects" slice within obj into a map. | ||
| // Modifies obj in-place. | ||
| // It returns an error if type assertions fail or expected keys are missing. | ||
| func TransformEntryLinkAspects(obj map[string]interface{}) error { | ||
| aspectsRaw, ok := obj["aspects"] | ||
| if !ok || aspectsRaw == nil { | ||
| return nil | ||
| } | ||
|
|
||
| originalSlice, ok := aspectsRaw.([]interface{}) | ||
| if !ok { | ||
| return fmt.Errorf("TransformEntryLinkAspects: 'aspects' field is not a []interface{}, got %T", aspectsRaw) | ||
| } | ||
|
|
||
| newMap := make(map[string]interface{}, len(originalSlice)) | ||
| for i, item := range originalSlice { | ||
| aspectMap, ok := item.(map[string]interface{}) | ||
| if !ok { | ||
| return fmt.Errorf("TransformEntryLinkAspects: item in 'aspects' slice at index %d is not a map[string]interface{}, got %T", i, item) | ||
| } | ||
|
|
||
| keyRaw, keyExists := aspectMap["aspectKey"] | ||
| if !keyExists { | ||
| return fmt.Errorf("TransformEntryLinkAspects: 'aspectKey' not found in aspect item at index %d", i) | ||
| } | ||
| key, ok := keyRaw.(string) | ||
| if !ok { | ||
| return fmt.Errorf("TransformEntryLinkAspects: 'aspectKey' in item at index %d is not a string, got %T", i, keyRaw) | ||
| } | ||
|
|
||
| valueRaw, valueExists := aspectMap["aspect"] | ||
| if !valueExists { | ||
| newMap[key] = map[string]interface{}{"data": map[string]interface{}{}} | ||
| continue | ||
| } | ||
|
|
||
| value, ok := valueRaw.(map[string]interface{}) | ||
| if ok { | ||
| newMap[key] = value | ||
| } else { | ||
| newMap[key] = map[string]interface{}{"data": map[string]interface{}{}} | ||
| } | ||
| } | ||
| obj["aspects"] = newMap | ||
| return nil | ||
| } |
44 changes: 44 additions & 0 deletions
44
mmv1/templates/terraform/custom_flatten/dataplex_entry_link_aspects.go.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // This file is a transposition of mmv1/templates/terraform/flatten_property_method.go.tmpl | ||
| // Most of the code is copied from there, with the exception of sorting logic. | ||
| func flatten{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { | ||
| if v == nil { | ||
| return v | ||
| } | ||
| l := v.([]interface{}) | ||
| transformed := make([]map[string]interface{}, 0, len(l)) | ||
| for _, raw := range l { | ||
| original := raw.(map[string]interface{}) | ||
| if len(original) < 1 { | ||
| // Do not include empty json objects coming back from the api | ||
| continue | ||
| } | ||
| transformed = append(transformed, map[string]interface{}{ | ||
|
|
||
| {{- range $prop := $.ItemType.UserProperties }} | ||
| {{- if not (or $prop.IgnoreRead $prop.WriteOnlyLegacy $prop.WriteOnly) }} | ||
| "{{ underscore $prop.Name }}": flatten{{$.GetPrefix}}{{$.TitlelizeProperty}}{{$prop.TitlelizeProperty}}(original["{{ $prop.ApiName }}"], d, config), | ||
| {{- end }} | ||
| {{- end }} | ||
| }) | ||
| } | ||
|
|
||
| configData := []map[string]interface{}{} | ||
|
|
||
| for _, item := range d.Get("aspects").([]interface{}) { | ||
| configData = append(configData, item.(map[string]interface{})) | ||
| } | ||
|
|
||
| sorted, err := tpgresource.SortMapsByConfigOrder(configData, transformed, "aspect_key") | ||
| if err != nil { | ||
| log.Printf("[ERROR] Could not sort API response value: %s", err) | ||
| return v | ||
| } | ||
|
|
||
| return sorted | ||
| } | ||
|
|
||
| {{- if $.NestedProperties }} | ||
| {{- range $prop := $.NestedProperties }} | ||
| {{ template "flattenPropertyMethod" $prop -}} | ||
| {{- end }} | ||
| {{- end }} |
31 changes: 31 additions & 0 deletions
31
mmv1/templates/terraform/decoders/dataplex_entry_link.go.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| aspectKeysOfInterest := make(map[string]struct{}) | ||
| var err error | ||
|
|
||
| if d.HasChange("aspects") { | ||
| currentAspects, futureAspects := d.GetChange("aspects") | ||
| err = AddEntryLinkAspectsToSet(aspectKeysOfInterest, currentAspects) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| err = AddEntryLinkAspectsToSet(aspectKeysOfInterest, futureAspects) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } else { | ||
| err = AddEntryLinkAspectsToSet(aspectKeysOfInterest, d.Get("aspects")) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
| err = FilterEntryLinkAspects(aspectKeysOfInterest, res) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| err = InverseTransformEntryLinkAspects(res) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return res, nil |
5 changes: 5 additions & 0 deletions
5
mmv1/templates/terraform/encoders/dataplex_entry_link.go.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| if err := TransformEntryLinkAspects(obj); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return obj, nil |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.