mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
chore(command): Organize Commands according to SIP-92 (#25850)
This commit is contained in:
@@ -24,13 +24,13 @@ from apispec.exceptions import DuplicateComponentNameError
|
||||
from flask import request, Response
|
||||
from marshmallow import ValidationError
|
||||
|
||||
from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod
|
||||
from superset.key_value.types import JsonKeyValueCodec
|
||||
from superset.temporary_cache.commands.exceptions import (
|
||||
from superset.commands.temporary_cache.exceptions import (
|
||||
TemporaryCacheAccessDeniedError,
|
||||
TemporaryCacheResourceNotFoundError,
|
||||
)
|
||||
from superset.temporary_cache.commands.parameters import CommandParameters
|
||||
from superset.commands.temporary_cache.parameters import CommandParameters
|
||||
from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod
|
||||
from superset.key_value.types import JsonKeyValueCodec
|
||||
from superset.temporary_cache.schemas import (
|
||||
TemporaryCachePostSchema,
|
||||
TemporaryCachePutSchema,
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
@@ -1,45 +0,0 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import logging
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
from superset.commands.base import BaseCommand
|
||||
from superset.temporary_cache.commands.exceptions import TemporaryCacheCreateFailedError
|
||||
from superset.temporary_cache.commands.parameters import CommandParameters
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CreateTemporaryCacheCommand(BaseCommand, ABC):
|
||||
def __init__(self, cmd_params: CommandParameters):
|
||||
self._cmd_params = cmd_params
|
||||
|
||||
def run(self) -> str:
|
||||
try:
|
||||
return self.create(self._cmd_params)
|
||||
except SQLAlchemyError as ex:
|
||||
logger.exception("Error running create command")
|
||||
raise TemporaryCacheCreateFailedError() from ex
|
||||
|
||||
def validate(self) -> None:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def create(self, cmd_params: CommandParameters) -> str:
|
||||
...
|
||||
@@ -1,45 +0,0 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import logging
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
from superset.commands.base import BaseCommand
|
||||
from superset.temporary_cache.commands.exceptions import TemporaryCacheDeleteFailedError
|
||||
from superset.temporary_cache.commands.parameters import CommandParameters
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DeleteTemporaryCacheCommand(BaseCommand, ABC):
|
||||
def __init__(self, cmd_params: CommandParameters):
|
||||
self._cmd_params = cmd_params
|
||||
|
||||
def run(self) -> bool:
|
||||
try:
|
||||
return self.delete(self._cmd_params)
|
||||
except SQLAlchemyError as ex:
|
||||
logger.exception("Error running delete command")
|
||||
raise TemporaryCacheDeleteFailedError() from ex
|
||||
|
||||
def validate(self) -> None:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete(self, cmd_params: CommandParameters) -> bool:
|
||||
...
|
||||
@@ -1,22 +0,0 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from typing import Optional, TypedDict
|
||||
|
||||
|
||||
class Entry(TypedDict):
|
||||
owner: Optional[int]
|
||||
value: str
|
||||
@@ -1,49 +0,0 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from flask_babel import lazy_gettext as _
|
||||
|
||||
from superset.commands.exceptions import (
|
||||
CommandException,
|
||||
CreateFailedError,
|
||||
DeleteFailedError,
|
||||
ForbiddenError,
|
||||
UpdateFailedError,
|
||||
)
|
||||
|
||||
|
||||
class TemporaryCacheCreateFailedError(CreateFailedError):
|
||||
message = _("An error occurred while creating the value.")
|
||||
|
||||
|
||||
class TemporaryCacheGetFailedError(CommandException):
|
||||
message = _("An error occurred while accessing the value.")
|
||||
|
||||
|
||||
class TemporaryCacheDeleteFailedError(DeleteFailedError):
|
||||
message = _("An error occurred while deleting the value.")
|
||||
|
||||
|
||||
class TemporaryCacheUpdateFailedError(UpdateFailedError):
|
||||
message = _("An error occurred while updating the value.")
|
||||
|
||||
|
||||
class TemporaryCacheAccessDeniedError(ForbiddenError):
|
||||
message = _("You don't have permission to modify the value.")
|
||||
|
||||
|
||||
class TemporaryCacheResourceNotFoundError(ForbiddenError):
|
||||
message = _("Resource was not found.")
|
||||
@@ -1,46 +0,0 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import logging
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
from superset.commands.base import BaseCommand
|
||||
from superset.temporary_cache.commands.exceptions import TemporaryCacheGetFailedError
|
||||
from superset.temporary_cache.commands.parameters import CommandParameters
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class GetTemporaryCacheCommand(BaseCommand, ABC):
|
||||
def __init__(self, cmd_params: CommandParameters):
|
||||
self._cmd_params = cmd_params
|
||||
|
||||
def run(self) -> Optional[str]:
|
||||
try:
|
||||
return self.get(self._cmd_params)
|
||||
except SQLAlchemyError as ex:
|
||||
logger.exception("Error running get command")
|
||||
raise TemporaryCacheGetFailedError() from ex
|
||||
|
||||
def validate(self) -> None:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get(self, cmd_params: CommandParameters) -> Optional[str]:
|
||||
...
|
||||
@@ -1,29 +0,0 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional
|
||||
|
||||
from superset.key_value.types import KeyValueCodec
|
||||
|
||||
|
||||
@dataclass
|
||||
class CommandParameters:
|
||||
resource_id: int
|
||||
codec: Optional[KeyValueCodec] = None
|
||||
tab_id: Optional[int] = None
|
||||
key: Optional[str] = None
|
||||
value: Optional[str] = None
|
||||
@@ -1,49 +0,0 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import logging
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
from superset.commands.base import BaseCommand
|
||||
from superset.temporary_cache.commands.exceptions import TemporaryCacheUpdateFailedError
|
||||
from superset.temporary_cache.commands.parameters import CommandParameters
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class UpdateTemporaryCacheCommand(BaseCommand, ABC):
|
||||
def __init__(
|
||||
self,
|
||||
cmd_params: CommandParameters,
|
||||
):
|
||||
self._parameters = cmd_params
|
||||
|
||||
def run(self) -> Optional[str]:
|
||||
try:
|
||||
return self.update(self._parameters)
|
||||
except SQLAlchemyError as ex:
|
||||
logger.exception("Error running update command")
|
||||
raise TemporaryCacheUpdateFailedError() from ex
|
||||
|
||||
def validate(self) -> None:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update(self, cmd_params: CommandParameters) -> Optional[str]:
|
||||
...
|
||||
Reference in New Issue
Block a user