Kuadrant / wasm-shim

A Proxy-Wasm module allowing communication to Authorino and Limitador.
Apache License 2.0
5 stars 5 forks source link

Fix return value when host property does not exist from data.selector #39

Closed eguzki closed 1 year ago

eguzki commented 1 year ago

What

Selectors in rules[].data.selector[] have a default named attribute to cover the use case where the property does not exist https://github.com/Kuadrant/wasm-shim/blob/main/src/configuration.rs#L7-L20

pub struct SelectorItem {
    // Selector of an attribute from the contextual properties provided by kuadrant
    // during request and connection processing
    pub selector: String,

    // If not set it defaults to `selector` field value as the descriptor key.
    #[serde(default)]
    pub key: Option<String>,

    // An optional value to use if the selector is not found in the context.
    // If not set and the selector is not found in the context, then no data is generated.
    #[serde(default)]
    pub default: Option<String>,
}

When the selector property does not exist, the behavior is ruled by the default field. Currently the implementation was enforcing a default value (empty string "") defeating the purpose of the default attribute.

Verification Steps

The wasm configuration applied for *.a.com is

{
                              "name": "rlp-ns-A/rlp-name-A",
                              "domain": "rlp-ns-A/rlp-name-A",
                              "service": "limitador",
                              "hostnames": ["*.a.com"],
                              "rules": [
                                {
                                  "data": [
                                    {
                                      "selector": {
                                        "selector": "unknown.path"
                                      }
                                    }
                                  ]
                                }
                              ]
                            }
eguzki commented 1 year ago

requires https://github.com/Kuadrant/wasm-test-framework/pull/2

eguzki commented 1 year ago

ready for review @alexsnaps