def queue_metadata_set(self, metadata):
     '''
     Set a metadata (dict) on a queue.
     '''
     assert isinstance(metadata, dict)
     qc = self._queueclient_get()
     if not qc:
         raise ApplicationException(
             f"{self.mth()}: queueclient is not populated")
     qc.set_queue_metadata(metadata=metadata)
 def hns_enabled(self):
     '''
     Return whether or not HNS (Hierarchical NameSpace) is enabled
     '''
     if not isinstance(self._name, ContainerName):
         raise ApplicationException("may not %s for %s" %
                                    (self.mth(), self._name))
     with self._lock:
         if self._hns_enabled is None:
             directory_client = self._directoryclient_get()
             self._hns_enabled = self._test_hns_enabled(directory_client)
         assert isinstance(self._hns_enabled, bool)
         return self._hns_enabled
 def queue_delete(self):
     '''
     Delete a queue.
     '''
     qc = self._queueclient_get()
     if not qc:
         raise ApplicationException(
             f"{self.mth()}: queueclient is not populated")
     try:
         qc.delete_queue()
     except Exception as exc:
         caught = laaso.az.azure.msapicall.Caught(exc)
         if caught.is_missing():
             return
         raise
 def _generate_directoryclient(self):
     '''
     Generate and return directoryclient.
     '''
     if not isinstance(self._name, ContainerName):
         raise ApplicationException("may not %s for %r" %
                                    (self.mth(), self._name))
     with self._lock:
         self._hns_enabled = None
         ret = self.directoryclient_create('/')
         if (not ret) and self.warn_missing:
             self.logger.warning(
                 "%s: cannot generate DataLakeDirectoryClient for %r",
                 self.mth(), self._name)
         return ret
 def directoryclient_create(self, path, test_hns_enabled=False):
     '''
     Return azure.storage.filedatalake.DataLakeDirectoryClient for the given path
     '''
     if not isinstance(self._name, ContainerName):
         raise ApplicationException("may not %s for %r" %
                                    (self.mth(), self._name))
     directory_client = None
     dsc = self._datalakeserviceclient_get()
     if dsc:
         directory_client = msapicall(self.logger, dsc.get_directory_client,
                                      self._name.container_name, path)
     if not directory_client:
         return None
     if test_hns_enabled and (not self._test_hns_enabled(directory_client)):
         return None
     return directory_client
 def blob_downloader(self, offset=None, length=None):
     '''
     Return azure.storage.blob.StorageStreamDownloader or None.
     The caller is responsible for handling errors from the downloader.
     '''
     if not isinstance(self._name, BlobName):
         raise ApplicationException("may not %s for %r" %
                                    (self.mth(), self._name))
     self.sa_key_prep()
     bc = self._blobclient_get()
     if not bc:
         return None
     try:
         return bc.download_blob(offset=offset, length=length)
     except Exception as exc:
         caught = laaso.az.azure.msapicall.Caught(exc)
         if caught.is_missing():
             return None
         raise
 def _generate_filesystemclient(self, credential=None):
     '''
     Generate and return azure.storage.filedatalake.FileSystemClient.
     '''
     if not isinstance(self._name, ContainerName):
         raise ApplicationException("may not %s for %r" %
                                    (self.mth(), self._name))
     credential = credential or self.sb_credential_preferred
     ret = None
     with self._lock:
         dsc = self._datalakeserviceclient_get()
         if dsc:
             ret = msapicall(self.logger,
                             dsc.get_file_system_client,
                             self._name.container_name,
                             credential=credential)
         if (not ret) and self.warn_missing:
             self.logger.warning(
                 "%s cannot generate FileSystemClient for %r", self.mth(),
                 self._name)
         return ret
 def blob_write(self,
                data,
                blob_name='',
                blob_type=azure.storage.blob.BlobType.BlockBlob,
                tags=None,
                overwrite=True,
                length=None):
     '''
     Write the given data to the target blob
     '''
     if not isinstance(self.name, ContainerName):
         raise ApplicationException(
             f"{self.mth()}: operation not valid for {self.name!r}")
     blob_name = blob_name or getattr(self.name, 'blob_name', '')
     if not blob_name:
         raise BlobNameMissingException(
             f"{self.mth()}: no blob_name for {self.name!r}")
     tags = self._az_mgr.tags_get(tags)
     if isinstance(data, str):
         data = bytes(data, encoding='utf-8')
     return self._blob_write(data, blob_name, blob_type, tags, overwrite,
                             length)
 def _generate_queueclient(self):
     '''
     Generate and return queueclient.
     '''
     ret = None
     if not isinstance(self._name, QueueName):
         raise ApplicationException("may not %s for %r" %
                                    (self.mth(), self._name))
     with self._lock:
         qsc = self._queueserviceclient_get()
         if qsc:
             try:
                 ret = msapicall(self.logger, qsc.get_queue_client,
                                 self._name.queue_name)
             except Exception as exc:
                 caught = laaso.az.azure.msapicall.Caught(exc)
                 if not caught.is_missing():
                     raise
         if (not ret) and self.warn_missing:
             self.logger.warning("%s: cannot generate QueueClient for %r",
                                 self.mth(), self._name)
         return ret
 def _generate_containerclient(self):
     '''
     Generate and return containerclient.
     '''
     ret = None
     with self._lock:
         if not isinstance(self._name, ContainerName):
             raise ApplicationException("may not %s for %r" %
                                        (self.mth(), self._name))
         bsc = self._blobserviceclient_get()
         if bsc:
             try:
                 ret = msapicall(self.logger, bsc.get_container_client,
                                 self._name.container_name)
             except Exception as exc:
                 caught = laaso.az.azure.msapicall.Caught(exc)
                 if not caught.is_missing():
                     raise
         if (not ret) and self.warn_missing:
             self.logger.warning(
                 "%s: cannot generate ContainerClient for %r", self.mth(),
                 self._name)
         return ret