Overriding Chef Attributes in an Array

I need help overriding an attribute in an array.

This is what I have in my cookbook’s attributes/default.rb file:

default['jboss_eap_6']['server']['id_management']['sts']['b2b']['endpoints'] = {
    'dev' => 'https://dev.mycompany.com',
    'stage' => 'https://stage.mycompany.com',
    'prod' => 'https://prod.mycompany.com'
}

default['jboss_eap_6']['server']['id_management']['saml_rest_consumer'] = {
  'security_domains' => {
    'samlRestConsumer' => {
      'cache_type' => 'default',
      'login_modules' => [{
        'code' => 'org.picketlink.trust.jbossws.jaas.JBWSTokenIssuingLoginModule',
        'flag' => 'required',
        'module_options' => {
          'endpointAddress'          => node['jboss_eap_6']['server']['id_management']['sts']['b2b']['endpoints']['dev'],
          'serviceName'              => 'SecurityTokenService',
          'portName'                 => 'RequestSecurityToken',
          'inject.callerprincipal'   => 'true',
          'handlerChain'             => 'map',
          'map.token.key'            => 'ClientID',
          'isBatch'                  => 'true',
          'soapBinding'              => 'http://www.w3.org/2003/05/soap/bindings/HTTP/',
          'requestType'              => 'http://docs.oasis-open.org/ws-sx/ws-trust/200512/Validate',
          'securityDomainForFactory' => 'SYSTEM_DEFAULT',
          'wspAppliesTo'             => 'http://localhost:8080/WSSampleSei/EchoService10',
          'wsaIssuer'                => 'http://localhost:8080/IVCRED_SAML2_ISSUE_TrustChain',
          'roleKey'                  => 'Membership'
        }
      }]
    }
  }
}

I want to be able to override the endpointAddress above in a recipe or LWRP so that it’s not always pointing to dev. I’m struggling because login_modules above is an array vs a hash. I don’t want to have to iterate over default[‘jboss_eap_6’][‘server’][‘id_management’][‘saml_rest_consumer’][‘security_domains’][‘samlRestConsumer’][‘login_modules’] to update endpointAddress. Anyone have an elegant way to do this?

See https://coderanger.net/arrays-and-chef/ for an overview of why this is a problem and how to go about fixing it.

1 Like