okta-cli
okta-cli copied to clipboard
Setting array-based Okta attributes using okta-cli
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 [email protected] \
-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?
hi @bousquf , those thoughts rang a bell, and i just had a look and realized i implemented that already (see here and here) for users update
, but apparently not for users add
or users bulk-update
. probably i was in a hurry.
i don't remember why exactly i didnt go for the array notation, probably because i disliked the shell escaping which you'd need then if i have to guess.
it's still kind of crappy cause you can't set values with a comma inside, but hey.
i will keep this open as a reminder to implement it for users add
and bulk-update
at least.