- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2.4k
Add resource property validation framework to SAM translator. #3805
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
      
      
            vicheey
  wants to merge
  12
  commits into
  aws:develop
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
vicheey:validation-framework-extraction
  
      
      
   
  
    
  
  
  
 
  
      
    base: develop
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
          
          
            12 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      89f8a01
              
                add resource property validation rule and logic
              
              
                vicheey f762c86
              
                Merge branch 'develop' into validation-framework-extraction
              
              
                vicheey d5410b0
              
                comment out validation rules for functions
              
              
                vicheey b52c322
              
                chore: ignore validator.oy from test coverage
              
              
                vicheey 7f854fb
              
                address comments
              
              
                vicheey 9d2125c
              
                address comments
              
              
                vicheey d638ffd
              
                Merge branch 'develop' into validation-framework-extraction
              
              
                vicheey d10dbd2
              
                Merge branch 'develop' into validation-framework-extraction
              
              
                vicheey 75de835
              
                Merge branch 'develop' into validation-framework-extraction
              
              
                vicheey dcc9fdb
              
                Merge branch 'develop' into validation-framework-extraction
              
              
                vicheey 3aa6b58
              
                Merge branch 'develop' into validation-framework-extraction
              
              
                vicheey dba1825
              
                Merge branch 'develop' into validation-framework-extraction
              
              
                vicheey 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
    
  
  
    
              
  
    
      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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| """ SAM macro definitions """ | ||
| """SAM macro definitions""" | ||
|  | ||
| import copy | ||
| import re | ||
|  | @@ -139,6 +139,7 @@ class SamFunction(SamResourceMacro): | |
| """SAM function macro.""" | ||
|  | ||
| resource_type = "AWS::Serverless::Function" | ||
|  | ||
| property_types = { | ||
| "FunctionName": PropertyType(False, one_of(IS_STR, IS_DICT)), | ||
| "Handler": PassThroughProperty(False), | ||
|  | @@ -252,6 +253,21 @@ class SamFunction(SamResourceMacro): | |
| "DestinationQueue": SQSQueue.resource_type, | ||
| } | ||
|  | ||
| # def get_property_validation_rules(self) -> Optional[PropertyRules]: | ||
| # """Override to provide PropertyRules validation for SAM Function.""" | ||
| # TODO: To enable these rules, we need to update translator test input/output files to property configure template | ||
| # to avoid fail-fast. eg: test with DeploymentPreference without AutoPublishAlias would fail fast before reaching testing state | ||
| # from samtranslator.internal.schema_source.aws_serverless_function import Properties as FunctionProperties | ||
| # return (PropertyRules(FunctionProperties) | ||
| # .addMutuallyExclusive("ImageUri", "InlineCode", "CodeUri") | ||
| # .addConditionalInclusive("DeploymentPreference", ["AutoPublishAlias"]) | ||
| # .addConditionalInclusive("ProvisionedConcurrencyConfig", ["AutoPublishAlias"]) | ||
| # .addConditionalInclusive("PackageType=Zip", ["Runtime", "Handler"]) | ||
| # .addConditionalInclusive("PackageType=Image", ["ImageUri"]) | ||
| # .addConditionalExclusive("PackageType=Zip", ["ImageUri", "ImageConfig"]) | ||
| # .addConditionalExclusive("PackageType=Image", ["Runtime", "Handler", "Layers"])) | ||
| # return None | ||
|  | ||
| 
      Comment on lines
    
      +256
     to 
      +270
    
   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. Do we plan to leave this here, commented out? | ||
| def resources_to_link(self, resources: Dict[str, Any]) -> Dict[str, Any]: | ||
| try: | ||
| return {"event_resources": self._event_resources_to_link(resources)} | ||
|  | @@ -274,6 +290,11 @@ def to_cloudformation(self, **kwargs): # type: ignore[no-untyped-def] # noqa: P | |
| conditions = kwargs.get("conditions", {}) | ||
| feature_toggle = kwargs.get("feature_toggle") | ||
|  | ||
| # TODO: Skip pass schema_class=aws_serverless_function.Properties to skip schema validation for now. | ||
| # - adding this now would required update error message in error error_function_*_test.py | ||
| # - add this when we can verify that changing error message would not break customers | ||
| # self.validate_before_transform(schema_class=aws_serverless_function.Properties) | ||
| 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. what is this  | ||
|  | ||
| if self.DeadLetterQueue: | ||
| self._validate_dlq(self.DeadLetterQueue) | ||
|  | ||
|  | @@ -1857,6 +1878,7 @@ def _validate_architectures(self, lambda_layer: LambdaLayerVersion) -> None: | |
| # Intrinsics are not validated | ||
| if is_intrinsic(architectures): | ||
| return | ||
|  | ||
| for arq in architectures: | ||
| # We validate the values only if we they're not intrinsics | ||
| if not is_intrinsic(arq) and arq not in [ARM64, X86_64]: | ||
|  | ||
      
      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.