mirror of
https://github.com/dalbodeule/sh0rt.kr-pdns.git
synced 2025-06-08 10:48:20 +00:00
fix pdns api clients (retry 21x)
This commit is contained in:
parent
d423075da8
commit
7b408eb946
@ -25,23 +25,31 @@ class PowerDNSAPIClient() {
|
||||
|
||||
@Throws(PowerDNSAPIException::class)
|
||||
fun createZone(zoneName: String): Response {
|
||||
val body = gson.toJson(mapOf(
|
||||
"name" to "$zoneName."
|
||||
)).toRequestBody()
|
||||
val request = Request.Builder()
|
||||
.url("$apiUrl/api/v1/servers/localhost/zones")
|
||||
.addHeader("X-API-Key", apiKey)
|
||||
.addHeader("Accept", "application/json")
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.post(body)
|
||||
.build()
|
||||
try {
|
||||
val body = gson.toJson(
|
||||
mapOf(
|
||||
"name" to "$zoneName.",
|
||||
"kind" to "Primary"
|
||||
)
|
||||
).toRequestBody()
|
||||
val request = Request.Builder()
|
||||
.url("$apiUrl/api/v1/servers/localhost/zones")
|
||||
.addHeader("X-API-Key", apiKey)
|
||||
.addHeader("Accept", "application/json")
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.post(body)
|
||||
.build()
|
||||
|
||||
val response = client.newCall(request).execute()
|
||||
if(!response.isSuccessful) {
|
||||
val error = gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java)
|
||||
throw PowerDNSAPIException(error)
|
||||
val response = client.newCall(request).execute()
|
||||
if (!response.isSuccessful) {
|
||||
val error = gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java)
|
||||
throw PowerDNSAPIException(error)
|
||||
}
|
||||
return response
|
||||
} catch(ex: Exception) {
|
||||
println(ex)
|
||||
throw ex
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
@Throws(PowerDNSAPIException::class)
|
||||
@ -63,11 +71,13 @@ class PowerDNSAPIClient() {
|
||||
}
|
||||
|
||||
@Throws(PowerDNSAPIException::class)
|
||||
fun createRecord(zoneName: String, recordName: String, recordType: String, recordContent: String): Response {
|
||||
fun createRecord(zoneName: String, recordName: String, recordType: String, recordContent: String, ttl: Int = 300, priority: Int = 0): Response {
|
||||
val body = gson.toJson(mapOf(
|
||||
"name" to recordName,
|
||||
"type" to recordType,
|
||||
"content" to recordContent
|
||||
"content" to recordContent,
|
||||
"ttl" to ttl,
|
||||
"priority" to priority
|
||||
)).toRequestBody("application/json".toMediaType())
|
||||
val request = Request.Builder()
|
||||
.url("$apiUrl/api/v1/servers/localhost/zones/$zoneName./records")
|
||||
@ -86,9 +96,11 @@ class PowerDNSAPIClient() {
|
||||
}
|
||||
|
||||
@Throws(PowerDNSAPIException::class)
|
||||
fun updateRecord(zoneName: String, recordName: String, recordType: String, recordContent: String): Response {
|
||||
fun updateRecord(zoneName: String, recordName: String, recordType: String, recordContent: String, ttl: Int = 300, priority: Int = 0): Response {
|
||||
val body = gson.toJson(mapOf(
|
||||
"content" to recordContent
|
||||
"content" to recordContent,
|
||||
"ttl" to ttl,
|
||||
"priority" to priority
|
||||
)).toRequestBody("application/json".toMediaType())
|
||||
val request = Request.Builder()
|
||||
.url("$apiUrl/api/v1/servers/localhost/zones/$zoneName./records/$recordName/$recordType")
|
||||
|
@ -11,10 +11,10 @@ data class RecordRequestDTO(
|
||||
val name: String,
|
||||
|
||||
@Schema(description = "Record data", example = "192.0.2.1")
|
||||
val content: String,
|
||||
val value: String,
|
||||
|
||||
@Schema(description = "TTL (Time to Live)", example = "3600")
|
||||
val ttl: Int = 300,
|
||||
var ttl: Int = 300,
|
||||
|
||||
@Schema(description = "Priority", example = "0")
|
||||
val priority: Int? = null,
|
||||
|
@ -32,13 +32,19 @@ class RecordService(
|
||||
if(domain.user.id != user.id)
|
||||
throw RuntimeException("Unauthorized to create record in API: $domain_id")
|
||||
|
||||
powerDNSApiClient.createRecord(domain.name, recordRequest.name, recordRequest.type, recordRequest.content)
|
||||
recordRequest.ttl = when {
|
||||
recordRequest.ttl == 1 -> 300
|
||||
recordRequest.ttl < 300 -> 300
|
||||
else -> recordRequest.ttl
|
||||
}
|
||||
|
||||
powerDNSApiClient.createRecord(domain.name, recordRequest.name, recordRequest.type, recordRequest.value, recordRequest.ttl, recordRequest.priority ?: 0)
|
||||
|
||||
val record = DomainRecord(
|
||||
domain = domain,
|
||||
name = recordRequest.name,
|
||||
type = recordRequest.type,
|
||||
content = recordRequest.content,
|
||||
content = recordRequest.value,
|
||||
ttl = recordRequest.ttl,
|
||||
prio = recordRequest.priority ?: 0,
|
||||
disabled = false,
|
||||
@ -134,13 +140,19 @@ class RecordService(
|
||||
// 레코드 업데이트
|
||||
record.name = updatedRecord.name
|
||||
record.type = updatedRecord.type
|
||||
record.content = updatedRecord.content
|
||||
record.content = updatedRecord.value
|
||||
record.ttl = updatedRecord.ttl
|
||||
record.prio = updatedRecord.priority ?: 0
|
||||
record.comment = updatedRecord.comment
|
||||
record.modifiedOn = Date()
|
||||
|
||||
powerDNSApiClient.updateRecord(domain!!.name, updatedRecord.name, updatedRecord.type, updatedRecord.content)
|
||||
record.ttl = when {
|
||||
record.ttl == 1 -> 300
|
||||
record.ttl < 300 -> 300
|
||||
else -> record.ttl
|
||||
}
|
||||
|
||||
powerDNSApiClient.updateRecord(domain!!.name, updatedRecord.name, updatedRecord.type, updatedRecord.value)
|
||||
|
||||
// 저장
|
||||
val savedRecord = recordRepository.save(record)
|
||||
|
Loading…
x
Reference in New Issue
Block a user