2024-08-15 15:12:42 +00:00
|
|
|
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
|
|
|
|
|
|
|
package data
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"decl/internal/mapper"
|
|
|
|
"decl/internal/transport"
|
|
|
|
"gitea.rosskeen.house/rosskeen.house/machine"
|
|
|
|
"io"
|
|
|
|
"io/fs"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
ErrInvalidResource error = errors.New("Invalid resource")
|
|
|
|
)
|
|
|
|
|
|
|
|
type ResourceMapper mapper.Map[string, Declaration]
|
|
|
|
|
|
|
|
type StateTransformer interface {
|
|
|
|
Apply() error
|
|
|
|
}
|
|
|
|
|
2024-10-16 17:26:42 +00:00
|
|
|
// Used by the resource factory to initialize new resources.
|
|
|
|
type ResourceInitializer interface {
|
|
|
|
Init(uri URIParser) error
|
|
|
|
}
|
|
|
|
|
2024-08-15 15:12:42 +00:00
|
|
|
type Resource interface {
|
|
|
|
Identifier
|
|
|
|
Type() string
|
|
|
|
StateMachine() machine.Stater
|
|
|
|
UseConfig(config ConfigurationValueGetter)
|
|
|
|
ResolveId(context.Context) string
|
|
|
|
Loader
|
|
|
|
StateTransformer
|
|
|
|
Crudder
|
|
|
|
Validator
|
|
|
|
Clone() Resource
|
|
|
|
SetResourceMapper(ResourceMapper)
|
|
|
|
}
|
|
|
|
|
|
|
|
type Declaration interface {
|
|
|
|
Identifier
|
|
|
|
ResourceType() TypeName
|
|
|
|
ResolveId(context.Context) string
|
|
|
|
Loader
|
|
|
|
Validator
|
2024-09-25 04:43:18 +00:00
|
|
|
DocumentStateTransformer
|
2024-08-15 15:12:42 +00:00
|
|
|
Resource() Resource
|
|
|
|
Clone() Declaration
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewResourceMapper() ResourceMapper {
|
|
|
|
return mapper.New[string, Declaration]()
|
|
|
|
}
|
|
|
|
|
2024-09-19 08:03:23 +00:00
|
|
|
type ContentHasher interface {
|
|
|
|
Hash() []byte
|
|
|
|
HashHexString() string
|
|
|
|
}
|
|
|
|
|
2024-08-15 15:12:42 +00:00
|
|
|
type ContentIdentifier interface {
|
|
|
|
ContentType() string
|
|
|
|
}
|
|
|
|
|
|
|
|
type ContentReader interface {
|
|
|
|
ContentReaderStream() (*transport.Reader, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type ContentWriter interface {
|
|
|
|
ContentWriterStream() (*transport.Writer, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type ContentReadWriter interface {
|
|
|
|
ContentReader
|
|
|
|
ContentWriter
|
|
|
|
}
|
|
|
|
|
|
|
|
type ContentGetter interface {
|
|
|
|
GetContent(w io.Writer) (contentReader io.ReadCloser, err error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type ContentSetter interface {
|
|
|
|
SetContent(r io.Reader) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type ContentGetSetter interface {
|
|
|
|
ContentGetter
|
|
|
|
ContentSetter
|
|
|
|
}
|
|
|
|
|
|
|
|
type FileResource interface {
|
2024-09-19 08:03:23 +00:00
|
|
|
SetBasePath(int)
|
2024-08-15 15:12:42 +00:00
|
|
|
FilePath() string
|
|
|
|
SetFileInfo(fs.FileInfo) error
|
|
|
|
FileInfo() fs.FileInfo
|
|
|
|
ContentGetSetter
|
2024-09-19 08:03:23 +00:00
|
|
|
GetContentSourceRef() string
|
2024-08-15 15:12:42 +00:00
|
|
|
SetContentSourceRef(uri string)
|
2024-09-19 08:03:23 +00:00
|
|
|
SetFS(fs.FS)
|
|
|
|
PathNormalization(bool)
|
|
|
|
NormalizePath() error
|
|
|
|
GetTarget() string
|
2024-10-04 00:30:49 +00:00
|
|
|
SetGzipContent(bool)
|
2024-08-15 15:12:42 +00:00
|
|
|
}
|
|
|
|
|
2024-11-10 18:27:31 +00:00
|
|
|
type ExecResource interface {
|
|
|
|
Start() error
|
|
|
|
Wait() error
|
|
|
|
StdoutPipe() (io.ReadCloser, error)
|
|
|
|
StderrPipe() (io.ReadCloser, error)
|
|
|
|
}
|
|
|
|
|
2024-09-19 08:03:23 +00:00
|
|
|
type Signed interface {
|
|
|
|
Signature() Signature
|
|
|
|
}
|
|
|
|
|
|
|
|
type FileInfoGetter interface {
|
|
|
|
Stat() (fs.FileInfo, error)
|
|
|
|
}
|