// given the existing roles (queried from keycloak) and the requested roles (via tf)
// calculate the required updates, i.e. roles to remove and roles to add
given the existing roles (queried from keycloak) and the requested roles (via tf)
calculate the required updates, i.e. roles to remove and roles to add
// given the existing roles ( queried from keycloak ) and the requested roles ( via tf ) // calculate the required updates i . e . roles to remove and roles to add
func calculateRoleMappingUpdates(requestedRoles *roleMapping, existingRoles *roleMapping) *terraformRoleMappingUpdates {
	clientRolesToRemove := make(map[string][]*keycloak.Role)
	clientRolesToAdd := make(map[string][]*keycloak.Role)
	realmRolesToRemove := minusRoles(existingRoles.realmRoles, requestedRoles.realmRoles)
	realmRolesToAdd := minusRoles(requestedRoles.realmRoles, existingRoles.realmRoles)
	for clientId, requestedClientRoles := range requestedRoles.clientRoles {
		if existingClientRoles, ok := existingRoles.clientRoles[clientId]; ok {
			clientRolesToAdd[clientId] = minusRoles(requestedClientRoles, existingClientRoles)
			clientRolesToRemove[clientId] = minusRoles(existingClientRoles, requestedClientRoles)
		} else {
			clientRolesToAdd[clientId] = requestedClientRoles
		}
	}
	for clientId, existingClientRoles := range existingRoles.clientRoles {
		if _, ok := requestedRoles.clientRoles[clientId]; !ok {
			clientRolesToRemove[clientId] = existingClientRoles
		}
	}
	updates := terraformRoleMappingUpdates{
		realmRolesToRemove:  realmRolesToRemove,
		realmRolesToAdd:     realmRolesToAdd,
		clientRolesToRemove: clientRolesToRemove,
		clientRolesToAdd:    clientRolesToAdd,
	}
	return &updates
}
func calculateRoleMappingUpdates ( requestedRoles * roleMapping , existingRoles * roleMapping ) * terraformRoleMappingUpdates { clientRolesToRemove := make ( map [ string ] [ ] * keycloak . Role ) clientRolesToAdd := make ( map [ string ] [ ] * keycloak . Role ) realmRolesToRemove := minusRoles ( existingRoles . realmRoles , requestedRoles . realmRoles ) realmRolesToAdd := minusRoles ( requestedRoles . realmRoles , existingRoles . realmRoles ) for clientId , requestedClientRoles := range requestedRoles . clientRoles { if existingClientRoles , ok := existingRoles . clientRoles [ clientId ] ; ok { clientRolesToAdd [ clientId ] = minusRoles ( requestedClientRoles , existingClientRoles ) clientRolesToRemove [ clientId ] = minusRoles ( existingClientRoles , requestedClientRoles ) } else { clientRolesToAdd [ clientId ] = requestedClientRoles } } for clientId , existingClientRoles := range existingRoles . clientRoles { if _ , ok := requestedRoles . clientRoles [ clientId ] ; ! ok { clientRolesToRemove [ clientId ] = existingClientRoles } } updates := terraformRoleMappingUpdates { realmRolesToRemove : realmRolesToRemove , realmRolesToAdd : realmRolesToAdd , clientRolesToRemove : clientRolesToRemove , clientRolesToAdd : clientRolesToAdd , } return & updates }
given the existing roles (queried from keycloak) and the requested roles (via tf)
calculate the required updates, i.e.
given the existing roles ( queried from keycloak ) and the requested roles ( via tf ) calculate the required updates i . e .
// if no roles for this client exist yet, then of course, all requested roles need to be created // now check all existing roles, if there are even any roles configured for each client // no role requested for this client? -> remove all existing client-roles