예제 #1
0
        public async Task <CiCdDto> CreateAsync(CiCdDto dto)
        {
            encryptionService.Encrypt(dto);

            CiCd cicd = new CiCd
            {
                Id             = Guid.NewGuid(),
                Endpoint       = dto.Endpoint,
                Kind           = dto.Kind,
                IsEnabled      = dto.IsEnabled,
                IsGuestEnabled = dto.IsGuestEnabled,
                ApiKey         = dto.ApiKey,
                Password       = dto.Password,
                Username       = dto.Username
            };

            context.CicdSources.Add(cicd);
            await context.SaveChangesAsync();

            return(new CiCdDto
            {
                ApiKey = cicd.ApiKey,
                CiCdId = cicd.Id,
                Endpoint = cicd.Endpoint,
                Kind = cicd.Kind,
                Username = cicd.Username,
                Password = cicd.Password
            });
        }
예제 #2
0
        public async Task <CiCdDto> GetByIdAsync(Guid cicdId)
        {
            CiCd cicd = await context.CicdSources.FindAsync(cicdId);

            return(new CiCdDto
            {
                CiCdId = cicd.Id,
                Endpoint = cicd.Endpoint,
                Kind = cicd.Kind,
                IsEnabled = cicd.IsEnabled,
                IsGuestEnabled = cicd.IsGuestEnabled,
                ApiKey = cicd.ApiKey,
                Username = cicd.Username,
                Password = cicd.Password
            });
        }
예제 #3
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity <RefreshTask>((entity) =>
            {
                entity.HasKey(x => x.Id);
                entity.Property(x => x.Created).IsRequired();
                entity.Property(x => x.Scope).IsRequired();
            });

            modelBuilder.Entity <Vcs>((entity) =>
            {
                entity.HasKey(x => x.Id);
                entity.Property(x => x.ApiKey).IsRequired();
                entity.Property(x => x.Kind).IsRequired();
                entity.HasMany(x => x.Repositories).WithOne(r => r.Vcs).HasForeignKey(s => s.VcsId);
            });

            modelBuilder.Entity <VcsRepository>((entity) =>
            {
                entity.HasKey(x => x.Id);
                entity.Property(x => x.Url).IsRequired();
                entity.Property(x => x.WebUrl).IsRequired();
            });

            modelBuilder.Entity <EcoRegistry>((entity) =>
            {
                entity.HasKey(x => x.Id);
                entity.Property(x => x.Endpoint).IsRequired();
                entity.Property(x => x.Kind).IsRequired();
                entity.Property(x => x.ApiKey);
                entity.Property(x => x.Username);
                entity.Property(x => x.Password);
            });

            modelBuilder.Entity <Asset>(entity =>
            {
                entity.HasKey(x => x.Id);
                entity.Property(x => x.Path).IsRequired();
                entity.Property(x => x.Raw).IsRequired();
                entity.HasOne(x => x.AssetEcosystem).WithOne(x => x.Asset).HasForeignKey <AssetEcosystem>(x => x.AssetId);
                entity.HasMany(x => x.Dependencies).WithOne(x => x.Asset).HasForeignKey(x => x.AssetId);
            });

            modelBuilder.Entity <AssetDependency>(entity =>
            {
                entity.HasKey(x => x.Id);
                entity.HasOne(x => x.Dependency).WithMany(x => x.Assets).HasForeignKey(x => x.DependencyId).OnDelete(DeleteBehavior.Cascade);
                entity.HasOne(x => x.DependencyVersion).WithMany(x => x.Assets).HasForeignKey(x => x.DependencyVersionId).OnDelete(DeleteBehavior.Restrict);
            });

            modelBuilder.Entity <Dependency>((entity) =>
            {
                entity.HasKey(x => x.Id);
                entity.Property(e => e.Kind);
                entity.HasMany(x => x.Versions).WithOne(v => v.Dependency).HasForeignKey(x => x.DependencyId);
                entity.HasMany(x => x.Assets).WithOne(x => x.Dependency).HasForeignKey(x => x.DependencyId);
            });

            modelBuilder.Entity <Vulnerability>((entity) =>
            {
                entity.HasKey(x => x.Id);
                entity.Property(x => x.Link).IsRequired();
                entity.Property(x => x.ResponseData).IsRequired();
            });

            modelBuilder.Entity <DependencyVersion>((entity) =>
            {
                entity.HasKey(x => x.Id);
                entity.Property(x => x.Version).IsRequired();

                entity.HasMany(x => x.Vulnerabilities)
                .WithOne(x => x.DependencyVersion)
                .HasForeignKey(x => x.DependencyVersionId)
                .OnDelete(DeleteBehavior.Cascade);
            });

            modelBuilder.Entity <Ecosystem>((entity) =>
            {
                entity.HasKey(x => x.Id);
                entity.Property(x => x.Name).IsRequired();
                entity.HasMany(x => x.EcosystemVersions)
                .WithOne(x => x.Ecosystem)
                .HasForeignKey(x => x.EcosystemId)
                .OnDelete(DeleteBehavior.Restrict);
            });

            modelBuilder.Entity <EcosystemVersion>((entity) =>
            {
                entity.HasKey(x => x.Id);
                entity.Property(x => x.EcosystemId).IsRequired();
                entity.Property(x => x.Version);
            });

            modelBuilder.Entity <CiCd>((entity) =>
            {
                entity.HasKey(x => x.Id);
                entity.Property(x => x.Endpoint).IsRequired();
            });

            modelBuilder.Entity <Vcs>().HasData(Vcs.MockData());
            modelBuilder.Entity <EcoRegistry>().HasData(EcoRegistry.MockData());
            modelBuilder.Entity <CiCd>().HasData(CiCd.MockData());
        }