-
Notifications
You must be signed in to change notification settings - Fork 60
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
[Integration] [AWS] | Added support to choose specific regions to query resources from #1099
Merged
Merged
Changes from 14 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
c318294
support to query specific regions
mk-armah 4318eaf
region policy for seemless control
mk-armah 273d922
Merge branch 'main' into improvement-aws
mk-armah 5943bd9
bump integration version
mk-armah 443a314
correct spacing in changelog
mk-armah 932ae04
query regions optionally in resources with special handling
mk-armah 6928f77
updated version
mk-armah 9f8bb71
Update integrations/aws/CHANGELOG.md
mk-armah 627bb9e
real time event supports region policy
mk-armah c15fb33
lint
mk-armah 3747e19
cast selector type
mk-armah b337b21
minimal update to webhook event logic
mk-armah e8fea8f
updated repolicy logic
mk-armah 42b64d9
Merge branch 'main' into improvement-aws
mk-armah 361f6ce
added tests
mk-armah 22bb035
Merge branch 'improvement-aws' of https://github.com/port-labs/ocean …
mk-armah 06f133a
production-ready release
mk-armah d065e06
Merge branch 'main' into improvement-aws
mk-armah 3b90a09
bumped integration version
mk-armah b95b358
updated error handling in querying all resources
mk-armah 550c23a
refactored phrase to improve constructive understanding
mk-armah f43c879
updated changelog
mk-armah 3014165
move log to Bug Fixes
mk-armah 174ab9d
skip resource not found exceptions
mk-armah 7cd9575
Merge branch 'main' into improvement-aws
mk-armah 4d9bae0
lint fix
mk-armah 6bf9095
Merge branch 'main' into improvement-aws
mk-armah 5fc1796
reformat resources.py
mk-armah 9287938
Merge branch 'improvement-aws' of https://github.com/port-labs/ocean …
mk-armah 92e4275
change log level for resource not found from warning to info
mk-armah 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 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
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,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "aws" | ||
version = "0.2.51" | ||
version = "0.2.52-rc1" | ||
description = "This integration will map all your resources in all the available accounts to your Port entities" | ||
authors = ["Shalev Avhar <[email protected]>", "Erik Zaadi <[email protected]>"] | ||
|
||
|
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,59 @@ | ||
import unittest | ||
from utils.overrides import AWSDescribeResourcesSelector, RegionPolicy | ||
|
||
|
||
class TestAWSDescribeResourcesSelector(unittest.TestCase): | ||
|
||
def test_is_region_allowed_no_policy(self) -> None: | ||
selector = AWSDescribeResourcesSelector(query="test") | ||
self.assertTrue(selector.is_region_allowed("us-east-1")) | ||
|
||
def test_is_region_allowed_deny_policy(self) -> None: | ||
region_policy = RegionPolicy(deny=["us-east-1"]) | ||
selector = AWSDescribeResourcesSelector( | ||
query="test", regionPolicy=region_policy | ||
) | ||
self.assertFalse(selector.is_region_allowed("us-east-1")) | ||
self.assertTrue(selector.is_region_allowed("us-west-2")) | ||
|
||
def test_is_region_allowed_allow_policy(self) -> None: | ||
region_policy = RegionPolicy(allow=["us-west-2"]) | ||
selector = AWSDescribeResourcesSelector( | ||
query="test", regionPolicy=region_policy | ||
) | ||
self.assertTrue(selector.is_region_allowed("us-west-2")) | ||
self.assertFalse(selector.is_region_allowed("us-east-1")) | ||
|
||
def test_is_region_allowed_both_policies(self) -> None: | ||
region_policy = RegionPolicy(allow=["us-west-2"], deny=["us-east-1"]) | ||
selector = AWSDescribeResourcesSelector( | ||
query="test", regionPolicy=region_policy | ||
) | ||
self.assertFalse(selector.is_region_allowed("us-east-1")) | ||
self.assertTrue(selector.is_region_allowed("us-west-2")) | ||
self.assertFalse(selector.is_region_allowed("eu-central-1")) | ||
|
||
def test_is_region_allowed_conflicting_policies(self) -> None: | ||
region_policy = RegionPolicy(allow=["us-east-1"], deny=["us-east-1"]) | ||
selector = AWSDescribeResourcesSelector( | ||
query="test", regionPolicy=region_policy | ||
) | ||
self.assertFalse(selector.is_region_allowed("us-east-1")) | ||
|
||
def test_is_region_allowed_deny_only(self) -> None: | ||
region_policy = RegionPolicy(deny=["us-east-1", "us-west-2"]) | ||
selector = AWSDescribeResourcesSelector( | ||
query="test", regionPolicy=region_policy | ||
) | ||
self.assertFalse(selector.is_region_allowed("us-east-1")) | ||
self.assertFalse(selector.is_region_allowed("us-west-2")) | ||
self.assertTrue(selector.is_region_allowed("eu-central-1")) | ||
|
||
def test_is_region_allowed_allow_only(self) -> None: | ||
region_policy = RegionPolicy(allow=["us-east-1", "us-west-2"]) | ||
selector = AWSDescribeResourcesSelector( | ||
query="test", regionPolicy=region_policy | ||
) | ||
self.assertTrue(selector.is_region_allowed("us-east-1")) | ||
self.assertTrue(selector.is_region_allowed("us-west-2")) | ||
self.assertFalse(selector.is_region_allowed("eu-central-1")) |
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,11 +1,18 @@ | ||
import enum | ||
|
||
from port_ocean.context.event import event | ||
from port_ocean.context.ocean import ocean | ||
from utils.overrides import AWSDescribeResourcesSelector | ||
import typing | ||
import asyncio | ||
|
||
|
||
MAX_CONCURRENT_TASKS = 50 | ||
semaphore = asyncio.BoundedSemaphore(MAX_CONCURRENT_TASKS) | ||
def get_semaphore() -> asyncio.BoundedSemaphore: | ||
max_concurrent_accounts: int = int( | ||
ocean.integration_config["maximum_concurrent_accounts"] | ||
) | ||
semaphore = asyncio.BoundedSemaphore(max_concurrent_accounts) | ||
return semaphore | ||
|
||
|
||
class CustomProperties(enum.StrEnum): | ||
|
@@ -46,16 +53,23 @@ def is_server_error(e: Exception) -> bool: | |
|
||
|
||
def get_matching_kinds_and_blueprints_from_config( | ||
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. can we test it? with the new expected behavior? |
||
kind: str, | ||
) -> dict[str, list[str]]: | ||
kinds: dict[str, list[str]] = {} | ||
kind: str, region: str | ||
) -> tuple[dict[str, list[str]], dict[str, list[str]]]: | ||
allowed_kinds: dict[str, list[str]] = {} | ||
disallowed_kinds: dict[str, list[str]] = {} | ||
resources = event.port_app_config.resources | ||
|
||
for resource in resources: | ||
blueprint = resource.port.entity.mappings.blueprint.strip('"') | ||
if resource.kind in kinds: | ||
kinds[resource.kind].append(blueprint) | ||
resource_selector = typing.cast(AWSDescribeResourcesSelector, resource.selector) | ||
if not resource_selector.is_region_allowed(region) and kind == resource.kind: | ||
if kind in disallowed_kinds: | ||
disallowed_kinds[kind].append(blueprint) | ||
else: | ||
disallowed_kinds[kind] = [blueprint] | ||
elif kind == resource.kind: | ||
kinds[resource.kind] = [blueprint] | ||
if kind in allowed_kinds: | ||
allowed_kinds[kind].append(blueprint) | ||
else: | ||
allowed_kinds[kind] = [blueprint] | ||
|
||
return kinds | ||
return allowed_kinds, disallowed_kinds |
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
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.
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.
which resource? add log containing more context about the resource, region etc.