Re: FW: Suggestions for perl examples

[email protected] (Joshua Miller) Thu, 2 Feb 2017 22:58:09 -0500
Newsgroups perl.ldap
Message-ID <CAL3qUHfRW+Fzpp4uZONKjq+8Kx5TS=8WaDP=ODaFvt+k8SXjXQ@mail.gmail.com>
--001a1143703a418ec80547984ab1
Content-Type: text/plain; charset=UTF-8

On Tue, Jan 31, 2017 at 11:19 AM, Steven M Chegash <
[email protected]> wrote:

>
>
>
>
> mesg = Net::LDAP=HASH(0x1a1c00d0)->modify("uid=testcust34,ou=CSOPortal,ou=External
> Users,ou=People,o=mycompany.com", changes => [ delete =>  'myCrmId' ] ,
> delete=>[ 'objectclass'=>'myPortaleProfile' ]  );
>
>
>
> error_text:The request referenced an attribute that does not exist
>
>
>
> error_code:16
>
> server_error:GLPRDB050E Attribute myPortaleProfile was not found in the
> schema definition.
>
>
>
> error:GLPRDB050E Attribute myPortaleProfile was not found in the schema
> definition.
>
>
>

I can't say for certain, as I don't work with Net::LDAP frequently, but the
syntax you used (delete => ['objectclass'=>'myPortaleProfile']), implied
that you had the wrong syntax (array versus hash), and the docs (man
Net::LDAP) agree. The "modify" method can be called with a "delete" key in
two ways:

1. delete => [ ATTR, ... ]
This deletes every listed attribute in the arrayref defined by the brackets.

2. delete => { ATTR => VALUE, ... }
This deletes individual values from an attribute. It can also delete the
whole attribute if the value is an empty arrayref. This is the syntax you
want to use. Just replace your square brackets with curly ones (which means
hashref).

Here's another way to rewrite that:

  my %attr_to_delete = ( objectclass => 'myPortaleProfile' );
  $ldap->modify("uid=... etc ...", delete => \%attr_to_delete);


AFAICT, you should either drop your use of "changes" with a separate
delete, or combine them all into changes. "changes" is there if "you want
to control the order in which the operations will be performed" (quoting
the docs).

To delete one attribute entirely, and delete a value from another one, I
think you would want to do:

  $ldap->modify("uid=...etc...", delete => {
    myCrmId => [],
    objectClass => 'myPortaleProfile',
  });


Hope that helps,
--
Josh I.

--001a1143703a418ec80547984ab1
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On T=
ue, Jan 31, 2017 at 11:19 AM, Steven M Chegash <span dir=3D"ltr">&lt;<a hre=
f=3D"mailto:[email protected]" target=3D"_blank">steven.chegash@=
dteenergy.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" st=
yle=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang=3D"EN-US" link=3D"blue" vlink=3D"purple">
<div class=3D"m_-4116638339801497907WordSection1">
<p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:12pt">=C2=A0</span><br></p>
<p class=3D"MsoNormal"><span style=3D"font-size:12.0pt">mesg =3D Net::LDAP=
=3DHASH(0x1a1c00d0)-&gt;<wbr>modify(&quot;uid=3Dtestcust34,ou=3D<wbr>CSOPor=
tal,ou=3DExternal Users,ou=3DPeople,o=3D<a href=3D"http://mycompany.com" ta=
rget=3D"_blank">mycompany.<wbr>com</a>&quot;, changes =3D&gt; [ delete =3D&=
gt;=C2=A0 &#39;myCrmId&#39; ] , delete=3D&gt;[ &#39;objectclass&#39;=3D&gt;=
&#39;<wbr>myPortaleProfile&#39; ]=C2=A0 );<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:12.0pt">=C2=A0<u></u><u></u=
></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:12.0pt">error_text:The requ=
est referenced an attribute that does not exist<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:12.0pt"><u></u>=C2=A0<u></u=
></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:12.0pt">error_code:16<u></u=
><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:12.0pt">server_error:GLPRDB=
050E Attribute myPortaleProfile was not found in the schema definition.<u><=
/u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:12.0pt"><u></u>=C2=A0<u></u=
></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:12.0pt">error:GLPRDB050E At=
tribute myPortaleProfile was not found in the schema definition.<u></u><u><=
/u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:12.0pt"><u></u>=C2=A0</span=
></p></div></div></blockquote><div><br></div><div>I can&#39;t say for certa=
in, as I don&#39;t work with Net::LDAP frequently, but the syntax you used =
(delete =3D&gt; [&#39;objectclass&#39;=3D&gt;&#39;myPortaleProfile&#39;]), =
implied that you had the wrong syntax (array versus hash), and the docs (ma=
n Net::LDAP) agree. The &quot;modify&quot; method can be called with a &quo=
t;delete&quot; key in two ways:</div><div><br></div><div>1. delete =3D&gt; =
[ ATTR, ... ]</div><div>This deletes every listed attribute in the arrayref=
 defined by the brackets.</div><div><br></div><div>2. delete =3D&gt; { ATTR=
 =3D&gt; VALUE, ... }</div><div>This deletes individual values from an attr=
ibute. It can also delete the whole attribute if the value is an empty arra=
yref. This is the syntax you want to use. Just replace your square brackets=
 with curly ones (which means hashref).</div><div><br></div><div>Here&#39;s=
 another way to rewrite that:</div><div><br></div><div>=C2=A0 my %attr_to_d=
elete =3D ( objectclass =3D&gt; &#39;myPortaleProfile&#39; );</div><div>=C2=
=A0 $ldap-&gt;modify(&quot;uid=3D... etc ...&quot;, delete =3D&gt; \%attr_t=
o_delete);</div><div><br></div><div><br></div><div>AFAICT, you should eithe=
r drop your use of &quot;changes&quot; with a separate delete, or combine t=
hem all into changes. &quot;changes&quot; is there if &quot;you want to con=
trol the order in which the operations will be performed&quot; (quoting the=
 docs).</div><div><br></div><div>To delete one attribute entirely, and dele=
te a value from another one, I think you would want to do:</div><div><br></=
div><div>=C2=A0 $ldap-&gt;modify(&quot;uid=3D...etc...&quot;, delete =3D&gt=
; {</div><div>=C2=A0 =C2=A0 myCrmId =3D&gt; [],</div><div>=C2=A0 =C2=A0 obj=
ectClass =3D&gt; &#39;myPortaleProfile&#39;,</div><div>=C2=A0 });</div><div=
><br></div><div><br></div><div>Hope that helps,</div><div>--</div><div>Josh=
 I.</div></div></div></div>

--001a1143703a418ec80547984ab1--