Initialize narratio Go module and CLI scaffold
This commit is contained in:
24
internal/artifacts/checksum.go
Normal file
24
internal/artifacts/checksum.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package artifacts
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
// SHA256File returns the SHA-256 hex digest of a file.
|
||||
func SHA256File(path string) (string, error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
h := sha256.New()
|
||||
if _, err := io.Copy(h, f); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return hex.EncodeToString(h.Sum(nil)), nil
|
||||
}
|
||||
2
internal/artifacts/doc.go
Normal file
2
internal/artifacts/doc.go
Normal file
@@ -0,0 +1,2 @@
|
||||
// Package artifacts defines artifact references and storage contracts.
|
||||
package artifacts
|
||||
31
internal/artifacts/local.go
Normal file
31
internal/artifacts/local.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package artifacts
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// LocalStore is a placeholder local filesystem artifact store.
|
||||
type LocalStore struct {
|
||||
RootDir string
|
||||
}
|
||||
|
||||
// WriteLocal returns a not-yet-implemented error in the scaffold.
|
||||
func (s *LocalStore) WriteLocal(_ context.Context, _ Ref, _ []byte) error {
|
||||
return fmt.Errorf("artifacts local write: not yet implemented")
|
||||
}
|
||||
|
||||
// ReadLocal returns a not-yet-implemented error in the scaffold.
|
||||
func (s *LocalStore) ReadLocal(_ context.Context, _ Ref) ([]byte, error) {
|
||||
return nil, fmt.Errorf("artifacts local read: not yet implemented")
|
||||
}
|
||||
|
||||
// ExistsLocal returns a not-yet-implemented error in the scaffold.
|
||||
func (s *LocalStore) ExistsLocal(_ context.Context, _ Ref) (bool, error) {
|
||||
return false, fmt.Errorf("artifacts local exists: not yet implemented")
|
||||
}
|
||||
|
||||
// Upload returns a not-yet-implemented error in the scaffold.
|
||||
func (s *LocalStore) Upload(_ context.Context, _ Ref) (string, error) {
|
||||
return "", fmt.Errorf("artifacts local upload: not yet implemented")
|
||||
}
|
||||
8
internal/artifacts/paths.go
Normal file
8
internal/artifacts/paths.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package artifacts
|
||||
|
||||
import "path/filepath"
|
||||
|
||||
// SessionWorkDir returns the work directory for one session.
|
||||
func SessionWorkDir(rootDir, sessionID string) string {
|
||||
return filepath.Join(rootDir, "work", sessionID)
|
||||
}
|
||||
32
internal/artifacts/s3.go
Normal file
32
internal/artifacts/s3.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package artifacts
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// S3Store is a placeholder S3-compatible artifact store.
|
||||
type S3Store struct {
|
||||
Bucket string
|
||||
Prefix string
|
||||
}
|
||||
|
||||
// WriteLocal returns a not-yet-implemented error in the scaffold.
|
||||
func (s *S3Store) WriteLocal(_ context.Context, _ Ref, _ []byte) error {
|
||||
return fmt.Errorf("artifacts s3 write local: not yet implemented")
|
||||
}
|
||||
|
||||
// ReadLocal returns a not-yet-implemented error in the scaffold.
|
||||
func (s *S3Store) ReadLocal(_ context.Context, _ Ref) ([]byte, error) {
|
||||
return nil, fmt.Errorf("artifacts s3 read local: not yet implemented")
|
||||
}
|
||||
|
||||
// ExistsLocal returns a not-yet-implemented error in the scaffold.
|
||||
func (s *S3Store) ExistsLocal(_ context.Context, _ Ref) (bool, error) {
|
||||
return false, fmt.Errorf("artifacts s3 exists local: not yet implemented")
|
||||
}
|
||||
|
||||
// Upload returns a not-yet-implemented error in the scaffold.
|
||||
func (s *S3Store) Upload(_ context.Context, _ Ref) (string, error) {
|
||||
return "", fmt.Errorf("artifacts s3 upload: not yet implemented")
|
||||
}
|
||||
19
internal/artifacts/store.go
Normal file
19
internal/artifacts/store.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package artifacts
|
||||
|
||||
import "context"
|
||||
|
||||
// Ref identifies a pipeline artifact and optional remote location.
|
||||
type Ref struct {
|
||||
Kind string
|
||||
LocalPath string
|
||||
RemoteKey string
|
||||
Checksum string
|
||||
}
|
||||
|
||||
// Store is a placeholder artifact storage abstraction.
|
||||
type Store interface {
|
||||
WriteLocal(ctx context.Context, ref Ref, data []byte) error
|
||||
ReadLocal(ctx context.Context, ref Ref) ([]byte, error)
|
||||
ExistsLocal(ctx context.Context, ref Ref) (bool, error)
|
||||
Upload(ctx context.Context, ref Ref) (string, error)
|
||||
}
|
||||
Reference in New Issue
Block a user