summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.envrc1
-rw-r--r--.gitignore2
-rw-r--r--Cargo.lock (renamed from fctdrive/Cargo.lock)0
-rw-r--r--Cargo.toml (renamed from fctdrive/Cargo.toml)0
-rw-r--r--NOTES.md3
-rw-r--r--operation.go147
-rw-r--r--src/main.rs (renamed from fctdrive/src/main.rs)0
-rwxr-xr-xtinyauth.sh9
8 files changed, 11 insertions, 151 deletions
diff --git a/.envrc b/.envrc
new file mode 100644
index 0000000..ad6ada5
--- /dev/null
+++ b/.envrc
@@ -0,0 +1 @@
export FCTDRIVE_PATH="$(pwd)/fctdrive"
diff --git a/.gitignore b/.gitignore
index 9bfc36b..68ad3b2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,7 @@
1/miei/ 1/miei/
2/drive/ 2/drive/
3/blobs/ 3/blobs/
4/fctdrive/blobs/ 4/.demon/
5flamegraph.svg 5flamegraph.svg
6perf.data 6perf.data
7perf.data.old 7perf.data.old
diff --git a/fctdrive/Cargo.lock b/Cargo.lock
index 102daaf..102daaf 100644
--- a/fctdrive/Cargo.lock
+++ b/Cargo.lock
diff --git a/fctdrive/Cargo.toml b/Cargo.toml
index f2ffa1d..f2ffa1d 100644
--- a/fctdrive/Cargo.toml
+++ b/Cargo.toml
diff --git a/NOTES.md b/NOTES.md
deleted file mode 100644
index 8d55dcb..0000000
--- a/NOTES.md
+++ /dev/null
@@ -1,3 +0,0 @@
1# fct drive
2
3
diff --git a/operation.go b/operation.go
deleted file mode 100644
index 80f7c04..0000000
--- a/operation.go
+++ /dev/null
@@ -1,147 +0,0 @@
1package main
2
3import (
4 "fmt"
5 "strconv"
6 "strings"
7
8 "github.com/pkg/errors"
9)
10
11const (
12 Operation_Type_CreateFile string = "create_file"
13 Operation_Type_CreateDir string = "create_dir"
14 Operation_Type_Remove string = "remove"
15 Operation_Type_Rename string = "rename"
16)
17
18type Operation struct {
19 Timestamp uint64
20 Revision uint64
21 Email string
22 Type string
23 Params []string
24}
25
26type CreateFileParams struct {
27 Path string
28 Blob string
29}
30
31type CreateDirParams struct {
32 Path string
33}
34
35type RemoveParams struct {
36 Path string
37}
38
39type RenameParams struct {
40 Old string
41 New string
42}
43
44func (op *Operation) GetCreateFileParams() CreateFileParams {
45 op.assertType(Operation_Type_CreateFile)
46 op.assertParamsLen(2)
47 return CreateFileParams{
48 Path: op.Params[0],
49 Blob: op.Params[1],
50 }
51}
52
53func (op *Operation) GetCreateDirParams() CreateDirParams {
54 op.assertType(Operation_Type_CreateDir)
55 op.assertParamsLen(1)
56 return CreateDirParams{
57 Path: op.Params[0],
58 }
59}
60
61func (op *Operation) GetRemoveParams() RemoveParams {
62 op.assertType(Operation_Type_Remove)
63 op.assertParamsLen(1)
64 return RemoveParams{
65 Path: op.Params[0],
66 }
67}
68
69func (op *Operation) GetRenameParams() RenameParams {
70 op.assertType(Operation_Type_Rename)
71 op.assertParamsLen(2)
72 return RenameParams{
73 Old: op.Params[0],
74 New: op.Params[1],
75 }
76}
77
78func (op *Operation) assertType(t string) {
79 if op.Type != t {
80 panic(fmt.Sprintf("unexpected operation type, got %s but expected %s", op.Type, t))
81 }
82}
83
84func (op *Operation) assertParamsLen(n int) {
85 if len(op.Params) != n {
86 panic(fmt.Sprintf("unexpected operation parameter length, got %d but expected %d", len(op.Params), n))
87 }
88}
89
90func ParseOperation(line string) (*Operation, error) {
91 op := &Operation{}
92 baseErr := fmt.Errorf("invalid operation line: '%s'", line)
93 components := strings.Split(line, " ")
94 if len(components) < 4 {
95 return nil, errors.Wrapf(baseErr, "invalid number of components %d", len(components))
96 }
97
98 if timestamp, err := strconv.ParseUint(components[0], 10, 64); err != nil {
99 return nil, errors.Wrapf(baseErr, "invalid timestamp %v: %v", components[0], err)
100 } else {
101 op.Timestamp = timestamp
102 }
103
104 if revision, err := strconv.ParseUint(components[0], 10, 64); err != nil {
105 return nil, errors.Wrapf(baseErr, "invalid revision %v: %v", components[0], err)
106 } else {
107 op.Revision = revision
108 }
109
110 op.Email = components[2]
111 op.Type = components[3]
112 op.Params = components[4:]
113
114 switch op.Type {
115 case Operation_Type_CreateFile:
116 if len(op.Params) != 2 {
117 return nil, errors.Wrapf(baseErr, "invalid number of parameters for operation create file")
118 }
119 case Operation_Type_CreateDir:
120 if len(op.Params) != 1 {
121 return nil, errors.Wrapf(baseErr, "invalid number of parameters for operation create dir")
122 }
123
124 case Operation_Type_Remove:
125 if len(op.Params) != 1 {
126 return nil, errors.Wrapf(baseErr, "invalid number of parameters for operation remove")
127 }
128
129 case Operation_Type_Rename:
130 if len(op.Params) != 2 {
131 return nil, errors.Wrapf(baseErr, "invalid number of parameters for operation rename")
132 }
133 default:
134 return nil, errors.Wrapf(baseErr, "invalid operation type '%v'", op.Type)
135 }
136
137 return op, nil
138}
139
140func (op *Operation) String() string {
141 params := strings.Join(op.Params, " ")
142 base := fmt.Sprintf("%d %d %s %s", op.Timestamp, op.Revision, op.Email, op.Type)
143 if len(params) > 0 {
144 base = base + " " + params
145 }
146 return base
147}
diff --git a/fctdrive/src/main.rs b/src/main.rs
index 3a8e5f9..3a8e5f9 100644
--- a/fctdrive/src/main.rs
+++ b/src/main.rs
diff --git a/tinyauth.sh b/tinyauth.sh
new file mode 100755
index 0000000..72f9d84
--- /dev/null
+++ b/tinyauth.sh
@@ -0,0 +1,9 @@
1#!/usr/bin/env bash
2
3# user:password
4podman run --rm -it \
5 --network host \
6 -e SECRET='some-random-32-chars-string11111' \
7 -e APP_URL='http://10.0.0.3:3000' \
8 -e USERS='user:$$2a$$10$$UdLYoJ5lgPsC0RKqYH/jMua7zIn0g9kPqWmhYayJYLaZQ/FTmH2/u' \
9 ghcr.io/steveiliop56/tinyauth:v3