Add dns zone/recordset query parameters

Change-Id: I5836232d7ff9ebfa576bfbfe128e77775624c05d
This commit is contained in:
Artem Goncharov 2024-10-04 11:03:05 +02:00
parent e575c6fe7d
commit e7b7cd9474
4 changed files with 329 additions and 57 deletions

@ -109,7 +109,7 @@ class DesignateGenerator(OpenStackServerSourceBase):
elif part in ["post", "post_all"]:
conditions["method"] = ["POST"]
action = "create"
elif part in ["put"]:
elif part in ["put", "put_one"]:
conditions["method"] = ["PUT"]
action = "update"
elif part in ["patch_one"]:
@ -258,6 +258,14 @@ class DesignateGenerator(OpenStackServerSourceBase):
return impl_path
def _post_process_operation_hook(
self, openapi_spec, operation_spec, path: str | None = None
):
"""Hook to allow service specific generator to modify details"""
designate_schemas._post_process_operation_hook(
openapi_spec, operation_spec, path
)
def _get_schema_ref(
self,
openapi_spec,

@ -15,7 +15,44 @@ import copy
from typing import Any
from codegenerator.common.schema import TypeSchema
from codegenerator.common.schema import ParameterSchema
ZONE_TYPES: list[str] = ["PRIMARY", "SECONDARY", "CATALOG"]
ZONE_ACTIONS: list[str] = ["CREATE", "DELETE", "UPDATE", "NONE"]
ZONE_STATUSES: list[str] = [
"ACTIVE",
"PENDING",
"DELETED",
"ERROR",
"SUCCESS",
"ZONE",
]
RECORDSET_TYPES: list[str] = [
"A",
"AAAA",
"CNAME",
"MX",
"SRV",
"TXT",
"SPF",
"NS",
"PTR",
"SSHFP",
"SOA",
"NAPTR",
"CAA",
"CERT",
]
RECORDSET_ACTIONS: list[str] = ["CREATE", "UPDATE", "DELETE", "NONE"]
RECORDSET_STATUSES: list[str] = [
"ACTIVE",
"PENDING",
"DELETED",
"ERROR",
"SUCCESS",
]
ZONE_SCHEMA: dict[str, Any] = {
"type": "object",
@ -60,20 +97,13 @@ ZONE_SCHEMA: dict[str, Any] = {
},
"status": {
"type": ["string", "null"],
"enum": [
"ACTIVE",
"PENDING",
"DELETED",
"ERROR",
"SUCCESS",
"ZONE",
],
"enum": ZONE_STATUSES,
"readOnly": True,
"description": "The status of the resource.",
},
"action": {
"type": ["string", "null"],
"enum": ["CREATE", "DELETE", "UPDATE", "NONE"],
"enum": ZONE_ACTIONS,
"readOnly": True,
"description": "current action in progress on the resource",
},
@ -88,7 +118,7 @@ ZONE_SCHEMA: dict[str, Any] = {
},
"type": {
"type": "string",
"enum": ["PRIMARY", "SECONDARY", "CATALOG"],
"enum": ZONE_TYPES,
"default": "PRIMARY",
"description": "Type of zone. PRIMARY is controlled by Designate, SECONDARY zones are slaved from another DNS Server. Defaults to PRIMARY",
},
@ -137,6 +167,121 @@ ZONES_SCHEMA: dict[str, Any] = {
"additionalProperties": False,
}
ZONES_LIST_PARAMETERS: dict[str, Any] = {
"x-auth-all-projects": {
"in": "header",
"name": "x-auth-all-projects",
"description": "If enabled this will show results from all projects in Designate",
"schema": {"type": "bool"},
},
"x-auth-sudo-project-id": {
"in": "header",
"name": "x-auth-sudo-project-id",
"description": "This allows a user to impersonate another project",
"schema": {"type": "string"},
},
"limit": {
"in": "query",
"name": "limit",
"description": "Requests a page size of items. Returns a number of items up to a limit value. Use the limit parameter to make an initial limited request and use the ID of the last-seen item from the response as the marker parameter value in a subsequent limited request.",
"schema": {"type": "integer"},
},
"marker": {
"in": "query",
"name": "market",
"description": "The ID of the last-seen item. Use the limit parameter to make an initial limited request and use the ID of the last-seen item from the response as the marker parameter value in a subsequent limited request.",
"schema": {"type": "string", "format": "uuid"},
},
"sort_dir": {
"in": "query",
"name": "sort_dir",
"description": "Sorts the response by the requested sort direction. A valid value is asc (ascending) or desc (descending). Default is asc. You can specify multiple pairs of sort key and sort direction query parameters. If you omit the sort direction in a pair, the API uses the natural sorting direction of the server attribute that is provided as the sort_key.",
"schema": {"type": "string", "enum": ["asc", "desc"]},
},
"sort_key": {
"in": "query",
"name": "sort_key",
"description": "Sorts the response by the this attribute value. Default is id. You can specify multiple pairs of sort key and sort direction query parameters. If you omit the sort direction in a pair, the API uses the natural sorting direction of the server attribute that is provided as the sort_key.",
"schema": {
"type": "string",
"enum": [
"created_at",
"id",
"updated_at",
"name",
"tenant_id",
"serial",
"ttl",
"status",
],
},
},
"name": {
"in": "query",
"name": "name",
"description": "Filter results to only show zones that have a name matching the filter",
"schema": {"type": "string"},
},
"description": {
"in": "query",
"name": "description",
"description": "Filter results to only show zones that have a description matching the filter",
"schema": {"type": "string"},
},
"type": {
"in": "query",
"name": "type",
"description": "Filter results to only show zones that have a type matching the filter",
"schema": {"type": "string", "enum": ZONE_TYPES},
},
"email": {
"in": "query",
"name": "email",
"description": "Filter results to only show zones that have an email matching the filter",
"schema": {"type": "string", "format": "email"},
},
"status": {
"in": "query",
"name": "status",
"description": "Filter results to only show zones that have a status matching the filter",
"schema": {"type": "string", "enum": ZONE_STATUSES},
},
"ttl": {
"in": "query",
"name": "ttl",
"description": "Filter results to only show zones that have a ttl matching the filter",
"schema": {"type": "integer"},
},
}
NAMESERVER_SCHEMA: dict[str, Any] = {
"type": "object",
"description": "DNS NAmeserver object",
"properties": {
"hostname": {
"type": "string",
"format": "hostname",
"readOnly": True,
"description": "The hostname of the nameserver that the zone should be delegated to",
},
"priority": {
"type": "integer",
"readOnly": True,
"description": "The priority of the nameserver. This is used to determine the order of the the nameserver listings, and which server is used in the SOA record for the zone.",
},
},
"additionalProperties": False,
}
NAMESERVERS_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {
"nameservers": {"type": "array", "items": NAMESERVER_SCHEMA}
},
"additionalProperties": False,
}
RECORDSET_SCHEMA: dict[str, Any] = {
"type": "object",
"description": "Zone Record object",
@ -164,14 +309,14 @@ RECORDSET_SCHEMA: dict[str, Any] = {
},
"status": {
"type": ["string", "null"],
"enum": ["ACTIVE", "PENDING", "DELETED", "ERROR", "SUCCESS"],
"enum": RECORDSET_STATUSES,
"readOnly": True,
"description": "The status of the resource.",
},
"action": {
"type": ["string", "null"],
"readOnly": True,
"enum": ["CREATE", "UPDATE", "DELETE", "NONE"],
"enum": ZONE_ACTIONS,
"description": "current action in progress on the resource",
},
"description": {
@ -191,22 +336,7 @@ RECORDSET_SCHEMA: dict[str, Any] = {
},
"type": {
"type": "string",
"enum": [
"A",
"AAAA",
"CNAME",
"MX",
"SRV",
"TXT",
"SPF",
"NS",
"PTR",
"SSHFP",
"SOA",
"NAPTR",
"CAA",
"CERT",
],
"enum": RECORDSET_TYPES,
"description": "They RRTYPE of the recordset.",
},
"version": {
@ -237,6 +367,124 @@ RECORDSETS_SCHEMA: dict[str, Any] = {
"additionalProperties": False,
}
RECORDSETS_LIST_PARAMETERS: dict[str, Any] = {
"x-auth-all-projects": {
"in": "header",
"name": "x-auth-all-projects",
"description": "If enabled this will show results from all projects in Designate",
"schema": {"type": "bool"},
},
"x-auth-sudo-project-id": {
"in": "header",
"name": "x-auth-sudo-project-id",
"description": "This allows a user to impersonate another project",
"schema": {"type": "string"},
},
"limit": {
"in": "query",
"name": "limit",
"description": "Requests a page size of items. Returns a number of items up to a limit value. Use the limit parameter to make an initial limited request and use the ID of the last-seen item from the response as the marker parameter value in a subsequent limited request.",
"schema": {"type": "integer"},
},
"marker": {
"in": "query",
"name": "market",
"description": "The ID of the last-seen item. Use the limit parameter to make an initial limited request and use the ID of the last-seen item from the response as the marker parameter value in a subsequent limited request.",
"schema": {"type": "string", "format": "uuid"},
},
"sort_dir": {
"in": "query",
"name": "sort_dir",
"description": "Sorts the response by the requested sort direction. A valid value is asc (ascending) or desc (descending). Default is asc. You can specify multiple pairs of sort key and sort direction query parameters. If you omit the sort direction in a pair, the API uses the natural sorting direction of the server attribute that is provided as the sort_key.",
"schema": {"type": "string", "enum": ["asc", "desc"]},
},
"sort_key": {
"in": "query",
"name": "sort_key",
"description": "Sorts the response by the this attribute value. Default is id. You can specify multiple pairs of sort key and sort direction query parameters. If you omit the sort direction in a pair, the API uses the natural sorting direction of the server attribute that is provided as the sort_key.",
"schema": {
"type": "string",
"enum": [
"created_at",
"id",
"updated_at",
"name",
"zone_id",
"tenant_id",
"name",
"type",
"ttl",
"records",
],
},
},
"zone_id": {
"in": "query",
"name": "zone_id",
"description": "ID of the zone",
"schema": {"type": "string", "format": "uuid"},
},
"name": {
"in": "query",
"name": "name",
"description": "Filter results to only show recordsets that have a name matching the filter",
"schema": {"type": "string"},
},
"description": {
"in": "query",
"name": "description",
"description": "Filter results to only show recordsets that have a description matching the filter",
"schema": {"type": "string"},
},
"type": {
"in": "query",
"name": "type",
"description": "Filter results to only show recordsets that have a type matching the filter",
"schema": {"type": "string", "enum": RECORDSET_TYPES},
},
"status": {
"in": "query",
"name": "status",
"description": "Filter results to only show recordsets that have a status matching the filter",
"schema": {"type": "string", "enum": RECORDSET_STATUSES},
},
"ttl": {
"in": "query",
"name": "ttl",
"description": "Filter results to only show recordsets that have a ttl matching the filter",
"schema": {"type": "integer"},
},
"data": {
"in": "query",
"name": "data",
"description": "Filter results to only show recordsets that have a record with data matching the filter",
"schema": {"type": "string"},
},
}
def _post_process_operation_hook(
openapi_spec, operation_spec, path: str | None = None
):
"""Hook to allow service specific generator to modify details"""
operationId = operation_spec.operationId
if operationId == "zones:get":
for key, val in ZONES_LIST_PARAMETERS.items():
openapi_spec.components.parameters.setdefault(
key, ParameterSchema(**val)
)
ref = f"#/components/parameters/{key}"
if ref not in [x.ref for x in operation_spec.parameters]:
operation_spec.parameters.append(ParameterSchema(ref=ref))
elif operationId == "zones/zone_id/recordsets:get":
for key, val in RECORDSETS_LIST_PARAMETERS.items():
openapi_spec.components.parameters.setdefault(
key, ParameterSchema(**val)
)
ref = f"#/components/parameters/{key}"
if ref not in [x.ref for x in operation_spec.parameters]:
operation_spec.parameters.append(ParameterSchema(ref=ref))
def _get_schema_ref(
openapi_spec, name, description: str | None = None
@ -267,6 +515,11 @@ def _get_schema_ref(
elif name in ["ZonesRecordsetsListResponse", "RecordsetsListResponse"]:
openapi_spec.components.schemas[name] = TypeSchema(**RECORDSETS_SCHEMA)
ref = f"#/components/schemas/{name}"
elif name in ["ZonesNameserversListResponse"]:
openapi_spec.components.schemas[name] = TypeSchema(
**NAMESERVERS_SCHEMA
)
ref = f"#/components/schemas/{name}"
else:
return (None, None, False)

@ -1,6 +1,6 @@
resources:
dns.limit:
spec_file: wrk/openapi_specs/dns/v2.1.yaml
spec_file: wrk/openapi_specs/dns/v2.yaml
api_version: v2
operations:
get:
@ -14,7 +14,7 @@ resources:
sdk_mod_name: get
cli_full_command: limit get
dns.reverse/floatingip:
spec_file: wrk/openapi_specs/dns/v2.1.yaml
spec_file: wrk/openapi_specs/dns/v2.yaml
api_version: v2
operations:
list:
@ -48,7 +48,7 @@ resources:
sdk_mod_name: set
cli_full_command: reverse floatingip set
dns.tld:
spec_file: wrk/openapi_specs/dns/v2.1.yaml
spec_file: wrk/openapi_specs/dns/v2.yaml
api_version: v2
operations:
show:
@ -102,7 +102,7 @@ resources:
sdk_mod_name: create
cli_full_command: tld create
dns.zone:
spec_file: wrk/openapi_specs/dns/v2.1.yaml
spec_file: wrk/openapi_specs/dns/v2.yaml
api_version: v2
operations:
show:
@ -166,10 +166,10 @@ resources:
module_name: find
sdk_mod_path: dns::v2::zone
name_field: name
name_filter_supported: false
name_filter_supported: true
list_mod: list
dns.zone/recordset:
spec_file: wrk/openapi_specs/dns/v2.1.yaml
spec_file: wrk/openapi_specs/dns/v2.yaml
api_version: v2
operations:
show:
@ -183,6 +183,17 @@ resources:
sdk_mod_name: get
find_implemented_by_sdk: true
cli_full_command: zone recordset show
update:
operation_id: zones/zone_id/recordsets/recordset_id:put
operation_type: set
targets:
rust-sdk:
module_name: set
rust-cli:
module_name: set
sdk_mod_name: set
find_implemented_by_sdk: true
cli_full_command: zone recordset set
delete:
operation_id: zones/zone_id/recordsets/recordset_id:delete
operation_type: delete
@ -222,10 +233,10 @@ resources:
module_name: find
sdk_mod_path: dns::v2::zone::recordset
name_field: name
name_filter_supported: false
name_filter_supported: true
list_mod: list
dns.zone/task/transfer_accept:
spec_file: wrk/openapi_specs/dns/v2.1.yaml
spec_file: wrk/openapi_specs/dns/v2.yaml
api_version: v2
operations:
list:
@ -259,7 +270,7 @@ resources:
sdk_mod_name: get
cli_full_command: zone task transfer-accept show
dns.zone/task/transfer_request:
spec_file: wrk/openapi_specs/dns/v2.1.yaml
spec_file: wrk/openapi_specs/dns/v2.yaml
api_version: v2
operations:
show:
@ -313,7 +324,7 @@ resources:
sdk_mod_name: create
cli_full_command: zone task transfer-request create
dns.zone/task:
spec_file: wrk/openapi_specs/dns/v2.1.yaml
spec_file: wrk/openapi_specs/dns/v2.yaml
api_version: v2
operations:
abandon:
@ -347,7 +358,7 @@ resources:
sdk_mod_name: pool_move
cli_full_command: zone task pool-move
dns.zone/task/import:
spec_file: wrk/openapi_specs/dns/v2.1.yaml
spec_file: wrk/openapi_specs/dns/v2.yaml
api_version: v2
operations:
delete:
@ -391,7 +402,7 @@ resources:
sdk_mod_name: get
cli_full_command: zone task import show
dns.zone/task/export:
spec_file: wrk/openapi_specs/dns/v2.1.yaml
spec_file: wrk/openapi_specs/dns/v2.yaml
api_version: v2
operations:
delete:
@ -435,7 +446,7 @@ resources:
sdk_mod_name: create
cli_full_command: zone task export create
dns.zone/task/export/export:
spec_file: wrk/openapi_specs/dns/v2.1.yaml
spec_file: wrk/openapi_specs/dns/v2.yaml
api_version: v2
operations:
get:
@ -449,21 +460,21 @@ resources:
sdk_mod_name: get
cli_full_command: zone task export export get
dns.zone/nameserver:
spec_file: wrk/openapi_specs/dns/v2.1.yaml
spec_file: wrk/openapi_specs/dns/v2.yaml
api_version: v2
operations:
get:
list:
operation_id: zones/zone_id/nameservers:get
operation_type: get
operation_type: list
targets:
rust-sdk:
module_name: get
module_name: list
rust-cli:
module_name: get
sdk_mod_name: get
cli_full_command: zone nameserver get
module_name: list
sdk_mod_name: list
cli_full_command: zone nameserver list
dns.zone/share:
spec_file: wrk/openapi_specs/dns/v2.1.yaml
spec_file: wrk/openapi_specs/dns/v2.yaml
api_version: v2
operations:
show:
@ -507,7 +518,7 @@ resources:
sdk_mod_name: create
cli_full_command: zone share create
dns.blacklist:
spec_file: wrk/openapi_specs/dns/v2.1.yaml
spec_file: wrk/openapi_specs/dns/v2.yaml
api_version: v2
operations:
show:
@ -561,7 +572,7 @@ resources:
sdk_mod_name: create
cli_full_command: blacklist create
dns.pool:
spec_file: wrk/openapi_specs/dns/v2.1.yaml
spec_file: wrk/openapi_specs/dns/v2.yaml
api_version: v2
operations:
show:
@ -615,7 +626,7 @@ resources:
sdk_mod_name: create
cli_full_command: pool create
dns.service_status:
spec_file: wrk/openapi_specs/dns/v2.1.yaml
spec_file: wrk/openapi_specs/dns/v2.yaml
api_version: v2
operations:
list:
@ -639,7 +650,7 @@ resources:
sdk_mod_name: get
cli_full_command: service-status show
dns.tsigkey:
spec_file: wrk/openapi_specs/dns/v2.1.yaml
spec_file: wrk/openapi_specs/dns/v2.yaml
api_version: v2
operations:
show:
@ -693,7 +704,7 @@ resources:
sdk_mod_name: create
cli_full_command: tsigkey create
dns.recordset:
spec_file: wrk/openapi_specs/dns/v2.1.yaml
spec_file: wrk/openapi_specs/dns/v2.yaml
api_version: v2
operations:
list:
@ -717,7 +728,7 @@ resources:
sdk_mod_name: get
cli_full_command: recordset show
dns.quota:
spec_file: wrk/openapi_specs/dns/v2.1.yaml
spec_file: wrk/openapi_specs/dns/v2.yaml
api_version: v2
operations:
show:

@ -9,6 +9,6 @@ target-version = "py38"
# UP: https://docs.astral.sh/ruff/rules/#pyupgrade-up
select = ["C4", "UP"]
[tool.ruff.format]
quote-style = "preserve"
quote-style = "double"
docstring-code-format = true
skip-magic-trailing-comma = true