public async Task RemoveSoftwareComponentDuplicates(JustificationTypeConstant type, long specId)
        {
            var parentId = await _ctx.BuildSpecifications.Where(p => p.Id == specId).Select(p => p.ParentId)
                           .FirstOrDefaultAsync();

            if (parentId.HasValue)
            {
                var parents = _ctx.SoftwareComponents.ForBuildSpec(parentId.Value).OfJustificationType(type)
                              .Select(p => p.Name.ToLower()).ToArray();
                var mine = _ctx.SoftwareComponents.ForBuildSpec(specId).OfJustificationType(type)
                           .Where(p => parents.Contains(p.Name.ToLower()));
                foreach (var c in mine)
                {
                    _ctx.SoftwareComponents.Remove(c);
                }

                await _ctx.SaveChangesAsync();
            }
        }
예제 #2
0
        protected PackageBase(JustificationTypeConstant packageType)
        {
            PackageType = packageType;
            switch (packageType)
            {
            case JustificationTypeConstant.Application:
                Example = "Chef Client 12.33.1";
                break;

            case JustificationTypeConstant.Feature:
                Example = "NET-Framework-45-Core";
                break;

            case JustificationTypeConstant.Package:
                Example = "chefclient";
                break;
            }

            AllPciScopes = Enum.GetValues(typeof(PciScopeConstant)).Cast <PciScopeConstant>().ToArray();
        }
        public async Task <ReviewDataItems> ReviewComplianceDataDetails(long specId, int environmentId,
                                                                        JustificationTypeConstant resultType, bool shouldExist, PortTypeConstant?portType, string name)
        {
            var date  = DateTime.Today.AddDays(-30);
            var nodes = await _ctx.Nodes.AsNoTracking()
                        .Where(p => p.BuildSpecification != null &&
                               (p.BuildSpecification.Id == specId || p.BuildSpecification.ParentId == specId))
                        .Active()
                        .ForEnvironment(environmentId)
                        .Where(p => p.LastComplianceResultId != null && p.LastComplianceResultDate > date)
                        .Join(_ctx.ComplianceResults.AsNoTracking(),
                              n => new { n.InventoryItemId, ResultId = (Guid)n.LastComplianceResultId },
                              c => new { c.InventoryItemId, c.ResultId },
                              (n, c) => new { Run = c, Node = n }
                              )
                        .Where(p => p.Run.Tests.Any(c =>
                                                    c.ResultType == resultType && c.PortType == portType && c.Name == name &&
                                                    c.ShouldExist == shouldExist))
                        .Select(p => new
            {
                p.Node.ChefNodeId,
                p.Node.Fqdn,
                p.Node.EnvironmentId,
                Environment = p.Node.Environment.Name,
                p.Node.PciScope,
                Product  = p.Node.Product.Name,
                Function = p.Node.Function.Name,
                p.Node.Owner,
                BuildSpec = p.Node.BuildSpecificationId == null ? string.Empty : p.Node.BuildSpecification.Name
            })
                        .ToArrayAsync();

            var items = nodes.Select(p => new ReviewDataItem(p.ChefNodeId.GetValueOrDefault(), p.Fqdn,
                                                             p.EnvironmentId, p.Environment,
                                                             p.PciScope, p.Product, p.Function, p.Owner.OwnerText(), p.BuildSpec));

            return(new ReviewDataItems(resultType, shouldExist, portType, name, items));
        }
 public async Task <PartialViewResult> All(JustificationTypeConstant id, long specId)
 {
     return(PartialView(new Packages(await _packageFactory.GetSoftwareComponents(id, specId))));
 }
 public async Task <PartialViewResult> ForSpec(JustificationTypeConstant id, BuildSpecificationTypeConstant specType, long specId)
 {
     return(PartialView(new PackagesScreen(specType, id, specId, await _packageFactory.GetSoftwareComponents(id, specId))));
 }
예제 #6
0
 public NewPackage(JustificationTypeConstant packageType, BuildSpecificationTypeConstant buildSpecificationType, long specId, IDictionary <int, (string name, string color)> allEnvironments) : base(packageType)
예제 #7
0
        public async Task <Suggestions> ComplianceDataSuggestions(long specId, JustificationTypeConstant resultType,
                                                                  bool shouldExist, PortTypeConstant?portType, string value)
        {
            var spec = await _ctx.BuildSpecifications.AsNoTracking()
                       .Include(p => p.Parent)
                       .Include(p => p.Parent.Owner)
                       .Include(p => p.Owner)
                       .ById(specId);

            if (spec == null)
            {
                return(Suggestions.Empty);
            }

            if (InvalidPlatform(spec.Platform ?? spec.Parent?.Platform, resultType, portType))
            {
                return(Suggestions.NodeMismatch);
            }

            var list = new List <Suggestion>();

            if (!shouldExist)
            {
                //2 - 4 ways to add it
                list.AddRange(CreateAdd(spec, spec.Owner, resultType, value, portType));
                if (spec.BuildSpecificationType == BuildSpecificationTypeConstant.Application &&
                    spec.ParentId.HasValue)
                {
                    list.AddRange(CreateAdd(spec.Parent, spec.Parent?.Owner, resultType, value, portType));
                }
            }
            else
            {
                //can only remove it if found.
                if (resultType == JustificationTypeConstant.Port)
                {
                    list.AddRange(CreateRemove(spec, spec.Owner, resultType, value,
                                               await FindPort(spec.Id, portType, value), portType));
                    if (spec.BuildSpecificationType == BuildSpecificationTypeConstant.Application &&
                        spec.ParentId.HasValue)
                    {
                        var parent = spec.Parent;
                        if (parent != null)
                        {
                            list.AddRange(CreateRemove(parent, parent.Owner, resultType, value,
                                                       await FindPort(parent.Id, portType, value), portType));
                        }
                    }
                }
                else
                {
                    list.AddRange(CreateRemove(spec, spec.Owner, resultType, value,
                                               await FindSoftware(spec.Id, resultType, value)));
                    if (spec.BuildSpecificationType == BuildSpecificationTypeConstant.Application &&
                        spec.ParentId.HasValue)
                    {
                        var parent = spec.Parent;
                        if (parent != null)
                        {
                            list.AddRange(CreateRemove(parent, parent.Owner, resultType, value,
                                                       await FindSoftware(parent.Id, resultType, value)));
                        }
                    }
                }
            }

            if (!list.Any())
            {
                return(Suggestions.Empty);
            }

            return(new Suggestions(spec.BuildSpecificationType, spec.Id, spec.Name, list));
        }
 public PartialViewResult New(JustificationTypeConstant id, long specId)
 {
     return(PartialView(new NewJustification(specId, id)));
 }
예제 #9
0
 public static string PartialGetJustificationsForSpec(this IUrlHelper helper, JustificationTypeConstant type, long specId)
 {
     return(helper.RouteUrl("default", new { controller = "Justifications", action = "ForSpec", id = type, specId }));
 }
 public static IQueryable<T> OfJustificationType<T>(this IQueryable<T> querable, JustificationTypeConstant type)
     where T : JustificationTypeReference
 {
     return querable.Where(p => p.JustificationType == type);
 }
예제 #11
0
 public static string PartialReviewSuggestions(this IUrlHelper helper, long specId, int environmentId, JustificationTypeConstant resultType, bool shouldExist, PortTypeConstant?portType)
 {
     return(helper.RouteUrl("default", new { controller = "BuildSpec", action = "Suggestions", id = specId, environmentId, resultType, shouldExist, portType }));
 }
 public static string PartialGetPackages(this IUrlHelper helper, JustificationTypeConstant packageType, long specId)
 {
     return(helper.RouteUrl("default", new { controller = "Packages", action = "All", id = packageType, specId }));
 }
 public static string JsonCleanupDuplicatePackages(this IUrlHelper helper, JustificationTypeConstant packageType, long specId)
 {
     return(helper.RouteUrl("default", new { controller = "Packages", action = "CleanDuplicates", id = packageType, specId }));
 }
 public static string JsonBulkAddPackages(this IUrlHelper helper, JustificationTypeConstant packageType)
 {
     return(helper.RouteUrl("default", new { controller = "Packages", action = "BulkAdd", id = packageType }));
 }
 public static string PartialNewBulkPackages(this IUrlHelper helper, BuildSpecificationTypeConstant specType, JustificationTypeConstant packageType, long specId)
 {
     return(helper.RouteUrl("default", new { controller = "Packages", action = "NewBulk", id = packageType, specId, specType }));
 }
 public static string PartialPackagesScreen(this IUrlHelper helper, BuildSpecificationTypeConstant specType, JustificationTypeConstant packageType)
 {
     return(helper.RouteUrl("default", new { controller = "Packages", action = "ForSpec", specType, id = packageType }));
 }
예제 #17
0
 public static string JsonAddJustification(this IUrlHelper helper, JustificationTypeConstant type, long specId)
 {
     return(helper.RouteUrl("default", new { controller = "Justifications", action = "Add", id = type, specId }));
 }
 public async Task <PartialViewResult> New(JustificationTypeConstant id, BuildSpecificationTypeConstant specType, long specId)
 {
     return(PartialView(new NewPackage(id, specType, specId, await _nodeFactory.GetEnvironments())));
 }
 public PartialViewResult NewBulk(JustificationTypeConstant id, BuildSpecificationTypeConstant specType, long specId)
 {
     return(PartialView(new NewBulkPackages(id, specType, specId)));
 }
 private static string[] SoftwareComponentsOfType(IEnumerable <SoftwareComponent> software,
                                                  JustificationTypeConstant type)
 {
     return(software.Where(p => p.JustificationType == type).Select(p => p.Name).Distinct()
            .ToArray());
 }
 public async Task <PartialViewResult> Suggestions(long id, JustificationTypeConstant resultType, bool shouldExist, PortTypeConstant?portType, string name)
 {
     return(PartialView(
                await _suggestionFactory.ComplianceDataSuggestions(id, resultType, shouldExist, portType, name)));
 }
예제 #22
0
 public NewBulkPackages(JustificationTypeConstant packageType, BuildSpecificationTypeConstant buildSpecificationType, long specId) : base(packageType, buildSpecificationType, specId)
 {
 }
 public async Task <PartialViewResult> ReviewDetails(long id, int environmentId, JustificationTypeConstant resultType, bool shouldExist, PortTypeConstant?portType, string name)
 {
     return(PartialView(
                await _buildSpecificationFactory.ReviewComplianceDataDetails(id, environmentId, resultType, shouldExist, portType, name)));
 }
예제 #24
0
        public async Task <string[]> BulkAddSoftwareComponents(JustificationTypeConstant type, long specId,
                                                               string[] names, string[] descriptions)
        {
            if (names == null)
            {
                throw new ArgumentNullException(nameof(names));
            }
            if (!names.All(IsValidName))
            {
                throw new ArgumentException(
                          $@"At least one of the {type} names is not valid, it must not be empty whitespace.", nameof(names));
            }

            if (descriptions != null && descriptions.Length > 0 && descriptions.Length != names.Length)
            {
                throw new ArgumentException(
                          $@"At least one of the {type} descriptions the number of names does not match the number of descriptions",
                          nameof(descriptions));
            }
            if (descriptions == null || descriptions.Length == 0)
            {
                descriptions = new string[names.Length];
            }

            var all = names.Select((name, index) => new SoftwareComponent
            {
                JustificationType    = type,
                BuildSpecificationId = specId,
                Name        = name,
                Description = descriptions[index]
            }).ToList();

            var notAdded = new List <string>();

            if (all.Count > 0)
            {
                var parentId = await _ctx.BuildSpecifications.Where(p => p.Id == specId).Select(p => p.ParentId)
                               .FirstOrDefaultAsync();

                var ids = new List <long> {
                    specId
                };
                if (parentId.HasValue)
                {
                    ids.Add(parentId.Value);
                }


                all.ForEach(c =>
                {
                    if (_ctx.SoftwareComponents.Any(p =>
                                                    ids.Contains(p.BuildSpecificationId) && p.Name == c.Name &&
                                                    p.JustificationType == c.JustificationType))
                    {
                        notAdded.Add(c.Name);
                    }
                    else
                    {
                        _ctx.SoftwareComponents.Add(c);
                    }
                });
                if (all.Count != notAdded.Count)
                {
                    await _ctx.SaveChangesAsync();
                }
            }

            return(notAdded.ToArray());
        }
 public async Task <PartialViewResult> ForSpec(JustificationTypeConstant id, long specId)
 {
     return(PartialView(new Justifications(await _justificationFactory.GetJustifications(id, specId))));
 }
예제 #26
0
        public async Task <string[]> BulkAddSoftwareComponentsWithJustifications(JustificationTypeConstant type,
                                                                                 long specId, string[] names,
                                                                                 string[] justifications)
        {
            if (names == null)
            {
                throw new ArgumentNullException(nameof(names));
            }

            if (justifications == null)
            {
                throw new ArgumentNullException(nameof(justifications));
            }

            if (!names.All(IsValidName))
            {
                throw new ArgumentException(
                          $@"At least one of the {type} names is not valid, it must not be empty whitespace.", nameof(names));
            }

            if (justifications.Length != names.Length)
            {
                throw new ArgumentException($@"At least one of the {type} names does not have a justification",
                                            nameof(justifications));
            }

            var all = names.Select((name, index) => new
            {
                Index = index,
                sc    = new SoftwareComponent
                {
                    JustificationType    = type,
                    BuildSpecificationId = specId,
                    Name = name
                }
            }).ToList();

            var notAdded = new List <string>();

            if (all.Count > 0)
            {
                var parentId = await _ctx.BuildSpecifications.Where(p => p.Id == specId).Select(p => p.ParentId)
                               .FirstOrDefaultAsync();

                var ids = new List <long> {
                    specId
                };
                if (parentId.HasValue)
                {
                    ids.Add(parentId.Value);
                }


                all.ForEach(c =>
                {
                    if (_ctx.SoftwareComponents.Any(p =>
                                                    ids.Contains(p.BuildSpecificationId) && p.Name == c.sc.Name &&
                                                    p.JustificationType == c.sc.JustificationType))
                    {
                        notAdded.Add(c.sc.Name);
                    }
                    else
                    {
                        if (!string.IsNullOrWhiteSpace(justifications[c.Index]))
                        {
                            var justification = _ctx.Justifications.Add(new Justification
                            {
                                BuildSpecificationId = specId,
                                JustificationType    = type,
                                JustificationText    = justifications[c.Index]
                            }).Entity;
                            c.sc.Justification = justification;
                        }

                        _ctx.SoftwareComponents.Add(c.sc);
                    }
                });
                if (all.Count != notAdded.Count)
                {
                    await _ctx.SaveChangesAsync();
                }
            }

            return(notAdded.ToArray());
        }
 public Suggestion(BuildSpecificationTypeConstant specType, long specId, string specName, string specOwner, string specOwnerSam, JustificationTypeConstant suggestionType, PortTypeConstant?portType, string value, bool clone)
 {
     SpecType       = specType;
     SpecId         = specId;
     SpecName       = specName;
     SpecOwner      = specOwner;
     SpecOwnerSam   = specOwnerSam;
     SuggestionType = suggestionType;
     PortType       = portType;
     Value          = value;
     Clone          = clone;
 }
예제 #28
0
 public NewJustification(long buildSpecid, JustificationTypeConstant justificationType)
 {
     SpecId            = buildSpecid;
     JustificationType = justificationType;
 }