Skip to content

Commit

Permalink
refactored with merge of previous commit, still some imports need fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
isaac-heist-slalom committed Mar 8, 2024
1 parent 850d462 commit 5bedc2b
Show file tree
Hide file tree
Showing 32 changed files with 437 additions and 495 deletions.
46 changes: 23 additions & 23 deletions secureli/actions/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,15 @@
from secureli.modules.observability.consts.logging import TELEMETRY_DEFAULT_ENDPOINT
from secureli.modules.shared.models.echo import Color
from secureli.modules.shared.models.install import VerifyOutcome, VerifyResult
from secureli.modules.shared.models.language import (
LanguageMetadata,
LanguageNotSupportedError,
)
from secureli.modules.shared.models import language
from secureli.modules.shared.models.scan import ScanMode
from secureli.repositories.secureli_config import (
SecureliConfig,
SecureliConfigRepository,
VerifyConfigOutcome,
)
from secureli.repositories.settings import SecureliRepository, TelemetrySettings
from secureli.modules.language_analyzer.language_analyzer_services.language_analyzer import (
LanguageAnalyzerService,
from secureli.repositories import secureli_config
from secureli.repositories.repo_settings import SecureliRepository, TelemetrySettings
from secureli.modules.language_analyzer.language_analyzer_services import (
language_analyzer,
)
from secureli.modules.language_analyzer.language_analyzer_services.language_support import (
LanguageSupportService,
from secureli.modules.language_analyzer.language_analyzer_services import (
language_support,
)
from secureli.modules.core.core_services.scanner import ScannerService
from secureli.modules.core.core_services.updater import UpdaterService
Expand All @@ -37,10 +30,10 @@ class ActionDependencies:
def __init__(
self,
echo: EchoAbstraction,
language_analyzer: LanguageAnalyzerService,
language_support: LanguageSupportService,
language_analyzer: language_analyzer.LanguageAnalyzerService,
language_support: language_support.LanguageSupportService,
scanner: ScannerService,
secureli_config: SecureliConfigRepository,
secureli_config: secureli_config.SecureliConfigRepository,
settings: SecureliRepository,
updater: UpdaterService,
):
Expand Down Expand Up @@ -69,19 +62,26 @@ def verify_install(
:param always_yes: Assume "Yes" to all prompts
"""

if self.action_deps.secureli_config.verify() == VerifyConfigOutcome.OUT_OF_DATE:
if (
self.action_deps.secureli_config.verify()
== secureli_config.VerifyConfigOutcome.OUT_OF_DATE
):
update_config = self._update_secureli_config_only(always_yes)
if update_config.outcome != VerifyOutcome.UPDATE_SUCCEEDED:
self.action_deps.echo.error(f"seCureLI could not be verified.")
return VerifyResult(
outcome=update_config.outcome,
)

config = SecureliConfig() if reset else self.action_deps.secureli_config.load()
config = (
secureli_config.SecureliConfig()
if reset
else self.action_deps.secureli_config.load()
)

try:
languages = self._detect_languages(folder_path)
except (ValueError, LanguageNotSupportedError) as e:
except (ValueError, language.LanguageNotSupportedError) as e:
if config.languages and config.version_installed:
self.action_deps.echo.warning(
f"Newly detected languages are unsupported by seCureLI"
Expand Down Expand Up @@ -172,7 +172,7 @@ def _install_secureli(
for error_msg in metadata.linter_config_write_errors:
self.action_deps.echo.warning(error_msg)

config = SecureliConfig(
config = secureli_config.SecureliConfig(
languages=detected_languages,
version_installed=metadata.version,
)
Expand Down Expand Up @@ -233,8 +233,8 @@ def _prompt_get_telemetry_api_url(self, always_yes: bool) -> str:
def _run_post_install_scan(
self,
folder_path: Path,
config: SecureliConfig,
metadata: LanguageMetadata,
config: secureli_config.SecureliConfig,
metadata: language.LanguageMetadata,
new_install: bool,
):
"""
Expand Down
4 changes: 1 addition & 3 deletions secureli/actions/build.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from secureli.modules.shared.abstractions.echo import EchoAbstraction, Color
from secureli.modules.observability.observability_services.logging import (
LoggingService,
)
from secureli.modules.observability.observability_services.logging import LoggingService
from secureli.modules.shared.models.logging import LogAction


Expand Down
4 changes: 1 addition & 3 deletions secureli/actions/initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

from secureli.actions.scan import ScanAction
from secureli.actions.action import Action, ActionDependencies
from secureli.modules.observability.observability_services.logging import (
LoggingService,
)
from secureli.modules.observability.observability_services.logging import LoggingService
from secureli.modules.shared.models.install import VerifyResult
from secureli.modules.shared.models.logging import LogAction

Expand Down
26 changes: 8 additions & 18 deletions secureli/actions/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,22 @@
from typing import Optional

from secureli.modules.shared.abstractions.echo import EchoAbstraction
from secureli.actions.action import (
Action,
ActionDependencies,
)
from secureli.actions import action
from secureli.modules.shared.models.exit_codes import ExitCode
from secureli.modules.shared.models.install import VerifyOutcome, VerifyResult
from secureli.modules.shared.models.logging import LogAction
from secureli.modules.shared.models.publish_results import PublishResultsOption
from secureli.modules.shared.models.result import Result
from secureli.modules.observability.observability_services.logging import (
LoggingService,
)
from secureli.modules.core.core_services.scanner import (
ScannerService,
)
from secureli.modules.observability.observability_services.logging import LoggingService
from secureli.modules.core.core_services.scanner import ScannerService
from secureli.modules.shared.models.scan import ScanMode
from secureli.settings import Settings
from secureli.modules.shared.utilities.usage_stats import (
post_log,
convert_failures_to_failure_count,
)
from secureli.modules.shared.utilities import usage_stats

ONE_WEEK_IN_SECONDS: int = 7 * 24 * 60 * 60


class ScanAction(Action):
class ScanAction(action.Action):
"""The action for the secureli `scan` command, orchestrating services and outputs results"""

"""Any verification outcomes that would cause us to not proceed to scan."""
Expand All @@ -41,7 +31,7 @@ class ScanAction(Action):

def __init__(
self,
action_deps: ActionDependencies,
action_deps: action.ActionDependencies,
echo: EchoAbstraction,
logging: LoggingService,
scanner: ScannerService,
Expand Down Expand Up @@ -95,7 +85,7 @@ def publish_results(
publish_results_condition == PublishResultsOption.ON_FAIL
and not action_successful
):
result = post_log(log_str, Settings())
result = usage_stats.post_log(log_str, Settings())
self.echo.debug(result.result_message)

if result.result == Result.SUCCESS:
Expand Down Expand Up @@ -147,7 +137,7 @@ def scan_repo(
[ob.__dict__ for ob in scan_result.failures]
)

individual_failure_count = convert_failures_to_failure_count(
individual_failure_count = usage_stats.convert_failures_to_failure_count(
scan_result.failures
)

Expand Down
4 changes: 1 addition & 3 deletions secureli/actions/setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import jinja2

from secureli.modules.shared.consts.language import (
supported_languages,
)
from secureli.modules.shared.consts.language import supported_languages


class SetupAction:
Expand Down
4 changes: 1 addition & 3 deletions secureli/actions/update.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from typing import Optional
from pathlib import Path
from secureli.modules.shared.abstractions.echo import EchoAbstraction
from secureli.modules.observability.observability_services.logging import (
LoggingService,
)
from secureli.modules.observability.observability_services.logging import LoggingService
from secureli.modules.core.core_services.updater import UpdaterService
from secureli.actions.action import Action, ActionDependencies

Expand Down
27 changes: 9 additions & 18 deletions secureli/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,13 @@
from secureli.actions.update import UpdateAction
from secureli.repositories.repo_files import RepoFilesRepository
from secureli.repositories.secureli_config import SecureliConfigRepository
from secureli.repositories.settings import SecureliRepository
from secureli.repositories.repo_settings import SecureliRepository
from secureli.modules.shared.resources import read_resource
from secureli.modules.language_analyzer.language_analyzer_services.git_ignore import (
GitIgnoreService,
)
from secureli.modules.language_analyzer.language_analyzer_services.language_analyzer import (
LanguageAnalyzerService,
)
from secureli.modules.language_analyzer.language_analyzer_services.language_support import (
LanguageSupportService,
)
from secureli.modules.language_analyzer import language_analyzer_services
from secureli.modules.observability.observability_services.logging import LoggingService
from secureli.modules.core.core_services.scanner import ScannerService
from secureli.modules.core.core_services.updater import UpdaterService
from secureli.modules.secureli_ignore import SecureliIgnoreService
from secureli.modules.language_analyzer.language_analyzer_services.language_config import (
LanguageConfigService,
)
from secureli.settings import Settings


Expand All @@ -50,7 +39,7 @@ class Container(containers.DeclarativeContainer):
)().ignored_file_patterns()

git_ignored_file_patterns = providers.Factory(
GitIgnoreService
language_analyzer_services.git_ignore.GitIgnoreService
)().ignored_file_patterns()

combined_ignored_file_patterns = list(
Expand Down Expand Up @@ -100,18 +89,20 @@ class Container(containers.DeclarativeContainer):
Manages the repository's git ignore file, making sure secureli-managed
files are ignored
"""
git_ignore_service = providers.Factory(GitIgnoreService)
git_ignore_service = providers.Factory(
language_analyzer_services.git_ignore.GitIgnoreService
)

language_config_service = providers.Factory(
LanguageConfigService,
language_analyzer_services.language_config.LanguageConfigService,
data_loader=read_resource,
command_timeout_seconds=config.language_support.command_timeout_seconds,
ignored_file_patterns=secureli_ignored_file_patterns,
)

"""Identifies the configuration version for the language and installs it"""
language_support_service = providers.Factory(
LanguageSupportService,
language_analyzer_services.language_support.LanguageSupportService,
pre_commit_hook=pre_commit_abstraction,
git_ignore=git_ignore_service,
language_config=language_config_service,
Expand All @@ -120,7 +111,7 @@ class Container(containers.DeclarativeContainer):

"""Analyzes a given repo to try to identify the most common language"""
language_analyzer_service = providers.Factory(
LanguageAnalyzerService,
language_analyzer_services.language_analyzer.LanguageAnalyzerService,
repo_files=repo_files_repository,
lexer_guesser=lexer_guesser,
)
Expand Down
2 changes: 1 addition & 1 deletion secureli/modules/core/core_services/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from secureli.modules.shared.abstractions.pre_commit import PreCommitAbstraction
from secureli.modules.shared.models.scan import ScanFailure, ScanMode, ScanResult
from secureli.repositories.settings import PreCommitSettings
from secureli.repositories.repo_settings import PreCommitSettings


class OutputParseErrors(str, Enum):
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from secureli.modules.shared.abstractions.lexer_guesser import LexerGuesser
from secureli.modules.shared.models.language import AnalyzeResult, SkippedFile
from secureli.repositories.repo_files import RepoFilesRepository
from secureli.modules.shared.consts.language import (
supported_languages,
)
from secureli.modules.shared.consts.language import supported_languages


class LanguageAnalyzerService:
Expand Down
Loading

0 comments on commit 5bedc2b

Please sign in to comment.