Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexZeitler/aa2e444cd6772a5b3d9dcde68e89655b to your computer and use it in GitHub Desktop.
Save AlexZeitler/aa2e444cd6772a5b3d9dcde68e89655b to your computer and use it in GitHub Desktop.
Inject client secrets from a local file into a Keycloak Realm Export (JSON) file
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
def jsonSlurper = new JsonSlurper()
def secrets = jsonSlurper.parse(new File(args[1] ?: "secrets.json")).clients.inject([:]) { map, c -> map[c.client] = c.secret; map }
def realm = jsonSlurper.parse(new File(args[0]))
for(client in realm.clients) {
if(secrets[client.clientId]) {
client.secret = secrets[client.clientId]
}
}
def output = JsonOutput.toJson(realm)
def json = JsonOutput.prettyPrint(output)
println json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment