Skip to content
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

chore: add common action models to shared models folder #459

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repos:
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.1.1
rev: 24.2.0
hooks:
- id: black
- repo: https://github.com/yelp/detect-secrets
Expand Down
27 changes: 2 additions & 25 deletions secureli/actions/action.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from abc import ABC
from enum import Enum
from pathlib import Path
from typing import Optional
from secureli.abstractions.echo import EchoAbstraction
from secureli.consts.logging import TELEMETRY_DEFAULT_ENDPOINT
from secureli.models.echo import Color
Expand All @@ -11,7 +9,7 @@
VerifyConfigOutcome,
)
from secureli.repositories.settings import SecureliRepository, TelemetrySettings
from secureli.services.language_analyzer import LanguageAnalyzerService, AnalyzeResult
from secureli.services.language_analyzer import LanguageAnalyzerService
from secureli.services.language_config import LanguageNotSupportedError
from secureli.services.language_support import (
LanguageMetadata,
Expand All @@ -20,31 +18,10 @@
from secureli.services.scanner import ScannerService, ScanMode
from secureli.services.updater import UpdaterService

import pydantic
from secureli.shared.models.actions import VerifyOutcome, VerifyResult
from secureli.utilities.formatter import format_sentence_list


class VerifyOutcome(str, Enum):
INSTALL_CANCELED = "install-canceled"
INSTALL_FAILED = "install-failed"
INSTALL_SUCCEEDED = "install-succeeded"
UPDATE_CANCELED = "update-canceled"
UPDATE_SUCCEEDED = "update-succeeded"
UPDATE_FAILED = "update-failed"
UP_TO_DATE = "up-to-date"


class VerifyResult(pydantic.BaseModel):
"""
The outcomes of performing verification. Actions can use these results
to decide whether to proceed with their post-initialization actions or not.
"""

outcome: VerifyOutcome
config: Optional[SecureliConfig] = None
analyze_result: Optional[AnalyzeResult] = None


class ActionDependencies:
"""
Consolidates a growing set of common dependencies so Action adopters can
Expand Down
3 changes: 1 addition & 2 deletions secureli/actions/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

from secureli.abstractions.echo import EchoAbstraction
from secureli.actions.action import (
VerifyOutcome,
Action,
ActionDependencies,
VerifyResult,
)
from secureli.models.exit_codes import ExitCode
from secureli.models.publish_results import PublishResultsOption
Expand All @@ -20,6 +18,7 @@
ScannerService,
)
from secureli.settings import Settings
from secureli.shared.models.actions import VerifyOutcome, VerifyResult
from secureli.utilities.usage_stats import post_log, convert_failures_to_failure_count

ONE_WEEK_IN_SECONDS: int = 7 * 24 * 60 * 60
Expand Down
Empty file added secureli/shared/__init__.py
Empty file.
Empty file.
28 changes: 28 additions & 0 deletions secureli/shared/models/actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from enum import Enum
from typing import Optional

import pydantic

from secureli.repositories.secureli_config import SecureliConfig
from secureli.services.language_analyzer import AnalyzeResult


class VerifyOutcome(str, Enum):
INSTALL_CANCELED = "install-canceled"
INSTALL_FAILED = "install-failed"
INSTALL_SUCCEEDED = "install-succeeded"
UPDATE_CANCELED = "update-canceled"
UPDATE_SUCCEEDED = "update-succeeded"
UPDATE_FAILED = "update-failed"
UP_TO_DATE = "up-to-date"


class VerifyResult(pydantic.BaseModel):
"""
The outcomes of performing verification. Actions can use these results
to decide whether to proceed with their post-initialization actions or not.
"""

outcome: VerifyOutcome
config: Optional[SecureliConfig] = None
analyze_result: Optional[AnalyzeResult] = None
3 changes: 2 additions & 1 deletion tests/actions/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
from secureli.abstractions.pre_commit import InstallResult

from secureli.actions.action import Action, ActionDependencies, VerifyOutcome
from secureli.actions.action import Action, ActionDependencies
from secureli.consts.logging import TELEMETRY_DEFAULT_ENDPOINT
from secureli.models.echo import Color
from secureli.repositories.secureli_config import SecureliConfig, VerifyConfigOutcome
Expand All @@ -13,6 +13,7 @@
from secureli.services.scanner import ScanResult, Failure
from secureli.services.updater import UpdateResult
from secureli.settings import Settings
from secureli.shared.models.actions import VerifyOutcome

test_folder_path = Path("does-not-matter")

Expand Down
3 changes: 2 additions & 1 deletion tests/actions/test_scan_action.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path
from secureli.abstractions.pre_commit import RevisionPair
from secureli.actions.action import ActionDependencies, VerifyOutcome
from secureli.actions.action import ActionDependencies
from secureli.actions.scan import ScanAction
from secureli.models.exit_codes import ExitCode
from secureli.models.publish_results import PublishResultsOption
Expand All @@ -25,6 +25,7 @@
import pytest

from secureli.settings import Settings
from secureli.shared.models.actions import VerifyOutcome

test_folder_path = Path("does-not-matter")

Expand Down
2 changes: 1 addition & 1 deletion tests/application/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import pytest
from pytest_mock import MockerFixture
from secureli.actions.action import VerifyOutcome, VerifyResult

import secureli.container
import secureli.main
from secureli.models.publish_results import PublishResultsOption
from secureli.services.scanner import ScanMode
from secureli.shared.models.actions import VerifyOutcome, VerifyResult
from secureli.utilities.secureli_meta import secureli_version


Expand Down
Loading