-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test: New test group to test for side effects (#2046) * test: New test group to test for side effects * refactor: Updated to use _compare_transform and test CN and GOV partitions * docs: fix dead link (#2045) * Percentage-based Enablement for Feature Toggle (#1952) * Percentage-based Enablement for Feature Toggle * Update Feature Toggle to accept stage, account_id and region during instanciation * remove unnecessary uses of dict.get method * Refactor feature toggle methods * Update test names * black reformat * Update FeatureToggle to require stage, region and account_id to instanciate * Update log message * Implement calculating account percentile based on hash of account_id and feature_name * Refactor _is_feature_enabled_for_region_config * Refactor dialup logic into its own classes * Add comments for dialup classes * Rename NeverEnabledDialup to DisabledDialup * chore(tests): Adding any tests (#2053) * Adding api_request_model any tests * Add any to api_request_model_openapi_3 cases * Add rest of relevant any test cases * Fix hashing to match python2 * add api_with_swagger_authorizer_none to be run * fix py2 hashes in api_with_swagger_authorizer_none tests Co-authored-by: Jacob Fuss <[email protected]> * Add modes support for RestApi (#2055) * Adding Mode passthrough property to RestApi with unit tests. * Adding integration test for Mode * Fixing sam-translate for manual translation. * running black formatting * Running black formatting, again. * Clearing pip-wheel-metadata. * Clearing tmp folder created by integ test. Co-authored-by: Tarun Mall <[email protected]> * chore: bump version to 1.38.0 (#2081) Co-authored-by: Mathieu Grandis <[email protected]> Co-authored-by: Chris Rehn <[email protected]> Co-authored-by: Wing Fung Lau <[email protected]> Co-authored-by: Jacob Fuss <[email protected]> Co-authored-by: Jacob Fuss <[email protected]> Co-authored-by: Tarun Mall <[email protected]> Co-authored-by: Raymond Wang <[email protected]> Co-authored-by: Mathieu Grandis <[email protected]> Co-authored-by: Chris Rehn <[email protected]> Co-authored-by: Wing Fung Lau <[email protected]> Co-authored-by: Jacob Fuss <[email protected]> Co-authored-by: Jacob Fuss <[email protected]> Co-authored-by: Tarun Mall <[email protected]> Co-authored-by: Raymond Wang <[email protected]>
- Loading branch information
1 parent
25fa8a8
commit 4ef6093
Showing
147 changed files
with
22,958 additions
and
13,156 deletions.
There are no files selected for viewing
This file contains 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 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 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
11 changes: 11 additions & 0 deletions
11
integration/resources/expected/single/basic_api_with_mode.json
This file contains 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,11 @@ | ||
[ | ||
{"LogicalResourceId": "MyApi", "ResourceType": "AWS::ApiGateway::RestApi"}, | ||
{"LogicalResourceId": "MyApiDeploymenta808f15210", "ResourceType": "AWS::ApiGateway::Deployment"}, | ||
{"LogicalResourceId": "MyApiMyNewStageNameStage", "ResourceType": "AWS::ApiGateway::Stage"}, | ||
{"LogicalResourceId": "TestFunction", "ResourceType": "AWS::Lambda::Function"}, | ||
{"LogicalResourceId": "TestFunctionAliaslive", "ResourceType": "AWS::Lambda::Alias"}, | ||
{"LogicalResourceId": "TestFunctionGetPermissionMyNewStageName", "ResourceType": "AWS::Lambda::Permission"}, | ||
{"LogicalResourceId": "TestFunctionPutPermissionMyNewStageName", "ResourceType": "AWS::Lambda::Permission"}, | ||
{"LogicalResourceId": "TestFunctionRole", "ResourceType": "AWS::IAM::Role"}, | ||
{"LogicalResourceId": "TestFunctionVersione9898fd501", "ResourceType": "AWS::Lambda::Version"} | ||
] |
10 changes: 10 additions & 0 deletions
10
integration/resources/expected/single/basic_api_with_mode_update.json
This file contains 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,10 @@ | ||
[ | ||
{"LogicalResourceId": "MyApi", "ResourceType": "AWS::ApiGateway::RestApi"}, | ||
{"LogicalResourceId": "MyApiDeploymentada889e3ac", "ResourceType": "AWS::ApiGateway::Deployment"}, | ||
{"LogicalResourceId": "MyApiMyNewStageNameStage", "ResourceType": "AWS::ApiGateway::Stage"}, | ||
{"LogicalResourceId": "TestFunction", "ResourceType": "AWS::Lambda::Function"}, | ||
{"LogicalResourceId": "TestFunctionAliaslive", "ResourceType": "AWS::Lambda::Alias"}, | ||
{"LogicalResourceId": "TestFunctionPutPermissionMyNewStageName", "ResourceType": "AWS::Lambda::Permission"}, | ||
{"LogicalResourceId": "TestFunctionRole", "ResourceType": "AWS::IAM::Role"}, | ||
{"LogicalResourceId": "TestFunctionVersion847aaa5fc1", "ResourceType": "AWS::Lambda::Version"} | ||
] |
34 changes: 34 additions & 0 deletions
34
integration/resources/templates/single/basic_api_with_mode.yaml
This file contains 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,34 @@ | ||
Resources: | ||
MyApi: | ||
Type: AWS::Serverless::Api | ||
Properties: | ||
StageName: MyNewStageName | ||
Mode: overwrite | ||
|
||
TestFunction: | ||
Type: 'AWS::Serverless::Function' | ||
Properties: | ||
Handler: index.handler | ||
Runtime: python3.6 | ||
AutoPublishAlias: live | ||
InlineCode: | | ||
import json | ||
def handler(event, context): | ||
return {'statusCode': 200, 'body': json.dumps('Hello World!')} | ||
Events: | ||
Get: | ||
Type: Api | ||
Properties: | ||
Path: /get | ||
Method: get | ||
RestApiId: !Ref MyApi | ||
Put: | ||
Type: Api | ||
Properties: | ||
Path: /put | ||
Method: put | ||
RestApiId: !Ref MyApi | ||
|
||
Outputs: | ||
ApiEndpoint: | ||
Value: !Sub "https://${MyApi}.execute-api.${AWS::Region}.amazonaws.com/MyNewStageName" |
24 changes: 24 additions & 0 deletions
24
integration/resources/templates/single/basic_api_with_mode_update.yaml
This file contains 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,24 @@ | ||
Resources: | ||
MyApi: | ||
Type: AWS::Serverless::Api | ||
Properties: | ||
StageName: MyNewStageName | ||
Mode: overwrite | ||
|
||
TestFunction: | ||
Type: 'AWS::Serverless::Function' | ||
Properties: | ||
Handler: index.handler | ||
Runtime: python3.6 | ||
AutoPublishAlias: live | ||
InlineCode: | | ||
def handler(event, context): | ||
print("Hello, world!") | ||
Events: | ||
Put: | ||
Type: Api | ||
Properties: | ||
Path: /put | ||
Method: put | ||
RestApiId: !Ref MyApi | ||
|
This file contains 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 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 +1 @@ | ||
__version__ = "1.37.0" | ||
__version__ = "1.38.0" |
This file contains 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,74 @@ | ||
import hashlib | ||
|
||
|
||
class BaseDialup(object): | ||
"""BaseDialup class to provide an interface for all dialup classes""" | ||
|
||
def __init__(self, region_config, **kwargs): | ||
self.region_config = region_config | ||
|
||
def is_enabled(self): | ||
""" | ||
Returns a bool on whether this dialup is enabled or not | ||
""" | ||
raise NotImplementedError | ||
|
||
def __str__(self): | ||
return self.__class__.__name__ | ||
|
||
|
||
class DisabledDialup(BaseDialup): | ||
""" | ||
A dialup that is never enabled | ||
""" | ||
|
||
def __init__(self, region_config, **kwargs): | ||
super(DisabledDialup, self).__init__(region_config) | ||
|
||
def is_enabled(self): | ||
return False | ||
|
||
|
||
class ToggleDialup(BaseDialup): | ||
""" | ||
A simple toggle Dialup | ||
Example of region_config: { "type": "toggle", "enabled": True } | ||
""" | ||
|
||
def __init__(self, region_config, **kwargs): | ||
super(ToggleDialup, self).__init__(region_config) | ||
self.region_config = region_config | ||
|
||
def is_enabled(self): | ||
return self.region_config.get("enabled", False) | ||
|
||
|
||
class SimpleAccountPercentileDialup(BaseDialup): | ||
""" | ||
Simple account percentile dialup, enabling X% of | ||
Example of region_config: { "type": "account-percentile", "enabled-%": 20 } | ||
""" | ||
|
||
def __init__(self, region_config, account_id, feature_name, **kwargs): | ||
super(SimpleAccountPercentileDialup, self).__init__(region_config) | ||
self.account_id = account_id | ||
self.feature_name = feature_name | ||
|
||
def _get_account_percentile(self): | ||
""" | ||
Get account percentile based on sha256 hash of account ID and feature_name | ||
:returns: integer n, where 0 <= n < 100 | ||
""" | ||
m = hashlib.sha256() | ||
m.update(self.account_id.encode()) | ||
m.update(self.feature_name.encode()) | ||
return int(m.hexdigest(), 16) % 100 | ||
|
||
def is_enabled(self): | ||
""" | ||
Enable when account_percentile falls within target_percentile | ||
Meaning only (target_percentile)% of accounts will be enabled | ||
""" | ||
target_percentile = self.region_config.get("enabled-%", 0) | ||
return self._get_account_percentile() < target_percentile |
This file contains 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.