Skip to content

Instantly share code, notes, and snippets.

@goeh
Created November 29, 2019 12:00
Show Gist options
  • Save goeh/fe35c1ac9d0c1e5aae5579b24db486e3 to your computer and use it in GitHub Desktop.
Save goeh/fe35c1ac9d0c1e5aae5579b24db486e3 to your computer and use it in GitHub Desktop.

Revisions

  1. goeh created this gist Nov 29, 2019.
    18 changes: 18 additions & 0 deletions set-keycloak-client-secret.groovy
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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