diff --git a/Makefile b/Makefile index 23f7d55..47b924a 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,12 @@ gen-model: fetch-v2-schema datamodel-codegen \ --input v2.json \ - --input-file-type jsonschema \ --collapse-root-models \ - --output-model-type pydantic_v2.BaseModel \ --output neon_client/schema.py \ --use-standard-collections \ - --output-model-type pydantic_v2.BaseModel \ - --input-file-type openapi \ - # --use-standard-collections \ + --output-model-type dataclasses.dataclass \ + # --input-file-type openapi \ + --use-standard-collections \ --use-union-operator \ --target-python-version 3.11 \ --use-schema-description \ @@ -18,17 +16,26 @@ gen-model: fetch-v2-schema --allow-population-by-field-name \ --use-title-as-name \ --reuse-model \ - --field-constraints \ + --collapse-root-models \ + # --field-constraints \ --disable-appending-item-suffix \ --allow-extra-fields \ --capitalise-enum-members \ + --allow-extra-fields \ + --use-field-description \ + --use-default \ + --use-enum-values \ + --reuse-model \ --use-unique-items-as-set \ --set-default-enum-member \ --enum-field-as-literal one \ + --allow-extra-fields \ --openapi-scopes {schemas,paths,tags,parameters} \ --use-operation-id-as-name \ + --strict-nullable \ + --keep-model-order \ + --field-constraints \ - # --field-constraints \ # --use-annotated \ diff --git a/Pipfile b/Pipfile index c51fc2b..d260379 100644 --- a/Pipfile +++ b/Pipfile @@ -5,6 +5,7 @@ name = "pypi" [packages] requests = "*" +pytest = "*" [dev-packages] neon-client = {file = ".", editable = true} diff --git a/Pipfile.lock b/Pipfile.lock index b3d1efd..f5c21fc 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "772851b6661af11cfdfc63062de6b894ea1b3f849eec2e665b8fd97be81ac72c" + "sha256": "ad05855f463975a7c461165b1f6a61f09782a791c2ded66bf623cd81af3f8f44" }, "pipfile-spec": 6, "requires": { @@ -128,6 +128,39 @@ "markers": "python_version >= '3.5'", "version": "==3.6" }, + "iniconfig": { + "hashes": [ + "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3", + "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374" + ], + "markers": "python_version >= '3.7'", + "version": "==2.0.0" + }, + "packaging": { + "hashes": [ + "sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5", + "sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7" + ], + "markers": "python_version >= '3.7'", + "version": "==23.2" + }, + "pluggy": { + "hashes": [ + "sha256:cf61ae8f126ac6f7c451172cf30e3e43d3ca77615509771b3a984a0730651e12", + "sha256:d89c696a773f8bd377d18e5ecda92b7a3793cbe66c87060a6fb58c7b6e1061f7" + ], + "markers": "python_version >= '3.8'", + "version": "==1.3.0" + }, + "pytest": { + "hashes": [ + "sha256:2cf0005922c6ace4a3e2ec8b4080eb0d9753fdc93107415332f50ce9e7994280", + "sha256:b090cdf5ed60bf4c45261be03239c2c1c22df034fbffe691abe93cd80cea01d8" + ], + "index": "pypi", + "markers": "python_version >= '3.7'", + "version": "==7.4.4" + }, "requests": { "hashes": [ "sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f", diff --git a/neon_client/client.py b/neon_client/client.py index 2112475..2185752 100644 --- a/neon_client/client.py +++ b/neon_client/client.py @@ -2,6 +2,7 @@ import os import typing as t import requests +from pydantic import ValidationError from . import schema from .utils import compact_mapping @@ -12,6 +13,7 @@ __VERSION__ = "0.1.0" NEON_API_KEY_ENVIRON = "NEON_API_KEY" NEON_API_BASE_URL = "https://console.neon.tech/api/v2/" +ENABLE_PYDANTIC = True def returns_model(model, is_array=False): @@ -19,10 +21,28 @@ def returns_model(model, is_array=False): def decorator(func): def wrapper(*args, **kwargs): + if not ENABLE_PYDANTIC: + return func(*args, **kwargs) + if is_array: - return [model.model_construct(**item) for item in func(*args, **kwargs)] + return [model(**item) for item in func(*args, **kwargs)] else: - return model.model_construct(**func(*args, **kwargs)) + return model(**func(*args, **kwargs)) + + return wrapper + + return decorator + + +def returns_subkey(key): + """Decorator that returns a subkey.""" + + def decorator(func): + def wrapper(*args, **kwargs): + try: + return getattr(func(*args, **kwargs), key) + except AttributeError: + return func(*args, **kwargs)[key] return wrapper @@ -82,7 +102,7 @@ class NeonAPI: @classmethod def from_environ(cls): - """Create a new Neon API client from the NEON_API_KEY environment variable.""" + """Create a new Neon API client from the `NEON_API_KEY` environment variable.""" return cls(os.environ[NEON_API_KEY_ENVIRON]) @@ -103,9 +123,14 @@ class NeonAPI: @returns_model(schema.ApiKeyRevokeResponse) def api_key_revoke(self, api_key_id: str) -> t.Dict[str, t.Any]: - """Revoke an API key.""" + """Revoke an API key. + + :param api_key_id: The ID of the API key to revoke. + :return: A dictionary representing the API key. + """ return self.request("DELETE", f"api_keys/{ api_key_id }") + # @returns_subkey("projects") @returns_model(schema.ProjectsResponse) def projects( self, diff --git a/neon_client/schema.py b/neon_client/schema.py index a5829c9..bce594c 100644 --- a/neon_client/schema.py +++ b/neon_client/schema.py @@ -1,23 +1,12 @@ # generated by datamodel-codegen: # filename: v2.json -# timestamp: 2024-01-17T17:45:44+00:00 +# timestamp: 2024-01-22T21:10:29+00:00 from __future__ import annotations +from pydantic.dataclasses import dataclass from enum import Enum from typing import Optional -from uuid import UUID - -from pydantic import ( - AwareDatetime, - BaseModel, - ConfigDict, - Field, - RootModel, - confloat, - conint, - constr, -) class Provisioner(Enum): @@ -25,59 +14,45 @@ class Provisioner(Enum): k8s_neonvm = "k8s-neonvm" -class Pagination(BaseModel): - cursor: constr(min_length=1) +@dataclass +class Pagination: + cursor: str -class EmptyResponse(BaseModel): +@dataclass +class EmptyResponse: pass -class ApiKeyCreateRequest(BaseModel): - key_name: str = Field( - ..., - description="A user-specified API key name. This value is required when creating an API key.", - ) +@dataclass +class ApiKeyCreateRequest: + key_name: str -class ApiKeyCreateResponse(BaseModel): - id: int = Field(..., description="The API key ID") - key: str = Field( - ..., description="The generated 64-bit token required to access the Neon API" - ) - name: str = Field(..., description="The user-specified API key name") - created_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the API key was created" - ) +@dataclass +class ApiKeyCreateResponse: + id: int + key: str + name: str + created_at: str -class ApiKeyRevokeResponse(BaseModel): - id: int = Field(..., description="The API key ID") - name: str = Field(..., description="The user-specified API key name") - revoked: bool = Field( - ..., - description="A `true` or `false` value indicating whether the API key is revoked", - ) - last_used_at: Optional[AwareDatetime] = Field( - None, description="A timestamp indicating when the API was last used" - ) - last_used_from_addr: str = Field( - ..., description="The IP address from which the API key was last used" - ) +@dataclass +class ApiKeyRevokeResponse: + id: int + name: str + revoked: bool + last_used_from_addr: str + last_used_at: Optional[str] = None -class ApiKeysListResponseItem(BaseModel): - id: int = Field(..., description="The API key ID") - name: str = Field(..., description="The user-specified API key name") - created_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the API key was created" - ) - last_used_at: Optional[AwareDatetime] = Field( - None, description="A timestamp indicating when the API was last used" - ) - last_used_from_addr: str = Field( - ..., description="The IP address from which the API key was last used" - ) +@dataclass +class ApiKeysListResponseItem: + id: int + name: str + created_at: str + last_used_from_addr: str + last_used_at: Optional[str] = None class OperationAction(Enum): @@ -105,90 +80,55 @@ class OperationStatus(Enum): scheduling = "scheduling" -class BranchUpdateItem(BaseModel): - name: Optional[str] = Field( - None, - description="The branch name. If not specified, the default branch name will be used.\n", - ) - role_name: Optional[str] = Field( - None, - description="The role name. If not specified, the default role name will be used.\n", - ) - database_name: Optional[str] = Field( - None, - description="The database name. If not specified, the default database name will be used.\n", - ) +@dataclass +class Branch: + name: Optional[str] = None + role_name: Optional[str] = None + database_name: Optional[str] = None -class ProjectConsumption(BaseModel): - project_id: str = Field(..., description="The project ID") - period_id: UUID = Field( - ..., - description="The Id of the consumption period, used to reference the `previous_period_id` field.\n", - ) - data_storage_bytes_hour: conint(ge=0) = Field( - ..., - description="Bytes-Hour. The amount of storage the project consumed during the billing period. Expect some lag in the reported value.\nThe value is reset at the beginning of each billing period.\n", - ) - data_storage_bytes_hour_updated_at: Optional[AwareDatetime] = Field( - None, - description="The timestamp of the last update of the `data_storage_bytes_hour` field.\n", - ) - synthetic_storage_size: conint(ge=0) = Field( - ..., - description="Bytes. The current space occupied by project in storage. Expect some lag in the reported value.\n", - ) - synthetic_storage_size_updated_at: Optional[AwareDatetime] = Field( - None, - description="The timestamp of the last update of the `synthetic_storage_size` field.\n", - ) - data_transfer_bytes: conint(ge=0) = Field( - ..., - description="Bytes. The egress traffic from the Neon cloud to the client for the project over the billing period.\nIncludes egress traffic for deleted endpoints. Expect some lag in the reported value. The value is reset at the beginning of each billing period.\n", - ) - data_transfer_bytes_updated_at: Optional[AwareDatetime] = Field( - None, - description="Timestamp of the last update of `data_transfer_bytes` field\n", - ) - written_data_bytes: conint(ge=0) = Field( - ..., - description="Bytes. The Amount of WAL that travelled through storage for given project for all branches.\nExpect some lag in the reported value. The value is reset at the beginning of each billing period.\n", - ) - written_data_bytes_updated_at: Optional[AwareDatetime] = Field( - None, - description="The timestamp of the last update of `written_data_bytes` field.\n", - ) - compute_time_seconds: conint(ge=0) = Field( - ..., - description="Seconds. The number of CPU seconds used by the project's compute endpoints, including compute endpoints that have been deleted.\nExpect some lag in the reported value. The value is reset at the beginning of each billing period.\nExamples:\n1. An endpoint that uses 1 CPU for 1 second is equal to `compute_time=1`.\n2. An endpoint that uses 2 CPUs simultaneously for 1 second is equal to `compute_time=2`.\n", - ) - compute_time_seconds_updated_at: Optional[AwareDatetime] = Field( - None, - description="The timestamp of the last update of `compute_time_seconds` field.\n", - ) - active_time_seconds: conint(ge=0) = Field( - ..., - description="Seconds. The amount of time that compute endpoints in this project have been active.\nExpect some lag in the reported value.\n\nThe value is reset at the beginning of each billing period.\n", - ) - active_time_seconds_updated_at: Optional[AwareDatetime] = Field( - None, - description="The timestamp of the last update of the `active_time_seconds` field.\n", - ) - updated_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the period was last updated.\n" - ) - period_start: AwareDatetime = Field( - ..., description="The start of the consumption period.\n" - ) - period_end: AwareDatetime = Field( - ..., description="The end of the consumption period.\n" - ) - previous_period_id: UUID = Field( - ..., description="The `period_id` of the previous consumption period.\n" - ) +@dataclass +class ProjectPermission: + id: str + granted_to_email: str + granted_at: str + revoked_at: Optional[str] = None -class Limits(BaseModel): +@dataclass +class ProjectPermissions: + project_permissions: list[ProjectPermission] + + +@dataclass +class GrantPermissionToProjectRequest: + email: str + + +@dataclass +class ProjectConsumption: + project_id: str + period_id: str + data_storage_bytes_hour: int + synthetic_storage_size: int + data_transfer_bytes: int + written_data_bytes: int + compute_time_seconds: int + active_time_seconds: int + updated_at: str + period_start: str + period_end: str + previous_period_id: str + data_storage_bytes_hour_updated_at: Optional[str] = None + synthetic_storage_size_updated_at: Optional[str] = None + data_transfer_bytes_updated_at: Optional[str] = None + written_data_bytes_updated_at: Optional[str] = None + compute_time_seconds_updated_at: Optional[str] = None + active_time_seconds_updated_at: Optional[str] = None + + +@dataclass +class Limits: active_time: int max_projects: int max_branches: int @@ -199,10 +139,8 @@ class Limits(BaseModel): max_allowed_ips: int -class ProjectLimits(BaseModel): - model_config = ConfigDict( - extra="allow", - ) +@dataclass +class ProjectLimits: limits: Limits @@ -211,43 +149,36 @@ class BranchState(Enum): ready = "ready" -class Branch2(BaseModel): - parent_id: Optional[str] = Field( - None, - description="The `branch_id` of the parent branch. If omitted or empty, the branch will be created from the project's primary branch.\n", - ) - name: Optional[str] = Field(None, description="The branch name\n") - parent_lsn: Optional[str] = Field( - None, - description="A Log Sequence Number (LSN) on the parent branch. The branch will be created with data from this LSN.\n", - ) - parent_timestamp: Optional[AwareDatetime] = Field( - None, - description="A timestamp identifying a point in time on the parent branch. The branch will be created with data starting from this point in time.\n", - ) +@dataclass +class Branch2: + parent_id: Optional[str] = None + name: Optional[str] = None + parent_lsn: Optional[str] = None + parent_timestamp: Optional[str] = None -class Branch3(BaseModel): +@dataclass +class Branch3: name: Optional[str] = None -class BranchUpdateRequest(BaseModel): +@dataclass +class BranchUpdateRequest: branch: Branch3 -class ConnectionParameters(BaseModel): - database: str = Field(..., description="Database name.\n") - password: str = Field(..., description="Password for the role.\n") - role: str = Field(..., description="Role name.\n") - host: str = Field(..., description="Host name.\n") - pooler_host: str = Field(..., description="Pooler host name.\n") +@dataclass +class ConnectionParameters: + database: str + password: str + role: str + host: str + pooler_host: str -class ConnectionDetails(BaseModel): - connection_uri: str = Field( - ..., - description="Connection URI is same as specified in https://www.postgresql.org/docs/current/libpq-connect.html#id-1.7.3.8.3.6\nIt is a ready to use string for psql or for DATABASE_URL environment variable.\n", - ) +@dataclass +class ConnectionDetails: + connection_uri: str connection_parameters: ConnectionParameters @@ -266,82 +197,75 @@ class EndpointPoolerMode(Enum): transaction = "transaction" -class AllowedIps(BaseModel): - ips: list[str] = Field( - ..., - description="A list of IP addresses that are allowed to connect to the endpoint.", - ) - primary_branch_only: bool = Field( - ..., description="If true, the list will be applied only to the primary branch." - ) +@dataclass +class AllowedIps: + primary_branch_only: bool + ips: Optional[list[str]] = None -class ConnectionURIsResponse(BaseModel): +@dataclass +class ConnectionURIsResponse: connection_uris: list[ConnectionDetails] -class ConnectionURIsOptionalResponse(BaseModel): +@dataclass +class ConnectionURIsOptionalResponse: connection_uris: Optional[list[ConnectionDetails]] = None -class EndpointPasswordlessSessionAuthRequest(BaseModel): +@dataclass +class EndpointPasswordlessSessionAuthRequest: session_id: str -class Duration(RootModel[int]): - root: int = Field( - ..., - description="A Duration represents the elapsed time between two instants\nas an int64 nanosecond count. The representation limits the\nlargest representable duration to approximately 290 years.", - ) +Duration = int -class StatementData(BaseModel): +@dataclass +class StatementData: + truncated: bool fields: Optional[list[str]] = None rows: Optional[list[list[str]]] = None - truncated: bool -class ExplainData(BaseModel): - QUERY_PLAN: str = Field(..., alias="QUERY PLAN") +@dataclass +class ExplainData: + QUERY_PLAN: str -class Role(BaseModel): - branch_id: str = Field( - ..., description="The ID of the branch to which the role belongs\n" - ) - name: str = Field(..., description="The role name\n") - password: Optional[str] = Field(None, description="The role password\n") - protected: Optional[bool] = Field( - None, description="Whether or not the role is system-protected\n" - ) - created_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the role was created\n" - ) - updated_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the role was last updated\n" - ) +@dataclass +class Role: + branch_id: str + name: str + created_at: str + updated_at: str + password: Optional[str] = None + protected: Optional[bool] = None -class Role1(BaseModel): - name: str = Field( - ..., description="The role name. Cannot exceed 63 bytes in length.\n" - ) +@dataclass +class Role1: + name: str -class RoleCreateRequest(BaseModel): +@dataclass +class RoleCreateRequest: role: Role1 -class RoleResponse(BaseModel): +@dataclass +class RoleResponse: role: Role -class RolesResponse(BaseModel): +@dataclass +class RolesResponse: roles: list[Role] -class RolePasswordResponse(BaseModel): - password: str = Field(..., description="The role password\n") +@dataclass +class RolePasswordResponse: + password: str class Brand(Enum): @@ -355,27 +279,28 @@ class Brand(Enum): visa = "visa" -class PaymentSourceBankCard(BaseModel): - last4: str = Field(..., description="Last 4 digits of the card.\n") - brand: Optional[Brand] = Field(None, description="Brand of credit card.\n") - exp_month: Optional[int] = Field(None, description="Credit card expiration month\n") - exp_year: Optional[int] = Field(None, description="Credit card expiration year\n") +@dataclass +class PaymentSourceBankCard: + last4: str + brand: Optional[Brand] = None + exp_month: Optional[int] = None + exp_year: Optional[int] = None -class PaymentSource(BaseModel): - type: str = Field(..., description='Type of payment source. E.g. "card".\n') +@dataclass +class PaymentSource: + type: str card: Optional[PaymentSourceBankCard] = None -class BillingAccountUpdateItem(BaseModel): - email: Optional[str] = Field( - None, - description="Billing email, to receive emails related to invoices and subscriptions.\n", - ) +@dataclass +class BillingAccount1: + email: Optional[str] = None -class BillingAccountUpdateRequest(BaseModel): - billing_account: BillingAccountUpdateItem +@dataclass +class BillingAccountUpdateRequest: + billing_account: BillingAccount1 class BillingSubscriptionType(Enum): @@ -386,54 +311,50 @@ class BillingSubscriptionType(Enum): aws_marketplace = "aws_marketplace" -class Database(BaseModel): - id: int = Field(..., description="The database ID\n") - branch_id: str = Field( - ..., description="The ID of the branch to which the database belongs\n" - ) - name: str = Field(..., description="The database name\n") - owner_name: str = Field( - ..., description="The name of role that owns the database\n" - ) - created_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the database was created\n" - ) - updated_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the database was last updated\n" - ) +@dataclass +class Database: + id: int + branch_id: str + name: str + owner_name: str + created_at: str + updated_at: str -class DatabaseCreateItem(BaseModel): - name: str = Field(..., description="The name of the datbase\n") - owner_name: str = Field( - ..., description="The name of the role that owns the database\n" - ) +@dataclass +class Database1: + name: str + owner_name: str -class DatabaseCreateRequest(BaseModel): - database: DatabaseCreateItem +@dataclass +class DatabaseCreateRequest: + database: Database1 -class DatabaseUpdateItem(BaseModel): - name: Optional[str] = Field(None, description="The name of the database\n") - owner_name: Optional[str] = Field( - None, description="The name of the role that owns the database\n" - ) +@dataclass +class Database2: + name: Optional[str] = None + owner_name: Optional[str] = None -class DatabaseUpdateRequest(BaseModel): - database: DatabaseUpdateItem +@dataclass +class DatabaseUpdateRequest: + database: Database2 -class DatabaseResponse(BaseModel): +@dataclass +class DatabaseResponse: database: Database -class DatabasesResponse(BaseModel): +@dataclass +class DatabasesResponse: databases: list[Database] -class CurrentUserAuthAccount(BaseModel): +@dataclass +class CurrentUserAuthAccount: email: str image: str login: str @@ -441,46 +362,41 @@ class CurrentUserAuthAccount(BaseModel): provider: str -class UpdateUserInfoRequest(BaseModel): +@dataclass +class UpdateUserInfoRequest: email: str - id: UUID + id: str image: Optional[str] = None first_name: Optional[str] = None last_name: Optional[str] = None -class ProjectQuota(BaseModel): - active_time_seconds: Optional[conint(ge=0)] = Field( - None, - description="The total amount of wall-clock time allowed to be spent by the project's compute endpoints.\n", - ) - compute_time_seconds: Optional[conint(ge=0)] = Field( - None, - description="The total amount of CPU seconds allowed to be spent by the project's compute endpoints.\n", - ) - written_data_bytes: Optional[conint(ge=0)] = Field( - None, - description="Total amount of data written to all of a project's branches.\n", - ) - data_transfer_bytes: Optional[conint(ge=0)] = Field( - None, - description="Total amount of data transferred from all of a project's branches using the proxy.\n", - ) - logical_size_bytes: Optional[conint(ge=0)] = Field( - None, description="Limit on the logical size of every project's branch.\n" - ) +@dataclass +class ProjectQuota: + active_time_seconds: Optional[int] = None + compute_time_seconds: Optional[int] = None + written_data_bytes: Optional[int] = None + data_transfer_bytes: Optional[int] = None + logical_size_bytes: Optional[int] = None -class HealthCheck(BaseModel): - status: str = Field(..., description="Service status") +@dataclass +class HealthCheck: + status: str -class ProjectOwnerData(BaseModel): +@dataclass +class ProjectOwnerData: email: str branches_limit: int subscription_type: BillingSubscriptionType +class SubscriptionDowngradeNewType(Enum): + free = "free" + free_v2 = "free_v2" + + class SupportTicketSeverity(Enum): low = "low" normal = "normal" @@ -488,172 +404,134 @@ class SupportTicketSeverity(Enum): critical = "critical" -class PaginationResponse(BaseModel): +class SubscriptionUpgradeNewType(Enum): + launch = "launch" + scale = "scale" + + +@dataclass +class PaginationResponse: pagination: Optional[Pagination] = None -class Operation(BaseModel): - id: UUID = Field(..., description="The operation ID") - project_id: str = Field(..., description="The Neon project ID") - branch_id: Optional[str] = Field(None, description="The branch ID") - endpoint_id: Optional[str] = Field(None, description="The endpoint ID") +@dataclass +class Operation: + id: str + project_id: str action: OperationAction status: OperationStatus - error: Optional[str] = Field(None, description="The error that occured") - failures_count: int = Field( - ..., description="The number of times the operation failed" - ) - retry_at: Optional[AwareDatetime] = Field( - None, description="A timestamp indicating when the operation was last retried" - ) - created_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the operation was created" - ) - updated_at: AwareDatetime = Field( - ..., - description="A timestamp indicating when the operation status was last updated", - ) - total_duration_ms: int = Field( - ..., description="The total duration of the operation in milliseconds" - ) + failures_count: int + created_at: str + updated_at: str + total_duration_ms: int + branch_id: Optional[str] = None + endpoint_id: Optional[str] = None + error: Optional[str] = None + retry_at: Optional[str] = None -class OperationResponse(BaseModel): +@dataclass +class OperationResponse: operation: Operation -class OperationsResponse(BaseModel): +@dataclass +class OperationsResponse: operations: list[Operation] -class ProjectSettingsData(BaseModel): +@dataclass +class ProjectSettingsData: quota: Optional[ProjectQuota] = None allowed_ips: Optional[AllowedIps] = None - enable_logical_replication: Optional[bool] = Field( - None, - description="Sets wal_level=logical for all compute endpoints in this project.\nAll active endpoints will be suspended.\nOnce enabled, logical replication cannot be disabled.\n", - ) + enable_logical_replication: Optional[bool] = None -class ProjectsConsumptionResponse(BaseModel): +@dataclass +class ProjectsConsumptionResponse: projects: list[ProjectConsumption] periods_in_response: int -class Branch(BaseModel): - id: str = Field( - ..., - description="The branch ID. This value is generated when a branch is created. A `branch_id` value has a `br` prefix. For example: `br-small-term-683261`.\n", - ) - project_id: str = Field( - ..., description="The ID of the project to which the branch belongs\n" - ) - parent_id: Optional[str] = Field( - None, description="The `branch_id` of the parent branch\n" - ) - parent_lsn: Optional[str] = Field( - None, - description="The Log Sequence Number (LSN) on the parent branch from which this branch was created\n", - ) - parent_timestamp: Optional[AwareDatetime] = Field( - None, - description="The point in time on the parent branch from which this branch was created\n", - ) - name: str = Field(..., description="The branch name\n") +@dataclass +class Branch1: + id: str + project_id: str + name: str current_state: BranchState - pending_state: Optional[BranchState] = None - logical_size: Optional[int] = Field( - None, description="The logical size of the branch, in bytes\n" - ) - creation_source: str = Field(..., description="The branch creation source\n") - primary: bool = Field( - ..., description="Whether the branch is the project's primary branch\n" - ) - cpu_used_sec: int = Field( - ..., - description="CPU seconds used by all the endpoints of the branch, including deleted ones.\nThis value is reset at the beginning of each billing period.\nExamples:\n1. A branch that uses 1 CPU for 1 second is equal to `cpu_used_sec=1`.\n2. A branch that uses 2 CPUs simultaneously for 1 second is equal to `cpu_used_sec=2`.\n", - ) + creation_source: str + primary: bool + cpu_used_sec: int compute_time_seconds: int active_time_seconds: int written_data_bytes: int data_transfer_bytes: int - created_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the branch was created\n" - ) - updated_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the branch was last updated\n" - ) - last_reset_at: Optional[AwareDatetime] = Field( - None, description="A timestamp indicating when the branch was last reset\n" - ) + created_at: str + updated_at: str + parent_id: Optional[str] = None + parent_lsn: Optional[str] = None + parent_timestamp: Optional[str] = None + pending_state: Optional[BranchState] = None + logical_size: Optional[int] = None + last_reset_at: Optional[str] = None -class BranchCreateRequestEndpointOptions(BaseModel): +@dataclass +class BranchCreateRequestEndpointOptions: type: EndpointType - autoscaling_limit_min_cu: Optional[confloat()] = Field( - None, - description="The minimum number of Compute Units. The minimum value is `0.25`.\n See [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\n for more information.\n", - ) - autoscaling_limit_max_cu: Optional[confloat()] = Field( - None, - description="The maximum number of Compute Units.\n See [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\n for more information.\n", - ) + autoscaling_limit_min_cu: Optional[float] = None + autoscaling_limit_max_cu: Optional[float] = None provisioner: Optional[Provisioner] = None - suspend_timeout_seconds: Optional[conint(ge=-1, le=604800)] = Field( - None, - description="Duration of inactivity in seconds after which the compute endpoint is\nautomatically suspended. The value `0` means use the global default.\nThe value `-1` means never suspend. The default value is `300` seconds (5 minutes).\nThe maximum value is `604800` seconds (1 week). For more information, see\n[Auto-suspend configuration](https://neon.tech/docs/manage/endpoints#auto-suspend-configuration).\n", - ) + suspend_timeout_seconds: Optional[int] = None -class BranchCreateRequest(BaseModel): +@dataclass +class BranchCreateRequest: endpoints: Optional[list[BranchCreateRequestEndpointOptions]] = None branch: Optional[Branch2] = None -class BranchResponse(BaseModel): - branch: Branch +@dataclass +class BranchResponse: + branch: Branch1 -class BranchesResponse(BaseModel): - branches: list[Branch] +@dataclass +class BranchesResponse: + branches: list[Branch1] -class StatementResult(BaseModel): +@dataclass +class StatementResult: + query: str data: Optional[StatementData] = None error: Optional[str] = None explain_data: Optional[list[ExplainData]] = None - query: str -class BillingAccount(BaseModel): +@dataclass +class BillingAccount: payment_source: PaymentSource subscription_type: BillingSubscriptionType - quota_reset_at_last: AwareDatetime = Field( - ..., - description="The last time the quota was reset. Defaults to the date-time the account is created.\n", - ) - email: str = Field( - ..., - description="Billing email, to receive emails related to invoices and subscriptions.\n", - ) - address_city: str = Field(..., description="Billing address city.\n") - address_country: str = Field(..., description="Billing address country.\n") - address_line1: str = Field(..., description="Billing address line 1.\n") - address_line2: str = Field(..., description="Billing address line 2.\n") - address_postal_code: str = Field(..., description="Billing address postal code.\n") - address_state: str = Field(..., description="Billing address state or region.\n") - orb_portal_url: Optional[str] = Field(None, description="Orb user portal url\n") + quota_reset_at_last: str + email: str + address_city: str + address_country: str + address_line1: str + address_line2: str + address_postal_code: str + address_state: str + orb_portal_url: Optional[str] = None -class BillingAccountResponse(BaseModel): +@dataclass +class BillingAccountResponse: billing_account: BillingAccount -class CurrentUserInfoResponse(BaseModel): - active_seconds_limit: int = Field( - ..., - description="Control plane observes active endpoints of a user this amount of wall-clock time.\n", - ) +@dataclass +class CurrentUserInfoResponse: + active_seconds_limit: int billing_account: BillingAccount auth_accounts: list[CurrentUserAuthAccount] email: str @@ -664,414 +542,226 @@ class CurrentUserInfoResponse(BaseModel): last_name: str projects_limit: int branches_limit: int - max_autoscaling_limit: confloat() - compute_seconds_limit: Optional[int] = None + max_autoscaling_limit: float plan: str + compute_seconds_limit: Optional[int] = None -class EndpointSettingsData(BaseModel): +@dataclass +class EndpointSettingsData: pg_settings: Optional[dict[str, str]] = None pgbouncer_settings: Optional[dict[str, str]] = None -class DefaultEndpointSettings(BaseModel): +@dataclass +class DefaultEndpointSettings: pg_settings: Optional[dict[str, str]] = None pgbouncer_settings: Optional[dict[str, str]] = None - autoscaling_limit_min_cu: Optional[confloat()] = Field( - None, - description="The minimum number of Compute Units. The minimum value is `0.25`.\nSee [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", - ) - autoscaling_limit_max_cu: Optional[confloat()] = Field( - None, - description="The maximum number of Compute Units. See [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", - ) - suspend_timeout_seconds: Optional[conint(ge=-1, le=604800)] = Field( - None, - description="Duration of inactivity in seconds after which the compute endpoint is\nautomatically suspended. The value `0` means use the global default.\nThe value `-1` means never suspend. The default value is `300` seconds (5 minutes).\nThe maximum value is `604800` seconds (1 week). For more information, see\n[Auto-suspend configuration](https://neon.tech/docs/manage/endpoints#auto-suspend-configuration).\n", - ) + autoscaling_limit_min_cu: Optional[float] = None + autoscaling_limit_max_cu: Optional[float] = None + suspend_timeout_seconds: Optional[int] = None -class GeneralError(BaseModel): +@dataclass +class GeneralError: code: str - message: str = Field(..., description="Error message") + message: str +@dataclass class BranchOperations(BranchResponse, OperationsResponse): pass +@dataclass class DatabaseOperations(DatabaseResponse, OperationsResponse): pass +@dataclass class RoleOperations(RoleResponse, OperationsResponse): pass -class ProjectListItem(BaseModel): - id: str = Field(..., description="The project ID\n") - platform_id: str = Field( - ..., - description="The cloud platform identifier. Currently, only AWS is supported, for which the identifier is `aws`.\n", - ) - region_id: str = Field(..., description="The region identifier\n") - name: str = Field(..., description="The project name\n") - provisioner: Optional[Provisioner] - default_endpoint_settings: Optional[DefaultEndpointSettings] = None - settings: Optional[ProjectSettingsData] = None - pg_version: conint(ge=14, le=16) = Field( - ..., - description="The major PostgreSQL version number. Currently supported versions are `14`, `15` and `16`.", - ) - proxy_host: str = Field( - ..., - description="The proxy host for the project. This value combines the `region_id`, the `platform_id`, and the Neon domain (`neon.tech`).\n", - ) - branch_logical_size_limit: int = Field( - ..., description="The logical size limit for a branch. The value is in MiB.\n" - ) - branch_logical_size_limit_bytes: int = Field( - ..., description="The logical size limit for a branch. The value is in B.\n" - ) - store_passwords: bool = Field( - ..., - description="Whether or not passwords are stored for roles in the Neon project. Storing passwords facilitates access to Neon features that require authorization.\n", - ) - active_time: conint(ge=0) = Field( - ..., - description="Control plane observed endpoints of this project being active this amount of wall-clock time.\n", - ) - cpu_used_sec: int = Field( - ..., description="DEPRECATED. Use data from the getProject endpoint instead.\n" - ) - maintenance_starts_at: Optional[AwareDatetime] = Field( - None, - description="A timestamp indicating when project maintenance begins. If set, the project is placed into maintenance mode at this time.\n", - ) - creation_source: str = Field(..., description="The project creation source\n") - created_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the project was created\n" - ) - updated_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the project was last updated\n" - ) - synthetic_storage_size: Optional[int] = Field( - None, - description="The current space occupied by the project in storage, in bytes. Synthetic storage size combines the logical data size and Write-Ahead Log (WAL) size for all branches in a project.\n", - ) - quota_reset_at: Optional[AwareDatetime] = Field( - None, - description="DEPRECATED. Use `consumption_period_end` from the getProject endpoint instead.\nA timestamp indicating when the project quota resets\n", - ) - owner_id: str - compute_last_active_at: Optional[AwareDatetime] = Field( - None, - description="The most recent time when any endpoint of this project was active.\n\nOmitted when observed no actitivy for endpoints of this project.\n", - ) - - -class Project(BaseModel): - data_storage_bytes_hour: conint(ge=0) = Field( - ..., - description="Bytes-Hour. Project consumed that much storage hourly during the billing period. The value has some lag.\nThe value is reset at the beginning of each billing period.\n", - ) - data_transfer_bytes: conint(ge=0) = Field( - ..., - description="Bytes. Egress traffic from the Neon cloud to the client for given project over the billing period.\nIncludes deleted endpoints. The value has some lag. The value is reset at the beginning of each billing period.\n", - ) - written_data_bytes: conint(ge=0) = Field( - ..., - description="Bytes. Amount of WAL that travelled through storage for given project across all branches.\nThe value has some lag. The value is reset at the beginning of each billing period.\n", - ) - compute_time_seconds: conint(ge=0) = Field( - ..., - description="Seconds. The number of CPU seconds used by the project's compute endpoints, including compute endpoints that have been deleted.\nThe value has some lag. The value is reset at the beginning of each billing period.\nExamples:\n1. An endpoint that uses 1 CPU for 1 second is equal to `compute_time=1`.\n2. An endpoint that uses 2 CPUs simultaneously for 1 second is equal to `compute_time=2`.\n", - ) - active_time_seconds: conint(ge=0) = Field( - ..., - description="Seconds. Control plane observed endpoints of this project being active this amount of wall-clock time.\nThe value has some lag.\nThe value is reset at the beginning of each billing period.\n", - ) - cpu_used_sec: int = Field( - ..., description="DEPRECATED, use compute_time instead.\n" - ) - id: str = Field(..., description="The project ID\n") - platform_id: str = Field( - ..., - description="The cloud platform identifier. Currently, only AWS is supported, for which the identifier is `aws`.\n", - ) - region_id: str = Field(..., description="The region identifier\n") - name: str = Field(..., description="The project name\n") +@dataclass +class ProjectListItem: + id: str + platform_id: str + region_id: str + name: str provisioner: Provisioner - default_endpoint_settings: Optional[DefaultEndpointSettings] = None - settings: Optional[ProjectSettingsData] = None - pg_version: conint(ge=14, le=16) = Field( - ..., - description="The major PostgreSQL version number. Currently supported versions are `14`, `15` and `16`.", - ) - proxy_host: str = Field( - ..., - description="The proxy host for the project. This value combines the `region_id`, the `platform_id`, and the Neon domain (`neon.tech`).\n", - ) - branch_logical_size_limit: int = Field( - ..., description="The logical size limit for a branch. The value is in MiB.\n" - ) - branch_logical_size_limit_bytes: int = Field( - ..., description="The logical size limit for a branch. The value is in B.\n" - ) - store_passwords: bool = Field( - ..., - description="Whether or not passwords are stored for roles in the Neon project. Storing passwords facilitates access to Neon features that require authorization.\n", - ) - maintenance_starts_at: Optional[AwareDatetime] = Field( - None, - description="A timestamp indicating when project maintenance begins. If set, the project is placed into maintenance mode at this time.\n", - ) - creation_source: str = Field(..., description="The project creation source\n") - history_retention_seconds: int = Field( - ..., - description="The number of seconds to retain point-in-time restore (PITR) backup history for this project.\n", - ) - created_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the project was created\n" - ) - updated_at: AwareDatetime = Field( - ..., description="A timestamp indicating when the project was last updated\n" - ) - synthetic_storage_size: Optional[int] = Field( - None, - description="The current space occupied by the project in storage, in bytes. Synthetic storage size combines the logical data size and Write-Ahead Log (WAL) size for all branches in a project.\n", - ) - consumption_period_start: AwareDatetime = Field( - ..., - description="A date-time indicating when Neon Cloud started measuring consumption for current consumption period.\n", - ) - consumption_period_end: AwareDatetime = Field( - ..., - description="A date-time indicating when Neon Cloud plans to stop measuring consumption for current consumption period.\n", - ) - quota_reset_at: Optional[AwareDatetime] = Field( - None, - description="DEPRECATED. Use `consumption_period_end` from the getProject endpoint instead.\nA timestamp indicating when the project quota resets.\n", - ) + pg_version: int + proxy_host: str + branch_logical_size_limit: int + branch_logical_size_limit_bytes: int + store_passwords: bool + active_time: int + cpu_used_sec: int + creation_source: str + created_at: str + updated_at: str owner_id: str + default_endpoint_settings: Optional[DefaultEndpointSettings] = None + settings: Optional[ProjectSettingsData] = None + maintenance_starts_at: Optional[str] = None + synthetic_storage_size: Optional[int] = None + quota_reset_at: Optional[str] = None + compute_last_active_at: Optional[str] = None + + +@dataclass +class Project: + data_storage_bytes_hour: int + data_transfer_bytes: int + written_data_bytes: int + compute_time_seconds: int + active_time_seconds: int + cpu_used_sec: int + id: str + platform_id: str + region_id: str + name: str + provisioner: Provisioner + pg_version: int + proxy_host: str + branch_logical_size_limit: int + branch_logical_size_limit_bytes: int + store_passwords: bool + creation_source: str + history_retention_seconds: int + created_at: str + updated_at: str + consumption_period_start: str + consumption_period_end: str + owner_id: str + default_endpoint_settings: Optional[DefaultEndpointSettings] = None + settings: Optional[ProjectSettingsData] = None + maintenance_starts_at: Optional[str] = None + synthetic_storage_size: Optional[int] = None + quota_reset_at: Optional[str] = None owner: Optional[ProjectOwnerData] = None - compute_last_active_at: Optional[AwareDatetime] = Field( - None, - description="The most recent time when any endpoint of this project was active.\n\nOmitted when observed no actitivy for endpoints of this project.\n", - ) + compute_last_active_at: Optional[str] = None -class ProjectCreateItem(BaseModel): +@dataclass +class Project1: settings: Optional[ProjectSettingsData] = None - name: Optional[str] = Field(None, description="The project name") - branch: Optional[BranchUpdateItem] = None - autoscaling_limit_min_cu: Optional[confloat()] = Field( - None, - description="DEPRECATED, use default_endpoint_settings.autoscaling_limit_min_cu instead.\n\nThe minimum number of Compute Units. The minimum value is `0.25`.\nSee [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", - ) - autoscaling_limit_max_cu: Optional[confloat()] = Field( - None, - description="DEPRECATED, use default_endpoint_settings.autoscaling_limit_max_cu instead.\n\nThe maximum number of Compute Units. See [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", - ) + name: Optional[str] = None + branch: Optional[Branch] = None + autoscaling_limit_min_cu: Optional[float] = None + autoscaling_limit_max_cu: Optional[float] = None provisioner: Optional[Provisioner] = None - region_id: Optional[str] = Field( - None, - description="The region identifier. Refer to our [Regions](https://neon.tech/docs/introduction/regions) documentation for supported regions. Values are specified in this format: `aws-us-east-1`\n", - ) + region_id: Optional[str] = None default_endpoint_settings: Optional[DefaultEndpointSettings] = None - pg_version: Optional[conint(ge=14, le=16)] = Field( - None, - description="The major PostgreSQL version number. Currently supported versions are `14`, `15` and `16`.", - ) - store_passwords: Optional[bool] = Field( - None, - description="Whether or not passwords are stored for roles in the Neon project. Storing passwords facilitates access to Neon features that require authorization.\n", - ) - history_retention_seconds: Optional[conint(ge=0, le=2592000)] = Field( - None, - description="The number of seconds to retain the point-in-time restore (PITR) backup history for this project.\nThe default is 604800 seconds (7 days).\n", - ) + pg_version: Optional[int] = None + store_passwords: Optional[bool] = None + history_retention_seconds: Optional[int] = None -class ProjectCreateRequest(BaseModel): - project: ProjectCreateItem +@dataclass +class ProjectCreateRequest: + project: Project1 -class ProjectUpdateItem(BaseModel): +@dataclass +class Project2: settings: Optional[ProjectSettingsData] = None - name: Optional[str] = Field(None, description="The project name") + name: Optional[str] = None default_endpoint_settings: Optional[DefaultEndpointSettings] = None - history_retention_seconds: Optional[conint(ge=0, le=2592000)] = Field( - None, - description="The number of seconds to retain the point-in-time restore (PITR) backup history for this project.\nThe default is 604800 seconds (7 days).\n", - ) + history_retention_seconds: Optional[int] = None -class ProjectUpdateRequest(BaseModel): - project: ProjectUpdateItem +@dataclass +class ProjectUpdateRequest: + project: Project2 -class ProjectResponse(BaseModel): +@dataclass +class ProjectResponse: project: Project -class ProjectsResponse(BaseModel): +@dataclass +class ProjectsResponse: projects: list[ProjectListItem] -class Endpoint(BaseModel): - host: str = Field( - ..., - description="The hostname of the compute endpoint. This is the hostname specified when connecting to a Neon database.\n", - ) - id: str = Field( - ..., - description="The compute endpoint ID. Compute endpoint IDs have an `ep-` prefix. For example: `ep-little-smoke-851426`\n", - ) - project_id: str = Field( - ..., description="The ID of the project to which the compute endpoint belongs\n" - ) - branch_id: str = Field( - ..., - description="The ID of the branch that the compute endpoint is associated with\n", - ) - autoscaling_limit_min_cu: confloat() = Field( - ..., description="The minimum number of Compute Units\n" - ) - autoscaling_limit_max_cu: confloat() = Field( - ..., description="The maximum number of Compute Units\n" - ) - region_id: str = Field(..., description="The region identifier\n") +@dataclass +class Endpoint: + host: str + id: str + project_id: str + branch_id: str + autoscaling_limit_min_cu: float + autoscaling_limit_max_cu: float + region_id: str type: EndpointType current_state: EndpointState - pending_state: Optional[EndpointState] = None settings: EndpointSettingsData - pooler_enabled: bool = Field( - ..., - description="Whether connection pooling is enabled for the compute endpoint\n", - ) + pooler_enabled: bool pooler_mode: EndpointPoolerMode - disabled: bool = Field( - ..., - description="Whether to restrict connections to the compute endpoint.\nEnabling this option schedules a suspend compute operation.\nA disabled compute endpoint cannot be enabled by a connection or\nconsole action. However, the compute endpoint is periodically\nenabled by check_availability operations.\n", - ) - passwordless_access: bool = Field( - ..., - description="Whether to permit passwordless access to the compute endpoint\n", - ) - last_active: Optional[AwareDatetime] = Field( - None, - description="A timestamp indicating when the compute endpoint was last active\n", - ) - creation_source: str = Field( - ..., description="The compute endpoint creation source\n" - ) - created_at: AwareDatetime = Field( - ..., - description="A timestamp indicating when the compute endpoint was created\n", - ) - updated_at: AwareDatetime = Field( - ..., - description="A timestamp indicating when the compute endpoint was last updated\n", - ) - proxy_host: str = Field( - ..., description='DEPRECATED. Use the "host" property instead.\n' - ) - suspend_timeout_seconds: conint(ge=-1, le=604800) = Field( - ..., - description="Duration of inactivity in seconds after which the compute endpoint is\nautomatically suspended. The value `0` means use the global default.\nThe value `-1` means never suspend. The default value is `300` seconds (5 minutes).\nThe maximum value is `604800` seconds (1 week). For more information, see\n[Auto-suspend configuration](https://neon.tech/docs/manage/endpoints#auto-suspend-configuration).\n", - ) + disabled: bool + passwordless_access: bool + creation_source: str + created_at: str + updated_at: str + proxy_host: str + suspend_timeout_seconds: int provisioner: Provisioner + pending_state: Optional[EndpointState] = None + last_active: Optional[str] = None -class EndpointCreateItem(BaseModel): - branch_id: str = Field( - ..., - description="The ID of the branch the compute endpoint will be associated with\n", - ) - region_id: Optional[str] = Field( - None, - description="The region where the compute endpoint will be created. Only the project's `region_id` is permitted.\n", - ) +@dataclass +class Endpoint1: + branch_id: str type: EndpointType + region_id: Optional[str] = None settings: Optional[EndpointSettingsData] = None - autoscaling_limit_min_cu: Optional[confloat()] = Field( - None, - description="The minimum number of Compute Units. The minimum value is `0.25`.\nSee [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", - ) - autoscaling_limit_max_cu: Optional[confloat()] = Field( - None, - description="The maximum number of Compute Units.\nSee [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", - ) + autoscaling_limit_min_cu: Optional[float] = None + autoscaling_limit_max_cu: Optional[float] = None provisioner: Optional[Provisioner] = None - pooler_enabled: Optional[bool] = Field( - None, - description="Whether to enable connection pooling for the compute endpoint\n", - ) + pooler_enabled: Optional[bool] = None pooler_mode: Optional[EndpointPoolerMode] = None - disabled: Optional[bool] = Field( - None, - description="Whether to restrict connections to the compute endpoint.\nEnabling this option schedules a suspend compute operation.\nA disabled compute endpoint cannot be enabled by a connection or\nconsole action. However, the compute endpoint is periodically\nenabled by check_availability operations.\n", - ) - passwordless_access: Optional[bool] = Field( - None, - description="NOT YET IMPLEMENTED. Whether to permit passwordless access to the compute endpoint.\n", - ) - suspend_timeout_seconds: Optional[conint(ge=-1, le=604800)] = Field( - None, - description="Duration of inactivity in seconds after which the compute endpoint is\nautomatically suspended. The value `0` means use the global default.\nThe value `-1` means never suspend. The default value is `300` seconds (5 minutes).\nThe maximum value is `604800` seconds (1 week). For more information, see\n[Auto-suspend configuration](https://neon.tech/docs/manage/endpoints#auto-suspend-configuration).\n", - ) + disabled: Optional[bool] = None + passwordless_access: Optional[bool] = None + suspend_timeout_seconds: Optional[int] = None -class EndpointCreateRequest(BaseModel): - endpoint: EndpointCreateItem +@dataclass +class EndpointCreateRequest: + endpoint: Endpoint1 -class Endpoint2(BaseModel): - branch_id: Optional[str] = Field( - None, - description="The destination branch ID. The destination branch must not have an exsiting read-write endpoint.\n", - ) - autoscaling_limit_min_cu: Optional[confloat()] = Field( - None, - description="The minimum number of Compute Units. The minimum value is `0.25`.\nSee [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", - ) - autoscaling_limit_max_cu: Optional[confloat()] = Field( - None, - description="The maximum number of Compute Units.\nSee [Compute size and Autoscaling configuration](https://neon.tech/docs/manage/endpoints#compute-size-and-autoscaling-configuration)\nfor more information.\n", - ) +@dataclass +class Endpoint2: + branch_id: Optional[str] = None + autoscaling_limit_min_cu: Optional[float] = None + autoscaling_limit_max_cu: Optional[float] = None provisioner: Optional[Provisioner] = None settings: Optional[EndpointSettingsData] = None - pooler_enabled: Optional[bool] = Field( - None, - description="Whether to enable connection pooling for the compute endpoint\n", - ) + pooler_enabled: Optional[bool] = None pooler_mode: Optional[EndpointPoolerMode] = None - disabled: Optional[bool] = Field( - None, - description="Whether to restrict connections to the compute endpoint.\nEnabling this option schedules a suspend compute operation.\nA disabled compute endpoint cannot be enabled by a connection or\nconsole action. However, the compute endpoint is periodically\nenabled by check_availability operations.\n", - ) - passwordless_access: Optional[bool] = Field( - None, - description="NOT YET IMPLEMENTED. Whether to permit passwordless access to the compute endpoint.\n", - ) - suspend_timeout_seconds: Optional[conint(ge=-1, le=604800)] = Field( - None, - description="Duration of inactivity in seconds after which the compute endpoint is\nautomatically suspended. The value `0` means use the global default.\nThe value `-1` means never suspend. The default value is `300` seconds (5 minutes).\nThe maximum value is `604800` seconds (1 week). For more information, see\n[Auto-suspend configuration](https://neon.tech/docs/manage/endpoints#auto-suspend-configuration).\n", - ) + disabled: Optional[bool] = None + passwordless_access: Optional[bool] = None + suspend_timeout_seconds: Optional[int] = None -class EndpointUpdateRequest(BaseModel): +@dataclass +class EndpointUpdateRequest: endpoint: Endpoint2 -class EndpointResponse(BaseModel): +@dataclass +class EndpointResponse: endpoint: Endpoint -class EndpointsResponse(BaseModel): +@dataclass +class EndpointsResponse: endpoints: list[Endpoint] +@dataclass class EndpointOperations(EndpointResponse, OperationsResponse): pass diff --git a/v2.json b/v2.json index 53680b4..7fb5b3d 100644 --- a/v2.json +++ b/v2.json @@ -893,7 +893,65 @@ "type": "string" } } - ] + ], + "get": { + "summary": "Return project's permissions", + "description": "Return project's permissions", + "tags": [ + "Project", + "Permissions" + ], + "operationId": "listProjectPermissions", + "responses": { + "200": { + "description": "Successfully returned permissions", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProjectPermissions" + } + } + } + }, + "default": { + "$ref": "#/components/responses/GeneralError" + } + } + }, + "post": { + "summary": "Grant project permission to the user", + "description": "Grant project permission to the user", + "tags": [ + "Project", + "Permissions" + ], + "operationId": "grantPermissionToProject", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/GrantPermissionToProjectRequest" + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "Successfully granted permission to the user", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProjectPermission" + } + } + } + }, + "default": { + "$ref": "#/components/responses/GeneralError" + } + } + } }, "/projects/{project_id}/permissions/{permission_id}": { "parameters": [ @@ -913,7 +971,31 @@ "type": "string" } } - ] + ], + "delete": { + "summary": "Revoke permission from the user", + "description": "Revoke permission from the user", + "tags": [ + "Project", + "Permissions" + ], + "operationId": "revokePermissionFromProject", + "responses": { + "200": { + "description": "Successfully revoked permission from the user", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProjectPermission" + } + } + } + }, + "default": { + "$ref": "#/components/responses/GeneralError" + } + } + } }, "/saved_queries/{saved_query_id}": { "parameters": [ @@ -3772,6 +3854,55 @@ } } }, + "ProjectPermission": { + "type": "object", + "required": [ + "id", + "granted_to_email", + "granted_at" + ], + "properties": { + "id": { + "type": "string" + }, + "granted_to_email": { + "type": "string" + }, + "granted_at": { + "type": "string", + "format": "date-time" + }, + "revoked_at": { + "type": "string", + "format": "date-time" + } + } + }, + "ProjectPermissions": { + "type": "object", + "required": [ + "project_permissions" + ], + "properties": { + "project_permissions": { + "type": "array", + "items": { + "$ref": "#/components/schemas/ProjectPermission" + } + } + } + }, + "GrantPermissionToProjectRequest": { + "type": "object", + "required": [ + "email" + ], + "properties": { + "email": { + "type": "string" + } + } + }, "ProjectsConsumptionResponse": { "type": "object", "required": [ @@ -4393,10 +4524,9 @@ "maximum": 604800 }, "AllowedIps": { - "description": "A list of IP addresses that are allowed to connect to the endpoint.\nIf the list is empty, all IP addresses are allowed.\nIf primary_branch_only is true, the list will be applied only to the primary branch.\n", + "description": "A list of IP addresses that are allowed to connect to the endpoint.\nIf the list is empty or not set, all IP addresses are allowed.\nIf primary_branch_only is true, the list will be applied only to the primary branch.\n", "type": "object", "required": [ - "ips", "primary_branch_only" ], "properties": { @@ -5271,6 +5401,13 @@ } } }, + "SubscriptionDowngradeNewType": { + "type": "string", + "enum": [ + "free", + "free_v2" + ] + }, "GeneralError": { "type": "object", "description": "General Error", @@ -5339,6 +5476,13 @@ "high", "critical" ] + }, + "SubscriptionUpgradeNewType": { + "type": "string", + "enum": [ + "launch", + "scale" + ] } } }