Repository: activeloopai/Hub
File: deeplake/core/storage/azure.py (Python)

Code before:
    def _set_attrs(self):
        self.account_name, self.container_name, self.root_folder = self._get_attrs(
            self.root
        )
        self.account_url = f"https://{self.account_name}.blob.core.windows.net"
        self.credential, self.account_key, self.sas_token = None, None, None
        self._set_credential(self.creds)
        self._set_clients()

    def _get_attrs(self, path: str) -> Tuple[str, str, str]:
        split_path = (
            path.replace("az://", "").replace("azure://", "").strip("/").split("/", 2)
        )
        if len(split_path) == 1:
            raise ValueError(
                "Container name must be provided. Path must be in the format az://<account_name>/<container_name>/<root_folder>"
            )
        elif len(split_path) == 2:
            account_name, container_name, root_folder = *split_path, ""
        else:
            account_name, container_name, root_folder = split_path
        return account_name, container_name, root_folder

    def _set_credential(self, creds: Dict[str, str]):
        account_name = creds.get("account_name")
        if account_name and account_name != self.account_name:
            raise ValueError(
                f"Account name in creds ({account_name}) does not match account name in path ({self.account_name})"
            )

        self.account_key = creds.get("account_key")
        if self.account_key:
            self.credential = AzureNamedKeyCredential(account_name, self.account_key)  # type: ignore

        self.sas_token = creds.get("sas_token")
        if self.sas_token and self.credential is None:
            self.credential = AzureSasCredential(self.sas_token)

        if self.credential is None:
            self.credential = DefaultAzureCredential()

    def _set_clients(self):
        self.blob_service_client = BlobServiceClient(
            self.account_url, credential=self.credential
        )
        self.container_client = self.blob_service_client.get_container_client(
            self.container_name
        )

    def __setitem__(self, path, content):
        self.check_readonly()

Review comment (suggestion):
This check seems correct, except when in `storage_factory`, generic `az://account/container` is passed, then `account` is compared to `creds.get("account_name")` which errors out unnecessarily

Code after:
    def _set_attrs(self):
        self.account_name, self.container_name, self.root_folder = self._get_attrs(
            self.root
        )
        self.account_url = f"https://{self.account_name}.blob.core.windows.net"
        self.credential, self.account_key, self.sas_token = None, None, None
        self._set_credential(self.creds)
        self._set_clients()

    def _get_attrs(self, path: str) -> Tuple[str, str, str]:
        split_path = (
            path.replace("az://", "").replace("azure://", "").strip("/").split("/", 2)
        )
        if len(split_path) == 1:
            raise ValueError(
                "Container name must be provided. Path must be in the format az://<account_name>/<container_name>/<root_folder>"
            )
        elif len(split_path) == 2:
            account_name, container_name, root_folder = *split_path, ""
        else:
            account_name, container_name, root_folder = split_path
        return account_name, container_name, root_folder

    def _set_credential(self, creds: Dict[str, str]):
        self.account_name = creds.get("account_name")
        # if account_name and account_name != self.account_name:
        #     raise ValueError(
        #         f"Account name in creds ({account_name}) does not match account name in path ({self.account_name})"
        #     )

        self.account_key = creds.get("account_key")
        if self.account_key:
            self.credential = AzureNamedKeyCredential(account_name, self.account_key)  # type: ignore

        self.sas_token = creds.get("sas_token")
        if self.sas_token and self.credential is None:
            self.credential = AzureSasCredential(self.sas_token)

        if self.credential is None:
            self.credential = DefaultAzureCredential()

    def _set_clients(self):
        self.blob_service_client = BlobServiceClient(
            self.account_url, credential=self.credential
        )
        self.container_client = self.blob_service_client.get_container_client(
            self.container_name
        )

    def __setitem__(self, path, content):
        self.check_readonly()