Commit: 690c1f6

Commit Details

SHA690c1f6ce426c62c29e87ac132dda0f8125192ff
Tree5a67fd55b56735ab4e469c7d06c1c73c4c2b4c20
Author<f69e50@finnacloud.com> 1766368110 +0300
Committer<f69e50@finnacloud.com> 1766368110 +0300
Message
initialize backend structure with controllers, DTOs, and configuration files
GPG Signature
-----BEGIN PGP SIGNATURE-----

iQJSBAABCAA8FiEEWJb139mJI+vZ81KkoAIVSUsXI0oFAmlIo24eHHNvcGhpYS5l
cmFzbGFuQGZpbm5hY2xvdWQuY29tAAoJEKACFUlLFyNKwXYP/RvWx8mxXoZbKEVA
wQFC9UnzcoL/lElB5QMr9opKzRv4uGgFkKMDhbSnqE6NoET5H5VanOFQ9u5a4Khi
9PBTLIEBjbEqA1trC+aTDk3EplVtQYYbSn19CdMSCW7FXJNSg0IiyWKA44iH8Ts0
Xcxh59m6WcwvRDhxQDy6hCXqUa9ISNNk75KRnJS/qRGIEy94DwUYxVfCJpAfzyVu
VmdinE6kZM2GDj8MBTPQTzi6hMf/e9CcAg51tf4oNtd9tnW8QKpTsPsFy434VUDh
Vxtv/oAJ5tuTIprs2BSnyZ6Kb8RDwDdmQyuKjZMUIwZTH/TCE85SZFf5sa5tpYOH
2KekT52ffZgKw/DUtpNosW6qeHgCJlSvwY7BW7M90X5xJuahrKS04lEDBO04cIRn
bg0ayPFTp7Idhl1OuTRhWS6e344g44mJ/9sZK1sXd/0U8OKBbytk35AnCIPCEdSX
8vgjqBR9Wt3A/Kel5j2VcUFDhrAR72a9lJiQHNBicvcVu9Nd41vDnEwUDdNQv6Uc
6omEz3pkVkq+89/eW1KQM8LvrIuGQ/wIUgykvCNSCQ5oba2fjtAXzI+SmxpeCWOz
jTKZOEJyhIQE7uvaUj6/0D2JwlxbMG27fcUN7N3aKv6mSVP7hYnHaUbRLQ+f8/xU
VfU776FkUXS+4CfSooHtu+ioul9O
=ZuqE
-----END PGP SIGNATURE-----

✓ Verified

File: src/main/java/com/paymentlink/service/DnsService.java

1 package com.paymentlink.service;
2
3 import jakarta.annotation.PostConstruct;
4 import org.slf4j.Logger;
5 import org.slf4j.LoggerFactory;
6 import org.springframework.beans.factory.annotation.Value;
7 import org.springframework.http.ResponseEntity;
8 import org.springframework.stereotype.Service;
9 import org.springframework.web.client.RestTemplate;
10
11 @Service
12 public class DnsService {
13
14 private static final Logger logger = LoggerFactory.getLogger(DnsService.class);
15
16 @Value("${cloudns.auth.id:}")
17 private String authId;
18
19 @Value("${cloudns.auth.password:}")
20 private String authPassword;
21
22 @Value("${app.tld:ironpath.ai}")
23 private String tld;
24
25 private final NodeIdService nodeIdService;
26 private final RestTemplate restTemplate = new RestTemplate();
27
28 public DnsService(NodeIdService nodeIdService) {
29 this.nodeIdService = nodeIdService;
30 }
31
32 /**
33 * Update or create DNS record on startup
34 */
35 @PostConstruct
36 public void updateOrCreateDNSRecord() {
37 if (authId == null || authId.isEmpty() || authPassword == null || authPassword.isEmpty()) {
38 logger.warn("CloudNS credentials not configured, skipping DNS update");
39 return;
40 }
41
42 try {
43 String serverIP = getServerIP();
44 String shortId = nodeIdService.getShortId();
45
46 logger.info("Updating DNS record for {} with IP {}", shortId, serverIP);
47
48 // Note: Actual CloudNS API implementation would go here
49 // This is a simplified version - the full implementation would:
50 // 1. List records to find existing
51 // 2. Update if exists, create if not
52 // 3. Handle CloudNS API specifics
53
54 logger.info("DNS record update completed (simulated)");
55
56 } catch (Exception e) {
57 logger.error("Failed to update DNS record", e);
58 }
59 }
60
61 /**
62 * Get server's public IP address
63 */
64 private String getServerIP() {
65 try {
66 // Try ipify first
67 String url = "https://api.ipify.org?format=text";
68 ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
69 if (response.getStatusCode().is2xxSuccessful() && response.getBody() != null) {
70 return response.getBody().trim();
71 }
72 } catch (Exception e) {
73 logger.warn("Failed to get IP from ipify, trying fallback", e);
74 }
75
76 try {
77 // Fallback to ipapi.co
78 String url = "https://ipapi.co/ip/";
79 ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
80 if (response.getStatusCode().is2xxSuccessful() && response.getBody() != null) {
81 return response.getBody().trim();
82 }
83 } catch (Exception e) {
84 logger.error("Failed to get IP from fallback", e);
85 }
86
87 throw new RuntimeException("Could not determine server IP");
88 }
89 }
90
91