utils

package
v0.14.0-rc.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2020 License: Apache-2.0 Imports: 14 Imported by: 85

Documentation

Index

Constants

View Source
const DefaultECCurve = "P-256"

DefaultECCurve sets the default curve for EC to P-256.

View Source
const DefaultRSASize = 2048

DefaultRSASize sets the default key size for RSA to 2048 bits.

Variables

View Source
var (
	// ErrFileExists is the error returned if a file exists.
	ErrFileExists = errors.New("file exists")

	// ErrIsDir is the error returned if the file is a directory.
	ErrIsDir = errors.New("file is a directory")

	// SnippetHeader is the header of a step generated snippet in a
	// configuration file.
	SnippetHeader = "# autogenerated by step"

	// SnippetFooter is the header of a step generated snippet in a
	// configuration file.
	SnippetFooter = "# end"
)

Functions

func AppendNewLine added in v0.14.0

func AppendNewLine(filename string, data []byte, perm os.FileMode) error

AppendNewLine appends the given data at the end of the file. If the last character of the file does not contain an LF it prepends it to the data.

func Fail

func Fail(err error)

Fail prints out the error struct if STEPDEBUG is true otherwise it just prints out the error message. Finally, it exits with an error code of 1.

func FileExists added in v0.9.0

func FileExists(path string) bool

FileExists is a wrapper on os.Stat that returns false if os.Stat returns an error, it returns true otherwise. This method does not care if os.Stat returns any other kind of errors.

func GetKeyDetailsFromCLI

func GetKeyDetailsFromCLI(ctx *cli.Context, insecure bool, ktyKey, curveKey, sizeKey string) (string, string, int, error)

GetKeyDetailsFromCLI gets the key pair algorithm, curve, and size inputs from the CLI context.

func ReadAll

func ReadAll(r io.Reader) ([]byte, error)

ReadAll returns a slice of bytes with the content of the given reader.

func ReadFile added in v0.8.1

func ReadFile(name string) (b []byte, err error)

ReadFile returns the contents of the file identified by name. It reads from STDIN if name is a hyphen ("-").

func ReadInput

func ReadInput(prompt string) ([]byte, error)

ReadInput from stdin if something is detected or ask the user for an input using the given prompt.

func ReadPasswordFromFile added in v0.8.1

func ReadPasswordFromFile(filename string) ([]byte, error)

ReadPasswordFromFile reads and returns the password from the given filename. The contents of the file will be trimmed at the right.

func ReadString

func ReadString(r io.Reader) (string, error)

ReadString reads one line from the given io.Reader.

func ReadStringPasswordFromFile added in v0.8.4

func ReadStringPasswordFromFile(filename string) (string, error)

ReadStringPasswordFromFile reads and returns the password from the given filename. The contents of the file will be trimmed at the right.

func WriteFile

func WriteFile(filename string, data []byte, perm os.FileMode) error

WriteFile wraps ioutil.WriteFile with a prompt to overwrite a file if the file exists. It returns ErrFileExists if the user picks to not overwrite the file. If force is set to true, the prompt will not be presented and the file if exists will be overwritten.

func WriteSnippet added in v0.14.0

func WriteSnippet(filename string, data []byte, perm os.FileMode) error

WriteSnippet writes the given data on the given filename. It surrounds the data with a header and footer, and it will replace the previous one.

Types

type File added in v0.14.0

type File struct {
	File *os.File
	// contains filtered or unexported fields
}

File represents a wrapper on os.File that supports read, write, seek and close methods, but they won't be called if an error occurred before.

func OpenFile added in v0.14.0

func OpenFile(name string, flag int, perm os.FileMode) (*File, error)

OpenFile calls os.OpenFile method and returns the os.File wrapped.

func (*File) Close added in v0.14.0

func (f *File) Close() error

Close wraps `func (*os.File) Close` it will always call Close but the error return will be the first error thrown if any.

func (*File) Read added in v0.14.0

func (f *File) Read(b []byte) (n int, err error)

Read wraps `func (*os.File) Read` but doesn't perform the operation if a previous error was thrown.

func (*File) ReadAt added in v0.14.0

func (f *File) ReadAt(b []byte, off int64) (n int, err error)

ReadAt wraps `func (*os.File) ReadAt` but doesn't perform the operation if a previous error was thrown.

func (*File) Seek added in v0.14.0

func (f *File) Seek(offset int64, whence int) (ret int64, err error)

Seek wraps `func (*os.File) Seek` but doesn't perform the operation if a previous error was thrown.

func (*File) Write added in v0.14.0

func (f *File) Write(b []byte) (n int, err error)

Write wraps `func (*os.File) Write` but doesn't perform the operation if a previous error was thrown.

func (*File) WriteAt added in v0.14.0

func (f *File) WriteAt(b []byte, off int64) (n int, err error)

WriteAt wraps `func (*os.File) WriteAt` but doesn't perform the operation if a previous error was thrown.

func (*File) WriteString added in v0.14.0

func (f *File) WriteString(s string) (n int, err error)

WriteString wraps `func (*os.File) WriteString` but doesn't perform the operation if a previous error was thrown.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL