#! /usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
import re
import argparse
from azure.storage.blob import (BlobServiceClient, StandardBlobTier)

parser = argparse.ArgumentParser()
parser.add_argument('-s', '--storage_account', help='storage account')
parser.add_argument('-c', '--container_name', help='container name')
parser.add_argument('-key', '--key', help='access key or SAS token')
parser.add_argument('-b', '--blob_name', help='full blob name')

args = parser.parse_args()

credential = getattr(args, 'key')
storage_account = getattr(args, 'storage_account')
container_name = getattr(args, 'container_name')
blob_name = getattr(args, 'blob_name')

if not storage_account:
    storage_account = os.environ.get('AZURE_STORAGE_ACCOUNT')
if not container_name:
    container_name = os.environ.get('AZURE_CONTAINER_NAME')
if not credential:
    credential = os.environ.get('AZURE_BLOB_KEY')

if not storage_account:
    print(
        "must provide storage_account or environment variable AZURE_STORAGE_ACCOUNT"
    )
    exit()
if not storage_account:
    print(
        "must provide container_name or environment variable AZURE_CONTAINER_NAME"
    )
    exit()
if not storage_account:
    print("must provide access_key or environment variable AZURE_BLOB_KEY")
    exit()

account_url = 'https://{storage_account}.blob.core.windows.net'.format(
    storage_account=storage_account)
service = BlobServiceClient(account_url=account_url, credential=credential)
container = service.get_container_client(container_name)
blob = container.get_blob_client(blob_name)
blob.delete_blob()
