Skip to content

Commit 966c518

Browse files
committed
GitOps - added path validator and GitOps documentation
1 parent 1dfd53b commit 966c518

22 files changed

+181
-17
lines changed

src/app/dashboard-module/domain-module/ext-gitops/ext-gitops.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { GitOpsEnvSelectionComponent } from './gitops-env-selection/gitops-env-s
1212
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
1313
import { AdminService } from 'src/app/services/admin.service';
1414
import { GitOpsUpdateTokensComponent } from './gitops-update-tokens/gitops-update-tokens.component';
15-
import { windowValidator } from './gitops-validator';
15+
import { pathValidator, windowValidator } from './gitops-validator';
1616
import { ToastService } from 'src/app/_helpers/toast.service';
1717
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
1818
import { NgbdModalConfirmComponent } from 'src/app/_helpers/confirmation-dialog';
@@ -268,7 +268,7 @@ export class ExtGitOpsComponent implements OnInit, OnDestroy {
268268
environment: new FormControl('', [Validators.required]),
269269
repository: new FormControl('', [Validators.required]),
270270
branch: new FormControl('', [Validators.required]),
271-
path: new FormControl(''),
271+
path: new FormControl('', [pathValidator(), Validators.maxLength(255)]),
272272
token: new FormControl('', [Validators.required]),
273273
active: new FormControl(true),
274274
forceprune: new FormControl(false),

src/app/dashboard-module/domain-module/ext-gitops/gitops-validator.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { ValidatorFn } from '@angular/forms';
22

3+
// Allow only values like 1s, 1m, 1h
34
const regex = new RegExp(/^\d+[smh]$/);
5+
// Allow slash, alphanumeric, hyphen, underscore, dot only
6+
const regexPath = new RegExp(/^[a-zA-Z0-9/_\-.]+$/);
47

58
/**
69
* Allows only values
@@ -22,4 +25,20 @@ export function windowValidator(): ValidatorFn {
2225
return { invalidWindow: true };
2326
}
2427
};
28+
}
29+
30+
export function pathValidator(): ValidatorFn {
31+
return control => {
32+
const value = control.value as string;
33+
34+
if (value.length > 0) {
35+
if (value.startsWith('/') || value.endsWith('/') || value.includes('//')) {
36+
return { invalidPath: true };
37+
}
38+
39+
if (!regexPath.test(value)) {
40+
return { invalidPath: true };
41+
}
42+
}
43+
};
2544
}

src/app/documentation-module/docs/api.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { MarkdownService } from 'ngx-markdown';
1515
})
1616
export class ApiComponent extends MarkdownInjector {
1717

18-
constructor(private markdownComponentService: MarkdownService) {
18+
constructor(private readonly markdownComponentService: MarkdownService) {
1919
super(markdownComponentService, 'documentation/api.md');
2020
}
2121

src/app/documentation-module/docs/components.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { MarkdownInjector } from './markdown-injector.component';
1515
})
1616
export class ComponentsComponent extends MarkdownInjector {
1717

18-
constructor(private markdownComponentService: MarkdownService) {
18+
constructor(private readonly markdownComponentService: MarkdownService) {
1919
super(markdownComponentService, 'documentation/components.md');
2020
}
2121

src/app/documentation-module/docs/environment.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { MarkdownService } from 'ngx-markdown';
1515
})
1616
export class EnvironmentComponent extends MarkdownInjector {
1717

18-
constructor(private markdownComponentService: MarkdownService) {
18+
constructor(private readonly markdownComponentService: MarkdownService) {
1919
super(markdownComponentService, 'documentation/environment.md');
2020
}
2121

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Component } from '@angular/core';
2+
import { MarkdownInjector } from './markdown-injector.component';
3+
import { MarkdownService } from 'ngx-markdown';
4+
5+
@Component({
6+
selector: 'app-home',
7+
template: `
8+
<div class="doc-header">
9+
<h3 class="doc-title">Switcher GitOps</h3>
10+
<img src="assets/switcherapi_mark_white.png" class="doc-icon" alt="Switcher API">
11+
</div>
12+
<markdown [data]="markdown"></markdown>
13+
`,
14+
styleUrls: ['../documentation/documentation.component.css']
15+
})
16+
export class GitOpsDocsComponent extends MarkdownInjector {
17+
18+
constructor(private readonly markdownComponentService: MarkdownService) {
19+
super(markdownComponentService, 'documentation/gitops.md');
20+
}
21+
22+
}

src/app/documentation-module/docs/home.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { MarkdownService } from 'ngx-markdown';
1515
})
1616
export class HomeComponent extends MarkdownInjector {
1717

18-
constructor(private markdownComponentService: MarkdownService) {
18+
constructor(private readonly markdownComponentService: MarkdownService) {
1919
super(markdownComponentService, 'documentation/overview.md');
2020
}
2121

src/app/documentation-module/docs/lib-java.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { MarkdownService } from 'ngx-markdown';
1515
})
1616
export class LibJavaComponent extends MarkdownInjector {
1717

18-
constructor(private markdownComponentService: MarkdownService) {
18+
constructor(private readonly markdownComponentService: MarkdownService) {
1919
super(markdownComponentService, 'documentation/libjava.md');
2020
}
2121

src/app/documentation-module/docs/lib-javascript.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { MarkdownService } from 'ngx-markdown';
1515
})
1616
export class LibJavaScriptComponent extends MarkdownInjector {
1717

18-
constructor(private markdownComponentService: MarkdownService) {
18+
constructor(private readonly markdownComponentService: MarkdownService) {
1919
super(markdownComponentService, 'documentation/libjavascript.md');
2020
}
2121

src/app/documentation-module/docs/metrics.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { MarkdownService } from 'ngx-markdown';
1515
})
1616
export class MetricsComponent extends MarkdownInjector {
1717

18-
constructor(private markdownComponentService: MarkdownService) {
18+
constructor(private readonly markdownComponentService: MarkdownService) {
1919
super(markdownComponentService, 'documentation/metrics.md');
2020
}
2121

0 commit comments

Comments
 (0)