|
| 1 | +# coding: utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | + Resource Manager API |
| 5 | +
|
| 6 | + API v2 to manage resource containers - organizations, folders, projects incl. labels ### Resource Management STACKIT resource management handles the terms _Organization_, _Folder_, _Project_, _Label_, and the hierarchical structure between them. Technically, organizations, folders, and projects are _Resource Containers_ to which a _Label_ can be attached to. The STACKIT _Resource Manager_ provides CRUD endpoints to query and to modify the state. ### Organizations STACKIT organizations are the base element to create and to use cloud-resources. An organization is bound to one customer account. Organizations have a lifecycle. - Organizations are always the root node in resource hierarchy and do not have a parent ### Projects STACKIT projects are needed to use cloud-resources. Projects serve as wrapper for underlying technical structures and processes. Projects have a lifecycle. Projects compared to folders may have different policies. - Projects are optional, but mandatory for cloud-resource usage - A project can be created having either an organization, or a folder as parent - A project must not have a project as parent - Project names under the same parent must not be unique - Root organization cannot be changed ### Label STACKIT labels are key-value pairs including a resource container reference. Labels can be defined and attached freely to resource containers by which resources can be organized and queried. - Policy-based, immutable labels may exists |
| 7 | +
|
| 8 | + The version of the OpenAPI document: 2.0 |
| 9 | + Generated by OpenAPI Generator (https://openapi-generator.tech) |
| 10 | +
|
| 11 | + Do not edit the class manually. |
| 12 | +""" # noqa: E501 docstring might be too long |
| 13 | + |
| 14 | +from __future__ import annotations |
| 15 | + |
| 16 | +import json |
| 17 | +import pprint |
| 18 | +import re |
| 19 | +from typing import Any, ClassVar, Dict, List, Optional, Set |
| 20 | + |
| 21 | +from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator |
| 22 | +from typing_extensions import Annotated, Self |
| 23 | + |
| 24 | +from stackit.resourcemanager.models.member import Member |
| 25 | + |
| 26 | + |
| 27 | +class CreateFolderPayload(BaseModel): |
| 28 | + """ |
| 29 | + CreateFolderPayload |
| 30 | + """ |
| 31 | + |
| 32 | + container_parent_id: StrictStr = Field( |
| 33 | + description="Identifier of the parent resource container - containerId as well as UUID identifier is supported.", |
| 34 | + alias="containerParentId", |
| 35 | + ) |
| 36 | + labels: Optional[Dict[str, StrictStr]] = Field( |
| 37 | + default=None, |
| 38 | + description="Labels are key-value string pairs that can be attached to a resource container. Some labels may be enforced via policies. - A label key must match the regex `[A-ZÄÜÖa-zäüöß0-9_-]{1,64}`. - A label value must match the regex `^$|[A-ZÄÜÖa-zäüöß0-9_-]{1,64}`.", |
| 39 | + ) |
| 40 | + members: Optional[Annotated[List[Member], Field(min_length=1)]] = Field( |
| 41 | + default=None, |
| 42 | + description="The initial members assigned to the project. At least one subject needs to be a user, and not a client or service account.", |
| 43 | + ) |
| 44 | + name: Annotated[str, Field(strict=True)] = Field( |
| 45 | + description="The name of the folder matching the regex `^[a-zA-ZäüöÄÜÖ0-9]( ?[a-zA-ZäüöÄÜÖß0-9_+&-]){0,39}$`." |
| 46 | + ) |
| 47 | + __properties: ClassVar[List[str]] = ["containerParentId", "labels", "members", "name"] |
| 48 | + |
| 49 | + @field_validator("name") |
| 50 | + def name_validate_regular_expression(cls, value): |
| 51 | + """Validates the regular expression""" |
| 52 | + if not re.match(r"^[a-zA-ZäüöÄÜÖ0-9]( ?[a-zA-ZäüöÄÜÖß0-9_+&-]){0,39}$", value): |
| 53 | + raise ValueError( |
| 54 | + r"must validate the regular expression /^[a-zA-ZäüöÄÜÖ0-9]( ?[a-zA-ZäüöÄÜÖß0-9_+&-]){0,39}$/" |
| 55 | + ) |
| 56 | + return value |
| 57 | + |
| 58 | + model_config = ConfigDict( |
| 59 | + populate_by_name=True, |
| 60 | + validate_assignment=True, |
| 61 | + protected_namespaces=(), |
| 62 | + ) |
| 63 | + |
| 64 | + def to_str(self) -> str: |
| 65 | + """Returns the string representation of the model using alias""" |
| 66 | + return pprint.pformat(self.model_dump(by_alias=True)) |
| 67 | + |
| 68 | + def to_json(self) -> str: |
| 69 | + """Returns the JSON representation of the model using alias""" |
| 70 | + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead |
| 71 | + return json.dumps(self.to_dict()) |
| 72 | + |
| 73 | + @classmethod |
| 74 | + def from_json(cls, json_str: str) -> Optional[Self]: |
| 75 | + """Create an instance of CreateFolderPayload from a JSON string""" |
| 76 | + return cls.from_dict(json.loads(json_str)) |
| 77 | + |
| 78 | + def to_dict(self) -> Dict[str, Any]: |
| 79 | + """Return the dictionary representation of the model using alias. |
| 80 | +
|
| 81 | + This has the following differences from calling pydantic's |
| 82 | + `self.model_dump(by_alias=True)`: |
| 83 | +
|
| 84 | + * `None` is only added to the output dict for nullable fields that |
| 85 | + were set at model initialization. Other fields with value `None` |
| 86 | + are ignored. |
| 87 | + """ |
| 88 | + excluded_fields: Set[str] = set([]) |
| 89 | + |
| 90 | + _dict = self.model_dump( |
| 91 | + by_alias=True, |
| 92 | + exclude=excluded_fields, |
| 93 | + exclude_none=True, |
| 94 | + ) |
| 95 | + # override the default output from pydantic by calling `to_dict()` of each item in members (list) |
| 96 | + _items = [] |
| 97 | + if self.members: |
| 98 | + for _item in self.members: |
| 99 | + if _item: |
| 100 | + _items.append(_item.to_dict()) |
| 101 | + _dict["members"] = _items |
| 102 | + return _dict |
| 103 | + |
| 104 | + @classmethod |
| 105 | + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: |
| 106 | + """Create an instance of CreateFolderPayload from a dict""" |
| 107 | + if obj is None: |
| 108 | + return None |
| 109 | + |
| 110 | + if not isinstance(obj, dict): |
| 111 | + return cls.model_validate(obj) |
| 112 | + |
| 113 | + _obj = cls.model_validate( |
| 114 | + { |
| 115 | + "containerParentId": obj.get("containerParentId"), |
| 116 | + "labels": obj.get("labels"), |
| 117 | + "members": ( |
| 118 | + [Member.from_dict(_item) for _item in obj["members"]] if obj.get("members") is not None else None |
| 119 | + ), |
| 120 | + "name": obj.get("name"), |
| 121 | + } |
| 122 | + ) |
| 123 | + return _obj |
0 commit comments