Cloudflare API v4 in kotlin
Go to file
2022-12-06 01:26:43 +01:00
gradle/wrapper removed conscrypt 2022-12-06 01:02:50 +01:00
src/dorkbox/kloudflareApi updated version 2022-12-06 01:26:43 +01:00
test/dorkbox/kloudflareApi Added CAA records, added multi-page results 2021-08-14 23:30:18 -06:00
.gitignore added gitignore 2019-06-21 19:09:46 +02:00
build.gradle.kts updated version 2022-12-06 01:26:43 +01:00
gradlew removed conscrypt 2022-12-06 01:02:50 +01:00
gradlew.bat updated info 2021-08-15 00:19:09 -06:00
LICENSE Removed kapt and conscrypt (not compatible with aarch64) 2022-12-06 01:26:16 +01:00
LICENSE.Apachev2 Added gradle build files 2019-06-24 16:42:03 +02:00
logback.xml added logback file 2019-07-28 15:02:06 +02:00
README.md updated version 2022-12-06 01:26:43 +01:00
settings.gradle.kts Added gradle build files 2019-06-24 16:42:03 +02:00

KloudflareAPI

Dorkbox Github Gitlab Bitbucket

KloudflareAPI is an kotlin project that implements (some of) the Cloudflare v4 API, allowing one manage DNS zones and user information

Pull requests are welcome!

  • This is for cross-platform use, specifically - linux 32/64, mac 64, and windows 32/64. Java 8+
val email = "test@example.com"
val token = "ac1d3f45b51cc5d23e47aa4ac7c07b54d60f2"

val kloudflare = Kloudflare(email, token)
println(kloudflare.getUser())
        
val listZones = kloudflare.listZones()
listZones.forEach { zone ->
    println("${zone.name} : ${zone.id}")

    val dnsRecords = kloudflare.listDnsRecords(zone)
    dnsRecords.forEach { dnsRecord ->
        if (dnsRecord.type == RecordType.A || dnsRecord.type == RecordType.AAAA) {
            val domainLength = zone.name.length
            val length = dnsRecord.name.length - domainLength

            val domainName = if (length == 0) {
                "@"
            }
            else {
                // -1 because we don't want the '.'
                dnsRecord.name.subSequence(0, length - 1)
            }

            println("  $domainName ${dnsRecord.type} : ${dnsRecord.id}")

            val newDnsRecord = CreateDnsRecord(zone)
            newDnsRecord.type = RecordType.A
            newDnsRecord.name = "test"
            newDnsRecord.content = "1.2.3.4"

            val newRecord = kloudflare.createDnsRecord(newDnsRecord)
            println("Created: ${newRecord.name} -> ${newRecord.content}")
        }
    }
}

   

Maven Info

<dependencies>
    ...
    <dependency>
      <groupId>com.dorkbox</groupId>
      <artifactId>KloudflareAPI</artifactId>
      <version>1.6</version>
    </dependency>
</dependencies>

Gradle Info

dependencies {
    ...
    compile 'com.dorkbox:KloudflareAPI:1.3'
}

License

This project is © 2019 dorkbox llc, and is distributed under the terms of the Apache v2.0 License. See file "LICENSE" for further references.