示例#1
0
        private async Task <Tuple <Waddle.Dtos.Project, bool> > EnsureProjectExistsAsync(
            ProjectManifest manifest, Waddle.ProjectService projectService,
            ProcessTemplate tempalte)
        {
            var projectCreatedJIT = false;
            var projects          = await projectService.GetProjectsAsync();

            var project = projects.Value.FirstOrDefault(p => p.Name.Equals(manifest.Metadata.Name,
                                                                           StringComparison.OrdinalIgnoreCase));

            if (project == null)
            {
                await projectService.CreateProjectAsync(
                    manifest.Metadata.Name, tempalte,
                    manifest.Template.SourceControlType, manifest.Metadata.Description);

                projectCreatedJIT = true;
                Logger.StatusBegin("Waiting on project creation...");
                while (project == null)
                {
                    projects = await projectService.GetProjectsAsync();

                    project = projects.Value.FirstOrDefault(p => p.Name.Equals(manifest.Metadata.Name,
                                                                               StringComparison.OrdinalIgnoreCase));
                }
                Logger.StatusEndSuccess("Succeed");
            }
            else
            {
                Logger.Message($"{project.Name} already exists...");
            }
            return(new Tuple <Waddle.Dtos.Project, bool>(project, projectCreatedJIT));
        }
示例#2
0
        private async Task EnsureTeamProvisionedAsync(ProjectManifest manifest, Waddle.AdoConnectionFactory factory, Waddle.ProjectService projectService, Tuple <Waddle.Dtos.Project, bool> outcome)
        {
            var gService   = factory.GetGroupService();
            var secService = factory.GetSecurityNamespaceService();
            var aclService = factory.GetAclListService();
            var allUsers   = await gService.ListUsersAsync();

            foreach (var teamManifest in manifest.Teams)
            {
                var tc = await projectService.GetTeamsAsync();

                var eteam = tc.Value
                            .FirstOrDefault(tc => tc.Name.Equals(teamManifest.Name,
                                                                 StringComparison.OrdinalIgnoreCase));

                if (eteam == null)
                {
                    Logger.StatusBegin($"Creating team [{teamManifest.Name}]...");
                    var team = await projectService.CreateTeamAsync(
                        new Microsoft.TeamFoundation.Core.WebApi.WebApiTeam
                    {
                        Name        = teamManifest.Name,
                        Description = teamManifest.Description,
                        ProjectId   = outcome.Item1.Id,
                        ProjectName = outcome.Item1.Name
                    },
                        outcome.Item1.Id);

                    while (eteam == null)
                    {
                        tc = await projectService.GetTeamsAsync();

                        eteam = tc.Value
                                .FirstOrDefault(tc => tc.Name.Equals(teamManifest.Name,
                                                                     StringComparison.OrdinalIgnoreCase));
                    }
                    Logger.StatusEndSuccess("Succeed");
                }

                if (eteam != null && teamManifest.Membership != null &&
                    (teamManifest.Membership.Groups != null && teamManifest.Membership.Groups.Any()))
                {
                    var teamGroup = await GetGroupByNameAsync(factory, IdentityOrigin.Vsts.ToString(), eteam.Name);

                    if (teamGroup != null)
                    {
                        foreach (var gp in teamManifest.Membership.Groups)
                        {
                            var groupObject = await GetGroupByNameAsync(factory, IdentityOrigin.Aad.ToString(), gp.Name, gp.Id);

                            if (groupObject != null)
                            {
                                await gService.AddMemberAsync(eteam.ProjectId, teamGroup.Descriptor, groupObject.Descriptor);
                            }
                        }


                        foreach (var user in teamManifest.Membership.Users)
                        {
                            var userInfo = allUsers.Value.FirstOrDefault(u => u.OriginId.Equals(user.Id));
                            if (userInfo != null)
                            {
                                await gService.AddMemberAsync(eteam.ProjectId, teamGroup.Descriptor, userInfo.Descriptor);
                            }
                        }
                    }
                }

                if (eteam != null &&
                    teamManifest.Admins != null &&
                    teamManifest.Admins.Any())
                {
                    var token            = $"{eteam.ProjectId}\\{eteam.Id}";
                    var releaseNamespace = await secService.GetNamespaceAsync(SecurityNamespaceConstants.Identity);

                    var secNamespaceId = releaseNamespace.NamespaceId;
                    var aclDictioanry  = new Dictionary <string, VstsAcesDictionaryEntry>();

                    foreach (var adminUserName in teamManifest.Admins)
                    {
                        var matches = await gService.GetLegacyIdentitiesByNameAsync(adminUserName.Name);

                        if (matches != null && matches.Count > 0)
                        {
                            var adminUserInfo = matches.Value.First();
                            aclDictioanry.Add(adminUserInfo.Descriptor, new VstsAcesDictionaryEntry
                            {
                                Allow      = 31,
                                Deny       = 0,
                                Descriptor = adminUserInfo.Descriptor
                            });
                        }
                    }
                    await aclService.SetAclsAsync(secNamespaceId, token, aclDictioanry, false);
                }
            }
        }