mirror of
https://github.com/dalbodeule/sh0rt.kr-pdns.git
synced 2025-06-08 18:58:20 +00:00
fix pdns api clients (retry 23x)
This commit is contained in:
parent
25a7b6ca85
commit
d8afd33d07
@ -42,7 +42,8 @@ class PowerDNSAPIClient() {
|
|||||||
|
|
||||||
val response = client.newCall(request).execute()
|
val response = client.newCall(request).execute()
|
||||||
if (!response.isSuccessful) {
|
if (!response.isSuccessful) {
|
||||||
val error = gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java)
|
val str = response.body?.string()
|
||||||
|
val error = gson.fromJson(str, PowerDNSAPIError::class.java)
|
||||||
throw PowerDNSAPIException(error)
|
throw PowerDNSAPIException(error)
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
@ -64,7 +65,9 @@ class PowerDNSAPIClient() {
|
|||||||
|
|
||||||
val response = client.newCall(request).execute()
|
val response = client.newCall(request).execute()
|
||||||
if(!response.isSuccessful) {
|
if(!response.isSuccessful) {
|
||||||
val error = gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java)
|
val str = response.body?.string()
|
||||||
|
println(str)
|
||||||
|
val error = gson.fromJson(str, PowerDNSAPIError::class.java)
|
||||||
throw PowerDNSAPIException(error)
|
throw PowerDNSAPIException(error)
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
@ -72,24 +75,32 @@ class PowerDNSAPIClient() {
|
|||||||
|
|
||||||
@Throws(PowerDNSAPIException::class)
|
@Throws(PowerDNSAPIException::class)
|
||||||
fun createRecord(zoneName: String, recordName: String, recordType: String, recordContent: String, ttl: Int = 300, priority: Int = 0): Response {
|
fun createRecord(zoneName: String, recordName: String, recordType: String, recordContent: String, ttl: Int = 300, priority: Int = 0): Response {
|
||||||
val body = gson.toJson(mapOf(
|
val rrset = mapOf(
|
||||||
"name" to recordName,
|
"name" to "$recordName.$zoneName.",
|
||||||
"type" to recordType,
|
"type" to recordType,
|
||||||
"content" to recordContent,
|
|
||||||
"ttl" to ttl,
|
"ttl" to ttl,
|
||||||
"priority" to priority
|
"changetype" to "REPLACE",
|
||||||
)).toRequestBody("application/json".toMediaType())
|
"records" to listOf(
|
||||||
|
mapOf(
|
||||||
|
"content" to recordContent,
|
||||||
|
"disabled" to false
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
val body = gson.toJson(mapOf("rrsets" to listOf(rrset))).toRequestBody("application/json".toMediaType())
|
||||||
val request = Request.Builder()
|
val request = Request.Builder()
|
||||||
.url("$apiUrl/api/v1/servers/localhost/zones/$zoneName./records")
|
.url("$apiUrl/api/v1/servers/localhost/zones/$zoneName.")
|
||||||
.addHeader("X-API-Key", apiKey)
|
.addHeader("X-API-Key", apiKey)
|
||||||
.addHeader("Accept", "application/json")
|
.addHeader("Accept", "application/json")
|
||||||
.addHeader("Content-Type", "application/json")
|
.addHeader("Content-Type", "application/json")
|
||||||
.post(body)
|
.patch(body)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
val response = client.newCall(request).execute()
|
val response = client.newCall(request).execute()
|
||||||
if(!response.isSuccessful) {
|
if(!response.isSuccessful) {
|
||||||
val error = gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java)
|
val str = response.body?.string()
|
||||||
|
println(str)
|
||||||
|
val error = gson.fromJson(str, PowerDNSAPIError::class.java)
|
||||||
throw PowerDNSAPIException(error)
|
throw PowerDNSAPIException(error)
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
@ -97,22 +108,32 @@ class PowerDNSAPIClient() {
|
|||||||
|
|
||||||
@Throws(PowerDNSAPIException::class)
|
@Throws(PowerDNSAPIException::class)
|
||||||
fun updateRecord(zoneName: String, recordName: String, recordType: String, recordContent: String, ttl: Int = 300, priority: Int = 0): Response {
|
fun updateRecord(zoneName: String, recordName: String, recordType: String, recordContent: String, ttl: Int = 300, priority: Int = 0): Response {
|
||||||
val body = gson.toJson(mapOf(
|
val rrset = mapOf(
|
||||||
"content" to recordContent,
|
"name" to "$recordName.$zoneName.",
|
||||||
|
"type" to recordType,
|
||||||
"ttl" to ttl,
|
"ttl" to ttl,
|
||||||
"priority" to priority
|
"changetype" to "REPLACE",
|
||||||
)).toRequestBody("application/json".toMediaType())
|
"records" to listOf(
|
||||||
|
mapOf(
|
||||||
|
"content" to recordContent,
|
||||||
|
"disabled" to false
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
val body = gson.toJson(mapOf("rrsets" to listOf(rrset))).toRequestBody("application/json".toMediaType())
|
||||||
val request = Request.Builder()
|
val request = Request.Builder()
|
||||||
.url("$apiUrl/api/v1/servers/localhost/zones/$zoneName./records/$recordName/$recordType")
|
.url("$apiUrl/api/v1/servers/localhost/zones/$zoneName.")
|
||||||
.addHeader("X-API-Key", apiKey)
|
.addHeader("X-API-Key", apiKey)
|
||||||
.addHeader("Accept", "application/json")
|
.addHeader("Accept", "application/json")
|
||||||
.addHeader("Content-Type", "application/json")
|
.addHeader("Content-Type", "application/json")
|
||||||
.put(body)
|
.patch(body)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
val response = client.newCall(request).execute()
|
val response = client.newCall(request).execute()
|
||||||
if(!response.isSuccessful) {
|
if(!response.isSuccessful) {
|
||||||
val error = gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java)
|
val str = response.body?.string()
|
||||||
|
println(str)
|
||||||
|
val error = gson.fromJson(str, PowerDNSAPIError::class.java)
|
||||||
throw PowerDNSAPIException(error)
|
throw PowerDNSAPIException(error)
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
@ -120,17 +141,26 @@ class PowerDNSAPIClient() {
|
|||||||
|
|
||||||
@Throws(PowerDNSAPIException::class)
|
@Throws(PowerDNSAPIException::class)
|
||||||
fun deleteRecord(zoneName: String, recordName: String, recordType: String): Response {
|
fun deleteRecord(zoneName: String, recordName: String, recordType: String): Response {
|
||||||
|
val rrset = mapOf(
|
||||||
|
"name" to "$recordName.$zoneName.",
|
||||||
|
"type" to recordType,
|
||||||
|
"changetype" to "DELETE",
|
||||||
|
"records" to listOf<Map<String, Any>>() // 빈 레코드 리스트
|
||||||
|
)
|
||||||
|
val body = gson.toJson(mapOf("rrsets" to listOf(rrset))).toRequestBody("application/json".toMediaType())
|
||||||
val request = Request.Builder()
|
val request = Request.Builder()
|
||||||
.url("$apiUrl/api/v1/servers/localhost/zones/$zoneName./records/$recordName/$recordType")
|
.url("$apiUrl/api/v1/servers/localhost/zones/$zoneName.")
|
||||||
.addHeader("X-API-Key", apiKey)
|
.addHeader("X-API-Key", apiKey)
|
||||||
.addHeader("Accept", "application/json")
|
.addHeader("Accept", "application/json")
|
||||||
.addHeader("Content-Type", "application/json")
|
.addHeader("Content-Type", "application/json")
|
||||||
.delete()
|
.patch(body)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
val response = client.newCall(request).execute()
|
val response = client.newCall(request).execute()
|
||||||
if(!response.isSuccessful) {
|
if(!response.isSuccessful) {
|
||||||
val error = gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java)
|
val str = response.body?.string()
|
||||||
|
println(str)
|
||||||
|
val error = gson.fromJson(str, PowerDNSAPIError::class.java)
|
||||||
throw PowerDNSAPIException(error)
|
throw PowerDNSAPIException(error)
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
|
@ -53,6 +53,7 @@ class RecordService(
|
|||||||
modifiedOn = Date(),
|
modifiedOn = Date(),
|
||||||
comment = recordRequest.comment,
|
comment = recordRequest.comment,
|
||||||
)
|
)
|
||||||
|
recordRepository.save(record)
|
||||||
|
|
||||||
return RecordResponseDTO(
|
return RecordResponseDTO(
|
||||||
id = record.cfid,
|
id = record.cfid,
|
||||||
@ -63,7 +64,7 @@ class RecordService(
|
|||||||
proxied = false,
|
proxied = false,
|
||||||
ttl = record.ttl,
|
ttl = record.ttl,
|
||||||
locked = false,
|
locked = false,
|
||||||
zoneId = record.cfid,
|
zoneId = record.domain.cfid,
|
||||||
zoneName = domain.name,
|
zoneName = domain.name,
|
||||||
createdOn = record.createdOn.getISOFormat(),
|
createdOn = record.createdOn.getISOFormat(),
|
||||||
modifiedOn = record.modifiedOn.getISOFormat(),
|
modifiedOn = record.modifiedOn.getISOFormat(),
|
||||||
@ -182,6 +183,8 @@ class RecordService(
|
|||||||
if(domain.user.id != user.id)
|
if(domain.user.id != user.id)
|
||||||
throw RuntimeException("Unauthorized to create record in API: $domain_id")
|
throw RuntimeException("Unauthorized to create record in API: $domain_id")
|
||||||
|
|
||||||
|
println("$domain, $record_id")
|
||||||
|
|
||||||
val record = recordRepository.findByDomainIdAndCfid(domain.id!!, record_id).orElseThrow {
|
val record = recordRepository.findByDomainIdAndCfid(domain.id!!, record_id).orElseThrow {
|
||||||
RuntimeException("Failed to find record in API: $record_id")
|
RuntimeException("Failed to find record in API: $record_id")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user