|
| 1 | +// Copyright Splunk, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package main |
| 16 | + |
| 17 | +import ( |
| 18 | + "fmt" |
| 19 | + "strings" |
| 20 | +) |
| 21 | + |
| 22 | +// generateInputsConf generates the inputs.conf file content |
| 23 | +func generateInputsConf(scheme *Scheme, globalSettings, inputName string) string { |
| 24 | + var sb strings.Builder |
| 25 | + |
| 26 | + // Write header with input name |
| 27 | + sb.WriteString(fmt.Sprintf("[%s://%s]\n\n", inputName, inputName)) |
| 28 | + |
| 29 | + // Write global settings |
| 30 | + sb.WriteString(globalSettings) |
| 31 | + if !strings.HasSuffix(globalSettings, "\n") { |
| 32 | + sb.WriteString("\n") |
| 33 | + } |
| 34 | + |
| 35 | + // Write TA specific settings header |
| 36 | + sb.WriteString("\n# TA specific settings\n") |
| 37 | + |
| 38 | + // Write each argument with its default value |
| 39 | + for _, arg := range scheme.Endpoint.Args { |
| 40 | + if arg.DefaultValue == "" { |
| 41 | + sb.WriteString(arg.Name + " =\n") |
| 42 | + } else { |
| 43 | + sb.WriteString(arg.Name + " = " + arg.DefaultValue + "\n") |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + return sb.String() |
| 48 | +} |
| 49 | + |
| 50 | +// generateInputsConfSpec generates the inputs.conf.spec file content |
| 51 | +func generateInputsConfSpec(scheme *Scheme, inputName string) string { |
| 52 | + var sb strings.Builder |
| 53 | + |
| 54 | + // Write header with input name |
| 55 | + sb.WriteString(fmt.Sprintf("[%s://<name>]\n\n", inputName)) |
| 56 | + |
| 57 | + // Write each argument specification |
| 58 | + for _, arg := range scheme.Endpoint.Args { |
| 59 | + // Argument name and value placeholder |
| 60 | + sb.WriteString(arg.Name + " = <value>\n") |
| 61 | + |
| 62 | + // Description (normalize whitespace) |
| 63 | + desc := normalizeDescription(arg.Description) |
| 64 | + |
| 65 | + sb.WriteString("* " + desc + "\n") |
| 66 | + |
| 67 | + // Default value |
| 68 | + if arg.DefaultValue == "" { |
| 69 | + sb.WriteString("* Default =\n") |
| 70 | + } else { |
| 71 | + sb.WriteString("* Default = " + arg.DefaultValue + "\n") |
| 72 | + } |
| 73 | + |
| 74 | + sb.WriteString("\n") |
| 75 | + } |
| 76 | + |
| 77 | + return sb.String() |
| 78 | +} |
| 79 | + |
| 80 | +// normalizeDescription normalizes the description by removing extra whitespace |
| 81 | +func normalizeDescription(desc string) string { |
| 82 | + // Replace multiple whitespace (including newlines) with single space |
| 83 | + return strings.Join(strings.Fields(desc), " ") |
| 84 | +} |
0 commit comments