(logCtx context.Context, meta waveobj.MetaMapType, connName string, shellType string)
| 815 | } |
| 816 | |
| 817 | func getCustomInitScript(logCtx context.Context, meta waveobj.MetaMapType, connName string, shellType string) string { |
| 818 | initScriptVal, metaKeyName := getCustomInitScriptValue(meta, connName, shellType) |
| 819 | if initScriptVal == "" { |
| 820 | return "" |
| 821 | } |
| 822 | if !fileutil.IsInitScriptPath(initScriptVal) { |
| 823 | blocklogger.Infof(logCtx, "[conndebug] inline initScript (size=%d) found in meta key: %s\n", len(initScriptVal), metaKeyName) |
| 824 | return initScriptVal |
| 825 | } |
| 826 | blocklogger.Infof(logCtx, "[conndebug] initScript detected as a file %q from meta key: %s\n", initScriptVal, metaKeyName) |
| 827 | initScriptVal, err := wavebase.ExpandHomeDir(initScriptVal) |
| 828 | if err != nil { |
| 829 | blocklogger.Infof(logCtx, "[conndebug] cannot expand home dir in Wave initscript file: %v\n", err) |
| 830 | return fmt.Sprintf("echo \"cannot expand home dir in Wave initscript file, from key %s\";\n", metaKeyName) |
| 831 | } |
| 832 | fileData, err := os.ReadFile(initScriptVal) |
| 833 | if err != nil { |
| 834 | blocklogger.Infof(logCtx, "[conndebug] cannot open Wave initscript file: %v\n", err) |
| 835 | return fmt.Sprintf("echo \"cannot open Wave initscript file, from key %s\";\n", metaKeyName) |
| 836 | } |
| 837 | if len(fileData) > MaxInitScriptSize { |
| 838 | blocklogger.Infof(logCtx, "[conndebug] initscript file too large, size=%d, max=%d\n", len(fileData), MaxInitScriptSize) |
| 839 | return fmt.Sprintf("echo \"initscript file too large, from key %s\";\n", metaKeyName) |
| 840 | } |
| 841 | if utilfn.HasBinaryData(fileData) { |
| 842 | blocklogger.Infof(logCtx, "[conndebug] initscript file contains binary data\n") |
| 843 | return fmt.Sprintf("echo \"initscript file contains binary data, from key %s\";\n", metaKeyName) |
| 844 | } |
| 845 | blocklogger.Infof(logCtx, "[conndebug] initscript file read successfully, size=%d\n", len(fileData)) |
| 846 | return string(fileData) |
| 847 | } |
| 848 | |
| 849 | // returns (value, metakey) |
| 850 | func getCustomInitScriptValue(meta waveobj.MetaMapType, connName string, shellType string) (string, string) { |
no test coverage detected