I'm trying to use okta-cli to set the value of an array-based attribute in Okta. The code currently assumes string only values for all cli arguments. However, I've been looking into how setting array based value could be implemented:
I managed to modify cli.py to somewhat detect an array if an attribute value starts/end with [ and ]. It is not pretty, but it somewhat works for what needed:
@@ -860,6 +860,9 @@ def apps_getuser(app, user, user_lookup_field, **kwargs):
def apps_adduser(app, user, user_lookup_field, set_fields, **kwargs):
"""Add a user to an application"""
appuser = {k: v for k, v in map(lambda x: x.split("=", 1), set_fields)}
+ for k,v in appuser.items():
+ if v.startswith("[") and v.endswith("]"):
+ appuser[k] = v.lstrip("[").rstrip("]").split(",")
app = _okta_get("apps", app,
selector=_selector_field_find("label", app))
user = _okta_get("users", user,
However, [ and ] characters need to be escaped at the shell level
% okta-cli apps adduser -a 0oado6m4123457Ao0357 -u username@domain.com \
-s profile.stringAttribute="String value" \
-s profile.arrayAttribute=\["A","B"\]
However, it would prevent someone from adding an actual string value that starts with a [ into an Okta attribute.
What would be the preferred way to handle a cli parameter value that is an array?
I'm trying to use okta-cli to set the value of an array-based attribute in Okta. The code currently assumes string only values for all cli arguments. However, I've been looking into how setting array based value could be implemented:
I managed to modify cli.py to somewhat detect an array if an attribute value starts/end with
[and]. It is not pretty, but it somewhat works for what needed:However,
[and]characters need to be escaped at the shell levelHowever, it would prevent someone from adding an actual string value that starts with a
[into an Okta attribute.What would be the preferred way to handle a cli parameter value that is an array?