From 5a1d3ebe82d1020d8f0fdd7ccbda4fe87bba3563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Thu, 15 Dec 2022 15:06:19 +0000 Subject: [PATCH] config and logging fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- services/graph/pkg/config/config.go | 7 ++++--- services/graph/pkg/identity/ldap_school.go | 18 ++++++++++++++++++ services/graph/pkg/service/v0/schools.go | 6 +++--- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/services/graph/pkg/config/config.go b/services/graph/pkg/config/config.go index f3491e38a3..79d18268a9 100644 --- a/services/graph/pkg/config/config.go +++ b/services/graph/pkg/config/config.go @@ -63,7 +63,7 @@ type LDAP struct { GroupNameAttribute string `yaml:"group_name_attribute" env:"LDAP_GROUP_SCHEMA_GROUPNAME;GRAPH_LDAP_GROUP_NAME_ATTRIBUTE" desc:"LDAP Attribute to use for the name of groups."` GroupIDAttribute string `yaml:"group_id_attribute" env:"LDAP_GROUP_SCHEMA_ID;GRAPH_LDAP_GROUP_ID_ATTRIBUTE" desc:"LDAP Attribute to use as the unique id for groups. This should be a stable globally unique ID like a UUID."` - EducationResourcesEnabled bool `yaml:"education_resources_enabled" env:"LDAP_EDUCATION_RESOURCES_ENABLE;GRAPH_LDAP_EDUCATION_RESOURCES_ENABLED" desc:"enable LDAP support for managin education related resources"` + EducationResourcesEnabled bool `yaml:"education_resources_enabled" env:"LDAP_EDUCATION_RESOURCES_ENABLED;GRAPH_LDAP_EDUCATION_RESOURCES_ENABLED" desc:"Enable LDAP support for managing education related resources"` EducationConfig LDAPEducationConfig } @@ -75,8 +75,9 @@ type LDAPEducationConfig struct { SchoolFilter string `yaml:"school_filter" env:"LDAP_SCHOOL_FILTER;GRAPH_LDAP_SCHOOL_FILTER" desc:"LDAP filter to add to the default filters for school searches."` SchoolObjectClass string `yaml:"school_objectclass" env:"LDAP_SCHOOL_OBJECTCLASS;GRAPH_LDAP_SCHOOL_OBJECTCLASS" desc:"The object class to use for schools in the default school search filter."` - SchoolNameAttribute string `yaml:"school_name_attribute" env:"LDAP_SCHOOL_SCHEMA_SCHOOLNAME;GRAPH_LDAP_SCHOOL_NAME_ATTRIBUTE" desc:"LDAP Attribute to use for the name of schools."` - SchoolIDAttribute string `yaml:"school_id_attribute" env:"LDAP_SCHOOL_SCHEMA_ID;GRAPH_LDAP_SCHOOL_ID_ATTRIBUTE" desc:"LDAP Attribute to use as the unique id for schools. This should be a stable globally unique ID like a UUID."` + SchoolNameAttribute string `yaml:"school_name_attribute" env:"LDAP_SCHOOL_SCHEMA_SCHOOL_NAME;GRAPH_LDAP_SCHOOL_NAME_ATTRIBUTE" desc:"LDAP Attribute to use for the name of a school."` + SchoolNumberAttribute string `yaml:"school_number_attribute" env:"LDAP_SCHOOL_SCHEMA_SCHOOL_NUMBER;GRAPH_LDAP_SCHOOL_NUMBER_ATTRIBUTE" desc:"LDAP Attribute to use for the number of a school."` + SchoolIDAttribute string `yaml:"school_id_attribute" env:"LDAP_SCHOOL_SCHEMA_ID;GRAPH_LDAP_SCHOOL_ID_ATTRIBUTE" desc:"LDAP Attribute to use as the unique id for schools. This should be a stable globally unique ID like a UUID."` } type Identity struct { diff --git a/services/graph/pkg/identity/ldap_school.go b/services/graph/pkg/identity/ldap_school.go index d033eef54e..6d1e7dd9d1 100644 --- a/services/graph/pkg/identity/ldap_school.go +++ b/services/graph/pkg/identity/ldap_school.go @@ -46,6 +46,24 @@ func newEducationConfig(config config.LDAP) (educationConfig, error) { return educationConfig{}, fmt.Errorf("error configuring school search scope: %w", err) } } + if config.EducationConfig.SchoolFilter != "" { + eduCfg.schoolFilter = config.EducationConfig.SchoolFilter + } + if config.EducationConfig.SchoolObjectClass != "" { + eduCfg.schoolObjectClass = config.EducationConfig.SchoolObjectClass + } + + // Attribute mapping config + if config.EducationConfig.SchoolNameAttribute != "" { + eduCfg.schoolAttributeMap.displayName = config.EducationConfig.SchoolNameAttribute + } + if config.EducationConfig.SchoolNumberAttribute != "" { + eduCfg.schoolAttributeMap.schoolNumber = config.EducationConfig.SchoolNumberAttribute + } + if config.EducationConfig.SchoolIDAttribute != "" { + eduCfg.schoolAttributeMap.id = config.EducationConfig.SchoolIDAttribute + } + return eduCfg, nil } return educationConfig{}, nil diff --git a/services/graph/pkg/service/v0/schools.go b/services/graph/pkg/service/v0/schools.go index 8cc57f24c5..bd33217b98 100644 --- a/services/graph/pkg/service/v0/schools.go +++ b/services/graph/pkg/service/v0/schools.go @@ -73,19 +73,19 @@ func (g Graph) PostSchool(w http.ResponseWriter, r *http.Request) { } if _, ok := school.GetDisplayNameOk(); !ok { - logger.Debug().Err(err).Interface("school", school).Msg("could not create school: missing required attribute") + logger.Debug().Interface("school", school).Msg("could not create school: missing required attribute") errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "Missing Required Attribute") return } if _, ok := school.GetSchoolNumberOk(); !ok { - logger.Debug().Err(err).Interface("school", school).Msg("could not create school: missing required attribute") + logger.Debug().Interface("school", school).Msg("could not create school: missing required attribute") errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "Missing Required Attribute") return } if school, err = g.identityEducationBackend.CreateSchool(r.Context(), *school); err != nil { - logger.Debug().Interface("school", school).Msg("could not create school: backend error") + logger.Debug().Err(err).Interface("school", school).Msg("could not create school: backend error") errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error()) return }