Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
Consider authorization token
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomassetti committed Jun 21, 2024
1 parent 0ae784e commit 6f87d19
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class LionWebClient(
val jsonSerializationProvider: (() -> JsonSerialization)? = null,
val connectTimeOutInSeconds: Long = 60,
val callTimeoutInSeconds: Long = 60,
val authorizationToken: String? = null,
) {
// Fields

Expand Down Expand Up @@ -72,6 +73,7 @@ class LionWebClient(
val request: Request =
Request.Builder()
.url(url)
.considerAuthenticationToken()
.post("".toRequestBody())
.build()
OkHttpClient().newCall(request).execute().use { response ->
Expand Down Expand Up @@ -99,6 +101,7 @@ class LionWebClient(
val request: Request =
Request.Builder()
.url("http://$hostname:$port/bulk/deletePartitions")
.considerAuthenticationToken()
.post(body)
.build()
httpClient.newCall(request).execute().use { response ->
Expand All @@ -113,11 +116,20 @@ class LionWebClient(
}
}

private fun Request.Builder.considerAuthenticationToken(): Request.Builder {
return if (authorizationToken == null) {
this
} else {
this.addHeader("Authorization", authorizationToken)
}
}

fun getPartitionIDs(): List<String> {
val url = "http://$hostname:$port/bulk/listPartitions"
val request: Request =
Request.Builder()
.url(url)
.considerAuthenticationToken()
.addHeader("Accept-Encoding", "gzip")
.get()
.build()
Expand Down Expand Up @@ -155,6 +167,7 @@ class LionWebClient(
val request: Request =
Request.Builder()
.url(urlBuilder.build())
.considerAuthenticationToken()
.post(body)
.build()
httpClient.newCall(request).execute().use { response ->
Expand Down Expand Up @@ -212,6 +225,7 @@ class LionWebClient(
val request: Request =
Request.Builder()
.url(urlBuilder.build())
.considerAuthenticationToken()
.post(body)
.build()
httpClient.newCall(request).execute().use { response ->
Expand Down Expand Up @@ -299,6 +313,7 @@ class LionWebClient(
val request: Request =
Request.Builder()
.url(urlBuilder.build())
.considerAuthenticationToken()
.post(body)
.build()
httpClient.newCall(request).execute().use { response ->
Expand Down Expand Up @@ -327,6 +342,7 @@ class LionWebClient(
val request: Request =
Request.Builder()
.url(urlBuilder.build())
.considerAuthenticationToken()
.post(body)
.build()
httpClient.newCall(request).execute().use { response ->
Expand Down Expand Up @@ -511,6 +527,7 @@ class LionWebClient(
val request: Request =
Request.Builder()
.url(urlBuilder.build())
.considerAuthenticationToken()
.get()
.build()
OkHttpClient().newCall(request).execute().use { response ->
Expand Down Expand Up @@ -592,6 +609,7 @@ class LionWebClient(
val request: Request =
Request.Builder()
.url(url)
.considerAuthenticationToken()
.addHeader("Content-Encoding", "gzip")
.post(body)
.build()
Expand Down
2 changes: 2 additions & 0 deletions starlasu-client/src/main/kotlin/KolasuClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class KolasuClient(
val debug: Boolean = false,
val connectTimeOutInSeconds: Long = 60,
val callTimeoutInSeconds: Long = 60,
val authorizationToken: String? = null,
) {
/**
* Exposed for testing purposes
Expand All @@ -78,6 +79,7 @@ class KolasuClient(
jsonSerializationProvider = { this.jsonSerialization },
connectTimeOutInSeconds = connectTimeOutInSeconds,
callTimeoutInSeconds = callTimeoutInSeconds,
authorizationToken = authorizationToken,
)

/**
Expand Down

0 comments on commit 6f87d19

Please sign in to comment.