// Copyright (c) 2023, the Drone Plugins project authors. // Please see the AUTHORS file for details. All rights reserved. // Use of this source code is governed by an Apache 2.0 license that can be // found in the LICENSE file. package plugin import ( "encoding/base64" "encoding/json" "io" "os" ) //nolint:errcheck func writeCard(path string, card interface{}) { data, _ := json.Marshal(card) switch { case path == "/dev/stdout": writeCardTo(os.Stdout, data) case path == "/dev/stderr": writeCardTo(os.Stderr, data) case path != "": os.WriteFile(path, data, 0o644) //nolint:gomnd,gosec } } //nolint:errcheck func writeCardTo(out io.Writer, data []byte) { encoded := base64.StdEncoding.EncodeToString(data) io.WriteString(out, "\u001B]1338;") io.WriteString(out, encoded) io.WriteString(out, "\u001B]0m") io.WriteString(out, "\n") }