proxy-wasm / proxy-wasm-cpp-sdk

WebAssembly for Proxies (C++ SDK)
Apache License 2.0
139 stars 67 forks source link

how to read file in wasm #117

Open Snailll opened 3 years ago

Snailll commented 3 years ago

In the wasm filter ,I want to read some configurations from file. I wrote some code in the onConfigure part like this

    std::string data;
    std::ifstream infile;
    infile.open("/configurations.json");
    infile >> data;;
    infile.close();
    LOG_ERROR("configurations -> " + data);

Howerev, I cannot get any content of the configuration file.

How to read a configuration file in wasm ? Is there a file read API in the proxy-wasm-cpp-sdk?

Ths.

bianpengyuan commented 3 years ago

Host does not yet support file read ABI: https://github.com/proxy-wasm/proxy-wasm-cpp-host/issues/127

PiotrSikora commented 3 years ago

The read-only file access is being actively worked on... But why exactly do you need it?

Note that the recommended way to configure plugins is to add the configuration in the proxy config itself, which is then available in the plugin via proxy_get_buffer_bytes(WasmBufferType::PluginConfiguration, ...).

CalbeeMing0530 commented 3 years ago

The read-only file access is being actively worked on... But why exactly do you need it?

Note that the recommended way to configure plugins is to add the configuration in the proxy config itself, which is then available in the plugin via proxy_get_buffer_bytes(WasmBufferType::PluginConfiguration, ...).

This kind of requirement is more common, for example, we use wasm to do some traffic processing work, which will involve policy reading, so we need to read the mounted configuration from the envoy proxy

CalbeeMing0530 commented 3 years ago

@PiotrSikora In addition,If the policy is complex and confidential, it is obviously not wise to put it all in the proxy configuration