Skip to content

Commit

Permalink
Zones: service, fe: model for getting zones data
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Dębowski committed Dec 10, 2024
1 parent 1dc242d commit 53a3c6a
Show file tree
Hide file tree
Showing 25 changed files with 292 additions and 10 deletions.
10 changes: 10 additions & 0 deletions src/hiPower.Abstracts/IZoneService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace hiPower.Abstracts;

public interface IZoneService
{
Task<ErrorOr<object>> GetListAsync (string serviceId);
Task<ErrorOr<object>> GetDetailsAsync(string zoneId);
Task<ErrorOr<object>> UpdateDetailsAsync ();
Task<ErrorOr<bool>> CreateMasterAsync();
Task<ErrorOr<bool>> CreateSlaveAsync();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static IServiceCollection ConfigureCoreServices(this IServiceCollection s
{
services.AddScoped<IDataCenterService, DataCenterService> ();
services.AddScoped<IServerService, ServerService> ();
services.AddScoped<IZoneService, ZoneService> ();

services.ConfigureMapster ();

Expand Down
37 changes: 37 additions & 0 deletions src/hiPower.Core/ZoneService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Text.Json;
using System.Text.Json.Nodes;
using hiPower.Abstracts;

namespace hiPower.Core;

public class ZoneService : IZoneService
{
public Task<ErrorOr<bool>> CreateMasterAsync ()
{
throw new NotImplementedException ();
}

public Task<ErrorOr<bool>> CreateSlaveAsync ()
{
throw new NotImplementedException ();
}

public async Task<ErrorOr<object>> GetDetailsAsync (string zoneId)
{
string json = "{\r\n \"account\": \"\",\r\n \"api_rectify\": false,\r\n \"catalog\": \"\",\r\n \"dnssec\": false,\r\n \"edited_serial\": 2024050502,\r\n \"id\": \"hihost.pl.\",\r\n \"kind\": \"Slave\",\r\n \"last_check\": 1732782113,\r\n \"master_tsig_key_ids\": [],\r\n \"masters\": [\r\n \"54.38.63.174\"\r\n ],\r\n \"name\": \"hihost.pl.\",\r\n \"notified_serial\": 0,\r\n \"nsec3narrow\": false,\r\n \"nsec3param\": \"\",\r\n \"rrsets\": [\r\n {\r\n \"comments\": [],\r\n \"name\": \"20210905._domainkey.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"\\\"v=DKIM1; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCiNKEpEquwoG1rHvkl0/zTe7pCe9VANvI+NBaSbI1qoO7LFY2w9toBR9ckuv/AFeSi5+t8b4TblFvAoNNTkbppUdf41YdTyDm5vpsAii5vUInwfb/fuawkSc7B1eu/xdzAUJQdoLxvjpLFmdTqaGFTd3u44D/egC96Ty1KmGRLiQIDAQAB;\\\"\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"TXT\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"www.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"54.38.63.171\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"A\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"support.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"54.38.63.172\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"A\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"autodiscover.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"54.38.63.165\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"A\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"ftp.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"54.38.63.161\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"A\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"help.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"support.hihost.pl.\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"CNAME\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"_imaps._tcp.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"0 0 993 imap4.hihost.pl.\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"SRV\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"_pop3s._tcp.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"0 0 995 pop3.hihost.pl.\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"SRV\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"_autodiscover._tcp.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"0 0 80 autodiscover.hihost.pl.\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"SRV\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"_imap._tcp.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"0 0 143 imap4.hihost.pl.\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"SRV\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"_submission._tcp.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"0 0 587 smtp2.hihost.pl.\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"SRV\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"_pop3._tcp.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"0 0 110 pop3.hihost.pl.\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"SRV\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"google-site-verification.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"\\\"sYsoadOMu1x1lC-e_bWvptvdKJybcxpcj4e63lnUD-U\\\"\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"TXT\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"panel.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"54.38.63.170\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"A\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"devapi.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"stage02.hihost.pl.\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"CNAME\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"vpngate.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"54.36.174.14\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"A\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"_dmarc.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"\\\"v=DMARC1; p=reject; rua=mailto:[email protected]; ruf=mailto:[email protected]; fo=1; adkim=s; aspf=s;\\\"\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"TXT\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"imap4.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"54.38.63.164\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"A\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"pop3.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"54.38.63.163\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"A\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"smtp2.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"54.38.63.162\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"A\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"admin2.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"54.38.63.165\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"A\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"poczta2.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"54.38.63.165\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"A\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"stage02.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"88.220.117.8\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"A\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"mx01.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"54.38.63.162\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"A\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"stage01.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"54.38.63.175\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"A\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"*.hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"54.38.63.171\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"A\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"mail01.hidnservice.com. .\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"RP\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"\\\"google-site-verification=sYsoadOMu1x1lC-e_bWvptvdKJybcxpcj4e63lnUD-U\\\"\",\r\n \"disabled\": false\r\n },\r\n {\r\n \"content\": \"\\\"v=spf1 mx ip4:54.38.63.162/32 -all\\\"\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"TXT\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"20 mx01.hihost.pl.\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"MX\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"nst01.hidnservice.net. dnsmaster.hidnservice.net. 2024050502 1200 900 1209600 3600\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"SOA\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"nst02.hidnservice.net.\",\r\n \"disabled\": false\r\n },\r\n {\r\n \"content\": \"nst01.hidnservice.net.\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"NS\"\r\n },\r\n {\r\n \"comments\": [],\r\n \"name\": \"hihost.pl.\",\r\n \"records\": [\r\n {\r\n \"content\": \"54.38.63.171\",\r\n \"disabled\": false\r\n }\r\n ],\r\n \"ttl\": 3600,\r\n \"type\": \"A\"\r\n }\r\n ],\r\n \"serial\": 2024050502,\r\n \"slave_tsig_key_ids\": [],\r\n \"soa_edit\": \"\",\r\n \"soa_edit_api\": \"DEFAULT\",\r\n \"url\": \"/api/v1/servers/localhost/zones/hihost.pl.\"\r\n}";

var result = JsonSerializer.Deserialize<JsonObject>(json);

return await Task.FromResult (result!);
}

public Task<ErrorOr<object>> GetListAsync (string serviceId)
{
throw new NotImplementedException ();
}

public Task<ErrorOr<object>> UpdateDetailsAsync ()
{
throw new NotImplementedException ();
}
}
12 changes: 10 additions & 2 deletions src/hiPower.WebApi/Controllers/ZonesController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
using Microsoft.AspNetCore.Mvc;
using hiPower.Abstracts;
using Microsoft.AspNetCore.Mvc;

namespace hiPower.WebApi.Controllers
{
[Route ("api/zones")]
[ApiController]
[Produces (MediaTypeNames.Application.Json)]
public class ZonesController : ControllerBase
public class ZonesController(IZoneService zoneService) : ControllerBase
{
[HttpGet("{zoneId}")]
[ProducesResponseType(StatusCodes.Status200OK, Type=typeof(ApiResult<object>))]
public async Task<IActionResult> GetDetails ([FromRoute] string zoneId)
{
var result = await zoneService.GetDetailsAsync (zoneId);
return Ok (new ApiResult<object>(!result.IsError, result.Value));
}
}
}
7 changes: 7 additions & 0 deletions src/hiPower.WebApi/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
"DefaultDbConnection": "Server=[server address];Database=hiPower_Manager;user id=[userId];Password=[pwd]",
"AzureBlobStorageConnection": "[Azure storage connection string]"
},
"JwtOptions": {
"Secret": "[secret]",
"Issuer": "[issuer]",
"Audiance": "[audiance]",
"ExpiretionAfterSeconds": 7200,
"RefreshTime": 1800
},
"Serilog": {
"MinimumLevel": {
"Default": "Information",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<button mat-raised-button type="button" aria-label="Go to server statistics" routerLink="state"><mat-icon>visibility</mat-icon>State</button>
<button mat-raised-button type="button" aria-label="Go to servers" routerLink="servers"><mat-icon>computer</mat-icon>Servers</button>
<button mat-raised-button type="button" aria-label="Go to data centers" routerLink="datacenters"><mat-icon>map</mat-icon>Data centers</button>
<button mat-raised-button type="button" aria-label="Go to zones templates" routerLink="templates"><mat-icon>fingerprint</mat-icon>Templates</button>
<mat-divider></mat-divider>
<button mat-raised-button type="button" aria-label="Go to user manager" routerLink="/"><mat-icon>people</mat-icon>Users</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
border-right: none;
background-color: #05038a;
color: $color-white;
border-radius: 1rem;
border-radius: $border-radius;
padding: 1rem;
text-align: center;
box-shadow: $border-shadow;
Expand Down Expand Up @@ -64,13 +64,15 @@

.content {
height: calc(100vh - 105px);
overflow: hidden;
overflow-y: auto;
margin: 1rem 2rem 1rem 2rem;
padding: 1rem;
display: flex;
justify-content: center;
font-size: 2rem;
color: $color-blue;
border-radius: 1rem;
border-radius: $border-radius;
background-color: $color-gray-light;
border: solid .5px silver;
box-shadow: $border-shadow;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h2>Zone details</h2>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ZoneComponent } from './zone.component';

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

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ZoneComponent]
})
.compileComponents();

fixture = TestBed.createComponent(ZoneComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Component } from '@angular/core';

@Component({
selector: 'app-zone',
standalone: true,
imports: [],
templateUrl: './zone.component.html',
styleUrl: './zone.component.scss'
})
export class ZoneComponent {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface RecordItem {
content: string;
disabled: boolean;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ZoneKind } from "../types/zone-kind";
import { ZoneRecord } from "./zone-record";

export interface ZoneDetails {
id: string;
name: string;
kind: ZoneKind,
account: string;
catalog: string;
serial: number;
notifiedSerial: number;
editedSerial: number;
last_check: number;
api_rectify: boolean;
masters: string[];
dnssec: boolean;
masterTsigKeyIds: string[];
slaveTsigKeyIds: string[],
msec3Narrow: boolean;
nsec3param: string;
soaEdit: string;
soaEditApi: string;
rrsets: ZoneRecord[];
url: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ZoneKind } from "../types/zone-kind";

export interface ZoneItem {
id: string;
name: string;
serial: number;
editedSerial: number;
notifiedSerial: number;
lastCheck: string;
account: string;
catalog: string;
dnssec: boolean;
kind: ZoneKind;
masters: string[]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { RecordItem } from "./record-item";

export interface ZoneRecord {
type: string;
name: string;
ttl: number;
comments: string [];
records: RecordItem[];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type ZoneKind = 'Slave' | 'Master';
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
<p>zones home works!</p>
<ng-container *ngIf="zoneDetails$ | async as zone">
<ul>
<li><span>Name</span>{{ zone.name }}</li>
<li><span>Serial</span>{{ zone.serial }}</li>
<li><span>Last check</span>{{ zone.last_check }}</li>
<li><span>Kind</span>{{ zone.kind }}</li>
<li><span>DNS SEC</span>{{ zone.dnssec}}</li>
<li><span>Records no</span>{{ zone.rrsets.length }}</li>
<li><span>Api rectify</span>{{ zone.api_rectify}}</li>
<li><span>Url</span>{{ zone.url }}</li>
</ul>
<hr>
<ul>
@for(item of zone.rrsets; track (item.type + item.name) ) {
<li><span>{{ item.type }}</span><br/>
Name: {{ item.name }}<br/>
values:
<ul>
@for(recordValue of item.records; track recordValue.content ) {
<li>{{ recordValue.content }}</li>
}
</ul>
</li>
}
</ul>
</ng-container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
:host {
ul {
font-size: 1rem;
list-style-type: '» ';
margin-left: 2rem;

li {
font-weight: 600;

& > span {
display: inline-block;
width: 12ch;
font-weight: 500;

&::after {
content: ':';
}
}
}
ul {
list-style-type: '- ';
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { ZonesService } from '../services/zones.service';
import { EMPTY, Observable } from 'rxjs';
import { ZoneDetails } from '../core/models/zone-details';

@Component({
selector: 'app-home-zones',
templateUrl: './home.component.html',
styleUrl: './home.component.scss'
})
export class HomeComponent {
export class HomeComponent implements OnInit {

zoneDetails$: Observable<ZoneDetails> = EMPTY;

constructor(private zonesService: ZonesService){}

ngOnInit(): void {
this.zoneDetails$ = this.zonesService.getDetails('hihost.pl');

this.zoneDetails$.subscribe();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { ZonesServiceService } from './zones.service';

describe('ZonesServiceService', () => {
let service: ZonesServiceService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(ZonesServiceService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
Loading

0 comments on commit 53a3c6a

Please sign in to comment.