I am working on a Gradle task that fetches a GraphQL schema and saves it to a file. The task needs to load configuration details from a YAML file (application-dev.yml). However, I keep encountering an error that says “identity-provider not found”. I’m using the SnakeYAML library to parse the YAML file.
Here is the relevant code in my build.gradle.kts:
// Load configuration from YAML
fun loadConfig(): Map<String, String> {
val yaml = Yaml()
val inputStream = FileInputStream("src/main/resources/application-dev.yml")
val data: Map<String, Any> = yaml.load(inputStream)
println("Data loaded from YAML: $data")
val customsConfig = data["customs"] as? Map<*, *> ?: run {
println("Customs key not found or not a map!")
throw IllegalArgumentException("customs not found")
}
println("Customs Config: $customsConfig")
val identityProviderConfig = customsConfig["identity-provider"] as? Map<*, *> ?: run {
println("Identity-provider key not found or not a map!")
throw IllegalArgumentException("identity-provider not found")
}
println("Identity Provider Config: $identityProviderConfig")
val tokenConfig = identityProviderConfig["token"] as? Map<*, *> ?: run {
println("Token key not found or not a map!")
throw IllegalArgumentException("token not found")
}
println("Token Config: $tokenConfig")
return tokenConfig as Map<String, String>
}
// Task to fetch GraphQL schema
tasks.register("fetchSchema") {
doLast {
try {
println("Loading configuration...")
val config = loadConfig()
val clientId = config["client-id"] ?: throw IllegalArgumentException("client-id not found")
val clientSecret = config["client-secret"] ?: throw IllegalArgumentException("client-secret not found")
val token = fetchToken(clientId, clientSecret)
println("Token fetched: $token")
println("Fetching GraphQL Schema...")
fetchGraphQLSchema("https://xxx-data.api.dev.xxx.com/graphql", token, "src/main/resources/schema2.graphql")
println("Schema has been fetched successfully.")
} catch (e: Exception) {
println("An error occurred: ${e.message}")
e.printStackTrace()
}
}
}
And here is the application-dev.yml content:
customs:
bridge:
public-url: http://localhost:8080
security:
post:
user:
creation:
enabled: false
multi-tenancy:
enabled: true
default:
maxPoolSize: 10
minIdle: 0
connectionTimeout: 5000
idleTimeout: 20000
maxLifetime: 600000
driverClassName: oracle.jdbc.driver.OracleDriver
identity-provider:
token:
url: https://login.dev.XXX.com/connect/token
client-id: placeholder_client_id
tenant-id: placeholder_tenant_id
scope: placeholder_scope
client-secret: placeholder_client_secret
I tried to load the YAML configuration and fetch a token using the fetchSchema task. I expected the task to load the configuration successfully and proceed to fetch the GraphQL schema. However, I encountered an error indicating that the “identity-provider” key was not found or not a map.
The console output is as follows:
> Task :fetchSchema
Loading configuration...
Data loaded from YAML: {server={port=8080, allow={origin=*}, tomcat={max-swallow-size=10MB}}, spring={sql={init-mode=never}, output={ansi={enabled=always}}, resources={cache-period=60000, chain={cache=true, enabled=true}}, thymeleaf={cache=false}, ...
Identity-provider key not found or not a map!
An error occurred: identity-provider not found
Could someone help me identify what might be wrong with my configuration loading logic or my YAML file?