(bugfix): configMap helm error, agent test

This commit is contained in:
Maksym Sadovnychyy 2025-10-26 16:08:31 +01:00
parent dcc33ac513
commit 9864040456
11 changed files with 148 additions and 16 deletions

View File

@ -1,4 +1,6 @@
enum ApiRoutes {
AGENT_TEST = 'api/agent/test',
ACCOUNTS = 'api/accounts',
ACCOUNT = 'api/account',

View File

@ -0,0 +1,39 @@
'use client'
import { ApiRoutes, GetApiRoute } from '@/ApiRoutes'
import { PageContainer } from '@/components/pageContainer'
import { CustomButton } from '@/controls'
import { showToast } from '@/redux/slices/toastSlice'
import { useAppDispatch } from '@/redux/store'
import { httpService } from '@/services/HttpService'
const TestPage = () => {
const dispatch = useAppDispatch()
const handleTestAgent = async () => {
httpService
.get<string>(GetApiRoute(ApiRoutes.AGENT_TEST))
.then((response) => {
dispatch(
showToast({
message: JSON.stringify(response),
type: 'info'
})
)
})
}
return (
<PageContainer title="CertsUI Tests">
<CustomButton
type="button"
onClick={handleTestAgent}
className="bg-green-500 text-white p-2 rounded ml-2"
>
Test Agent
</CustomButton>
</PageContainer>
)
}
export default TestPage

View File

@ -1,5 +1,11 @@
import React, { FC } from 'react'
import { FaHome, FaUserPlus, FaBars, FaSyncAlt } from 'react-icons/fa'
import {
FaHome,
FaUserPlus,
FaBars,
FaSyncAlt,
FaThermometerHalf
} from 'react-icons/fa'
import Link from 'next/link'
interface SideMenuProps {
@ -9,7 +15,8 @@ interface SideMenuProps {
const menuItems = [
{ icon: <FaSyncAlt />, label: 'Auto Renew', path: '/' },
{ icon: <FaUserPlus />, label: 'Register', path: '/register' }
{ icon: <FaUserPlus />, label: 'Register', path: '/register' },
{ icon: <FaThermometerHalf />, label: 'Test', path: '/test' }
]
const SideMenu: FC<SideMenuProps> = ({ isCollapsed, toggleSidebar }) => {

View File

@ -0,0 +1,11 @@
{
"profiles": {
"Docker Compose": {
"commandName": "DockerCompose",
"commandVersion": "1.0",
"serviceActions": {
"letsencryptserver": "StartDebugging"
}
}
}
}

View File

@ -0,0 +1,24 @@
using MaksIT.LetsEncryptServer.Services;
using Microsoft.AspNetCore.Mvc;
namespace LetsEncryptServer.Controllers;
[ApiController]
[Route("api")]
public class AgentController : ControllerBase {
private readonly IAgentService _agentController;
public AgentController(
IAgentService agentController
) {
_agentController = agentController;
}
[HttpGet("agent/test")]
public async Task<IActionResult> Test() {
var result = await _agentController.GetHelloWorld();
return result.ToActionResult();
}
}

View File

@ -8,6 +8,8 @@ EXPOSE 5000
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Models/Models.csproj", "Models/"]
COPY ["LetsEncrypt/LetsEncrypt.csproj", "LetsEncrypt/"]
COPY ["LetsEncryptServer/LetsEncryptServer.csproj", "LetsEncryptServer/"]
RUN dotnet restore "./LetsEncryptServer/LetsEncryptServer.csproj"
COPY . .

View File

@ -1,13 +1,15 @@
using MaksIT.Models.Agent.Requests;
using MaksIT.Results;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Models.Agent.Responses;
using System.Text;
using System.Text.Json;
namespace MaksIT.LetsEncryptServer.Services {
public interface IAgentService {
Task<Result> GetHelloWorld();
Task<Result<HelloWorldResponse?>> GetHelloWorld();
Task<Result> UploadCerts(Dictionary<string, string> certs);
Task<Result> ReloadService(string serviceName);
}
@ -28,8 +30,42 @@ namespace MaksIT.LetsEncryptServer.Services {
_httpClient = httpClient;
}
public Task<Result> GetHelloWorld() {
throw new NotImplementedException();
public async Task<Result<HelloWorldResponse?>> GetHelloWorld() {
try {
var endpoint = $"/HelloWorld";
var fullAddress = $"{_appSettings.Agent.AgentHostname}:{_appSettings.Agent.AgentPort}{endpoint}";
var request = new HttpRequestMessage(HttpMethod.Get, fullAddress);
request.Headers.Add("x-api-key", _appSettings.Agent.AgentKey);
_logger.LogInformation($"Sending GET request to {fullAddress}");
var response = await _httpClient.SendAsync(request);
if (response.IsSuccessStatusCode) {
var content = await response.Content.ReadAsStringAsync();
return Result<HelloWorldResponse?>.Ok(new HelloWorldResponse {
Message = content
});
}
else {
_logger.LogError($"Request to {endpoint} failed with status code: {response.StatusCode}");
return Result<HelloWorldResponse?>.InternalServerError(null, $"Request to {endpoint} failed with status code: {response.StatusCode}");
}
}
catch (Exception ex) {
List<string> messages = new() { "Something went wrong" };
_logger.LogError(ex, messages.FirstOrDefault());
messages.Add(ex.Message);
return Result<HelloWorldResponse?>.InternalServerError(null, [.. messages]);
}
}
public async Task<Result> ReloadService(string serviceName) {
@ -64,8 +100,13 @@ namespace MaksIT.LetsEncryptServer.Services {
}
}
catch (Exception ex) {
_logger.LogError(ex, "Something went wrong");
return Result.InternalServerError("Something went wrong");
List<string> messages = new() { "Something went wrong" };
_logger.LogError(ex, messages.FirstOrDefault());
messages.Add(ex.Message);
return Result.InternalServerError([.. messages]);
}
}
}

View File

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Models.Agent.Responses;
public class HelloWorldResponse {
public string Message { get; set; }
}

View File

@ -7,7 +7,6 @@
</PropertyGroup>
<ItemGroup>
<Folder Include="Agent\Responses\" />
<Folder Include="LetsEncryptServer\CertsFlow\Responses\" />
</ItemGroup>

View File

@ -50,7 +50,7 @@ spec:
{{- $vols := default (list) $p.volumes -}}
{{- $hasVols := gt (len $vols) 0 -}}
{{- $hasSecret := (hasKey $comp "secretsFile") -}}
{{- if or $hasVols $hasSecret }}
{{- if or $hasVols $hasSecret $comp.configMapFile }}
volumeMounts:
{{- range $vol := $vols }}
- name: {{ $compName }}-{{ $vol.name }}
@ -63,14 +63,11 @@ spec:
{{- end }}
{{- if $comp.configMapFile }}
- name: {{ $compName }}-configmap
configMap:
name: {{ include "certs-ui.fullname" $root }}-{{ $compName }}-configmap
items:
- key: {{ $comp.configMapFile.key }}
path: {{ base $comp.configMapFile.mountPath }}
mountPath: {{ $comp.configMapFile.mountPath }}
subPath: {{ base $comp.configMapFile.mountPath }}
{{- end }}
{{- end }}
{{- if or $hasVols $hasSecret }}
{{- if or $hasVols $hasSecret $comp.configMapFile }}
volumes:
{{- range $vol := $vols }}
- name: {{ $compName }}-{{ $vol.name }}

View File

@ -69,7 +69,7 @@ components:
"Agent": {
"AgentHostname": "http://websrv0001.corp.maks-it.com",
"AgentPort": 9000,
"AgentPort": 5000,
"ServiceToReload": "haproxy"
}
}