MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / resolveOperationValues

Function resolveOperationValues

agent/middleware/operation.go:137–168  ·  view source on GitHub ↗
(pathItem string, values map[string]interface{}, beforeFunctions []functionInfo)

Source from the content-addressed store, hash-verified

135}
136
137func resolveOperationValues(pathItem string, values map[string]interface{}, beforeFunctions []functionInfo) (map[string]string, error) {
138 dbItem, err := newResolveDB(pathItem)
139 if err != nil {
140 return nil, err
141 }
142 defer closeResolveDB(dbItem)
143
144 resolved := make(map[string]string)
145 for _, funcs := range beforeFunctions {
146 if !isSafeIdentifier(funcs.DB) || !isSafeIdentifier(funcs.InputColumn) || !isSafeIdentifier(funcs.OutputColumn) {
147 continue
148 }
149 for key, value := range values {
150 if funcs.InputValue != key {
151 continue
152 }
153 var names []string
154 if funcs.IsList {
155 sql := fmt.Sprintf("SELECT %s FROM %s where %s in (?);", funcs.OutputColumn, funcs.DB, funcs.InputColumn)
156 _ = dbItem.Raw(sql, value).Scan(&names)
157 } else {
158 sql := fmt.Sprintf("SELECT %s FROM %s where %s = ?;", funcs.OutputColumn, funcs.DB, funcs.InputColumn)
159 _ = dbItem.Raw(sql, value).Scan(&names)
160 }
161 outputValue := strings.Join(names, ",")
162 resolved[funcs.OutputValue] = outputValue
163 values[funcs.OutputValue] = outputValue
164 break
165 }
166 }
167 return resolved, nil
168}
169
170func newResolveDB(pathItem string) (*gorm.DB, error) {
171 dbFile := ""

Callers 1

OperationResolveMetaFunction · 0.85

Calls 4

newResolveDBFunction · 0.85
closeResolveDBFunction · 0.85
isSafeIdentifierFunction · 0.85
ScanMethod · 0.65

Tested by

no test coverage detected