Groovy web console

subscribe to the feed Subscribe
to this
site

mutating a string directly in a list

Published 3 weeks ago by Kevin Grant with tags groovy list string replace mutate iterate loop
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def metadata = [authpolicy:[request_auth_claims_aud: ["foo","bar","thisisCLUSTER_ENV"]]]

println((String)metadata)
if(metadata.authpolicy != null && metadata.authpolicy.request_auth_claims_aud != null)
{
    metadata.authpolicy.request_auth_claims_aud.eachWithIndex
    { it, i ->
        println ("audience: ${i} ${it} ${it.replace('CLUSTER_ENV', 'SPARTA')}")
        metadata.authpolicy.request_auth_claims_aud[i] = it.replace('CLUSTER_ENV', 'SPARTA')
    }
}
println((String)metadata)