mirror of
https://github.com/dalbodeule/sh0rt.kr-pdns.git
synced 2025-06-08 18:58:20 +00:00
fix pdns api clients (retry 13x)
This commit is contained in:
parent
af304197f1
commit
1bc653db3b
@ -23,6 +23,7 @@ class PowerDNSAPIClient() {
|
|||||||
private val gson = Gson()
|
private val gson = Gson()
|
||||||
private val client = OkHttpClient()
|
private val client = OkHttpClient()
|
||||||
|
|
||||||
|
@Throws(PowerDNSAPIError::class)
|
||||||
fun createZone(zoneName: String): Response {
|
fun createZone(zoneName: String): Response {
|
||||||
val body = gson.toJson(mapOf(
|
val body = gson.toJson(mapOf(
|
||||||
"name" to zoneName,
|
"name" to zoneName,
|
||||||
@ -38,11 +39,13 @@ class PowerDNSAPIClient() {
|
|||||||
|
|
||||||
val response = client.newCall(request).execute()
|
val response = client.newCall(request).execute()
|
||||||
if(!response.isSuccessful) {
|
if(!response.isSuccessful) {
|
||||||
throw gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java)
|
val error = gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java)
|
||||||
|
throw error
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Throws(PowerDNSAPIError::class)
|
||||||
fun deleteZone(zoneName: String): Response {
|
fun deleteZone(zoneName: String): Response {
|
||||||
val request = Request.Builder()
|
val request = Request.Builder()
|
||||||
.url("$apiUrl/api/v1/servers/localhost/zones/$zoneName")
|
.url("$apiUrl/api/v1/servers/localhost/zones/$zoneName")
|
||||||
@ -54,11 +57,13 @@ class PowerDNSAPIClient() {
|
|||||||
|
|
||||||
val response = client.newCall(request).execute()
|
val response = client.newCall(request).execute()
|
||||||
if(!response.isSuccessful) {
|
if(!response.isSuccessful) {
|
||||||
throw gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java)
|
val error = gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java)
|
||||||
|
throw error
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Throws(PowerDNSAPIError::class)
|
||||||
fun createRecord(zoneName: String, recordName: String, recordType: String, recordContent: String): Response {
|
fun createRecord(zoneName: String, recordName: String, recordType: String, recordContent: String): Response {
|
||||||
val body = gson.toJson(mapOf(
|
val body = gson.toJson(mapOf(
|
||||||
"name" to recordName,
|
"name" to recordName,
|
||||||
@ -75,11 +80,13 @@ class PowerDNSAPIClient() {
|
|||||||
|
|
||||||
val response = client.newCall(request).execute()
|
val response = client.newCall(request).execute()
|
||||||
if(!response.isSuccessful) {
|
if(!response.isSuccessful) {
|
||||||
throw gson.fromJson(response.body?.string(), Error::class.java)
|
val error = gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java)
|
||||||
|
throw error
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Throws(PowerDNSAPIError::class)
|
||||||
fun updateRecord(zoneName: String, recordName: String, recordType: String, recordContent: String): Response {
|
fun updateRecord(zoneName: String, recordName: String, recordType: String, recordContent: String): Response {
|
||||||
val body = gson.toJson(mapOf(
|
val body = gson.toJson(mapOf(
|
||||||
"content" to recordContent
|
"content" to recordContent
|
||||||
@ -94,11 +101,13 @@ class PowerDNSAPIClient() {
|
|||||||
|
|
||||||
val response = client.newCall(request).execute()
|
val response = client.newCall(request).execute()
|
||||||
if(!response.isSuccessful) {
|
if(!response.isSuccessful) {
|
||||||
throw gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java)
|
val error = gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java)
|
||||||
|
throw error
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Throws(PowerDNSAPIError::class)
|
||||||
fun deleteRecord(zoneName: String, recordName: String, recordType: String): Response {
|
fun deleteRecord(zoneName: String, recordName: String, recordType: String): Response {
|
||||||
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/records/$recordName/$recordType")
|
||||||
@ -110,10 +119,11 @@ class PowerDNSAPIClient() {
|
|||||||
|
|
||||||
val response = client.newCall(request).execute()
|
val response = client.newCall(request).execute()
|
||||||
if(!response.isSuccessful) {
|
if(!response.isSuccessful) {
|
||||||
throw gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java)
|
val error = gson.fromJson(response.body?.string(), PowerDNSAPIError::class.java)
|
||||||
|
throw error
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class PowerDNSAPIError(val error: String, val errors: List<String>): RuntimeException(error)
|
class PowerDNSAPIError(val error: String, val errors: List<String>): RuntimeException(error)
|
Loading…
x
Reference in New Issue
Block a user