Hi Iuliana,

This would be an awesome addition.  The use of beans is really powerful and this lets us do even more with them.

I'd like us to support *both* the `["user"]` and the `.users` syntax.  The former could allow accessing other DSL values (if you use a DSL expression rather than a quoted string).  I'd also say for list indices it should be a number not a string, ie `[0]` not `["0"]`.  So the following would be supported (and equivalent):

$brooklyn:config("user_credentials")[config("user_name")].roles[0]
$brooklyn:config("user_credentials")[config("user_name")]["roles"][0]

^ assuming your object is of type `map<string,user_credentials>` and `user_credentials` has a field `roles` of type `list<string>`.

BTW the Apache mailing lists don't like any fancy formatting so it mangled your mail a little bit but it was still totally readable.

Best
Alex



On 19/02/2021 16:46, Iuliana Cosmina wrote:
Hi Brooklyners,



I am new here, but while writing CAMP blueprints  using Brooklyn DSL I hit
a wall.



Here’s my situation: I have a brooklyn.parameter of a custom type named
Credential, that is defined like this:

- *id*: Credential
   *format*: bean-with-type
   *item*:
     *type*: my.type.Credential



The Credential class has two properties: user and token.



I want to be able to use the value of the ‘user’ property when configuring
my service, like this:



*items*:
- *itemType*: template  *item*:    *brooklyn.parameters*:    - *name*:
user_credentials      *type*: Credential      *default*:
*user*: *"unsername"
         **token*: *"password"
     **services*:    - *id*: credential-service      *type*:
my.credential.Service      *brooklyn.initializers*:      - *type*:
my.initializer.AAA        *brooklyn.config*:          *name*:
user.name          *static.value*:
*$brooklyn:config("user_credentials")["user"]*


Currently I see no way to access the value of the "user" property of my
brooklyn parameter.  Also, in case the Credential type also has a "roles"
property which is a list<string> or an array, I would very much like to be
able to write

*$brooklyn:config("user_credentials")["roles"]["0"]*

Of if the “user.credentials” is of type  list<Credentials>, it would be
nice if I could do

*$brooklyn:config("user_credentials")["0"]["user"]*


I personally like the [x] approach where x is tried (in order):

    - an argument to a `get(x)` method (works for lists and maps: index or
    key)
    - a bean property (if x is a string, look for method called getX() or a
    field called  x
    - a config key, if the target is Configurable , ie getConfig(x) or
    config().get(x)


Or we could go for something pretty similar to a JsonPath style (
https://github.com/json-path/JsonPath)



This would allow us to write constructs like:

*$brooklyn:config("user_credentials").user*

*$brooklyn:config("user_credentials").roles[0]*

*$brooklyn:config("user_credentials")[0].user*



I think a change like this would make Brooklyn DSL more flexible and open
the door to further improvements and also make blueprints more readable.



I propose to work on the above and welcome any thoughts from the community.



Cheers,

Iuliana


Reply via email to