def create_panda(self, primary_object, filter=''): users = okta_connect(primary_object=primary_object, limit=500, filter=filter).fetch_from_okta() users_profile_list = pd.read_json(path_or_buf=json.dumps(users), encoding='str') # print json.dumps([reponse_headers], indent=4, sort_keys=True) self.raw_users = users_profile_list try: okta_id = pd.DataFrame(self.raw_users['id']) okta_status = pd.DataFrame(self.raw_users['status']) self.users = pd.DataFrame( users_profile_list['profile'].tolist()).join(okta_id) self.users = self.users.join(okta_status) try: okta_credentials = pd.DataFrame( self.raw_users['credentials'].tolist()) self.users = self.users.join(okta_credentials) except: pass return self.users except Exception, e: # print e return pd.DataFrame()
def deactivate_user(user_id): try: if '@' in user_id: user_id = Okta_Users.get_okta_id_from_email(query=user_id) else: user_id = user_id primary_object = 'user/' + user_id + '/lifecycle/deactivate' return okta_connect(primary_object=primary_object, limit='', filter='').fetch_from_okta(query_type='POST') except Exception, e: return e
def set_user_name(self, user_id, user_name): """ Once an app object is created user name can be set by passing the user id and user name. :param user_id: 20 character okta id should be passed as a string. :param user_name: New user name for the user id passed in. :return: DataFrame of new Profile for App """ primary_object = self.primary_object + '/users/' + user_id data = {"credentials": {"userName": user_name}} user_app_profile = okta_connect(primary_object=primary_object, limit='', filter='', data=json.dumps(data)).fetch_from_okta(query_type='POST') users_app_profile_df = pd.read_json(path_or_buf=json.dumps(user_app_profile), orient='records', lines=True) return users_app_profile_df
def create_panda(self, primary_object): users = okta_connect(primary_object=primary_object, limit=500, filter='').fetch_from_okta() users_profile_list = pd.read_json(path_or_buf=json.dumps(users), encoding='str') if users_profile_list.empty: group_response = users_profile_list else: group_response = pd.DataFrame(users_profile_list[['profile', 'id']]) group_response = create_feature_dataframe(group_response, 'id', 'profile') return group_response
def create_panda(self, primary_object): self.raw_user = okta_connect(primary_object=primary_object, limit=500, filter='').fetch_from_okta() print self.raw_user # users_profile_list = pd.read_json(path_or_buf=json.dumps(self.raw_user), encoding='str', orient='columns') # users_profile_list json.dumps([reponse_headers], indent=4, sort_keys=True) try: self.user = pd.DataFrame([self.raw_user]) self.user = pd.DataFrame(self.user['profile'].tolist()).join( self.user) return self.user except Exception, e: print e return pd.DataFrame()
def get_app_id(self, app_name): """ Retrieve the app Id given the app name. :param app_name: Okta label for the tile :return: string of 'apps/<id>/' """ try: primary_object = 'apps/' if app_name == '': return primary_object else: apps_list = okta_connect(primary_object=primary_object, limit=200).fetch_from_okta() id_label_list = pd.read_json(path_or_buf=json.dumps(apps_list), encoding='str')[['id', 'label']] apps_id_label = id_label_list[id_label_list['label'].str.lower() == app_name.lower()] primary_object = primary_object + str(apps_id_label.id.iloc[0]) return primary_object except: error_result = "Unexpected error 1TL: %s, %s" % (sys.exc_info()[0], sys.exc_info()[1]) print error_result
def add_user_to_group(self, user_email, user_id=''): """Provide the user id(s) or user email(s) to add to the group. :param user_id: Tuple of Alpha numeric ids for Okta user objects. :param user_email: Tuple of Emails :return: """ try: if user_id == '': user_value = okta_user.get_okta_id_from_email(user_email) else: user_value = user_id add_to_group_url = self.primary_object + '/' + str(user_value) result = okta_connect(primary_object=add_to_group_url, limit='', filter='').fetch_from_okta(query_type='PUT') except Exception, e: result = e
def __init__(self, app_name=''): self.primary_object = self.get_app_id(app_name=app_name) self.details = okta_connect(primary_object=self.primary_object) self.app_users = okta_users(app_id=self.primary_object).users