0

我在内部部署的 azure devops 环境中自动化了几个进程,并且我正在寻找允许我从 azure devops 服务器检索用户权利的 rest api。

4

1 回答 1

0

目前没有这样的 REST API 来检索本地 Azure DevOps 服务器的用户权利。

但是,作为一种解决方法,我们可以使用客户端 API 从特定集合中检索所有用户:(需要安装Microsoft.TeamFoundationServer.ExtendedClient

using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Framework.Common;
using System.Linq;
using System.IO;

namespace Getuserlist

{

    class Program

    {
        static void Main(string[] args)

        {

            TfsConfigurationServer tcs = new TfsConfigurationServer(new Uri("https://wsicads2019"));

            IIdentityManagementService ims = tcs.GetService<IIdentityManagementService>();

            TeamFoundationIdentity tfi = ims.ReadIdentity(IdentitySearchFactor.AccountName, "[DefaultCollection]\\Project Collection Valid Users", MembershipQuery.Expanded, ReadIdentityOptions.None);

            TeamFoundationIdentity[] ids = ims.ReadIdentities(tfi.Members, MembershipQuery.None, ReadIdentityOptions.None);

            using (StreamWriter file = new StreamWriter("userlist.txt"))

                foreach (TeamFoundationIdentity id in ids)

                {
                    if (id.Descriptor.IdentityType == "System.Security.Principal.WindowsIdentity")

                    { Console.WriteLine("[{0},{1}]", id.UniqueName); }

                    file.WriteLine("[{0},{1}]", id.UniqueName);
                }

            var count = ids.Count(x => ids.Contains(x));
            Console.WriteLine(count);
            Console.ReadLine();
        }
    }
}

或者从客户端上的开发人员命令提示符运行TFSSecurity命令或在 Azure DevOps 服务器应用程序层上运行以获取所有用户和组的列表:

tfssecurity /imx all: /server:http://server:8080/tfs

对于访问级别,我们可以调用以下 REST API 来获取相应的用户:(在 Azure DevOps 2019 上测试)

Stakeholder : 
http://server:8080/tfs/_api/_identity/ReadLicenseUsers?__v=5&licenseTypeId=242a857e-50ce-43d9-ba9f-3aa82457d726

Basic : 
http://server:8080/tfs/_api/_identity/ReadLicenseUsers?__v=5&licenseTypeId=8b71784c-27ab-4490-bb97-e699ed4123e1

Basic + Test Plans : 
http://server:8080/tfs/_api/_identity/ReadLicenseUsers?__v=5&licenseTypeId=f29e17f1-60bd-44f0-ab2f-d67207ee9484

VS Enterprise : 
http://server:8080/tfs/_api/_identity/ReadLicenseUsers?__v=5&licenseTypeId=519a4528-2bd6-4ea4-b3cb-5440c1aaebc3
于 2020-07-14T08:10:32.373 回答