@@ -0,0 +1,2160 @@
+%22%22%22%0ATeardown service item action for Google Storage bucket.%0A%22%22%22%0A%0Afrom __future__ import unicode_literals%0A%0Aimport json%0A%0Afrom common.methods import set_progress%0Afrom google.oauth2.credentials import Credentials%0Afrom googleapiclient.discovery import Resource as GCPResource%0Afrom googleapiclient.discovery import build%0Afrom resourcehandlers.gcp.models import GCPHandler%0A%0A%0Adef create_storage_api_wrapper(gcp_handler: GCPHandler) -%3E GCPResource:%0A    %22%22%22%0A    Using googleapiclient.discovery, build the api wrapper for the storage api:%0A    https://googleapis.github.io/google-api-python-client/docs/dyn/storage_v1.html%0A    %22%22%22%0A    credentials_dict = json.loads(gcp_handler.gcp_api_credentials)%0A    credentials = Credentials(**credentials_dict)%0A    storage_wrapper: GCPResource = build(%0A        %22storage%22, %22v1%22, credentials=credentials, cache_discovery=False%0A    )%0A    return storage_wrapper%0A%0A%0Adef delete_bucket(%0A    wrapper: GCPResource,%0A    bucket_name: str,%0A) -%3E dict:%0A    %22%22%22%0A    Create a bucket (many other aspects can be specified - see api docs for details)%0A    https://googleapis.github.io/google-api-python-client/docs/dyn/storage_v1.buckets.html#insert%0A    %22%22%22%0A    buckets_resource = wrapper.buckets()%0A    delete_request = buckets_resource.delete(bucket=bucket_name)%0A    created_bucket = delete_request.execute()%0A    return created_bucket%0A%0A%0Adef run(job=None, logger=None, **kwargs):%0A    # Get system information%0A    resource = kwargs.pop(%22resources%22).first()%0A    bucket_name = resource.attributes.get(field__name=%22bucket_name%22).value%0A    resource_handler_id = resource.attributes.get(field__name=%22google_rh_id%22).value%0A    resource_handler = GCPHandler.objects.get(id=resource_handler_id)%0A%0A    # Connecte to GCP%0A    set_progress(%22Connecting to Google Cloud...%22)%0A    wrapper = create_storage_api_wrapper(resource_handler)%0A    set_progress(%22Connection established%22)%0A%0A    # Delete the bucket%0A    set_progress('Deleting bucket %22%25s%22...' %25 bucket_name)%0A    try:%0A        delete_bucket(wrapper, bucket_name)%0A    except Exception as error:%0A        return %22FAILURE%22, f%22%7Berror%7D%22, %22%22%0A%0A    set_progress('Bucket %22%25s%22 was deleted' %25 bucket_name)%0A    return %22SUCCESS%22, %22%22, %22%22%0A

Add Delete script