Added ability to add/delete/update dns records. Updated URL's in javadocs
This commit is contained in:
parent
f695333664
commit
46b0419acc
@ -18,12 +18,10 @@ package dorkbox
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.Types
|
||||
import dorkbox.api.CloudflareActions
|
||||
import dorkbox.api.core.CfErrorResponse
|
||||
import dorkbox.api.core.CfResponse
|
||||
import dorkbox.api.core.Error
|
||||
import dorkbox.api.core.ISO8601Adapter
|
||||
import dorkbox.api.core.*
|
||||
import dorkbox.api.dns.CreateDnsRecord
|
||||
import dorkbox.api.dns.DeleteDnsRecord
|
||||
import dorkbox.api.dns.DnsRecord
|
||||
import dorkbox.api.dns.DnsRecordTypeAdapter
|
||||
import dorkbox.api.user.BillingHistory
|
||||
import dorkbox.api.user.BillingProfile
|
||||
import dorkbox.api.user.User
|
||||
@ -111,16 +109,28 @@ class Kloudflare(private val xAuthEmail: String, private val xAuthKey: String) {
|
||||
return wrap(cloudflare.listZones(xAuthEmail, xAuthKey, options))
|
||||
}
|
||||
|
||||
fun getZoneRatePlans(zoneIdentifier: String): RatePlan {
|
||||
return wrap(cloudflare.getZoneRatePlans(xAuthEmail, xAuthKey, zoneIdentifier))
|
||||
fun getZoneRatePlans(zone: Zone): RatePlan {
|
||||
return wrap(cloudflare.getZoneRatePlans(xAuthEmail, xAuthKey, zone.id))
|
||||
}
|
||||
|
||||
fun getZoneSettings(zoneIdentifier: String): ZoneSetting {
|
||||
return wrap(cloudflare.getZoneSettings(xAuthEmail, xAuthKey, zoneIdentifier))
|
||||
fun getZoneSettings(zone: Zone): ZoneSetting {
|
||||
return wrap(cloudflare.getZoneSettings(xAuthEmail, xAuthKey, zone.id))
|
||||
}
|
||||
|
||||
fun listDnsRecords(zoneIdentifier: String): List<DnsRecord> {
|
||||
return wrap(cloudflare.listDnsRecords(xAuthEmail, xAuthKey, zoneIdentifier))
|
||||
fun listDnsRecords(zone: Zone): List<DnsRecord> {
|
||||
return wrap(cloudflare.listDnsRecords(xAuthEmail, xAuthKey, zone.id))
|
||||
}
|
||||
|
||||
fun createDnsRecord(zone: Zone, dnsRecord: CreateDnsRecord): DnsRecord {
|
||||
return wrap(cloudflare.createDnsRecord(xAuthEmail, xAuthKey, zone.id, dnsRecord))
|
||||
}
|
||||
|
||||
fun updateDnsRecord(zone: Zone, newDnsRecord: CreateDnsRecord): Any {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
fun deleteDnsRecord(zone: Zone, dnsRecord: DnsRecord): DeleteDnsRecord {
|
||||
return wrap(cloudflare.deleteDnsRecord(xAuthEmail, xAuthKey, zone.id, dnsRecord.id))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,10 @@
|
||||
package dorkbox.api
|
||||
|
||||
import dorkbox.api.core.CfResponse
|
||||
import dorkbox.api.dns.CreateDnsRecord
|
||||
import dorkbox.api.dns.DeleteDnsRecord
|
||||
import dorkbox.api.dns.DnsRecord
|
||||
import dorkbox.api.dns.UpdateDnsRecord
|
||||
import dorkbox.api.user.BillingHistory
|
||||
import dorkbox.api.user.BillingProfile
|
||||
import dorkbox.api.user.User
|
||||
@ -27,6 +30,11 @@ import retrofit2.Call
|
||||
import retrofit2.http.*
|
||||
|
||||
interface CloudflareActions {
|
||||
/**
|
||||
* Gets the User details
|
||||
*
|
||||
* https://api.cloudflare.com/#user-properties
|
||||
*/
|
||||
@Headers("Content-Type: application/json")
|
||||
@GET("user")
|
||||
fun getUser(
|
||||
@ -34,6 +42,11 @@ interface CloudflareActions {
|
||||
@Header("X-Auth-Key") key: String
|
||||
): Call<CfResponse<User>>
|
||||
|
||||
/**
|
||||
* Gets the user's Billing Profile
|
||||
*
|
||||
* https://api.cloudflare.com/#user-billing-profile-billing-profile
|
||||
*/
|
||||
@Headers("Content-Type: application/json")
|
||||
@GET("user/billing/profile")
|
||||
fun getUserBillingProfile(
|
||||
@ -41,6 +54,11 @@ interface CloudflareActions {
|
||||
@Header("X-Auth-Key") key: String
|
||||
): Call<CfResponse<BillingProfile>>
|
||||
|
||||
/**
|
||||
* Gets the users Billing History
|
||||
*
|
||||
* https://api.cloudflare.com/#user-billing-history-billing-history
|
||||
*/
|
||||
@Headers("Content-Type: application/json")
|
||||
@GET("user/billing/history")
|
||||
fun getUserBillingHistory(
|
||||
@ -48,6 +66,11 @@ interface CloudflareActions {
|
||||
@Header("X-Auth-Key") key: String
|
||||
): Call<CfResponse<BillingHistory>>
|
||||
|
||||
/**
|
||||
* Gets the list of Zone's owned by this user
|
||||
*
|
||||
* https://api.cloudflare.com/#zone-properties
|
||||
*/
|
||||
@Headers("Content-Type: application/json")
|
||||
@GET("zones")
|
||||
fun listZones(
|
||||
@ -56,7 +79,11 @@ interface CloudflareActions {
|
||||
@QueryMap options: Map<String, String>
|
||||
): Call<CfResponse<List<Zone>>>
|
||||
|
||||
|
||||
/**
|
||||
* Gets the zone rate plan for the specified zone from the billing service
|
||||
*
|
||||
* https://api.cloudflare.com/#zone-rate-plan-properties
|
||||
*/
|
||||
@Headers("Content-Type: application/json")
|
||||
@GET("zones/{zone_identifier}/available_rate_plans")
|
||||
fun getZoneRatePlans(
|
||||
@ -65,7 +92,11 @@ interface CloudflareActions {
|
||||
@Path("zone_identifier") zoneIdentifier: String
|
||||
): Call<CfResponse<RatePlan>>
|
||||
|
||||
|
||||
/**
|
||||
* Gets the zone settings for the specified zone
|
||||
*
|
||||
* https://api.cloudflare.com/#zone-settings-properties
|
||||
*/
|
||||
@Headers("Content-Type: application/json")
|
||||
@GET("zones/{zone_identifier}/settings")
|
||||
fun getZoneSettings(
|
||||
@ -74,6 +105,11 @@ interface CloudflareActions {
|
||||
@Path("zone_identifier") zoneIdentifier: String
|
||||
): Call<CfResponse<ZoneSetting>>
|
||||
|
||||
/**
|
||||
* Lists the DNS records for a specified zone
|
||||
*
|
||||
* https://api.cloudflare.com/#dns-records-for-a-zone-properties
|
||||
*/
|
||||
@Headers("Content-Type: application/json")
|
||||
@GET("zones/{zone_identifier}/dns_records")
|
||||
fun listDnsRecords(
|
||||
@ -82,4 +118,48 @@ interface CloudflareActions {
|
||||
@Path("zone_identifier") zoneIdentifier: String
|
||||
): Call<CfResponse<List<DnsRecord>>>
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new DNS record in the specified zone
|
||||
*
|
||||
* https://api.cloudflare.com/#dns-records-for-a-zone-create-dns-record
|
||||
*/
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST("zones/{zone_identifier}/dns_records")
|
||||
fun createDnsRecord(
|
||||
@Header("X-Auth-Email") email: String,
|
||||
@Header("X-Auth-Key") key: String,
|
||||
@Path("zone_identifier") zoneIdentifier: String,
|
||||
@Body data: CreateDnsRecord
|
||||
): Call<CfResponse<DnsRecord>>
|
||||
|
||||
/**
|
||||
* Updates a DNS record for the specified zone + dns record
|
||||
*
|
||||
* https://api.cloudflare.com/#dns-records-for-a-zone-update-dns-record
|
||||
*/
|
||||
@Headers("Content-Type: application/json")
|
||||
@PUT("zones/{zone_identifier}/dns_records/{identifier}")
|
||||
fun updateDnsRecord(
|
||||
@Header("X-Auth-Email") email: String,
|
||||
@Header("X-Auth-Key") key: String,
|
||||
@Path("zone_identifier") zoneIdentifier: String,
|
||||
@Path("identifier") identifier: String,
|
||||
@Body data: UpdateDnsRecord
|
||||
): Call<CfResponse<DnsRecord>>
|
||||
|
||||
/**
|
||||
* Deletes a DNS record for the specified zone + dns record
|
||||
*
|
||||
* https://api.cloudflare.com/#dns-records-for-a-zone-delete-dns-record
|
||||
*/
|
||||
@Headers("Content-Type: application/json")
|
||||
@DELETE("zones/{zone_identifier}/dns_records/{identifier}")
|
||||
fun deleteDnsRecord(
|
||||
@Header("X-Auth-Email") email: String,
|
||||
@Header("X-Auth-Key") key: String,
|
||||
@Path("zone_identifier") zoneIdentifier: String,
|
||||
@Path("identifier") identifier: String
|
||||
): Call<CfResponse<DeleteDnsRecord>>
|
||||
|
||||
}
|
||||
|
@ -13,25 +13,20 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package dorkbox.api.dns
|
||||
package dorkbox.api.core
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.JsonQualifier
|
||||
import com.squareup.moshi.ToJson
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
@JsonQualifier
|
||||
annotation class DnsType
|
||||
import dorkbox.api.dns.RecordType
|
||||
|
||||
/** Converts byte arrays to base64 (so it looks better as a string...) */
|
||||
internal class DnsRecordTypeAdapter {
|
||||
@ToJson
|
||||
fun toJson(@DnsType recordType: RecordType): String {
|
||||
fun toJson(recordType: RecordType): String {
|
||||
return recordType.name
|
||||
}
|
||||
|
||||
@FromJson
|
||||
@DnsType
|
||||
fun fromJson(recordType: String): RecordType {
|
||||
return RecordType.valueOf(recordType)
|
||||
}
|
61
src/dorkbox/api/dns/CreateDnsRecord.kt
Normal file
61
src/dorkbox/api/dns/CreateDnsRecord.kt
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2019 dorkbox, llc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package dorkbox.api.dns
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
|
||||
/**
|
||||
* https://api.cloudflare.com/#dns-records-for-a-zone-create-dns-record
|
||||
*/
|
||||
open class CreateDnsRecord {
|
||||
/**
|
||||
* Record type
|
||||
* A, AAAA, CNAME, TXT, SRV, LOC, MX, NS, SPF, CERT, DNSKEY, DS, NAPTR, SMIMEA, SSHFP, TLSA, URI
|
||||
*/
|
||||
@field:[Json(name = "type")]
|
||||
var type = RecordType.A
|
||||
|
||||
/**
|
||||
* DNS record name
|
||||
*/
|
||||
@field:[Json(name = "name")]
|
||||
var name = ""
|
||||
|
||||
/**
|
||||
* A valid IPv4 address
|
||||
*/
|
||||
@field:[Json(name = "content")]
|
||||
var content = ""
|
||||
|
||||
|
||||
/**
|
||||
* Time to live for DNS record. Value of 1 is 'automatic'
|
||||
*/
|
||||
@field:[Json(name = "ttl")]
|
||||
var ttl = 1
|
||||
|
||||
/**
|
||||
* Used with some records like MX and SRV to determine priority. If you do not supply a priority for an MX record, a default value of 0 will be set
|
||||
*/
|
||||
@field:[Json(name = "priority")]
|
||||
var priority = 0
|
||||
|
||||
/**
|
||||
* Whether the record is receiving the performance and security benefits of Cloudflare
|
||||
*/
|
||||
@field:[Json(name = "proxied")]
|
||||
var proxied = false
|
||||
}
|
@ -15,7 +15,9 @@
|
||||
*/
|
||||
package dorkbox.api.dns
|
||||
|
||||
class ARecord : DnsRecord() {
|
||||
val asd = ""
|
||||
/**
|
||||
* https://api.cloudflare.com/#dns-records-for-a-zone-properties
|
||||
*/
|
||||
class Data {
|
||||
|
||||
}
|
29
src/dorkbox/api/dns/DeleteDnsRecord.kt
Normal file
29
src/dorkbox/api/dns/DeleteDnsRecord.kt
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2019 dorkbox, llc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package dorkbox.api.dns
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
|
||||
/**
|
||||
* https://api.cloudflare.com/#dns-records-for-a-zone-delete-dns-record
|
||||
*/
|
||||
open class DeleteDnsRecord {
|
||||
/**
|
||||
* DNS record identifier tag
|
||||
*/
|
||||
@field:[Json(name = "id")]
|
||||
var id = ""
|
||||
}
|
@ -33,7 +33,7 @@ open class DnsRecord {
|
||||
* Record type
|
||||
* A, AAAA, CNAME, TXT, SRV, LOC, MX, NS, SPF, CERT, DNSKEY, DS, NAPTR, SMIMEA, SSHFP, TLSA, URI
|
||||
*/
|
||||
@field:[Json(name = "type") DnsType]
|
||||
@field:[Json(name = "type")]
|
||||
var type = RecordType.A
|
||||
|
||||
/**
|
||||
@ -93,11 +93,15 @@ open class DnsRecord {
|
||||
@field:[Json(name = "created_on") ISO8601]
|
||||
var createdOn = LocalDateTime.now()
|
||||
|
||||
/**
|
||||
* Extra Cloudflare-specific information about the record
|
||||
*/
|
||||
@field:[Json(name = "meta")]
|
||||
var meta = Meta()
|
||||
|
||||
/**
|
||||
* Metadata about the record
|
||||
*/
|
||||
var data: String? = null
|
||||
@field:[Json(name = "data")]
|
||||
var data: Data = Data()
|
||||
}
|
||||
|
8
src/dorkbox/api/dns/UpdateDnsRecord.kt
Normal file
8
src/dorkbox/api/dns/UpdateDnsRecord.kt
Normal file
@ -0,0 +1,8 @@
|
||||
package dorkbox.api.dns
|
||||
|
||||
/**
|
||||
* https://api.cloudflare.com/#dns-records-for-a-zone-update-dns-record
|
||||
*
|
||||
* This is the "same" object as creating a new record. This is a different type in order to prevent confusion and simplify naming conventions
|
||||
*/
|
||||
class UpdateDnsRecord : CreateDnsRecord()
|
@ -18,7 +18,7 @@ package dorkbox.api.zone
|
||||
import com.squareup.moshi.Json
|
||||
|
||||
/**
|
||||
* https://api.cloudflare.com/#zone-properties
|
||||
* https://api.cloudflare.com/#zone-rate-plan-properties
|
||||
*/
|
||||
class RatePlan {
|
||||
|
||||
|
@ -788,12 +788,13 @@ class HTTP2EdgePrioritization : ZoneSetting() {
|
||||
|
||||
|
||||
/**
|
||||
* @see [https://api.cloudflare.com](https://api.cloudflare.com/#zone-properties)
|
||||
* https://api.cloudflare.com/#zone-settings-properties
|
||||
*/
|
||||
open class ZoneSetting {
|
||||
|
||||
/**
|
||||
* ID of the zone setting
|
||||
*
|
||||
* always_online, advanced_ddos, brotli, browser_cache_ttl, browser_check, flatten_at_root, cache_level, challenge_ttl,
|
||||
* development_mode, edge_cache_ttl, origin_error_page_pass_thru, sort_query_string_for_cache, email_obfuscation,
|
||||
* hotlink_protection, ip_geolocation, ipv6, websockets, sha1_support, tls_1_2_only, minify, max_upload, mobile_redirect,
|
||||
|
Loading…
Reference in New Issue
Block a user