How can I authenticate when using the Bugzilla Perl API in a script?

随声附和 提交于 2019-12-01 06:49:01

Oh, I'm being rather ignorant today, I focused on "web services" and didn't understand what you really wanted.

If you're just using the API to communicate with the database (as opposed to manipulating the database directly), do you really need to authenticate as any user at all?

In the 3.2 source tree, look at merge-users.pl for instance, which uses Bugzilla::User objects. Couldn't you do the same with Bugzilla::Component?

You should also look at sanitycheck.pl, which uses Bugzilla->set_user.

There's been some significant upgrades in the web services capabilities since 3.2, can you upgrade?

In 3.6 at least, check out contrib/bz_webservice_demo.pl for how to use the User.login method.

http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/User.html

The following code snippet might enter the question. Here we check also that the user has the correct "editcomponents" credential.

my $user = new Bugzilla::User({ name => $login })
  || ThrowUserError('invalid_username', { name => $login });


# Authenticate using this user account.
Bugzilla->set_user($user);
$user->in_group('editcomponents')
      || ThrowUserError("auth_failure", {group  => "editcomponents",
                                         action => "add",
                                         object => "products"});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!