# Path: libcloudforensics/logging_utils.py
# def _GenerateColorSequences() -> List[str]:
#   def __init__(self,
#                colorize: bool = True,
#                random_color: bool = False,
#                **kwargs: str) -> None:
#   def format(self, record: logging.LogRecord) -> str:
# def SetUpLogger(name: str, no_newline: bool = False) -> None:
# def GetLogger(name: str) -> logging.Logger:
# COLOR_SEQS = _GenerateColorSequences()
# RESET_SEQ = '\u001b[0m'
# BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = COLOR_SEQS[8:16]
# BG_RED = '\u001b[41m'  # Red background
# BOLD = '\u001b[1m'  # Bold / bright modifier
# LOG_FORMAT = ('[%(asctime)s] [{0:s}{color:s}%(name)-20s{1:s}] %(levelname)-8s'
#               ' %(message)s')
# LEVEL_COLOR_MAP = {
#     'WARNING': YELLOW,
#     'INFO': WHITE,
#     'DEBUG': BLUE,
#     'CRITICAL': BOLD + BG_RED + WHITE,
#     'ERROR': RED
# }
# class Formatter(logging.Formatter):
# 
# Path: libcloudforensics/errors.py
# class LCFError(Exception):
# class CredentialsConfigurationError(LCFError):
# class InvalidFileFormatError(LCFError):
# class InvalidNameError(LCFError):
# class ResourceNotFoundError(LCFError):
# class ResourceCreationError(LCFError):
# class ResourceDeletionError(LCFError):
# class InstanceStateChangeError(LCFError):
# class ServiceAccountRemovalError(LCFError):
# class InstanceProfileCreationError(LCFError):
# class OperationFailedError(LCFError):
# class TransferCreationError(LCFError):
# class TransferExecutionError(LCFError):
# class ResourceAlreadyExistsError(LCFError):
#   def __init__(self,
#                message: str,
#                name: str) -> None:
# 
# Path: libcloudforensics/providers/azure/internal/compute_base_resource.py
# class AZComputeResource:
#   def __init__(self,
#                az_account: 'account.AZAccount',
#                resource_id: str,
#                name: str,
#                region: str,
#                zones: Optional[List[str]] = None) -> None:
#   def compute_client(self) -> compute_sdk.ComputeManagementClient:
# 
# Path: libcloudforensics/providers/azure/internal/common.py
# REGEX_DISK_NAME = re.compile('^[\\w]{1,80}$')
# REGEX_SNAPSHOT_NAME = re.compile('^(?=.{1,80}$)[a-zA-Z0-9]([\\w,-]*[\\w])?$')
# REGEX_ACCOUNT_STORAGE_NAME = re.compile('^[a-z0-9]{1,24}$')
# REGEX_COMPUTE_RESOURCE_ID = re.compile(
#     '/subscriptions/.+/resourceGroups/.+/providers/Microsoft.Compute/.+/.+')
# DEFAULT_DISK_COPY_PREFIX = 'evidence'
# UBUNTU_1804_SKU = '18.04-LTS'
# def _ParseCredentialsFile(profile_name: str) -> Dict[str, Any]:
# def _CheckAzureCliCredentials() -> Optional[str]:
# def GetCredentials(profile_name: Optional[str] = None
#                    ) -> Tuple[str, DefaultAzureCredential]:
# def ExecuteRequest(
#     client: Any,
#     func: str,
#     kwargs: Optional[Dict[str, str]] = None) -> List[Any]:
# def GenerateDiskName(snapshot: 'compute.AZComputeSnapshot',
#                      disk_name_prefix: Optional[str] = None) -> str:
# 
# Path: libcloudforensics/scripts/utils.py
# FORENSICS_STARTUP_SCRIPT = 'forensics_packages_startup.sh'
# FORENSICS_STARTUP_SCRIPT_AWS = 'forensics_packages_startup_aws.sh'
# FORENSICS_STARTUP_SCRIPT_GCP = FORENSICS_STARTUP_SCRIPT
# FORENSICS_STARTUP_SCRIPT_AZ = FORENSICS_STARTUP_SCRIPT
# EBS_SNAPSHOT_COPY_SCRIPT_AWS = 'ebs_snapshot_copy_aws.sh'
# def ReadStartupScript(filename: Optional[str] = '') -> str:


import base64
import hashlib
import sshpubkeys
from time import sleep
from typing import Optional, List, Dict, TYPE_CHECKING, Tuple, Any
from msrestazure import azure_exceptions
from azure.storage import blob
from azure.core import exceptions
from azure.mgmt import compute as compute_sdk
from azure.mgmt.compute.v2020_05_01 import models
from libcloudforensics import logging_utils
from libcloudforensics import errors
from libcloudforensics.providers.azure.internal import compute_base_resource  # pylint: disable=line-too-long, ungrouped-imports
from libcloudforensics.providers.azure.internal import common  # pylint: disable=line-too-long, ungrouped-imports
from libcloudforensics.scripts import utils
  from libcloudforensics.providers.azure.internal import account  # pylint: disable=cyclic-import

    Args:
      az_account (AZAccount): An Azure account object.
      resource_id (str): The Azure ID of the snapshot.
      name (str): The snapshot name.
      region (str): The region in which the snapshot is located.
      source_disk (AZComputeDisk): The disk from which the snapshot was taken.
    """
    super().__init__(az_account,
                     resource_id,
                     name,
                     region)

    self.disk = source_disk

  def Delete(self) -> None:
    """Delete a snapshot.

    Raises:
      ResourceDeletionError: If the snapshot could not be deleted.
    """

    try:
      logger.info('Deleting snapshot: {0:s}'.format(self.name))
      request = self.compute_client.snapshots.begin_delete(
          self.resource_group_name, self.name)
      while not request.done():
        sleep(5)  # Wait 5 seconds before checking snapshot status again
      logger.info('Snapshot {0:s} successfully deleted.'.format(self.name))
    except azure_exceptions.CloudError as exception:

# Path: libcloudforensics/logging_utils.py
# def _GenerateColorSequences() -> List[str]:
#   def __init__(self,
#                colorize: bool = True,
#                random_color: bool = False,
#                **kwargs: str) -> None:
#   def format(self, record: logging.LogRecord) -> str:
# def SetUpLogger(name: str, no_newline: bool = False) -> None:
# def GetLogger(name: str) -> logging.Logger:
# COLOR_SEQS = _GenerateColorSequences()
# RESET_SEQ = '\u001b[0m'
# BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = COLOR_SEQS[8:16]
# BG_RED = '\u001b[41m'  # Red background
# BOLD = '\u001b[1m'  # Bold / bright modifier
# LOG_FORMAT = ('[%(asctime)s] [{0:s}{color:s}%(name)-20s{1:s}] %(levelname)-8s'
#               ' %(message)s')
# LEVEL_COLOR_MAP = {
#     'WARNING': YELLOW,
#     'INFO': WHITE,
#     'DEBUG': BLUE,
#     'CRITICAL': BOLD + BG_RED + WHITE,
#     'ERROR': RED
# }
# class Formatter(logging.Formatter):
# 
# Path: libcloudforensics/errors.py
# class LCFError(Exception):
# class CredentialsConfigurationError(LCFError):
# class InvalidFileFormatError(LCFError):
# class InvalidNameError(LCFError):
# class ResourceNotFoundError(LCFError):
# class ResourceCreationError(LCFError):
# class ResourceDeletionError(LCFError):
# class InstanceStateChangeError(LCFError):
# class ServiceAccountRemovalError(LCFError):
# class InstanceProfileCreationError(LCFError):
# class OperationFailedError(LCFError):
# class TransferCreationError(LCFError):
# class TransferExecutionError(LCFError):
# class ResourceAlreadyExistsError(LCFError):
#   def __init__(self,
#                message: str,
#                name: str) -> None:
# 
# Path: libcloudforensics/providers/azure/internal/compute_base_resource.py
# class AZComputeResource:
#   def __init__(self,
#                az_account: 'account.AZAccount',
#                resource_id: str,
#                name: str,
#                region: str,
#                zones: Optional[List[str]] = None) -> None:
#   def compute_client(self) -> compute_sdk.ComputeManagementClient:
# 
# Path: libcloudforensics/providers/azure/internal/common.py
# REGEX_DISK_NAME = re.compile('^[\\w]{1,80}$')
# REGEX_SNAPSHOT_NAME = re.compile('^(?=.{1,80}$)[a-zA-Z0-9]([\\w,-]*[\\w])?$')
# REGEX_ACCOUNT_STORAGE_NAME = re.compile('^[a-z0-9]{1,24}$')
# REGEX_COMPUTE_RESOURCE_ID = re.compile(
#     '/subscriptions/.+/resourceGroups/.+/providers/Microsoft.Compute/.+/.+')
# DEFAULT_DISK_COPY_PREFIX = 'evidence'
# UBUNTU_1804_SKU = '18.04-LTS'
# def _ParseCredentialsFile(profile_name: str) -> Dict[str, Any]:
# def _CheckAzureCliCredentials() -> Optional[str]:
# def GetCredentials(profile_name: Optional[str] = None
#                    ) -> Tuple[str, DefaultAzureCredential]:
# def ExecuteRequest(
#     client: Any,
#     func: str,
#     kwargs: Optional[Dict[str, str]] = None) -> List[Any]:
# def GenerateDiskName(snapshot: 'compute.AZComputeSnapshot',
#                      disk_name_prefix: Optional[str] = None) -> str:
# 
# Path: libcloudforensics/scripts/utils.py
# FORENSICS_STARTUP_SCRIPT = 'forensics_packages_startup.sh'
# FORENSICS_STARTUP_SCRIPT_AWS = 'forensics_packages_startup_aws.sh'
# FORENSICS_STARTUP_SCRIPT_GCP = FORENSICS_STARTUP_SCRIPT
# FORENSICS_STARTUP_SCRIPT_AZ = FORENSICS_STARTUP_SCRIPT
# EBS_SNAPSHOT_COPY_SCRIPT_AWS = 'ebs_snapshot_copy_aws.sh'
# def ReadStartupScript(filename: Optional[str] = '') -> str:


# Path: libcloudforensics/providers/azure/internal/compute.py
import base64
import hashlib
import sshpubkeys
from time import sleep
from typing import Optional, List, Dict, TYPE_CHECKING, Tuple, Any
from msrestazure import azure_exceptions
from azure.storage import blob
from azure.core import exceptions
from azure.mgmt import compute as compute_sdk
from azure.mgmt.compute.v2020_05_01 import models
from libcloudforensics import logging_utils
from libcloudforensics import errors
from libcloudforensics.providers.azure.internal import compute_base_resource  # pylint: disable=line-too-long, ungrouped-imports
from libcloudforensics.providers.azure.internal import common  # pylint: disable=line-too-long, ungrouped-imports
from libcloudforensics.scripts import utils
  from libcloudforensics.providers.azure.internal import account  # pylint: disable=cyclic-import


    Args:
      az_account (AZAccount): An Azure account object.
      resource_id (str): The Azure ID of the snapshot.
      name (str): The snapshot name.
      region (str): The region in which the snapshot is located.
      source_disk (AZComputeDisk): The disk from which the snapshot was taken.
    """
    super().__init__(az_account,
                     resource_id,
                     name,
                     region)

    self.disk = source_disk

  def Delete(self) -> None:
    """Delete a snapshot.

    Raises:
      ResourceDeletionError: If the snapshot could not be deleted.
    """

    try:
      logger.info('Deleting snapshot: {0:s}'.format(self.name))
      request = self.compute_client.snapshots.begin_delete(
          self.resource_group_name, self.name)
      while not request.done():
        sleep(5)  # Wait 5 seconds before checking snapshot status again
      logger.info('Snapshot {0:s} successfully deleted.'.format(self.name))
    except azure_exceptions.CloudError as exception:

      raise errors.ResourceDeletionError(