proxy-wasm-cpp-sdk icon indicating copy to clipboard operation
proxy-wasm-cpp-sdk copied to clipboard

how to read file in wasm

Open Snailll opened this issue 3 years ago • 4 comments

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.

Snailll avatar Jun 03 '21 08:06 Snailll

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

bianpengyuan avatar Jun 03 '21 18:06 bianpengyuan

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, ...).

PiotrSikora avatar Jun 03 '21 18:06 PiotrSikora

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 avatar Jun 04 '21 01:06 CalbeeMing0530

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

CalbeeMing0530 avatar Jun 04 '21 01:06 CalbeeMing0530