Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting array-based Okta attributes using okta-cli #10

Open
bousquf opened this issue Dec 2, 2021 · 1 comment
Open

Setting array-based Okta attributes using okta-cli #10

bousquf opened this issue Dec 2, 2021 · 1 comment

Comments

@bousquf
Copy link
Contributor

bousquf commented Dec 2, 2021

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?

@flypenguin
Copy link
Owner

flypenguin commented Dec 3, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants