generated from amazon-archives/__template_Apache-2.0
    
        
        - 
                Notifications
    
You must be signed in to change notification settings  - Fork 7
 
feat: tagging backward compatibility #90
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
      
      
            ammokhov
  wants to merge
  2
  commits into
  main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
feature/tagging-backward-compatibility
  
      
      
   
  
    
  
  
  
 
  
      
    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.
          
          
      
        
          +503
        
        
          −0
        
        
          
        
      
    
  
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            2 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -72,6 +72,11 @@ class DIFFKEYS: | |
| "arrayType", | ||
| } | ||
| 
     | 
||
| # Top-level object constructs that need special tracking | ||
| cfn_object_constructs = { | ||
| "tagging", | ||
| } | ||
| 
     | 
||
| native_constructs = { | ||
| "type", | ||
| "description", | ||
| 
          
            
          
           | 
    @@ -161,6 +166,16 @@ def _is_cfn_leaf_construct(path_list): | |
| return len(path_list) > 0 and path_list[-1] in cfn_leaf_level_constructs | ||
| 
     | 
||
| 
     | 
||
| def _is_cfn_object_construct(path_list): | ||
| """This method defines cfn object constructs like tagging""" | ||
| return len(path_list) == 1 and path_list[0] in cfn_object_constructs | ||
| 
     | 
||
| 
     | 
||
| def _is_tagging_property(path_list): | ||
| """This method checks if path is a tagging nested property""" | ||
| return len(path_list) == 2 and path_list[0] == "tagging" | ||
| 
     | 
||
| 
     | 
||
| def _get_path(path_list): | ||
| """This method converts array into schema path notation""" | ||
| return "/".join([""] + path_list) | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: is   | 
||
| 
          
            
          
           | 
    @@ -326,10 +341,32 @@ def _translate_dict_change( | |
| def __translate_dict_diff(diffkey, schema_meta_diff, diff_value): | ||
| for key, value in diff_value.items(): | ||
| path_list = _cast_path(key) | ||
| 
     | 
||
| if _is_combiner_property(path_list): | ||
| raise NotImplementedError( | ||
| "Schemas with combiners are not yet supported for stateful evaluation" | ||
| ) | ||
| if _is_cfn_object_construct(path_list): | ||
| 
     | 
||
| _add_item(schema_meta_diff, path_list[0], diffkey, True) | ||
| if _is_tagging_property(path_list): | ||
| # Track nested tagging properties in flat structure | ||
| # For removed/added: tagging: {removed: ['/tagging/taggable', ...]} | ||
| # For changed: tagging: {changed: [{property: '/tagging/taggable', old_value: ..., new_value: ...}]} | ||
| if len(path_list) == 2: # e.g., ['tagging', 'taggable'] | ||
| parent_key = path_list[0] # 'tagging' | ||
| 
     | 
||
| if parent_key not in schema_meta_diff: | ||
| schema_meta_diff[parent_key] = {} | ||
| 
     | 
||
| # Create the property path | ||
| property_path = _get_path(path_list) | ||
| 
     | 
||
| # For added/removed, just add the path string | ||
| # (changed is handled separately in _translate_values_changed_diff_) | ||
| if diffkey not in schema_meta_diff[parent_key]: | ||
| schema_meta_diff[parent_key][diffkey] = [] | ||
| schema_meta_diff[parent_key][diffkey].append(property_path) | ||
| if _is_resource_property(path_list): | ||
| _add_item(schema_meta_diff, PROPERTIES, diffkey, _get_path(path_list)) | ||
| if isinstance(value, dict): | ||
| 
          
            
          
           | 
    @@ -404,6 +441,24 @@ def _translate_values_changed_diff_(schema_meta_diff, diff_value): | |
| DIFFKEYS.ADDED, | ||
| value[DIFFKEYS.NEW_VALUE], | ||
| ) | ||
| if _is_tagging_property(path_list): | ||
| # Track changes to nested tagging properties in flat structure | ||
| # Create structure like: tagging: {changed: [{property: '/tagging/taggable', ...}]} | ||
| if len(path_list) == 2: # e.g., ['tagging', 'taggable'] | ||
| parent_key = path_list[0] # 'tagging' | ||
| 
     | 
||
| if parent_key not in schema_meta_diff: | ||
| schema_meta_diff[parent_key] = {} | ||
| 
     | 
||
| change_value = { | ||
| DIFFKEYS.PROPERTY: "/" + "/".join(path_list), | ||
| DIFFKEYS.OLD_VALUE: value[DIFFKEYS.OLD_VALUE], | ||
| DIFFKEYS.NEW_VALUE: value[DIFFKEYS.NEW_VALUE], | ||
| } | ||
| 
     | 
||
| if DIFFKEYS.CHANGED not in schema_meta_diff[parent_key]: | ||
| schema_meta_diff[parent_key][DIFFKEYS.CHANGED] = [] | ||
| schema_meta_diff[parent_key][DIFFKEYS.CHANGED].append(change_value) | ||
| if _is_json_construct(path_list): | ||
| _add_item( | ||
| schema_meta_diff, | ||
| 
          
            
          
           | 
    ||
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
      
      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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can we put 2 inside a var like
TAGGING_NEST_DEPTHor something and use that var everywhere?