secfs

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 14 Imported by: 0

README

secfs

Package secfs implements afero.Fs and afero.File for Kubernetes secrets.

A Kubernetes secret path can be written as /NAMESPACE/SECRET[/KEY]. Where /NAMESPACE/SECRET represents the directory and KEY the file part of the path.

Documentation

Overview

Package secfs is a filesystem for k8s secrets Namespace -> directory Secret -> directory Secret key -> file Absolute path to secret key: namespace/secret/key

Index

Constants

View Source
const (
	// DefaultSecretPrefix for k8s secrets
	DefaultSecretPrefix = ""
	// DefaultSecretSuffix for k8s secrets
	DefaultSecretSuffix = ""
	// DefaultRequestTimeout for k8s API requests
	DefaultRequestTimeout = 5 * time.Second
)

Variables

View Source
var (
	// ErrMoveCrossNamespace is currently not allowed
	ErrMoveCrossNamespace = errors.New("move a secret between namespaces is not allowed")
	// ErrMoveConvert secrets can contain files only
	ErrMoveConvert = errors.New("convert a secret to a file is not allowed")
)

Functions

func New

func New(k kubernetes.Interface, opts ...Option) afero.Fs

New returns a new afero.Fs for handling k8s secrets as files

Types

type File

type File struct {
	TLS bool // TODO: corev1.SecretTypeTLS
	// contains filtered or unexported fields
}

File is the corev1.Secret without k8s specific data

func FileCreate

func FileCreate(b backend.Backend, name string) (*File, error)

FileCreate create a new or truncated file https://pkg.go.dev/os#Create returns *File (implements afero.File and os.FileInfo)

func Open

func Open(b backend.Backend, name string) (*File, error)

Open open a secret or file https://pkg.go.dev/os#Open returns *File (implements afero.File and os.FileInfo)

func (*File) Close

func (f *File) Close() error

Close io.Closer

func (*File) Data

func (f *File) Data() map[string][]byte

Data returns the underlying secret data map (backend.Secret)

func (*File) Delete

func (f *File) Delete() bool

Delete key (backend.Secret)

func (*File) IsDir

func (f *File) IsDir() bool

IsDir returns true for a secret, false for a key (io.FileInfo)

func (*File) Key

func (f *File) Key() string

Key returns the file name (backend.Metadata)

func (*File) ModTime

func (f *File) ModTime() time.Time

ModTime returns file modification time (io.FileInfo)

func (*File) Mode

func (f *File) Mode() fs.FileMode

Mode returns file mode bits (io.FileInfo)

func (*File) Name

func (f *File) Name() string

Name returns the name of the secret or file (afero.File, io.FileInfo)

func (*File) Namespace

func (f *File) Namespace() string

Namespace returns the namespace name (backend.Metadata)

func (*File) Read

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

Read io.Reader https://pkg.go.dev/io#Reader

func (*File) ReadAt

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

ReadAt io.ReaderAt https://pkg.go.dev/io#ReaderAt

func (*File) Readdir

func (f *File) Readdir(count int) ([]os.FileInfo, error)

Readdir (afero.File) TODO: When return io.EOF?

func (*File) Readdirnames

func (f *File) Readdirnames(n int) ([]string, error)

Readdirnames (afero.File)

func (*File) Secret

func (f *File) Secret() string

Secret returns the name of the secret (backend.Metadata)

func (*File) Seek

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

Seek io.Seeker https://pkg.go.dev/io#Seeker

func (*File) SetData

func (f *File) SetData(data map[string][]byte)

SetData sets the secret data map (backend.Secret)

func (*File) SetTime

func (f *File) SetTime(mtime time.Time)

SetTime sets the secret mtime (backend.Secret)

func (*File) Size

func (f *File) Size() int64

Size returns length in bytes for keys (io.FileInfo)

func (*File) Stat

func (f *File) Stat() (os.FileInfo, error)

Stat (afero.File)

func (*File) Sync

func (f *File) Sync() error

Sync (afero.File)

func (*File) Sys

func (f *File) Sys() interface{}

Sys returns underlying data source (io.FileInfo) can return nil

func (*File) Truncate

func (f *File) Truncate(size int64) error

Truncate (afero.File)

func (*File) Value

func (f *File) Value() []byte

Value returns the file content (backend.Secret)

func (*File) Write

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

Write io.Writer https://pkg.go.dev/io#Writer

func (*File) WriteString

func (f *File) WriteString(st string) (int, error)

WriteString (afero.File)

type Option

type Option func(*secfs)

Option represents a functional Option

func WithSecretLabels

func WithSecretLabels(labels map[string]string) Option

WithSecretLabels configures a custom secret labels

func WithSecretPrefix

func WithSecretPrefix(x string) Option

WithSecretPrefix configures a custom secret prefix

func WithSecretSuffix

func WithSecretSuffix(x string) Option

WithSecretSuffix configures a custom secret suffix

func WithTimeout

func WithTimeout(t time.Duration) Option

WithTimeout configures a custom request timeout

Directories

Path Synopsis
internal
backend
Package backend provides CRUD for the secrets
Package backend provides CRUD for the secrets

Jump to

Keyboard shortcuts

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