Search code examples
volttron

How to call a function when "RPC.allow" is applied?


 In the volttron/platform/store.py file, it contains:

@ RPC.export
@ RPC.allow ('edit_config_store')
def manage_store (self, identity, config_name, raw_contents, config_type = "raw"):
    contents = process_raw_config (raw_contents, config_type)
    self._add_config_to_store (identity, config_name, raw_contents, contents, config_type,
                                  trigger_callback = True)

To call this function from outside, I wrote the code as below.

 self.vip.rpc.call (CONFIGURATION_STORE, "manage_store", 'platform.driver', config_name, raw_contents, 'json')

The error code is as follows.

volttron.platform.jsonrpc.Error: method "manage_store" requires capabilities {'edit_config_store'}, but capability [] was provided for user pnp

auth is registered as below.

INDEX: 8
{
  "domain": null,
  "address": null,
  "mechanism": "CURVE",
  "credentials": "6vjPXC8ctO8oWkeMXAOe5FsAM9vZD_sg0vkLrstnVFs",
  "groups": [],
  "roles": [],
  "capabilities": {
    "edit_config_store": {
      "identity": "pnp.b"
    }
  },
  "comments": "Automatically added on agent install",
  "user_id": "pnp.b",
  "enabled": true
}

How do I fix Capability?


Solution

  • This is a security feature. By default an agent can only update its own config store. So the agent with identity pnp.b can only edit its own config store and not of platform.driver. But you (or whoever has access to run vctl auth command or to directly edit the $VOLTTRON_HOME/auth.json file) can edit config store by giving the pnp.b agent the capability to edit the config store of platform.driver.

    The capabilities entry for the agent can be changed to a regular expression that allows pnp.b or platform.driver (Or any other pattern you want). Regular expressions should be enclosed in / For example

    {
      "domain": null,
      "address": null,
      "mechanism": "CURVE",
      "credentials": "6vjPXC8ctO8oWkeMXAOe5FsAM9vZD_sg0vkLrstnVFs",
      "groups": [],
      "roles": [],
      "capabilities": {
        "edit_config_store": {
          "identity": "/pnp.b|platform.driver/"
        }
      },
      "comments": "Automatically added on agent install",
      "user_id": "pnp.b",
      "enabled": true
    }