Support file path as input param for Kubernetes token value
This commit is contained in:
parent
ff7966f9cd
commit
980dac4572
37 changed files with 292 additions and 256 deletions
32
pkg/types/file_or_content.go
Normal file
32
pkg/types/file_or_content.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package types
|
||||
|
||||
import "os"
|
||||
|
||||
// FileOrContent holds a file path or content.
|
||||
type FileOrContent string
|
||||
|
||||
// String returns the FileOrContent in string format.
|
||||
func (f FileOrContent) String() string {
|
||||
return string(f)
|
||||
}
|
||||
|
||||
// IsPath returns true if the FileOrContent is a file path, otherwise returns false.
|
||||
func (f FileOrContent) IsPath() bool {
|
||||
_, err := os.Stat(f.String())
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// Read returns the content after reading the FileOrContent variable.
|
||||
func (f FileOrContent) Read() ([]byte, error) {
|
||||
var content []byte
|
||||
if f.IsPath() {
|
||||
var err error
|
||||
content, err = os.ReadFile(f.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
content = []byte(f)
|
||||
}
|
||||
return content, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue