Repository: Significant-Gravitas/Auto-GPT
File: autogpt_platform/backend/backend/sdk/registry.py (Python)

Code before:

class AutoRegistry:
    """Central registry for all block-related configurations."""

    _lock = threading.Lock()
    _providers: Dict[str, "Provider"] = {}
    _default_credentials: List[Credentials] = []
    _oauth_handlers: Dict[str, Type[BaseOAuthHandler]] = {}
    _oauth_credentials: Dict[str, SDKOAuthCredentials] = {}
    _webhook_managers: Dict[str, Type[BaseWebhooksManager]] = {}
    _block_configurations: Dict[Type[Block], BlockConfiguration] = {}
    _api_key_mappings: Dict[str, str] = {}  # provider -> env_var_name

    @classmethod
    def register_provider(cls, provider: "Provider") -> None:
        """Auto-register provider and all its configurations."""
        with cls._lock:
            cls._providers[provider.name] = provider

            # Register OAuth handler if provided
            if provider.oauth_config:
                oauth_env_vars_set = os.getenv(
                    provider.oauth_config.client_id_env_var
                ) and os.getenv(provider.oauth_config.client_secret_env_var)

                if oauth_env_vars_set:
                    # Dynamically set PROVIDER_NAME if not already set
                    if (
                        not hasattr(
                            provider.oauth_config.oauth_handler, "PROVIDER_NAME"
                        )
                        or provider.oauth_config.oauth_handler.PROVIDER_NAME is None
                    ):
                        # Import ProviderName to create dynamic enum value
                        from backend.integrations.providers import ProviderName

                        # This works because ProviderName has _missing_ method
                        provider.oauth_config.oauth_handler.PROVIDER_NAME = (
                            ProviderName(provider.name)
                        )
                    cls._oauth_handlers[provider.name] = (
                        provider.oauth_config.oauth_handler
                    )

                    oauth_creds = SDKOAuthCredentials(
                        use_secrets=False,  # SDK providers use custom env vars
                        client_id_env_var=provider.oauth_config.client_id_env_var,
                        client_secret_env_var=provider.oauth_config.client_secret_env_var,
                    )
                    cls._oauth_credentials[provider.name] = oauth_creds


Review comment (security):
unnecessary nested `if` can be replaced with one (and avoid the indent change):
```suggestion
            if (
                provider.oauth_config
                and os.getenv(provider.oauth_config.client_id_env_var)
                and os.getenv(provider.oauth_config.client_secret_env_var)
            ):
```

Code after:

class AutoRegistry:
    """Central registry for all block-related configurations."""

    _lock = threading.Lock()
    _providers: Dict[str, "Provider"] = {}
    _default_credentials: List[Credentials] = []
    _oauth_handlers: Dict[str, Type[BaseOAuthHandler]] = {}
    _oauth_credentials: Dict[str, SDKOAuthCredentials] = {}
    _webhook_managers: Dict[str, Type[BaseWebhooksManager]] = {}
    _block_configurations: Dict[Type[Block], BlockConfiguration] = {}
    _api_key_mappings: Dict[str, str] = {}  # provider -> env_var_name

    @classmethod
    def register_provider(cls, provider: "Provider") -> None:
        """Auto-register provider and all its configurations."""
        with cls._lock:
            cls._providers[provider.name] = provider

            # Register OAuth handler if provided
            if provider.oauth_config:
                # Dynamically set PROVIDER_NAME if not already set
                if (
                    not hasattr(provider.oauth_config.oauth_handler, "PROVIDER_NAME")
                    or provider.oauth_config.oauth_handler.PROVIDER_NAME is None
                ):
                    # This works because ProviderName has _missing_ method
                    provider.oauth_config.oauth_handler.PROVIDER_NAME = ProviderName(
                        provider.name
                    )
                cls._oauth_handlers[provider.name] = provider.oauth_config.oauth_handler

                oauth_creds = SDKOAuthCredentials(
                    use_secrets=False,  # SDK providers use custom env vars
                    client_id_env_var=provider.oauth_config.client_id_env_var,
                    client_secret_env_var=provider.oauth_config.client_secret_env_var,
                )
                cls._oauth_credentials[provider.name] = oauth_creds

            # Register webhook manager if provided
            if provider.webhook_manager:
                # Dynamically set PROVIDER_NAME if not already set
                if (
                    not hasattr(provider.webhook_manager, "PROVIDER_NAME")
                    or provider.webhook_manager.PROVIDER_NAME is None
                ):

                    # This works because ProviderName has _missing_ method
                    provider.webhook_manager.PROVIDER_NAME = ProviderName(provider.name)
                cls._webhook_managers[provider.name] = provider.webhook_manager