Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ val generateFilcApiClient by tasks.registering(GenerateTask::class) {
packageName.set("hu.petrik.filcapp.api")
apiPackage.set("hu.petrik.filcapp.api.client")
modelPackage.set("hu.petrik.filcapp.api.model")
generateModelTests.set(false)
generateApiTests.set(false)
configOptions.set(
mapOf(
"dateLibrary" to "string",
"serializationLibrary" to "kotlinx_serialization",
"omitGradleWrapper" to "true",
"omitGradlePluginVersions" to "true",
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
package hu.petrik.filcapp.api.auth

class ApiKeyAuth(
private val location: String,
val paramName: String,
) : Authentication {
class ApiKeyAuth(private val location: String, val paramName: String) : Authentication {
var apiKey: String? = null
var apiKeyPrefix: String? = null

override fun apply(
query: MutableMap<String, List<String>>,
headers: MutableMap<String, String>,
) {
override fun apply(query: MutableMap<String, List<String>>, headers: MutableMap<String, String>) {
val key: String = apiKey ?: return
val prefix: String? = apiKeyPrefix
val value: String = if (prefix != null) "$prefix $key" else key
when (location) {
"cookie" -> Unit
"query" -> query[paramName] = listOf(key)
"header" -> headers[paramName] = key
"query" -> query[paramName] = listOf(value)
"header" -> headers[paramName] = value
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package hu.petrik.filcapp.api.auth

interface Authentication {

/**
* Apply authentication settings to header and query params.
*
* @param query Query parameters.
* @param headers Header parameters.
*/
fun apply(
query: MutableMap<String, List<String>>,
headers: MutableMap<String, String>,
)
fun apply(query: MutableMap<String, List<String>>, headers: MutableMap<String, String>)

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package hu.petrik.filcapp.api.auth

import io.ktor.util.encodeBase64
import kotlin.io.encoding.Base64

class HttpBasicAuth : Authentication {
var username: String? = null
var password: String? = null

override fun apply(
query: MutableMap<String, List<String>>,
headers: MutableMap<String, String>,
) {
override fun apply(query: MutableMap<String, List<String>>, headers: MutableMap<String, String>) {
if (username == null && password == null) return
val str = (username ?: "") + ":" + (password ?: "")
val auth = str.encodeBase64()
val auth = Base64.encode(str.encodeToByteArray())
headers["Authorization"] = "Basic $auth"
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package hu.petrik.filcapp.api.auth

class HttpBearerAuth(
private val scheme: String?,
) : Authentication {
class HttpBearerAuth(private val scheme: String?) : Authentication {
var bearerToken: String? = null

override fun apply(
query: MutableMap<String, List<String>>,
headers: MutableMap<String, String>,
) {
override fun apply(query: MutableMap<String, List<String>>, headers: MutableMap<String, String>) {
val token: String = bearerToken ?: return
headers["Authorization"] = (if (scheme != null) upperCaseBearer(scheme)!! + " " else "") + token
}

private fun upperCaseBearer(scheme: String): String? = if ("bearer".equals(scheme, ignoreCase = true)) "Bearer" else scheme
private fun upperCaseBearer(scheme: String): String? {
return if ("bearer".equals(scheme, ignoreCase = true)) "Bearer" else scheme
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ package hu.petrik.filcapp.api.auth
class OAuth : Authentication {
var accessToken: String? = null

override fun apply(
query: MutableMap<String, List<String>>,
headers: MutableMap<String, String>,
) {
override fun apply(query: MutableMap<String, List<String>>, headers: MutableMap<String, String>) {
val token: String = accessToken ?: return
headers["Authorization"] = "Bearer $token"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,77 +8,92 @@

@file:Suppress(
"ArrayInDataClass",
"DuplicatedCode",
"EnumEntryName",
"RemoveRedundantQualifierName",
"RemoveRedundantCallsOfConversionMethods",
"REDUNDANT_CALL_OF_CONVERSION_METHOD",
"RedundantUnitReturnType",
"RemoveEmptyClassBody",
"UnnecessaryVariable",
"UnusedImport",
"UnnecessaryVariable",
"unused"
)

package hu.petrik.filcapp.api.client

import hu.petrik.filcapp.api.infrastructure.*
import hu.petrik.filcapp.api.model.DeleteAdminApiKeysByKeyId200Response
import hu.petrik.filcapp.api.model.DeleteAdminApiKeysByKeyId400Response
import hu.petrik.filcapp.api.model.GetAdminApiKeys200Response
import hu.petrik.filcapp.api.model.PatchAdminApiKeysByKeyId200Response
import hu.petrik.filcapp.api.model.PatchAdminApiKeysByKeyId400Response
import hu.petrik.filcapp.api.model.PatchAdminApiKeysByKeyIdRequest

import hu.petrik.filcapp.api.infrastructure.*
import io.ktor.client.HttpClient
import io.ktor.client.HttpClientConfig
import io.ktor.client.engine.HttpClientEngine
import io.ktor.client.request.forms.formData
import io.ktor.client.engine.HttpClientEngine
import kotlinx.serialization.json.Json
import io.ktor.http.ParametersBuilder
import io.ktor.http.Headers
import io.ktor.http.HttpHeaders
import io.ktor.http.ContentType
import io.ktor.http.content.PartData
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
import kotlinx.serialization.json.Json

open class APIKeysApi : ApiClient {

constructor(
baseUrl: String = ApiClient.BASE_URL,
httpClientEngine: HttpClientEngine? = null,
httpClientConfig: ((HttpClientConfig<*>) -> Unit)? = null,
jsonSerializer: Json = ApiClient.JSON_DEFAULT,
jsonSerializer: Json = ApiClient.JSON_DEFAULT
) : super(baseUrl = baseUrl, httpClientEngine = httpClientEngine, httpClientConfig = httpClientConfig, jsonBlock = jsonSerializer)

constructor(
baseUrl: String,
httpClient: HttpClient,
) : super(baseUrl = baseUrl, httpClient = httpClient)
httpClient: HttpClient
): super(baseUrl = baseUrl, httpClient = httpClient)

/**
*
*
* Revoke any user&#39;s API key
* @param keyId
* @param keyId
* @return DeleteAdminApiKeysByKeyId200Response
*/
@Suppress("UNCHECKED_CAST")
open suspend fun deleteAdminApiKeysByKeyId(keyId: kotlin.String): HttpResponse<DeleteAdminApiKeysByKeyId200Response> {

val localVariableAuthNames = listOf<String>("sessionAuth")

val localVariableBody =
val localVariableBody =
io.ktor.client.utils.EmptyContent

val localVariableQuery = mutableMapOf<String, List<String>>()
val localVariableHeaders = mutableMapOf<String, String>()

val localVariableConfig =
RequestConfig<kotlin.Any?>(
RequestMethod.DELETE,
"/admin/api-keys/{keyId}".replace("{" + "keyId" + "}", "$keyId"),
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
)
val localVariableConfig = RequestConfig<kotlin.Any?>(
RequestMethod.DELETE,
"/admin/api-keys/{keyId}".replace("{" + "keyId" + "}", "$keyId"),
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
)

return request(
localVariableConfig,
localVariableBody,
localVariableAuthNames,
localVariableAuthNames
).wrap()
}


/**
*
*
* List every user&#39;s API keys
* @param limit (optional, default to 20)
* @param offset (optional, default to 0)
Expand All @@ -87,15 +102,11 @@ open class APIKeysApi : ApiClient {
* @return GetAdminApiKeys200Response
*/
@Suppress("UNCHECKED_CAST")
open suspend fun getAdminApiKeys(
limit: kotlin.Double? = 20.toDouble(),
offset: kotlin.Double? = 0.toDouble(),
ownerId: kotlin.String? = null,
search: kotlin.String? = null,
): HttpResponse<GetAdminApiKeys200Response> {
open suspend fun getAdminApiKeys(limit: kotlin.Double? = 20.toDouble(), offset: kotlin.Double? = 0.toDouble(), ownerId: kotlin.String? = null, search: kotlin.String? = null): HttpResponse<GetAdminApiKeys200Response> {

val localVariableAuthNames = listOf<String>("sessionAuth")

val localVariableBody =
val localVariableBody =
io.ktor.client.utils.EmptyContent

val localVariableQuery = mutableMapOf<String, List<String>>()
Expand All @@ -105,54 +116,54 @@ open class APIKeysApi : ApiClient {
search?.apply { localVariableQuery["search"] = listOf("$search") }
val localVariableHeaders = mutableMapOf<String, String>()

val localVariableConfig =
RequestConfig<kotlin.Any?>(
RequestMethod.GET,
"/admin/api-keys",
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
)
val localVariableConfig = RequestConfig<kotlin.Any?>(
RequestMethod.GET,
"/admin/api-keys",
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
)

return request(
localVariableConfig,
localVariableBody,
localVariableAuthNames,
localVariableAuthNames
).wrap()
}


/**
*
*
* Enable or disable any user&#39;s API key
* @param keyId
* @param patchAdminApiKeysByKeyIdRequest
* @param keyId
* @param patchAdminApiKeysByKeyIdRequest
* @return PatchAdminApiKeysByKeyId200Response
*/
@Suppress("UNCHECKED_CAST")
open suspend fun patchAdminApiKeysByKeyId(
keyId: kotlin.String,
patchAdminApiKeysByKeyIdRequest: PatchAdminApiKeysByKeyIdRequest,
): HttpResponse<PatchAdminApiKeysByKeyId200Response> {
open suspend fun patchAdminApiKeysByKeyId(keyId: kotlin.String, patchAdminApiKeysByKeyIdRequest: PatchAdminApiKeysByKeyIdRequest): HttpResponse<PatchAdminApiKeysByKeyId200Response> {

val localVariableAuthNames = listOf<String>("sessionAuth")

val localVariableBody = patchAdminApiKeysByKeyIdRequest

val localVariableQuery = mutableMapOf<String, List<String>>()
val localVariableHeaders = mutableMapOf<String, String>()

val localVariableConfig =
RequestConfig<kotlin.Any?>(
RequestMethod.PATCH,
"/admin/api-keys/{keyId}".replace("{" + "keyId" + "}", "$keyId"),
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
)
val localVariableConfig = RequestConfig<kotlin.Any?>(
RequestMethod.PATCH,
"/admin/api-keys/{keyId}".replace("{" + "keyId" + "}", "$keyId"),
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
)

return jsonRequest(
localVariableConfig,
localVariableBody,
localVariableAuthNames,
localVariableAuthNames
).wrap()
}



}
Loading
Loading