automaticmode / active_workflow

Polyglot workflows without leaving the comfort of your technology stack.
https://www.activeworkflow.org
Other
830 stars 67 forks source link

How to use credentials? #5

Closed suhrm1 closed 4 years ago

suhrm1 commented 4 years ago

Hey all, very simple question here: how do I refer to stored credentials in an Agent's options?

Best regards, Markus

vidas commented 4 years ago

Hi Markus!

To refer to stored user credentials in the agent options you should use liquid templating like this:

{
    "password": "{% credential PASSWORD %}"
}

Where PASSWORD is the name of the credential. Expression in curly braces will be replaced by the value of the credential.

Thanks!

suhrm1 commented 4 years ago

Thank you! (Of course just now I finally spotted the help text where it says exactly that...)

But still I don't seem to get it right: I set up a credential with my user account with the name cred_test and some gibberish value, put it in the options JSON object like this: { ..., "username": "{% credential cred_test %}" } and had my custom remote agent print the received payload to stdout which reads:

{
  'method': 'check', 
  'params': {
    'message': None, 
    'options': { ... , 'username': '{% credential cred_test %}'},
    'memory': {}, 
    'credentials': {'name': 'value'}
  }
}

PS: The exact same syntax works fine if I put it in the Manual Message agent, my cred_test gets replaced with the stored value. Do I have to enable liquid templating for the remote agent somehow?

vidas commented 4 years ago

Ah, I see. Custom remote agents don't get liquid templating out of the box (yet)... We will add partial "preprocessing" of options through liquid templating (specifically to handle cases like yours).

Currently, your remote agent is getting options verbatim as entered by the user. It also receives all the credentials. If you need that users of your remote agent can use credentials in options you can add liquid templating support in your agent yourself (not a straightforward thing) or do it in a simple, but less generic way:

For example, if you only need a credential for some password, you could create an agent option:

{
    "password_from_credential": "[name_of_the_credential]"
}

And then use it to look up the value of the credential in your agent's code.

Sorry for the inconvenience and thank you!

P.S.

Liquid templating is not supported out of the box for remote agents, because users may want to refer to something that is internal to the agent and that data is not available to the ActiveWorkflow system.

Another solution in the works will be toolkits/libraries for several popular programming languages (rust included!) that will help develop custom remote agents and will include liquid templating. Imagine it like some sort of agent SDK.

suhrm1 commented 4 years ago

Thank you for the clarification. Using credentials is not a must at the moment for my project, I am just trying to figure all of the possible options out :)

Still one more follow-up question though: My custom remote agent apparently receives 'credentials': {'name': 'value'} as the actual payload. If I understood you correctly though, it should have received the actual credentials stored in the Active Workflow UI? (which would have been something like {'cred_test': '123456789abc'} in this case)

vidas commented 4 years ago

Hm, that is unexpected. In fact credentials to remote agents are sent in the following format:

{
    ...,
    'params': {
        ...,
        'credentials': [{ 'name': 'qwerty', 'value': 'asdfg' }, {...}, {...}]
    }
}

I.e. a list of objects with name and value fields.

I suspect something with JSON parsing, but I may be wrong. Could you please print raw (before parsing) request content to stdout to make sure that remote agent indeed fails to receive the right credentials?

Thank you, Markus!

suhrm1 commented 4 years ago

Mystery solved, it was indeed a problem with the JSON parsing of our remote agent :)

Thank you so much, I really enjoy this project and will spread the word about it!