github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/ias/assertion_attribute.go (about) 1 package ias 2 3 // AssertionAttributeDeliver ensures required AssertionAttributes 4 // instead remove all and replace by new one, it will remove only not existing in templates 5 // and leave existing with probably fresher version of user attributes 6 type AssertionAttributeDeliver struct { 7 assertionAttributesTemplate map[string]AssertionAttribute 8 } 9 10 // NewAssertionAttributeDeliver returns new AssertionAttributeDeliver with default attributes template 11 func NewAssertionAttributeDeliver() *AssertionAttributeDeliver { 12 return &AssertionAttributeDeliver{ 13 assertionAttributesTemplate: map[string]AssertionAttribute{ 14 "first_name": { 15 AssertionAttribute: "first_name", 16 UserAttribute: "firstName", 17 }, 18 "last_name": { 19 AssertionAttribute: "last_name", 20 UserAttribute: "lastName", 21 }, 22 "email": { 23 AssertionAttribute: "email", 24 UserAttribute: "mail", 25 }, 26 "groups": { 27 AssertionAttribute: "groups", 28 UserAttribute: "companyGroups", 29 }, 30 }, 31 } 32 } 33 34 // GenerateAssertionAttribute remove not existing in template attributes, leaves existing 35 func (a *AssertionAttributeDeliver) GenerateAssertionAttribute(serviceProvider ServiceProvider) []AssertionAttribute { 36 defaults := a.tmplDeepCopy() 37 // overrides defaults with given attr 38 for _, overrideAtr := range serviceProvider.AssertionAttributes { 39 if _, found := defaults[overrideAtr.AssertionAttribute]; found { 40 defaults[overrideAtr.AssertionAttribute] = overrideAtr 41 } 42 } 43 44 // convert to slice 45 var newAssertionAttributes []AssertionAttribute 46 for _, atr := range defaults { 47 newAssertionAttributes = append(newAssertionAttributes, atr) 48 } 49 50 return newAssertionAttributes 51 } 52 53 func (a AssertionAttributeDeliver) tmplDeepCopy() map[string]AssertionAttribute { 54 cpy := map[string]AssertionAttribute{} 55 for k, v := range a.assertionAttributesTemplate { 56 cpy[k] = v 57 } 58 return cpy 59 }