github.com/GuanceCloud/cliutils@v1.1.21/pipeline/manager/name_rule.go (about)

     1  // Unless explicitly stated otherwise all files in this repository are licensed
     2  // under the MIT License.
     3  // This product includes software developed at Guance Cloud (https://www.guance.com/).
     4  // Copyright 2021-present Guance, Inc.
     5  
     6  // Package manager for managing pipeline scripts
     7  package manager
     8  
     9  import (
    10  	"github.com/GuanceCloud/cliutils/point"
    11  )
    12  
    13  func _rumSName(pt *point.Point) string {
    14  	if id := pt.Get("app_id"); id != nil {
    15  		if rumID, ok := id.(string); ok {
    16  			return rumID + "_" + pt.Name()
    17  		}
    18  	}
    19  	return ""
    20  }
    21  
    22  func _securitySName(pt *point.Point) string {
    23  	if scheckCat := pt.Get("category"); scheckCat != nil {
    24  		if cat, ok := scheckCat.(string); ok {
    25  			return cat
    26  		}
    27  	}
    28  	return ""
    29  }
    30  
    31  func _apmSName(pt *point.Point) string {
    32  	if apmSvc := pt.Get("service"); apmSvc != nil {
    33  		if svc, ok := apmSvc.(string); ok {
    34  			return svc
    35  		}
    36  	}
    37  	return ""
    38  }
    39  
    40  func _defaultCatSName(pt *point.Point) string {
    41  	return pt.Name()
    42  }
    43  
    44  func ScriptName(relation *ScriptRelation, cat point.Category, pt *point.Point, scriptMap map[string]string) (string, bool) {
    45  	if pt == nil {
    46  		return "", false
    47  	}
    48  
    49  	var scriptName string
    50  
    51  	// built-in rules last
    52  	switch cat { //nolint:exhaustive
    53  	case point.RUM:
    54  		scriptName = _rumSName(pt)
    55  	case point.Security:
    56  		scriptName = _securitySName(pt)
    57  	case point.Tracing, point.Profiling:
    58  		scriptName = _apmSName(pt)
    59  	default:
    60  		scriptName = _defaultCatSName(pt)
    61  	}
    62  
    63  	if scriptName == "" {
    64  		return "", false
    65  	}
    66  
    67  	// remote relation first
    68  	if relation != nil {
    69  		if sName, ok := relation.Query(cat, scriptName); ok {
    70  			return sName, true
    71  		}
    72  	}
    73  
    74  	// config rules second
    75  	if sName, ok := scriptMap[scriptName]; ok {
    76  		switch sName {
    77  		case "-":
    78  			return "", false
    79  		case "":
    80  		default:
    81  			return sName, true
    82  		}
    83  	}
    84  
    85  	// built-in rule last
    86  	return scriptName + ".p", true
    87  }