Skip to content
This repository was archived by the owner on Jun 3, 2021. It is now read-only.

infra scan widget implementation #201

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
538 changes: 265 additions & 273 deletions package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import {StaticAnalysisDeleteFormComponent} from '../../../widget_modules/static-
import {SecurityScanDeleteFormComponent} from '../../../widget_modules/security-scan/security-scan-delete-form/security-scan-delete-form.component';
import {OSSDeleteFormComponent} from '../../../widget_modules/opensource-scan/oss-delete-form/oss-delete-form.component';
import {TestDeleteFormComponent} from '../../../widget_modules/test/test-delete-form/test-delete-form.component';
import {InfraScanWidgetComponent} from '../../../widget_modules/infra-scan/infra-scan-widget/infra-scan-widget.component';
import {InfraScanConfigComponent} from '../../../widget_modules/infra-scan/infra-scan-config/infra-scan-config.component';
import {InfraScanDeleteComponent} from '../../../widget_modules/infra-scan/infra-scan-delete/infra-scan-delete.component';

export interface IDashboardResponse {
data: any;
Expand Down Expand Up @@ -77,12 +80,12 @@ export const widgetsAll = [
configForm: [StaticAnalysisConfigFormComponent, SecurityScanConfigComponent, OSSConfigFormComponent, TestConfigFormComponent],
deleteForm: [StaticAnalysisDeleteFormComponent, SecurityScanDeleteFormComponent, OSSDeleteFormComponent, TestDeleteFormComponent]
},
/*{
title: ['Placeholder'],
component: [PlaceholderWidgetComponent],
{
title: ['Infra Scan'],
component: [InfraScanWidgetComponent],
status: 'Success',
widgetSize: 'col-xl-2',
configForm: [BuildConfigFormComponent],
deleteForm: [BuildDeleteFormComponent]
},*/
widgetSize: 'col-xl-4',
configForm: [InfraScanConfigComponent],
deleteForm: [InfraScanDeleteComponent]
}
];
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {BuildModule} from '../../widget_modules/build/build.module';
import {RepoModule} from '../../widget_modules/repo/repo.module';
import {DeployModule} from '../../widget_modules/deploy/deploy.module';
import {FeatureModule} from '../../widget_modules/feature/feature.module';
import {InfraScanModule} from '../../widget_modules/infra-scan/infra-scan.module';

@NgModule({
declarations: [
Expand All @@ -29,6 +30,7 @@ import {FeatureModule} from '../../widget_modules/feature/feature.module';
RepoModule,
DeployModule,
FeatureModule,
InfraScanModule,
],
entryComponents: [
]
Expand Down
4 changes: 4 additions & 0 deletions src/app/shared/charts/click-list/click-list-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ export interface IClickListItemOSS extends IClickListItem {
components: string[];
lastUpdated: number;
}

export interface IClickListItemInfra extends IClickListItem {
vulnerability: any;
}
9 changes: 2 additions & 7 deletions src/app/shared/dashboard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,15 @@ export class DashboardService {
tempDashboard$.subscribe(dashboard => this.dashboardSubject.next(dashboard));
}

checkCollectorItemTypeExist(ciType: string) {
checkCollectorItemTypeExist(ciType: string): boolean {
let collectorItems;
let exists = false;
this.dashboardConfig$.pipe(take(1), map(dashboard => dashboard)).subscribe(dashboard => {
dashboard.application.components.forEach((component: any, index: number) => {
collectorItems = dashboard.application.components[index].collectorItems;
for (const key in collectorItems) {
if (key === ciType) {
exists = true;
}
}
exists = Object.keys(collectorItems).some(type => type === ciType);
});
});

return exists;
}

Expand Down
1 change: 1 addition & 0 deletions src/app/shared/widget-header/widget-header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ export class WidgetHeaderComponent implements OnInit {
case 'Security Analysis': { collectorType = 'StaticSecurityScan'; break; }
case 'Open Source': { collectorType = 'LibraryPolicy'; break; }
case 'Test': { collectorType = 'Test'; break; }
case 'Infra Scan': { collectorType = 'InfrastructureScan'; break; }
default: { collectorType = ''; break; }
}
return collectorType;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<form [formGroup]="infraScanConfigForm" (ngSubmit)="submitForm()">
<div class="modal-body">
<div class="container">
<div class="form-group">
<label class="col-form-label" for="iJob">Infrastructure Scan <span class="required-text"> *</span></label>
<input id="iJob" type="search" class="form-control"
[class.is-invalid]="((configForm.iJob.dirty || configForm.iJob.touched) && configForm.iJob.errors) || searchFailed"
formControlName="iJob"
[ngbTypeahead]="typeAheadResults"
[inputFormatter]="getInfraScanJobTitle"
[resultFormatter]="getInfraScanJobTitle"
placeholder="Infrastructure Scan Job..." required/>
<span *ngIf="searching">searching...</span>
<div class="invalid-feedback" *ngIf="!searchFailed || configForm.iJob.value === ''">Please provide a infrastructure scan job.</div>
<div class="invalid-feedback" *ngIf="searchFailed && !searching && configForm.iJob.value !== ''">Sorry, suggestions could not be loaded.</div>
</div>
</div>
</div>
<div class="modal-footer">
<div class="container">
<div class="row">
<div class="col text-center">
<button class="btn btn-primary" [disabled]="!infraScanConfigForm.valid">
Save
</button>
</div>
</div>
</div>
</div>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { InfraScanConfigComponent } from './infra-scan-config.component';

describe('InfraScanConfigComponent', () => {
let component: InfraScanConfigComponent;
let fixture: ComponentFixture<InfraScanConfigComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ InfraScanConfigComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(InfraScanConfigComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import {Component, Input, OnInit} from '@angular/core';
import {FormBuilder, FormGroup} from "@angular/forms";
import {Observable, of} from "rxjs";
import {NgbActiveModal} from "@ng-bootstrap/ng-bootstrap";
import {CollectorService} from "../../../shared/collector.service";
import {DashboardService} from "../../../shared/dashboard.service";
import {catchError, debounceTime, distinctUntilChanged, map, switchMap, take, tap} from "rxjs/operators";

@Component({
selector: 'app-infra-scan-config',
templateUrl: './infra-scan-config.component.html',
styleUrls: ['./infra-scan-config.component.sass']
})
export class InfraScanConfigComponent implements OnInit {
private componentId: string;
private widgetConfigId: string;
infraScanConfigForm: FormGroup;

searching = false;
searchFailed = false;
typeAheadResults: (text$: Observable<string>) => Observable<any>;

getInfraScanJobTitle = (collectorItem: any) => {
if (!collectorItem) {
return '';
}
const description = (collectorItem.description as string);
return collectorItem.collector.name + ' : ' + description;
}

@Input()
set widgetConfig(widgetConfig: any) {
if (!widgetConfig) {
return;
}
this.widgetConfigId = widgetConfig.options.id;
this.infraScanConfigForm.get('iJob').setValue(widgetConfig.options.iJob);
}

constructor(
public activeModal: NgbActiveModal,
public formBuilder: FormBuilder,
public collectorService: CollectorService,
public dashboardService: DashboardService
) {
this.createForm();
}

createForm() {
this.infraScanConfigForm = this.formBuilder.group({
iJob: ''
});
}

ngOnInit() {

this.typeAheadResults = (text$: Observable<string>) =>
text$.pipe(
debounceTime(300),
distinctUntilChanged(),
tap(() => this.searching = true),
switchMap(term => {
return term.length < 2 ? of([]) :
this.collectorService.searchItems('InfrastructureScan', term).pipe(
tap(val => {
if (!val || val.length === 0) {
this.searchFailed = true;
return of([]);
}
this.searchFailed = false;
}),
catchError(() => {
this.searchFailed = true;
return of([]);
}));
}),
tap(() => this.searching = false)
);

this.loadSavedInfraScanJob();
this.getDashboardComponent();
}

submitForm() {
const newConfig = {
name: 'infrascan',
componentId: this.componentId,
collectorItemId: this.infraScanConfigForm.value.iJob.id,
options: {
id: this.widgetConfigId ? this.widgetConfigId : 'infrascan0',
},
};
this.activeModal.close(newConfig);
}

loadSavedInfraScanJob() {
this.dashboardService.dashboardConfig$.pipe(take(1),
map(dashboard => {
const infraScanCollector = dashboard.application.components[0].collectorItems.InfrastructureScan;
const savedCollectorinfraScanJob = infraScanCollector ? infraScanCollector : null;

if (savedCollectorinfraScanJob) {
const securityId = savedCollectorinfraScanJob[0].id;
return securityId;
}
return null;
}),
switchMap(securityId => {
if (securityId) {
return this.collectorService.getItemsById(securityId);
}
return of(null);
})).subscribe(collectorData => {
if (collectorData) {
this.infraScanConfigForm.get('iJob').setValue(collectorData);
}
});
}

private getDashboardComponent() {
this.dashboardService.dashboardConfig$.pipe(take(1),
map(dashboard => {
return dashboard.application.components[0].id;
})).subscribe(componentId => this.componentId = componentId);
}

get configForm() { return this.infraScanConfigForm.controls; }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<form [formGroup]="infraScanDeleteForm" (ngSubmit)="submitForm()">
<div class="modal-body">
<div class="row">
<div class="col">
<div class="col-form-label">{{message}}</div>
</div>
</div>
</div>
<div class="modal-footer">
<div class="col text-center">
<button class="btn btn-outline-secondary mr-3" (click)="activeModal.dismiss()">Cancel</button>
<button class="btn btn-danger" [disabled]="!infraScanDeleteForm.valid || !widgetConfigId">Delete</button>
</div>
</div>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { InfraScanDeleteComponent } from './infra-scan-delete.component';

describe('InfraScanDeleteComponent', () => {
let component: InfraScanDeleteComponent;
let fixture: ComponentFixture<InfraScanDeleteComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ InfraScanDeleteComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(InfraScanDeleteComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Loading