|
| 1 | +# coding: utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | + IaaS-API |
| 5 | +
|
| 6 | + This API allows you to create and modify IaaS resources. |
| 7 | +
|
| 8 | + The version of the OpenAPI document: 1beta1 |
| 9 | + Contact: stackit-iaas@mail.schwarz |
| 10 | + Generated by OpenAPI Generator (https://openapi-generator.tech) |
| 11 | +
|
| 12 | + Do not edit the class manually. |
| 13 | +""" # noqa: E501 docstring might be too long |
| 14 | + |
| 15 | +from __future__ import annotations |
| 16 | + |
| 17 | +import json |
| 18 | +import pprint |
| 19 | +import re |
| 20 | +from datetime import datetime |
| 21 | +from typing import Any, ClassVar, Dict, List, Optional, Set |
| 22 | + |
| 23 | +from pydantic import BaseModel, ConfigDict, Field, field_validator |
| 24 | +from typing_extensions import Annotated, Self |
| 25 | + |
| 26 | + |
| 27 | +class CreateKeyPairPayload(BaseModel): |
| 28 | + """ |
| 29 | + Object that represents the public key of an SSH keypair and its name. |
| 30 | + """ |
| 31 | + |
| 32 | + created_at: Optional[datetime] = Field( |
| 33 | + default=None, description="Date-time when resource was created.", alias="createdAt" |
| 34 | + ) |
| 35 | + fingerprint: Optional[Annotated[str, Field(min_length=47, strict=True, max_length=47)]] = Field( |
| 36 | + default=None, description="Object that represents an SSH keypair MD5 fingerprint." |
| 37 | + ) |
| 38 | + labels: Optional[Dict[str, Any]] = Field( |
| 39 | + default=None, description="Object that represents the labels of an object." |
| 40 | + ) |
| 41 | + name: Optional[Annotated[str, Field(strict=True, max_length=127)]] = Field( |
| 42 | + default=None, |
| 43 | + description="The name of an SSH keypair. Allowed characters are letters [a-zA-Z], digits [0-9] and the following special characters: [@._-].", |
| 44 | + ) |
| 45 | + public_key: Annotated[str, Field(strict=True)] = Field( |
| 46 | + description="Object that represents a public SSH key.", alias="publicKey" |
| 47 | + ) |
| 48 | + updated_at: Optional[datetime] = Field( |
| 49 | + default=None, description="Date-time when resource was last updated.", alias="updatedAt" |
| 50 | + ) |
| 51 | + __properties: ClassVar[List[str]] = ["createdAt", "fingerprint", "labels", "name", "publicKey", "updatedAt"] |
| 52 | + |
| 53 | + @field_validator("fingerprint") |
| 54 | + def fingerprint_validate_regular_expression(cls, value): |
| 55 | + """Validates the regular expression""" |
| 56 | + if value is None: |
| 57 | + return value |
| 58 | + |
| 59 | + if not re.match(r"^([0-9A-Fa-f]{2}[:-]){15}([0-9A-Fa-f]{2})$", value): |
| 60 | + raise ValueError(r"must validate the regular expression /^([0-9A-Fa-f]{2}[:-]){15}([0-9A-Fa-f]{2})$/") |
| 61 | + return value |
| 62 | + |
| 63 | + @field_validator("name") |
| 64 | + def name_validate_regular_expression(cls, value): |
| 65 | + """Validates the regular expression""" |
| 66 | + if value is None: |
| 67 | + return value |
| 68 | + |
| 69 | + if not re.match(r"^[A-Za-z0-9@._-]*$", value): |
| 70 | + raise ValueError(r"must validate the regular expression /^[A-Za-z0-9@._-]*$/") |
| 71 | + return value |
| 72 | + |
| 73 | + @field_validator("public_key") |
| 74 | + def public_key_validate_regular_expression(cls, value): |
| 75 | + """Validates the regular expression""" |
| 76 | + if not re.match(r"^(ssh-rsa|ssh-ed25519)\s+[A-Za-z0-9+\/]+[=]{0,3}(\s+.+)?\s*$", value): |
| 77 | + raise ValueError( |
| 78 | + r"must validate the regular expression /^(ssh-rsa|ssh-ed25519)\s+[A-Za-z0-9+\/]+[=]{0,3}(\s+.+)?\s*$/" |
| 79 | + ) |
| 80 | + return value |
| 81 | + |
| 82 | + model_config = ConfigDict( |
| 83 | + populate_by_name=True, |
| 84 | + validate_assignment=True, |
| 85 | + protected_namespaces=(), |
| 86 | + ) |
| 87 | + |
| 88 | + def to_str(self) -> str: |
| 89 | + """Returns the string representation of the model using alias""" |
| 90 | + return pprint.pformat(self.model_dump(by_alias=True)) |
| 91 | + |
| 92 | + def to_json(self) -> str: |
| 93 | + """Returns the JSON representation of the model using alias""" |
| 94 | + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead |
| 95 | + return json.dumps(self.to_dict()) |
| 96 | + |
| 97 | + @classmethod |
| 98 | + def from_json(cls, json_str: str) -> Optional[Self]: |
| 99 | + """Create an instance of CreateKeyPairPayload from a JSON string""" |
| 100 | + return cls.from_dict(json.loads(json_str)) |
| 101 | + |
| 102 | + def to_dict(self) -> Dict[str, Any]: |
| 103 | + """Return the dictionary representation of the model using alias. |
| 104 | +
|
| 105 | + This has the following differences from calling pydantic's |
| 106 | + `self.model_dump(by_alias=True)`: |
| 107 | +
|
| 108 | + * `None` is only added to the output dict for nullable fields that |
| 109 | + were set at model initialization. Other fields with value `None` |
| 110 | + are ignored. |
| 111 | + * OpenAPI `readOnly` fields are excluded. |
| 112 | + * OpenAPI `readOnly` fields are excluded. |
| 113 | + * OpenAPI `readOnly` fields are excluded. |
| 114 | + """ |
| 115 | + excluded_fields: Set[str] = set( |
| 116 | + [ |
| 117 | + "created_at", |
| 118 | + "fingerprint", |
| 119 | + "updated_at", |
| 120 | + ] |
| 121 | + ) |
| 122 | + |
| 123 | + _dict = self.model_dump( |
| 124 | + by_alias=True, |
| 125 | + exclude=excluded_fields, |
| 126 | + exclude_none=True, |
| 127 | + ) |
| 128 | + return _dict |
| 129 | + |
| 130 | + @classmethod |
| 131 | + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: |
| 132 | + """Create an instance of CreateKeyPairPayload from a dict""" |
| 133 | + if obj is None: |
| 134 | + return None |
| 135 | + |
| 136 | + if not isinstance(obj, dict): |
| 137 | + return cls.model_validate(obj) |
| 138 | + |
| 139 | + _obj = cls.model_validate( |
| 140 | + { |
| 141 | + "createdAt": obj.get("createdAt"), |
| 142 | + "fingerprint": obj.get("fingerprint"), |
| 143 | + "labels": obj.get("labels"), |
| 144 | + "name": obj.get("name"), |
| 145 | + "publicKey": obj.get("publicKey"), |
| 146 | + "updatedAt": obj.get("updatedAt"), |
| 147 | + } |
| 148 | + ) |
| 149 | + return _obj |
0 commit comments