diff --git a/dbt_project.yml b/dbt_project.yml index 2946a8fe..d3783446 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -6,7 +6,7 @@ version: "1.0.0" config-version: 2 # This setting configures which "profile" dbt uses for this project. -profile: "livequery" +profile: livequery # These configurations specify where dbt should look for different types of files. # The `source-paths` config, for example, states that models in this project can be diff --git a/macros/core/_live.yaml.sql b/macros/core/_live.yaml.sql index 5a698a80..680bd646 100644 --- a/macros/core/_live.yaml.sql +++ b/macros/core/_live.yaml.sql @@ -15,4 +15,50 @@ NOT NULL RETURNS NULL ON NULL INPUT sql: udf_api + +- name: {{ schema }}.udf_rest_api_args_only + signature: + - [method, STRING] + - [url, STRING] + - [headers, OBJECT] + - [DATA, VARIANT] + - [SECRET_NAME, STRING] + return_type: OBJECT + func_type: SECURE + options: | + NOT NULL + RETURNS NULL ON NULL INPUT + sql: | + { + 'method': method, + 'url': url, + 'headers': headers, + 'data': data, + 'secret_name': SECRET_NAME + } + +{# - name: {{ schema }}.udf_api + description: | + This function is used to select the appropriate function to call based on the user_id + signature: + - [method, STRING] + - [url, STRING] + - [headers, OBJECT] + - [DATA, VARIANT] + - [user_id, STRING] + - [SECRET, STRING] + return_type: VARIANT + func_type: SECURE + options: | + NOT NULL + RETURNS NULL ON NULL INPUT + sql: | + SELECT + CASE + WHEN user_id ilike 'AWS_%' + THEN {{ schema }}.udf_rest_api_args_only(method, url, headers, DATA, SECRET)::VARIANT + ELSE {{ schema }}._udf_api(method, url, headers, DATA, user_id, SECRET) + END #} + + {% endmacro %} \ No newline at end of file diff --git a/macros/core/live.yaml.sql b/macros/core/live.yaml.sql index e5988f00..e6945cbc 100644 --- a/macros/core/live.yaml.sql +++ b/macros/core/live.yaml.sql @@ -120,6 +120,24 @@ secret_name ) +- name: {{ schema }}.udf_api + signature: + - [args, OBJECT] + return_type: VARIANT + options: | + NOT NULL + VOLATILE + sql: | + SELECT + _live.UDF_API( + COALESCE(args:method, 'GET'), + args:url, + COALESCE(args:headers, {}), + COALESCE(args:data, {}), + _utils.UDF_WHOAMI(), + COALESCE(args:secret_name, '') + ) + - name: {{ schema }}.udf_rpc signature: - [blockchain, STRING] diff --git a/models/deploy/core/_live._yml b/models/deploy/core/_live._yml new file mode 100644 index 00000000..bae72e41 --- /dev/null +++ b/models/deploy/core/_live._yml @@ -0,0 +1,47 @@ +version: 2 +models: + - name: _live + columns: + - name: udf_rest_api_args_only + tests: + - test_udf: + name: test___live_udf_rest_api_args_only + args: > + 'GET', + 'https://api.example.com', + {'Content-Type': 'application/json'}, + {'hello': 'world'}, + 'my_secret' + assertions: + - | + result = { + 'method': 'GET', + 'url': 'https://api.example.com', + 'headers': {'Content-Type': 'application/json'}, + 'data': {'hello': 'world'}, + 'secret_name': 'my_secret' + } + - test_udf: + name: test___live_udf_rest_api_args_only_null + args: null, null, null, null, null + assertions: + - result = {} + - test_udf: + name: test___live_udf_api + args: > + 'GET', + 'https://api.example.com', + {'Content-Type': 'application/json'}, + {'hello': 'world'}, + 'non_streamline_user' + 'my_secret' + assertions: + - | + result = { + 'method': 'GET', + 'url': 'https://httpbin.org/get', + 'headers': {'Content-Type': 'application/json'}, + 'data': {'hello': 'world'}, + 'user': 'non_streamline_user', + 'secret_name': 'my_secret' + }