Skip to content

Commit

Permalink
update with auth
Browse files Browse the repository at this point in the history
  • Loading branch information
leeduckgo committed Nov 26, 2023
1 parent 5fb590f commit c058a5a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
3 changes: 2 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ config :tai_shang_micro_faas_system,
github_token: System.get_env("GITHUB_TOKEN"),
embedbase_key: System.get_env("EMBEDBASE_KEY"),
did_mainnet: "0x61b96051f553d767d7e6dfcc04b04c28d793c8af3d07d3a43b4e2f8f4ca04c9f",
did_testnet: "0xc71124a51e0d63cfc6eb04e690c39a4ea36774ed4df77c00f7cbcbc9d0505b2c"
did_testnet: "0xc71124a51e0d63cfc6eb04e690c39a4ea36774ed4df77c00f7cbcbc9d0505b2c",
api_key: System.get_env("API_KEY")

config :cors_plug,
max_age: 2592000,
Expand Down
3 changes: 1 addition & 2 deletions lib/components/movespace_db.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ defmodule Components.MovespaceDB do
end

def insert_vector(vector_db_name, id_in_embedbase, raw_data, meta_data, embedding) do
IO.puts "tttttt"
IO.puts raw_data
IO.puts "insert_vector"
sql_cmd = """
INSERT INTO #{vector_db_name} (id_in_embedbase, raw_data, meta_data, embedding) VALUES (
'#{id_in_embedbase}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,33 @@ defmodule TaiShangMicroFaasSystemWeb.FunctionRunnerController do
end

def run(conn, payload) do
result =
payload
|> ExStructTranslator.to_atom_struct()
|> do_run()
|> handle_param()
json(conn, %{result: result})
# TODO: optimize here.
if is_nil(Constants.get_api_key()) do
result =
payload
|> ExStructTranslator.to_atom_struct()
|> do_run()
|> handle_param()
json(conn, %{result: result})
else
atomed_payload =
%{api_key: api_key} =
ExStructTranslator.to_atom_struct(payload)

result =
if guide(api_key) do
atomed_payload
|> do_run()
|> handle_param()
else
handle_param({:error, "wrong api key!"})
end
json(conn, %{result: result})
end
end

def guide(api_key), do: api_key == Constants.get_api_key()

def do_run(%{
tx_id: tx_id,
func_name: func_name,
Expand Down
4 changes: 4 additions & 0 deletions lib/utils/constants.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ defmodule Constants do
Application.fetch_env!(:tai_shang_micro_faas_system, :did_testnet)
end

def get_api_key() do
Application.fetch_env!(:tai_shang_micro_faas_system, :api_key)
end

end

0 comments on commit c058a5a

Please sign in to comment.