-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
153 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Container with application | ||
FROM bellsoft/liberica-openjre-alpine:17.0.5 | ||
FROM bellsoft/liberica-openjre-alpine:21.0.3 | ||
RUN apk --no-cache add curl | ||
COPY /build/install/ddns /ddns | ||
ENTRYPOINT /ddns/bin/ddns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/kotlin/io/heapy/ddns/dns_clients/CloudflareVerifyToken.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.heapy.ddns.dns_clients | ||
|
||
import io.ktor.client.* | ||
import io.ktor.client.call.* | ||
import io.ktor.client.request.* | ||
import kotlinx.serialization.Serializable | ||
|
||
class CloudflareVerifyToken( | ||
private val httpClient: HttpClient, | ||
) { | ||
suspend operator fun invoke( | ||
token: String, | ||
): VerifyTokenResponse { | ||
return httpClient | ||
.get("https://api.cloudflare.com/client/v4/user/tokens/verify") { | ||
header("Content-Type", "application/json") | ||
bearerAuth(token) | ||
} | ||
.body<VerifyTokenResponse>() | ||
} | ||
|
||
@Serializable | ||
data class VerifyTokenResponse( | ||
val result: Result? = null, | ||
val success: Boolean, | ||
val errors: List<Error>, | ||
val messages: List<Message>, | ||
) { | ||
@Serializable | ||
data class Result( | ||
val id: String, | ||
val status: String, | ||
) | ||
|
||
@Serializable | ||
data class Error( | ||
val code: Int, | ||
val message: String, | ||
) | ||
|
||
@Serializable | ||
data class Message( | ||
val code: Int, | ||
val message: String, | ||
val type: String? = null, | ||
) | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/test/kotlin/io/heapy/ddns/dns_clients/CloudflareClientFactoryTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.heapy.ddns.dns_clients | ||
|
||
import io.heapy.ddns.ClientFactory | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.Test | ||
import kotlin.test.assertEquals | ||
|
||
class CloudflareClientFactoryTest { | ||
@Test | ||
fun `verify test token`() = runBlocking { | ||
val factory = ClientFactory(System.getenv()) | ||
val token = factory.cloudflareToken | ||
|
||
val response = factory.cloudflareVerifyToken(token) | ||
|
||
assertEquals( | ||
response.success, | ||
true, | ||
) | ||
} | ||
|
||
@Test | ||
fun `get dns record`() = runBlocking { | ||
val factory = ClientFactory(System.getenv()) | ||
val config = factory.cloudflareConfiguration | ||
|
||
val record = factory.cloudflareDnsClient.getRecord( | ||
name = config.domainName, | ||
zoneId = config.zoneId, | ||
token = config.token, | ||
) | ||
|
||
assertEquals( | ||
record?.name, | ||
config.domainName, | ||
) | ||
} | ||
} |