diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 736a08fd..e8e1e5a9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,7 +35,7 @@ jobs: needs: Lint strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11"] name: Test Python ${{ matrix.python-version }} steps: - uses: actions/checkout@v3 diff --git a/README.md b/README.md index 3631e96e..81c3a099 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ You can create Rest APIs: ```python from goblet import Goblet, jsonify, goblet_entrypoint -app = Goblet(function_name="goblet_example") +app = Goblet(function_name="goblet-example") goblet_entrypoint(app) @app.route('/home') @@ -37,7 +37,7 @@ You can also create other GCP resources that are related to your REST api: ```python from goblet import Goblet, jsonify, goblet_entrypoint -app = Goblet(function_name="goblet_example") +app = Goblet(function_name="goblet-example") goblet_entrypoint(app) # Scheduled job @@ -69,13 +69,14 @@ $ curl https://api.uc.gateway.dev/home {"hello": "world"} ``` -> Note: Due to breaking changes in Cloudfunctions you will need to wrap your goblet class in a function. See [issue #88](https://github.com/goblet/goblet/issues/88). In the latest goblet version (0.5.0) there is a helper function `goblet_entrypoint` that can be used as well. +> Note: Due to breaking changes in Cloudfunctions you will need to wrap your goblet class in a function. See [issue #88](https://github.com/goblet/goblet/issues/88). In the latest goblet version (0.5.0) there is a helper function `goblet_entrypoint` that can be used as well. > `goblet_entrypoint(app)` ## Resources Supported #### Infrastructure + * vpc connector * redis * api gateway @@ -84,15 +85,18 @@ $ curl https://api.uc.gateway.dev/home * bq spark stored procedures #### Backends + * cloudfunction * cloudfunction V2 * cloudrun #### Routing + * api gateway * http #### Handlers + * pubsub * scheduler * storage @@ -103,6 +107,7 @@ $ curl https://api.uc.gateway.dev/home * uptime checks #### Alerts + * Backend Alerts * Uptime Alerts * PubSub DLQ Alerts @@ -173,7 +178,7 @@ Let's take a look at the main.py file: ```python from goblet import Goblet, goblet_entrypoint -app = Goblet(function_name="goblet_example") +app = Goblet(function_name="goblet-example") goblet_entrypoint(app) @app.route('/home') @@ -190,7 +195,7 @@ Running your functions locally for testing and debugging is easy to do with gobl ```python from goblet import Goblet -app = Goblet(function_name="goblet_example") +app = Goblet(function_name="goblet-example") goblet_entrypoint(app) @app.route('/home') @@ -345,7 +350,6 @@ Please file any issues, bugs or feature requests as an issue on our [GitHub](htt ☑ Automatically add IAM invoker bindings on the backend based on deployed handlers \ ☑ [Uptime Checks](https://cloud.google.com/monitoring/uptime-checks) - ## Want to Contribute If you would like to contribute to the library (e.g. by improving the documentation, solving a bug or adding a cool new feature) please follow the [contribution guide](CONTRIBUTING.md) and submit a [pull request](https://github.com/goblet/goblet/pulls). diff --git a/docs/source/index.rst b/docs/source/index.rst index 0c3666d8..071b550b 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -27,7 +27,7 @@ You can create Rest APIs: from goblet import Goblet - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") @app.route('/home') def home(): diff --git a/docs/source/local.rst b/docs/source/local.rst index d68d2458..ec71fd28 100644 --- a/docs/source/local.rst +++ b/docs/source/local.rst @@ -14,7 +14,7 @@ You can have a custom local name by setting the local param in the goblet class from goblet import Goblet - app = Goblet(function_name="goblet_example", local='test') + app = Goblet(function_name="goblet-example", local='test') Then run ``goblet local test`` diff --git a/docs/source/quickstart.rst b/docs/source/quickstart.rst index 802795eb..6e836bc1 100644 --- a/docs/source/quickstart.rst +++ b/docs/source/quickstart.rst @@ -58,7 +58,7 @@ Let's take a look at the main.py file: from goblet import Goblet, goblet_entrypoint - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") goblet_entrypoint(app) @app.route('/home') diff --git a/goblet/__version__.py b/goblet/__version__.py index 5c51ae46..dafc5cff 100644 --- a/goblet/__version__.py +++ b/goblet/__version__.py @@ -1,4 +1,4 @@ -VERSION = (0, 13, 3) +VERSION = (0, 14, 0) __version__ = ".".join(map(str, VERSION)) diff --git a/goblet/alerts/alert_conditions.py b/goblet/alerts/alert_conditions.py index 900d8958..8f01d9e6 100644 --- a/goblet/alerts/alert_conditions.py +++ b/goblet/alerts/alert_conditions.py @@ -191,10 +191,12 @@ def __init__(self, name, filter, **kwargs) -> None: super().__init__( name=name, log_match={ - "filter": filter - if kwargs.get("replace_filter", False) - else 'resource.type="{monitoring_type}"\nresource.labels.{monitoring_label_key}="{resource_name}"\n' - + filter + "filter": ( + filter + if kwargs.get("replace_filter", False) + else 'resource.type="{monitoring_type}"\nresource.labels.{monitoring_label_key}="{resource_name}"\n' + + filter + ) }, ) self.default_alert_kwargs = { diff --git a/goblet/app.py b/goblet/app.py index faffdd98..4f5fe048 100644 --- a/goblet/app.py +++ b/goblet/app.py @@ -29,7 +29,7 @@ class Goblet(Goblet_Decorators, Resource_Manager): def __init__( self, function_name="goblet", - backend="cloudfunction", + backend="cloudfunctionv2", local="local", cors=None, routes_type="apigateway", diff --git a/goblet/tests/test_alerts.py b/goblet/tests/test_alerts.py index aab175d4..9a4732a4 100644 --- a/goblet/tests/test_alerts.py +++ b/goblet/tests/test_alerts.py @@ -18,7 +18,7 @@ class TestAlerts: def test_add_alert(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example", backend="cloudfunction") metric_alert = BackendAlert( "metric", @@ -79,7 +79,7 @@ def test_deploy_alerts(self, monkeypatch): reset_replay_count() - app = Goblet(function_name="alerts-test") + app = Goblet(function_name="alerts-test", backend="cloudfunction") metric_alert = BackendAlert( "metric", @@ -169,7 +169,7 @@ def test_destroy_alerts(self, monkeypatch): reset_replay_count() - app = Goblet(function_name="alerts-test") + app = Goblet(function_name="alerts-test", backend="cloudfunction") metric_alert = BackendAlert( "metric", @@ -210,7 +210,7 @@ def test_sync_alerts(self, monkeypatch): monkeypatch.setenv("G_TEST_NAME", "alerts-sync") monkeypatch.setenv("G_HTTP_TEST", "REPLAY") - app = Goblet(function_name="alerts-test") + app = Goblet(function_name="alerts-test", backend="cloudfunction") custom_alert = BackendAlert( "custom", diff --git a/goblet/tests/test_apigateway.py b/goblet/tests/test_apigateway.py index ec3918a6..4cdb12b9 100644 --- a/goblet/tests/test_apigateway.py +++ b/goblet/tests/test_apigateway.py @@ -87,7 +87,7 @@ def test_deploy_api_gateway(self, monkeypatch, requests_mock): "definitions": {}, } - app = Goblet("goblet_routes") + app = Goblet("goblet_routes", backend="cloudfunction") app.apigateway("goblet-routes", "URL", openapi_dict=openapi_dict) app.deploy(force=True, skip_handlers=True, skip_backend=True) diff --git a/goblet/tests/test_app.py b/goblet/tests/test_app.py index 1a7c7952..5c2af08c 100644 --- a/goblet/tests/test_app.py +++ b/goblet/tests/test_app.py @@ -54,8 +54,8 @@ def start_response_status(status, response_headers, exc_info=None): class TestDecoraters: def test_add(self): - app1 = Goblet("test") - app2 = Goblet("test") + app1 = Goblet("test", backend="cloudfunction") + app2 = Goblet("test", backend="cloudfunction") @app1.route("/home") @app2.route("/home2") @@ -76,8 +76,8 @@ def dummy_function2(self, home_id): ] def test_add_current_request(self): - app1 = Goblet("test") - app2 = Goblet("test") + app1 = Goblet("test", backend="cloudfunction") + app2 = Goblet("test", backend="cloudfunction") @app2.route("/app2") def dummy_function(): diff --git a/goblet/tests/test_bqremotefunction.py b/goblet/tests/test_bqremotefunction.py index 7e532f58..324eb438 100644 --- a/goblet/tests/test_bqremotefunction.py +++ b/goblet/tests/test_bqremotefunction.py @@ -8,7 +8,7 @@ class TestBqRemoteFunction: def test_register_bqremotefunction(self, monkeypatch): - app = Goblet(function_name="bqremotefunction_test") + app = Goblet(function_name="bqremotefunction_test", backend="cloudfunction") monkeypatch.setenv("GOOGLE_PROJECT", "TEST_PROJECT") monkeypatch.setenv("GOOGLE_LOCATION", "us-central1") @@ -50,7 +50,7 @@ def test_call_bqremotefunction_vectorize(self, monkeypatch): monkeypatch.setenv("GOOGLE_LOCATION", "us-central1") test_name = "bqremotefunction_test" - app = Goblet(function_name=test_name) + app = Goblet(function_name=test_name, backend="cloudfunction") @app.bqremotefunction(dataset_id="blogs", vectorize_func=True) def function_test(x: List[int], y: List[str]) -> List[str]: @@ -77,7 +77,7 @@ def test_call_bqremotefunction(self, monkeypatch): monkeypatch.setenv("GOOGLE_LOCATION", "us-central1") test_name = "bqremotefunction_test" - app = Goblet(function_name=test_name) + app = Goblet(function_name=test_name, backend="cloudfunction") @app.bqremotefunction(dataset_id="blogs") def function_test(x: int, y: int) -> int: @@ -107,7 +107,7 @@ def test_deploy_bqremotefunction(self, monkeypatch): monkeypatch.setenv("G_HTTP_TEST", "REPLAY") test_name = "bqremotefunction_test" - app = Goblet(function_name=test_name) + app = Goblet(function_name=test_name, backend="cloudfunction") @app.bqremotefunction(dataset_id="blogs") def string_test_blogs_1(x: str, y: str) -> str: @@ -170,7 +170,7 @@ def test_deploy_bqremotefunction_region(self, monkeypatch, requests_mock): requests_mock.register_uri("PUT", "https://storage.googleapis.com/mock") test_name = "bq-test-region" - app = Goblet(function_name=test_name) + app = Goblet(function_name=test_name, backend="cloudfunction") @app.bqremotefunction(dataset_id="test", location="US") def string_test_blogs_1(x: str, y: str) -> str: @@ -228,7 +228,7 @@ def test_destroy_bqremotefunction(self, monkeypatch): monkeypatch.setenv("G_HTTP_TEST", "REPLAY") test_name = "bqremotefunction_test" - app = Goblet(function_name=test_name) + app = Goblet(function_name=test_name, backend="cloudfunction") @app.bqremotefunction(dataset_id="blogs") def string_test_blogs_1(x: str, y: str) -> str: @@ -260,7 +260,7 @@ def test_destroy_bqremotefunction_region(self, monkeypatch): monkeypatch.setenv("G_HTTP_TEST", "REPLAY") test_name = "bqremotefunction_test" - app = Goblet(function_name=test_name) + app = Goblet(function_name=test_name, backend="cloudfunction") @app.bqremotefunction(dataset_id="test", location="US") def string_test_blogs_1(x: str, y: str) -> str: diff --git a/goblet/tests/test_bqsparkstoredprocedure.py b/goblet/tests/test_bqsparkstoredprocedure.py index 6f94c5fb..dd880e68 100644 --- a/goblet/tests/test_bqsparkstoredprocedure.py +++ b/goblet/tests/test_bqsparkstoredprocedure.py @@ -13,7 +13,9 @@ class TestBqSparkStoredProcedure: def test_register_bqsparkstoredprocedure(self, monkeypatch): - app = Goblet(function_name="bqsparkstoredprocedure_test") + app = Goblet( + function_name="bqsparkstoredprocedure_test", backend="cloudfunction" + ) monkeypatch.setenv("GOOGLE_PROJECT", "goblet") monkeypatch.setenv("GOOGLE_LOCATION", "us") reset_replay_count() @@ -62,7 +64,7 @@ def test_deploy_bqsparkstoredprocedure(self, monkeypatch): test_name = "bqsparkstoredprocedure_test" procedure_name = "test_spark_stored_procedure" - app = Goblet(function_name=test_name) + app = Goblet(function_name=test_name, backend="cloudfunction") test_dataset_id = "blogs" def spark_handler(): @@ -112,7 +114,7 @@ def test_destroy_bqsparkstoredprocedure(self, monkeypatch): reset_replay_count() test_name = "bqsparkstoredprocedure_test" - app = Goblet(function_name=test_name) + app = Goblet(function_name=test_name, backend="cloudfunction") test_dataset_id = "blogs" def spark_handler(): @@ -139,7 +141,7 @@ def test_deploy_bqsparkstoredprocedure_remote_code(self, monkeypatch): reset_replay_count() procedure_name = "test_spark_stored_procedure" - app = Goblet(function_name=test_name) + app = Goblet(function_name=test_name, backend="cloudfunction") test_dataset_id = "blogs" with open("spark.py", "w") as f: @@ -199,7 +201,7 @@ def test_destroy_bqsparkstoredprocedure_remote_code(self, monkeypatch): test_name = "bqsparkstoredprocedure-remote-deploy" procedure_name = "test_spark_stored_procedure" - app = Goblet(function_name=test_name) + app = Goblet(function_name=test_name, backend="cloudfunction") test_dataset_id = "blogs" app.bqsparkstoredprocedure( diff --git a/goblet/tests/test_cloudtasks.py b/goblet/tests/test_cloudtasks.py index 4589bd74..0dcd79cf 100644 --- a/goblet/tests/test_cloudtasks.py +++ b/goblet/tests/test_cloudtasks.py @@ -10,7 +10,7 @@ class TestCloudTasks: def test_add_cloudtaskqueues(self): app = Goblet( - function_name="goblet_example", + function_name="goblet-example", config={"cloudtask": {"serviceAccount": "service-account@goblet.com"}}, ) @@ -28,7 +28,7 @@ def test_deploy_cloudtaskqueue(self, monkeypatch): monkeypatch.setenv("G_HTTP_TEST", "REPLAY") app = Goblet( - function_name="goblet_example", + function_name="goblet-example", config={"cloudtask": {"serviceAccount": "service-account@goblet.com"}}, ) @@ -58,6 +58,7 @@ def test_destroy_cloudtaskqueue(self, monkeypatch): app = Goblet( function_name="goblet_example", config={"cloudtask": {"serviceAccount": "service-account@goblet.com"}}, + backend="cloudfunction", ) client: CloudTaskClient = app.cloudtaskqueue( # noqa: F841 @@ -80,8 +81,9 @@ def test_enqueue_task(self, monkeypatch): monkeypatch.setenv("G_HTTP_TEST", "REPLAY") app = Goblet( - function_name="goblet_example", + function_name="goblet-example", config={"cloudtask": {"serviceAccount": "service-account@goblet.com"}}, + backend="cloudfunction", ) client: CloudTaskClient = app.cloudtaskqueue(name="cloudtaskqueue") @@ -137,7 +139,7 @@ def test_build_task(self): ) def test_duplicate_targets(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") with pytest.raises(Exception): @@ -150,7 +152,7 @@ def dummy_function2(task): return {} def test_handle_cloud_task(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") @app.cloudtasktarget(name="target") def dummy_function(task): diff --git a/goblet/tests/test_deployer.py b/goblet/tests/test_deployer.py index 29726dc3..83cd9e2f 100644 --- a/goblet/tests/test_deployer.py +++ b/goblet/tests/test_deployer.py @@ -20,7 +20,7 @@ def test_deploy_http_function(self, monkeypatch, requests_mock): requests_mock.register_uri("PUT", "https://storage.googleapis.com/mock") - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example", backend="cloudfunction") setattr(app, "entrypoint", "app") app.handlers["http"] = HTTP("name", app) @@ -181,7 +181,7 @@ def test_destroy_http_function(self, monkeypatch): monkeypatch.setenv("G_TEST_NAME", "deployer-function-destroy") monkeypatch.setenv("G_HTTP_TEST", "REPLAY") - app = Goblet(function_name="goblet_test_app") + app = Goblet(function_name="goblet_test_app", backend="cloudfunction") app.destroy() @@ -199,7 +199,7 @@ def test_destroy_http_function_all(self, monkeypatch): monkeypatch.setenv("G_TEST_NAME", "deployer-function-destroy-all") monkeypatch.setenv("G_HTTP_TEST", "REPLAY") - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet_example", backend="cloudfunction") app.destroy(all=True) @@ -219,6 +219,7 @@ def test_set_iam_bindings(self, monkeypatch, requests_mock): app = Goblet( function_name="goblet_bindings", config={"bindings": bindings}, + backend="cloudfunction", ) setattr(app, "entrypoint", "app") @@ -245,7 +246,7 @@ def test_cloudfunction_delta(self, monkeypatch, requests_mock): headers={"x-goog-hash": "crc32c=+kjoHA==, md5=QcWxCkEOHzBSBgerQcjMEg=="}, ) - app = Goblet(function_name="goblet_test_app") + app = Goblet(function_name="goblet_test_app", backend="cloudfunction") app_backend = app.backend_class(app) @@ -443,7 +444,7 @@ def test_cloudfunction_build_tags(self, monkeypatch, requests_mock): monkeypatch.setenv("GOBLET_ARTIFACT_BUCKET", "bucket") requests_mock.register_uri("PUT", "https://storage.googleapis.com/mock") - app = Goblet(function_name="cloudfunction-build-tags") + app = Goblet(function_name="cloudfunction-build-tags", backend="cloudfunction") goblet_entrypoint(app) setattr(app, "entrypoint", "app") @@ -463,7 +464,7 @@ def test_cloudfunction_artifact_tag(self, monkeypatch): monkeypatch.setenv("GOBLET_ARTIFACT_BUCKET", "bucket") monkeypatch.setenv("GOBLET_ARTIFACT_TAG", artifact_tag) - app = Goblet(function_name="cloudfunction-build-tags") + app = Goblet(function_name="cloudfunction-build-tags", backend="cloudfunction") goblet_entrypoint(app) setattr(app, "entrypoint", "app") diff --git a/goblet/tests/test_eventarc.py b/goblet/tests/test_eventarc.py index 41c1c535..ab5bb0b6 100644 --- a/goblet/tests/test_eventarc.py +++ b/goblet/tests/test_eventarc.py @@ -12,7 +12,7 @@ class TestEventArc: def test_add_trigger_topic(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") app.eventarc(topic="test")(dummy_function) @@ -28,7 +28,7 @@ def test_add_trigger_topic(self): ] def test_add_trigger_event_filter(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") app.eventarc( event_filters=[ @@ -50,7 +50,7 @@ def test_add_trigger_event_filter(self): ] def test_call_eventarc_topic(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") mock = Mock() app.eventarc(topic="test")(mock_dummy_function(mock)) @@ -66,7 +66,7 @@ def test_call_eventarc_topic(self): assert mock.call_count == 1 def test_call_eventarc_topic_no_response(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") app.eventarc(topic="test")(mock_dummy_function(dummy_function)) diff --git a/goblet/tests/test_http.py b/goblet/tests/test_http.py index 5ab339b5..7490d5e4 100644 --- a/goblet/tests/test_http.py +++ b/goblet/tests/test_http.py @@ -5,7 +5,7 @@ class TestHttp: def test_call_route(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") mock = Mock() app.http()(mock_dummy_function(mock)) @@ -20,7 +20,7 @@ def test_call_route(self): assert mock.call_count == 1 def test_call_headers_dict(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") mock = Mock() @app.http(headers={"test": 1, "test2": 2}) @@ -50,7 +50,7 @@ def mock_function(request): assert mock.call_count == 1 def test_call_headers_set(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") mock = Mock() @app.http(headers={"test", "also_test"}) diff --git a/goblet/tests/test_jobs.py b/goblet/tests/test_jobs.py index 493aa64f..34f225b5 100644 --- a/goblet/tests/test_jobs.py +++ b/goblet/tests/test_jobs.py @@ -16,7 +16,7 @@ class TestJobs: def test_add_job(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") app.job("test")(dummy_function) @@ -25,7 +25,7 @@ def test_add_job(self): assert jobs.resources[f"{app.function_name}-test"].get(0) def test_add_job_tasks(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") app.job("test")(dummy_function) app.job("test", task_id=1)(dummy_function) @@ -38,7 +38,7 @@ def test_add_job_tasks(self): assert jobs.resources[f"{app.function_name}-test"].get(2) def test_add_job_tasks_valid_kwargs(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") with pytest.raises(Exception): app.job("test", task_id=1, schedule="* * * * *")(dummy_function) @@ -47,7 +47,7 @@ def test_add_job_tasks_valid_kwargs(self): app.job("test", task_id=1, extra_arg="test")(dummy_function) def test_add_job_with_schedule(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") app.job("test", schedule="* * * * *")(dummy_function) @@ -60,13 +60,13 @@ def test_add_job_with_schedule(self): assert scheduler.resources["schedule-job-test"]["uri"] def test_call_job(self, monkeypatch): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet_example", backend="cloudfunction") monkeypatch.setenv("CLOUD_RUN_TASK_INDEX", "0") mock = Mock() mock2 = Mock() - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet_example", backend="cloudfunction") app.job("test")(mock_dummy_function(mock)) app.job("test", task_id=1)(mock_dummy_function(mock2)) diff --git a/goblet/tests/test_permissions.py b/goblet/tests/test_permissions.py index f02fad72..64a47f3d 100644 --- a/goblet/tests/test_permissions.py +++ b/goblet/tests/test_permissions.py @@ -23,7 +23,7 @@ def test_gcp_generic_resource_permissions(self): assert len(permissions) == 5 def test_get_permissions(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") app.pubsub_subscription("test")(dummy_function) permissions = app.get_permissions() diff --git a/goblet/tests/test_pubsub.py b/goblet/tests/test_pubsub.py index a23939e1..eee500f4 100644 --- a/goblet/tests/test_pubsub.py +++ b/goblet/tests/test_pubsub.py @@ -9,7 +9,7 @@ class TestPubSub: def test_add_pubsub_topics(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") app.pubsub_topic(name="pubsub_topic01") app.pubsub_topic(name="pubsub_topic02") @@ -24,7 +24,7 @@ def test_create_pubsub_topic(self, monkeypatch): monkeypatch.setenv("G_TEST_NAME", "pubsub-deploy") monkeypatch.setenv("G_HTTP_TEST", "REPLAY") - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") client: PubSubClient = app.pubsub_topic(name="test") # noqa: F841 @@ -49,7 +49,7 @@ def test_destroy_pubsub_topic(self, monkeypatch): monkeypatch.setenv("G_TEST_NAME", "pubsub-deploy") monkeypatch.setenv("G_HTTP_TEST", "REPLAY") - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") client: PubSubClient = app.pubsub_topic(name="test") # noqa: F841 @@ -73,7 +73,7 @@ def test_update_pubsub_topic(self, monkeypatch): monkeypatch.setenv("G_TEST_NAME", "pubsub-update") monkeypatch.setenv("G_HTTP_TEST", "REPLAY") - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") app.pubsub_topic(name="test") # noqa: F841 @@ -124,7 +124,7 @@ def test_deploy_local(self, monkeypatch): monkeypatch.setenv("PUBSUB_EMULATOR_HOST", "localhost:8085") reset_replay_count() - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") app.pubsub_topic(name="test") # noqa: F841 diff --git a/goblet/tests/test_pubsub_subscription.py b/goblet/tests/test_pubsub_subscription.py index 7019b69f..9a1a182b 100644 --- a/goblet/tests/test_pubsub_subscription.py +++ b/goblet/tests/test_pubsub_subscription.py @@ -22,7 +22,7 @@ class TestPubSubSubscription: def test_add_topic(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") app.pubsub_subscription("test")(dummy_function) @@ -34,7 +34,7 @@ def test_add_topic(self): ) def test_add_topic_with_subscription(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") app.pubsub_subscription("test", use_subscription="true")(dummy_function) @@ -46,7 +46,7 @@ def test_add_topic_with_subscription(self): ) def test_add_topic_attributes(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example", backend="cloudfunction") app.pubsub_subscription("test", attributes={"test": True})(dummy_function) @@ -65,7 +65,7 @@ def test_add_topic_attributes(self): ) def test_add_topic_filter(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example", backend="cloudfunction") app.pubsub_subscription("test", filter='attributes.test = "1"')(dummy_function) @@ -77,7 +77,7 @@ def test_add_topic_filter(self): ) def test_call_topic(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example", backend="cloudfunction") @app.pubsub_subscription("test") def dummy_function(data): @@ -93,7 +93,7 @@ def dummy_function(data): app(event, mock_context) def test_call_responses(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example", backend="cloudfunction") @app.pubsub_subscription("test") def dummy_function(data): @@ -117,7 +117,7 @@ def dummy_function2(data): assert app(event, mock_context2) == "success" def test_call_topic_attributes(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example", backend="cloudfunction") @app.pubsub_subscription("test", attributes={"t": 1}) def dummy_function(data): @@ -143,7 +143,7 @@ def dummy_function2(data): app(event3, mock_context) def test_call_subscription(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet_example", backend="cloudfunction") mock = Mock() app.pubsub_subscription("test")(mock_dummy_function(mock)) @@ -162,7 +162,7 @@ def test_call_subscription(self): assert mock.call_count == 1 def test_call_subscription_attributes(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet_example", backend="cloudfunction") mock = Mock() app.pubsub_subscription("test", attributes={"t": 1})(mock_dummy_function(mock)) @@ -188,7 +188,7 @@ def test_call_subscription_attributes(self): assert mock.call_count == 1 def test_context(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet_example", backend="cloudfunction") @app.pubsub_subscription("test") def dummy_function(data): @@ -210,7 +210,7 @@ def test_deploy_pubsub(self, monkeypatch, requests_mock): requests_mock.register_uri("PUT", "https://storage.googleapis.com/mock") - app = Goblet(function_name="goblet_topic") + app = Goblet(function_name="goblet_topic", backend="cloudfunction") setattr(app, "entrypoint", "app") app.pubsub_subscription("test-topic")(dummy_function) @@ -245,6 +245,7 @@ def test_deploy_pubsub_cross_project(self, monkeypatch, requests_mock): app = Goblet( function_name="goblet-topic-cross-project", config={"pubsub": {"serviceAccountEmail": service_account}}, + backend="cloudfunction", ) setattr(app, "entrypoint", "app") @@ -270,6 +271,7 @@ def test_deploy_pubsub_subscription_with_filter(self, monkeypatch): app = Goblet( function_name="goblet-topic-subscription-filter", config={"pubsub": {"serviceAccountEmail": service_account}}, + backend="cloudfunction", ) setattr(app, "entrypoint", "app") @@ -295,7 +297,7 @@ def test_destroy_pubsub(self, monkeypatch): pubsub = PubSub( "goblet_topic", - backend=CloudFunctionV1(Goblet()), + backend=CloudFunctionV1(Goblet(backend="cloudfunction")), resources={ "test-topic": {"trigger": {"test-topic": {}}, "subscription": {}} }, @@ -487,6 +489,7 @@ def test_deploy_pubsub_subscription_with_config(self, monkeypatch): app = Goblet( function_name="goblet-topic-subscription-config", config={"pubsub": {"serviceAccountEmail": service_account}}, + backend="cloudfunction", ) setattr(app, "entrypoint", "app") @@ -515,6 +518,7 @@ def test_deploy_pubsub_subscription_with_dlq(self, monkeypatch): app = Goblet( function_name="goblet-topic-subscription", config={"pubsub": {"serviceAccountEmail": service_account}}, + backend="cloudfunction", ) setattr(app, "entrypoint", "app") @@ -580,6 +584,7 @@ def test_deploy_pubsub_subscription_with_dlq_with_stage(self, monkeypatch): app = Goblet( function_name="goblet-topic-subscription", config={"pubsub": {"serviceAccountEmail": service_account}}, + backend="cloudfunction", ) setattr(app, "entrypoint", "app") @@ -618,6 +623,7 @@ def test_deploy_local(self, monkeypatch): app = Goblet( function_name="goblet-topic-subscription", config={"pubsub": {"serviceAccountEmail": service_account}}, + backend="cloudfunction", ) app.pubsub_subscription("test", use_subscription=True)(dummy_function) diff --git a/goblet/tests/test_redis.py b/goblet/tests/test_redis.py index 0b8cc505..2ca864d9 100644 --- a/goblet/tests/test_redis.py +++ b/goblet/tests/test_redis.py @@ -11,7 +11,7 @@ class TestRedis: def test_add_redis(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") app.redis(name="redis-test") redis = app.infrastructure["redis"] diff --git a/goblet/tests/test_routes.py b/goblet/tests/test_routes.py index 631c8418..33d25b6c 100644 --- a/goblet/tests/test_routes.py +++ b/goblet/tests/test_routes.py @@ -12,7 +12,7 @@ class TestRoutes: def test_add_base_route(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") app.route("/home")(dummy_function) @@ -25,7 +25,7 @@ def test_add_base_route(self): assert route_entry.route_function == dummy_function def test_add_route_path_params(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") app.route("/home/{home_id}", content_types={"home_id": "boolean"})( dummy_function @@ -40,7 +40,7 @@ def test_add_route_path_params(self): assert route_entry.route_function == dummy_function def test_add_multiple_methods(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") @app.route("/home", methods=["POST", "GET"]) def dummy_function(self): @@ -65,7 +65,7 @@ def dummy_function2(self): ) def test_add_multiple_routes(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") app.route("/home")(dummy_function) app.route("/home2")(dummy_function) @@ -76,7 +76,7 @@ def test_add_multiple_routes(self): assert gateway.resources["/home2"]["GET"] def test_call_tuple_response(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") @app.route("/test", methods=["POST"]) def mock_function(): @@ -91,7 +91,7 @@ def mock_function(): assert resp == ("success", 201) def test_call_tuple_with_cors_response(self): - app = Goblet(function_name="goblet_example", cors=True) + app = Goblet(function_name="goblet-example", cors=True) @app.route("/test", methods=["POST"]) def mock_function(): @@ -107,7 +107,7 @@ def mock_function(): assert resp.status_code == 201 def test_call_tuple_with_headers_response(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example", backend="cloudfunction") @app.route("/test", methods=["POST"]) def mock_function(): @@ -122,7 +122,7 @@ def mock_function(): assert resp == ("success", 201, {"x-header": "test"}) def test_call_tuple_with_cors_and_headers_response(self): - app = Goblet(function_name="goblet_example", cors=True) + app = Goblet(function_name="goblet-example", cors=True, backend="cloudfunction") @app.route("/test", methods=["POST"]) def mock_function(): @@ -139,7 +139,7 @@ def mock_function(): assert resp[2].get("x-header") == "test" def test_call_route(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example", backend="cloudfunction") mock = Mock() mock_param = Mock() @@ -169,7 +169,7 @@ def mock_function2(param): mock_param.assert_called_once_with("param") def test_call_route_list_request_body(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example", backend="cloudfunction") mock = Mock() app.route("/test", methods=["POST"])(mock_dummy_function(mock)) @@ -184,9 +184,11 @@ def test_call_route_list_request_body(self): assert mock.call_count == 1 def test_cors(self): - app = Goblet(function_name="goblet_cors") + app = Goblet(function_name="goblet_cors", backend="cloudfunction") app2 = Goblet( - function_name="goblet_cors", cors=CORSConfig(allow_origin="app-level") + function_name="goblet_cors", + cors=CORSConfig(allow_origin="app-level"), + backend="cloudfunction", ) @app.route("/test", cors=True) @@ -247,7 +249,7 @@ def mock_function3(): assert resp3[2]["X-TEST"] == "X-VALUE" def test_cors_options(self): - app = Goblet(function_name="goblet_cors") + app = Goblet(function_name="goblet_cors", backend="cloudfunction") @app.route("/test", cors=True) def mock_function(): @@ -270,7 +272,7 @@ def test_deploy_routes(self, monkeypatch, requests_mock): requests_mock.register_uri("PUT", "https://storage.googleapis.com/mock") - app = Goblet(function_name="goblet_routes") + app = Goblet(function_name="goblet_routes", backend="cloudfunction") setattr(app, "entrypoint", "app") app.route("/")(dummy_function) @@ -335,7 +337,9 @@ def test_destroy_routes(self, monkeypatch): apigw = Routes( "goblet_routes", resources=["not_empty"], - backend=CloudFunctionV1(Goblet(function_name="goblet_routes")), + backend=CloudFunctionV1( + Goblet(function_name="goblet_routes", backend="cloudfunction") + ), ) apigw.destroy() @@ -354,7 +358,7 @@ def test_deploy_routes_without_backend(self, monkeypatch): monkeypatch.setenv("G_TEST_NAME", "routes-deploy-without-backend") monkeypatch.setenv("G_HTTP_TEST", "REPLAY") - app = Goblet("goblet-routes") + app = Goblet("goblet-routes", backend="cloudfunction") app.route("/home")(dummy_function) with pytest.raises(SystemExit) as e: diff --git a/goblet/tests/test_scheduler.py b/goblet/tests/test_scheduler.py index acd9bce0..f9ba5f9d 100644 --- a/goblet/tests/test_scheduler.py +++ b/goblet/tests/test_scheduler.py @@ -11,7 +11,7 @@ class TestScheduler: def test_add_schedule(self, monkeypatch): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet_example", backend="cloudfunction") monkeypatch.setenv("GOOGLE_PROJECT", "TEST_PROJECT") monkeypatch.setenv("GOOGLE_LOCATION", "us-central1") @@ -40,7 +40,7 @@ def test_add_schedule(self, monkeypatch): assert scheduler.resources["dummy_function"]["func"] == dummy_function def test_multiple_schedules(self, monkeypatch): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet_example", backend="cloudfunction") monkeypatch.setenv("GOOGLE_PROJECT", "TEST_PROJECT") monkeypatch.setenv("GOOGLE_LOCATION", "us-central1") @@ -94,7 +94,7 @@ def test_multiple_schedules(self, monkeypatch): ) def test_call_scheduler(self, monkeypatch): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet_example", backend="cloudfunction") monkeypatch.setenv("GOOGLE_PROJECT", "TEST_PROJECT") monkeypatch.setenv("GOOGLE_LOCATION", "us-central1") @@ -122,7 +122,9 @@ def test_deploy_schedule(self, monkeypatch): monkeypatch.setenv("G_HTTP_TEST", "REPLAY") goblet_name = "goblet_example" - scheduler = Scheduler(goblet_name, backend=CloudFunctionV1(Goblet())) + scheduler = Scheduler( + goblet_name, backend=CloudFunctionV1(Goblet(backend="cloudfunction")) + ) scheduler.register( "test-job", None, @@ -186,7 +188,10 @@ def test_deploy_multiple_schedule(self, monkeypatch): goblet_name = "goblet-test-schedule" scheduler = Scheduler( - goblet_name, backend=CloudFunctionV1(Goblet(function_name=goblet_name)) + goblet_name, + backend=CloudFunctionV1( + Goblet(function_name=goblet_name, backend="cloudfunction") + ), ) scheduler.register( "test-job", @@ -246,7 +251,10 @@ def test_destroy_schedule(self, monkeypatch): goblet_name = "goblet_example" scheduler = Scheduler( - goblet_name, backend=CloudFunctionV1(Goblet(function_name=goblet_name)) + goblet_name, + backend=CloudFunctionV1( + Goblet(function_name=goblet_name, backend="cloudfunction") + ), ) scheduler.register( "test-job", diff --git a/goblet/tests/test_storage.py b/goblet/tests/test_storage.py index 62c7ce09..3c216841 100644 --- a/goblet/tests/test_storage.py +++ b/goblet/tests/test_storage.py @@ -11,7 +11,7 @@ class TestStorage: def test_add_bucket(self, monkeypatch): monkeypatch.setenv("G_HTTP_TEST", "REPLAY") - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example", backend="cloudfunction") app.storage("test", "finalize")(dummy_function) app.storage("test2", "archive")(dummy_function) @@ -22,7 +22,7 @@ def test_add_bucket(self, monkeypatch): assert storage.resources[1]["event_type"] == "archive" def test_add_invalid_event(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") with pytest.raises(Exception): app.storage("test", "wrong")(dummy_function) @@ -30,7 +30,7 @@ def test_add_invalid_event(self): def test_call_storage(self, monkeypatch): monkeypatch.setenv("G_HTTP_TEST", "REPLAY") - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example", backend="cloudfunction") mock = Mock() app.storage("test", "finalize")(mock_dummy_function(mock)) @@ -50,7 +50,7 @@ def test_deploy_storage(self, monkeypatch, requests_mock): requests_mock.register_uri("PUT", "https://storage.googleapis.com/mock") - app = Goblet(function_name="goblet_storage") + app = Goblet(function_name="goblet_storage", backend="cloudfunction") setattr(app, "entrypoint", "app") app.storage("test", "finalize")(dummy_function) diff --git a/goblet/tests/test_vpcconnector.py b/goblet/tests/test_vpcconnector.py index 001b93db..812d45fb 100644 --- a/goblet/tests/test_vpcconnector.py +++ b/goblet/tests/test_vpcconnector.py @@ -10,7 +10,7 @@ class TestVPCConnector: def test_add_vpcconnector(self): app = Goblet( - function_name="goblet_example", + function_name="goblet-example", config={"vpcconnector": {"ipCidrRange": "10.32.1.0/28"}}, ) @@ -19,7 +19,7 @@ def test_add_vpcconnector(self): assert vpc.resources["name"] == "vpc-test" def test_add_invalid_vpcconnector(self): - app = Goblet(function_name="goblet_example") + app = Goblet(function_name="goblet-example") with raises(ValueError): app.vpcconnector(name="vpc-test") diff --git a/requirements.txt b/requirements.txt index ed83f519..5c960de3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,9 @@ -apispec==6.3.0 -click==8.1.6 -functions-framework==3.4.0 -marshmallow==3.19.0 -pydantic==2.4.0 +apispec==6.6.1 +click== 8.1.8 +functions-framework==3.9.2 +marshmallow==3.26.1 +pydantic==2.11.7 PyYAML==6.0.1 -google-cloud-logging==3.6.0 -google-cloud-appengine-logging==1.3.1 -goblet-gcp-client==0.1.9 -protobuf==4.24.0 +google-cloud-logging==3.12.1 +google-cloud-appengine-logging==1.6.2 +goblet-gcp-client==0.1.9 \ No newline at end of file diff --git a/setup.py b/setup.py index 036b5a60..2ce01150 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,6 @@ "google-cloud-logging", "google-cloud-appengine-logging", "goblet-gcp-client", - "protobuf==4.24.*", ] here = os.path.abspath(os.path.dirname(__file__)) @@ -117,7 +116,6 @@ def run(self): "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11",