@@ -14,6 +14,7 @@ class StorageType(Enum):
1414
1515 S3 = "s3"
1616 LOCAL = "local"
17+ AZURE = "azure"
1718
1819
1920class S3StorageConfig (BaseModel ):
@@ -91,6 +92,102 @@ def from_aws_profile(
9192 return cls (backup_path = backup_path , bucket = bucket , profile = profile )
9293
9394
95+ class AzureStorageConfig (BaseModel ):
96+ """Configuration for Azure Blob Storage.
97+
98+ Can be created using the following constructor methods:
99+ - `from_workload_identity`
100+ - `from_connection_string`
101+ - `from_service_principal`
102+ """
103+
104+ backup_path : str
105+ account_name : str
106+ container : str
107+ connection_string : str | None = None
108+ client_id : str | None = None
109+ client_secret : str | None = None
110+ tenant_id : str | None = None
111+
112+ @classmethod
113+ def from_workload_identity (
114+ cls , backup_path : str , account_name : str , container : str
115+ ) -> "AzureStorageConfig" :
116+ """Use Azure Workload Identity (for Kubernetes).
117+
118+ Args:
119+ backup_path: The path to the backup directory.
120+ account_name: The Azure storage account name.
121+ container: The name of the blob container.
122+
123+ Returns:
124+ AzureStorageConfig: The Azure storage configuration.
125+ """
126+ return cls (
127+ backup_path = backup_path ,
128+ account_name = account_name ,
129+ container = container ,
130+ )
131+
132+ @classmethod
133+ def from_connection_string (
134+ cls ,
135+ backup_path : str ,
136+ account_name : str ,
137+ container : str ,
138+ connection_string : str ,
139+ ) -> "AzureStorageConfig" :
140+ """Use Azure Storage connection string.
141+
142+ Args:
143+ backup_path: The path to the backup directory.
144+ account_name: The Azure storage account name.
145+ container: The name of the blob container.
146+ connection_string: The Azure Storage connection string.
147+
148+ Returns:
149+ AzureStorageConfig: The Azure storage configuration.
150+ """
151+ return cls (
152+ backup_path = backup_path ,
153+ account_name = account_name ,
154+ container = container ,
155+ connection_string = connection_string ,
156+ )
157+
158+ @classmethod
159+ def from_service_principal (
160+ cls ,
161+ backup_path : str ,
162+ account_name : str ,
163+ container : str ,
164+ client_id : str ,
165+ client_secret : str ,
166+ tenant_id : str ,
167+ ) -> "AzureStorageConfig" :
168+ """Use Azure Service Principal credentials.
169+
170+ Args:
171+ backup_path: The path to the backup directory.
172+ account_name: The Azure storage account name.
173+ container: The name of the blob container.
174+ client_id: The Azure client ID.
175+ client_secret: The Azure client secret.
176+ tenant_id: The Azure tenant ID.
177+
178+ Returns:
179+ AzureStorageConfig: The Azure storage configuration.
180+ """
181+ return cls (
182+ backup_path = backup_path ,
183+ account_name = account_name ,
184+ container = container ,
185+ client_id = client_id ,
186+ client_secret = client_secret ,
187+ tenant_id = tenant_id ,
188+ )
189+
190+
94191class LocalStorageConfig (BaseModel ):
95192 """Placeholder for local storage config."""
96193
@@ -102,14 +199,14 @@ class BackupRestoreConfig(BaseModel):
102199
103200 Args:
104201 storage_type: The type of storage to use. Defaults to `StorageType.LOCAL`.
105- storage: Storage configuration. Either `S3StorageConfig` or `LocalStorageConfig`. Defaults to `LocalStorageConfig()`.
202+ storage: Storage configuration. Either `S3StorageConfig`, `AzureStorageConfig`, or `LocalStorageConfig`. Defaults to `LocalStorageConfig()`.
106203 api_page_size: The page size for fetching workspace relationships. Defaults to `BackupSettings.API.PAGE_SIZE`.
107204 batch_size: The batch size for fetching workspace relationships. Defaults to `BackupSettings.API.BATCH_SIZE`.
108205 api_calls_per_second: The maximum API calls per second (rate limiting). Defaults to `BackupSettings.API.CALLS_PER_SECOND`.
109206 """
110207
111208 storage_type : StorageType = Field (default = StorageType .LOCAL )
112- storage : S3StorageConfig | LocalStorageConfig = Field (
209+ storage : S3StorageConfig | AzureStorageConfig | LocalStorageConfig = Field (
113210 default_factory = LocalStorageConfig
114211 )
115212 api_page_size : Annotated [
@@ -142,12 +239,17 @@ def from_yaml(cls, conf_path: str) -> "BackupRestoreConfig":
142239
143240 @model_validator (mode = "after" )
144241 def validate_storage (self ) -> "BackupRestoreConfig" :
145- """Check that the storage gets correct configuration when using S3 storage """
242+ """Check that the storage gets correct configuration"""
146243 if self .storage_type == StorageType .S3 :
147244 if not isinstance (self .storage , S3StorageConfig ):
148245 raise ValueError (
149246 "S3 storage must be configured with S3StorageConfig object"
150247 )
248+ elif self .storage_type == StorageType .AZURE :
249+ if not isinstance (self .storage , AzureStorageConfig ):
250+ raise ValueError (
251+ "Azure storage must be configured with AzureStorageConfig object"
252+ )
151253 elif self .storage_type == StorageType .LOCAL :
152254 if not isinstance (self .storage , LocalStorageConfig ):
153255 raise ValueError (
0 commit comments