如何使用 Azure DevOps Server Rest APi 赋予权限?

问题描述 投票:0回答:1

https:/docs.microsoft.comen-usrestapiazuredevopssecurity?view=azure-devops-server-rest-5.0。https:/docs.microsoft.comen-usrestapiazuredevopssecurityaccess%20control%20entries?view=azure-devops-server-rest-5.0。

你好,我在尝试了解ADO 2019中使用API设置权限的方式时遇到了问题。 我可以看到安全命名空间一个API做什么。我可以得到与,例如,git repos有关的位智。我看不到如何给用户或组添加权限,比如我看不到如何得到一个有多个权限的位智,我是把它们加在一起吗?我可以看到API说如何添加ACE,但实际上并没有告诉我如何真正添加权限。我试着解释一下。

如果我运行ACL的API,我得到一堆信息,其中一个是token。好吧,所以如果我用 git API 获取 git repo 的 GUID 来列出它们,GUID 肯定会像命名空间那样与 token 中的 ID 匹配。 不对。

这些例子似乎不是实际的例子。我在找 "如果你有一个 git repo ,下面是你如何给别人权限""这是一个获取一个组的现有权限并添加另一个组的例子"。

而不是仅仅是 '这里有一串guid要放到API中去' 而没有解释这几块,也没有解释它具体在做什么。我似乎无法将GUI中添加perms的内容,和安全API带回来的东西联系起来。

我是Azure DevOps on prem,所以在工具选择上比较有限。我问过的其他人都说他们放弃了尝试使用这个。 微博上AzureDevops说我可以在这里和团队联系。 我问的是如何用安全API做事情,然后我可以去写出来,建议如何更新文档。 我显然太厚道了,无法从那里的内容中找出答案,而且我似乎不是唯一一个。谢谢你

azure-devops azure-devops-rest-api azure-devops-server-2019
1个回答
0
投票

对于 Azure DevOps 服务,您可以使用以下方法管理组成员资格 图形API. 但是这个api对于Azure DevOps Server来说是不可用的。

在我看来,对于内部部署的TFSAzure DevOps Server,TFSSecurity命令行比TFS API更容易为服务器级、集合级或项目级组中的用户或组添加权限。你可以考虑使用TFSSecurity命令行。

https:/docs.microsoft.comen-usazuredevopsservercommand-linetfssecurity-cmd?view=azure-devops-2019。

你也可以查看以下代码来获取权限。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.TeamFoundation.Client;
    using Microsoft.TeamFoundation.Server;
    using Microsoft.TeamFoundation.VersionControl.Client;
    using Microsoft.TeamFoundation.Framework.Client;

    namespace API
    {
        class Program
        {
            static void Main(string[] args)
            {
                string project = "http://xxx.xxx.xxx.xxx:8080/tfs";
                TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(project));
                var tps = tpc.GetService<VersionControlServer>();
                var ttt = tps.GetTeamProject("ProjectName");
                ISecurityService securityService = tpc.GetService<ISecurityService>();
                System.Collections.ObjectModel.ReadOnlyCollection<SecurityNamespace> securityNamespaces = securityService.GetSecurityNamespaces();
                IGroupSecurityService gss = tpc.GetService<IGroupSecurityService>();
                Identity SIDS = gss.ReadIdentity(SearchFactor.AccountName, "GroupName", QueryMembership.Expanded);//GourName format: [ProjectName]\\GourpName
                IdentityDescriptor id = new IdentityDescriptor("Microsoft.TeamFoundation.Identity", SIDS.Sid);
                List<SecurityNamespace> securityList = securityNamespaces.ToList<SecurityNamespace>();
                string securityToken;
                foreach (SecurityNamespace sn in securityList)
                {
                    if (sn.Description.DisplayName == "Project")
                    {
                        securityToken = "$PROJECT:" + ttt.ArtifactUri.AbsoluteUri;
                        sn.SetPermissions(securityToken, id, 115, 0, true);
                    }
                }                
            }
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.