mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-10-30 23:34:27 +00:00
fix(image): resolve migration conflict and refactor API connection test
- Renumber image migration from 0076 to 0081 to avoid conflict with openstack - Add registry parameter to ImageProvider.test_connection() for registry-level testing - Refactor API connection test to delegate to test_connection() like other providers - Add tests for registry path in test_connection()
This commit is contained in:
4 files changed
+101
-17
No files matched your search
+2
-1
@@ -7,7 +7,7 @@ import api.db_utils
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("api", "0075_cloudflare_provider"),
|
||||
("api", "0080_backfill_attack_paths_graph_data_ready"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
@@ -27,6 +27,7 @@ class Migration(migrations.Migration):
|
||||
("oraclecloud", "Oracle Cloud Infrastructure"),
|
||||
("alibabacloud", "Alibaba Cloud"),
|
||||
("cloudflare", "Cloudflare"),
|
||||
("openstack", "OpenStack"),
|
||||
("image", "Image"),
|
||||
],
|
||||
default="aws",
|
||||
@@ -324,19 +324,14 @@ def prowler_provider_connection_test(provider: Provider) -> Connection:
|
||||
}
|
||||
return prowler_provider.test_connection(**openstack_kwargs)
|
||||
elif provider.provider == Provider.ProviderChoices.IMAGE.value:
|
||||
from prowler.providers.image.lib.registry.factory import create_registry_adapter
|
||||
|
||||
try:
|
||||
adapter = create_registry_adapter(
|
||||
registry_url=provider.uid,
|
||||
username=prowler_provider_kwargs.get("registry_username"),
|
||||
password=prowler_provider_kwargs.get("registry_password"),
|
||||
token=prowler_provider_kwargs.get("registry_token"),
|
||||
)
|
||||
adapter.list_repositories()
|
||||
return Connection(is_connected=True, error=None)
|
||||
except Exception as e:
|
||||
return Connection(is_connected=False, error=str(e))
|
||||
image_kwargs = {
|
||||
"registry": provider.uid,
|
||||
"raise_on_exception": False,
|
||||
}
|
||||
for key in ("registry_username", "registry_password", "registry_token"):
|
||||
if key in prowler_provider_kwargs:
|
||||
image_kwargs[key] = prowler_provider_kwargs[key]
|
||||
return prowler_provider.test_connection(**image_kwargs)
|
||||
else:
|
||||
return prowler_provider.test_connection(
|
||||
**prowler_provider_kwargs,
|
||||
|
||||
Reference in new issue
Block a user