ruby on rails - Parse hash for value from a table -
i writing aws-federation proxy in rails. means grab groups using net-ldap on our local activedirectory , want compare list , matches. netldap-searchresult hash:
[#<net::ldap::entry:0x000000048cfdd0 @myhash={:dn=>["cn=username,ou=support,ou=mycompany ,ou=organisation,dc=mycompany,dc=com"], :memberof=>["cn=my aws groupname,cn=receiver,cn=users,dc=mycompany,dc=com"]}>]
now want parse hash , matches in local "groups" table. looks that:
name aws-role aws-groupname group aws-othergroup other-group
i have group-model. best practices approach? i've never done before. use regex here? loop groups through tables? what's rails way this?
edited more information
i'm going assume few things here, since don't know ldap search results from, assuming hash looks this:
edit: based on additional information:
// example require 'net-ldap' entry = net::ldap::entry.new entry.dn = ["cn=username,ou=support,ou=mycompany ,ou=organisation,dc=mycompany,dc=com"] entry[:memberof] =["cn=my aws groupname,cn=receiver,cn=users,dc=mycompany,dc=com"] name = entry.memberof.first.split(',').first.gsub('cn=', '')
and assuming have model called group mapped "groups" table, can this:
group.where(name: name).any?
if find results, means have match in table. depends on table structure , hash. answer question, i'd need see objects have in rails, , structure of hash looks like.
edit: updated answer based on received feedback. use code @ own risk.
Comments
Post a Comment