...

Source file src/edge-infra.dev/pkg/edge/api/graph/mapper/log_classification_mapper.go

Documentation: edge-infra.dev/pkg/edge/api/graph/mapper

     1  package mapper
     2  
     3  /*
     4    TODO: TO BE DEPRECATED IN 0.25 @RS185722
     5  */
     6  
     7  import (
     8  	"errors"
     9  
    10  	"edge-infra.dev/pkg/edge/api/graph/model"
    11  	"edge-infra.dev/pkg/edge/api/utils"
    12  )
    13  
    14  // ToLogClassSelection converts a string value to an LogClassSelection type.
    15  func ToLogClassSelection(val string) (model.LogClassSelection, error) {
    16  	switch val {
    17  	case "audit":
    18  		return model.LogClassSelectionAudit, nil
    19  	case "security":
    20  		return model.LogClassSelectionSecurity, nil
    21  	default:
    22  		return "", errors.New("value not a valid log class")
    23  	}
    24  }
    25  
    26  // FromLogClassSelection converts from an LogClassSelection type to a string value.
    27  func FromLogClassSelection(val model.LogClassSelection) (string, error) {
    28  	switch val {
    29  	case model.LogClassSelectionAudit:
    30  		return "audit", nil
    31  	case model.LogClassSelectionSecurity:
    32  		return "security", nil
    33  	default:
    34  		return "", errors.New("value not a valid log class")
    35  	}
    36  }
    37  
    38  // Takes in oldClassificaiton and returns an updatedClassification based on values in newClassification
    39  func ToNewClassification(newClassification *model.UpdateClassificationInput, oldClassificaiton *model.LogClassification, logClass string) *model.LogClassification {
    40  	updatedClassification := oldClassificaiton
    41  
    42  	if !utils.IsNullOrEmpty(newClassification.Description) {
    43  		updatedClassification.Description = *newClassification.Description
    44  	}
    45  	if !utils.IsNullOrEmpty(newClassification.Pod) {
    46  		updatedClassification.Pod = *newClassification.Pod
    47  	}
    48  	if !utils.IsNullOrEmpty(newClassification.Container) {
    49  		updatedClassification.Container = *newClassification.Container
    50  	}
    51  	if !utils.IsNullOrEmpty(newClassification.Type) {
    52  		updatedClassification.Type = *newClassification.Type
    53  	}
    54  	if newClassification.Class != nil && logClass != "" {
    55  		updatedClassification.Class = logClass
    56  	}
    57  	if newClassification.Pattern != nil {
    58  		updatedClassification.Pattern = *newClassification.Pattern
    59  	}
    60  
    61  	return updatedClassification
    62  }
    63  

View as plain text