# Path: testbench/servers/iam_rest_server.py
# _IAM_HANDLER_PATH = "/iamapi"
# def sign_blob(service_account):
# def get_iam_app():
# 
# Path: testbench/servers/projects_rest_server.py
# _PROJECTS_HANDLER_PATH = "/storage/v1/projects"
# def get_projects_app(db):
#     def projects_get(project_id):
#     def hmac_keys_insert(project_id):
#     def hmac_keys_list(project_id):
#     def hmac_keys_delete(project_id, access_id):
#     def hmac_keys_get(project_id, access_id):
#     def hmac_keys_update(project_id, access_id):


import argparse
import datetime
import httpbin
import json
import logging
import flask
import gcs as gcs_type
import testbench
from google.protobuf import json_format
from werkzeug import serving
from werkzeug.middleware.dispatcher import DispatcherMiddleware
from google.storage.v2 import storage_pb2
from testbench.servers import iam_rest_server, projects_rest_server

@gcs.route("/b/<bucket_name>/notificationConfigs", methods=["POST"])
@retry_test(method="storage.notifications.insert")
def bucket_notification_insert(bucket_name):
    bucket = db.get_bucket(bucket_name, None)
    return bucket.insert_notification(flask.request.data, None)


@gcs.route("/b/<bucket_name>/notificationConfigs/<notification_id>")
@retry_test(method="storage.notifications.get")
def bucket_notification_get(bucket_name, notification_id):
    bucket = db.get_bucket(bucket_name, None)
    return bucket.get_notification(notification_id, None)


@gcs.route("/b/<bucket_name>/notificationConfigs/<notification_id>", methods=["DELETE"])
@retry_test(method="storage.notifications.delete")
def bucket_notification_delete(bucket_name, notification_id):
    bucket = db.get_bucket(bucket_name, None)
    bucket.delete_notification(notification_id, None)
    return ""


@gcs.route("/b/<bucket_name>/iam")
@retry_test(method="storage.buckets.getIamPolicy")
def bucket_get_iam_policy(bucket_name):
    db.insert_test_bucket()
    bucket = db.get_bucket(bucket_name, None)
    response = json_format.MessageToDict(bucket.iam_policy)
    response["kind"] = "storage#policy"

# Path: testbench/servers/iam_rest_server.py
# _IAM_HANDLER_PATH = "/iamapi"
# def sign_blob(service_account):
# def get_iam_app():
# 
# Path: testbench/servers/projects_rest_server.py
# _PROJECTS_HANDLER_PATH = "/storage/v1/projects"
# def get_projects_app(db):
#     def projects_get(project_id):
#     def hmac_keys_insert(project_id):
#     def hmac_keys_list(project_id):
#     def hmac_keys_delete(project_id, access_id):
#     def hmac_keys_get(project_id, access_id):
#     def hmac_keys_update(project_id, access_id):


# Path: testbench/rest_server.py
import argparse
import datetime
import httpbin
import json
import logging
import flask
import gcs as gcs_type
import testbench
from google.protobuf import json_format
from werkzeug import serving
from werkzeug.middleware.dispatcher import DispatcherMiddleware
from google.storage.v2 import storage_pb2
from testbench.servers import iam_rest_server, projects_rest_server


@gcs.route("/b/<bucket_name>/notificationConfigs", methods=["POST"])
@retry_test(method="storage.notifications.insert")
def bucket_notification_insert(bucket_name):
    bucket = db.get_bucket(bucket_name, None)
    return bucket.insert_notification(flask.request.data, None)


@gcs.route("/b/<bucket_name>/notificationConfigs/<notification_id>")
@retry_test(method="storage.notifications.get")
def bucket_notification_get(bucket_name, notification_id):
    bucket = db.get_bucket(bucket_name, None)
    return bucket.get_notification(notification_id, None)


@gcs.route("/b/<bucket_name>/notificationConfigs/<notification_id>", methods=["DELETE"])
@retry_test(method="storage.notifications.delete")
def bucket_notification_delete(bucket_name, notification_id):
    bucket = db.get_bucket(bucket_name, None)
    bucket.delete_notification(notification_id, None)
    return ""


@gcs.route("/b/<bucket_name>/iam")
@retry_test(method="storage.buckets.getIamPolicy")
def bucket_get_iam_policy(bucket_name):
    db.insert_test_bucket()
    bucket = db.get_bucket(bucket_name, None)
    response = json_format.MessageToDict(bucket.iam_policy)
    response["kind"] = "storage#policy"

    return response