Skip to content

Commit

Permalink
Merge pull request #8 from rebbuh/blob-service-properties-only
Browse files Browse the repository at this point in the history
Refactors setting of BlobServiceProperties
  • Loading branch information
swoehrl-mw authored Jan 12, 2023
2 parents c2cea1e + 154d3c9 commit 8e5d0d0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ spec:
allowedHeaders: # List of HTTP headers to allow in the response, wildcard "*" is allowed, required
- "*"
maxAgeInSeconds: 200 # Time in seconds the bucket should cache Preflight-OPTIONS requests, required
dataRetention: # Settings related to data retention, optional
dataRetention: # Settings related to data retention, optional; will not be respected if backup.enabled = true
versioning: # Settings related to versioning, optional
enabled: false # Enable versioning in storage account, optional
deleteRetention: # Settings related to delete retention, optional
Expand Down
39 changes: 24 additions & 15 deletions hybridcloud/backends/azureblob.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,29 @@ def create_or_update_bucket(self, namespace, name, spec):
self._lock_client.management_locks.create_or_update_at_resource_level(self._resource_group, "Microsoft.Storage", "", "storageAccounts", bucket_name, "DoNotDeleteLock", parameters=ManagementLockObject(level="CanNotDelete", notes="Protection from accidental deletion"))

# Create blob services
retention, changefeed = _map_retention(spec)
versioning = field_from_spec(spec, "dataRetention.versioning.enabled", default=_backend_config("parameters.versioning.enabled", default=False))
parameters = BlobServiceProperties(
cors=_map_cors_rules(spec.get("security", dict()).get("cors")),
is_versioning_enabled=versioning,
delete_retention_policy=retention,
container_delete_retention_policy=retention,
restore_policy=None,
change_feed=changefeed,
)
cors_rules = _map_cors_rules(spec.get("security", dict()).get("cors"))
retention = _map_retention(spec)
if backup_enabled:
# If backup is enabled,
# is_versioning_enabled, delete_retention_policy and change_feed are not allowed to be overwritten.
# container_delete_retention_policy would work, but setting it makes no sense due to consistency reasons.
parameters = BlobServiceProperties(
cors=cors_rules,
)
else:
versioning = field_from_spec(spec, "dataRetention.versioning.enabled",
default=_backend_config("parameters.versioning.enabled", default=False))
change_feed = ChangeFeed(
enabled=False,
retention_in_days=None,
)
parameters = BlobServiceProperties(
cors=cors_rules,
is_versioning_enabled=versioning,
delete_retention_policy=retention,
container_delete_retention_policy=retention,
change_feed=change_feed,
)
self._storage_client.blob_services.set_service_properties(self._resource_group, bucket_name, parameters=parameters)

# Create containers
Expand Down Expand Up @@ -380,11 +393,7 @@ def _map_retention(spec):
enabled=enabled,
days=days if enabled else None,
)
changefeed = ChangeFeed(
enabled=False,
retention_in_days=None,
)
return retention, changefeed
return retention


def _calc_tags(namespace, name, extra_tags={}):
Expand Down

0 comments on commit 8e5d0d0

Please sign in to comment.