Simplify TUI extension by generation of resource filter structure and corresponding execute traits. Change-Id: I35fe5c9e568c13cc35183588fe3f7bd4e1c45c72
160 lines
5.9 KiB
Python
160 lines
5.9 KiB
Python
# Licensed 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 typing as ty
|
|
|
|
from codegenerator.types import OperationModel
|
|
from codegenerator.types import OperationTargetParams
|
|
from codegenerator.metadata.base import MetadataBase
|
|
|
|
|
|
class IdentityMetadata(MetadataBase):
|
|
@staticmethod
|
|
def get_operation_key(
|
|
operation, path: str, method: str, resource_name: str
|
|
) -> ty.Tuple[str | None, bool]:
|
|
skip: bool = False
|
|
operation_key: str | None = None
|
|
|
|
if path == "/v3/users/{user_id}/password":
|
|
if method == "post":
|
|
operation_key = "update"
|
|
|
|
if resource_name in [
|
|
"OS_FEDERATION/identity_provider",
|
|
"OS_FEDERATION/identity_provider/protocol",
|
|
"OS_FEDERATION/mapping",
|
|
"OS_FEDERATION/service_provider",
|
|
]:
|
|
if method == "put":
|
|
operation_key = "create"
|
|
elif method == "patch":
|
|
operation_key = "update"
|
|
if (
|
|
resource_name
|
|
in [
|
|
"domain/config",
|
|
"domain/config/group",
|
|
"domain/config/group/option",
|
|
]
|
|
and path.endswith("/default")
|
|
and method == "get"
|
|
):
|
|
operation_key = "default"
|
|
|
|
if (
|
|
resource_name
|
|
in [
|
|
"domain/config",
|
|
"domain/config/group",
|
|
"domain/config/group/option",
|
|
]
|
|
and path.endswith("/default")
|
|
and method == "head"
|
|
):
|
|
# No need in HEAD defaults
|
|
skip = True
|
|
return (operation_key, skip)
|
|
|
|
@staticmethod
|
|
def post_process_operation(
|
|
resource_name: str, operation_name: str, operation
|
|
):
|
|
if resource_name == "role/imply":
|
|
if operation_name == "list":
|
|
operation.targets["rust-cli"].response_key = "role_inference"
|
|
operation.targets["rust-sdk"].response_key = "role_inference"
|
|
if resource_name == "role_inference":
|
|
if operation_name == "list":
|
|
operation.targets["rust-cli"].response_key = "role_inferences"
|
|
operation.targets["rust-sdk"].response_key = "role_inferences"
|
|
|
|
if resource_name == "domain/config/group":
|
|
operation.targets["rust-sdk"].response_key = "config"
|
|
if "rust-cli" in operation.targets:
|
|
operation.targets["rust-cli"].response_key = "config"
|
|
elif resource_name == "domain/config/group/option":
|
|
operation.targets["rust-sdk"].response_key = "config"
|
|
if "rust-cli" in operation.targets:
|
|
operation.targets["rust-cli"].response_key = "config"
|
|
|
|
if "rust-cli" in operation.targets:
|
|
if "OS_FEDERATION" in resource_name:
|
|
operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command = operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command.replace("OS-FEDERATION", "federation")
|
|
if "OS_EP_FILTER" in resource_name:
|
|
operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command = operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command.replace("OS-EP-FILTER", "endpoint-filter")
|
|
elif resource_name == "user/project":
|
|
operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command = "user projects"
|
|
elif resource_name == "user/group":
|
|
operation.targets["rust-cli"].cli_full_command = "user groups"
|
|
elif resource_name == "user/access_rule":
|
|
operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command = operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command.replace("user access-rule", "access-rule")
|
|
elif resource_name == "user/application_credential":
|
|
operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command = operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command.replace(
|
|
"user application-credential", "application-credential"
|
|
)
|
|
|
|
if "/tag" in resource_name:
|
|
if operation_name == "update":
|
|
operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command = operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command.replace("set", "add")
|
|
elif operation_name == "show":
|
|
operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command = operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command.replace("show", "check")
|
|
|
|
if operation_name == "delete_all":
|
|
operation.targets["rust-cli"].cli_full_command = operation.targets[
|
|
"rust-cli"
|
|
].cli_full_command.replace("delete-all", "purge")
|
|
|
|
if resource_name in [
|
|
"auth/project",
|
|
"group",
|
|
"group/user",
|
|
"project",
|
|
"user",
|
|
"user/application_credential",
|
|
]:
|
|
if operation_name in ["list", "delete"]:
|
|
operation.targets.setdefault(
|
|
"rust-tui",
|
|
OperationTargetParams(
|
|
module_name=operation.targets["rust-sdk"].module_name
|
|
),
|
|
)
|
|
return operation
|