<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How do you add a role to a user with Splunk Python SDK? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/How-do-you-add-a-role-to-a-user-with-Splunk-Python-SDK/m-p/385556#M6445</link>
    <description>&lt;P&gt;I need to add a specific role to a user using the Splunk SDK.&lt;/P&gt;

&lt;P&gt;I can list the users and find the roles owned by the user I want to add a role to. But, I can't work out how to access and update that user object. I've tried to use a number of variations on "services.user.name", "service.user.content" etc etc, but can't get anything with "service.user.xxxxxx" to work. The calls to service.roles.xxxxxx and service.users.xxxxxx both work as advertised. &lt;/P&gt;

&lt;P&gt;Does anyone have any examples as to how to use the splunklib.client.User class? Any help to point me in the right direction greatly appreciated.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;newrolename="new_role"
newrole = service.roles.create(newrolename)
kwargs = {"sort_key": "realname", "sort_dir": "asc"}
users = service.users.list(count=-1,**kwargs)
for user in users:
    username=user.name
    logger.info(username)
    logger.info("username="+username+", current_user="+current_user)
    if user.name == current_user:
        logger.info("username==current_user")
        user_roles=[newrolename]
        for role in user.role_entities:
            user_roles.append(role.name)
            logger.info(user_roles)
            #service.user.name # - seems to do nothing (when uncommented)
            #TODO: get user object?? update user object to add role to user??
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 19 Sep 2018 02:01:21 GMT</pubDate>
    <dc:creator>aldonnelley</dc:creator>
    <dc:date>2018-09-19T02:01:21Z</dc:date>
    <item>
      <title>How do you add a role to a user with Splunk Python SDK?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-you-add-a-role-to-a-user-with-Splunk-Python-SDK/m-p/385556#M6445</link>
      <description>&lt;P&gt;I need to add a specific role to a user using the Splunk SDK.&lt;/P&gt;

&lt;P&gt;I can list the users and find the roles owned by the user I want to add a role to. But, I can't work out how to access and update that user object. I've tried to use a number of variations on "services.user.name", "service.user.content" etc etc, but can't get anything with "service.user.xxxxxx" to work. The calls to service.roles.xxxxxx and service.users.xxxxxx both work as advertised. &lt;/P&gt;

&lt;P&gt;Does anyone have any examples as to how to use the splunklib.client.User class? Any help to point me in the right direction greatly appreciated.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;newrolename="new_role"
newrole = service.roles.create(newrolename)
kwargs = {"sort_key": "realname", "sort_dir": "asc"}
users = service.users.list(count=-1,**kwargs)
for user in users:
    username=user.name
    logger.info(username)
    logger.info("username="+username+", current_user="+current_user)
    if user.name == current_user:
        logger.info("username==current_user")
        user_roles=[newrolename]
        for role in user.role_entities:
            user_roles.append(role.name)
            logger.info(user_roles)
            #service.user.name # - seems to do nothing (when uncommented)
            #TODO: get user object?? update user object to add role to user??
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Sep 2018 02:01:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-you-add-a-role-to-a-user-with-Splunk-Python-SDK/m-p/385556#M6445</guid>
      <dc:creator>aldonnelley</dc:creator>
      <dc:date>2018-09-19T02:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do you add a role to a user with Splunk Python SDK?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-you-add-a-role-to-a-user-with-Splunk-Python-SDK/m-p/385557#M6446</link>
      <description>&lt;P&gt;Hi @aldonnelley,&lt;/P&gt;

&lt;P&gt;As you want to add role to user, so here I am assuming that you have local user on splunk not LDAP user, right ?&lt;BR /&gt;
 If you have LDAP users in that case you can't assign role directly to user because role based access is mapped with LDAP group.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 14:03:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-you-add-a-role-to-a-user-with-Splunk-Python-SDK/m-p/385557#M6446</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2018-09-20T14:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do you add a role to a user with Splunk Python SDK?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-you-add-a-role-to-a-user-with-Splunk-Python-SDK/m-p/385558#M6447</link>
      <description>&lt;P&gt;Hi, @harsmarvania57&lt;/P&gt;

&lt;P&gt;Thanks for your response. That's an excellent point. I will have both local and LDAP users...&lt;BR /&gt;
So I guess I'm going to have to come up with a way for the app to manage its own local permissions for the feature. Which is fine - it's not a critical security feature, more just about keeping low-level users from meddling with a few things they shouldn't. &lt;/P&gt;

&lt;P&gt;Thanks again.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 22:16:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-you-add-a-role-to-a-user-with-Splunk-Python-SDK/m-p/385558#M6447</guid>
      <dc:creator>aldonnelley</dc:creator>
      <dc:date>2018-09-20T22:16:22Z</dc:date>
    </item>
  </channel>
</rss>

