feat: Make STFS API public

Also: Happy new year :)
This commit is contained in:
Felix Pojtinger
2021-12-31 23:57:21 +01:00
parent ef364c836b
commit 67d97ed32b
32 changed files with 214 additions and 222 deletions

View File

@@ -2,9 +2,9 @@ package cmd
import (
"github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/pkg/config"
"github.com/pojntfx/stfs/pkg/inventory"
"github.com/pojntfx/stfs/pkg/persisters"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

View File

@@ -2,9 +2,9 @@ package cmd
import (
"github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/pkg/config"
"github.com/pojntfx/stfs/pkg/inventory"
"github.com/pojntfx/stfs/pkg/persisters"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

View File

@@ -2,9 +2,9 @@ package cmd
import (
"github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/pkg/config"
"github.com/pojntfx/stfs/pkg/inventory"
"github.com/pojntfx/stfs/pkg/persisters"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

View File

@@ -7,12 +7,12 @@ import (
"os"
"path/filepath"
"github.com/pojntfx/stfs/internal/compression"
"github.com/pojntfx/stfs/internal/check"
"github.com/pojntfx/stfs/internal/keys"
"github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/pkg/config"
"github.com/pojntfx/stfs/pkg/operations"
"github.com/pojntfx/stfs/pkg/persisters"
"github.com/pojntfx/stfs/pkg/tape"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@@ -37,15 +37,15 @@ var operationArchiveCmd = &cobra.Command{
return err
}
if err := compression.CheckCompressionLevel(viper.GetString(compressionLevelFlag)); err != nil {
if err := check.CheckCompressionLevel(viper.GetString(compressionLevelFlag)); err != nil {
return err
}
if err := keys.CheckKeyAccessible(viper.GetString(encryptionFlag), viper.GetString(recipientFlag)); err != nil {
if err := check.CheckKeyAccessible(viper.GetString(encryptionFlag), viper.GetString(recipientFlag)); err != nil {
return err
}
return keys.CheckKeyAccessible(viper.GetString(signatureFlag), viper.GetString(identityFlag))
return check.CheckKeyAccessible(viper.GetString(signatureFlag), viper.GetString(identityFlag))
},
RunE: func(cmd *cobra.Command, args []string) error {
pubkey, err := keys.ReadKey(viper.GetString(encryptionFlag), viper.GetString(recipientFlag))

View File

@@ -1,11 +1,12 @@
package cmd
import (
"github.com/pojntfx/stfs/internal/check"
"github.com/pojntfx/stfs/internal/keys"
"github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/pkg/config"
"github.com/pojntfx/stfs/pkg/operations"
"github.com/pojntfx/stfs/pkg/persisters"
"github.com/pojntfx/stfs/pkg/tape"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@@ -24,11 +25,11 @@ var operationDeleteCmd = &cobra.Command{
return err
}
if err := keys.CheckKeyAccessible(viper.GetString(encryptionFlag), viper.GetString(recipientFlag)); err != nil {
if err := check.CheckKeyAccessible(viper.GetString(encryptionFlag), viper.GetString(recipientFlag)); err != nil {
return err
}
return keys.CheckKeyAccessible(viper.GetString(signatureFlag), viper.GetString(identityFlag))
return check.CheckKeyAccessible(viper.GetString(signatureFlag), viper.GetString(identityFlag))
},
RunE: func(cmd *cobra.Command, args []string) error {
pubkey, err := keys.ReadKey(viper.GetString(encryptionFlag), viper.GetString(recipientFlag))

View File

@@ -1,11 +1,12 @@
package cmd
import (
"github.com/pojntfx/stfs/internal/check"
"github.com/pojntfx/stfs/internal/keys"
"github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/pkg/config"
"github.com/pojntfx/stfs/pkg/operations"
"github.com/pojntfx/stfs/pkg/persisters"
"github.com/pojntfx/stfs/pkg/tape"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@@ -20,11 +21,11 @@ var operationMoveCmd = &cobra.Command{
return err
}
if err := keys.CheckKeyAccessible(viper.GetString(encryptionFlag), viper.GetString(recipientFlag)); err != nil {
if err := check.CheckKeyAccessible(viper.GetString(encryptionFlag), viper.GetString(recipientFlag)); err != nil {
return err
}
return keys.CheckKeyAccessible(viper.GetString(signatureFlag), viper.GetString(identityFlag))
return check.CheckKeyAccessible(viper.GetString(signatureFlag), viper.GetString(identityFlag))
},
RunE: func(cmd *cobra.Command, args []string) error {
pubkey, err := keys.ReadKey(viper.GetString(encryptionFlag), viper.GetString(recipientFlag))

View File

@@ -5,11 +5,12 @@ import (
"io/fs"
"os"
"github.com/pojntfx/stfs/internal/check"
"github.com/pojntfx/stfs/internal/keys"
"github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/pkg/config"
"github.com/pojntfx/stfs/pkg/operations"
"github.com/pojntfx/stfs/pkg/persisters"
"github.com/pojntfx/stfs/pkg/tape"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@@ -28,11 +29,11 @@ var operationRestoreCmd = &cobra.Command{
return err
}
if err := keys.CheckKeyAccessible(viper.GetString(encryptionFlag), viper.GetString(identityFlag)); err != nil {
if err := check.CheckKeyAccessible(viper.GetString(encryptionFlag), viper.GetString(identityFlag)); err != nil {
return err
}
return keys.CheckKeyAccessible(viper.GetString(signatureFlag), viper.GetString(recipientFlag))
return check.CheckKeyAccessible(viper.GetString(signatureFlag), viper.GetString(recipientFlag))
},
RunE: func(cmd *cobra.Command, args []string) error {
pubkey, err := keys.ReadKey(viper.GetString(signatureFlag), viper.GetString(recipientFlag))

View File

@@ -7,12 +7,12 @@ import (
"os"
"path/filepath"
"github.com/pojntfx/stfs/internal/compression"
"github.com/pojntfx/stfs/internal/check"
"github.com/pojntfx/stfs/internal/keys"
"github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/pkg/config"
"github.com/pojntfx/stfs/pkg/operations"
"github.com/pojntfx/stfs/pkg/persisters"
"github.com/pojntfx/stfs/pkg/tape"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@@ -27,15 +27,15 @@ var operationUpdateCmd = &cobra.Command{
return err
}
if err := compression.CheckCompressionLevel(viper.GetString(compressionLevelFlag)); err != nil {
if err := check.CheckCompressionLevel(viper.GetString(compressionLevelFlag)); err != nil {
return err
}
if err := keys.CheckKeyAccessible(viper.GetString(encryptionFlag), viper.GetString(recipientFlag)); err != nil {
if err := check.CheckKeyAccessible(viper.GetString(encryptionFlag), viper.GetString(recipientFlag)); err != nil {
return err
}
return keys.CheckKeyAccessible(viper.GetString(signatureFlag), viper.GetString(identityFlag))
return check.CheckKeyAccessible(viper.GetString(signatureFlag), viper.GetString(identityFlag))
},
RunE: func(cmd *cobra.Command, args []string) error {
pubkey, err := keys.ReadKey(viper.GetString(encryptionFlag), viper.GetString(recipientFlag))

View File

@@ -5,6 +5,7 @@ import (
"io/fs"
"os"
"github.com/pojntfx/stfs/internal/check"
"github.com/pojntfx/stfs/internal/keys"
"github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/pkg/config"
@@ -29,11 +30,11 @@ var recoveryFetchCmd = &cobra.Command{
return err
}
if err := keys.CheckKeyAccessible(viper.GetString(encryptionFlag), viper.GetString(identityFlag)); err != nil {
if err := check.CheckKeyAccessible(viper.GetString(encryptionFlag), viper.GetString(identityFlag)); err != nil {
return err
}
return keys.CheckKeyAccessible(viper.GetString(signatureFlag), viper.GetString(recipientFlag))
return check.CheckKeyAccessible(viper.GetString(signatureFlag), viper.GetString(recipientFlag))
},
RunE: func(cmd *cobra.Command, args []string) error {
pubkey, err := keys.ReadKey(viper.GetString(signatureFlag), viper.GetString(recipientFlag))

View File

@@ -3,12 +3,13 @@ package cmd
import (
"archive/tar"
"github.com/pojntfx/stfs/internal/check"
"github.com/pojntfx/stfs/internal/encryption"
"github.com/pojntfx/stfs/internal/keys"
"github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/internal/signature"
"github.com/pojntfx/stfs/pkg/config"
"github.com/pojntfx/stfs/pkg/persisters"
"github.com/pojntfx/stfs/pkg/recovery"
"github.com/pojntfx/stfs/pkg/tape"
"github.com/spf13/cobra"
@@ -23,11 +24,11 @@ var recoveryIndexCmd = &cobra.Command{
return err
}
if err := keys.CheckKeyAccessible(viper.GetString(encryptionFlag), viper.GetString(identityFlag)); err != nil {
if err := check.CheckKeyAccessible(viper.GetString(encryptionFlag), viper.GetString(identityFlag)); err != nil {
return err
}
return keys.CheckKeyAccessible(viper.GetString(signatureFlag), viper.GetString(recipientFlag))
return check.CheckKeyAccessible(viper.GetString(signatureFlag), viper.GetString(recipientFlag))
},
RunE: func(cmd *cobra.Command, args []string) error {
pubkey, err := keys.ReadKey(viper.GetString(signatureFlag), viper.GetString(recipientFlag))

View File

@@ -1,6 +1,7 @@
package cmd
import (
"github.com/pojntfx/stfs/internal/check"
"github.com/pojntfx/stfs/internal/keys"
"github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/pkg/config"
@@ -18,11 +19,11 @@ var recoveryQueryCmd = &cobra.Command{
return err
}
if err := keys.CheckKeyAccessible(viper.GetString(encryptionFlag), viper.GetString(identityFlag)); err != nil {
if err := check.CheckKeyAccessible(viper.GetString(encryptionFlag), viper.GetString(identityFlag)); err != nil {
return err
}
return keys.CheckKeyAccessible(viper.GetString(signatureFlag), viper.GetString(recipientFlag))
return check.CheckKeyAccessible(viper.GetString(signatureFlag), viper.GetString(recipientFlag))
},
RunE: func(cmd *cobra.Command, args []string) error {
pubkey, err := keys.ReadKey(viper.GetString(signatureFlag), viper.GetString(recipientFlag))

View File

@@ -6,10 +6,8 @@ import (
"path/filepath"
"strings"
"github.com/pojntfx/stfs/internal/compression"
"github.com/pojntfx/stfs/internal/encryption"
"github.com/pojntfx/stfs/internal/check"
"github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/internal/signature"
"github.com/pojntfx/stfs/pkg/config"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@@ -45,15 +43,15 @@ https://github.com/pojntfx/stfs`,
boil.DebugWriter = logging.NewJSONLoggerWriter(verbosity, "SQL Query", "query")
}
if err := compression.CheckCompressionFormat(viper.GetString(compressionFlag)); err != nil {
if err := check.CheckCompressionFormat(viper.GetString(compressionFlag)); err != nil {
return err
}
if err := encryption.CheckEncryptionFormat(viper.GetString(encryptionFlag)); err != nil {
if err := check.CheckEncryptionFormat(viper.GetString(encryptionFlag)); err != nil {
return err
}
return signature.CheckSignatureFormat(viper.GetString(signatureFlag))
return check.CheckSignatureFormat(viper.GetString(signatureFlag))
},
}

View File

@@ -8,15 +8,16 @@ import (
"time"
ftpserver "github.com/fclairamb/ftpserverlib"
"github.com/pojntfx/stfs/internal/cache"
"github.com/pojntfx/stfs/internal/check"
models "github.com/pojntfx/stfs/internal/db/sqlite/models/metadata"
sfs "github.com/pojntfx/stfs/internal/fs"
"github.com/pojntfx/stfs/internal/ftp"
"github.com/pojntfx/stfs/internal/keys"
"github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/pkg/cache"
"github.com/pojntfx/stfs/pkg/config"
sfs "github.com/pojntfx/stfs/pkg/fs"
"github.com/pojntfx/stfs/pkg/operations"
"github.com/pojntfx/stfs/pkg/persisters"
"github.com/pojntfx/stfs/pkg/tape"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@@ -47,27 +48,27 @@ var serveFTPCmd = &cobra.Command{
return err
}
if err := cache.CheckFileSystemCacheType(viper.GetString(cacheFileSystemFlag)); err != nil {
if err := check.CheckFileSystemCacheType(viper.GetString(cacheFileSystemFlag)); err != nil {
return err
}
if err := cache.CheckWriteCacheType(viper.GetString(cacheWriteFlag)); err != nil {
if err := check.CheckWriteCacheType(viper.GetString(cacheWriteFlag)); err != nil {
return err
}
if err := keys.CheckKeyAccessible(viper.GetString(encryptionFlag), viper.GetString(encryptionIdentityFlag)); err != nil {
if err := check.CheckKeyAccessible(viper.GetString(encryptionFlag), viper.GetString(encryptionIdentityFlag)); err != nil {
return err
}
if err := keys.CheckKeyAccessible(viper.GetString(encryptionFlag), viper.GetString(encryptionRecipientFlag)); err != nil {
if err := check.CheckKeyAccessible(viper.GetString(encryptionFlag), viper.GetString(encryptionRecipientFlag)); err != nil {
return err
}
if err := keys.CheckKeyAccessible(viper.GetString(signatureFlag), viper.GetString(signatureIdentityFlag)); err != nil {
if err := check.CheckKeyAccessible(viper.GetString(signatureFlag), viper.GetString(signatureIdentityFlag)); err != nil {
return err
}
return keys.CheckKeyAccessible(viper.GetString(signatureFlag), viper.GetString(signatureRecipientFlag))
return check.CheckKeyAccessible(viper.GetString(signatureFlag), viper.GetString(signatureRecipientFlag))
},
RunE: func(cmd *cobra.Command, args []string) error {
signaturePubkey, err := keys.ReadKey(viper.GetString(signatureFlag), viper.GetString(signatureRecipientFlag))
@@ -192,7 +193,7 @@ var serveFTPCmd = &cobra.Command{
},
)
stfs := sfs.NewFileSystem(
stfs := sfs.NewSTFS(
readOps,
writeOps,
@@ -201,7 +202,7 @@ var serveFTPCmd = &cobra.Command{
},
viper.GetString(compressionLevelFlag),
func() (sfs.WriteCache, func() error, error) {
func() (cache.WriteCache, func() error, error) {
return cache.NewCacheWrite(
filepath.Join(viper.GetString(cacheDirFlag), "write"),
viper.GetString(cacheWriteFlag),
@@ -258,8 +259,8 @@ func init() {
serveFTPCmd.PersistentFlags().StringP(compressionLevelFlag, "l", config.CompressionLevelBalanced, fmt.Sprintf("Compression level to use (default %v, available are %v)", config.CompressionLevelBalanced, config.KnownCompressionLevels))
serveFTPCmd.PersistentFlags().StringP(laddrFlag, "a", "localhost:1337", "Listen address")
serveFTPCmd.PersistentFlags().StringP(cacheFileSystemFlag, "n", config.NoneKey, fmt.Sprintf("File system cache to use (default %v, available are %v)", config.NoneKey, cache.KnownFileSystemCacheTypes))
serveFTPCmd.PersistentFlags().StringP(cacheWriteFlag, "q", cache.WriteCacheTypeFile, fmt.Sprintf("Write cache to use (default %v, available are %v)", cache.WriteCacheTypeFile, cache.KnownWriteCacheTypes))
serveFTPCmd.PersistentFlags().StringP(cacheFileSystemFlag, "n", config.NoneKey, fmt.Sprintf("File system cache to use (default %v, available are %v)", config.NoneKey, config.KnownFileSystemCacheTypes))
serveFTPCmd.PersistentFlags().StringP(cacheWriteFlag, "q", config.WriteCacheTypeFile, fmt.Sprintf("Write cache to use (default %v, available are %v)", config.WriteCacheTypeFile, config.KnownWriteCacheTypes))
serveFTPCmd.PersistentFlags().DurationP(cacheDurationFlag, "u", time.Hour, "Duration until cache is invalidated")
serveFTPCmd.PersistentFlags().StringP(cacheDirFlag, "w", cacheDir, "Directory to use if dir cache is enabled")

View File

@@ -7,15 +7,16 @@ import (
"path/filepath"
"time"
"github.com/pojntfx/stfs/internal/cache"
"github.com/pojntfx/stfs/internal/check"
models "github.com/pojntfx/stfs/internal/db/sqlite/models/metadata"
sfs "github.com/pojntfx/stfs/internal/fs"
"github.com/pojntfx/stfs/internal/handlers"
"github.com/pojntfx/stfs/internal/keys"
"github.com/pojntfx/stfs/internal/logging"
"github.com/pojntfx/stfs/internal/persisters"
"github.com/pojntfx/stfs/pkg/cache"
"github.com/pojntfx/stfs/pkg/config"
sfs "github.com/pojntfx/stfs/pkg/fs"
"github.com/pojntfx/stfs/pkg/operations"
"github.com/pojntfx/stfs/pkg/persisters"
"github.com/pojntfx/stfs/pkg/tape"
"github.com/spf13/afero"
"github.com/spf13/cobra"
@@ -38,15 +39,15 @@ var serveHTTPCmd = &cobra.Command{
return err
}
if err := cache.CheckFileSystemCacheType(viper.GetString(cacheFileSystemFlag)); err != nil {
if err := check.CheckFileSystemCacheType(viper.GetString(cacheFileSystemFlag)); err != nil {
return err
}
if err := keys.CheckKeyAccessible(viper.GetString(encryptionFlag), viper.GetString(identityFlag)); err != nil {
if err := check.CheckKeyAccessible(viper.GetString(encryptionFlag), viper.GetString(identityFlag)); err != nil {
return err
}
return keys.CheckKeyAccessible(viper.GetString(signatureFlag), viper.GetString(recipientFlag))
return check.CheckKeyAccessible(viper.GetString(signatureFlag), viper.GetString(recipientFlag))
},
RunE: func(cmd *cobra.Command, args []string) error {
pubkey, err := keys.ReadKey(viper.GetString(signatureFlag), viper.GetString(recipientFlag))
@@ -119,7 +120,7 @@ var serveHTTPCmd = &cobra.Command{
},
)
stfs := sfs.NewFileSystem(
stfs := sfs.NewSTFS(
readOps,
nil,
@@ -170,7 +171,7 @@ func init() {
serveHTTPCmd.PersistentFlags().StringP(passwordFlag, "p", "", "Password for the private key")
serveHTTPCmd.PersistentFlags().StringP(recipientFlag, "r", "", "Path to the public key to verify with")
serveHTTPCmd.PersistentFlags().StringP(laddrFlag, "a", "localhost:1337", "Listen address")
serveHTTPCmd.PersistentFlags().StringP(cacheFileSystemFlag, "n", config.NoneKey, fmt.Sprintf("File system cache to use (default %v, available are %v)", config.NoneKey, cache.KnownFileSystemCacheTypes))
serveHTTPCmd.PersistentFlags().StringP(cacheFileSystemFlag, "n", config.NoneKey, fmt.Sprintf("File system cache to use (default %v, available are %v)", config.NoneKey, config.KnownFileSystemCacheTypes))
serveHTTPCmd.PersistentFlags().DurationP(cacheDurationFlag, "u", time.Hour, "Duration until cache is invalidated")
serveHTTPCmd.PersistentFlags().StringP(cacheDirFlag, "w", cacheDir, "Directory to use if dir cache is enabled")