package mapper /* TODO: TO BE DEPRECATED IN 0.25 @RS185722 */ import ( "errors" "edge-infra.dev/pkg/edge/api/graph/model" "edge-infra.dev/pkg/edge/api/utils" ) // ToLogClassSelection converts a string value to an LogClassSelection type. func ToLogClassSelection(val string) (model.LogClassSelection, error) { switch val { case "audit": return model.LogClassSelectionAudit, nil case "security": return model.LogClassSelectionSecurity, nil default: return "", errors.New("value not a valid log class") } } // FromLogClassSelection converts from an LogClassSelection type to a string value. func FromLogClassSelection(val model.LogClassSelection) (string, error) { switch val { case model.LogClassSelectionAudit: return "audit", nil case model.LogClassSelectionSecurity: return "security", nil default: return "", errors.New("value not a valid log class") } } // Takes in oldClassificaiton and returns an updatedClassification based on values in newClassification func ToNewClassification(newClassification *model.UpdateClassificationInput, oldClassificaiton *model.LogClassification, logClass string) *model.LogClassification { updatedClassification := oldClassificaiton if !utils.IsNullOrEmpty(newClassification.Description) { updatedClassification.Description = *newClassification.Description } if !utils.IsNullOrEmpty(newClassification.Pod) { updatedClassification.Pod = *newClassification.Pod } if !utils.IsNullOrEmpty(newClassification.Container) { updatedClassification.Container = *newClassification.Container } if !utils.IsNullOrEmpty(newClassification.Type) { updatedClassification.Type = *newClassification.Type } if newClassification.Class != nil && logClass != "" { updatedClassification.Class = logClass } if newClassification.Pattern != nil { updatedClassification.Pattern = *newClassification.Pattern } return updatedClassification }