|
| 1 | +from dataclasses import dataclass, field |
| 2 | +from typing import TYPE_CHECKING, Any, TypedDict |
| 3 | + |
| 4 | +from databricks.bundles.apps._models.app_permission import ( |
| 5 | + AppPermission, |
| 6 | + AppPermissionParam, |
| 7 | +) |
| 8 | +from databricks.bundles.apps._models.app_resource import AppResource, AppResourceParam |
| 9 | +from databricks.bundles.apps._models.lifecycle import Lifecycle, LifecycleParam |
| 10 | +from databricks.bundles.core._resource import Resource |
| 11 | +from databricks.bundles.core._transform import _transform |
| 12 | +from databricks.bundles.core._transform_to_json import _transform_to_json_value |
| 13 | +from databricks.bundles.core._variable import ( |
| 14 | + VariableOr, |
| 15 | + VariableOrDict, |
| 16 | + VariableOrList, |
| 17 | + VariableOrOptional, |
| 18 | +) |
| 19 | + |
| 20 | +if TYPE_CHECKING: |
| 21 | + from typing_extensions import Self |
| 22 | + |
| 23 | + |
| 24 | +@dataclass(kw_only=True) |
| 25 | +class App(Resource): |
| 26 | + """Databricks App resource""" |
| 27 | + |
| 28 | + name: VariableOr[str] |
| 29 | + """ |
| 30 | + The name of the app. The name must be unique within the workspace. |
| 31 | + """ |
| 32 | + |
| 33 | + source_code_path: VariableOrOptional[str] = None |
| 34 | + """ |
| 35 | + Path to the app source code on local disk. This is used by DABs to deploy the app. |
| 36 | + """ |
| 37 | + |
| 38 | + description: VariableOrOptional[str] = None |
| 39 | + """ |
| 40 | + The description of the app. |
| 41 | + """ |
| 42 | + |
| 43 | + resources: VariableOrList[AppResource] = field(default_factory=list) |
| 44 | + """ |
| 45 | + A list of workspace resources associated with the app. |
| 46 | + Each resource can be a job, secret, serving endpoint, SQL warehouse, or Unity Catalog securable. |
| 47 | + """ |
| 48 | + |
| 49 | + permissions: VariableOrList[AppPermission] = field(default_factory=list) |
| 50 | + """ |
| 51 | + Access control list for the app. Multiple permissions can be defined for different principals. |
| 52 | + """ |
| 53 | + |
| 54 | + lifecycle: VariableOrOptional[Lifecycle] = None |
| 55 | + """ |
| 56 | + Lifecycle is a struct that contains the lifecycle settings for a resource. It controls the behavior of the resource when it is deployed or destroyed. |
| 57 | + """ |
| 58 | + |
| 59 | + config: VariableOrDict[Any] = field(default_factory=dict) |
| 60 | + """ |
| 61 | + Application-specific configuration. |
| 62 | +
|
| 63 | + This can include various settings such as: |
| 64 | + - command: List of strings for the command to run the app |
| 65 | + - env: List of environment variable configurations with 'name', 'value', or 'valueFrom' |
| 66 | + - Any other custom app-specific settings |
| 67 | +
|
| 68 | + See AppConfigDict for common configuration structure. |
| 69 | + """ |
| 70 | + |
| 71 | + @classmethod |
| 72 | + def from_dict(cls, value: "AppDict") -> "Self": |
| 73 | + return _transform(cls, value) |
| 74 | + |
| 75 | + def as_dict(self) -> "AppDict": |
| 76 | + return _transform_to_json_value(self) # type:ignore |
| 77 | + |
| 78 | + |
| 79 | +class AppDict(TypedDict, total=False): |
| 80 | + """Databricks App resource""" |
| 81 | + |
| 82 | + name: VariableOr[str] |
| 83 | + """ |
| 84 | + The name of the app. The name must be unique within the workspace. |
| 85 | + """ |
| 86 | + |
| 87 | + source_code_path: VariableOrOptional[str] |
| 88 | + """ |
| 89 | + Path to the app source code on local disk. This is used by DABs to deploy the app. |
| 90 | + """ |
| 91 | + |
| 92 | + description: VariableOrOptional[str] |
| 93 | + """ |
| 94 | + The description of the app. |
| 95 | + """ |
| 96 | + |
| 97 | + resources: VariableOrList[AppResourceParam] |
| 98 | + """ |
| 99 | + A list of workspace resources associated with the app. |
| 100 | + Each resource can be a job, secret, serving endpoint, SQL warehouse, or Unity Catalog securable. |
| 101 | + """ |
| 102 | + |
| 103 | + permissions: VariableOrList[AppPermissionParam] |
| 104 | + """ |
| 105 | + Access control list for the app. Multiple permissions can be defined for different principals. |
| 106 | + """ |
| 107 | + |
| 108 | + lifecycle: VariableOrOptional[LifecycleParam] |
| 109 | + """ |
| 110 | + Lifecycle is a struct that contains the lifecycle settings for a resource. It controls the behavior of the resource when it is deployed or destroyed. |
| 111 | + """ |
| 112 | + |
| 113 | + config: VariableOrDict[Any] |
| 114 | + """ |
| 115 | + Application-specific configuration. |
| 116 | +
|
| 117 | + This can include various settings such as: |
| 118 | + - command: List of strings for the command to run the app |
| 119 | + - env: List of environment variable configurations with 'name', 'value', or 'valueFrom' |
| 120 | + - Any other custom app-specific settings |
| 121 | +
|
| 122 | + See AppConfigDict for common configuration structure. |
| 123 | + """ |
| 124 | + |
| 125 | + |
| 126 | +AppParam = AppDict | App |
0 commit comments